Annotation of loncom/interface/domainprefs.pm, revision 1.444
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.444 ! raeburn 4: # $Id: domainprefs.pm,v 1.443 2024/08/31 18:48:53 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
1.286 raeburn 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
1.1 raeburn 24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: ###############################################################
1.297 raeburn 30: ###############################################################
1.1 raeburn 31:
1.101 raeburn 32: =pod
33:
34: =head1 NAME
35:
36: Apache::domainprefs.pm
37:
38: =head1 SYNOPSIS
39:
40: Handles configuration of a LON-CAPA domain.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
45:
46: =head1 OVERVIEW
47:
48: Each institution using LON-CAPA will typically have a single domain designated
1.183 bisitz 49: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 50: may define a default set of logos and a color scheme which can be used to "brand"
51: the LON-CAPA instance. In addition, an institution will typically have a language
52: and timezone which are used for the majority of courses.
53:
54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
55: host of other domain-wide settings which determine the types of functionality
56: available to users and courses in the domain.
57:
58: There is also a mechanism to configure cataloging of courses in the domain, and
59: controls on the operation of automated processes which govern such things as
60: roster updates, user directory updates and processing of course requests.
61:
62: The domain coordination manual which is built dynamically on install/update of
63: LON-CAPA from the relevant help items provides more information about domain
64: configuration.
65:
66: Most of the domain settings are stored in the configuration.db GDBM file which is
67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
68: where $dom is the domain. The configuration.db stores settings in a number of
69: frozen hashes of hashes. In a few cases, domain information must be uploaded to
70: the domain as files (e.g., image files for logos etc., or plain text files for
71: bubblesheet formats). In this case the domainprefs.pm must be running in a user
72: session hosted on the primary library server in the domain, as these files are
73: stored in author space belonging to a special $dom-domainconfig user.
74:
75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
76: the current settings, and provides an interface to make modifications.
77:
78: =head1 SUBROUTINES
79:
80: =over
81:
82: =item print_quotas()
83:
84: Inputs: 4
85:
86: $dom,$settings,$rowtotal,$action.
87:
88: $dom is the domain, $settings is a reference to a hash of current settings for
89: the current context, $rowtotal is a reference to the scalar used to record the
1.210 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.163 raeburn 91: requestcourses or requestauthor).
1.101 raeburn 92:
93: The print_quotas routine was orginally created to display/store information
94: about default quota sizes for portfolio spaces for the different types of
95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
96: but is now also used to manage availability of user tools:
97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.429 raeburn 98: used by course owners to request creation of a course.
1.101 raeburn 99:
100: Outputs: 1
101:
102: $datatable - HTML containing form elements which allow settings to be changed.
103:
104: In the case of course requests, radio buttons are displayed for each institutional
105: affiliate type (and also default, and _LC_adv) for each of the course types
1.325 raeburn 106: (official, unofficial, community, textbook, placement, and lti).
1.425 raeburn 107: In each case the radio buttons allow the selection of one of four values:
1.101 raeburn 108:
1.104 raeburn 109: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 110: which have the following effects:
111:
112: 0
113:
114: =over
115:
116: - course requests are not allowed for this course types/affiliation
117:
118: =back
119:
1.104 raeburn 120: approval
1.101 raeburn 121:
122: =over
123:
124: - course requests must be approved by a Doman Coordinator in the
125: course's domain
126:
127: =back
128:
129: validate
130:
131: =over
132:
133: - an institutional validation (e.g., check requestor is instructor
134: of record) needs to be passed before the course will be created. The required
135: validation is in localenroll.pm on the primary library server for the course
136: domain.
137:
138: =back
139:
140: autolimit
141:
142: =over
143:
1.143 raeburn 144: - course requests will be processed automatically up to a limit of
1.101 raeburn 145: N requests for the course type for the particular requestor.
146: If N is undefined, there is no limit to the number of course requests
147: which a course owner may submit and have processed automatically.
148:
149: =back
150:
151: =item modify_quotas()
152:
153: =back
154:
155: =cut
156:
1.1 raeburn 157: package Apache::domainprefs;
158:
159: use strict;
160: use Apache::Constants qw(:common :http);
161: use Apache::lonnet;
162: use Apache::loncommon();
163: use Apache::lonhtmlcommon();
164: use Apache::lonlocal;
1.43 raeburn 165: use Apache::lonmsg();
1.91 raeburn 166: use Apache::lonconfigsettings;
1.232 raeburn 167: use Apache::lonuserutils();
1.235 raeburn 168: use Apache::loncoursequeueadmin();
1.419 raeburn 169: use Apache::courseprefs();
1.69 raeburn 170: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 171: use LONCAPA::Enrollment;
1.81 raeburn 172: use LONCAPA::lonauthcgi();
1.275 raeburn 173: use LONCAPA::SSL;
1.9 raeburn 174: use File::Copy;
1.43 raeburn 175: use Locale::Language;
1.62 raeburn 176: use DateTime::TimeZone;
1.68 raeburn 177: use DateTime::Locale;
1.267 raeburn 178: use Time::HiRes qw( sleep );
1.373 raeburn 179: use Net::CIDR;
1.424 raeburn 180: use Crypt::CBC;
1.1 raeburn 181:
1.155 raeburn 182: my $registered_cleanup;
183: my $modified_urls;
184:
1.1 raeburn 185: sub handler {
186: my $r=shift;
187: if ($r->header_only) {
188: &Apache::loncommon::content_type($r,'text/html');
189: $r->send_http_header;
190: return OK;
191: }
192:
1.91 raeburn 193: my $context = 'domain';
1.1 raeburn 194: my $dom = $env{'request.role.domain'};
1.5 albertel 195: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 196: if (&Apache::lonnet::allowed('mau',$dom)) {
197: &Apache::loncommon::content_type($r,'text/html');
198: $r->send_http_header;
199: } else {
200: $env{'user.error.msg'}=
201: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
202: return HTTP_NOT_ACCEPTABLE;
203: }
1.155 raeburn 204:
205: $registered_cleanup=0;
206: @{$modified_urls}=();
207:
1.1 raeburn 208: &Apache::lonhtmlcommon::clear_breadcrumbs();
209: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 210: ['phase','actions']);
1.30 raeburn 211: my $phase = 'pickactions';
1.3 raeburn 212: if ( exists($env{'form.phase'}) ) {
213: $phase = $env{'form.phase'};
214: }
1.150 raeburn 215: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 216: my %domconfig =
1.6 raeburn 217: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 218: 'quotas','autoenroll','autoupdate','autocreate',
219: 'directorysrch','usercreation','usermodification',
220: 'contacts','defaults','scantron','coursecategories',
221: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 222: 'coursedefaults','usersessions','loadbalancing',
1.267 raeburn 223: 'requestauthor','selfenrollment','inststatus',
1.421 raeburn 224: 'ltitools','toolsec','ssl','trust','lti','ltisec',
1.429 raeburn 225: 'privacy','passwords','proctoring','wafproxy',
226: 'ipaccess','authordefaults'],$dom);
1.320 raeburn 227: my %encconfig =
1.405 raeburn 228: &Apache::lonnet::get_dom('encconfig',['ltitools','lti','proctoring','linkprot'],$dom,undef,1);
1.424 raeburn 229: my ($checked_is_home,$is_home);
1.297 raeburn 230: if (ref($domconfig{'ltitools'}) eq 'HASH') {
231: if (ref($encconfig{'ltitools'}) eq 'HASH') {
1.423 raeburn 232: my $home = &Apache::lonnet::domain($dom,'primary');
233: unless (($home eq 'no_host') || ($home eq '')) {
234: my @ids=&Apache::lonnet::current_machine_ids();
235: if (grep(/^\Q$home\E$/,@ids)) {
236: $is_home = 1;
237: }
238: }
1.425 raeburn 239: $checked_is_home = 1;
1.297 raeburn 240: foreach my $id (keys(%{$domconfig{'ltitools'}})) {
1.320 raeburn 241: if ((ref($domconfig{'ltitools'}{$id}) eq 'HASH') &&
242: (ref($encconfig{'ltitools'}{$id}) eq 'HASH')) {
1.421 raeburn 243: $domconfig{'ltitools'}{$id}{'key'} = $encconfig{'ltitools'}{$id}{'key'};
1.423 raeburn 244: if (($is_home) && ($phase eq 'process')) {
245: $domconfig{'ltitools'}{$id}{'secret'} = $encconfig{'ltitools'}{$id}{'secret'};
246: }
1.297 raeburn 247: }
248: }
249: }
250: }
1.320 raeburn 251: if (ref($domconfig{'lti'}) eq 'HASH') {
252: if (ref($encconfig{'lti'}) eq 'HASH') {
1.424 raeburn 253: unless ($checked_is_home) {
254: my $home = &Apache::lonnet::domain($dom,'primary');
255: unless (($home eq 'no_host') || ($home eq '')) {
256: my @ids=&Apache::lonnet::current_machine_ids();
257: if (grep(/^\Q$home\E$/,@ids)) {
258: $is_home = 1;
259: }
260: }
261: $checked_is_home = 1;
262: }
1.320 raeburn 263: foreach my $id (keys(%{$domconfig{'lti'}})) {
264: if ((ref($domconfig{'lti'}{$id}) eq 'HASH') &&
265: (ref($encconfig{'lti'}{$id}) eq 'HASH')) {
1.424 raeburn 266: $domconfig{'lti'}{$id}{'key'} = $encconfig{'lti'}{$id}{'key'};
267: if (($is_home) && ($phase eq 'process')) {
268: $domconfig{'lti'}{$id}{'secret'} = $encconfig{'lti'}{$id}{'secret'};
1.320 raeburn 269: }
270: }
271: }
272: }
273: }
1.405 raeburn 274: if (ref($domconfig{'ltisec'}) eq 'HASH') {
1.406 raeburn 275: if (ref($domconfig{'ltisec'}{'linkprot'}) eq 'HASH') {
1.405 raeburn 276: if (ref($encconfig{'linkprot'}) eq 'HASH') {
1.406 raeburn 277: foreach my $id (keys(%{$domconfig{'ltisec'}{'linkprot'}})) {
278: unless ($id =~ /^\d+$/) {
279: delete($domconfig{'ltisec'}{'linkprot'}{$id});
280: }
281: if ((ref($domconfig{'ltisec'}{'linkprot'}{$id}) eq 'HASH') &&
1.405 raeburn 282: (ref($encconfig{'linkprot'}{$id}) eq 'HASH')) {
283: foreach my $item ('key','secret') {
1.406 raeburn 284: $domconfig{'ltisec'}{'linkprot'}{$id}{$item} = $encconfig{'linkprot'}{$id}{$item};
1.405 raeburn 285: }
286: }
287: }
288: }
289: }
290: }
1.372 raeburn 291: if (ref($domconfig{'proctoring'}) eq 'HASH') {
292: if (ref($encconfig{'proctoring'}) eq 'HASH') {
293: foreach my $provider (keys(%{$domconfig{'proctoring'}})) {
294: if ((ref($domconfig{'proctoring'}{$provider}) eq 'HASH') &&
295: (ref($encconfig{'proctoring'}{$provider}) eq 'HASH')) {
296: foreach my $item ('key','secret') {
297: $domconfig{'proctoring'}{$provider}{$item} = $encconfig{'proctoring'}{$provider}{$item};
298: }
299: }
300: }
301: }
302: }
1.394 raeburn 303: my @prefs_order = ('rolecolors','login','ipaccess','defaults','wafproxy','passwords',
304: 'quotas','autoenroll','autoupdate','autocreate','directorysrch',
1.373 raeburn 305: 'contacts','privacy','usercreation','selfcreation',
1.374 raeburn 306: 'usermodification','scantron','requestcourses','requestauthor',
1.373 raeburn 307: 'coursecategories','serverstatuses','helpsettings','coursedefaults',
1.429 raeburn 308: 'authordefaults','ltitools','proctoring','selfenrollment',
309: 'usersessions','ssl','trust','lti');
1.171 raeburn 310: my %existing;
311: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
312: %existing = %{$domconfig{'loadbalancing'}};
313: }
314: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 315: push(@prefs_order,'loadbalancing');
316: }
1.30 raeburn 317: my %prefs = (
318: 'rolecolors' =>
319: { text => 'Default color schemes',
1.67 raeburn 320: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 321: header => [{col1 => 'Student Settings',
322: col2 => '',},
323: {col1 => 'Coordinator Settings',
324: col2 => '',},
325: {col1 => 'Author Settings',
326: col2 => '',},
327: {col1 => 'Administrator Settings',
328: col2 => '',}],
1.230 raeburn 329: print => \&print_rolecolors,
330: modify => \&modify_rolecolors,
1.30 raeburn 331: },
1.110 raeburn 332: 'login' =>
1.30 raeburn 333: { text => 'Log-in page options',
1.67 raeburn 334: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 335: header => [{col1 => 'Log-in Page Items',
336: col2 => '',},
337: {col1 => 'Log-in Help',
1.256 raeburn 338: col2 => 'Value'},
339: {col1 => 'Custom HTML in document head',
1.386 raeburn 340: col2 => 'Value'},
341: {col1 => 'SSO',
342: col2 => 'Dual login: SSO and non-SSO options'},
343: ],
1.230 raeburn 344: print => \&print_login,
345: modify => \&modify_login,
1.30 raeburn 346: },
1.43 raeburn 347: 'defaults' =>
1.236 raeburn 348: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 349: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 350: header => [{col1 => 'Setting',
1.236 raeburn 351: col2 => 'Value'},
352: {col1 => 'Institutional user types',
1.409 raeburn 353: col2 => 'Name displayed'},
354: {col1 => 'Mapping for missing usernames via standard log-in',
355: col2 => 'Rules in use'}],
1.230 raeburn 356: print => \&print_defaults,
357: modify => \&modify_defaults,
1.43 raeburn 358: },
1.381 raeburn 359: 'wafproxy' =>
360: { text => 'Web Application Firewall/Reverse Proxy',
1.373 raeburn 361: help => 'Domain_Configuration_WAF_Proxy',
1.381 raeburn 362: header => [{col1 => 'Domain(s)',
363: col2 => 'Servers and WAF/Reverse Proxy alias(es)',
1.373 raeburn 364: },
1.381 raeburn 365: {col1 => 'Domain(s)',
366: col2 => 'WAF Configuration',}],
1.373 raeburn 367: print => \&print_wafproxy,
1.381 raeburn 368: modify => \&modify_wafproxy,
1.373 raeburn 369: },
1.354 raeburn 370: 'passwords' =>
371: { text => 'Passwords (Internal authentication)',
372: help => 'Domain_Configuration_Passwords',
373: header => [{col1 => 'Resetting Forgotten Password',
374: col2 => 'Settings'},
375: {col1 => 'Encryption of Stored Passwords (Internal Auth)',
376: col2 => 'Settings'},
377: {col1 => 'Rules for LON-CAPA Passwords',
378: col2 => 'Settings'},
379: {col1 => 'Course Owner Changing Student Passwords',
380: col2 => 'Settings'}],
381: print => \&print_passwords,
382: modify => \&modify_passwords,
383: },
1.30 raeburn 384: 'quotas' =>
1.429 raeburn 385: { text => 'Blogs, personal pages/timezones, portfolio/quotas',
1.67 raeburn 386: help => 'Domain_Configuration_Quotas',
1.77 raeburn 387: header => [{col1 => 'User affiliation',
1.72 raeburn 388: col2 => 'Available tools',
1.435 raeburn 389: col3 => 'Portfolio quota (MB)',}],
1.230 raeburn 390: print => \&print_quotas,
391: modify => \&modify_quotas,
1.30 raeburn 392: },
393: 'autoenroll' =>
394: { text => 'Auto-enrollment settings',
1.67 raeburn 395: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 396: header => [{col1 => 'Configuration setting',
397: col2 => 'Value(s)'}],
1.230 raeburn 398: print => \&print_autoenroll,
399: modify => \&modify_autoenroll,
1.30 raeburn 400: },
401: 'autoupdate' =>
402: { text => 'Auto-update settings',
1.67 raeburn 403: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 404: header => [{col1 => 'Setting',
405: col2 => 'Value',},
1.131 raeburn 406: {col1 => 'Setting',
407: col2 => 'Affiliation'},
1.43 raeburn 408: {col1 => 'User population',
1.227 bisitz 409: col2 => 'Updatable user data'}],
1.230 raeburn 410: print => \&print_autoupdate,
411: modify => \&modify_autoupdate,
1.30 raeburn 412: },
1.125 raeburn 413: 'autocreate' =>
414: { text => 'Auto-course creation settings',
415: help => 'Domain_Configuration_Auto_Creation',
416: header => [{col1 => 'Configuration Setting',
417: col2 => 'Value',}],
1.230 raeburn 418: print => \&print_autocreate,
419: modify => \&modify_autocreate,
1.125 raeburn 420: },
1.30 raeburn 421: 'directorysrch' =>
1.277 raeburn 422: { text => 'Directory searches',
1.67 raeburn 423: help => 'Domain_Configuration_InstDirectory_Search',
1.277 raeburn 424: header => [{col1 => 'Institutional Directory Setting',
425: col2 => 'Value',},
426: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 427: col2 => 'Value',}],
1.230 raeburn 428: print => \&print_directorysrch,
429: modify => \&modify_directorysrch,
1.30 raeburn 430: },
431: 'contacts' =>
1.286 raeburn 432: { text => 'E-mail addresses and helpform',
1.67 raeburn 433: help => 'Domain_Configuration_Contact_Info',
1.286 raeburn 434: header => [{col1 => 'Default e-mail addresses',
435: col2 => 'Value',},
436: {col1 => 'Recipient(s) for notifications',
437: col2 => 'Value',},
1.340 raeburn 438: {col1 => 'Nightly status check e-mail',
439: col2 => 'Settings',},
1.286 raeburn 440: {col1 => 'Ask helpdesk form settings',
441: col2 => 'Value',},],
1.230 raeburn 442: print => \&print_contacts,
443: modify => \&modify_contacts,
1.30 raeburn 444: },
445: 'usercreation' =>
446: { text => 'User creation',
1.67 raeburn 447: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 448: header => [{col1 => 'Format rule type',
449: col2 => 'Format rules in force'},
1.34 raeburn 450: {col1 => 'User account creation',
451: col2 => 'Usernames which may be created',},
1.30 raeburn 452: {col1 => 'Context',
1.43 raeburn 453: col2 => 'Assignable authentication types'}],
1.230 raeburn 454: print => \&print_usercreation,
455: modify => \&modify_usercreation,
1.30 raeburn 456: },
1.224 raeburn 457: 'selfcreation' =>
458: { text => 'Users self-creating accounts',
459: help => 'Domain_Configuration_Self_Creation',
460: header => [{col1 => 'Self-creation with institutional username',
461: col2 => 'Enabled?'},
462: {col1 => 'Institutional user type (login/SSO self-creation)',
463: col2 => 'Information user can enter'},
1.303 raeburn 464: {col1 => 'Self-creation with e-mail verification',
1.224 raeburn 465: col2 => 'Settings'}],
1.230 raeburn 466: print => \&print_selfcreation,
467: modify => \&modify_selfcreation,
1.224 raeburn 468: },
1.69 raeburn 469: 'usermodification' =>
1.33 raeburn 470: { text => 'User modification',
1.67 raeburn 471: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 472: header => [{col1 => 'Target user has role',
1.227 bisitz 473: col2 => 'User information updatable in author context'},
1.33 raeburn 474: {col1 => 'Target user has role',
1.443 raeburn 475: col2 => 'User information updatable by co-author manager'},
476: {col1 => 'Target user has role',
1.227 bisitz 477: col2 => 'User information updatable in course context'}],
1.230 raeburn 478: print => \&print_usermodification,
479: modify => \&modify_usermodification,
1.33 raeburn 480: },
1.69 raeburn 481: 'scantron' =>
1.346 raeburn 482: { text => 'Bubblesheet format',
1.67 raeburn 483: help => 'Domain_Configuration_Scantron_Format',
1.346 raeburn 484: header => [ {col1 => 'Bubblesheet format file',
485: col2 => ''},
486: {col1 => 'Bubblesheet data upload formats',
487: col2 => 'Settings'}],
1.230 raeburn 488: print => \&print_scantron,
489: modify => \&modify_scantron,
1.46 raeburn 490: },
1.86 raeburn 491: 'requestcourses' =>
492: {text => 'Request creation of courses',
493: help => 'Domain_Configuration_Request_Courses',
494: header => [{col1 => 'User affiliation',
1.102 raeburn 495: col2 => 'Availability/Processing of requests',},
496: {col1 => 'Setting',
1.216 raeburn 497: col2 => 'Value'},
498: {col1 => 'Available textbooks',
1.235 raeburn 499: col2 => ''},
1.242 raeburn 500: {col1 => 'Available templates',
501: col2 => ''},
1.235 raeburn 502: {col1 => 'Validation (not official courses)',
503: col2 => 'Value'},],
1.230 raeburn 504: print => \&print_quotas,
505: modify => \&modify_quotas,
1.86 raeburn 506: },
1.163 raeburn 507: 'requestauthor' =>
1.223 bisitz 508: {text => 'Request Authoring Space',
1.163 raeburn 509: help => 'Domain_Configuration_Request_Author',
510: header => [{col1 => 'User affiliation',
511: col2 => 'Availability/Processing of requests',},
512: {col1 => 'Setting',
513: col2 => 'Value'}],
1.230 raeburn 514: print => \&print_quotas,
515: modify => \&modify_quotas,
1.163 raeburn 516: },
1.69 raeburn 517: 'coursecategories' =>
1.120 raeburn 518: { text => 'Cataloging of courses/communities',
1.67 raeburn 519: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 520: header => [{col1 => 'Catalog type/availability',
521: col2 => '',},
522: {col1 => 'Category settings for standard catalog',
1.57 raeburn 523: col2 => '',},
524: {col1 => 'Categories',
525: col2 => '',
526: }],
1.230 raeburn 527: print => \&print_coursecategories,
528: modify => \&modify_coursecategories,
1.69 raeburn 529: },
530: 'serverstatuses' =>
1.77 raeburn 531: {text => 'Access to server status pages',
1.69 raeburn 532: help => 'Domain_Configuration_Server_Status',
533: header => [{col1 => 'Status Page',
534: col2 => 'Other named users',
535: col3 => 'Specific IPs',
536: }],
1.230 raeburn 537: print => \&print_serverstatuses,
538: modify => \&modify_serverstatuses,
1.69 raeburn 539: },
1.118 jms 540: 'helpsettings' =>
1.282 raeburn 541: {text => 'Support settings',
1.118 jms 542: help => 'Domain_Configuration_Help_Settings',
1.282 raeburn 543: header => [{col1 => 'Help Page Settings (logged-in users)',
544: col2 => 'Value'},
545: {col1 => 'Helpdesk Roles',
546: col2 => 'Settings'},],
1.230 raeburn 547: print => \&print_helpsettings,
548: modify => \&modify_helpsettings,
1.118 jms 549: },
1.121 raeburn 550: 'coursedefaults' =>
551: {text => 'Course/Community defaults',
552: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 553: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
554: col2 => 'Value',},
555: {col1 => 'Defaults which can be overridden for each course by a DC',
556: col2 => 'Value',},],
1.230 raeburn 557: print => \&print_coursedefaults,
558: modify => \&modify_coursedefaults,
1.121 raeburn 559: },
1.231 raeburn 560: 'selfenrollment' =>
561: {text => 'Self-enrollment in Course/Community',
562: help => 'Domain_Configuration_Selfenrollment',
563: header => [{col1 => 'Configuration Rights',
564: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
565: {col1 => 'Defaults',
566: col2 => 'Value'},
567: {col1 => 'Self-enrollment validation (optional)',
568: col2 => 'Value'},],
569: print => \&print_selfenrollment,
570: modify => \&modify_selfenrollment,
571: },
1.120 raeburn 572: 'privacy' =>
1.427 raeburn 573: {text => 'Role assignments and user privacy',
1.120 raeburn 574: help => 'Domain_Configuration_User_Privacy',
1.357 raeburn 575: header => [{col1 => 'Role assigned in different domain',
576: col2 => 'Approval options'},
577: {col1 => 'Role assigned in different domain to user of type',
578: col2 => 'User information available in that domain'},
579: {col1 => "Role assigned in user's domain",
580: col2 => 'Information viewable by privileged user'},
581: {col1 => "Role assigned in user's domain",
582: col2 => 'Information viewable by unprivileged user'}],
1.230 raeburn 583: print => \&print_privacy,
584: modify => \&modify_privacy,
1.120 raeburn 585: },
1.141 raeburn 586: 'usersessions' =>
1.145 raeburn 587: {text => 'User session hosting/offloading',
1.137 raeburn 588: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 589: header => [{col1 => 'Domain server',
590: col2 => 'Servers to offload sessions to when busy'},
591: {col1 => 'Hosting of users from other domains',
1.137 raeburn 592: col2 => 'Rules'},
593: {col1 => "Hosting domain's own users elsewhere",
594: col2 => 'Rules'}],
1.230 raeburn 595: print => \&print_usersessions,
596: modify => \&modify_usersessions,
1.137 raeburn 597: },
1.279 raeburn 598: 'loadbalancing' =>
1.185 raeburn 599: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 600: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 601: header => [{col1 => 'Balancers',
1.150 raeburn 602: col2 => 'Default destinations',
1.183 bisitz 603: col3 => 'User affiliation',
1.150 raeburn 604: col4 => 'Overrides'},
605: ],
1.230 raeburn 606: print => \&print_loadbalancing,
607: modify => \&modify_loadbalancing,
1.150 raeburn 608: },
1.425 raeburn 609: 'ltitools' =>
1.267 raeburn 610: {text => 'External Tools (LTI)',
1.296 raeburn 611: help => 'Domain_Configuration_LTI_Tools',
1.421 raeburn 612: header => [{col1 => 'Encryption of shared secrets',
613: col2 => 'Settings'},
614: {col1 => 'Rules for shared secrets',
615: col2 => 'Settings'},
616: {col1 => 'Providers',
617: col2 => 'Settings',}],
1.267 raeburn 618: print => \&print_ltitools,
619: modify => \&modify_ltitools,
620: },
1.372 raeburn 621: 'proctoring' =>
622: {text => 'Remote Proctoring Integration',
623: help => 'Domain_Configuration_Proctoring',
624: header => [{col1 => 'Name',
625: col2 => 'Configuration'}],
626: print => \&print_proctoring,
627: modify => \&modify_proctoring,
628: },
1.279 raeburn 629: 'ssl' =>
1.275 raeburn 630: {text => 'LON-CAPA Network (SSL)',
631: help => 'Domain_Configuration_Network_SSL',
632: header => [{col1 => 'Server',
633: col2 => 'Certificate Status'},
634: {col1 => 'Connections to other servers',
635: col2 => 'Rules'},
1.293 raeburn 636: {col1 => 'Connections from other servers',
637: col2 => 'Rules'},
1.275 raeburn 638: {col1 => "Replicating domain's published content",
639: col2 => 'Rules'}],
640: print => \&print_ssl,
641: modify => \&modify_ssl,
642: },
1.279 raeburn 643: 'trust' =>
644: {text => 'Trust Settings',
645: help => 'Domain_Configuration_Trust',
646: header => [{col1 => "Access to this domain's content by others",
647: col2 => 'Rules'},
648: {col1 => "Access to other domain's content by this domain",
649: col2 => 'Rules'},
650: {col1 => "Enrollment in this domain's courses by others",
651: col2 => 'Rules',},
652: {col1 => "Co-author roles in this domain for others",
653: col2 => 'Rules',},
654: {col1 => "Co-author roles for this domain's users elsewhere",
655: col2 => 'Rules',},
656: {col1 => "Domain roles in this domain assignable to others",
657: col2 => 'Rules'},
658: {col1 => "Course catalog for this domain displayed elsewhere",
659: col2 => 'Rules'},
660: {col1 => "Requests for creation of courses in this domain by others",
661: col2 => 'Rules'},
662: {col1 => "Users in other domains can send messages to this domain",
663: col2 => 'Rules'},],
664: print => \&print_trust,
665: modify => \&modify_trust,
666: },
1.425 raeburn 667: 'lti' =>
1.405 raeburn 668: {text => 'LTI Link Protection and LTI Consumers',
1.320 raeburn 669: help => 'Domain_Configuration_LTI_Provider',
1.405 raeburn 670: header => [{col1 => 'Encryption of shared secrets',
671: col2 => 'Settings'},
1.425 raeburn 672: {col1 => 'Rules for shared secrets',
1.405 raeburn 673: col2 => 'Settings'},
1.434 raeburn 674: {col1 => 'Link Protectors in Courses',
1.436 raeburn 675: col2 => 'Values'},
1.406 raeburn 676: {col1 => 'Link Protectors',
1.405 raeburn 677: col2 => 'Settings'},
678: {col1 => 'Consumers',
679: col2 => 'Settings'},],
1.320 raeburn 680: print => \&print_lti,
681: modify => \&modify_lti,
682: },
1.425 raeburn 683: 'ipaccess' =>
1.394 raeburn 684: {text => 'IP-based access control',
685: help => 'Domain_Configuration_IP_Access',
686: header => [{col1 => 'Setting',
687: col2 => 'Value'},],
688: print => \&print_ipaccess,
689: modify => \&modify_ipaccess,
690: },
1.436 raeburn 691: 'authordefaults' =>
1.429 raeburn 692: {text => 'Authoring Space defaults',
693: help => 'Domain_Configuration_Author_Defaults',
694: header => [{col1 => 'Defaults which can be overridden by Author',
695: col2 => 'Settings',},
696: {col1 => 'Defaults which can be overridden by a Dom. Coord.',
697: col2 => 'Settings',},],
698: print => \&print_authordefaults,
699: modify => \&modify_authordefaults,
700: },
1.3 raeburn 701: );
1.110 raeburn 702: if (keys(%servers) > 1) {
703: $prefs{'login'} = { text => 'Log-in page options',
704: help => 'Domain_Configuration_Login_Page',
705: header => [{col1 => 'Log-in Service',
706: col2 => 'Server Setting',},
707: {col1 => 'Log-in Page Items',
1.405 raeburn 708: col2 => 'Settings'},
1.168 raeburn 709: {col1 => 'Log-in Help',
1.256 raeburn 710: col2 => 'Value'},
711: {col1 => 'Custom HTML in document head',
1.386 raeburn 712: col2 => 'Value'},
713: {col1 => 'SSO',
714: col2 => 'Dual login: SSO and non-SSO options'},
715: ],
1.230 raeburn 716: print => \&print_login,
717: modify => \&modify_login,
1.110 raeburn 718: };
719: }
1.174 foxr 720:
1.6 raeburn 721: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 722: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 723: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 724: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 725: text=>"Settings to display/modify"});
1.9 raeburn 726: my $confname = $dom.'-domainconfig';
1.174 foxr 727:
1.3 raeburn 728: if ($phase eq 'process') {
1.212 raeburn 729: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
730: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 731: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 732: $r->rflush();
1.212 raeburn 733: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 734: }
1.30 raeburn 735: } elsif ($phase eq 'display') {
1.192 raeburn 736: my $js = &recaptcha_js().
1.236 raeburn 737: &toggle_display_js();
1.171 raeburn 738: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 739: my ($othertitle,$usertypes,$types) =
740: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 741: $js .= &lonbalance_targets_js($dom,$types,\%servers,
742: $domconfig{'loadbalancing'}).
1.170 raeburn 743: &new_spares_js().
744: &common_domprefs_js().
745: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 746: }
1.216 raeburn 747: if (grep(/^requestcourses$/,@actions)) {
748: my $javascript_validations;
749: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
750: $js .= <<END;
751: <script type="text/javascript">
752: $javascript_validations
753: </script>
754: $coursebrowserjs
755: END
1.394 raeburn 756: } elsif (grep(/^ipaccess$/,@actions)) {
757: $js .= &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
1.216 raeburn 758: }
1.305 raeburn 759: if (grep(/^selfcreation$/,@actions)) {
760: $js .= &selfcreate_javascript();
761: }
1.286 raeburn 762: if (grep(/^contacts$/,@actions)) {
763: $js .= &contacts_javascript();
764: }
1.346 raeburn 765: if (grep(/^scantron$/,@actions)) {
766: $js .= &scantron_javascript();
767: }
1.150 raeburn 768: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 769: } else {
1.180 raeburn 770: # check if domconfig user exists for the domain.
771: my $servadm = $r->dir_config('lonAdmEMail');
772: my ($configuserok,$author_ok,$switchserver) =
773: &config_check($dom,$confname,$servadm);
774: unless ($configuserok eq 'ok') {
1.181 raeburn 775: &Apache::lonconfigsettings::print_header($r,$phase,$context);
776: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 777: $confname).
1.181 raeburn 778: '<br />'
779: );
1.180 raeburn 780: if ($switchserver) {
1.181 raeburn 781: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
782: '<br />'.
783: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
784: '<br />'.
785: &mt('The "[_1]" user can be created automatically when a Domain Coordinator visits the web-based "Set domain configuration" screen, in a session hosted on the primary library server.',$confname).
786: '<br />'.
787: &mt('To do that now, use the following link: [_1]',$switchserver)
788: );
789: } else {
790: $r->print(&mt('To create that user from the command line run the ./UPDATE script found in the top level directory of the extracted LON-CAPA tarball.').
791: '<br />'.
792: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
793: );
1.180 raeburn 794: }
795: $r->print(&Apache::loncommon::end_page());
796: return OK;
797: }
1.21 raeburn 798: if (keys(%domconfig) == 0) {
799: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 800: my @ids=&Apache::lonnet::current_machine_ids();
801: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 802: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 803: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 804: my $custom_img_count = 0;
805: foreach my $img (@loginimages) {
806: if ($designhash{$dom.'.login.'.$img} ne '') {
807: $custom_img_count ++;
808: }
809: }
810: foreach my $role (@roles) {
811: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
812: $custom_img_count ++;
813: }
814: }
815: if ($custom_img_count > 0) {
1.94 raeburn 816: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 817: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 818: $r->print(
819: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
820: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
821: &mt("Thereafter, (with a Domain Coordinator role selected in the domain) you will be able to update settings when logged in to any server in the LON-CAPA network.").'<br />'.
822: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
823: if ($switch_server) {
1.30 raeburn 824: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 825: }
1.91 raeburn 826: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 827: return OK;
828: }
829: }
830: }
1.91 raeburn 831: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 832: }
833: return OK;
834: }
835:
836: sub process_changes {
1.205 raeburn 837: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 838: my %domconfig;
839: if (ref($values) eq 'HASH') {
840: %domconfig = %{$values};
841: }
1.3 raeburn 842: my $output;
843: if ($action eq 'login') {
1.205 raeburn 844: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 845: } elsif ($action eq 'rolecolors') {
1.9 raeburn 846: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 847: $lastactref,%domconfig);
1.3 raeburn 848: } elsif ($action eq 'quotas') {
1.216 raeburn 849: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 850: } elsif ($action eq 'autoenroll') {
1.205 raeburn 851: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 852: } elsif ($action eq 'autoupdate') {
853: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 854: } elsif ($action eq 'autocreate') {
855: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 856: } elsif ($action eq 'directorysrch') {
1.295 raeburn 857: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 858: } elsif ($action eq 'usercreation') {
1.28 raeburn 859: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 860: } elsif ($action eq 'selfcreation') {
1.305 raeburn 861: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 862: } elsif ($action eq 'usermodification') {
863: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 864: } elsif ($action eq 'contacts') {
1.205 raeburn 865: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 866: } elsif ($action eq 'defaults') {
1.212 raeburn 867: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 868: } elsif ($action eq 'scantron') {
1.205 raeburn 869: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 870: } elsif ($action eq 'coursecategories') {
1.239 raeburn 871: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 872: } elsif ($action eq 'serverstatuses') {
873: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 874: } elsif ($action eq 'requestcourses') {
1.216 raeburn 875: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 876: } elsif ($action eq 'requestauthor') {
1.216 raeburn 877: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 878: } elsif ($action eq 'helpsettings') {
1.285 raeburn 879: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 880: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 881: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 882: } elsif ($action eq 'selfenrollment') {
883: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 884: } elsif ($action eq 'usersessions') {
1.212 raeburn 885: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 886: } elsif ($action eq 'loadbalancing') {
887: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 888: } elsif ($action eq 'ltitools') {
889: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.372 raeburn 890: } elsif ($action eq 'proctoring') {
891: $output = &modify_proctoring($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 892: } elsif ($action eq 'ssl') {
893: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 894: } elsif ($action eq 'trust') {
895: $output = &modify_trust($dom,$lastactref,%domconfig);
1.320 raeburn 896: } elsif ($action eq 'lti') {
897: $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.357 raeburn 898: } elsif ($action eq 'privacy') {
1.427 raeburn 899: $output = &modify_privacy($dom,$lastactref,%domconfig);
1.354 raeburn 900: } elsif ($action eq 'passwords') {
901: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.373 raeburn 902: } elsif ($action eq 'wafproxy') {
903: $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
1.394 raeburn 904: } elsif ($action eq 'ipaccess') {
905: $output = &modify_ipaccess($dom,$lastactref,%domconfig);
1.429 raeburn 906: } elsif ($action eq 'authordefaults') {
907: $output = &modify_authordefaults($dom,$lastactref,%domconfig);
1.3 raeburn 908: }
909: return $output;
910: }
911:
912: sub print_config_box {
1.9 raeburn 913: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 914: my $rowtotal = 0;
1.49 raeburn 915: my $output;
916: if ($action eq 'coursecategories') {
917: $output = &coursecategories_javascript($settings);
1.236 raeburn 918: } elsif ($action eq 'defaults') {
919: $output = &defaults_javascript($settings);
1.354 raeburn 920: } elsif ($action eq 'passwords') {
1.405 raeburn 921: $output = &passwords_javascript($action);
1.282 raeburn 922: } elsif ($action eq 'helpsettings') {
923: my (%privs,%levelscurrent);
924: my %full=();
925: my %levels=(
926: course => {},
927: domain => {},
928: system => {},
929: );
930: my $context = 'domain';
931: my $crstype = 'Course';
932: my $formname = 'display';
933: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
934: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
935: $output =
1.425 raeburn 936: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
1.282 raeburn 937: \@templateroles);
1.334 raeburn 938: } elsif ($action eq 'ltitools') {
1.421 raeburn 939: $output .= &Apache::lonconfigsettings::ltitools_javascript($settings);
1.334 raeburn 940: } elsif ($action eq 'lti') {
1.421 raeburn 941: $output .= &passwords_javascript('ltisecrets')."\n".
1.405 raeburn 942: <i_javascript($dom,$settings);
1.372 raeburn 943: } elsif ($action eq 'proctoring') {
944: $output .= &proctoring_javascript($settings);
1.381 raeburn 945: } elsif ($action eq 'wafproxy') {
946: $output .= &wafproxy_javascript($dom);
1.385 raeburn 947: } elsif ($action eq 'autoupdate') {
948: $output .= &autoupdate_javascript();
1.399 raeburn 949: } elsif ($action eq 'autoenroll') {
950: $output .= &autoenroll_javascript();
1.386 raeburn 951: } elsif ($action eq 'login') {
952: $output .= &saml_javascript();
1.394 raeburn 953: } elsif ($action eq 'ipaccess') {
954: $output .= &ipaccess_javascript($settings);
1.429 raeburn 955: } elsif ($action eq 'authordefaults') {
956: $output .= &authordefaults_javascript();
1.91 raeburn 957: }
1.236 raeburn 958: $output .=
1.30 raeburn 959: '<table class="LC_nested_outer">
1.3 raeburn 960: <tr>
1.306 raeburn 961: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 962: &mt($item->{text}).' '.
963: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
964: '</tr>';
1.30 raeburn 965: $rowtotal ++;
1.110 raeburn 966: my $numheaders = 1;
967: if (ref($item->{'header'}) eq 'ARRAY') {
968: $numheaders = scalar(@{$item->{'header'}});
969: }
970: if ($numheaders > 1) {
1.64 raeburn 971: my $colspan = '';
1.145 raeburn 972: my $rightcolspan = '';
1.369 raeburn 973: my $leftnobr = '';
1.238 raeburn 974: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 975: ($action eq 'directorysrch') ||
1.386 raeburn 976: (($action eq 'login') && ($numheaders < 5))) {
1.64 raeburn 977: $colspan = ' colspan="2"';
978: }
1.145 raeburn 979: if ($action eq 'usersessions') {
980: $rightcolspan = ' colspan="3"';
981: }
1.369 raeburn 982: if ($action eq 'passwords') {
983: $leftnobr = ' LC_nobreak';
984: }
1.30 raeburn 985: $output .= '
1.3 raeburn 986: <tr>
987: <td>
988: <table class="LC_nested">
989: <tr class="LC_info_row">
1.369 raeburn 990: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 991: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 992: </tr>';
1.69 raeburn 993: $rowtotal ++;
1.230 raeburn 994: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 995: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 996: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 997: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
1.421 raeburn 998: ($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'wafproxy') ||
1.429 raeburn 999: ($action eq 'lti') || ($action eq 'ltitools') || ($action eq 'authordefaults')) {
1.230 raeburn 1000: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.354 raeburn 1001: } elsif ($action eq 'passwords') {
1002: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 1003: } elsif ($action eq 'coursecategories') {
1.230 raeburn 1004: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.346 raeburn 1005: } elsif ($action eq 'scantron') {
1006: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 1007: } elsif ($action eq 'login') {
1.386 raeburn 1008: if ($numheaders == 5) {
1.168 raeburn 1009: $colspan = ' colspan="2"';
1010: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
1011: } else {
1012: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
1013: }
1.230 raeburn 1014: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 1015: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 1016: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1017: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 1018: }
1.30 raeburn 1019: $output .= '
1.6 raeburn 1020: </table>
1021: </td>
1022: </tr>
1023: <tr>
1024: <td>
1025: <table class="LC_nested">
1026: <tr class="LC_info_row">
1.230 raeburn 1027: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 1028: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 1029: </tr>';
1030: $rowtotal ++;
1.230 raeburn 1031: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
1032: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 1033: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.409 raeburn 1034: ($action eq 'trust') || ($action eq 'contacts') || ($action eq 'defaults') ||
1.421 raeburn 1035: ($action eq 'privacy') || ($action eq 'passwords') || ($action eq 'lti') ||
1.443 raeburn 1036: ($action eq 'ltitools') || ($action eq 'usermodification')) {
1.238 raeburn 1037: if ($action eq 'coursecategories') {
1038: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
1039: $colspan = ' colspan="2"';
1.279 raeburn 1040: } elsif ($action eq 'trust') {
1041: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.354 raeburn 1042: } elsif ($action eq 'passwords') {
1043: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.434 raeburn 1044: } elsif ($action eq 'lti') {
1045: $output .= $item->{'print'}->('upper',$dom,$settings,\$rowtotal).'
1046: </table>
1047: </td>
1048: </tr>
1049: <tr>
1050: <td>
1051: <table class="LC_nested">
1052: <tr class="LC_info_row">
1053: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1054: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1055: </tr>'."\n".
1056: $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
1.238 raeburn 1057: } else {
1058: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
1059: }
1.279 raeburn 1060: if ($action eq 'trust') {
1061: $output .= '
1062: </table>
1063: </td>
1064: </tr>';
1065: my @trusthdrs = qw(2 3 4 5 6 7);
1066: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
1067: for (my $i=0; $i<@trusthdrs; $i++) {
1068: $output .= '
1069: <tr>
1070: <td>
1071: <table class="LC_nested">
1072: <tr class="LC_info_row">
1073: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
1074: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
1075: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
1076: </table>
1077: </td>
1078: </tr>';
1079: }
1080: $output .= '
1081: <tr>
1082: <td>
1083: <table class="LC_nested">
1084: <tr class="LC_info_row">
1085: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
1086: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
1087: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1088: } else {
1.434 raeburn 1089: my $hdridx = 2;
1090: if ($action eq 'lti') {
1091: $hdridx = 3;
1092: }
1.279 raeburn 1093: $output .= '
1.63 raeburn 1094: </table>
1095: </td>
1096: </tr>
1097: <tr>
1098: <td>
1099: <table class="LC_nested">
1100: <tr class="LC_info_row">
1.434 raeburn 1101: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col1'}).'</td>
1102: <td class="LC_right_item">'.&mt($item->{'header'}->[$hdridx]->{'col2'}).'</td>
1.238 raeburn 1103: </tr>'."\n";
1.279 raeburn 1104: if ($action eq 'coursecategories') {
1105: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.405 raeburn 1106: } elsif (($action eq 'contacts') || ($action eq 'privacy') ||
1107: ($action eq 'passwords') || ($action eq 'lti')) {
1.354 raeburn 1108: if ($action eq 'passwords') {
1109: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
1110: } else {
1111: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
1112: }
1.434 raeburn 1113: $hdridx ++;
1.354 raeburn 1114: $output .= '
1.340 raeburn 1115: </tr>
1116: </table>
1117: </td>
1118: </tr>
1119: <tr>
1120: <td>
1121: <table class="LC_nested">
1122: <tr class="LC_info_row">
1.434 raeburn 1123: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col1'}).'</td>
1124: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col2'}).'</td></tr>'."\n";
1.354 raeburn 1125: if ($action eq 'passwords') {
1126: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
1127: } else {
1128: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1129: }
1130: $output .= '
1.340 raeburn 1131: </table>
1132: </td>
1133: </tr>
1134: <tr>';
1.279 raeburn 1135: } else {
1136: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1137: }
1.238 raeburn 1138: }
1.63 raeburn 1139: $rowtotal ++;
1.443 raeburn 1140: } elsif (($action eq 'coursedefaults') || ($action eq 'authordefaults') ||
1.409 raeburn 1141: ($action eq 'directorysrch') || ($action eq 'helpsettings') ||
1.443 raeburn 1142: ($action eq 'wafproxy')) {
1.230 raeburn 1143: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.346 raeburn 1144: } elsif ($action eq 'scantron') {
1145: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.293 raeburn 1146: } elsif ($action eq 'ssl') {
1147: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
1148: </table>
1149: </td>
1150: </tr>
1151: <tr>
1152: <td>
1153: <table class="LC_nested">
1154: <tr class="LC_info_row">
1155: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1156: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1157: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
1158: </table>
1159: </td>
1160: </tr>
1161: <tr>
1162: <td>
1163: <table class="LC_nested">
1164: <tr class="LC_info_row">
1165: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1166: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
1167: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 1168: } elsif ($action eq 'login') {
1.386 raeburn 1169: if ($numheaders == 5) {
1.168 raeburn 1170: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
1171: </table>
1172: </td>
1173: </tr>
1174: <tr>
1175: <td>
1176: <table class="LC_nested">
1177: <tr class="LC_info_row">
1178: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 1179: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 1180: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1181: $rowtotal ++;
1182: } else {
1183: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1184: }
1.256 raeburn 1185: $output .= '
1186: </table>
1187: </td>
1188: </tr>
1189: <tr>
1190: <td>
1191: <table class="LC_nested">
1192: <tr class="LC_info_row">';
1.386 raeburn 1193: if ($numheaders == 5) {
1.256 raeburn 1194: $output .= '
1195: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1196: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1197: </tr>';
1198: } else {
1199: $output .= '
1200: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1201: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1202: </tr>';
1203: }
1204: $rowtotal ++;
1.386 raeburn 1205: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
1206: </table>
1207: </td>
1208: </tr>
1209: <tr>
1210: <td>
1211: <table class="LC_nested">
1212: <tr class="LC_info_row">';
1213: if ($numheaders == 5) {
1214: $output .= '
1215: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1216: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1217: </tr>';
1218: } else {
1219: $output .= '
1220: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1221: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1222: </tr>';
1223: }
1224: $rowtotal ++;
1225: $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 1226: } elsif ($action eq 'requestcourses') {
1.247 raeburn 1227: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1228: $rowtotal ++;
1229: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 1230: </table>
1231: </td>
1232: </tr>
1233: <tr>
1234: <td>
1235: <table class="LC_nested">
1236: <tr class="LC_info_row">
1237: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1238: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 1239: &textbookcourses_javascript($settings).
1240: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
1241: </table>
1242: </td>
1243: </tr>
1244: <tr>
1245: <td>
1246: <table class="LC_nested">
1247: <tr class="LC_info_row">
1248: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1249: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1250: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 1251: </table>
1252: </td>
1253: </tr>
1254: <tr>
1255: <td>
1256: <table class="LC_nested">
1257: <tr class="LC_info_row">
1.306 raeburn 1258: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1259: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 1260: </tr>'.
1261: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 1262: } elsif ($action eq 'requestauthor') {
1263: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 1264: $rowtotal ++;
1.122 jms 1265: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1266: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1267: </table>
1268: </td>
1269: </tr>
1270: <tr>
1271: <td>
1272: <table class="LC_nested">
1273: <tr class="LC_info_row">
1.306 raeburn 1274: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69 raeburn 1275: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306 raeburn 1276: <td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1277: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1278: </tr>'.
1.30 raeburn 1279: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1280: </table>
1281: </td>
1282: </tr>
1283: <tr>
1284: <td>
1285: <table class="LC_nested">
1286: <tr class="LC_info_row">
1.59 bisitz 1287: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1288: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1289: </tr>'.
1.30 raeburn 1290: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1291: $rowtotal += 2;
1.6 raeburn 1292: }
1.3 raeburn 1293: } else {
1.30 raeburn 1294: $output .= '
1.3 raeburn 1295: <tr>
1296: <td>
1297: <table class="LC_nested">
1.30 raeburn 1298: <tr class="LC_info_row">';
1.277 raeburn 1299: if ($action eq 'login') {
1.30 raeburn 1300: $output .= '
1.59 bisitz 1301: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1302: } elsif ($action eq 'serverstatuses') {
1303: $output .= '
1.306 raeburn 1304: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69 raeburn 1305: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1306:
1.6 raeburn 1307: } else {
1.30 raeburn 1308: $output .= '
1.306 raeburn 1309: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1310: }
1.72 raeburn 1311: if (defined($item->{'header'}->[0]->{'col3'})) {
1.306 raeburn 1312: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72 raeburn 1313: &mt($item->{'header'}->[0]->{'col2'});
1314: if ($action eq 'serverstatuses') {
1315: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1316: }
1.69 raeburn 1317: } else {
1.306 raeburn 1318: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1319: &mt($item->{'header'}->[0]->{'col2'});
1320: }
1321: $output .= '</td>';
1322: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1323: if (defined($item->{'header'}->[0]->{'col4'})) {
1.306 raeburn 1324: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150 raeburn 1325: &mt($item->{'header'}->[0]->{'col3'});
1326: } else {
1.306 raeburn 1327: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1328: &mt($item->{'header'}->[0]->{'col3'});
1329: }
1.69 raeburn 1330: if ($action eq 'serverstatuses') {
1331: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1332: }
1333: $output .= '</td>';
1.6 raeburn 1334: }
1.150 raeburn 1335: if ($item->{'header'}->[0]->{'col4'}) {
1.306 raeburn 1336: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1337: &mt($item->{'header'}->[0]->{'col4'});
1338: }
1.69 raeburn 1339: $output .= '</tr>';
1.48 raeburn 1340: $rowtotal ++;
1.168 raeburn 1341: if ($action eq 'quotas') {
1.86 raeburn 1342: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1343: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1344: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.421 raeburn 1345: ($action eq 'proctoring') || ($action eq 'ipaccess')) {
1.230 raeburn 1346: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1347: }
1.3 raeburn 1348: }
1.30 raeburn 1349: $output .= '
1.3 raeburn 1350: </table>
1351: </td>
1352: </tr>
1.30 raeburn 1353: </table><br />';
1354: return ($output,$rowtotal);
1.1 raeburn 1355: }
1356:
1.3 raeburn 1357: sub print_login {
1.168 raeburn 1358: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.386 raeburn 1359: my ($css_class,$datatable,$switchserver,%lt);
1.6 raeburn 1360: my %choices = &login_choices();
1.386 raeburn 1361: if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
1362: %lt = &login_file_options();
1363: $switchserver = &check_switchserver($dom,$confname);
1364: }
1.168 raeburn 1365: if ($caller eq 'service') {
1.149 raeburn 1366: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1367: my $choice = $choices{'disallowlogin'};
1368: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1369: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306 raeburn 1370: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1371: '<th>'.$choices{'server'}.'</th>'.
1372: '<th>'.$choices{'serverpath'}.'</th>'.
1373: '<th>'.$choices{'custompath'}.'</th>'.
1374: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1375: my %disallowed;
1376: if (ref($settings) eq 'HASH') {
1377: if (ref($settings->{'loginvia'}) eq 'HASH') {
1378: %disallowed = %{$settings->{'loginvia'}};
1379: }
1380: }
1381: foreach my $lonhost (sort(keys(%servers))) {
1382: my $direct = 'selected="selected"';
1.128 raeburn 1383: if (ref($disallowed{$lonhost}) eq 'HASH') {
1384: if ($disallowed{$lonhost}{'server'} ne '') {
1385: $direct = '';
1386: }
1.110 raeburn 1387: }
1.115 raeburn 1388: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1389: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1390: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1391: '</option>';
1.184 raeburn 1392: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1393: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1394: my $selected = '';
1.128 raeburn 1395: if (ref($disallowed{$lonhost}) eq 'HASH') {
1396: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1397: $selected = 'selected="selected"';
1398: }
1.110 raeburn 1399: }
1400: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1401: $servers{$hostid}.'</option>';
1402: }
1.128 raeburn 1403: $datatable .= '</select></td>'.
1404: '<td><select name="'.$lonhost.'_serverpath">';
1405: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1406: my $pathname = $path;
1407: if ($path eq 'custom') {
1408: $pathname = &mt('Custom Path').' ->';
1409: }
1410: my $selected = '';
1411: if (ref($disallowed{$lonhost}) eq 'HASH') {
1412: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1413: $selected = 'selected="selected"';
1414: }
1415: } elsif ($path eq '') {
1416: $selected = 'selected="selected"';
1417: }
1418: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1419: }
1420: $datatable .= '</select></td>';
1421: my ($custom,$exempt);
1422: if (ref($disallowed{$lonhost}) eq 'HASH') {
1423: $custom = $disallowed{$lonhost}{'custompath'};
1424: $exempt = $disallowed{$lonhost}{'exempt'};
1425: }
1426: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1427: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1428: '</tr>';
1.110 raeburn 1429: }
1430: $datatable .= '</table></td></tr>';
1431: return $datatable;
1.168 raeburn 1432: } elsif ($caller eq 'page') {
1433: my %defaultchecked = (
1434: 'coursecatalog' => 'on',
1.188 raeburn 1435: 'helpdesk' => 'on',
1.168 raeburn 1436: 'adminmail' => 'off',
1437: 'newuser' => 'off',
1438: );
1.188 raeburn 1439: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1440: my (%checkedon,%checkedoff);
1.42 raeburn 1441: foreach my $item (@toggles) {
1.168 raeburn 1442: if ($defaultchecked{$item} eq 'on') {
1443: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1444: $checkedoff{$item} = ' ';
1.168 raeburn 1445: } elsif ($defaultchecked{$item} eq 'off') {
1446: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1447: $checkedon{$item} = ' ';
1448: }
1.1 raeburn 1449: }
1.168 raeburn 1450: my @images = ('img','logo','domlogo','login');
1.402 raeburn 1451: my @alttext = ('img','logo','domlogo');
1.168 raeburn 1452: my @logintext = ('textcol','bgcol');
1453: my @bgs = ('pgbg','mainbg','sidebg');
1454: my @links = ('link','alink','vlink');
1455: my %designhash = &Apache::loncommon::get_domainconf($dom);
1456: my %defaultdesign = %Apache::loncommon::defaultdesign;
1457: my (%is_custom,%designs);
1458: my %defaults = (
1459: font => $defaultdesign{'login.font'},
1460: );
1.6 raeburn 1461: foreach my $item (@images) {
1.168 raeburn 1462: $defaults{$item} = $defaultdesign{'login.'.$item};
1463: $defaults{'showlogo'}{$item} = 1;
1464: }
1465: foreach my $item (@bgs) {
1466: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1467: }
1.41 raeburn 1468: foreach my $item (@logintext) {
1.168 raeburn 1469: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1470: }
1.168 raeburn 1471: foreach my $item (@links) {
1472: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1473: }
1.168 raeburn 1474: if (ref($settings) eq 'HASH') {
1475: foreach my $item (@toggles) {
1476: if ($settings->{$item} eq '1') {
1477: $checkedon{$item} = ' checked="checked" ';
1478: $checkedoff{$item} = ' ';
1479: } elsif ($settings->{$item} eq '0') {
1480: $checkedoff{$item} = ' checked="checked" ';
1481: $checkedon{$item} = ' ';
1482: }
1483: }
1484: foreach my $item (@images) {
1485: if (defined($settings->{$item})) {
1486: $designs{$item} = $settings->{$item};
1487: $is_custom{$item} = 1;
1488: }
1489: if (defined($settings->{'showlogo'}{$item})) {
1490: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1491: }
1492: }
1.402 raeburn 1493: foreach my $item (@alttext) {
1494: if (ref($settings->{'alttext'}) eq 'HASH') {
1495: if ($settings->{'alttext'}->{$item} ne '') {
1496: $designs{'alttext'}{$item} = $settings->{'alttext'}{$item};
1497: }
1498: }
1499: }
1.168 raeburn 1500: foreach my $item (@logintext) {
1501: if ($settings->{$item} ne '') {
1502: $designs{'logintext'}{$item} = $settings->{$item};
1503: $is_custom{$item} = 1;
1504: }
1505: }
1506: if ($settings->{'font'} ne '') {
1507: $designs{'font'} = $settings->{'font'};
1508: $is_custom{'font'} = 1;
1509: }
1510: foreach my $item (@bgs) {
1511: if ($settings->{$item} ne '') {
1512: $designs{'bgs'}{$item} = $settings->{$item};
1513: $is_custom{$item} = 1;
1514: }
1515: }
1516: foreach my $item (@links) {
1517: if ($settings->{$item} ne '') {
1518: $designs{'links'}{$item} = $settings->{$item};
1519: $is_custom{$item} = 1;
1520: }
1521: }
1522: } else {
1523: if ($designhash{$dom.'.login.font'} ne '') {
1524: $designs{'font'} = $designhash{$dom.'.login.font'};
1525: $is_custom{'font'} = 1;
1526: }
1527: foreach my $item (@images) {
1528: if ($designhash{$dom.'.login.'.$item} ne '') {
1529: $designs{$item} = $designhash{$dom.'.login.'.$item};
1530: $is_custom{$item} = 1;
1531: }
1532: }
1533: foreach my $item (@bgs) {
1534: if ($designhash{$dom.'.login.'.$item} ne '') {
1535: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1536: $is_custom{$item} = 1;
1537: }
1.6 raeburn 1538: }
1.168 raeburn 1539: foreach my $item (@links) {
1540: if ($designhash{$dom.'.login.'.$item} ne '') {
1541: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1542: $is_custom{$item} = 1;
1543: }
1.6 raeburn 1544: }
1545: }
1.168 raeburn 1546: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1547: logo => 'Institution Logo',
1548: domlogo => 'Domain Logo',
1549: login => 'Login box');
1550: my $itemcount = 1;
1551: foreach my $item (@toggles) {
1552: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1553: $datatable .=
1554: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1555: '</td><td>'.
1556: '<span class="LC_nobreak"><label><input type="radio" name="'.
1557: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1558: '</label> <label><input type="radio" name="'.$item.'"'.
1559: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1560: '</tr>';
1561: $itemcount ++;
1.6 raeburn 1562: }
1.168 raeburn 1563: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1564: $datatable .= '</tr></table></td></tr>';
1565: } elsif ($caller eq 'help') {
1.386 raeburn 1566: my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1.168 raeburn 1567: my $itemcount = 1;
1568: $defaulturl = '/adm/loginproblems.html';
1569: $defaulttype = 'default';
1570: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1571: my @currlangs;
1572: if (ref($settings) eq 'HASH') {
1573: if (ref($settings->{'helpurl'}) eq 'HASH') {
1574: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1575: next if ($settings->{'helpurl'}{$key} eq '');
1576: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1577: $type{$key} = 'custom';
1578: unless ($key eq 'nolang') {
1579: push(@currlangs,$key);
1580: }
1581: }
1582: } elsif ($settings->{'helpurl'} ne '') {
1583: $type{'nolang'} = 'custom';
1584: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1585: }
1586: }
1.168 raeburn 1587: foreach my $lang ('nolang',sort(@currlangs)) {
1588: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1589: $datatable .= '<tr'.$css_class.'>';
1590: if ($url{$lang} eq '') {
1591: $url{$lang} = $defaulturl;
1592: }
1593: if ($type{$lang} eq '') {
1594: $type{$lang} = $defaulttype;
1595: }
1596: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1597: if ($lang eq 'nolang') {
1598: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1599: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1600: } else {
1601: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1602: $langchoices{$lang},
1603: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1604: }
1605: $datatable .= '</span></td>'."\n".
1606: '<td class="LC_left_item">';
1607: if ($type{$lang} eq 'custom') {
1608: $datatable .= '<span class="LC_nobreak"><label>'.
1609: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1610: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1611: } else {
1612: $datatable .= $lt{'upl'};
1613: }
1614: $datatable .='<br />';
1615: if ($switchserver) {
1616: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1617: } else {
1618: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1619: }
1.168 raeburn 1620: $datatable .= '</td></tr>';
1621: $itemcount ++;
1.6 raeburn 1622: }
1.168 raeburn 1623: my @addlangs;
1624: foreach my $lang (sort(keys(%langchoices))) {
1625: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1626: push(@addlangs,$lang);
1627: }
1628: if (@addlangs > 0) {
1629: my %toadd;
1630: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1631: $toadd{''} = &mt('Select');
1632: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1633: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1634: &mt('Add log-in help page for a specific language:').' '.
1635: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1636: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1637: if ($switchserver) {
1638: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1639: } else {
1640: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1641: }
1.168 raeburn 1642: $datatable .= '</td></tr>';
1.169 raeburn 1643: $itemcount ++;
1.6 raeburn 1644: }
1.169 raeburn 1645: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1646: } elsif ($caller eq 'headtag') {
1647: my %domservers = &Apache::lonnet::get_servers($dom);
1648: my $choice = $choices{'headtag'};
1649: $css_class = ' class="LC_odd_row"';
1650: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306 raeburn 1651: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256 raeburn 1652: '<th>'.$choices{'current'}.'</th>'.
1653: '<th>'.$choices{'action'}.'</th>'.
1654: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1655: my (%currurls,%currexempt);
1656: if (ref($settings) eq 'HASH') {
1657: if (ref($settings->{'headtag'}) eq 'HASH') {
1658: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1659: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1660: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1661: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1662: }
1663: }
1664: }
1665: }
1666: foreach my $lonhost (sort(keys(%domservers))) {
1667: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1668: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1669: if ($currurls{$lonhost}) {
1670: $datatable .= '<td class="LC_right_item"><a href="'.
1671: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1672: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1673: '">'.$lt{'curr'}.'</a></td>'.
1674: '<td><span class="LC_nobreak"><label>'.
1675: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1676: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1677: } else {
1678: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1679: }
1680: $datatable .='<br />';
1681: if ($switchserver) {
1682: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1683: } else {
1684: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1685: }
1.330 raeburn 1686: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256 raeburn 1687: }
1688: $datatable .= '</table></td></tr>';
1.386 raeburn 1689: } elsif ($caller eq 'saml') {
1690: my %domservers = &Apache::lonnet::get_servers($dom);
1691: $datatable .= '<tr><td colspan="3" style="text-align: left">'.
1692: '<table><tr><th>'.$choices{'hostid'}.'</th>'.
1693: '<th>'.$choices{'samllanding'}.'</th>'.
1694: '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
1.412 raeburn 1695: my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso,%styleon,%styleoff);
1.386 raeburn 1696: foreach my $lonhost (keys(%domservers)) {
1697: $samlurl{$lonhost} = '/adm/sso';
1698: $styleon{$lonhost} = 'display:none';
1699: $styleoff{$lonhost} = '';
1700: }
1.411 raeburn 1701: if ((ref($settings) eq 'HASH') && (ref($settings->{'saml'}) eq 'HASH')) {
1.386 raeburn 1702: foreach my $lonhost (keys(%{$settings->{'saml'}})) {
1703: if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
1704: $saml{$lonhost} = 1;
1705: $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
1706: $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
1707: $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
1708: $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
1709: $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
1.412 raeburn 1710: $samlwindow{$lonhost} = $settings->{'saml'}{$lonhost}{'window'};
1.386 raeburn 1711: $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
1712: $styleon{$lonhost} = '';
1713: $styleoff{$lonhost} = 'display:none';
1714: } else {
1715: $styleon{$lonhost} = 'display:none';
1716: $styleoff{$lonhost} = '';
1717: }
1718: }
1719: }
1720: my $itemcount = 1;
1721: foreach my $lonhost (sort(keys(%domservers))) {
1722: my $samlon = ' ';
1723: my $samloff = ' checked="checked" ';
1724: if ($saml{$lonhost}) {
1725: $samlon = $samloff;
1726: $samloff = ' ';
1727: }
1.412 raeburn 1728: my $samlwinon = '';
1729: my $samlwinoff = ' checked="checked"';
1730: if ($samlwindow{$lonhost}) {
1731: $samlwinon = $samlwinoff;
1732: $samlwinoff = '';
1733: }
1.386 raeburn 1734: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1735: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
1736: '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
1737: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
1738: &mt('No').'</label>'.(' 'x2).
1739: '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
1740: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
1741: &mt('Yes').'</label></span></td>'.
1742: '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
1.412 raeburn 1743: '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th></tr>'.
1.386 raeburn 1744: '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
1.412 raeburn 1745: '<th>'.&mt('Alt Text').'</th></tr>'.
1746: '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="20" value="'.
1.386 raeburn 1747: $samltext{$lonhost}.'" /></td><td>';
1748: if ($samlimg{$lonhost}) {
1749: $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
1750: '<span class="LC_nobreak"><label>'.
1751: '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
1752: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1753: } else {
1754: $datatable .= $lt{'upl'};
1755: }
1756: $datatable .='<br />';
1757: if ($switchserver) {
1758: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1759: } else {
1760: $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
1761: }
1762: $datatable .= '</td>'.
1.412 raeburn 1763: '<td><input type="text" name="saml_alt_'.$lonhost.'" size="25" '.
1764: 'value="'.$samlalt{$lonhost}.'" /></td></tr></table><br />'.
1765: '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th><th align="center">'.
1766: '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
1767: '<tr><th>'.&mt('URL').'</th><th>'.&mt('Tool Tip').'</th>'.
1768: '<th>'.&mt('Pop-up if iframe').'</th><th>'.&mt('Text').'</th></tr>'.
1769: '<tr'.$css_class.'>'.
1770: '<td><input type="text" name="saml_url_'.$lonhost.'" size="30" '.
1.386 raeburn 1771: 'value="'.$samlurl{$lonhost}.'" /></td>'.
1.412 raeburn 1772: '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="20">'.
1.386 raeburn 1773: $samltitle{$lonhost}.'</textarea></td>'.
1.412 raeburn 1774: '<td><label><input type="radio" name="saml_window_'.$lonhost.'" value=""'.$samlwinoff.'>'.
1775: &mt('No').'</label>'.(' 'x2).'<label><input type="radio" '.
1776: 'name="saml_window_'.$lonhost.'" value="1"'.$samlwinon.'>'.&mt('Yes').'</label></td>'.
1777: '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="12" '.
1.386 raeburn 1778: 'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
1779: '</table></td>'.
1780: '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%"> </td></tr>';
1781: $itemcount ++;
1782: }
1783: $datatable .= '</table></td></tr>';
1.1 raeburn 1784: }
1.6 raeburn 1785: return $datatable;
1786: }
1787:
1788: sub login_choices {
1789: my %choices =
1790: &Apache::lonlocal::texthash (
1.116 bisitz 1791: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1792: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1793: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1794: disallowlogin => "Login page requests redirected",
1795: hostid => "Server",
1.128 raeburn 1796: server => "Redirect to:",
1797: serverpath => "Path",
1798: custompath => "Custom",
1799: exempt => "Exempt IP(s)",
1.110 raeburn 1800: directlogin => "No redirect",
1801: newuser => "Link to create a user account",
1802: img => "Header",
1803: logo => "Main Logo",
1804: domlogo => "Domain Logo",
1805: login => "Log-in Header",
1806: textcol => "Text color",
1807: bgcol => "Box color",
1808: bgs => "Background colors",
1809: links => "Link colors",
1810: font => "Font color",
1811: pgbg => "Header",
1812: mainbg => "Page",
1813: sidebg => "Login box",
1814: link => "Link",
1815: alink => "Active link",
1816: vlink => "Visited link",
1.256 raeburn 1817: headtag => "Custom markup",
1818: action => "Action",
1819: current => "Current",
1.386 raeburn 1820: samllanding => "Dual login?",
1821: samloptions => "Options",
1.402 raeburn 1822: alttext => "Alt text",
1.6 raeburn 1823: );
1824: return %choices;
1825: }
1826:
1.386 raeburn 1827: sub login_file_options {
1828: return &Apache::lonlocal::texthash(
1829: del => 'Delete?',
1830: rep => 'Replace:',
1831: upl => 'Upload:',
1832: curr => 'View contents',
1833: default => 'Default',
1834: custom => 'Custom',
1835: none => 'None',
1836: );
1837: }
1838:
1.394 raeburn 1839: sub print_ipaccess {
1840: my ($dom,$settings,$rowtotal) = @_;
1841: my $css_class;
1842: my $itemcount = 0;
1843: my $datatable;
1844: my %ordered;
1845: if (ref($settings) eq 'HASH') {
1846: foreach my $item (keys(%{$settings})) {
1847: if (ref($settings->{$item}) eq 'HASH') {
1848: my $num = $settings->{$item}{'order'};
1849: if ($num eq '') {
1850: $num = scalar(keys(%{$settings}));
1851: }
1852: $ordered{$num} = $item;
1853: }
1854: }
1855: }
1856: my $maxnum = scalar(keys(%ordered));
1857: if (keys(%ordered)) {
1858: my @items = sort { $a <=> $b } keys(%ordered);
1859: for (my $i=0; $i<@items; $i++) {
1860: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1861: my $item = $ordered{$items[$i]};
1862: my ($name,$ipranges,%commblocks,%courses);
1863: if (ref($settings->{$item}) eq 'HASH') {
1864: $name = $settings->{$item}->{'name'};
1865: $ipranges = $settings->{$item}->{'ip'};
1866: if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
1867: %commblocks = %{$settings->{$item}->{'commblocks'}};
1868: }
1869: if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
1870: %courses = %{$settings->{$item}->{'courses'}};
1871: }
1872: }
1873: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
1874: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1875: .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
1876: for (my $k=0; $k<=$maxnum; $k++) {
1877: my $vpos = $k+1;
1878: my $selstr;
1879: if ($k == $i) {
1880: $selstr = ' selected="selected" ';
1881: }
1882: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1883: }
1884: $datatable .= '</select>'.(' 'x2).
1885: '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
1886: &mt('Delete?').'</label></span></td>'.
1887: '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
1888: &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
1889: '</td></tr>';
1890: $itemcount ++;
1891: }
1892: }
1893: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1894: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
1895: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1896: '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
1897: '<select name="ipaccess_pos_add"'.$chgstr.'>';
1898: for (my $k=0; $k<$maxnum+1; $k++) {
1899: my $vpos = $k+1;
1900: my $selstr;
1901: if ($k == $maxnum) {
1902: $selstr = ' selected="selected" ';
1903: }
1904: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1905: }
1906: $datatable .= '</select> '."\n".
1907: '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1908: '<td colspan="2">'.
1909: &ipaccess_options('add',$itemcount,$dom).
1910: '</td>'."\n".
1911: '</tr>'."\n";
1912: $$rowtotal ++;
1913: return $datatable;
1914: }
1915:
1916: sub ipaccess_options {
1917: my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
1918: my (%currblocks,%currcourses,$output);
1919: if (ref($blocksref) eq 'HASH') {
1920: %currblocks = %{$blocksref};
1921: }
1922: if (ref($coursesref) eq 'HASH') {
1923: %currcourses = %{$coursesref};
1924: }
1925: $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
1926: '<span class="LC_nobreak">'.&mt('Name').': '.
1927: '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
1928: '</span></fieldset>'.
1929: '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
1930: &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
1931: &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
1932: '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
1933: $ipranges.'</textarea></fieldset>'.
1934: '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
1935: &blocker_checkboxes($num,$blocksref).'</fieldset>'.
1936: '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
1937: '<table>';
1938: foreach my $cid (sort(keys(%currcourses))) {
1939: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1940: $output .= '<tr><td><span class="LC_nobreak">'.
1941: '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
1942: &mt('Delete?').' <span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
1943: ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
1944: }
1945: $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').': '.
1946: '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
1947: &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
1948: '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
1949: '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
1950: '</span></td></tr></table>'."\n".
1951: '</fieldset>';
1952: return $output;
1953: }
1954:
1955: sub blocker_checkboxes {
1956: my ($num,$blocks) = @_;
1957: my ($typeorder,$types) = &commblocktype_text();
1958: my $numinrow = 6;
1959: my $output = '<table>';
1960: for (my $i=0; $i<@{$typeorder}; $i++) {
1961: my $block = $typeorder->[$i];
1962: my $blockstatus;
1963: if (ref($blocks) eq 'HASH') {
1964: if ($blocks->{$block} eq 'on') {
1965: $blockstatus = 'checked="checked"';
1966: }
1967: }
1968: my $rem = $i%($numinrow);
1969: if ($rem == 0) {
1970: if ($i > 0) {
1971: $output .= '</tr>';
1972: }
1973: $output .= '<tr>';
1974: }
1975: if ($i == scalar(@{$typeorder})-1) {
1976: my $colsleft = $numinrow-$rem;
1977: if ($colsleft > 1) {
1978: $output .= '<td colspan="'.$colsleft.'">';
1979: } else {
1980: $output .= '<td>';
1981: }
1982: } else {
1983: $output .= '<td>';
1984: }
1985: my $item = 'ipaccess_block_'.$num;
1986: if ($blockstatus) {
1987: $blockstatus = ' '.$blockstatus;
1988: }
1989: $output .= '<span class="LC_nobreak"><label>'."\n".
1990: '<input type="checkbox" name="'.$item.'"'.
1991: $blockstatus.' value="'.$block.'"'.' />'.
1992: $types->{$block}.'</label></span>'."\n".
1993: '<br /></td>';
1994: }
1995: $output .= '</tr></table>';
1996: return $output;
1997: }
1998:
1999: sub commblocktype_text {
2000: my %types = &Apache::lonlocal::texthash(
2001: 'com' => 'Messaging',
2002: 'chat' => 'Chat Room',
2003: 'boards' => 'Discussion',
2004: 'port' => 'Portfolio',
2005: 'groups' => 'Groups',
2006: 'blogs' => 'Blogs',
2007: 'about' => 'User Information',
2008: 'printout' => 'Printouts',
2009: 'passwd' => 'Change Password',
2010: 'grades' => 'Gradebook',
1.397 raeburn 2011: 'search' => 'Course search',
2012: 'wishlist' => 'Stored links',
2013: 'annotate' => 'Annotations',
1.394 raeburn 2014: );
1.397 raeburn 2015: my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','annotate','passwd'];
1.394 raeburn 2016: return ($typeorder,\%types);
2017: }
2018:
1.6 raeburn 2019: sub print_rolecolors {
1.30 raeburn 2020: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 2021: my %choices = &color_font_choices();
2022: my @bgs = ('pgbg','tabbg','sidebg');
2023: my @links = ('link','alink','vlink');
2024: my @images = ('img');
2025: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 2026: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 2027: my %defaultdesign = %Apache::loncommon::defaultdesign;
2028: my (%is_custom,%designs);
1.200 raeburn 2029: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 2030: if (ref($settings) eq 'HASH') {
2031: if (ref($settings->{$role}) eq 'HASH') {
2032: if ($settings->{$role}->{'img'} ne '') {
2033: $designs{'img'} = $settings->{$role}->{'img'};
2034: $is_custom{'img'} = 1;
2035: }
2036: if ($settings->{$role}->{'font'} ne '') {
2037: $designs{'font'} = $settings->{$role}->{'font'};
2038: $is_custom{'font'} = 1;
2039: }
1.97 tempelho 2040: if ($settings->{$role}->{'fontmenu'} ne '') {
2041: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
2042: $is_custom{'fontmenu'} = 1;
2043: }
1.6 raeburn 2044: foreach my $item (@bgs) {
2045: if ($settings->{$role}->{$item} ne '') {
2046: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
2047: $is_custom{$item} = 1;
2048: }
2049: }
2050: foreach my $item (@links) {
2051: if ($settings->{$role}->{$item} ne '') {
2052: $designs{'links'}{$item} = $settings->{$role}->{$item};
2053: $is_custom{$item} = 1;
2054: }
2055: }
2056: }
2057: } else {
2058: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
2059: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
2060: $is_custom{'img'} = 1;
2061: }
1.97 tempelho 2062: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
2063: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
2064: $is_custom{'fontmenu'} = 1;
2065: }
1.6 raeburn 2066: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
2067: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
2068: $is_custom{'font'} = 1;
2069: }
2070: foreach my $item (@bgs) {
2071: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
2072: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
2073: $is_custom{$item} = 1;
2074:
2075: }
2076: }
2077: foreach my $item (@links) {
2078: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
2079: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
2080: $is_custom{$item} = 1;
2081: }
2082: }
2083: }
2084: my $itemcount = 1;
1.30 raeburn 2085: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 2086: $datatable .= '</tr></table></td></tr>';
2087: return $datatable;
2088: }
2089:
1.200 raeburn 2090: sub role_defaults {
2091: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 2092: my %defaults;
2093: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 2094: return %defaults;
2095: }
2096: my %defaultdesign = %Apache::loncommon::defaultdesign;
2097: if ($role eq 'login') {
2098: %defaults = (
2099: font => $defaultdesign{$role.'.font'},
2100: );
2101: if (ref($logintext) eq 'ARRAY') {
2102: foreach my $item (@{$logintext}) {
2103: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
2104: }
2105: }
2106: foreach my $item (@{$images}) {
2107: $defaults{'showlogo'}{$item} = 1;
2108: }
2109: } else {
2110: %defaults = (
2111: img => $defaultdesign{$role.'.img'},
2112: font => $defaultdesign{$role.'.font'},
2113: fontmenu => $defaultdesign{$role.'.fontmenu'},
2114: );
2115: }
2116: foreach my $item (@{$bgs}) {
2117: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
2118: }
2119: foreach my $item (@{$links}) {
2120: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
2121: }
2122: foreach my $item (@{$images}) {
2123: $defaults{$item} = $defaultdesign{$role.'.'.$item};
2124: }
2125: return %defaults;
2126: }
2127:
1.6 raeburn 2128: sub display_color_options {
1.9 raeburn 2129: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 2130: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 2131: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 2132: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 2133: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 2134: '<td>'.$choices->{'font'}.'</td>';
2135: if (!$is_custom->{'font'}) {
1.329 raeburn 2136: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 2137: } else {
2138: $datatable .= '<td> </td>';
2139: }
1.174 foxr 2140: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
2141:
1.8 raeburn 2142: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2143: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 2144: ' value="'.$current_color.'" /> '.
1.329 raeburn 2145: ' </span></td></tr>';
1.107 raeburn 2146: unless ($role eq 'login') {
2147: $datatable .= '<tr'.$css_class.'>'.
2148: '<td>'.$choices->{'fontmenu'}.'</td>';
2149: if (!$is_custom->{'fontmenu'}) {
1.329 raeburn 2150: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 2151: } else {
2152: $datatable .= '<td> </td>';
2153: }
1.202 raeburn 2154: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 2155: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 2156: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2157: '<input class="colorchooser" type="text" size="10" name="'
2158: .$role.'_fontmenu"'.
2159: ' value="'.$current_color.'" /> '.
1.329 raeburn 2160: ' </span></td></tr>';
1.97 tempelho 2161: }
1.9 raeburn 2162: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 2163: foreach my $img (@{$images}) {
1.18 albertel 2164: $itemcount ++;
1.6 raeburn 2165: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 2166: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 2167: '<td>'.$choices->{$img};
1.402 raeburn 2168: my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext);
1.70 raeburn 2169: if ($role eq 'login') {
2170: if ($img eq 'login') {
2171: $login_hdr_pick =
1.135 bisitz 2172: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 2173: $logincolors =
2174: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 2175: $designs,$defaults);
1.402 raeburn 2176: } else {
2177: if ($img ne 'domlogo') {
2178: $datatable.= &logo_display_options($img,$defaults,$designs);
2179: }
2180: if (ref($designs->{'alttext'}) eq 'HASH') {
2181: $alttext = $designs->{'alttext'}{$img};
2182: }
1.70 raeburn 2183: }
2184: }
2185: $datatable .= '</td>';
1.6 raeburn 2186: if ($designs->{$img} ne '') {
2187: $imgfile = $designs->{$img};
1.18 albertel 2188: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 2189: } else {
2190: $imgfile = $defaults->{$img};
2191: }
2192: if ($imgfile) {
1.9 raeburn 2193: my ($showfile,$fullsize);
2194: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 2195: my $urldir = $1;
2196: my $filename = $2;
2197: my @info = &Apache::lonnet::stat_file($designs->{$img});
2198: if (@info) {
2199: my $thumbfile = 'tn-'.$filename;
2200: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
2201: if (@thumb) {
2202: $showfile = $urldir.'/'.$thumbfile;
2203: } else {
2204: $showfile = $imgfile;
2205: }
2206: } else {
2207: $showfile = '';
2208: }
2209: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 2210: $showfile = $imgfile;
1.6 raeburn 2211: my $imgdir = $1;
2212: my $filename = $2;
1.159 raeburn 2213: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 2214: $showfile = "/$imgdir/tn-".$filename;
2215: } else {
1.159 raeburn 2216: my $input = $londocroot.$imgfile;
2217: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 2218: if (!-e $output) {
1.9 raeburn 2219: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 2220: my ($fullwidth,$fullheight) = &check_dimensions($input);
2221: if ($fullwidth ne '' && $fullheight ne '') {
2222: if ($fullwidth > $width && $fullheight > $height) {
2223: my $size = $width.'x'.$height;
1.316 raeburn 2224: my @args = ('convert','-sample',$size,$input,$output);
2225: system({$args[0]} @args);
1.159 raeburn 2226: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 2227: }
2228: }
1.6 raeburn 2229: }
2230: }
1.16 raeburn 2231: }
1.6 raeburn 2232: if ($showfile) {
1.40 raeburn 2233: if ($showfile =~ m{^/(adm|res)/}) {
2234: if ($showfile =~ m{^/res/}) {
2235: my $local_showfile =
2236: &Apache::lonnet::filelocation('',$showfile);
2237: &Apache::lonnet::repcopy($local_showfile);
2238: }
2239: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
2240: }
2241: if ($imgfile) {
2242: if ($imgfile =~ m{^/(adm|res)/}) {
2243: if ($imgfile =~ m{^/res/}) {
2244: my $local_imgfile =
2245: &Apache::lonnet::filelocation('',$imgfile);
2246: &Apache::lonnet::repcopy($local_imgfile);
2247: }
2248: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
2249: } else {
2250: $fullsize = $imgfile;
2251: }
2252: }
1.41 raeburn 2253: $datatable .= '<td>';
2254: if ($img eq 'login') {
1.135 bisitz 2255: $datatable .= $login_hdr_pick;
2256: }
1.41 raeburn 2257: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
2258: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 2259: } else {
1.201 raeburn 2260: $datatable .= '<td> </td><td class="LC_left_item">'.
2261: &mt('Upload:').'<br />';
1.6 raeburn 2262: }
2263: } else {
1.201 raeburn 2264: $datatable .= '<td> </td><td class="LC_left_item">'.
2265: &mt('Upload:').'<br />';
1.6 raeburn 2266: }
1.9 raeburn 2267: if ($switchserver) {
2268: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2269: } else {
1.135 bisitz 2270: if ($img ne 'login') { # suppress file selection for Log-in header
2271: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
2272: }
1.9 raeburn 2273: }
1.402 raeburn 2274: if (($role eq 'login') && ($img ne 'login')) {
2275: $datatable .= (' ' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'.
2276: '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'.
2277: '</label></span>';
2278: }
1.9 raeburn 2279: $datatable .= '</td></tr>';
1.6 raeburn 2280: }
2281: $itemcount ++;
2282: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2283: $datatable .= '<tr'.$css_class.'>'.
2284: '<td>'.$choices->{'bgs'}.'</td>';
2285: my $bgs_def;
2286: foreach my $item (@{$bgs}) {
2287: if (!$is_custom->{$item}) {
1.329 raeburn 2288: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span class="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 2289: }
2290: }
2291: if ($bgs_def) {
1.8 raeburn 2292: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 2293: } else {
2294: $datatable .= '<td> </td>';
2295: }
2296: $datatable .= '<td class="LC_right_item">'.
2297: '<table border="0"><tr>';
1.174 foxr 2298:
1.6 raeburn 2299: foreach my $item (@{$bgs}) {
1.306 raeburn 2300: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 2301: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 2302: if ($designs->{'bgs'}{$item}) {
1.174 foxr 2303: $datatable .= ' ';
1.6 raeburn 2304: }
1.174 foxr 2305: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 2306: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 2307: }
2308: $datatable .= '</tr></table></td></tr>';
2309: $itemcount ++;
2310: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2311: $datatable .= '<tr'.$css_class.'>'.
2312: '<td>'.$choices->{'links'}.'</td>';
2313: my $links_def;
2314: foreach my $item (@{$links}) {
2315: if (!$is_custom->{$item}) {
1.329 raeburn 2316: $links_def .= '<td>'.$choices->{$item}.'<br /><span class="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 2317: }
2318: }
2319: if ($links_def) {
1.8 raeburn 2320: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 2321: } else {
2322: $datatable .= '<td> </td>';
2323: }
2324: $datatable .= '<td class="LC_right_item">'.
2325: '<table border="0"><tr>';
2326: foreach my $item (@{$links}) {
1.234 raeburn 2327: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 2328: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 2329: if ($designs->{'links'}{$item}) {
1.174 foxr 2330: $datatable.=' ';
1.6 raeburn 2331: }
1.174 foxr 2332: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 2333: '" /></td>';
2334: }
1.30 raeburn 2335: $$rowtotal += $itemcount;
1.3 raeburn 2336: return $datatable;
2337: }
2338:
1.70 raeburn 2339: sub logo_display_options {
2340: my ($img,$defaults,$designs) = @_;
2341: my $checkedon;
2342: if (ref($defaults) eq 'HASH') {
2343: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2344: if ($defaults->{'showlogo'}{$img}) {
2345: $checkedon = 'checked="checked" ';
2346: }
2347: }
2348: }
2349: if (ref($designs) eq 'HASH') {
2350: if (ref($designs->{'showlogo'}) eq 'HASH') {
2351: if (defined($designs->{'showlogo'}{$img})) {
2352: if ($designs->{'showlogo'}{$img} == 0) {
2353: $checkedon = '';
2354: } elsif ($designs->{'showlogo'}{$img} == 1) {
2355: $checkedon = 'checked="checked" ';
2356: }
2357: }
2358: }
2359: }
2360: return '<br /><label> <input type="checkbox" name="'.
2361: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2362: &mt('show').'</label>'."\n";
2363: }
2364:
1.41 raeburn 2365: sub login_header_options {
1.135 bisitz 2366: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2367: my $output = '';
1.41 raeburn 2368: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 2369: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 2370: if (!$is_custom->{'textcol'}) {
2371: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2372: ' ';
2373: }
2374: if (!$is_custom->{'bgcol'}) {
2375: $output .= $choices->{'bgcol'}.': '.
2376: '<span id="css_'.$role.'_font" style="background-color: '.
2377: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2378: }
2379: $output .= '<br />';
2380: }
2381: $output .='<br />';
2382: return $output;
2383: }
2384:
2385: sub login_text_colors {
1.201 raeburn 2386: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 2387: my $color_menu = '<table border="0"><tr>';
2388: foreach my $item (@{$logintext}) {
1.306 raeburn 2389: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 2390: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2391: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2392: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 2393: }
2394: $color_menu .= '</tr></table><br />';
2395: return $color_menu;
2396: }
2397:
2398: sub image_changes {
2399: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2400: my $output;
1.135 bisitz 2401: if ($img eq 'login') {
1.331 raeburn 2402: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 2403: } elsif (!$is_custom) {
1.70 raeburn 2404: if ($img ne 'domlogo') {
1.331 raeburn 2405: $output = &mt('Default image:').'<br />';
1.41 raeburn 2406: } else {
1.331 raeburn 2407: $output = &mt('Default in use:').'<br />';
1.41 raeburn 2408: }
2409: }
1.331 raeburn 2410: if ($img ne 'login') {
1.135 bisitz 2411: if ($img_import) {
2412: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2413: }
2414: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2415: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2416: if ($is_custom) {
2417: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2418: '<input type="checkbox" name="'.
2419: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2420: '</label> '.&mt('Replace:').'</span><br />';
2421: } else {
1.306 raeburn 2422: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 2423: }
1.41 raeburn 2424: }
2425: return $output;
2426: }
2427:
1.3 raeburn 2428: sub print_quotas {
1.86 raeburn 2429: my ($dom,$settings,$rowtotal,$action) = @_;
2430: my $context;
2431: if ($action eq 'quotas') {
2432: $context = 'tools';
2433: } else {
2434: $context = $action;
2435: }
1.429 raeburn 2436: my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44 raeburn 2437: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2438: my $typecount = 0;
1.101 raeburn 2439: my ($css_class,%titles);
1.86 raeburn 2440: if ($context eq 'requestcourses') {
1.325 raeburn 2441: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 2442: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2443: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2444: %titles = &courserequest_titles();
1.163 raeburn 2445: } elsif ($context eq 'requestauthor') {
2446: @usertools = ('author');
2447: @options = ('norequest','approval','automatic');
1.210 raeburn 2448: %titles = &authorrequest_titles();
1.86 raeburn 2449: } else {
1.430 raeburn 2450: @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.101 raeburn 2451: %titles = &tool_titles();
1.86 raeburn 2452: }
1.26 raeburn 2453: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2454: foreach my $type (@{$types}) {
1.429 raeburn 2455: my $currdefquota;
1.163 raeburn 2456: unless (($context eq 'requestcourses') ||
2457: ($context eq 'requestauthor')) {
1.86 raeburn 2458: if (ref($settings) eq 'HASH') {
2459: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 2460: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2461: } else {
2462: $currdefquota = $settings->{$type};
2463: }
1.78 raeburn 2464: }
1.72 raeburn 2465: }
1.3 raeburn 2466: if (defined($usertypes->{$type})) {
2467: $typecount ++;
2468: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2469: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2470: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2471: '<td class="LC_left_item">';
1.101 raeburn 2472: if ($context eq 'requestcourses') {
2473: $datatable .= '<table><tr>';
2474: }
2475: my %cell;
1.72 raeburn 2476: foreach my $item (@usertools) {
1.101 raeburn 2477: if ($context eq 'requestcourses') {
2478: my ($curroption,$currlimit);
2479: if (ref($settings) eq 'HASH') {
2480: if (ref($settings->{$item}) eq 'HASH') {
2481: $curroption = $settings->{$item}->{$type};
2482: if ($curroption =~ /^autolimit=(\d*)$/) {
2483: $currlimit = $1;
2484: }
2485: }
2486: }
2487: if (!$curroption) {
2488: $curroption = 'norequest';
2489: }
2490: $datatable .= '<th>'.$titles{$item}.'</th>';
2491: foreach my $option (@options) {
2492: my $val = $option;
2493: if ($option eq 'norequest') {
2494: $val = 0;
2495: }
2496: if ($option eq 'validate') {
2497: my $canvalidate = 0;
2498: if (ref($validations{$item}) eq 'HASH') {
2499: if ($validations{$item}{$type}) {
2500: $canvalidate = 1;
2501: }
2502: }
2503: next if (!$canvalidate);
2504: }
2505: my $checked = '';
2506: if ($option eq $curroption) {
2507: $checked = ' checked="checked"';
2508: } elsif ($option eq 'autolimit') {
2509: if ($curroption =~ /^autolimit/) {
2510: $checked = ' checked="checked"';
2511: }
2512: }
2513: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2514: '<input type="radio" name="crsreq_'.$item.
2515: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2516: $titles{$option}.'</label>';
1.101 raeburn 2517: if ($option eq 'autolimit') {
1.127 raeburn 2518: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2519: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2520: 'value="'.$currlimit.'" />';
1.101 raeburn 2521: }
1.127 raeburn 2522: $cell{$item} .= '</span> ';
1.103 raeburn 2523: if ($option eq 'autolimit') {
1.127 raeburn 2524: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2525: }
1.101 raeburn 2526: }
1.163 raeburn 2527: } elsif ($context eq 'requestauthor') {
2528: my $curroption;
2529: if (ref($settings) eq 'HASH') {
2530: $curroption = $settings->{$type};
2531: }
2532: if (!$curroption) {
2533: $curroption = 'norequest';
2534: }
2535: foreach my $option (@options) {
2536: my $val = $option;
2537: if ($option eq 'norequest') {
2538: $val = 0;
2539: }
2540: my $checked = '';
2541: if ($option eq $curroption) {
2542: $checked = ' checked="checked"';
2543: }
2544: $datatable .= '<span class="LC_nobreak"><label>'.
2545: '<input type="radio" name="authorreq_'.$type.
2546: '" value="'.$val.'"'.$checked.' />'.
2547: $titles{$option}.'</label></span> ';
2548: }
1.101 raeburn 2549: } else {
2550: my $checked = 'checked="checked" ';
1.413 raeburn 2551: if ($item eq 'timezone') {
2552: $checked = '';
2553: }
1.101 raeburn 2554: if (ref($settings) eq 'HASH') {
2555: if (ref($settings->{$item}) eq 'HASH') {
1.413 raeburn 2556: if (!$settings->{$item}->{$type}) {
1.101 raeburn 2557: $checked = '';
2558: } elsif ($settings->{$item}->{$type} == 1) {
2559: $checked = 'checked="checked" ';
2560: }
1.78 raeburn 2561: }
1.72 raeburn 2562: }
1.101 raeburn 2563: $datatable .= '<span class="LC_nobreak"><label>'.
2564: '<input type="checkbox" name="'.$context.'_'.$item.
2565: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2566: '</label></span> ';
1.72 raeburn 2567: }
1.101 raeburn 2568: }
2569: if ($context eq 'requestcourses') {
2570: $datatable .= '</tr><tr>';
2571: foreach my $item (@usertools) {
1.106 raeburn 2572: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2573: }
2574: $datatable .= '</tr></table>';
1.72 raeburn 2575: }
1.86 raeburn 2576: $datatable .= '</td>';
1.163 raeburn 2577: unless (($context eq 'requestcourses') ||
2578: ($context eq 'requestauthor')) {
1.86 raeburn 2579: $datatable .=
1.197 raeburn 2580: '<td class="LC_right_item">'.
1.429 raeburn 2581: '<span class="LC_nobreak">'.
1.3 raeburn 2582: '<input type="text" name="quota_'.$type.
1.72 raeburn 2583: '" value="'.$currdefquota.
1.197 raeburn 2584: '" size="5" /></span></td>';
1.86 raeburn 2585: }
2586: $datatable .= '</tr>';
1.3 raeburn 2587: }
2588: }
2589: }
1.163 raeburn 2590: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2591: $defaultquota = '20';
2592: if (ref($settings) eq 'HASH') {
2593: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2594: $defaultquota = $settings->{'defaultquota'}->{'default'};
2595: } elsif (defined($settings->{'default'})) {
2596: $defaultquota = $settings->{'default'};
2597: }
1.3 raeburn 2598: }
2599: }
2600: $typecount ++;
2601: $css_class = $typecount%2?' class="LC_odd_row"':'';
2602: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2603: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2604: '<td class="LC_left_item">';
1.101 raeburn 2605: if ($context eq 'requestcourses') {
2606: $datatable .= '<table><tr>';
2607: }
2608: my %defcell;
1.72 raeburn 2609: foreach my $item (@usertools) {
1.101 raeburn 2610: if ($context eq 'requestcourses') {
2611: my ($curroption,$currlimit);
2612: if (ref($settings) eq 'HASH') {
2613: if (ref($settings->{$item}) eq 'HASH') {
2614: $curroption = $settings->{$item}->{'default'};
2615: if ($curroption =~ /^autolimit=(\d*)$/) {
2616: $currlimit = $1;
2617: }
2618: }
2619: }
2620: if (!$curroption) {
2621: $curroption = 'norequest';
2622: }
2623: $datatable .= '<th>'.$titles{$item}.'</th>';
2624: foreach my $option (@options) {
2625: my $val = $option;
2626: if ($option eq 'norequest') {
2627: $val = 0;
2628: }
2629: if ($option eq 'validate') {
2630: my $canvalidate = 0;
2631: if (ref($validations{$item}) eq 'HASH') {
2632: if ($validations{$item}{'default'}) {
2633: $canvalidate = 1;
2634: }
2635: }
2636: next if (!$canvalidate);
2637: }
2638: my $checked = '';
2639: if ($option eq $curroption) {
2640: $checked = ' checked="checked"';
2641: } elsif ($option eq 'autolimit') {
2642: if ($curroption =~ /^autolimit/) {
2643: $checked = ' checked="checked"';
2644: }
2645: }
2646: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2647: '<input type="radio" name="crsreq_'.$item.
2648: '_default" value="'.$val.'"'.$checked.' />'.
2649: $titles{$option}.'</label>';
2650: if ($option eq 'autolimit') {
1.127 raeburn 2651: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2652: $item.'_limit_default" size="1" '.
2653: 'value="'.$currlimit.'" />';
2654: }
1.127 raeburn 2655: $defcell{$item} .= '</span> ';
1.104 raeburn 2656: if ($option eq 'autolimit') {
1.127 raeburn 2657: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2658: }
1.101 raeburn 2659: }
1.163 raeburn 2660: } elsif ($context eq 'requestauthor') {
2661: my $curroption;
2662: if (ref($settings) eq 'HASH') {
1.172 raeburn 2663: $curroption = $settings->{'default'};
1.163 raeburn 2664: }
2665: if (!$curroption) {
2666: $curroption = 'norequest';
2667: }
2668: foreach my $option (@options) {
2669: my $val = $option;
2670: if ($option eq 'norequest') {
2671: $val = 0;
2672: }
2673: my $checked = '';
2674: if ($option eq $curroption) {
2675: $checked = ' checked="checked"';
2676: }
2677: $datatable .= '<span class="LC_nobreak"><label>'.
2678: '<input type="radio" name="authorreq_default"'.
2679: ' value="'.$val.'"'.$checked.' />'.
2680: $titles{$option}.'</label></span> ';
2681: }
1.101 raeburn 2682: } else {
2683: my $checked = 'checked="checked" ';
2684: if (ref($settings) eq 'HASH') {
2685: if (ref($settings->{$item}) eq 'HASH') {
2686: if ($settings->{$item}->{'default'} == 0) {
2687: $checked = '';
2688: } elsif ($settings->{$item}->{'default'} == 1) {
2689: $checked = 'checked="checked" ';
2690: }
1.78 raeburn 2691: }
1.72 raeburn 2692: }
1.101 raeburn 2693: $datatable .= '<span class="LC_nobreak"><label>'.
2694: '<input type="checkbox" name="'.$context.'_'.$item.
2695: '" value="default" '.$checked.'/>'.$titles{$item}.
2696: '</label></span> ';
2697: }
2698: }
2699: if ($context eq 'requestcourses') {
2700: $datatable .= '</tr><tr>';
2701: foreach my $item (@usertools) {
1.106 raeburn 2702: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2703: }
1.101 raeburn 2704: $datatable .= '</tr></table>';
1.72 raeburn 2705: }
1.86 raeburn 2706: $datatable .= '</td>';
1.163 raeburn 2707: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2708: $datatable .= '<td class="LC_right_item">'.
1.429 raeburn 2709: '<span class="LC_nobreak">'.
1.86 raeburn 2710: '<input type="text" name="defaultquota" value="'.
1.429 raeburn 2711: $defaultquota.'" size="5" /></span></td>';
1.86 raeburn 2712: }
2713: $datatable .= '</tr>';
1.72 raeburn 2714: $typecount ++;
2715: $css_class = $typecount%2?' class="LC_odd_row"':'';
2716: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2717: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2718: if ($context eq 'requestcourses') {
1.109 raeburn 2719: $datatable .= &mt('(overrides affiliation, if set)').
2720: '</td>'.
2721: '<td class="LC_left_item">'.
2722: '<table><tr>';
1.101 raeburn 2723: } else {
1.109 raeburn 2724: $datatable .= &mt('(overrides affiliation, if checked)').
2725: '</td>'.
2726: '<td class="LC_left_item" colspan="2">'.
2727: '<br />';
1.101 raeburn 2728: }
2729: my %advcell;
1.72 raeburn 2730: foreach my $item (@usertools) {
1.101 raeburn 2731: if ($context eq 'requestcourses') {
2732: my ($curroption,$currlimit);
2733: if (ref($settings) eq 'HASH') {
2734: if (ref($settings->{$item}) eq 'HASH') {
2735: $curroption = $settings->{$item}->{'_LC_adv'};
2736: if ($curroption =~ /^autolimit=(\d*)$/) {
2737: $currlimit = $1;
2738: }
2739: }
2740: }
2741: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2742: my $checked = '';
2743: if ($curroption eq '') {
2744: $checked = ' checked="checked"';
2745: }
2746: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2747: '<input type="radio" name="crsreq_'.$item.
2748: '__LC_adv" value=""'.$checked.' />'.
2749: &mt('No override set').'</label></span> ';
1.101 raeburn 2750: foreach my $option (@options) {
2751: my $val = $option;
2752: if ($option eq 'norequest') {
2753: $val = 0;
2754: }
2755: if ($option eq 'validate') {
2756: my $canvalidate = 0;
2757: if (ref($validations{$item}) eq 'HASH') {
2758: if ($validations{$item}{'_LC_adv'}) {
2759: $canvalidate = 1;
2760: }
2761: }
2762: next if (!$canvalidate);
2763: }
2764: my $checked = '';
1.104 raeburn 2765: if ($val eq $curroption) {
1.101 raeburn 2766: $checked = ' checked="checked"';
2767: } elsif ($option eq 'autolimit') {
2768: if ($curroption =~ /^autolimit/) {
2769: $checked = ' checked="checked"';
2770: }
2771: }
2772: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2773: '<input type="radio" name="crsreq_'.$item.
2774: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2775: $titles{$option}.'</label>';
2776: if ($option eq 'autolimit') {
1.127 raeburn 2777: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2778: $item.'_limit__LC_adv" size="1" '.
2779: 'value="'.$currlimit.'" />';
2780: }
1.127 raeburn 2781: $advcell{$item} .= '</span> ';
1.104 raeburn 2782: if ($option eq 'autolimit') {
1.127 raeburn 2783: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2784: }
1.101 raeburn 2785: }
1.163 raeburn 2786: } elsif ($context eq 'requestauthor') {
2787: my $curroption;
2788: if (ref($settings) eq 'HASH') {
2789: $curroption = $settings->{'_LC_adv'};
2790: }
2791: my $checked = '';
2792: if ($curroption eq '') {
2793: $checked = ' checked="checked"';
2794: }
2795: $datatable .= '<span class="LC_nobreak"><label>'.
2796: '<input type="radio" name="authorreq__LC_adv"'.
2797: ' value=""'.$checked.' />'.
2798: &mt('No override set').'</label></span> ';
2799: foreach my $option (@options) {
2800: my $val = $option;
2801: if ($option eq 'norequest') {
2802: $val = 0;
2803: }
2804: my $checked = '';
2805: if ($val eq $curroption) {
2806: $checked = ' checked="checked"';
2807: }
2808: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2809: '<input type="radio" name="authorreq__LC_adv"'.
2810: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2811: $titles{$option}.'</label></span> ';
2812: }
1.101 raeburn 2813: } else {
2814: my $checked = 'checked="checked" ';
2815: if (ref($settings) eq 'HASH') {
2816: if (ref($settings->{$item}) eq 'HASH') {
2817: if ($settings->{$item}->{'_LC_adv'} == 0) {
2818: $checked = '';
2819: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2820: $checked = 'checked="checked" ';
2821: }
1.79 raeburn 2822: }
1.72 raeburn 2823: }
1.101 raeburn 2824: $datatable .= '<span class="LC_nobreak"><label>'.
2825: '<input type="checkbox" name="'.$context.'_'.$item.
2826: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2827: '</label></span> ';
2828: }
2829: }
2830: if ($context eq 'requestcourses') {
2831: $datatable .= '</tr><tr>';
2832: foreach my $item (@usertools) {
1.106 raeburn 2833: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2834: }
1.101 raeburn 2835: $datatable .= '</tr></table>';
1.72 raeburn 2836: }
1.98 raeburn 2837: $datatable .= '</td></tr>';
1.30 raeburn 2838: $$rowtotal += $typecount;
1.3 raeburn 2839: return $datatable;
2840: }
2841:
1.163 raeburn 2842: sub print_requestmail {
1.305 raeburn 2843: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2844: my ($now,$datatable,%currapp);
1.102 raeburn 2845: $now = time;
2846: if (ref($settings) eq 'HASH') {
2847: if (ref($settings->{'notify'}) eq 'HASH') {
2848: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2849: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2850: }
2851: }
2852: }
1.191 raeburn 2853: my $numinrow = 2;
1.224 raeburn 2854: my $css_class;
1.305 raeburn 2855: if ($$rowtotal%2) {
2856: $css_class = 'LC_odd_row';
2857: }
2858: if ($customcss) {
2859: $css_class .= " $customcss";
2860: }
2861: $css_class =~ s/^\s+//;
2862: if ($css_class) {
2863: $css_class = ' class="'.$css_class.'"';
2864: }
2865: if ($rowstyle) {
2866: $css_class .= ' style="'.$rowstyle.'"';
2867: }
1.163 raeburn 2868: my $text;
2869: if ($action eq 'requestcourses') {
2870: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2871: } elsif ($action eq 'requestauthor') {
2872: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2873: } else {
1.224 raeburn 2874: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2875: }
1.224 raeburn 2876: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2877: ' <td>'.$text.'</td>'.
1.102 raeburn 2878: ' <td class="LC_left_item">';
1.191 raeburn 2879: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2880: $action.'notifyapproval',%currapp);
1.191 raeburn 2881: if ($numdc > 0) {
2882: $datatable .= $table;
1.102 raeburn 2883: } else {
2884: $datatable .= &mt('There are no active Domain Coordinators');
2885: }
2886: $datatable .='</td></tr>';
2887: return $datatable;
2888: }
2889:
1.216 raeburn 2890: sub print_studentcode {
2891: my ($settings,$rowtotal) = @_;
2892: my $rownum = 0;
1.218 raeburn 2893: my ($output,%current);
1.325 raeburn 2894: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248 raeburn 2895: if (ref($settings) eq 'HASH') {
2896: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2897: foreach my $type (@crstypes) {
2898: $current{$type} = $settings->{'uniquecode'}{$type};
2899: }
1.218 raeburn 2900: }
2901: }
2902: $output .= '<tr>'.
2903: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2904: '<td class="LC_left_item">';
2905: foreach my $type (@crstypes) {
2906: my $check = ' ';
2907: if ($current{$type}) {
2908: $check = ' checked="checked" ';
2909: }
2910: $output .= '<span class="LC_nobreak"><label>'.
2911: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2912: &mt($type).'</label></span>'.(' 'x2).' ';
2913: }
2914: $output .= '</td></tr>';
2915: $$rowtotal ++;
2916: return $output;
1.216 raeburn 2917: }
2918:
2919: sub print_textbookcourses {
1.242 raeburn 2920: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2921: my $rownum = 0;
2922: my $css_class;
2923: my $itemcount = 1;
2924: my $maxnum = 0;
2925: my $bookshash;
2926: if (ref($settings) eq 'HASH') {
1.242 raeburn 2927: $bookshash = $settings->{$type};
1.216 raeburn 2928: }
2929: my %ordered;
2930: if (ref($bookshash) eq 'HASH') {
2931: foreach my $item (keys(%{$bookshash})) {
2932: if (ref($bookshash->{$item}) eq 'HASH') {
2933: my $num = $bookshash->{$item}{'order'};
2934: $ordered{$num} = $item;
2935: }
2936: }
2937: }
2938: my $confname = $dom.'-domainconfig';
2939: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2940: my $maxnum = scalar(keys(%ordered));
2941: my $datatable;
1.216 raeburn 2942: if (keys(%ordered)) {
2943: my @items = sort { $a <=> $b } keys(%ordered);
2944: for (my $i=0; $i<@items; $i++) {
2945: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2946: my $key = $ordered{$items[$i]};
2947: my %coursehash=&Apache::lonnet::coursedescription($key);
2948: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2949: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2950: if (ref($bookshash->{$key}) eq 'HASH') {
2951: $subject = $bookshash->{$key}->{'subject'};
2952: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2953: if ($type eq 'textbooks') {
1.243 raeburn 2954: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2955: $author = $bookshash->{$key}->{'author'};
2956: $image = $bookshash->{$key}->{'image'};
2957: if ($image ne '') {
2958: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2959: my $imagethumb = "$path/tn-".$imagefile;
2960: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2961: }
1.216 raeburn 2962: }
2963: }
1.242 raeburn 2964: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2965: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2966: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2967: for (my $k=0; $k<=$maxnum; $k++) {
2968: my $vpos = $k+1;
2969: my $selstr;
2970: if ($k == $i) {
2971: $selstr = ' selected="selected" ';
2972: }
2973: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2974: }
2975: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2976: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2977: &mt('Delete?').'</label></span></td>'.
2978: '<td colspan="2">'.
1.242 raeburn 2979: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2980: (' 'x2).
1.242 raeburn 2981: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2982: if ($type eq 'textbooks') {
2983: $datatable .= (' 'x2).
1.243 raeburn 2984: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2985: (' 'x2).
1.242 raeburn 2986: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2987: (' 'x2).
2988: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2989: if ($image) {
1.267 raeburn 2990: $datatable .= $imgsrc.
1.242 raeburn 2991: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2992: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2993: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2994: }
2995: if ($switchserver) {
2996: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2997: } else {
2998: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2999: }
1.216 raeburn 3000: }
1.242 raeburn 3001: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 3002: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
3003: $coursetitle.'</span></td></tr>'."\n";
3004: $itemcount ++;
3005: }
3006: }
3007: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 3008: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 3009: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 3010: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
3011: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 3012: for (my $k=0; $k<$maxnum+1; $k++) {
3013: my $vpos = $k+1;
3014: my $selstr;
3015: if ($k == $maxnum) {
3016: $selstr = ' selected="selected" ';
3017: }
3018: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3019: }
3020: $datatable .= '</select> '."\n".
1.334 raeburn 3021: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216 raeburn 3022: '<td colspan="2">'.
1.242 raeburn 3023: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 3024: (' 'x2).
1.242 raeburn 3025: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
3026: (' 'x2);
3027: if ($type eq 'textbooks') {
1.243 raeburn 3028: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
3029: (' 'x2).
3030: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 3031: (' 'x2).
3032: '<span class="LC_nobreak">'.&mt('Image:').' ';
3033: if ($switchserver) {
3034: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3035: } else {
3036: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
3037: }
1.334 raeburn 3038: $datatable .= '</span>'."\n";
1.216 raeburn 3039: }
1.334 raeburn 3040: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 3041: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
3042: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 3043: &Apache::loncommon::selectcourse_link
1.334 raeburn 3044: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216 raeburn 3045: '</span></td>'."\n".
3046: '</tr>'."\n";
3047: $itemcount ++;
3048: return $datatable;
3049: }
3050:
1.217 raeburn 3051: sub textbookcourses_javascript {
1.242 raeburn 3052: my ($settings) = @_;
3053: return unless(ref($settings) eq 'HASH');
3054: my (%ordered,%total,%jstext);
3055: foreach my $type ('textbooks','templates') {
3056: $total{$type} = 0;
3057: if (ref($settings->{$type}) eq 'HASH') {
3058: foreach my $item (keys(%{$settings->{$type}})) {
3059: if (ref($settings->{$type}->{$item}) eq 'HASH') {
3060: my $num = $settings->{$type}->{$item}{'order'};
3061: $ordered{$type}{$num} = $item;
3062: }
3063: }
3064: $total{$type} = scalar(keys(%{$settings->{$type}}));
3065: }
3066: my @jsarray = ();
3067: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
3068: push(@jsarray,$ordered{$type}{$item});
3069: }
3070: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 3071: }
3072: return <<"ENDSCRIPT";
3073: <script type="text/javascript">
3074: // <![CDATA[
1.242 raeburn 3075: function reorderBooks(form,item,caller) {
1.217 raeburn 3076: var changedVal;
1.242 raeburn 3077: $jstext{'textbooks'};
3078: $jstext{'templates'};
3079: var newpos;
3080: var maxh;
3081: if (caller == 'textbooks') {
3082: newpos = 'textbooks_addbook_pos';
3083: maxh = 1 + $total{'textbooks'};
3084: } else {
3085: newpos = 'templates_addbook_pos';
3086: maxh = 1 + $total{'templates'};
3087: }
1.217 raeburn 3088: var current = new Array;
3089: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3090: if (item == newpos) {
3091: changedVal = newitemVal;
3092: } else {
3093: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3094: current[newitemVal] = newpos;
3095: }
1.242 raeburn 3096: if (caller == 'textbooks') {
3097: for (var i=0; i<textbooks.length; i++) {
3098: var elementName = 'textbooks_'+textbooks[i];
3099: if (elementName != item) {
3100: if (form.elements[elementName]) {
3101: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3102: current[currVal] = elementName;
3103: }
3104: }
3105: }
3106: }
3107: if (caller == 'templates') {
3108: for (var i=0; i<templates.length; i++) {
3109: var elementName = 'templates_'+templates[i];
3110: if (elementName != item) {
3111: if (form.elements[elementName]) {
3112: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3113: current[currVal] = elementName;
3114: }
1.217 raeburn 3115: }
3116: }
3117: }
3118: var oldVal;
3119: for (var j=0; j<maxh; j++) {
3120: if (current[j] == undefined) {
3121: oldVal = j;
3122: }
3123: }
3124: if (oldVal < changedVal) {
3125: for (var k=oldVal+1; k<=changedVal ; k++) {
3126: var elementName = current[k];
3127: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3128: }
3129: } else {
3130: for (var k=changedVal; k<oldVal; k++) {
3131: var elementName = current[k];
3132: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3133: }
3134: }
3135: return;
3136: }
3137:
3138: // ]]>
3139: </script>
3140:
3141: ENDSCRIPT
3142: }
3143:
1.267 raeburn 3144: sub ltitools_javascript {
3145: my ($settings) = @_;
1.319 raeburn 3146: my $togglejs = <itools_toggle_js();
3147: unless (ref($settings) eq 'HASH') {
3148: return $togglejs;
3149: }
1.267 raeburn 3150: my (%ordered,$total,%jstext);
3151: $total = 0;
3152: foreach my $item (keys(%{$settings})) {
3153: if (ref($settings->{$item}) eq 'HASH') {
3154: my $num = $settings->{$item}{'order'};
3155: $ordered{$num} = $item;
3156: }
3157: }
3158: $total = scalar(keys(%{$settings}));
3159: my @jsarray = ();
3160: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3161: push(@jsarray,$ordered{$item});
3162: }
3163: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
3164: return <<"ENDSCRIPT";
3165: <script type="text/javascript">
3166: // <![CDATA[
1.319 raeburn 3167: function reorderLTITools(form,item) {
1.267 raeburn 3168: var changedVal;
3169: $jstext
3170: var newpos = 'ltitools_add_pos';
3171: var maxh = 1 + $total;
3172: var current = new Array;
3173: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3174: if (item == newpos) {
3175: changedVal = newitemVal;
3176: } else {
3177: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3178: current[newitemVal] = newpos;
3179: }
3180: for (var i=0; i<ltitools.length; i++) {
3181: var elementName = 'ltitools_'+ltitools[i];
3182: if (elementName != item) {
3183: if (form.elements[elementName]) {
3184: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3185: current[currVal] = elementName;
3186: }
3187: }
3188: }
3189: var oldVal;
3190: for (var j=0; j<maxh; j++) {
3191: if (current[j] == undefined) {
3192: oldVal = j;
3193: }
3194: }
3195: if (oldVal < changedVal) {
3196: for (var k=oldVal+1; k<=changedVal ; k++) {
3197: var elementName = current[k];
3198: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3199: }
3200: } else {
3201: for (var k=changedVal; k<oldVal; k++) {
3202: var elementName = current[k];
3203: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3204: }
3205: }
3206: return;
3207: }
3208:
3209: // ]]>
3210: </script>
3211:
1.319 raeburn 3212: $togglejs
3213:
3214: ENDSCRIPT
3215: }
3216:
3217: sub ltitools_toggle_js {
3218: return <<"ENDSCRIPT";
3219: <script type="text/javascript">
3220: // <![CDATA[
3221:
3222: function toggleLTITools(form,setting,item) {
3223: var radioname = '';
3224: var divid = '';
3225: if ((setting == 'passback') || (setting == 'roster')) {
3226: radioname = 'ltitools_'+setting+'_'+item;
3227: divid = 'ltitools_'+setting+'time_'+item;
3228: var num = form.elements[radioname].length;
3229: if (num) {
3230: var setvis = '';
3231: for (var i=0; i<num; i++) {
3232: if (form.elements[radioname][i].checked) {
3233: if (form.elements[radioname][i].value == '1') {
3234: if (document.getElementById(divid)) {
3235: document.getElementById(divid).style.display = 'inline-block';
3236: }
3237: setvis = 1;
3238: }
3239: break;
3240: }
3241: }
3242: }
3243: if (!setvis) {
3244: if (document.getElementById(divid)) {
3245: document.getElementById(divid).style.display = 'none';
3246: }
3247: }
3248: }
1.324 raeburn 3249: if (setting == 'user') {
3250: divid = 'ltitools_'+setting+'_div_'+item;
3251: var checkid = 'ltitools_'+setting+'_field_'+item;
3252: if (document.getElementById(divid)) {
3253: if (document.getElementById(checkid)) {
3254: if (document.getElementById(checkid).checked) {
3255: document.getElementById(divid).style.display = 'inline-block';
3256: } else {
3257: document.getElementById(divid).style.display = 'none';
3258: }
3259: }
3260: }
3261: }
1.319 raeburn 3262: return;
3263: }
3264: // ]]>
3265: </script>
3266:
1.267 raeburn 3267: ENDSCRIPT
3268: }
3269:
1.381 raeburn 3270: sub wafproxy_javascript {
3271: my ($dom) = @_;
3272: return <<"ENDSCRIPT";
3273: <script type="text/javascript">
3274: // <![CDATA[
3275: function updateWAF() {
3276: if (document.getElementById('wafproxy_remoteip')) {
3277: var wafremote = 0;
3278: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
3279: wafremote = 1;
3280: }
3281: var fields = new Array('header','trust');
3282: for (var i=0; i<fields.length; i++) {
3283: if (document.getElementById('wafproxy_'+fields[i])) {
3284: if (wafremote == 1) {
3285: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
3286: }
3287: else {
3288: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
3289: }
3290: }
3291: }
3292: if (document.getElementById('wafproxyranges_$dom')) {
3293: if (wafremote == 1) {
3294: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3295: } else {
3296: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3297: if (document.display.wafproxy_vpnaccess[i].checked) {
3298: if (document.display.wafproxy_vpnaccess[i].value == 0) {
3299: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3300: }
3301: }
3302: }
3303: }
3304: }
3305: }
3306: return;
3307: }
3308:
3309: function checkWAF() {
3310: if (document.getElementById('wafproxy_remoteip')) {
3311: var wafvpn = 0;
3312: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3313: if (document.display.wafproxy_vpnaccess[i].checked) {
3314: if (document.display.wafproxy_vpnaccess[i].value == 1) {
3315: wafvpn = 1;
3316: }
3317: break;
3318: }
3319: }
3320: var vpn = new Array('vpnint','vpnext');
3321: for (var i=0; i<vpn.length; i++) {
3322: if (document.getElementById('wafproxy_show_'+vpn[i])) {
3323: if (wafvpn == 1) {
3324: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
3325: }
3326: else {
3327: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
3328: }
3329: }
3330: }
3331: if (document.getElementById('wafproxyranges_$dom')) {
3332: if (wafvpn == 1) {
3333: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3334: }
3335: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
3336: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3337: }
3338: }
3339: }
3340: return;
3341: }
3342:
3343: function toggleWAF() {
3344: if (document.getElementById('wafproxy_table')) {
3345: var wafproxy = 0;
3346: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
3347: if (document.display.wafproxy_${dom}[i].checked) {
3348: if (document.display.wafproxy_${dom}[i].value == 1) {
3349: wafproxy = 1;
3350: break;
3351: }
3352: }
3353: }
3354: if (wafproxy == 1) {
3355: document.getElementById('wafproxy_table').style.display='inline';
3356: }
3357: else {
3358: document.getElementById('wafproxy_table').style.display='none';
3359: }
3360: if (document.getElementById('wafproxyrow_${dom}')) {
3361: if (wafproxy == 1) {
3362: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
3363: }
3364: else {
3365: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
3366: }
3367: }
3368: if (document.getElementById('nowafproxyrow_$dom')) {
3369: if (wafproxy == 1) {
3370: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
3371: }
3372: else {
3373: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
3374: }
3375: }
3376: }
3377: return;
3378: }
3379: // ]]>
3380: </script>
3381:
3382: ENDSCRIPT
3383: }
3384:
1.372 raeburn 3385: sub proctoring_javascript {
3386: my ($settings) = @_;
3387: my (%ordered,$total,%jstext);
3388: $total = 0;
3389: if (ref($settings) eq 'HASH') {
3390: foreach my $item (keys(%{$settings})) {
3391: if (ref($settings->{$item}) eq 'HASH') {
3392: my $num = $settings->{$item}{'order'};
3393: $ordered{$num} = $item;
3394: }
3395: }
3396: $total = scalar(keys(%{$settings}));
3397: } else {
3398: %ordered = (
3399: 0 => 'proctorio',
3400: 1 => 'examity',
3401: );
3402: $total = 2;
3403: }
3404: my @jsarray = ();
3405: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3406: push(@jsarray,$ordered{$item});
3407: }
3408: my $jstext = ' var proctors = Array('."'".join("','",@jsarray)."'".');'."\n";
3409: return <<"ENDSCRIPT";
3410: <script type="text/javascript">
3411: // <![CDATA[
3412: function reorderProctoring(form,item) {
3413: var changedVal;
3414: $jstext
3415: var maxh = $total;
3416: var current = new Array;
3417: var changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3418: for (var i=0; i<proctors.length; i++) {
3419: var elementName = 'proctoring_pos_'+proctors[i];
3420: if (elementName != item) {
3421: if (form.elements[elementName]) {
3422: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3423: current[currVal] = elementName;
3424: }
3425: }
3426: }
3427: var oldVal;
3428: for (var j=0; j<maxh; j++) {
3429: if (current[j] == undefined) {
3430: oldVal = j;
3431: }
3432: }
3433: if (oldVal < changedVal) {
3434: for (var k=oldVal+1; k<=changedVal ; k++) {
3435: var elementName = current[k];
3436: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3437: }
3438: } else {
3439: for (var k=changedVal; k<oldVal; k++) {
3440: var elementName = current[k];
3441: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3442: }
3443: }
3444: return;
3445: }
3446:
3447: function toggleProctoring(form,item) {
3448: var fieldsets = document.getElementsByClassName('proctoring_'+item);
3449: if (fieldsets.length) {
3450: var radioname = 'proctoring_available_'+item;
3451: var num = form.elements[radioname].length;
3452: if (num) {
3453: var setvis = '';
3454: for (var i=0; i<num; i++) {
3455: if (form.elements[radioname][i].checked) {
3456: if (form.elements[radioname][i].value == '1') {
3457: setvis = 1;
3458: break;
3459: }
3460: }
3461: }
3462: for (var j=0; j<fieldsets.length; j++) {
3463: if (setvis) {
3464: fieldsets[j].style.display = 'block';
3465: } else {
3466: fieldsets[j].style.display = 'none';
3467: }
3468: }
3469: }
3470: }
3471: return;
3472: }
3473:
3474: // ]]>
3475: </script>
3476:
3477: ENDSCRIPT
3478: }
3479:
3480:
1.320 raeburn 3481: sub lti_javascript {
1.405 raeburn 3482: my ($dom,$settings) = @_;
3483: my $togglejs = <i_toggle_js($dom);
1.419 raeburn 3484: my $linkprot_js = &Apache::courseprefs::linkprot_javascript();
1.320 raeburn 3485: unless (ref($settings) eq 'HASH') {
1.419 raeburn 3486: return $togglejs.'
3487: <script type="text/javascript">
3488: // <![CDATA[
3489:
3490: '.$linkprot_js.'
3491:
3492: // ]]>
3493: </script>
3494: ';
1.320 raeburn 3495: }
3496: my (%ordered,$total,%jstext);
1.390 raeburn 3497: $total = scalar(keys(%{$settings}));
1.320 raeburn 3498: foreach my $item (keys(%{$settings})) {
3499: if (ref($settings->{$item}) eq 'HASH') {
3500: my $num = $settings->{$item}{'order'};
1.390 raeburn 3501: if ($num eq '') {
3502: $num = $total - 1;
3503: }
1.320 raeburn 3504: $ordered{$num} = $item;
3505: }
3506: }
3507: my @jsarray = ();
3508: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3509: push(@jsarray,$ordered{$item});
3510: }
3511: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
3512: return <<"ENDSCRIPT";
3513: <script type="text/javascript">
3514: // <![CDATA[
3515: function reorderLTI(form,item) {
3516: var changedVal;
3517: $jstext
3518: var newpos = 'lti_pos_add';
3519: var maxh = 1 + $total;
3520: var current = new Array;
3521: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3522: if (item == newpos) {
3523: changedVal = newitemVal;
3524: } else {
3525: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3526: current[newitemVal] = newpos;
3527: }
3528: for (var i=0; i<lti.length; i++) {
3529: var elementName = 'lti_pos_'+lti[i];
3530: if (elementName != item) {
3531: if (form.elements[elementName]) {
3532: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3533: current[currVal] = elementName;
3534: }
3535: }
3536: }
3537: var oldVal;
3538: for (var j=0; j<maxh; j++) {
3539: if (current[j] == undefined) {
3540: oldVal = j;
3541: }
3542: }
3543: if (oldVal < changedVal) {
3544: for (var k=oldVal+1; k<=changedVal ; k++) {
3545: var elementName = current[k];
3546: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3547: }
3548: } else {
3549: for (var k=changedVal; k<oldVal; k++) {
3550: var elementName = current[k];
3551: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3552: }
3553: }
3554: return;
3555: }
1.406 raeburn 3556:
3557: $linkprot_js
3558:
1.320 raeburn 3559: // ]]>
3560: </script>
3561:
3562: $togglejs
3563:
3564: ENDSCRIPT
3565: }
3566:
3567: sub lti_toggle_js {
1.405 raeburn 3568: my ($dom) = @_;
1.325 raeburn 3569: my %lcauthparmtext = &Apache::lonlocal::texthash (
3570: localauth => 'Local auth argument',
3571: krb => 'Kerberos domain',
3572: );
1.391 raeburn 3573: my $crsincalert = &mt('"User\'s identity sent" needs to be set to "Yes" first,[_1] before setting "Course\'s identity sent" to "Yes"',"\n");
3574: &js_escape(\$crsincalert);
1.405 raeburn 3575: my %servers = &Apache::lonnet::get_servers($dom,'library');
3576: my $primary = &Apache::lonnet::domain($dom,'primary');
3577: my $course_servers = "'".join("','",keys(%servers))."'";
1.320 raeburn 3578: return <<"ENDSCRIPT";
3579: <script type="text/javascript">
3580: // <![CDATA[
3581:
3582: function toggleLTI(form,setting,item) {
1.391 raeburn 3583: if ((setting == 'requser') || (setting == 'crsinc')) {
3584: var usrfieldsets = document.getElementsByClassName('ltioption_usr_'+item);
3585: var setvis = '';
3586: var radioname = 'lti_requser_'+item;
3587: var num = form.elements[radioname].length;
3588: if (num) {
3589: for (var i=0; i<num; i++) {
3590: if (form.elements[radioname][i].checked) {
3591: if (form.elements[radioname][i].value == '1') {
3592: setvis = 1;
3593: break;
3594: }
3595: }
3596: }
3597: }
3598: if (usrfieldsets.length) {
3599: for (var j=0; j<usrfieldsets.length; j++) {
3600: if (setvis) {
3601: usrfieldsets[j].style.display = 'block';
3602: } else {
3603: usrfieldsets[j].style.display = 'none';
3604: }
3605: }
3606: }
3607: var crsfieldsets = document.getElementsByClassName('ltioption_crs_'+item);
3608: if (crsfieldsets.length) {
3609: radioname = 'lti_crsinc_'+item;
1.345 raeburn 3610: var num = form.elements[radioname].length;
3611: if (num) {
1.391 raeburn 3612: var crsvis = '';
1.345 raeburn 3613: for (var i=0; i<num; i++) {
3614: if (form.elements[radioname][i].checked) {
3615: if (form.elements[radioname][i].value == '1') {
1.391 raeburn 3616: if (setvis == '') {
3617: if (setting == 'crsinc'){
3618: alert("$crsincalert");
3619: form.elements[radioname][0].checked = true;
3620: }
3621: } else {
3622: crsvis = 1;
3623: }
3624: break;
1.345 raeburn 3625: }
3626: }
3627: }
1.391 raeburn 3628: setvis = crsvis;
3629: }
3630: for (var j=0; j<crsfieldsets.length; j++) {
3631: if (setvis) {
3632: crsfieldsets[j].style.display = 'block';
3633: } else {
3634: crsfieldsets[j].style.display = 'none';
1.345 raeburn 3635: }
3636: }
3637: }
1.363 raeburn 3638: } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
1.320 raeburn 3639: var radioname = '';
3640: var divid = '';
3641: if (setting == 'user') {
3642: radioname = 'lti_mapuser_'+item;
3643: divid = 'lti_userfield_'+item;
1.343 raeburn 3644: } else if (setting == 'crs') {
1.320 raeburn 3645: radioname = 'lti_mapcrs_'+item;
3646: divid = 'lti_crsfield_'+item;
1.363 raeburn 3647: } else if (setting == 'callback') {
3648: radioname = 'lti_callback_'+item;
3649: divid = 'lti_callbackfield_'+item;
1.337 raeburn 3650: } else {
1.351 raeburn 3651: radioname = 'lti_passback_'+item;
1.337 raeburn 3652: divid = 'lti_passback_'+item;
1.320 raeburn 3653: }
3654: var num = form.elements[radioname].length;
3655: if (num) {
3656: var setvis = '';
3657: for (var i=0; i<num; i++) {
3658: if (form.elements[radioname][i].checked) {
1.363 raeburn 3659: if ((setting == 'passback') || (setting == 'callback')) {
1.337 raeburn 3660: if (form.elements[radioname][i].value == '1') {
3661: if (document.getElementById(divid)) {
3662: document.getElementById(divid).style.display = 'inline-block';
3663: }
3664: setvis = 1;
3665: break;
3666: }
3667: } else {
3668: if (form.elements[radioname][i].value == 'other') {
3669: if (document.getElementById(divid)) {
3670: document.getElementById(divid).style.display = 'inline-block';
3671: }
3672: setvis = 1;
3673: break;
1.320 raeburn 3674: }
3675: }
1.425 raeburn 3676: }
1.320 raeburn 3677: }
3678: if (!setvis) {
3679: if (document.getElementById(divid)) {
3680: document.getElementById(divid).style.display = 'none';
3681: }
3682: }
3683: }
3684: } else if ((setting == 'sec') || (setting == 'secsrc')) {
3685: var numsec = form.elements['lti_crssec_'+item].length;
3686: if (numsec) {
3687: var setvis = '';
3688: for (var i=0; i<numsec; i++) {
3689: if (form.elements['lti_crssec_'+item][i].checked) {
3690: if (form.elements['lti_crssec_'+item][i].value == '1') {
3691: if (document.getElementById('lti_crssecfield_'+item)) {
3692: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
3693: setvis = 1;
3694: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
3695: if (numsrcsec) {
3696: var setsrcvis = '';
3697: for (var j=0; j<numsrcsec; j++) {
3698: if (form.elements['lti_crssecsrc_'+item][j].checked) {
3699: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
3700: if (document.getElementById('lti_secsrcfield_'+item)) {
3701: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
3702: setsrcvis = 1;
3703: }
3704: }
3705: }
3706: }
3707: if (!setsrcvis) {
3708: if (document.getElementById('lti_secsrcfield_'+item)) {
3709: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3710: }
3711: }
3712: }
3713: }
3714: }
3715: }
3716: }
3717: if (!setvis) {
3718: if (document.getElementById('lti_crssecfield_'+item)) {
3719: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
3720: }
3721: if (document.getElementById('lti_secsrcfield_'+item)) {
3722: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3723: }
3724: }
3725: }
1.325 raeburn 3726: } else if (setting == 'lcauth') {
3727: var numauth = form.elements['lti_lcauth_'+item].length;
3728: if (numauth) {
3729: for (var i=0; i<numauth; i++) {
3730: if (form.elements['lti_lcauth_'+item][i].checked) {
3731: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
3732: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
3733: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
3734: } else {
3735: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
3736: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
3737: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
3738: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
3739: } else {
3740: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
3741: }
3742: }
3743: }
3744: }
3745: }
3746: }
3747: }
1.326 raeburn 3748: } else if (setting == 'lcmenu') {
3749: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3750: var divid = 'lti_menufield_'+item;
3751: var setvis = '';
3752: for (var i=0; i<menus.length; i++) {
1.425 raeburn 3753: var radioname = menus[i];
1.326 raeburn 3754: var num = form.elements[radioname].length;
3755: if (num) {
3756: for (var j=0; j<num; j++) {
3757: if (form.elements[radioname][j].checked) {
3758: if (form.elements[radioname][j].value == '1') {
3759: if (document.getElementById(divid)) {
3760: document.getElementById(divid).style.display = 'inline-block';
3761: }
3762: setvis = 1;
3763: break;
3764: }
3765: }
3766: }
3767: }
3768: if (setvis == 1) {
3769: break;
3770: }
3771: }
3772: if (!setvis) {
3773: if (document.getElementById(divid)) {
3774: document.getElementById(divid).style.display = 'none';
3775: }
3776: }
1.320 raeburn 3777: }
3778: return;
3779: }
1.405 raeburn 3780:
1.320 raeburn 3781: // ]]>
3782: </script>
3783:
3784: ENDSCRIPT
3785: }
3786:
1.385 raeburn 3787: sub autoupdate_javascript {
3788: return <<"ENDSCRIPT";
3789: <script type="text/javascript">
3790: // <![CDATA[
3791: function toggleLastActiveDays(form) {
3792: var radioname = 'lastactive';
3793: var divid = 'lastactive_div';
3794: var num = form.elements[radioname].length;
3795: if (num) {
3796: var setvis = '';
3797: for (var i=0; i<num; i++) {
3798: if (form.elements[radioname][i].checked) {
3799: if (form.elements[radioname][i].value == '1') {
3800: if (document.getElementById(divid)) {
3801: document.getElementById(divid).style.display = 'inline-block';
3802: }
3803: setvis = 1;
3804: }
3805: break;
3806: }
3807: }
3808: if (!setvis) {
3809: if (document.getElementById(divid)) {
3810: document.getElementById(divid).style.display = 'none';
3811: }
3812: }
3813: }
3814: return;
3815: }
3816: // ]]>
3817: </script>
3818:
3819: ENDSCRIPT
3820: }
3821:
1.399 raeburn 3822: sub autoenroll_javascript {
3823: return <<"ENDSCRIPT";
3824: <script type="text/javascript">
3825: // <![CDATA[
3826: function toggleFailsafe(form) {
3827: var radioname = 'autoenroll_failsafe';
3828: var divid = 'autoenroll_failsafe_div';
3829: var num = form.elements[radioname].length;
3830: if (num) {
3831: var setvis = '';
3832: for (var i=0; i<num; i++) {
3833: if (form.elements[radioname][i].checked) {
3834: if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
3835: if (document.getElementById(divid)) {
3836: document.getElementById(divid).style.display = 'inline-block';
3837: }
3838: setvis = 1;
3839: }
3840: break;
3841: }
3842: }
3843: if (!setvis) {
3844: if (document.getElementById(divid)) {
3845: document.getElementById(divid).style.display = 'none';
3846: }
3847: }
3848: }
3849: return;
3850: }
3851: // ]]>
3852: </script>
3853:
3854: ENDSCRIPT
3855: }
3856:
1.386 raeburn 3857: sub saml_javascript {
3858: return <<"ENDSCRIPT";
3859: <script type="text/javascript">
3860: // <![CDATA[
1.425 raeburn 3861: function toggleSamlOptions(form,hostid) {
1.386 raeburn 3862: var radioname = 'saml_'+hostid;
3863: var tablecellon = 'samloptionson_'+hostid;
3864: var tablecelloff = 'samloptionsoff_'+hostid;
3865: var num = form.elements[radioname].length;
3866: if (num) {
1.425 raeburn 3867: var setvis = '';
1.386 raeburn 3868: for (var i=0; i<num; i++) {
3869: if (form.elements[radioname][i].checked) {
1.425 raeburn 3870: if (form.elements[radioname][i].value == '1') {
1.386 raeburn 3871: if (document.getElementById(tablecellon)) {
3872: document.getElementById(tablecellon).style.display='';
3873: }
3874: if (document.getElementById(tablecelloff)) {
3875: document.getElementById(tablecelloff).style.display='none';
3876: }
3877: setvis = 1;
3878: }
3879: break;
3880: }
3881: }
3882: if (!setvis) {
3883: if (document.getElementById(tablecellon)) {
3884: document.getElementById(tablecellon).style.display='none';
3885: }
3886: if (document.getElementById(tablecelloff)) {
3887: document.getElementById(tablecelloff).style.display='';
3888: }
3889: }
3890: }
3891: return;
3892: }
3893: // ]]>
3894: </script>
3895:
3896: ENDSCRIPT
3897: }
3898:
1.394 raeburn 3899: sub ipaccess_javascript {
3900: my ($settings) = @_;
3901: my (%ordered,$total,%jstext);
3902: $total = 0;
3903: if (ref($settings) eq 'HASH') {
3904: foreach my $item (keys(%{$settings})) {
3905: if (ref($settings->{$item}) eq 'HASH') {
3906: my $num = $settings->{$item}{'order'};
3907: $ordered{$num} = $item;
3908: }
3909: }
3910: $total = scalar(keys(%{$settings}));
3911: }
3912: my @jsarray = ();
3913: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3914: push(@jsarray,$ordered{$item});
3915: }
3916: my $jstext = ' var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
3917: return <<"ENDSCRIPT";
3918: <script type="text/javascript">
3919: // <![CDATA[
3920: function reorderIPaccess(form,item) {
3921: var changedVal;
3922: $jstext
3923: var newpos = 'ipaccess_pos_add';
3924: var maxh = 1 + $total;
3925: var current = new Array;
3926: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3927: if (item == newpos) {
3928: changedVal = newitemVal;
3929: } else {
3930: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3931: current[newitemVal] = newpos;
3932: }
3933: for (var i=0; i<ipaccess.length; i++) {
3934: var elementName = 'ipaccess_pos_'+ipaccess[i];
3935: if (elementName != item) {
3936: if (form.elements[elementName]) {
3937: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3938: current[currVal] = elementName;
3939: }
3940: }
3941: }
3942: var oldVal;
3943: for (var j=0; j<maxh; j++) {
3944: if (current[j] == undefined) {
3945: oldVal = j;
3946: }
3947: }
3948: if (oldVal < changedVal) {
3949: for (var k=oldVal+1; k<=changedVal ; k++) {
3950: var elementName = current[k];
3951: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3952: }
3953: } else {
3954: for (var k=changedVal; k<oldVal; k++) {
3955: var elementName = current[k];
3956: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3957: }
3958: }
3959: return;
3960: }
3961: // ]]>
3962: </script>
3963:
3964: ENDSCRIPT
3965: }
3966:
1.429 raeburn 3967: sub authordefaults_javascript {
3968: my %alert = &Apache::lonlocal::texthash (
3969: reqd => 'Warning: at least one editor needs to be available.',
3970: rest => 'Unchecking this editor disallowed while others unchecked.',
3971: );
3972: &js_escape(\%alert);
3973: return <<"ENDSCRIPT";
3974: <script type="text/javascript">
3975: // <![CDATA[
3976:
3977: function checkEditors(form,checkbox,current) {
3978: if (form.elements[checkbox].length != undefined) {
3979: var count = 0;
3980: for (var i=0; i<form.elements[checkbox].length; i++) {
3981: if (form.elements[checkbox][i].checked) {
3982: count ++;
3983: }
3984: }
3985: if (count == 0) {
3986: if (current.type =='radio') {
3987: current.checked = true;
3988: alert('$alert{reqd}\\n$alert{rest}');
3989: }
3990: }
3991: }
3992: return;
3993: }
3994: // ]]>
3995: </script>
3996:
3997: ENDSCRIPT
3998: }
3999:
1.3 raeburn 4000: sub print_autoenroll {
1.30 raeburn 4001: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 4002: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.399 raeburn 4003: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
4004: $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
4005: $failsafesty = 'none';
4006: %failsafechecked = (
4007: off => ' checked="checked"',
4008: );
1.3 raeburn 4009: if (ref($settings) eq 'HASH') {
4010: if (exists($settings->{'run'})) {
4011: if ($settings->{'run'} eq '0') {
4012: $runoff = ' checked="checked" ';
4013: $runon = ' ';
4014: } else {
4015: $runon = ' checked="checked" ';
4016: $runoff = ' ';
4017: }
4018: } else {
4019: if ($autorun) {
4020: $runon = ' checked="checked" ';
4021: $runoff = ' ';
4022: } else {
4023: $runoff = ' checked="checked" ';
4024: $runon = ' ';
4025: }
4026: }
1.129 raeburn 4027: if (exists($settings->{'co-owners'})) {
4028: if ($settings->{'co-owners'} eq '0') {
4029: $coownersoff = ' checked="checked" ';
4030: $coownerson = ' ';
4031: } else {
4032: $coownerson = ' checked="checked" ';
4033: $coownersoff = ' ';
4034: }
4035: } else {
4036: $coownersoff = ' checked="checked" ';
4037: $coownerson = ' ';
4038: }
1.3 raeburn 4039: if (exists($settings->{'sender_domain'})) {
4040: $defdom = $settings->{'sender_domain'};
4041: }
1.399 raeburn 4042: if (exists($settings->{'failsafe'})) {
4043: $failsafe = $settings->{'failsafe'};
4044: if ($failsafe eq 'zero') {
1.400 raeburn 4045: $failsafechecked{'zero'} = ' checked="checked"';
1.399 raeburn 4046: $failsafechecked{'off'} = '';
4047: $failsafesty = 'inline-block';
4048: } elsif ($failsafe eq 'any') {
4049: $failsafechecked{'any'} = ' checked="checked"';
4050: $failsafechecked{'off'} = '';
4051: }
4052: $autofailsafe = $settings->{'autofailsafe'};
4053: } elsif (exists($settings->{'autofailsafe'})) {
4054: $autofailsafe = $settings->{'autofailsafe'};
4055: if ($autofailsafe ne '') {
4056: $failsafechecked{'zero'} = ' checked="checked"';
4057: $failsafe = 'zero';
1.400 raeburn 4058: $failsafechecked{'off'} = '';
1.399 raeburn 4059: }
1.274 raeburn 4060: }
1.14 raeburn 4061: } else {
4062: if ($autorun) {
4063: $runon = ' checked="checked" ';
4064: $runoff = ' ';
4065: } else {
4066: $runoff = ' checked="checked" ';
4067: $runon = ' ';
4068: }
1.3 raeburn 4069: }
4070: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 4071: my $notif_sender;
4072: if (ref($settings) eq 'HASH') {
4073: $notif_sender = $settings->{'sender_uname'};
4074: }
1.3 raeburn 4075: my $datatable='<tr class="LC_odd_row">'.
4076: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 4077: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 4078: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 4079: $runon.' value="1" />'.&mt('Yes').'</label> '.
4080: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 4081: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 4082: '</tr><tr>'.
4083: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 4084: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 4085: &mt('username').': '.
4086: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 4087: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 4088: ': '.$domform.'</span></td></tr>'.
4089: '<tr class="LC_odd_row">'.
4090: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
4091: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4092: '<input type="radio" name="autoassign_coowners"'.
4093: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
4094: '<label><input type="radio" name="autoassign_coowners"'.
4095: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 4096: '</tr><tr>'.
4097: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
1.400 raeburn 4098: '<td class="LC_left_item"><span class="LC_nobreak">'.
4099: '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="off" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'off'}.' />'.&mt('Not in use').'</label></span> '.
4100: '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="zero" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'zero'}.' />'.&mt('Retrieved section enrollment is zero').'</label></span><br />'.
4101: '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="any" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'any'}.' />'.&mt('Retrieved section enrollment is zero or greater').'</label></span>'.
1.399 raeburn 4102: '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
4103: '<span class="LC_nobreak">'.
4104: &mt('Threshold for number of students in section to drop: [_1]',
4105: '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
4106: '</span></div></td></tr>';
1.274 raeburn 4107: $$rowtotal += 4;
1.3 raeburn 4108: return $datatable;
4109: }
4110:
4111: sub print_autoupdate {
1.30 raeburn 4112: my ($position,$dom,$settings,$rowtotal) = @_;
1.385 raeburn 4113: my ($enable,$datatable);
1.3 raeburn 4114: if ($position eq 'top') {
1.385 raeburn 4115: my %choices = &Apache::lonlocal::texthash (
4116: run => 'Auto-update active?',
4117: classlists => 'Update information in classlists?',
4118: unexpired => 'Skip updates for users without active or future roles?',
4119: lastactive => 'Skip updates for inactive users?',
4120: );
4121: my $itemcount = 0;
1.3 raeburn 4122: my $updateon = ' ';
4123: my $updateoff = ' checked="checked" ';
4124: if (ref($settings) eq 'HASH') {
4125: if ($settings->{'run'} eq '1') {
4126: $updateon = $updateoff;
4127: $updateoff = ' ';
4128: }
4129: }
1.385 raeburn 4130: $enable = '<tr class="LC_odd_row">'.
4131: '<td>'.$choices{'run'}.'</td>'.
4132: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 4133: '<input type="radio" name="autoupdate_run"'.
1.397 raeburn 4134: $updateoff.'value="0" />'.&mt('No').'</label> '.
1.8 raeburn 4135: '<label><input type="radio" name="autoupdate_run"'.
1.385 raeburn 4136: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 4137: '</tr>';
1.385 raeburn 4138: my @toggles = ('classlists','unexpired');
4139: my %defaultchecked = ('classlists' => 'off',
4140: 'unexpired' => 'off'
4141: );
4142: $$rowtotal ++;
4143: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4144: \%choices,$itemcount,'','','left','no');
4145: $datatable = $enable.$datatable;
4146: $$rowtotal += $itemcount;
4147: my $lastactiveon = ' ';
4148: my $lastactiveoff = ' checked="checked" ';
4149: my $lastactivestyle = 'none';
4150: my $lastactivedays;
4151: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
4152: if (ref($settings) eq 'HASH') {
4153: if ($settings->{'lastactive'} =~ /^\d+$/) {
4154: $lastactiveon = $lastactiveoff;
4155: $lastactiveoff = ' ';
4156: $lastactivestyle = 'inline-block';
4157: $lastactivedays = $settings->{'lastactive'};
4158: }
4159: }
4160: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4161: $datatable .= '<tr'.$css_class.'>'.
4162: '<td>'.$choices{'lastactive'}.'</td>'.
4163: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
4164: '<input type="radio" name="lastactive"'.
4165: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
4166: ' <label>'.
4167: '<input type="radio" name="lastactive"'.
4168: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
4169: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
4170: ': '.&mt('inactive = no activity in last [_1] days',
4171: '<input type="text" size="5" name="lastactivedays" value="'.
4172: $lastactivedays.'" />').
4173: '</span></td>'.
4174: '</tr>';
4175: $$rowtotal ++;
1.131 raeburn 4176: } elsif ($position eq 'middle') {
4177: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4178: my $numinrow = 3;
4179: my $locknamesettings;
4180: $datatable .= &insttypes_row($settings,$types,$usertypes,
4181: $dom,$numinrow,$othertitle,
1.305 raeburn 4182: 'lockablenames',$rowtotal);
1.131 raeburn 4183: $$rowtotal ++;
1.3 raeburn 4184: } else {
1.44 raeburn 4185: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 4186: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 4187: 'permanentemail','id');
1.33 raeburn 4188: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 4189: my $numrows = 0;
1.26 raeburn 4190: if (ref($types) eq 'ARRAY') {
4191: if (@{$types} > 0) {
4192: $datatable =
4193: &usertype_update_row($settings,$usertypes,\%fieldtitles,
4194: \@fields,$types,\$numrows);
1.30 raeburn 4195: $$rowtotal += @{$types};
1.26 raeburn 4196: }
1.3 raeburn 4197: }
4198: $datatable .=
4199: &usertype_update_row($settings,{'default' => $othertitle},
4200: \%fieldtitles,\@fields,['default'],
4201: \$numrows);
1.30 raeburn 4202: $$rowtotal ++;
1.3 raeburn 4203: }
4204: return $datatable;
4205: }
4206:
1.125 raeburn 4207: sub print_autocreate {
4208: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 4209: my (%createon,%createoff,%currhash);
1.125 raeburn 4210: my @types = ('xml','req');
4211: if (ref($settings) eq 'HASH') {
4212: foreach my $item (@types) {
4213: $createoff{$item} = ' checked="checked" ';
4214: $createon{$item} = ' ';
4215: if (exists($settings->{$item})) {
4216: if ($settings->{$item}) {
4217: $createon{$item} = ' checked="checked" ';
4218: $createoff{$item} = ' ';
4219: }
4220: }
4221: }
1.210 raeburn 4222: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 4223: $currhash{$settings->{'xmldc'}} = 1;
4224: }
1.125 raeburn 4225: } else {
4226: foreach my $item (@types) {
4227: $createoff{$item} = ' checked="checked" ';
4228: $createon{$item} = ' ';
4229: }
4230: }
4231: $$rowtotal += 2;
1.191 raeburn 4232: my $numinrow = 2;
1.125 raeburn 4233: my $datatable='<tr class="LC_odd_row">'.
4234: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
4235: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4236: '<input type="radio" name="autocreate_xml"'.
4237: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
4238: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 4239: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
4240: '</td></tr><tr>'.
4241: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
4242: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4243: '<input type="radio" name="autocreate_req"'.
4244: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
4245: '<label><input type="radio" name="autocreate_req"'.
4246: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 4247: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4248: 'autocreate_xmldc',%currhash);
1.247 raeburn 4249: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 4250: if ($numdc > 1) {
1.247 raeburn 4251: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
4252: '</td><td class="LC_left_item">';
1.125 raeburn 4253: } else {
1.247 raeburn 4254: $datatable .= &mt('Course creation processed as:').
4255: '</td><td class="LC_right_item">';
1.125 raeburn 4256: }
1.247 raeburn 4257: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 4258: $$rowtotal += $rows;
1.125 raeburn 4259: return $datatable;
4260: }
4261:
1.23 raeburn 4262: sub print_directorysrch {
1.277 raeburn 4263: my ($position,$dom,$settings,$rowtotal) = @_;
4264: my $datatable;
4265: if ($position eq 'top') {
4266: my $instsrchon = ' ';
4267: my $instsrchoff = ' checked="checked" ';
4268: my ($exacton,$containson,$beginson);
4269: my $instlocalon = ' ';
4270: my $instlocaloff = ' checked="checked" ';
4271: if (ref($settings) eq 'HASH') {
4272: if ($settings->{'available'} eq '1') {
4273: $instsrchon = $instsrchoff;
4274: $instsrchoff = ' ';
4275: }
4276: if ($settings->{'localonly'} eq '1') {
4277: $instlocalon = $instlocaloff;
4278: $instlocaloff = ' ';
4279: }
4280: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
4281: foreach my $type (@{$settings->{'searchtypes'}}) {
4282: if ($type eq 'exact') {
4283: $exacton = ' checked="checked" ';
4284: } elsif ($type eq 'contains') {
4285: $containson = ' checked="checked" ';
4286: } elsif ($type eq 'begins') {
4287: $beginson = ' checked="checked" ';
4288: }
4289: }
4290: } else {
4291: if ($settings->{'searchtypes'} eq 'exact') {
4292: $exacton = ' checked="checked" ';
4293: } elsif ($settings->{'searchtypes'} eq 'contains') {
4294: $containson = ' checked="checked" ';
4295: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 4296: $exacton = ' checked="checked" ';
4297: $containson = ' checked="checked" ';
4298: }
4299: }
1.277 raeburn 4300: }
4301: my ($searchtitles,$titleorder) = &sorted_searchtitles();
4302: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4303:
4304: my $numinrow = 4;
4305: my $cansrchrow = 0;
4306: $datatable='<tr class="LC_odd_row">'.
4307: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
4308: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4309: '<input type="radio" name="dirsrch_available"'.
4310: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
4311: '<label><input type="radio" name="dirsrch_available"'.
4312: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4313: '</tr><tr>'.
4314: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
4315: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4316: '<input type="radio" name="dirsrch_instlocalonly"'.
4317: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4318: '<label><input type="radio" name="dirsrch_instlocalonly"'.
4319: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4320: '</tr>';
4321: $$rowtotal += 2;
4322: if (ref($usertypes) eq 'HASH') {
4323: if (keys(%{$usertypes}) > 0) {
4324: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 4325: $numinrow,$othertitle,'cansearch',
4326: $rowtotal);
1.277 raeburn 4327: $cansrchrow = 1;
1.25 raeburn 4328: }
1.23 raeburn 4329: }
1.277 raeburn 4330: if ($cansrchrow) {
4331: $$rowtotal ++;
4332: $datatable .= '<tr>';
4333: } else {
4334: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 4335: }
1.277 raeburn 4336: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
4337: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
4338: foreach my $title (@{$titleorder}) {
4339: if (defined($searchtitles->{$title})) {
4340: my $check = ' ';
4341: if (ref($settings) eq 'HASH') {
4342: if (ref($settings->{'searchby'}) eq 'ARRAY') {
4343: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
4344: $check = ' checked="checked" ';
4345: }
1.39 raeburn 4346: }
1.25 raeburn 4347: }
1.277 raeburn 4348: $datatable .= '<td class="LC_left_item">'.
4349: '<span class="LC_nobreak"><label>'.
4350: '<input type="checkbox" name="searchby" '.
4351: 'value="'.$title.'"'.$check.'/>'.
4352: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 4353: }
4354: }
1.277 raeburn 4355: $datatable .= '</tr></table></td></tr>';
4356: $$rowtotal ++;
4357: if ($cansrchrow) {
4358: $datatable .= '<tr class="LC_odd_row">';
4359: } else {
4360: $datatable .= '<tr>';
4361: }
4362: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
4363: '<td class="LC_left_item" colspan="2">'.
4364: '<span class="LC_nobreak"><label>'.
4365: '<input type="checkbox" name="searchtypes" '.
4366: $exacton.' value="exact" />'.&mt('Exact match').
4367: '</label> '.
4368: '<label><input type="checkbox" name="searchtypes" '.
4369: $beginson.' value="begins" />'.&mt('Begins with').
4370: '</label> '.
4371: '<label><input type="checkbox" name="searchtypes" '.
4372: $containson.' value="contains" />'.&mt('Contains').
4373: '</label></span></td></tr>';
4374: $$rowtotal ++;
1.26 raeburn 4375: } else {
1.277 raeburn 4376: my $domsrchon = ' checked="checked" ';
4377: my $domsrchoff = ' ';
4378: my $domlocalon = ' ';
4379: my $domlocaloff = ' checked="checked" ';
4380: if (ref($settings) eq 'HASH') {
4381: if ($settings->{'lclocalonly'} eq '1') {
4382: $domlocalon = $domlocaloff;
4383: $domlocaloff = ' ';
4384: }
4385: if ($settings->{'lcavailable'} eq '0') {
4386: $domsrchoff = $domsrchon;
4387: $domsrchon = ' ';
4388: }
4389: }
4390: $datatable='<tr class="LC_odd_row">'.
4391: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
4392: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4393: '<input type="radio" name="dirsrch_domavailable"'.
4394: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
4395: '<label><input type="radio" name="dirsrch_domavailable"'.
4396: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4397: '</tr><tr>'.
4398: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
4399: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4400: '<input type="radio" name="dirsrch_domlocalonly"'.
4401: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4402: '<label><input type="radio" name="dirsrch_domlocalonly"'.
4403: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4404: '</tr>';
4405: $$rowtotal += 2;
1.26 raeburn 4406: }
1.25 raeburn 4407: return $datatable;
4408: }
4409:
1.28 raeburn 4410: sub print_contacts {
1.286 raeburn 4411: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 4412: my $datatable;
4413: my @contacts = ('adminemail','supportemail');
1.286 raeburn 4414: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340 raeburn 4415: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286 raeburn 4416: if ($position eq 'top') {
4417: if (ref($settings) eq 'HASH') {
4418: foreach my $item (@contacts) {
4419: if (exists($settings->{$item})) {
4420: $to{$item} = $settings->{$item};
4421: }
4422: }
4423: }
4424: } elsif ($position eq 'middle') {
4425: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350 raeburn 4426: 'updatesmail','idconflictsmail','hostipmail');
1.288 raeburn 4427: foreach my $type (@mailings) {
4428: $otheremails{$type} = '';
4429: }
1.340 raeburn 4430: } elsif ($position eq 'lower') {
4431: if (ref($settings) eq 'HASH') {
4432: if (ref($settings->{'lonstatus'}) eq 'HASH') {
4433: %lonstatus = %{$settings->{'lonstatus'}};
4434: }
4435: }
1.286 raeburn 4436: } else {
4437: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 4438: foreach my $type (@mailings) {
4439: $otheremails{$type} = '';
4440: }
1.286 raeburn 4441: $bccemails{'helpdeskmail'} = '';
4442: $bccemails{'otherdomsmail'} = '';
4443: $includestr{'helpdeskmail'} = '';
4444: $includestr{'otherdomsmail'} = '';
4445: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
4446: }
1.28 raeburn 4447: if (ref($settings) eq 'HASH') {
1.340 raeburn 4448: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4449: foreach my $type (@mailings) {
4450: if (exists($settings->{$type})) {
4451: if (ref($settings->{$type}) eq 'HASH') {
4452: foreach my $item (@contacts) {
4453: if ($settings->{$type}{$item}) {
4454: $checked{$type}{$item} = ' checked="checked" ';
4455: }
4456: }
4457: $otheremails{$type} = $settings->{$type}{'others'};
4458: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4459: $bccemails{$type} = $settings->{$type}{'bcc'};
4460: if ($settings->{$type}{'include'} ne '') {
4461: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4462: $includestr{$type} = &unescape($includestr{$type});
4463: }
4464: }
4465: }
4466: } elsif ($type eq 'lonstatusmail') {
4467: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
4468: }
1.28 raeburn 4469: }
4470: }
1.286 raeburn 4471: if ($position eq 'bottom') {
4472: foreach my $type (@mailings) {
4473: $bccemails{$type} = $settings->{$type}{'bcc'};
4474: if ($settings->{$type}{'include'} ne '') {
4475: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4476: $includestr{$type} = &unescape($includestr{$type});
4477: }
4478: }
4479: if (ref($settings->{'helpform'}) eq 'HASH') {
4480: if (ref($fields) eq 'ARRAY') {
4481: foreach my $field (@{$fields}) {
4482: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 4483: }
1.286 raeburn 4484: }
4485: if (exists($settings->{'helpform'}{'maxsize'})) {
4486: $maxsize = $settings->{'helpform'}{'maxsize'};
4487: } else {
1.289 raeburn 4488: $maxsize = '1.0';
1.286 raeburn 4489: }
4490: } else {
4491: if (ref($fields) eq 'ARRAY') {
4492: foreach my $field (@{$fields}) {
4493: $currfield{$field} = 'yes';
1.134 raeburn 4494: }
1.28 raeburn 4495: }
1.286 raeburn 4496: $maxsize = '1.0';
1.28 raeburn 4497: }
4498: }
4499: } else {
1.286 raeburn 4500: if ($position eq 'top') {
4501: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
4502: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
4503: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
4504: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 4505: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4506: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
4507: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
4508: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350 raeburn 4509: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4510: } elsif ($position eq 'bottom') {
4511: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
4512: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
4513: if (ref($fields) eq 'ARRAY') {
4514: foreach my $field (@{$fields}) {
4515: $currfield{$field} = 'yes';
4516: }
4517: }
4518: $maxsize = '1.0';
4519: }
1.28 raeburn 4520: }
4521: my ($titles,$short_titles) = &contact_titles();
4522: my $rownum = 0;
4523: my $css_class;
1.286 raeburn 4524: if ($position eq 'top') {
4525: foreach my $item (@contacts) {
4526: $css_class = $rownum%2?' class="LC_odd_row"':'';
4527: $datatable .= '<tr'.$css_class.'>'.
4528: '<td><span class="LC_nobreak">'.$titles->{$item}.
4529: '</span></td><td class="LC_right_item">'.
4530: '<input type="text" name="'.$item.'" value="'.
4531: $to{$item}.'" /></td></tr>';
4532: $rownum ++;
4533: }
1.315 raeburn 4534: } elsif ($position eq 'bottom') {
4535: $css_class = $rownum%2?' class="LC_odd_row"':'';
4536: $datatable .= '<tr'.$css_class.'>'.
4537: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
4538: &mt('(e-mail, subject, and description always shown)').
4539: '</td><td class="LC_left_item">';
4540: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
4541: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
4542: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
4543: foreach my $field (@{$fields}) {
4544: $datatable .= '<tr><td>'.$fieldtitles->{$field};
4545: if (($field eq 'screenshot') || ($field eq 'cc')) {
4546: $datatable .= ' '.&mt('(logged-in users)');
4547: }
4548: $datatable .='</td><td>';
4549: my $clickaction;
4550: if ($field eq 'screenshot') {
4551: $clickaction = ' onclick="screenshotSize(this);"';
4552: }
4553: if (ref($possoptions->{$field}) eq 'ARRAY') {
4554: foreach my $option (@{$possoptions->{$field}}) {
4555: my $checked;
4556: if ($currfield{$field} eq $option) {
4557: $checked = ' checked="checked"';
4558: }
4559: $datatable .= '<span class="LC_nobreak"><label>'.
4560: '<input type="radio" name="helpform_'.$field.'" '.
4561: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
4562: '</label></span>'.(' 'x2);
4563: }
4564: }
4565: if ($field eq 'screenshot') {
4566: my $display;
4567: if ($currfield{$field} eq 'no') {
4568: $display = ' style="display:none"';
4569: }
1.334 raeburn 4570: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315 raeburn 4571: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
4572: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
4573: }
4574: $datatable .= '</td></tr>';
4575: }
4576: $datatable .= '</table>';
4577: }
4578: $datatable .= '</td></tr>'."\n";
4579: $rownum ++;
4580: }
1.340 raeburn 4581: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4582: foreach my $type (@mailings) {
4583: $css_class = $rownum%2?' class="LC_odd_row"':'';
4584: $datatable .= '<tr'.$css_class.'>'.
4585: '<td><span class="LC_nobreak">'.
4586: $titles->{$type}.': </span></td>'.
4587: '<td class="LC_left_item">';
4588: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4589: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
4590: }
4591: $datatable .= '<span class="LC_nobreak">';
4592: foreach my $item (@contacts) {
4593: $datatable .= '<label>'.
4594: '<input type="checkbox" name="'.$type.'"'.
4595: $checked{$type}{$item}.
4596: ' value="'.$item.'" />'.$short_titles->{$item}.
4597: '</label> ';
4598: }
4599: $datatable .= '</span><br />'.&mt('Others').': '.
4600: '<input type="text" name="'.$type.'_others" '.
4601: 'value="'.$otheremails{$type}.'" />';
4602: my %locchecked;
4603: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4604: foreach my $loc ('s','b') {
4605: if ($includeloc{$type} eq $loc) {
4606: $locchecked{$loc} = ' checked="checked"';
4607: last;
4608: }
4609: }
4610: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
4611: '<input type="text" name="'.$type.'_bcc" '.
4612: 'value="'.$bccemails{$type}.'" /></fieldset>'.
4613: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4614: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4615: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286 raeburn 4616: '<span class="LC_nobreak">'.&mt('Location:').' '.
4617: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4618: (' 'x2).
4619: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4620: '</span></fieldset>';
4621: }
4622: $datatable .= '</td></tr>'."\n";
4623: $rownum ++;
4624: }
1.28 raeburn 4625: }
1.286 raeburn 4626: if ($position eq 'middle') {
4627: my %choices;
1.340 raeburn 4628: my $corelink = &core_link_msu();
4629: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286 raeburn 4630: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340 raeburn 4631: $corelink);
4632: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
4633: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286 raeburn 4634: my %defaultchecked = ('reporterrors' => 'on',
1.340 raeburn 4635: 'reportupdates' => 'on',
4636: 'reportstatus' => 'on');
1.286 raeburn 4637: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4638: \%choices,$rownum);
4639: $datatable .= $reports;
1.340 raeburn 4640: } elsif ($position eq 'lower') {
1.378 raeburn 4641: my (%current,%excluded,%weights);
1.340 raeburn 4642: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
4643: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.378 raeburn 4644: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.340 raeburn 4645: } else {
1.378 raeburn 4646: $current{'errorthreshold'} = $defaults->{'threshold'};
1.340 raeburn 4647: }
4648: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.378 raeburn 4649: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.340 raeburn 4650: } else {
1.378 raeburn 4651: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.340 raeburn 4652: }
4653: if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341 raeburn 4654: foreach my $type ('E','W','N','U') {
1.340 raeburn 4655: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
4656: $weights{$type} = $lonstatus{'weights'}{$type};
4657: } else {
4658: $weights{$type} = $defaults->{$type};
4659: }
4660: }
4661: } else {
1.341 raeburn 4662: foreach my $type ('E','W','N','U') {
1.340 raeburn 4663: $weights{$type} = $defaults->{$type};
4664: }
4665: }
4666: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
4667: if (@{$lonstatus{'excluded'}} > 0) {
4668: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
4669: }
4670: }
1.425 raeburn 4671: foreach my $item ('errorthreshold','errorsysmail') {
1.378 raeburn 4672: $css_class = $rownum%2?' class="LC_odd_row"':'';
4673: $datatable .= '<tr'.$css_class.'>'.
4674: '<td class="LC_left_item"><span class="LC_nobreak">'.
4675: $titles->{$item}.
4676: '</span></td><td class="LC_left_item">'.
4677: '<input type="text" name="'.$item.'" value="'.
4678: $current{$item}.'" size="5" /></td></tr>';
4679: $rownum ++;
4680: }
1.340 raeburn 4681: $css_class = $rownum%2?' class="LC_odd_row"':'';
4682: $datatable .= '<tr'.$css_class.'>'.
4683: '<td class="LC_left_item">'.
4684: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
4685: '</span></td><td class="LC_left_item"><table><tr>';
1.341 raeburn 4686: foreach my $type ('E','W','N','U') {
1.340 raeburn 4687: $datatable .= '<td>'.$names->{$type}.'<br />'.
4688: '<input type="text" name="errorweights_'.$type.'" value="'.
4689: $weights{$type}.'" size="5" /></td>';
4690: }
4691: $datatable .= '</tr></table></tr>';
4692: $rownum ++;
4693: $css_class = $rownum%2?' class="LC_odd_row"':'';
4694: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
4695: $titles->{'errorexcluded'}.'</td>'.
4696: '<td class="LC_left_item"><table>';
4697: my $numinrow = 4;
4698: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
4699: for (my $i=0; $i<@ids; $i++) {
4700: my $rem = $i%($numinrow);
4701: if ($rem == 0) {
4702: if ($i > 0) {
4703: $datatable .= '</tr>';
4704: }
4705: $datatable .= '<tr>';
4706: }
4707: my $check;
4708: if ($excluded{$ids[$i]}) {
4709: $check = ' checked="checked" ';
4710: }
4711: $datatable .= '<td class="LC_left_item">'.
4712: '<span class="LC_nobreak"><label>'.
4713: '<input type="checkbox" name="errorexcluded" '.
4714: 'value="'.$ids[$i].'"'.$check.' />'.
4715: $ids[$i].'</label></span></td>';
4716: }
4717: my $colsleft = $numinrow - @ids%($numinrow);
4718: if ($colsleft > 1 ) {
4719: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4720: ' </td>';
4721: } elsif ($colsleft == 1) {
4722: $datatable .= '<td class="LC_left_item"> </td>';
4723: }
4724: $datatable .= '</tr></table></td></tr>';
4725: $rownum ++;
1.286 raeburn 4726: } elsif ($position eq 'bottom') {
1.315 raeburn 4727: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4728: my (@posstypes,%usertypeshash);
4729: if (ref($types) eq 'ARRAY') {
4730: @posstypes = @{$types};
4731: }
4732: if (@posstypes) {
4733: if (ref($usertypes) eq 'HASH') {
4734: %usertypeshash = %{$usertypes};
4735: }
4736: my @overridden;
4737: my $numinrow = 4;
4738: if (ref($settings) eq 'HASH') {
4739: if (ref($settings->{'overrides'}) eq 'HASH') {
4740: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
4741: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
4742: push(@overridden,$key);
4743: foreach my $item (@contacts) {
4744: if ($settings->{'overrides'}{$key}{$item}) {
4745: $checked{'override_'.$key}{$item} = ' checked="checked" ';
4746: }
4747: }
4748: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
4749: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
4750: $includeloc{'override_'.$key} = '';
4751: $includestr{'override_'.$key} = '';
4752: if ($settings->{'overrides'}{$key}{'include'} ne '') {
1.425 raeburn 4753: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
1.315 raeburn 4754: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
4755: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
4756: }
1.286 raeburn 4757: }
4758: }
4759: }
1.315 raeburn 4760: }
4761: my $customclass = 'LC_helpdesk_override';
4762: my $optionsprefix = 'LC_options_helpdesk_';
4763:
4764: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
4765: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
4766: $numinrow,$othertitle,'overrides',
4767: \$rownum,$onclicktypes,$customclass);
4768: $rownum ++;
4769: $usertypeshash{'default'} = $othertitle;
4770: foreach my $status (@posstypes) {
4771: my $css_class;
4772: if ($rownum%2) {
4773: $css_class = 'LC_odd_row ';
4774: }
4775: $css_class .= $customclass;
4776: my $rowid = $optionsprefix.$status;
4777: my $hidden = 1;
4778: my $currstyle = 'display:none';
4779: if (grep(/^\Q$status\E$/,@overridden)) {
4780: $currstyle = 'display:table-row';
4781: $hidden = 0;
4782: }
4783: my $key = 'override_'.$status;
4784: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
4785: $includeloc{$key},$includestr{$key},$status,$rowid,
4786: $usertypeshash{$status},$css_class,$currstyle,
4787: \@contacts,$short_titles);
4788: unless ($hidden) {
4789: $rownum ++;
1.286 raeburn 4790: }
4791: }
1.134 raeburn 4792: }
1.28 raeburn 4793: }
1.30 raeburn 4794: $$rowtotal += $rownum;
1.28 raeburn 4795: return $datatable;
4796: }
4797:
1.340 raeburn 4798: sub core_link_msu {
4799: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
4800: &mt('LON-CAPA core group - MSU'),600,500);
4801: }
4802:
1.315 raeburn 4803: sub overridden_helpdesk {
4804: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
4805: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
4806: my $class = 'LC_left_item';
4807: if ($css_class) {
4808: $css_class = ' class="'.$css_class.'"';
4809: }
4810: if ($rowid) {
4811: $rowid = ' id="'.$rowid.'"';
4812: }
4813: if ($rowstyle) {
4814: $rowstyle = ' style="'.$rowstyle.'"';
4815: }
4816: my ($output,$description);
4817: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
4818: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
4819: "<td>$description</td>\n".
4820: '<td class="'.$class.'" colspan="2">'.
4821: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
4822: '<span class="LC_nobreak">';
4823: if (ref($contacts) eq 'ARRAY') {
4824: foreach my $item (@{$contacts}) {
4825: my $check;
4826: if (ref($checked) eq 'HASH') {
4827: $check = $checked->{$item};
4828: }
4829: my $title;
4830: if (ref($short_titles) eq 'HASH') {
1.425 raeburn 4831: $title = $short_titles->{$item};
1.315 raeburn 4832: }
4833: $output .= '<label>'.
4834: '<input type="checkbox" name="override_'.$type.'"'.$check.
4835: ' value="'.$item.'" />'.$title.'</label> ';
4836: }
4837: }
4838: $output .= '</span><br />'.&mt('Others').': '.
4839: '<input type="text" name="override_'.$type.'_others" '.
4840: 'value="'.$otheremails.'" />';
4841: my %locchecked;
4842: foreach my $loc ('s','b') {
4843: if ($includeloc eq $loc) {
4844: $locchecked{$loc} = ' checked="checked"';
4845: last;
4846: }
4847: }
4848: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4849: '<input type="text" name="override_'.$type.'_bcc" '.
4850: 'value="'.$bccemails.'" /></fieldset>'.
4851: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4852: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4853: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315 raeburn 4854: '<span class="LC_nobreak">'.&mt('Location:').' '.
4855: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4856: (' 'x2).
4857: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4858: '</span></fieldset>'.
4859: '</td></tr>'."\n";
4860: return $output;
4861: }
4862:
1.286 raeburn 4863: sub contacts_javascript {
4864: return <<"ENDSCRIPT";
4865:
4866: <script type="text/javascript">
4867: // <![CDATA[
4868:
4869: function screenshotSize(field) {
4870: if (document.getElementById('help_screenshotsize')) {
4871: if (field.value == 'no') {
1.289 raeburn 4872: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 4873: } else {
4874: document.getElementById('help_screenshotsize').style.display="";
4875: }
4876: }
4877: return;
4878: }
4879:
1.315 raeburn 4880: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4881: if (form.elements[checkbox].length != undefined) {
4882: var count = 0;
4883: if (docount) {
4884: for (var i=0; i<form.elements[checkbox].length; i++) {
4885: if (form.elements[checkbox][i].checked) {
4886: count ++;
4887: }
4888: }
4889: }
4890: for (var i=0; i<form.elements[checkbox].length; i++) {
4891: var type = form.elements[checkbox][i].value;
4892: if (document.getElementById(prefix+type)) {
4893: if (form.elements[checkbox][i].checked) {
4894: document.getElementById(prefix+type).style.display = 'table-row';
4895: if (count % 2 == 1) {
4896: document.getElementById(prefix+type).className = target+' LC_odd_row';
4897: } else {
4898: document.getElementById(prefix+type).className = target;
4899: }
4900: count ++;
4901: } else {
4902: document.getElementById(prefix+type).style.display = 'none';
4903: }
4904: }
4905: }
4906: }
4907: return;
4908: }
4909:
1.286 raeburn 4910: // ]]>
4911: </script>
4912:
4913: ENDSCRIPT
4914: }
4915:
1.118 jms 4916: sub print_helpsettings {
1.282 raeburn 4917: my ($position,$dom,$settings,$rowtotal) = @_;
4918: my $confname = $dom.'-domainconfig';
1.285 raeburn 4919: my $formname = 'display';
1.168 raeburn 4920: my ($datatable,$itemcount);
1.282 raeburn 4921: if ($position eq 'top') {
4922: $itemcount = 1;
4923: my (%choices,%defaultchecked,@toggles);
4924: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4925: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4926: &mt('LON-CAPA bug tracker'),600,500));
4927: %defaultchecked = ('submitbugs' => 'on');
4928: @toggles = ('submitbugs');
4929: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4930: \%choices,$itemcount);
4931: $$rowtotal ++;
4932: } else {
4933: my $css_class;
4934: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 4935: my (%customroles,%ordered,%current);
1.301 raeburn 4936: if (ref($settings) eq 'HASH') {
4937: if (ref($settings->{'adhoc'}) eq 'HASH') {
4938: %current = %{$settings->{'adhoc'}};
4939: }
1.285 raeburn 4940: }
4941: my $count = 0;
4942: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 4943: if ($key=~/^rolesdef\_(\w+)$/) {
4944: my $rolename = $1;
1.285 raeburn 4945: my (%privs,$order);
1.282 raeburn 4946: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4947: $customroles{$rolename} = \%privs;
1.285 raeburn 4948: if (ref($current{$rolename}) eq 'HASH') {
4949: $order = $current{$rolename}{'order'};
4950: }
4951: if ($order eq '') {
4952: $order = $count;
4953: }
4954: $ordered{$order} = $rolename;
4955: $count++;
4956: }
4957: }
4958: my $maxnum = scalar(keys(%ordered));
4959: my @roles_by_num = ();
4960: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4961: push(@roles_by_num,$item);
4962: }
4963: my $context = 'domprefs';
4964: my $crstype = 'Course';
4965: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 4966: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 4967: my ($numstatustypes,@jsarray);
4968: if (ref($types) eq 'ARRAY') {
4969: if (@{$types} > 0) {
4970: $numstatustypes = scalar(@{$types});
4971: push(@accesstypes,'status');
4972: @jsarray = ('bystatus');
1.282 raeburn 4973: }
4974: }
1.290 raeburn 4975: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 4976: if (keys(%domhelpdesk)) {
4977: push(@accesstypes,('inc','exc'));
4978: push(@jsarray,('notinc','notexc'));
4979: }
4980: my $hiddenstr = join("','",@jsarray);
1.282 raeburn 4981: my $context = 'domprefs';
4982: my $crstype = 'Course';
1.285 raeburn 4983: my $prefix = 'helproles_';
4984: my $add_class = 'LC_hidden';
4985: foreach my $num (@roles_by_num) {
4986: my $role = $ordered{$num};
4987: my ($desc,$access,@statuses);
4988: if (ref($current{$role}) eq 'HASH') {
4989: $desc = $current{$role}{'desc'};
4990: $access = $current{$role}{'access'};
4991: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4992: @statuses = @{$current{$role}{'insttypes'}};
4993: }
4994: }
4995: if ($desc eq '') {
4996: $desc = $role;
4997: }
4998: my $identifier = 'custhelp'.$num;
1.282 raeburn 4999: my %full=();
5000: my %levels= (
5001: course => {},
5002: domain => {},
5003: system => {},
5004: );
5005: my %levelscurrent=(
5006: course => {},
5007: domain => {},
5008: system => {},
5009: );
5010: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
5011: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
5012: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 5013: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 5014: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 5015: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
5016: for (my $k=0; $k<=$maxnum; $k++) {
5017: my $vpos = $k+1;
5018: my $selstr;
5019: if ($k == $num) {
5020: $selstr = ' selected="selected" ';
5021: }
5022: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5023: }
5024: $datatable .= '</select>'.(' 'x2).
5025: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
5026: '</td>'.
5027: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
5028: &mt('Name shown to users:').
5029: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
5030: '</fieldset>'.
5031: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
5032: $othertitle,$usertypes,$types,\%domhelpdesk).
5033: '<fieldset>'.
5034: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 5035: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 5036: \%levelscurrent,$identifier,
5037: 'LC_hidden',$prefix.$num.'_privs').
5038: '</fieldset></td>';
1.282 raeburn 5039: $itemcount ++;
5040: }
5041: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5042: my $newcust = 'custhelp'.$count;
5043: my (%privs,%levelscurrent);
5044: my %full=();
5045: my %levels= (
5046: course => {},
5047: domain => {},
5048: system => {},
5049: );
5050: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
5051: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 5052: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 5053: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 5054: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
5055: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
5056: for (my $k=0; $k<$maxnum+1; $k++) {
5057: my $vpos = $k+1;
5058: my $selstr;
5059: if ($k == $maxnum) {
5060: $selstr = ' selected="selected" ';
5061: }
5062: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5063: }
5064: $datatable .= '</select> '."\n".
1.282 raeburn 5065: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
5066: '</label></span></td>'.
1.285 raeburn 5067: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
5068: '<span class="LC_nobreak">'.
5069: &mt('Internal name:').
5070: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
5071: '</span>'.(' 'x4).
5072: '<span class="LC_nobreak">'.
5073: &mt('Name shown to users:').
5074: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
5075: '</span></fieldset>'.
5076: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
5077: $usertypes,$types,\%domhelpdesk).
5078: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 5079: &Apache::lonuserutils::custom_role_header($context,$crstype,
5080: \@templateroles,$newcust).
5081: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
5082: \%levelscurrent,$newcust).
1.334 raeburn 5083: '</fieldset>'.
5084: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
5085: '</td></tr>';
1.282 raeburn 5086: $count ++;
5087: $$rowtotal += $count;
5088: }
1.166 raeburn 5089: return $datatable;
1.121 raeburn 5090: }
5091:
1.285 raeburn 5092: sub adhocbutton {
5093: my ($prefix,$num,$field,$visibility) = @_;
5094: my %lt = &Apache::lonlocal::texthash(
5095: show => 'Show details',
5096: hide => 'Hide details',
5097: );
5098: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
5099: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
5100: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
5101: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
5102: }
5103:
5104: sub helpsettings_javascript {
5105: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
5106: return unless(ref($roles_by_num) eq 'ARRAY');
5107: my %html_js_lt = &Apache::lonlocal::texthash(
5108: show => 'Show details',
5109: hide => 'Hide details',
5110: );
5111: &html_escape(\%html_js_lt);
5112: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
5113: return <<"ENDSCRIPT";
5114: <script type="text/javascript">
5115: // <![CDATA[
5116:
5117: function reorderHelpRoles(form,item) {
5118: var changedVal;
5119: $jstext
5120: var newpos = 'helproles_${total}_pos';
5121: var maxh = 1 + $total;
5122: var current = new Array();
5123: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5124: if (item == newpos) {
5125: changedVal = newitemVal;
5126: } else {
5127: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5128: current[newitemVal] = newpos;
5129: }
5130: for (var i=0; i<helproles.length; i++) {
5131: var elementName = 'helproles_'+helproles[i]+'_pos';
5132: if (elementName != item) {
5133: if (form.elements[elementName]) {
5134: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5135: current[currVal] = elementName;
5136: }
5137: }
5138: }
5139: var oldVal;
5140: for (var j=0; j<maxh; j++) {
5141: if (current[j] == undefined) {
5142: oldVal = j;
5143: }
5144: }
5145: if (oldVal < changedVal) {
5146: for (var k=oldVal+1; k<=changedVal ; k++) {
5147: var elementName = current[k];
5148: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5149: }
5150: } else {
5151: for (var k=changedVal; k<oldVal; k++) {
5152: var elementName = current[k];
5153: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5154: }
5155: }
5156: return;
5157: }
5158:
5159: function helpdeskAccess(num) {
5160: var curraccess = null;
5161: if (document.$formname.elements['helproles_'+num+'_access'].length) {
5162: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
5163: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
5164: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
5165: }
5166: }
5167: }
5168: var shown = Array();
5169: var hidden = Array();
5170: if (curraccess == 'none') {
5171: hidden = Array('$hiddenstr');
5172: } else {
5173: if (curraccess == 'status') {
5174: shown = Array('bystatus');
5175: hidden = Array('notinc','notexc');
5176: } else {
5177: if (curraccess == 'exc') {
5178: shown = Array('notexc');
5179: hidden = Array('notinc','bystatus');
5180: }
5181: if (curraccess == 'inc') {
5182: shown = Array('notinc');
5183: hidden = Array('notexc','bystatus');
5184: }
1.293 raeburn 5185: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 5186: hidden = Array('notinc','notexc','bystatus');
5187: }
5188: }
5189: }
5190: if (hidden.length > 0) {
5191: for (var i=0; i<hidden.length; i++) {
5192: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
5193: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
5194: }
5195: }
5196: }
5197: if (shown.length > 0) {
5198: for (var i=0; i<shown.length; i++) {
5199: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
5200: if (shown[i] == 'privs') {
5201: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
5202: } else {
5203: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
5204: }
5205: }
5206: }
5207: }
5208: return;
5209: }
5210:
5211: function toggleHelpdeskItem(num,field) {
5212: if (document.getElementById('helproles_'+num+'_'+field)) {
5213: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 5214: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 5215: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
5216: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5217: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
5218: }
5219: } else {
5220: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
5221: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5222: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
5223: }
5224: }
5225: }
5226: return;
5227: }
5228:
5229: // ]]>
5230: </script>
5231:
5232: ENDSCRIPT
5233: }
5234:
5235: sub helpdeskroles_access {
5236: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
5237: $usertypes,$types,$domhelpdesk) = @_;
5238: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
5239: my %lt = &Apache::lonlocal::texthash(
5240: 'rou' => 'Role usage',
5241: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 5242: 'all' => 'All with domain helpdesk or helpdesk assistant role',
5243: 'dh' => 'All with domain helpdesk role',
5244: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 5245: 'none' => 'None',
5246: 'status' => 'Determined based on institutional status',
5247: 'inc' => 'Include all, but exclude specific personnel',
5248: 'exc' => 'Exclude all, but include specific personnel',
5249: );
5250: my %usecheck = (
5251: all => ' checked="checked"',
5252: );
5253: my %displaydiv = (
5254: status => 'none',
5255: inc => 'none',
5256: exc => 'none',
5257: priv => 'block',
5258: );
5259: my $output;
5260: if (ref($current) eq 'HASH') {
5261: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
5262: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
5263: $usecheck{$current->{access}} = $usecheck{'all'};
5264: delete($usecheck{'all'});
5265: if ($current->{access} =~ /^(status|inc|exc)$/) {
5266: my $access = $1;
5267: $displaydiv{$access} = 'inline';
5268: } elsif ($current->{access} eq 'none') {
5269: $displaydiv{'priv'} = 'none';
5270: }
5271: }
5272: }
5273: }
5274: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
5275: '<p>'.$lt{'whi'}.'</p>';
5276: foreach my $access (@{$accesstypes}) {
5277: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
5278: ' onclick="helpdeskAccess('."'$num'".');" />'.
5279: $lt{$access}.'</label>';
5280: if ($access eq 'status') {
5281: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
5282: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
5283: $othertitle,$usertypes,$types).
5284: '</div>';
5285: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
5286: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
5287: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5288: '</div>';
5289: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
5290: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
5291: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5292: '</div>';
5293: }
5294: $output .= '</p>';
5295: }
5296: $output .= '</fieldset>';
5297: return $output;
5298: }
5299:
1.121 raeburn 5300: sub radiobutton_prefs {
1.192 raeburn 5301: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.385 raeburn 5302: $additional,$align,$firstval) = @_;
1.121 raeburn 5303: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
5304: (ref($choices) eq 'HASH'));
5305:
1.170 raeburn 5306: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 5307:
5308: foreach my $item (@{$toggles}) {
5309: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 5310: $checkedon{$item} = ' checked="checked" ';
5311: $checkedoff{$item} = ' ';
1.121 raeburn 5312: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 5313: $checkedoff{$item} = ' checked="checked" ';
5314: $checkedon{$item} = ' ';
5315: }
5316: }
5317: if (ref($settings) eq 'HASH') {
1.121 raeburn 5318: foreach my $item (@{$toggles}) {
1.118 jms 5319: if ($settings->{$item} eq '1') {
5320: $checkedon{$item} = ' checked="checked" ';
5321: $checkedoff{$item} = ' ';
5322: } elsif ($settings->{$item} eq '0') {
5323: $checkedoff{$item} = ' checked="checked" ';
5324: $checkedon{$item} = ' ';
5325: }
5326: }
1.121 raeburn 5327: }
1.192 raeburn 5328: if ($onclick) {
5329: $onclick = ' onclick="'.$onclick.'"';
5330: }
1.121 raeburn 5331: foreach my $item (@{$toggles}) {
1.118 jms 5332: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 5333: $datatable .=
1.306 raeburn 5334: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 5335: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 5336: '</span></td>';
5337: if ($align eq 'left') {
5338: $datatable .= '<td class="LC_left_item">';
5339: } else {
5340: $datatable .= '<td class="LC_right_item">';
5341: }
1.385 raeburn 5342: $datatable .= '<span class="LC_nobreak">';
5343: if ($firstval eq 'no') {
5344: $datatable .=
5345: '<label><input type="radio" name="'.
5346: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
5347: '</label> <label><input type="radio" name="'.$item.'" '.
5348: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
5349: } else {
5350: $datatable .=
5351: '<label><input type="radio" name="'.
5352: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
5353: '</label> <label><input type="radio" name="'.$item.'" '.
5354: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
5355: }
5356: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 5357: $itemcount ++;
1.121 raeburn 5358: }
5359: return ($datatable,$itemcount);
5360: }
5361:
1.267 raeburn 5362: sub print_ltitools {
1.421 raeburn 5363: my ($position,$dom,$settings,$rowtotal) = @_;
5364: my (%rules,%encrypt,%privkeys,%linkprot);
1.267 raeburn 5365: if (ref($settings) eq 'HASH') {
1.421 raeburn 5366: if ($position eq 'top') {
5367: if (exists($settings->{'encrypt'})) {
5368: if (ref($settings->{'encrypt'}) eq 'HASH') {
5369: foreach my $key (keys(%{$settings->{'encrypt'}})) {
5370: $encrypt{'toolsec_'.$key} = $settings->{'encrypt'}{$key};
1.324 raeburn 5371: }
5372: }
1.267 raeburn 5373: }
1.421 raeburn 5374: if (exists($settings->{'private'})) {
5375: if (ref($settings->{'private'}) eq 'HASH') {
5376: if (ref($settings->{'private'}) eq 'HASH') {
5377: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
5378: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
1.267 raeburn 5379: }
5380: }
5381: }
5382: }
1.421 raeburn 5383: } elsif ($position eq 'middle') {
5384: if (exists($settings->{'rules'})) {
5385: if (ref($settings->{'rules'}) eq 'HASH') {
5386: %rules = %{$settings->{'rules'}};
1.273 raeburn 5387: }
5388: }
1.421 raeburn 5389: } else {
5390: foreach my $key ('encrypt','private','rules') {
5391: if (exists($settings->{$key})) {
5392: delete($settings->{$key});
1.267 raeburn 5393: }
5394: }
5395: }
5396: }
1.421 raeburn 5397: my $datatable;
5398: my $itemcount = 1;
5399: if ($position eq 'top') {
5400: $datatable = &secrets_form($dom,'toolsec',\%encrypt,\%privkeys,$rowtotal);
5401: } elsif ($position eq 'middle') {
5402: $datatable = &password_rules('toolsecrets',\$itemcount,\%rules);
5403: $$rowtotal += $itemcount;
5404: } else {
5405: $datatable = &Apache::courseprefs::print_ltitools($dom,'',$settings,\$rowtotal,'','','domain');
1.267 raeburn 5406: }
5407: return $datatable;
5408: }
5409:
5410: sub ltitools_names {
5411: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 5412: 'title' => 'Title',
5413: 'version' => 'Version',
5414: 'msgtype' => 'Message Type',
1.323 raeburn 5415: 'sigmethod' => 'Signature Method',
1.296 raeburn 5416: 'url' => 'URL',
5417: 'key' => 'Key',
1.322 raeburn 5418: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 5419: 'secret' => 'Secret',
1.425 raeburn 5420: 'icon' => 'Icon',
1.324 raeburn 5421: 'user' => 'User',
1.296 raeburn 5422: 'fullname' => 'Full Name',
5423: 'firstname' => 'First Name',
5424: 'lastname' => 'Last Name',
5425: 'email' => 'E-mail',
5426: 'roles' => 'Role',
1.298 raeburn 5427: 'window' => 'Window',
5428: 'tab' => 'Tab',
1.296 raeburn 5429: 'iframe' => 'iFrame',
5430: 'height' => 'Height',
5431: 'width' => 'Width',
5432: 'linktext' => 'Default Link Text',
5433: 'explanation' => 'Default Explanation',
5434: 'passback' => 'Tool can return grades:',
5435: 'roster' => 'Tool can retrieve roster:',
5436: 'crstarget' => 'Display target',
5437: 'crslabel' => 'Course label',
1.425 raeburn 5438: 'crstitle' => 'Course title',
1.296 raeburn 5439: 'crslinktext' => 'Link Text',
5440: 'crsexplanation' => 'Explanation',
1.318 raeburn 5441: 'crsappend' => 'Provider URL',
1.267 raeburn 5442: );
5443: return %lt;
5444: }
5445:
1.421 raeburn 5446: sub secrets_form {
5447: my ($dom,$context,$encrypt,$privkeys,$rowtotal) = @_;
5448: my @ids=&Apache::lonnet::current_machine_ids();
5449: my %servers = &Apache::lonnet::get_servers($dom,'library');
5450: my $primary = &Apache::lonnet::domain($dom,'primary');
5451: my ($css_class,$extra,$numshown,$itemcount,$output);
5452: $itemcount = 0;
5453: foreach my $hostid (sort(keys(%servers))) {
5454: my ($showextra,$divsty,$switch);
5455: if ($hostid eq $primary) {
5456: if ($context eq 'ltisec') {
5457: if (($encrypt->{'ltisec_consumers'}) || ($encrypt->{'ltisec_domlinkprot'})) {
5458: $showextra = 1;
5459: }
5460: if ($encrypt->{'ltisec_crslinkprot'}) {
5461: $showextra = 1;
5462: }
5463: } else {
5464: if (($encrypt->{'toolsec_crs'}) || ($encrypt->{'toolsec_dom'})) {
5465: $showextra = 1;
5466: }
5467: }
5468: unless (grep(/^\Q$hostid\E$/,@ids)) {
5469: $switch = 1;
5470: }
5471: if ($showextra) {
5472: $numshown ++;
5473: $divsty = 'display:inline-block';
5474: } else {
5475: $divsty = 'display:none';
5476: }
5477: $extra .= '<fieldset id="'.$context.'_info_'.$hostid.'" style="'.$divsty.'">'.
5478: '<legend>'.$hostid.'</legend>';
5479: if ($switch) {
5480: my $switchserver = '<a href="/adm/switchserver?otherserver='.$hostid.'&role='.
5481: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
5482: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
5483: if (exists($privkeys->{$hostid})) {
5484: $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" />'.
5485: '<span class="LC_nobreak">'.
5486: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5487: '<span class="LC_nobreak">'.&mt('Change?').
5488: '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5489: (' 'x2).
5490: '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5491: '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5492: '<span class="LC_nobreak"> - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5493: '</span></div>';
5494: } else {
5495: $extra .= '<span class="LC_nobreak">'.
5496: &mt('Key required').' - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5497: '</span>'."\n";
5498: }
5499: } elsif (exists($privkeys->{$hostid})) {
5500: $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" /><span class="LC_nobreak">'.
5501: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5502: '<span class="LC_nobreak">'.&mt('Change?').
5503: '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5504: (' 'x2).
5505: '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5506: '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5507: '<span class="LC_nobreak">'.&mt('New Key').':'.
5508: '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5509: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.'.$context.'_privkey_'.$hostid.'.type='."'text'".' } else { this.form.'.$context.'_privkey_'.$hostid.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
5510: '</span></div>';
5511: } else {
5512: $extra .= '<span class="LC_nobreak">'.&mt('Encryption Key').':'.
5513: '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5514: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.'.$context.'_privkey_'.$hostid.'.type='."'text'".' } else { this.form.'.$context.'_privkey_'.$hostid.'.type='."'password'".' }" />'.&mt('Visible input').'</label>';
5515: }
5516: $extra .= '</fieldset>';
5517: }
5518: }
5519: my (%choices,@toggles,%defaultchecked);
5520: if ($context eq 'ltisec') {
5521: %choices = &Apache::lonlocal::texthash (
5522: ltisec_crslinkprot => 'Encrypt stored link protection secrets defined in courses',
5523: ltisec_domlinkprot => 'Encrypt stored link protection secrets defined in domain',
5524: ltisec_consumers => 'Encrypt stored consumer secrets defined in domain',
5525: );
5526: @toggles = qw(ltisec_crslinkprot ltisec_domlinkprot ltisec_consumers);
5527: %defaultchecked = (
5528: 'ltisec_crslinkprot' => 'off',
5529: 'ltisec_domlinkprot' => 'off',
5530: 'ltisec_consumers' => 'off',
5531: );
5532: } else {
5533: %choices = &Apache::lonlocal::texthash (
5534: toolsec_crs => 'Encrypt stored external tool secrets defined in courses',
5535: toolsec_dom => 'Encrypt stored external tool secrets defined in domain',
5536: );
5537: @toggles = qw(toolsec_crs toolsec_dom);
5538: %defaultchecked = (
5539: 'toolsec_crs' => 'off',
5540: 'toolsec_dom' => 'off',
5541: );
5542: }
5543: my ($onclick,$itemcount);
5544: $onclick = 'javascript:toggleLTIEncKey(this.form,'."'$context'".');';
5545: ($output,$itemcount) = &radiobutton_prefs($encrypt,\@toggles,\%defaultchecked,
5546: \%choices,$itemcount,$onclick,'','left','no');
5547:
5548: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5549: my $noprivkeysty = 'display:inline-block';
5550: if ($numshown) {
5551: $noprivkeysty = 'display:none';
5552: }
5553: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.&mt('Encryption Key(s)').'</td>'.
5554: '<td><div id="'.$context.'_noprivkey" style="'.$noprivkeysty.'" >'.
5555: '<span class="LC_nobreak">'.&mt('Not in use').'</span></div>'.
5556: $extra.
5557: '</td></tr>';
5558: $itemcount ++;
5559: $$rowtotal += $itemcount;
5560: return $output;
5561: }
5562:
1.372 raeburn 5563: sub print_proctoring {
5564: my ($dom,$settings,$rowtotal) = @_;
5565: my $itemcount = 1;
5566: my (%ordered,%providernames,%current,%currentdef);
5567: my $confname = $dom.'-domainconfig';
5568: my $switchserver = &check_switchserver($dom,$confname);
5569: if (ref($settings) eq 'HASH') {
5570: foreach my $item (keys(%{$settings})) {
5571: if (ref($settings->{$item}) eq 'HASH') {
5572: my $num = $settings->{$item}{'order'};
5573: $ordered{$num} = $item;
5574: }
5575: }
5576: } else {
5577: %ordered = (
5578: 1 => 'proctorio',
5579: 2 => 'examity',
5580: );
5581: }
5582: %providernames = &proctoring_providernames();
5583: my $maxnum = scalar(keys(%ordered));
5584: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
5585: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
5586: if (ref($requref) eq 'HASH') {
5587: %requserfields = %{$requref};
5588: }
5589: if (ref($opturef) eq 'HASH') {
5590: %optuserfields = %{$opturef};
5591: }
5592: if (ref($defref) eq 'HASH') {
5593: %defaults = %{$defref};
5594: }
5595: if (ref($extref) eq 'HASH') {
5596: %extended = %{$extref};
5597: }
5598: if (ref($crsref) eq 'HASH') {
5599: %crsconf = %{$crsref};
5600: }
5601: if (ref($rolesref) eq 'ARRAY') {
5602: @courseroles = @{$rolesref};
5603: }
5604: if (ref($ltiref) eq 'ARRAY') {
5605: @ltiroles = @{$ltiref};
5606: }
5607: my $datatable;
5608: my $css_class;
5609: if (keys(%ordered)) {
5610: my @items = sort { $a <=> $b } keys(%ordered);
5611: for (my $i=0; $i<@items; $i++) {
5612: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5613: my $provider = $ordered{$items[$i]};
5614: my $optionsty = 'none';
5615: my ($available,$version,$lifetime,$imgsrc,$userincdom,$showroles,
5616: %checkedfields,%rolemaps,%inuse,%crsconfig,%current);
5617: if (ref($settings) eq 'HASH') {
5618: if (ref($settings->{$provider}) eq 'HASH') {
5619: %current = %{$settings->{$provider}};
5620: if ($current{'available'}) {
5621: $optionsty = 'block';
5622: $available = 1;
5623: }
5624: if ($current{'lifetime'} =~ /^\d+$/) {
5625: $lifetime = $current{'lifetime'};
5626: }
5627: if ($current{'version'} =~ /^\d+\.\d+$/) {
5628: $version = $current{'version'};
5629: }
5630: if ($current{'image'} ne '') {
5631: $imgsrc = '<img src="'.$current{'image'}.'" alt="'.&mt('Proctoring service icon').'" />';
5632: }
5633: if (ref($current{'fields'}) eq 'ARRAY') {
5634: map { $checkedfields{$_} = 1; } @{$current{'fields'}};
5635: }
5636: $userincdom = $current{'incdom'};
5637: if (ref($current{'roles'}) eq 'HASH') {
5638: %rolemaps = %{$current{'roles'}};
5639: $checkedfields{'roles'} = 1;
5640: }
5641: if (ref($current{'defaults'}) eq 'ARRAY') {
5642: foreach my $val (@{$current{'defaults'}}) {
5643: if (grep(/^\Q$val\E$/,@{$defaults{$provider}})) {
5644: $inuse{$val} = 1;
5645: } else {
5646: foreach my $poss (keys(%{$extended{$provider}})) {
5647: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5648: if (grep(/^\Q$val\E$/,@{$extended{$provider}{$poss}})) {
5649: $inuse{$poss} = $val;
5650: last;
5651: }
5652: }
5653: }
5654: }
5655: }
5656: } elsif (ref($current{'defaults'}) eq 'HASH') {
5657: foreach my $key (keys(%{$current{'defaults'}})) {
5658: my $currval = $current{'defaults'}{$key};
5659: if (grep(/^\Q$key\E$/,@{$defaults{$provider}})) {
5660: $inuse{$key} = 1;
5661: } else {
5662: my $match;
5663: foreach my $poss (keys(%{$extended{$provider}})) {
5664: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5665: if (grep(/^\Q$key\E$/,@{$extended{$provider}{$poss}})) {
5666: $inuse{$poss} = $key;
5667: last;
5668: }
5669: } elsif (ref($extended{$provider}{$poss}) eq 'HASH') {
5670: foreach my $inner (sort(keys(%{$extended{$provider}{$poss}}))) {
5671: if (ref($extended{$provider}{$poss}{$inner}) eq 'ARRAY') {
5672: if (grep(/^\Q$currval\E$/,@{$extended{$provider}{$poss}{$inner}})) {
5673: $currentdef{$inner} = $currval;
5674: $match = 1;
5675: last;
5676: }
5677: } elsif ($inner eq $key) {
5678: $currentdef{$key} = $currval;
5679: $match = 1;
5680: last;
5681: }
5682: }
5683: }
5684: last if ($match);
5685: }
5686: }
5687: }
5688: }
5689: if (ref($current{'crsconf'}) eq 'ARRAY') {
5690: map { $crsconfig{$_} = 1; } @{$current{'crsconf'}};
5691: }
5692: }
5693: }
5694: my %lt = &proctoring_titles($provider);
5695: my %fieldtitles = &proctoring_fieldtitles($provider);
5696: my $onclickavailable = ' onclick="toggleProctoring(this.form,'."'$provider'".');"';
5697: my %checkedavailable = (
5698: yes => '',
5699: no => ' checked="checked"',
5700: );
5701: if ($available) {
5702: $checkedavailable{'yes'} = $checkedavailable{'no'};
5703: $checkedavailable{'no'} = '';
5704: }
5705: my $chgstr = ' onchange="javascript:reorderProctoring(this.form,'."'proctoring_pos_".$provider."'".');"';
5706: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5707: .'<select name="proctoring_pos_'.$provider.'"'.$chgstr.'>';
5708: for (my $k=0; $k<$maxnum; $k++) {
5709: my $vpos = $k+1;
5710: my $selstr;
5711: if ($k == $i) {
5712: $selstr = ' selected="selected" ';
5713: }
5714: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5715: }
5716: if ($version eq '') {
5717: if ($provider eq 'proctorio') {
5718: $version = '1.0';
5719: } elsif ($provider eq 'examity') {
5720: $version = '1.1';
5721: }
5722: }
5723: if ($lifetime eq '') {
5724: $lifetime = '300';
5725: }
5726: $datatable .=
5727: '</select>'.(' 'x2).'<b>'.$providernames{$provider}.'</b></span><br />'.
5728: '<span class="LC_nobreak">'.$lt{'avai'}.' '.
5729: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="1"'.$onclickavailable.$checkedavailable{yes}.' />'.&mt('Yes').'</label> '."\n".
5730: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="0"'.$onclickavailable.$checkedavailable{no}.' />'.&mt('No').'</label></span>'."\n".
5731: '</td>'.
5732: '<td colspan="2">'.
5733: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'base'}.'</legend>'.
5734: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="proctoring_'.$provider.'_version">'.
5735: '<option value="'.$version.'" selected="selected">'.$version.'</option></select></span> '."\n".
5736: (' 'x2).
5737: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="proctoring_'.$provider.'_sigmethod">'.
5738: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5739: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
5740: (' 'x2).
5741: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="proctoring_'.$provider.'_lifetime" value="'.$lifetime.'" /></span> '."\n".
5742: '<br />'.
5743: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="proctoring_'.$provider.'_url" value="'.$current{'url'}.'" /></span> '."\n".
5744: '<br />'.
5745: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="proctoring_'.$provider.'_key" value="'.$current{'key'}.'" /></span> '."\n".
5746: (' 'x2).
5747: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="proctoring_'.$provider.'_secret" value="'.$current{'secret'}.'" />'.
5748: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.proctoring_'.$provider.'_secret.type='."'text'".' } else { this.form.proctoring_'.$provider.'_secret.type='."'password'".' }" />'.$lt{'visible'}.'</label></span><br />'."\n";
5749: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
5750: if ($imgsrc) {
5751: $datatable .= $imgsrc.
5752: '<label><input type="checkbox" name="proctoring_image_del"'.
5753: ' value="'.$provider.'" />'.&mt('Delete?').'</label></span> '.
5754: '<span class="LC_nobreak"> '.&mt('Replace:');
5755: }
5756: $datatable .= ' ';
5757: if ($switchserver) {
5758: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5759: } else {
5760: $datatable .= '<input type="file" name="proctoring_image_'.$provider.'" value="" />';
5761: }
5762: unless ($imgsrc) {
5763: $datatable .= '<br />('.&mt('if larger than 21x21 pixels, image will be scaled').')';
5764: }
5765: $datatable .= '</fieldset>'."\n";
5766: if (ref($requserfields{$provider}) eq 'ARRAY') {
5767: if (@{$requserfields{$provider}} > 0) {
5768: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'requ'}.'</legend>';
5769: foreach my $field (@{$requserfields{$provider}}) {
5770: $datatable .= '<span class="LC_nobreak">'.
5771: '<label><input type="checkbox" name="proctoring_reqd_'.$provider.'" value="'.$field.'" checked="checked" disabled="disabled" />'.
5772: $lt{$field}.'</label>';
5773: if ($field eq 'user') {
5774: my $seluserdom = '';
5775: my $unseluserdom = ' selected="selected"';
5776: if ($userincdom) {
5777: $seluserdom = $unseluserdom;
5778: $unseluserdom = '';
5779: }
5780: $datatable .= ': '.
5781: '<select name="proctoring_userincdom_'.$provider.'">'.
5782: '<option value="0"'.$unseluserdom.'>'.$lt{'username'}.'</option>'.
5783: '<option value="1"'.$seluserdom.'>'.$lt{'uname:dom'}.'</option>'.
5784: '</select> ';
5785: } else {
5786: $datatable .= ' ';
5787: if ($field eq 'roles') {
5788: $showroles = 1;
5789: }
5790: }
5791: $datatable .= '</span> ';
5792: }
5793: }
5794: $datatable .= '</fieldset>'."\n";
5795: }
5796: if (ref($optuserfields{$provider}) eq 'ARRAY') {
5797: if (@{$optuserfields{$provider}} > 0) {
5798: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'optu'}.'</legend>';
5799: foreach my $field (@{$optuserfields{$provider}}) {
5800: my $checked;
5801: if ($checkedfields{$field}) {
5802: $checked = ' checked="checked"';
5803: }
5804: $datatable .= '<span class="LC_nobreak">'.
5805: '<label><input type="checkbox" name="proctoring_optional_'.$provider.'" value="'.$field.'"'.$checked.' />'.$lt{$field}.'</label></span> ';
5806: }
5807: $datatable .= '</fieldset>'."\n";
5808: }
5809: }
5810: if (ref($defaults{$provider}) eq 'ARRAY') {
5811: if (@{$defaults{$provider}}) {
5812: my (%options,@selectboxes);
5813: if (ref($extended{$provider}) eq 'HASH') {
5814: %options = %{$extended{$provider}};
5815: }
5816: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'defa'}.'</legend>';
5817: my ($rem,$numinrow,$dropdowns);
5818: if ($provider eq 'proctorio') {
5819: $datatable .= '<table>';
5820: $numinrow = 4;
5821: }
5822: my $i = 0;
5823: foreach my $field (@{$defaults{$provider}}) {
5824: my $checked;
5825: if ($inuse{$field}) {
5826: $checked = ' checked="checked"';
5827: }
5828: if ($provider eq 'examity') {
5829: if ($field eq 'display') {
5830: $datatable .= '<span class="LC_nobreak">'.&mt('Display target:');
5831: foreach my $option ('iframe','tab','window') {
5832: my $checkdisp;
5833: if ($currentdef{'target'} eq $option) {
5834: $checkdisp = ' checked="checked"';
5835: }
5836: $datatable .= '<label><input type="radio" name="proctoring_target_'.$provider.'" value="'.$option.'"'.$checkdisp.' />'.
5837: $fieldtitles{$option}.'</label>'.(' 'x2);
5838: }
5839: $datatable .= (' 'x4);
5840: foreach my $dimen ('width','height') {
5841: $datatable .= '<label>'.$fieldtitles{$dimen}.' '.
5842: '<input type="text" name="proctoring_'.$dimen.'_'.$provider.'" size="5" '.
5843: 'value="'.$currentdef{$dimen}.'" /></label>'.
5844: (' 'x2);
5845: }
5846: $datatable .= '</span><br />'.
5847: '<div class="LC_left_float">'.$fieldtitles{'linktext'}.'<br />'.
5848: '<input type="text" name="proctoring_linktext_'.$provider.'" '.
5849: 'size="25" value="'.$currentdef{'linktext'}.'" /></div>'.
5850: '<div class="LC_left_float">'.$fieldtitles{'explanation'}.'<br />'.
5851: '<textarea name="proctoring_explanation_'.$provider.'" rows="5" cols="40">'.
5852: $currentdef{'explanation'}.
5853: '</textarea></div><div style=""></div><br />';
5854: }
5855: } else {
5856: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
5857: my ($output,$selnone);
5858: unless ($checked) {
5859: $selnone = ' selected="selected"';
5860: }
5861: $output .= '<span class="LC_nobreak">'.$fieldtitles{$field}.': '.
5862: '<select name="proctoring_defaults_'.$field.'_'.$provider.'">'.
5863: '<option value=""'.$selnone.'>'.&mt('Not in use').'</option>';
5864: foreach my $option (@{$options{$field}}) {
5865: my $sel;
5866: if ($inuse{$field} eq $option) {
5867: $sel = ' selected="selected"';
5868: }
5869: $output .= '<option value="'.$option.'"'.$sel.'>'.$fieldtitles{$option}.'</option>';
5870: }
5871: $output .= '</select></span>';
5872: push(@selectboxes,$output);
5873: } else {
5874: $rem = $i%($numinrow);
5875: if ($rem == 0) {
5876: if ($i > 0) {
5877: $datatable .= '</tr>';
5878: }
5879: $datatable .= '<tr>';
5880: }
5881: $datatable .= '<td class="LC_left_item">'.
5882: '<span class="LC_nobreak">'.
5883: '<label><input type="checkbox" name="proctoring_defaults_'.$provider.'" value="'.$field.'"'.$checked.' />'.
5884: $fieldtitles{$field}.'</label></span></td>';
5885: $i++;
5886: }
5887: }
5888: }
5889: if ($provider eq 'proctorio') {
5890: if ($numinrow) {
5891: $rem = $i%$numinrow;
5892: }
5893: my $colsleft = $numinrow - $rem;
5894: if ($colsleft > 1) {
5895: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5896: } else {
5897: $datatable .= '<td class="LC_left_item">';
5898: }
5899: $datatable .= ' '.
5900: '</td></tr></table>';
5901: if (@selectboxes) {
5902: $datatable .= '<hr /><table>';
5903: $numinrow = 2;
5904: for (my $i=0; $i<@selectboxes; $i++) {
5905: $rem = $i%($numinrow);
5906: if ($rem == 0) {
5907: if ($i > 0) {
5908: $datatable .= '</tr>';
5909: }
5910: $datatable .= '<tr>';
5911: }
5912: $datatable .= '<td class="LC_left_item">'.
5913: $selectboxes[$i].'</td>';
5914: }
5915: if ($numinrow) {
5916: $rem = $i%$numinrow;
5917: }
5918: $colsleft = $numinrow - $rem;
5919: if ($colsleft > 1) {
5920: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5921: } else {
5922: $datatable .= '<td class="LC_left_item">';
5923: }
5924: $datatable .= ' '.
5925: '</td></tr></table>';
5926: }
5927: }
5928: $datatable .= '</fieldset>';
5929: }
5930: if (ref($crsconf{$provider}) eq 'ARRAY') {
5931: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5932: '<legend>'.&mt('Configurable in course').'</legend>';
5933: my ($rem,$numinrow);
5934: if ($provider eq 'proctorio') {
5935: $datatable .= '<table>';
5936: $numinrow = 4;
5937: }
5938: my $i = 0;
5939: foreach my $item (@{$crsconf{$provider}}) {
5940: my $name;
5941: if ($provider eq 'examity') {
5942: $name = $lt{'crs'.$item};
5943: } elsif ($provider eq 'proctorio') {
5944: $name = $fieldtitles{$item};
5945: $rem = $i%($numinrow);
5946: if ($rem == 0) {
5947: if ($i > 0) {
5948: $datatable .= '</tr>';
5949: }
5950: $datatable .= '<tr>';
5951: }
5952: $datatable .= '<td class="LC_left_item>';
5953: }
5954: my $checked;
5955: if ($crsconfig{$item}) {
5956: $checked = ' checked="checked"';
5957: }
5958: $datatable .= '<span class="LC_nobreak"><label>'.
5959: '<input type="checkbox" name="proctoring_crsconf_'.$provider.'" value="'.$item.'"'.$checked.' />'.
5960: $name.'</label></span>';
5961: if ($provider eq 'examity') {
5962: $datatable .= ' ';
5963: }
5964: $datatable .= "\n";
5965: $i++;
5966: }
5967: if ($provider eq 'proctorio') {
5968: if ($numinrow) {
5969: $rem = $i%$numinrow;
5970: }
5971: my $colsleft = $numinrow - $rem;
5972: if ($colsleft > 1) {
5973: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5974: } else {
5975: $datatable .= '<td class="LC_left_item">';
5976: }
5977: $datatable .= ' '.
5978: '</td></tr></table>';
5979: }
5980: $datatable .= '</fieldset>';
5981: }
5982: if ($showroles) {
5983: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5984: '<legend>'.&mt('Role mapping').'</legend><table><tr>';
5985: foreach my $role (@courseroles) {
5986: my ($selected,$selectnone);
5987: if (!$rolemaps{$role}) {
5988: $selectnone = ' selected="selected"';
5989: }
5990: $datatable .= '<td style="text-align: center">'.
5991: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5992: '<select name="proctoring_roles_'.$role.'_'.$provider.'">'.
5993: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5994: foreach my $ltirole (@ltiroles) {
5995: unless ($selectnone) {
5996: if ($rolemaps{$role} eq $ltirole) {
5997: $selected = ' selected="selected"';
5998: } else {
5999: $selected = '';
6000: }
6001: }
6002: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
6003: }
6004: $datatable .= '</select></td>';
6005: }
6006: $datatable .= '</tr></table></fieldset>'.
6007: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
6008: '<legend>'.&mt('Custom items sent on launch').'</legend>'.
6009: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
6010: '<tr><td></td><td>lms</td>'.
6011: '<td><input type="text" name="proctoring_customval_lms_'.$provider.'"'.
6012: ' value="Loncapa" disabled="disabled"/></td></tr>';
6013: if ((ref($settings) eq 'HASH') && (ref($settings->{$provider}) eq 'HASH') &&
6014: (ref($settings->{$provider}->{'custom'}) eq 'HASH')) {
6015: my %custom = %{$settings->{$provider}->{'custom'}};
6016: if (keys(%custom) > 0) {
6017: foreach my $key (sort(keys(%custom))) {
6018: next if ($key eq 'lms');
6019: $datatable .= '<tr><td><span class="LC_nobreak">'.
6020: '<label><input type="checkbox" name="proctoring_customdel_'.$provider.'" value="'.
6021: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
6022: '<td><input type="text" name="proctoring_customval_'.$key.'_'.$provider.'"'.
6023: ' value="'.$custom{$key}.'" /></td></tr>';
6024: }
6025: }
6026: }
6027: $datatable .= '<tr><td><span class="LC_nobreak">'.
6028: '<label><input type="checkbox" name="proctoring_customadd" value="'.$provider.'" />'.
6029: &mt('Add more').'</label></span></td><td><input type="text" name="proctoring_custom_name_'.$provider.'" />'.
6030: '</td><td><input type="text" name="proctoring_custom_value_'.$provider.'" /></td></tr>'.
6031: '</table></fieldset></td></tr>'."\n";
6032: }
6033: $datatable .= '</td></tr>';
6034: }
6035: $itemcount ++;
6036: }
6037: }
6038: return $datatable;
6039: }
6040:
6041: sub proctoring_data {
6042: my $requserfields = {
6043: proctorio => ['user'],
6044: examity => ['roles','user'],
6045: };
6046: my $optuserfields = {
6047: proctorio => ['fullname'],
6048: examity => ['fullname','firstname','lastname','email'],
6049: };
6050: my $defaults = {
6051: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6052: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6053: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6054: 'closetabs','onescreen','print','downloads','cache','rightclick',
6055: 'reentry','calculator','whiteboard'],
6056: examity => ['display'],
6057: };
6058: my $extended = {
6059: proctorio => {
6060: verifyid => ['verifyidauto','verifyidlive'],
6061: fullscreen => ['fullscreenlenient','fullscreenmoderate','fullscreensever'],
6062: tabslinks => ['notabs','linksonly'],
6063: reentry => ['noreentry','agentreentry'],
6064: calculator => ['calculatorbasic','calculatorsci'],
6065: },
6066: examity => {
6067: display => {
6068: target => ['iframe','tab','window'],
6069: width => '',
6070: height => '',
6071: linktext => '',
6072: explanation => '',
6073: },
6074: },
6075: };
6076: my $crsconf = {
6077: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6078: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6079: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6080: 'closetabs','onescreen','print','downloads','cache','rightclick',
6081: 'reentry','calculator','whiteboard'],
6082: examity => ['label','title','target','linktext','explanation','append'],
6083: };
6084: my $courseroles = ['cc','in','ta','ep','st'];
6085: my $ltiroles = ['Instructor','ContentDeveloper','TeachingAssistant','Learner'];
6086: return ($requserfields,$optuserfields,$defaults,$extended,$crsconf,$courseroles,$ltiroles);
6087: }
6088:
6089: sub proctoring_titles {
6090: my ($item) = @_;
6091: my (%common_lt,%custom_lt);
6092: %common_lt = &Apache::lonlocal::texthash (
6093: 'avai' => 'Available?',
6094: 'base' => 'Basic Settings',
6095: 'requ' => 'User data required to be sent on launch',
6096: 'optu' => 'User data optionally sent on launch',
6097: 'udsl' => 'User data sent on launch',
6098: 'defa' => 'Defaults for items configurable in course',
6099: 'sigmethod' => 'Signature Method',
6100: 'key' => 'Key',
6101: 'lifetime' => 'Nonce lifetime (s)',
6102: 'secret' => 'Secret',
6103: 'icon' => 'Icon',
6104: 'fullname' => 'Full Name',
6105: 'visible' => 'Visible input',
6106: 'username' => 'username',
6107: 'user' => 'User',
6108: );
6109: if ($item eq 'proctorio') {
6110: %custom_lt = &Apache::lonlocal::texthash (
6111: 'version' => 'OAuth version',
6112: 'url' => 'API URL',
6113: 'uname:dom' => 'username-domain',
6114: );
6115: } elsif ($item eq 'examity') {
6116: %custom_lt = &Apache::lonlocal::texthash (
6117: 'version' => 'LTI Version',
6118: 'url' => 'URL',
6119: 'uname:dom' => 'username:domain',
6120: 'msgtype' => 'Message Type',
6121: 'firstname' => 'First Name',
6122: 'lastname' => 'Last Name',
6123: 'email' => 'E-mail',
6124: 'roles' => 'Role',
6125: 'crstarget' => 'Display target',
6126: 'crslabel' => 'Course label',
6127: 'crstitle' => 'Course title',
6128: 'crslinktext' => 'Link Text',
6129: 'crsexplanation' => 'Explanation',
6130: 'crsappend' => 'Provider URL',
6131: );
6132: }
6133: my %lt = (%common_lt,%custom_lt);
6134: return %lt;
6135: }
6136:
6137: sub proctoring_fieldtitles {
6138: my ($item) = @_;
6139: if ($item eq 'proctorio') {
6140: return &Apache::lonlocal::texthash (
6141: 'recordvideo' => 'Record video',
6142: 'recordaudio' => 'Record audio',
6143: 'recordscreen' => 'Record screen',
6144: 'recordwebtraffic' => 'Record web traffic',
6145: 'recordroomstart' => 'Record room scan',
6146: 'verifyvideo' => 'Verify webcam',
6147: 'verifyaudio' => 'Verify microphone',
6148: 'verifydesktop' => 'Verify desktop recording',
6149: 'verifyid' => 'Photo ID verification',
6150: 'verifysignature' => 'Require signature',
6151: 'fullscreen' => 'Fullscreen',
6152: 'clipboard' => 'Disable copy/paste',
6153: 'tabslinks' => 'New tabs/windows',
6154: 'closetabs' => 'Close other tabs',
6155: 'onescreen' => 'Limit to single screen',
6156: 'print' => 'Disable Printing',
6157: 'downloads' => 'Disable Downloads',
6158: 'cache' => 'Empty cache after exam',
6159: 'rightclick' => 'Disable right click',
6160: 'reentry' => 'Re-entry to exam',
6161: 'calculator' => 'Onscreen calculator',
6162: 'whiteboard' => 'Onscreen whiteboard',
6163: 'verifyidauto' => 'Automated verification',
6164: 'verifyidlive' => 'Live agent verification',
6165: 'fullscreenlenient' => 'Forced, but can navigate away for up to 30s',
6166: 'fullscreenmoderate' => 'Forced, but can navigate away for up to 15s',
6167: 'fullscreensever' => 'Forced, navigation away ends exam',
6168: 'notabs' => 'Disaallowed',
6169: 'linksonly' => 'Allowed from links in exam',
6170: 'noreentry' => 'Disallowed',
6171: 'agentreentry' => 'Agent required for re-entry',
6172: 'calculatorbasic' => 'Basic',
6173: 'calculatorsci' => 'Scientific',
6174: );
6175: } elsif ($item eq 'examity') {
6176: return &Apache::lonlocal::texthash (
6177: 'target' => 'Display target',
6178: 'window' => 'Window',
6179: 'tab' => 'Tab',
6180: 'iframe' => 'iFrame',
6181: 'height' => 'Height (pixels)',
6182: 'width' => 'Width (pixels)',
6183: 'linktext' => 'Default Link Text',
6184: 'explanation' => 'Default Explanation',
6185: 'append' => 'Provider URL',
6186: );
6187: }
6188: }
6189:
6190: sub proctoring_providernames {
6191: return (
6192: proctorio => 'Proctorio',
6193: examity => 'Examity',
6194: );
6195: }
6196:
1.320 raeburn 6197: sub print_lti {
1.405 raeburn 6198: my ($position,$dom,$settings,$rowtotal) = @_;
1.320 raeburn 6199: my $itemcount = 1;
1.405 raeburn 6200: my ($datatable,$css_class);
1.434 raeburn 6201: my (%rules,%encrypt,%privkeys,%linkprot,%suggestions);
1.320 raeburn 6202: if (ref($settings) eq 'HASH') {
1.405 raeburn 6203: if ($position eq 'top') {
6204: if (exists($settings->{'encrypt'})) {
6205: if (ref($settings->{'encrypt'}) eq 'HASH') {
6206: foreach my $key (keys(%{$settings->{'encrypt'}})) {
6207: if ($key eq 'consumers') {
6208: $encrypt{'ltisec_'.$key} = $settings->{'encrypt'}{$key};
6209: } else {
6210: $encrypt{'ltisec_'.$key.'linkprot'} = $settings->{'encrypt'}{$key};
6211: }
6212: }
6213: }
6214: }
6215: if (exists($settings->{'private'})) {
6216: if (ref($settings->{'private'}) eq 'HASH') {
6217: if (ref($settings->{'private'}) eq 'HASH') {
6218: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
6219: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
6220: }
6221: }
6222: }
6223: }
1.434 raeburn 6224: } elsif ($position eq 'upper') {
1.405 raeburn 6225: if (exists($settings->{'rules'})) {
6226: if (ref($settings->{'rules'}) eq 'HASH') {
6227: %rules = %{$settings->{'rules'}};
6228: }
6229: }
1.434 raeburn 6230: } elsif ($position eq 'middle') {
6231: if (exists($settings->{'suggested'})) {
6232: if (ref($settings->{'suggested'}) eq 'HASH') {
6233: %suggestions = %{$settings->{'suggested'}};
6234: }
6235: }
1.405 raeburn 6236: } elsif ($position eq 'lower') {
6237: if (exists($settings->{'linkprot'})) {
6238: if (ref($settings->{'linkprot'}) eq 'HASH') {
6239: %linkprot = %{$settings->{'linkprot'}};
1.406 raeburn 6240: if ($linkprot{'lock'}) {
6241: delete($linkprot{'lock'});
6242: }
1.405 raeburn 6243: }
6244: }
6245: } else {
1.434 raeburn 6246: foreach my $key ('encrypt','private','rules','linkprot','suggestions') {
1.405 raeburn 6247: if (exists($settings->{$key})) {
6248: delete($settings->{$key});
1.390 raeburn 6249: }
1.320 raeburn 6250: }
6251: }
6252: }
1.405 raeburn 6253: if ($position eq 'top') {
1.421 raeburn 6254: $datatable = &secrets_form($dom,'ltisec',\%encrypt,\%privkeys,$rowtotal);
1.434 raeburn 6255: } elsif ($position eq 'upper') {
6256: $datatable = &password_rules('ltisecrets',\$itemcount,\%rules);
6257: $$rowtotal += $itemcount;
1.421 raeburn 6258: } elsif ($position eq 'middle') {
1.434 raeburn 6259: $datatable = &linkprot_suggestions(\%suggestions,\$itemcount);
1.421 raeburn 6260: $$rowtotal += $itemcount;
6261: } elsif ($position eq 'lower') {
1.434 raeburn 6262: $datatable .= &Apache::courseprefs::print_linkprotection($dom,'',$settings,$rowtotal,'','','domain');
1.421 raeburn 6263: } else {
1.424 raeburn 6264: my ($switchserver,$switchmessage);
6265: $switchserver = &check_switchserver($dom);
6266: $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
1.421 raeburn 6267: my $maxnum = 0;
6268: my %ordered;
6269: if (ref($settings) eq 'HASH') {
6270: foreach my $item (keys(%{$settings})) {
6271: if (ref($settings->{$item}) eq 'HASH') {
6272: my $num = $settings->{$item}{'order'};
6273: if ($num eq '') {
6274: $num = scalar(keys(%{$settings}));
6275: }
6276: $ordered{$num} = $item;
1.405 raeburn 6277: }
1.352 raeburn 6278: }
1.405 raeburn 6279: }
6280: $maxnum = scalar(keys(%ordered));
6281: my %lt = <i_names();
6282: if (keys(%ordered)) {
6283: my @items = sort { $a <=> $b } keys(%ordered);
6284: for (my $i=0; $i<@items; $i++) {
6285: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6286: my $item = $ordered{$items[$i]};
1.424 raeburn 6287: my ($key,$secret,$usable,$lifetime,$consumer,$requser,$crsinc,$current);
1.405 raeburn 6288: if (ref($settings->{$item}) eq 'HASH') {
6289: $key = $settings->{$item}->{'key'};
1.424 raeburn 6290: $usable = $settings->{$item}->{'usable'};
1.405 raeburn 6291: $lifetime = $settings->{$item}->{'lifetime'};
6292: $consumer = $settings->{$item}->{'consumer'};
6293: $requser = $settings->{$item}->{'requser'};
6294: $crsinc = $settings->{$item}->{'crsinc'};
6295: $current = $settings->{$item};
6296: }
6297: my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
6298: my %checkedrequser = (
6299: yes => ' checked="checked"',
6300: no => '',
6301: );
6302: if (!$requser) {
6303: $checkedrequser{'no'} = $checkedrequser{'yes'};
6304: $checkedrequser{'yes'} = '';
6305: }
6306: my $onclickcrsinc = ' onclick="toggleLTI(this.form,'."'crsinc','$i'".');"';
6307: my %checkedcrsinc = (
1.391 raeburn 6308: yes => ' checked="checked"',
6309: no => '',
1.405 raeburn 6310: );
6311: if (!$crsinc) {
6312: $checkedcrsinc{'no'} = $checkedcrsinc{'yes'};
6313: $checkedcrsinc{'yes'} = '';
6314: }
6315: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
6316: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6317: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
6318: for (my $k=0; $k<=$maxnum; $k++) {
6319: my $vpos = $k+1;
6320: my $selstr;
6321: if ($k == $i) {
6322: $selstr = ' selected="selected" ';
6323: }
6324: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320 raeburn 6325: }
1.405 raeburn 6326: $datatable .= '</select>'.(' 'x2).
6327: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
6328: &mt('Delete?').'</label></span></td>'.
6329: '<td colspan="2">'.
6330: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6331: '<span class="LC_nobreak">'.$lt{'consumer'}.
6332: ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
6333: (' 'x2).
6334: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
6335: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
6336: (' 'x2).
6337: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
1.424 raeburn 6338: 'value="'.$lifetime.'" size="3" /></span><br /><br />';
6339: if ($key ne '') {
6340: $datatable .= '<span class="LC_nobreak">'.$lt{'key'};
6341: if ($switchserver) {
6342: $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
6343: } else {
6344: $datatable .= ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />';
6345: }
6346: $datatable .= '</span> '.(' 'x2);
6347: } elsif (!$switchserver) {
6348: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':'.
6349: '<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />'.
6350: '</span> '.(' 'x2);
6351: }
6352: if ($switchserver) {
6353: if ($usable ne '') {
6354: $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6355: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6356: '<span class="LC_nobreak">'.&mt('Change secret?').
6357: '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
6358: (' 'x2).
6359: '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').'</label>'.(' 'x2).
6360: '</span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
6361: '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
6362: '</div>';
6363: } elsif ($key eq '') {
6364: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6365: } else {
6366: $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
6367: }
6368: } else {
6369: if ($usable ne '') {
6370: $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6371: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6372: '<span class="LC_nobreak">'.&mt('Change?').
6373: '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
6374: (' 'x2).
6375: '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').
6376: '</label> </span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
6377: '<span class="LC_nobreak">'.&mt('New Secret').':'.
6378: '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
6379: '<label><input type="checkbox" name="lti_visible_'.$i.'" id="lti_visible_'.$i.'" onclick="if (this.checked) { this.form.lti_secret_'.$i.'.type='."'text'".' } else { this.form.lti_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label></span></div>';
6380: } else {
6381: $datatable .=
6382: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
6383: '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
6384: '<label><input type="checkbox" name="lti_visible_'.$i.'" id="lti_visible_'.$i.'" onclick="if (this.checked) { this.form.lti_secret_'.$i.'.type='."'text'".' } else { this.form.lti_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label>';
6385: }
6386: }
1.425 raeburn 6387: $datatable .= '<br /><br />'.
1.405 raeburn 6388: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6389: '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
6390: '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
6391: '<br /><br />'.
6392: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6393: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="1"'.$onclickcrsinc.$checkedcrsinc{yes}.' />'.&mt('Yes').'</label> '."\n".
6394: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="0"'.$onclickcrsinc.$checkedcrsinc{no}.' />'.&mt('No').'</label></span>'."\n".
6395: (' 'x4).
6396: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
6397: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
6398: $itemcount ++;
1.320 raeburn 6399: }
6400: }
1.405 raeburn 6401: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6402: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
6403: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6404: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
6405: '<select name="lti_pos_add"'.$chgstr.'>';
6406: for (my $k=0; $k<$maxnum+1; $k++) {
6407: my $vpos = $k+1;
6408: my $selstr;
6409: if ($k == $maxnum) {
6410: $selstr = ' selected="selected" ';
6411: }
6412: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320 raeburn 6413: }
1.405 raeburn 6414: $datatable .= '</select> '."\n".
6415: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6416: '<td colspan="2">'.
6417: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6418: '<span class="LC_nobreak">'.$lt{'consumer'}.
6419: ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
6420: (' 'x2).
6421: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
6422: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
6423: (' 'x2).
1.424 raeburn 6424: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span><br /><br />'."\n";
6425: if ($switchserver) {
6426: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6427: } else {
6428: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" autocomplete="off" /></span> '."\n".
6429: (' 'x2).
6430: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" autocomplete="new-password" />'.
6431: '<label><input type="checkbox" name="lti_add_visible" id="lti_add_visible" onclick="if (this.checked) { this.form.lti_secret_add.type='."'text'".' } else { this.form.lti_secret_add.type='."'password'".' }" />'.&mt('Visible input').'</label></span> '."\n";
6432: }
6433: $datatable .= '<br /><br />'.
1.405 raeburn 6434: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6435: '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6436: '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
6437: '<br /><br />'.
6438: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6439: '<label><input type="radio" name="lti_crsinc_add" value="1" onclick="toggleLTI(this.form,'."'crsinc','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6440: '<label><input type="radio" name="lti_crsinc_add" value="0" onclick="toggleLTI(this.form,'."'crsinc','add'".');" />'.&mt('No').'</label></span>'."\n".
6441: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
6442: '</td>'."\n".
6443: '</tr>'."\n";
6444: $itemcount ++;
1.320 raeburn 6445: }
1.405 raeburn 6446: $$rowtotal += $itemcount;
6447: return $datatable;
1.320 raeburn 6448: }
6449:
6450: sub lti_names {
6451: my %lt = &Apache::lonlocal::texthash(
6452: 'version' => 'LTI Version',
6453: 'url' => 'URL',
6454: 'key' => 'Key',
1.322 raeburn 6455: 'lifetime' => 'Nonce lifetime (s)',
1.345 raeburn 6456: 'consumer' => 'Consumer',
1.320 raeburn 6457: 'secret' => 'Secret',
1.345 raeburn 6458: 'requser' => "User's identity sent",
1.391 raeburn 6459: 'crsinc' => "Course's identity sent",
1.320 raeburn 6460: 'email' => 'Email address',
6461: 'sourcedid' => 'User ID',
6462: 'other' => 'Other',
6463: 'passback' => 'Can return grades to Consumer:',
6464: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 6465: 'topmenu' => 'Display LON-CAPA page header',
1.345 raeburn 6466: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 6467: );
6468: return %lt;
6469: }
6470:
6471: sub lti_options {
1.325 raeburn 6472: my ($num,$current,$itemcount,%lt) = @_;
1.363 raeburn 6473: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
1.320 raeburn 6474: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
6475: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
1.392 raeburn 6476: $checked{'storecrs'}{'Y'} = ' checked="checked"';
6477: $checked{'makecrs'}{'N'} = ' checked="checked"';
1.320 raeburn 6478: $checked{'mapcrstype'} = {};
6479: $checked{'makeuser'} = {};
6480: $checked{'selfenroll'} = {};
6481: $checked{'crssec'} = {};
6482: $checked{'crssecsrc'} = {};
1.325 raeburn 6483: $checked{'lcauth'} = {};
1.326 raeburn 6484: $checked{'menuitem'} = {};
1.325 raeburn 6485: if ($num eq 'add') {
6486: $checked{'lcauth'}{'lti'} = ' checked="checked"';
6487: }
1.320 raeburn 6488: my $userfieldsty = 'none';
6489: my $crsfieldsty = 'none';
6490: my $crssecfieldsty = 'none';
6491: my $secsrcfieldsty = 'none';
1.363 raeburn 6492: my $callbacksty = 'none';
1.337 raeburn 6493: my $passbacksty = 'none';
1.345 raeburn 6494: my $optionsty = 'block';
1.391 raeburn 6495: my $crssty = 'block';
1.325 raeburn 6496: my $lcauthparm;
6497: my $lcauthparmstyle = 'display:none';
6498: my $lcauthparmtext;
1.326 raeburn 6499: my $menusty;
1.325 raeburn 6500: my $numinrow = 4;
1.326 raeburn 6501: my %menutitles = <imenu_titles();
1.320 raeburn 6502:
6503: if (ref($current) eq 'HASH') {
1.345 raeburn 6504: if (!$current->{'requser'}) {
6505: $optionsty = 'none';
1.391 raeburn 6506: $crssty = 'none';
6507: } elsif (!$current->{'crsinc'}) {
6508: $crssty = 'none';
1.345 raeburn 6509: }
1.320 raeburn 6510: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
6511: $checked{'mapuser'}{'sourcedid'} = '';
6512: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
1.425 raeburn 6513: $checked{'mapuser'}{'email'} = ' checked="checked"';
1.320 raeburn 6514: } else {
6515: $checked{'mapuser'}{'other'} = ' checked="checked"';
6516: $userfield = $current->{'mapuser'};
6517: $userfieldsty = 'inline-block';
6518: }
6519: }
6520: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
6521: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
6522: if ($current->{'mapcrs'} eq 'context_id') {
1.425 raeburn 6523: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
1.320 raeburn 6524: } else {
6525: $checked{'mapcrs'}{'other'} = ' checked="checked"';
6526: $cidfield = $current->{'mapcrs'};
6527: $crsfieldsty = 'inline-block';
6528: }
6529: }
6530: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
6531: foreach my $type (@{$current->{'mapcrstype'}}) {
6532: $checked{'mapcrstype'}{$type} = ' checked="checked"';
6533: }
6534: }
1.392 raeburn 6535: if (!$current->{'storecrs'}) {
6536: $checked{'storecrs'}{'N'} = $checked{'storecrs'}{'Y'};
6537: $checked{'storecrs'}{'Y'} = '';
6538: }
1.345 raeburn 6539: if ($current->{'makecrs'}) {
1.320 raeburn 6540: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 6541: }
1.320 raeburn 6542: if (ref($current->{'makeuser'}) eq 'ARRAY') {
6543: foreach my $role (@{$current->{'makeuser'}}) {
6544: $checked{'makeuser'}{$role} = ' checked="checked"';
6545: }
6546: }
1.325 raeburn 6547: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
6548: $checked{'lcauth'}{$1} = ' checked="checked"';
6549: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
6550: $lcauthparm = $current->{'lcauthparm'};
1.425 raeburn 6551: $lcauthparmstyle = 'display:table-row';
1.325 raeburn 6552: if ($current->{'lcauth'} eq 'localauth') {
6553: $lcauthparmtext = &mt('Local auth argument');
6554: } else {
6555: $lcauthparmtext = &mt('Kerberos domain');
6556: }
6557: }
6558: }
1.320 raeburn 6559: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
6560: foreach my $role (@{$current->{'selfenroll'}}) {
6561: $checked{'selfenroll'}{$role} = ' checked="checked"';
6562: }
6563: }
6564: if (ref($current->{'maproles'}) eq 'HASH') {
6565: %rolemaps = %{$current->{'maproles'}};
6566: }
6567: if ($current->{'section'} ne '') {
1.425 raeburn 6568: $checked{'crssec'}{'Y'} = ' checked="checked"';
1.320 raeburn 6569: $crssecfieldsty = 'inline-block';
6570: if ($current->{'section'} eq 'course_section_sourcedid') {
6571: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
6572: } else {
6573: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
6574: $crssecsrc = $current->{'section'};
6575: $secsrcfieldsty = 'inline-block';
6576: }
6577: } else {
6578: $checked{'crssec'}{'N'} = ' checked="checked"';
6579: }
1.363 raeburn 6580: if ($current->{'callback'} ne '') {
6581: $callback = $current->{'callback'};
6582: $checked{'callback'}{'Y'} = ' checked="checked"';
6583: $callbacksty = 'inline-block';
6584: } else {
6585: $checked{'callback'}{'N'} = ' checked="checked"';
6586: }
1.326 raeburn 6587: if ($current->{'topmenu'}) {
6588: $checked{'topmenu'}{'Y'} = ' checked="checked"';
6589: } else {
6590: $checked{'topmenu'}{'N'} = ' checked="checked"';
6591: }
6592: if ($current->{'inlinemenu'}) {
6593: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
6594: } else {
6595: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
6596: }
6597: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
6598: $menusty = 'inline-block';
6599: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
6600: foreach my $item (@{$current->{'lcmenu'}}) {
6601: if (exists($menutitles{$item})) {
6602: $checked{'menuitem'}{$item} = ' checked="checked"';
6603: }
6604: }
6605: }
6606: } else {
6607: $menusty = 'none';
6608: }
1.320 raeburn 6609: } else {
6610: $checked{'makecrs'}{'N'} = ' checked="checked"';
6611: $checked{'crssec'}{'N'} = ' checked="checked"';
1.363 raeburn 6612: $checked{'callback'}{'N'} = ' checked="checked"';
1.326 raeburn 6613: $checked{'topmenu'}{'N'} = ' checked="checked"';
1.425 raeburn 6614: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
1.326 raeburn 6615: $checked{'menuitem'}{'grades'} = ' checked="checked"';
1.425 raeburn 6616: $menusty = 'inline-block';
1.320 raeburn 6617: }
1.325 raeburn 6618: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 6619: my %coursetypetitles = &Apache::lonlocal::texthash (
6620: official => 'Official',
6621: unofficial => 'Unofficial',
6622: community => 'Community',
6623: textbook => 'Textbook',
6624: placement => 'Placement Test',
1.325 raeburn 6625: lti => 'LTI Provider',
1.320 raeburn 6626: );
1.325 raeburn 6627: my @authtypes = ('internal','krb4','krb5','localauth');
6628: my %shortauth = (
6629: internal => 'int',
6630: krb4 => 'krb4',
6631: krb5 => 'krb5',
6632: localauth => 'loc'
6633: );
6634: my %authnames = &authtype_names();
1.320 raeburn 6635: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
6636: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
6637: my @courseroles = ('cc','in','ta','ep','st');
6638: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
6639: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
6640: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
1.363 raeburn 6641: my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
1.320 raeburn 6642: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 6643: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 6644: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.391 raeburn 6645: my $output = '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Logout options').'</legend>'.
1.392 raeburn 6646: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback to logout LON-CAPA on log out from Consumer').': '.
1.391 raeburn 6647: '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
6648: $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.(' 'x2).
6649: '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
6650: $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
6651: '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
6652: '<span class="LC_nobreak">'.&mt('Parameter').': '.
6653: '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
6654: '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
6655: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320 raeburn 6656: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
6657: foreach my $option ('sourcedid','email','other') {
6658: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
6659: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
6660: ($option eq 'other' ? '' : (' 'x2) );
6661: }
6662: $output .= '</span></div>'.
6663: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
6664: '<input type="text" name="lti_customuser_'.$num.'" '.
1.372 raeburn 6665: 'value="'.$userfield.'" /></div></fieldset>'.
1.391 raeburn 6666: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320 raeburn 6667: foreach my $ltirole (@ltiroles) {
6668: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
1.425 raeburn 6669: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
1.320 raeburn 6670: }
6671: $output .= '</fieldset>'.
1.391 raeburn 6672: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325 raeburn 6673: '<table>'.
6674: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
6675: '</table>'.
6676: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
6677: '<td class="LC_left_item">';
6678: foreach my $auth ('lti',@authtypes) {
6679: my $authtext;
6680: if ($auth eq 'lti') {
6681: $authtext = &mt('None');
6682: } else {
6683: $authtext = $authnames{$shortauth{$auth}};
6684: }
6685: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
6686: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
6687: $authtext.'</label></span> ';
6688: }
6689: $output .= '</td></tr>'.
6690: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
6691: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
6692: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
6693: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
6694: '</table></fieldset>'.
1.391 raeburn 6695: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.
6696: &mt('LON-CAPA menu items (Course Coordinator can override)').'</legend>'.
6697: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
6698: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
6699: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6700: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
6701: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
6702: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6703: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
6704: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
6705: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6706: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
6707: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
6708: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6709: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
6710: '<span class="LC_nobreak">'.&mt('Menu items').': ';
6711: foreach my $type ('fullname','coursetitle','role','logout','grades') {
6712: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
6713: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
6714: (' 'x2);
6715: }
6716: $output .= '</span></div></fieldset>'.
6717: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320 raeburn 6718: '<div class="LC_floatleft"><span class="LC_nobreak">'.
6719: &mt('Unique course identifier').': ';
6720: foreach my $option ('course_offering_sourcedid','context_id','other') {
6721: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
6722: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
6723: ($option eq 'other' ? '' : (' 'x2) );
6724: }
1.334 raeburn 6725: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320 raeburn 6726: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
6727: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
6728: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
6729: foreach my $type (@coursetypes) {
6730: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
6731: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
6732: (' 'x2);
6733: }
1.392 raeburn 6734: $output .= '</span><br /><br />'.
6735: '<span class="LC_nobreak">'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.
6736: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="0"'.
6737: $checked{'storecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6738: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="1"'.
6739: $checked{'storecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6740: '</fieldset>'.
1.391 raeburn 6741: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
6742: foreach my $ltirole (@lticourseroles) {
6743: my ($selected,$selectnone);
6744: if ($rolemaps{$ltirole} eq '') {
6745: $selectnone = ' selected="selected"';
6746: }
6747: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
6748: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
6749: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
6750: foreach my $role (@courseroles) {
6751: unless ($selectnone) {
6752: if ($rolemaps{$ltirole} eq $role) {
6753: $selected = ' selected="selected"';
6754: } else {
6755: $selected = '';
6756: }
6757: }
6758: $output .= '<option value="'.$role.'"'.$selected.'>'.
6759: &Apache::lonnet::plaintext($role,'Course').
6760: '</option>';
6761: }
6762: $output .= '</select></td>';
6763: }
6764: $output .= '</tr></table></fieldset>'.
6765: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320 raeburn 6766: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
6767: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
6768: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6769: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
6770: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6771: '</fieldset>'.
1.391 raeburn 6772: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320 raeburn 6773: foreach my $lticrsrole (@lticourseroles) {
6774: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
6775: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
6776: }
6777: $output .= '</fieldset>'.
1.391 raeburn 6778: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Course options').'</legend>'.
1.320 raeburn 6779: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
6780: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
6781: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
6782: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334 raeburn 6783: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320 raeburn 6784: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
6785: '<span class="LC_nobreak">'.&mt('From').':<label>'.
6786: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
6787: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
6788: &mt('Standard field').'</label>'.(' 'x2).
6789: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
6790: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334 raeburn 6791: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320 raeburn 6792: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337 raeburn 6793: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6794: my ($pb1p1chk,$pb1p0chk,$onclickpb);
6795: foreach my $extra ('roster','passback') {
1.320 raeburn 6796: my $checkedon = '';
6797: my $checkedoff = ' checked="checked"';
1.337 raeburn 6798: if ($extra eq 'passback') {
6799: $pb1p1chk = ' checked="checked"';
6800: $pb1p0chk = '';
1.425 raeburn 6801: $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
1.337 raeburn 6802: } else {
1.425 raeburn 6803: $onclickpb = '';
1.337 raeburn 6804: }
1.320 raeburn 6805: if (ref($current) eq 'HASH') {
6806: if (($current->{$extra})) {
6807: $checkedon = $checkedoff;
6808: $checkedoff = '';
1.337 raeburn 6809: if ($extra eq 'passback') {
6810: $passbacksty = 'inline-block';
6811: }
6812: if ($current->{'passbackformat'} eq '1.0') {
6813: $pb1p0chk = ' checked="checked"';
6814: $pb1p1chk = '';
6815: }
1.320 raeburn 6816: }
6817: }
6818: $output .= $lt{$extra}.' '.
1.337 raeburn 6819: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320 raeburn 6820: &mt('No').'</label>'.(' 'x2).
1.339 raeburn 6821: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320 raeburn 6822: &mt('Yes').'</label><br />';
6823: }
1.337 raeburn 6824: $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
6825: '<span class="LC_nobreak">'.&mt('Grade format').
6826: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
6827: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
6828: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
1.363 raeburn 6829: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
1.391 raeburn 6830: '<div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>';
1.334 raeburn 6831: $output .= '</span></div></fieldset>';
1.320 raeburn 6832: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
6833: #
6834: # $output .= '</fieldset>'.
6835: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
6836: return $output;
6837: }
6838:
1.326 raeburn 6839: sub ltimenu_titles {
6840: return &Apache::lonlocal::texthash(
6841: fullname => 'Full name',
6842: coursetitle => 'Course title',
6843: role => 'Role',
6844: logout => 'Logout',
6845: grades => 'Grades',
6846: );
6847: }
6848:
1.434 raeburn 6849: sub linkprot_suggestions {
6850: my ($suggested,$itemcount) = @_;
6851: my $count = 0;
6852: my $next = 1;
6853: my %lt = &Apache::lonlocal::texthash(
6854: 'name' => 'Suggested Launcher',
6855: 'info' => 'Recommendations',
6856: );
6857: my ($datatable,$css_class,$dest);
6858: if (ref($suggested) eq 'HASH') {
6859: my @current = sort { $a <=> $b } keys(%{$suggested});
6860: $next += $current[-1];
6861: for (my $i=0; $i<@current; $i++) {
6862: my $num = $current[$i];
6863: my %values;
6864: if (ref($suggested->{$num}) eq 'HASH') {
6865: %values = %{$suggested->{$num}};
6866: } else {
6867: next;
6868: }
6869: $css_class = $$itemcount%2?' class="LC_odd_row"':'';
6870: $datatable .=
6871: '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6872: '<label><input type="checkbox" name="linkprot_suggested_del" value="'.$i.'" />'."\n".
6873: &mt('Delete?').'</label></span></td><td>'."\n".
6874: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'name'}.'</legend>'."\n".
6875: '<input type="text" size="15" name="linkprot_suggested_name_'.$i.'" value="'.$values{'name'}.'" autocomplete="off" />'."\n".
6876: '</fieldset></div>'.
6877: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'info'}.'</legend>'."\n".
6878: '<textarea cols="55" rows="5" name="linkprot_suggested_info_'.$i.'">'.$values{'info'}.'</textarea>'.
6879: '</fieldset></div>'.
6880: '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
6881: '<input type="hidden" name="linkprot_suggested_id_'.$i.'" value="'.$num.'" /></td></tr>'."\n";
6882: $$itemcount ++;
6883: }
6884: }
6885: $css_class = $$itemcount%2?' class="LC_odd_row"':'';
6886: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6887: '<input type="hidden" name="linkprot_suggested_maxnum" value="'.$next.'" />'."\n".
6888: '<input type="checkbox" name="linkprot_suggested_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6889: '<td>'."\n".
6890: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'name'}.'</legend>'."\n".
6891: '<input type="text" size="15" name="linkprot_suggested_name_add" value="" autocomplete="off" />'."\n".
6892: '</fieldset></div>'.
6893: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'info'}.'</legend>'."\n".
6894: '<textarea cols="55" rows="5" name="linkprot_suggested_info_add"></textarea>'.
6895: '</fieldset></div>'.
6896: '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
6897: '</td></tr>'."\n";
6898: return $datatable;
6899: }
6900:
1.121 raeburn 6901: sub print_coursedefaults {
1.139 raeburn 6902: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 6903: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 6904: my $itemcount = 1;
1.192 raeburn 6905: my %choices = &Apache::lonlocal::texthash (
6906: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 6907: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.432 raeburn 6908: coursequota => 'Default cumulative quota for all group portfolio spaces in course (MB)',
1.192 raeburn 6909: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
6910: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 6911: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
6912: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.398 raeburn 6913: inline_chem => 'Use inline previewer for chemical reaction response in place of pop-up',
1.314 raeburn 6914: texengine => 'Default method to display mathematics',
1.257 raeburn 6915: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 6916: canclone => "People who may clone a course (besides course's owner and coordinators)",
6917: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.405 raeburn 6918: ltiauth => 'Student username in LTI launch of deep-linked URL can be accepted without re-authentication',
1.422 raeburn 6919: domexttool => 'External Tools defined in the domain may be used in courses/communities (by type)',
6920: exttool => 'External Tools can be defined and configured in courses/communities (by type)',
1.432 raeburn 6921: crsauthor => 'Standard LON-CAPA problems can be created within a course/community (by type)',
1.438 raeburn 6922: crseditors => 'Available editors for web pages and/or problems created in a course/community',
1.192 raeburn 6923: );
1.198 raeburn 6924: my %staticdefaults = (
6925: anonsurvey_threshold => 10,
6926: uploadquota => 500,
1.428 raeburn 6927: coursequota => 20,
1.257 raeburn 6928: postsubmit => 60,
1.276 raeburn 6929: mysqltables => 172800,
1.422 raeburn 6930: domexttool => 1,
6931: exttool => 0,
1.432 raeburn 6932: crsauthor => 1,
1.438 raeburn 6933: crseditors => ['edit','xml'],
1.198 raeburn 6934: );
1.139 raeburn 6935: if ($position eq 'top') {
1.257 raeburn 6936: %defaultchecked = (
6937: 'canuse_pdfforms' => 'off',
6938: 'uselcmath' => 'on',
6939: 'usejsme' => 'on',
1.398 raeburn 6940: 'inline_chem' => 'on',
1.289 raeburn 6941: 'canclone' => 'none',
1.257 raeburn 6942: );
1.398 raeburn 6943: @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem');
1.349 raeburn 6944: my $deftex = $Apache::lonnet::deftex;
1.314 raeburn 6945: if (ref($settings) eq 'HASH') {
6946: if ($settings->{'texengine'}) {
6947: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
6948: $deftex = $settings->{'texengine'};
6949: }
6950: }
6951: }
6952: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6953: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
6954: '<span class="LC_nobreak">'.$choices{'texengine'}.
6955: '</span></td><td class="LC_right_item">'.
6956: '<select name="texengine">'."\n";
6957: my %texoptions = (
6958: MathJax => 'MathJax',
6959: mimetex => &mt('Convert to Images'),
6960: tth => &mt('TeX to HTML'),
6961: );
6962: foreach my $renderer ('MathJax','mimetex','tth') {
6963: my $selected = '';
6964: if ($renderer eq $deftex) {
6965: $selected = ' selected="selected"';
6966: }
6967: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
6968: }
6969: $mathdisp .= '</select></td></tr>'."\n";
6970: $itemcount ++;
1.139 raeburn 6971: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 6972: \%choices,$itemcount);
1.314 raeburn 6973: $datatable = $mathdisp.$datatable;
1.264 raeburn 6974: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6975: $datatable .=
1.306 raeburn 6976: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 6977: '<span class="LC_nobreak">'.$choices{'canclone'}.
6978: '</span></td><td class="LC_left_item">';
6979: my $currcanclone = 'none';
6980: my $onclick;
6981: my @cloneoptions = ('none','domain');
1.380 raeburn 6982: my %clonetitles = &Apache::lonlocal::texthash (
1.264 raeburn 6983: none => 'No additional course requesters',
6984: domain => "Any course requester in course's domain",
6985: instcode => 'Course requests for official courses ...',
6986: );
6987: my (%codedefaults,@code_order,@posscodes);
6988: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
6989: \@code_order) eq 'ok') {
6990: if (@code_order > 0) {
6991: push(@cloneoptions,'instcode');
6992: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
6993: }
6994: }
6995: if (ref($settings) eq 'HASH') {
6996: if ($settings->{'canclone'}) {
6997: if (ref($settings->{'canclone'}) eq 'HASH') {
6998: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
6999: if (@code_order > 0) {
7000: $currcanclone = 'instcode';
7001: @posscodes = @{$settings->{'canclone'}{'instcode'}};
7002: }
7003: }
7004: } elsif ($settings->{'canclone'} eq 'domain') {
7005: $currcanclone = $settings->{'canclone'};
7006: }
7007: }
1.289 raeburn 7008: }
1.264 raeburn 7009: foreach my $option (@cloneoptions) {
7010: my ($checked,$additional);
7011: if ($currcanclone eq $option) {
7012: $checked = ' checked="checked"';
7013: }
7014: if ($option eq 'instcode') {
7015: if (@code_order) {
7016: my $show = 'none';
7017: if ($checked) {
7018: $show = 'block';
7019: }
1.317 raeburn 7020: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 7021: &mt('Institutional codes for new and cloned course have identical:').
7022: '<br />';
7023: foreach my $item (@code_order) {
7024: my $codechk;
7025: if ($checked) {
7026: if (grep(/^\Q$item\E$/,@posscodes)) {
7027: $codechk = ' checked="checked"';
7028: }
7029: }
7030: $additional .= '<label>'.
7031: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
7032: $item.'</label>';
7033: }
7034: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
7035: }
7036: }
7037: $datatable .=
7038: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
7039: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
7040: '</label> '.$additional.'</span><br />';
7041: }
7042: $datatable .= '</td>'.
7043: '</tr>';
7044: $itemcount ++;
1.139 raeburn 7045: } else {
7046: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.428 raeburn 7047: my ($currdefresponder,%defcredits,%curruploadquota,%currcoursequota,
7048: %deftimeout,%currmysql);
1.192 raeburn 7049: my $currusecredits = 0;
1.257 raeburn 7050: my $postsubmitclient = 1;
1.405 raeburn 7051: my $ltiauth = 0;
1.422 raeburn 7052: my %domexttool;
7053: my %exttool;
1.432 raeburn 7054: my %crsauthor;
1.438 raeburn 7055: my %crseditors;
1.271 raeburn 7056: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 7057: if (ref($settings) eq 'HASH') {
1.404 raeburn 7058: if ($settings->{'ltiauth'}) {
7059: $ltiauth = 1;
1.405 raeburn 7060: }
1.422 raeburn 7061: if (ref($settings->{'domexttool'}) eq 'HASH') {
7062: foreach my $type (@types) {
7063: if ($settings->{'domexttool'}->{$type}) {
7064: $domexttool{$type} = ' checked="checked"';
7065: }
7066: }
7067: } else {
7068: foreach my $type (@types) {
7069: if ($staticdefaults{'domexttool'}) {
7070: $domexttool{$type} = ' checked="checked"';
7071: }
7072: }
7073: }
7074: if (ref($settings->{'exttool'}) eq 'HASH') {
7075: foreach my $type (@types) {
7076: if ($settings->{'exttool'}->{$type}) {
7077: $exttool{$type} = ' checked="checked"';
7078: }
7079: }
7080: }
1.432 raeburn 7081: if (ref($settings->{'crsauthor'}) eq 'HASH') {
7082: foreach my $type (@types) {
7083: if ($settings->{'crsauthor'}->{$type}) {
7084: $crsauthor{$type} = ' checked="checked"';
7085: }
7086: }
7087: } else {
7088: foreach my $type (@types) {
7089: if ($staticdefaults{'crsauthor'}) {
7090: $crsauthor{$type} = ' checked="checked"';
7091: }
7092: }
7093: }
1.438 raeburn 7094: if (ref($settings->{'crseditors'}) eq 'ARRAY') {
7095: foreach my $editor (@{$settings->{'crseditors'}}) {
7096: $crseditors{$editor} = ' checked="checked"';
7097: }
7098: } else {
7099: foreach my $editor (@{$staticdefaults{'crseditors'}}) {
7100: $crseditors{$editor} = ' checked="checked"';
7101: }
7102: }
1.139 raeburn 7103: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 7104: if (ref($settings->{'uploadquota'}) eq 'HASH') {
7105: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
7106: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
7107: }
7108: }
1.428 raeburn 7109: if (ref($settings->{'coursequota'}) eq 'HASH') {
7110: foreach my $type (keys(%{$settings->{'coursequota'}})) {
7111: $currcoursequota{$type} = $settings->{'coursequota'}{$type};
7112: }
7113: }
1.192 raeburn 7114: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 7115: foreach my $type (@types) {
7116: next if ($type eq 'community');
7117: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
7118: if ($defcredits{$type} ne '') {
7119: $currusecredits = 1;
7120: }
7121: }
7122: }
7123: if (ref($settings->{'postsubmit'}) eq 'HASH') {
7124: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
7125: $postsubmitclient = 0;
7126: foreach my $type (@types) {
7127: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7128: }
7129: } else {
7130: foreach my $type (@types) {
7131: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
7132: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 7133: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 7134: } else {
7135: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7136: }
7137: } else {
7138: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7139: }
7140: }
7141: }
7142: } else {
7143: foreach my $type (@types) {
7144: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 7145: }
7146: }
1.276 raeburn 7147: if (ref($settings->{'mysqltables'}) eq 'HASH') {
7148: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
7149: $currmysql{$type} = $settings->{'mysqltables'}{$type};
7150: }
7151: } else {
7152: foreach my $type (@types) {
7153: $currmysql{$type} = $staticdefaults{'mysqltables'};
7154: }
7155: }
1.258 raeburn 7156: } else {
7157: foreach my $type (@types) {
7158: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.422 raeburn 7159: if ($staticdefaults{'domexttool'}) {
7160: $domexttool{$type} = ' checked="checked"';
7161: }
1.432 raeburn 7162: if ($staticdefaults{'crsauthor'}) {
7163: $crsauthor{$type} = ' checked="checked"';
7164: }
1.258 raeburn 7165: }
1.438 raeburn 7166: foreach my $editor (@{$staticdefaults{'crseditors'}}) {
7167: $crseditors{$editor} = ' checked="checked"';
7168: }
1.139 raeburn 7169: }
7170: if (!$currdefresponder) {
1.198 raeburn 7171: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 7172: } elsif ($currdefresponder < 1) {
7173: $currdefresponder = 1;
7174: }
1.198 raeburn 7175: foreach my $type (@types) {
7176: if ($curruploadquota{$type} eq '') {
7177: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
7178: }
1.428 raeburn 7179: if ($currcoursequota{$type} eq '') {
7180: $currcoursequota{$type} = $staticdefaults{'coursequota'};
7181: }
1.198 raeburn 7182: }
1.139 raeburn 7183: $datatable .=
1.192 raeburn 7184: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7185: $choices{'anonsurvey_threshold'}.
1.139 raeburn 7186: '</span></td>'.
7187: '<td class="LC_right_item"><span class="LC_nobreak">'.
7188: '<input type="text" name="anonsurvey_threshold"'.
7189: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 7190: '</td></tr>'."\n";
7191: $itemcount ++;
7192: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7193: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7194: $choices{'uploadquota'}.
7195: '</span></td>'.
1.306 raeburn 7196: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 7197: '<table><tr>';
1.198 raeburn 7198: foreach my $type (@types) {
1.306 raeburn 7199: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 7200: '<input type="text" name="uploadquota_'.$type.'"'.
7201: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
7202: }
7203: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 7204: $itemcount ++;
1.428 raeburn 7205: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7206: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7207: $choices{'coursequota'}.
7208: '</span></td>'.
7209: '<td style="text-align: right" class="LC_right_item">'.
7210: '<table><tr>';
7211: foreach my $type (@types) {
7212: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
7213: '<input type="text" name="coursequota_'.$type.'"'.
7214: ' value="'.$currcoursequota{$type}.'" size="5" /></td>';
7215: }
7216: $datatable .= '</tr></table></td></tr>'."\n";
7217: $itemcount ++;
1.236 raeburn 7218: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 7219: my $display = 'none';
1.192 raeburn 7220: if ($currusecredits) {
7221: $display = 'block';
7222: }
7223: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 7224: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
7225: foreach my $type (@types) {
7226: next if ($type eq 'community');
1.306 raeburn 7227: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7228: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 7229: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 7230: }
7231: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 7232: %defaultchecked = ('coursecredits' => 'off');
7233: @toggles = ('coursecredits');
7234: my $current = {
7235: 'coursecredits' => $currusecredits,
7236: };
7237: (my $table,$itemcount) =
7238: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 7239: \%choices,$itemcount,$onclick,$additional,'left');
7240: $datatable .= $table;
7241: $onclick = "toggleDisplay(this.form,'studentsubmission');";
7242: my $display = 'none';
7243: if ($postsubmitclient) {
7244: $display = 'block';
7245: }
7246: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 7247: &mt('Number of seconds submit is disabled').'<br />'.
7248: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
7249: '<table><tr>';
1.257 raeburn 7250: foreach my $type (@types) {
1.306 raeburn 7251: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7252: '<input type="text" name="'.$type.'_timeout" value="'.
7253: $deftimeout{$type}.'" size="5" /></td>';
7254: }
7255: $additional .= '</tr></table></div>'."\n";
7256: %defaultchecked = ('postsubmit' => 'on');
7257: @toggles = ('postsubmit');
1.280 raeburn 7258: $current = {
7259: 'postsubmit' => $postsubmitclient,
7260: };
1.257 raeburn 7261: ($table,$itemcount) =
7262: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7263: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 7264: $datatable .= $table;
1.276 raeburn 7265: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7266: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7267: $choices{'mysqltables'}.
7268: '</span></td>'.
1.306 raeburn 7269: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 7270: '<table><tr>';
7271: foreach my $type (@types) {
1.306 raeburn 7272: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 7273: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 7274: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 7275: }
7276: $datatable .= '</tr></table></td></tr>'."\n";
7277: $itemcount ++;
1.404 raeburn 7278: %defaultchecked = ('ltiauth' => 'off');
7279: @toggles = ('ltiauth');
7280: $current = {
7281: 'ltiauth' => $ltiauth,
7282: };
7283: ($table,$itemcount) =
7284: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7285: \%choices,$itemcount,undef,undef,'left');
7286: $datatable .= $table;
1.422 raeburn 7287: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7288: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7289: $choices{'domexttool'}.
7290: '</span></td>'.
7291: '<td style="text-align: right" class="LC_right_item">'.
7292: '<table><tr>';
7293: foreach my $type (@types) {
7294: $datatable .= '<td style="text-align: left">'.
7295: '<span class="LC_nobreak">'.
1.438 raeburn 7296: '<label><input type="checkbox" name="domexttool"'.
1.422 raeburn 7297: ' value="'.$type.'"'.$domexttool{$type}.' />'.
1.438 raeburn 7298: &mt($type).'</label></span></td>'."\n";
1.422 raeburn 7299: }
7300: $datatable .= '</tr></table></td></tr>'."\n";
1.404 raeburn 7301: $itemcount ++;
1.422 raeburn 7302: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7303: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7304: $choices{'exttool'}.
7305: '</span></td>'.
7306: '<td style="text-align: right" class="LC_right_item">'.
7307: '<table><tr>';
7308: foreach my $type (@types) {
7309: $datatable .= '<td style="text-align: left">'.
7310: '<span class="LC_nobreak">'.
1.438 raeburn 7311: '<label><input type="checkbox" name="exttool"'.
1.422 raeburn 7312: ' value="'.$type.'"'.$exttool{$type}.' />'.
1.438 raeburn 7313: &mt($type).'</label></span></td>'."\n";
1.422 raeburn 7314: }
7315: $datatable .= '</tr></table></td></tr>'."\n";
1.432 raeburn 7316: $itemcount ++;
7317: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7318: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7319: $choices{'crsauthor'}.
7320: '</span></td>'.
7321: '<td style="text-align: right" class="LC_right_item">'.
7322: '<table><tr>';
7323: foreach my $type (@types) {
7324: $datatable .= '<td style="text-align: left">'.
7325: '<span class="LC_nobreak">'.
1.438 raeburn 7326: '<label><input type="checkbox" name="crsauthor"'.
1.432 raeburn 7327: ' value="'.$type.'"'.$crsauthor{$type}.' />'.
1.438 raeburn 7328: &mt($type).'</label></span></td>'."\n";
7329: }
7330: $datatable .= '</tr></table></td></tr>'."\n";
7331: $itemcount ++;
7332: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7333: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7334: $choices{'crseditors'}.
7335: '</span></td>'.
7336: '<td style="text-align: right" class="LC_right_item">'.
7337: '<table><tr>';
7338: my @editors = ('edit','xml','daxe');
7339: my %editornames = &crseditor_titles();
7340: foreach my $editor (@editors) {
7341: $datatable .= '<td style="text-align: left">'.
7342: '<span class="LC_nobreak">'.
7343: '<label><input type="checkbox" name="crseditors"'.
7344: ' value="'.$editor.'"'.$crseditors{$editor}.' />'.
7345: $editornames{$editor}.'</label></span></td>'."\n";
1.432 raeburn 7346: }
7347: $datatable .= '</tr></table></td></tr>'."\n";
1.139 raeburn 7348: }
1.192 raeburn 7349: $$rowtotal += $itemcount;
1.121 raeburn 7350: return $datatable;
1.118 jms 7351: }
7352:
1.438 raeburn 7353: sub crseditor_titles {
7354: return &Apache::lonlocal::texthash(
7355: edit => 'Standard editor (Edit)',
7356: xml => 'Text editor (EditXML)',
7357: daxe => 'Daxe editor (Daxe)',
7358: );
7359: }
7360:
1.429 raeburn 7361: sub print_authordefaults {
7362: my ($position,$dom,$settings,$rowtotal) = @_;
7363: my ($css_class,$datatable,%checkedon,%checkedoff);
7364: my $itemcount = 1;
7365: my %titles = &authordefaults_titles();
7366: if ($position eq 'top') {
7367: my %defaultchecked = (
7368: 'nocodemirror' => 'off',
1.437 raeburn 7369: 'daxecollapse' => 'off',
1.429 raeburn 7370: 'domcoordacc' => 'on',
7371: );
1.437 raeburn 7372: my @toggles = ('nocodemirror','daxecollapse','domcoordacc');
1.429 raeburn 7373: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
7374: \%titles,$itemcount);
7375: my %staticdefaults = (
7376: 'copyright' => 'default',
7377: 'sourceavail' => 'closed',
7378: );
7379: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7380: my %currrights;
7381: foreach my $item ('copyright','sourceavail') {
7382: $currrights{$item} = $staticdefaults{$item};
7383: if (ref($settings) eq 'HASH') {
7384: if (exists($settings->{$item})) {
7385: $currrights{$item} = $settings->{$item};
7386: }
7387: }
7388: }
7389: $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
7390: '<span class="LC_nobreak">'.$titles{'copyright'}.
7391: '</span></td><td class="LC_right_item">'.
7392: &selectbox('copyright',$currrights{'copyright'},'',
7393: \&Apache::loncommon::copyrightdescription,
7394: (grep !/^priv|custom$/,(&Apache::loncommon::copyrightids))).
7395: '</td></tr>'."\n";
7396: $itemcount ++;
7397: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7398: $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
7399: '<span class="LC_nobreak">'.$titles{'sourceavail'}.
7400: '</span></td><td class="LC_right_item">'.
7401: &selectbox('sourceavail',$currrights{'sourceavail'},'',
7402: \&Apache::loncommon::source_copyrightdescription,
7403: (&Apache::loncommon::source_copyrightids)).
7404: '</td></tr>'."\n";
7405: } else {
7406: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7407: my $curreditors;
7408: my %staticdefaults = (
7409: editors => ['edit','xml'],
7410: authorquota => 500,
7411: webdav => 0,
7412: );
7413: my $curreditors = $staticdefaults{'editors'};
7414: if ((ref($settings) eq 'HASH') &&
7415: (ref($settings->{'editors'}) eq 'ARRAY')) {
7416: $curreditors = $settings->{'editors'};
7417: } else {
7418: $curreditors = $staticdefaults{'editors'};
7419: }
7420: my @editors = ('edit','xml','daxe');
7421: $datatable = '<tr'.$css_class.'>'."\n".
7422: '<td>'.$titles{'editors'}.'</td>'."\n".
7423: '<td class="LC_left_item">'."\n".
7424: '<span class="LC_nobreak">';
7425: foreach my $editor (@editors) {
7426: my $checked;
7427: if (grep(/^\Q$editor\E$/,@{$curreditors})) {
7428: $checked = ' checked="checked"';
7429: }
7430: $datatable .= '<label>'.
7431: '<input type="checkbox" name="author_editors" '.
7432: $checked.' value="'.$editor.'" '.
7433: 'onclick="javascript:checkEditors(this.form,'."'author_editors'".',this);" />'.
7434: $titles{$editor}.'</label> ';
7435: }
7436: $datatable .= '</span>'."\n".'</td>'."\n".'</tr>'."\n";
7437: $itemcount ++;
7438: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7439: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7440: my @insttypes;
7441: if (ref($types) eq 'ARRAY') {
7442: @insttypes = @{$types};
7443: }
7444: my $typecount = 0;
7445: my %domconf = &Apache::lonnet::get_dom('configuration',['quotas'],$dom);
7446: my @items = ('webdav','authorquota');
7447: my %quotas;
7448: if (ref($domconf{'quotas'}) eq 'HASH') {
7449: %quotas = %{$domconf{'quotas'}};
7450: foreach my $item (@items) {
7451: if (ref($quotas{$item}) eq 'HASH') {
7452: foreach my $type (@insttypes,'default') {
7453: if ($item eq 'authorquota') {
7454: if ($quotas{$item}{$type} !~ /^\d+$/) {
7455: $quotas{$item}{$type} = $staticdefaults{$item};
7456: }
7457: } elsif ($item eq 'webdav') {
7458: if ($quotas{$item}{$type} !~ /^(0|1)$/) {
7459: $quotas{$item}{$type} = $staticdefaults{$item};
7460: }
7461: }
7462: }
7463: } else {
7464: foreach my $type (@insttypes,'default') {
7465: $quotas{$item}{$type} = $staticdefaults{$item};
7466: }
7467: }
7468: }
7469: } else {
7470: foreach my $item (@items) {
7471: foreach my $type (@insttypes,'default') {
7472: $quotas{$item}{$type} = $staticdefaults{$item};
7473: }
7474: }
7475: }
7476: if (ref($usertypes) eq 'HASH') {
7477: my $numinrow = 4;
7478: my $onclick = '';
7479: $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
7480: $numinrow,$othertitle,'authorquota',
7481: \$itemcount,$onclick);
7482: $itemcount ++;
7483: $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
7484: $numinrow,$othertitle,'webdav',
7485: \$itemcount);
7486: $itemcount ++;
7487: }
7488: my $checkedno = ' checked="checked"';
7489: my ($checkedon,$checkedoff);
7490: if (ref($quotas{'webdav'}) eq 'HASH') {
1.436 raeburn 7491: if ($quotas{'webdav'}{'_LC_adv'} =~ /^0|1$/) {
1.429 raeburn 7492: if ($quotas{'webdav'}{'_LC_adv'}) {
7493: $checkedon = $checkedno;
7494: } else {
7495: $checkedoff = $checkedno;
7496: }
7497: undef($checkedno);
7498: }
7499: }
7500: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7501: $datatable .= '<tr'.$css_class.'>'.
7502: '<td>'.$titles{'webdav_LC_adv'}.'<br />'.
7503: $titles{'webdav_LC_adv_over'}.
7504: '</td>'.
7505: '<td class="LC_left_item">';
7506: foreach my $option ('none','off','on') {
7507: my ($text,$val,$checked);
7508: if ($option eq 'none') {
7509: $text = $titles{'none'};
7510: $val = '';
7511: $checked = $checkedno;
7512: } elsif ($option eq 'off') {
7513: $text = $titles{'overoff'};
7514: $val = 0;
7515: $checked = $checkedoff;
7516: } elsif ($option eq 'on') {
7517: $text = $titles{'overon'};
7518: $val = 1;
7519: $checked = $checkedon;
1.436 raeburn 7520: }
1.429 raeburn 7521: $datatable .= '<span class="LC_nobreak"><label>'.
7522: '<input type="radio" name="webdav_LC_adv"'.
7523: ' value="'.$val.'"'.$checked.' />'.
7524: $text.'</label></span> ';
7525: }
7526: $datatable .= '</td></tr>';
7527: $itemcount ++;
1.440 raeburn 7528: my %defchecked = (
7529: 'archive' => 'off',
7530: );
7531: my @toggles = ('archive');
7532: (my $archive,$itemcount) = &radiobutton_prefs($settings,['archive'],
7533: {'archive' => 'off'},
7534: \%titles,$itemcount);
7535: $datatable .= $archive."\n";
7536: $itemcount ++;
1.429 raeburn 7537: }
7538: $$rowtotal += $itemcount;
7539: return $datatable;
7540: }
7541:
7542: sub authordefaults_titles {
7543: return &Apache::lonlocal::texthash(
7544: copyright => 'Copyright/Distribution',
7545: sourceavail => ' Source Available',
7546: editors => 'Available Editors',
7547: webdav => 'WebDAV',
7548: authorquota => 'Authoring Space quotas (MB)',
7549: nocodemirror => 'Deactivate CodeMirror for EditXML editor',
1.437 raeburn 7550: daxecollapse => 'Daxe editor: LON-CAPA standard menus start collapsed',
1.429 raeburn 7551: domcoordacc => 'Dom. Coords. can enter Authoring Spaces in domain',
7552: edit => 'Standard editor (Edit)',
7553: xml => 'Text editor (EditXML)',
7554: daxe => 'Daxe editor (Daxe)',
7555: webdav_LC_adv => 'WebDAV access for LON-CAPA "advanced" users',
7556: webdav_LC_adv_over => '(overrides access based on affiliation, if set)',
7557: none => 'No override set',
7558: overon => 'Override -- webDAV on',
1.436 raeburn 7559: overoff => 'Override -- webDAV off',
1.440 raeburn 7560: archive => 'Authors can download tar.gz file of Authoring Space',
1.429 raeburn 7561: );
7562: }
7563:
7564: sub selectbox {
7565: my ($name,$value,$readonly,$functionref,@idlist)=@_;
7566: my $selout = '<select name="'.$name.'">';
7567: foreach my $id (@idlist) {
7568: $selout.='<option value="'.$id.'"';
7569: if ($id eq $value) {
7570: $selout.=' selected="selected"';
7571: }
7572: if ($readonly) {
7573: $selout .= ' disabled="disabled"';
7574: }
7575: $selout.='>'.&{$functionref}($id).'</option>';
7576: }
7577: $selout.='</select>';
7578: return $selout;
7579: }
7580:
1.231 raeburn 7581: sub print_selfenrollment {
7582: my ($position,$dom,$settings,$rowtotal) = @_;
7583: my ($css_class,$datatable);
7584: my $itemcount = 1;
1.271 raeburn 7585: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 7586: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 7587: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
7588: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 7589: my @rows;
7590: my $key;
7591: if ($position eq 'top') {
7592: $key = 'admin';
7593: if (ref($rowsref) eq 'ARRAY') {
7594: @rows = @{$rowsref};
7595: }
7596: } elsif ($position eq 'middle') {
7597: $key = 'default';
7598: @rows = ('types','registered','approval','limit');
7599: }
7600: foreach my $row (@rows) {
7601: if (defined($titlesref->{$row})) {
7602: $itemcount ++;
7603: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7604: $datatable .= '<tr'.$css_class.'>'.
7605: '<td>'.$titlesref->{$row}.'</td>'.
7606: '<td class="LC_left_item">'.
7607: '<table><tr>';
7608: my (%current,%currentcap);
7609: if (ref($settings) eq 'HASH') {
7610: if (ref($settings->{$key}) eq 'HASH') {
7611: foreach my $type (@types) {
7612: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7613: $current{$type} = $settings->{$key}->{$type}->{$row};
7614: }
7615: if (($row eq 'limit') && ($key eq 'default')) {
7616: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7617: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
7618: }
7619: }
7620: }
7621: }
7622: }
7623: my %roles = (
7624: '0' => &Apache::lonnet::plaintext('dc'),
7625: );
7626:
7627: foreach my $type (@types) {
7628: unless (($row eq 'registered') && ($key eq 'default')) {
7629: $datatable .= '<th>'.&mt($type).'</th>';
7630: }
7631: }
7632: unless (($row eq 'registered') && ($key eq 'default')) {
7633: $datatable .= '</tr><tr>';
7634: }
7635: foreach my $type (@types) {
7636: if ($type eq 'community') {
7637: $roles{'1'} = &mt('Community personnel');
7638: } else {
7639: $roles{'1'} = &mt('Course personnel');
7640: }
7641: $datatable .= '<td style="vertical-align: top">';
7642: if ($position eq 'top') {
7643: my %checked;
7644: if ($current{$type} eq '0') {
7645: $checked{'0'} = ' checked="checked"';
7646: } else {
7647: $checked{'1'} = ' checked="checked"';
7648: }
7649: foreach my $role ('1','0') {
7650: $datatable .= '<span class="LC_nobreak"><label>'.
7651: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
7652: 'value="'.$role.'"'.$checked{$role}.' />'.
7653: $roles{$role}.'</label></span> ';
7654: }
7655: } else {
7656: if ($row eq 'types') {
7657: my %checked;
7658: if ($current{$type} =~ /^(all|dom)$/) {
7659: $checked{$1} = ' checked="checked"';
7660: } else {
7661: $checked{''} = ' checked="checked"';
7662: }
7663: foreach my $val ('','dom','all') {
7664: $datatable .= '<span class="LC_nobreak"><label>'.
7665: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7666: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7667: }
7668: } elsif ($row eq 'registered') {
7669: my %checked;
7670: if ($current{$type} eq '1') {
7671: $checked{'1'} = ' checked="checked"';
7672: } else {
7673: $checked{'0'} = ' checked="checked"';
7674: }
7675: foreach my $val ('0','1') {
7676: $datatable .= '<span class="LC_nobreak"><label>'.
7677: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7678: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7679: }
7680: } elsif ($row eq 'approval') {
7681: my %checked;
7682: if ($current{$type} =~ /^([12])$/) {
7683: $checked{$1} = ' checked="checked"';
7684: } else {
7685: $checked{'0'} = ' checked="checked"';
7686: }
7687: for my $val (0..2) {
7688: $datatable .= '<span class="LC_nobreak"><label>'.
7689: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7690: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7691: }
7692: } elsif ($row eq 'limit') {
7693: my %checked;
7694: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
7695: $checked{$1} = ' checked="checked"';
7696: } else {
7697: $checked{'none'} = ' checked="checked"';
7698: }
7699: my $cap;
7700: if ($currentcap{$type} =~ /^\d+$/) {
7701: $cap = $currentcap{$type};
7702: }
7703: foreach my $val ('none','allstudents','selfenrolled') {
7704: $datatable .= '<span class="LC_nobreak"><label>'.
7705: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7706: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7707: }
7708: $datatable .= '<br />'.
7709: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
7710: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
7711: '</span>';
7712: }
7713: }
7714: $datatable .= '</td>';
7715: }
7716: $datatable .= '</tr>';
7717: }
7718: $datatable .= '</table></td></tr>';
7719: }
7720: } elsif ($position eq 'bottom') {
1.235 raeburn 7721: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
7722: }
7723: $$rowtotal += $itemcount;
7724: return $datatable;
7725: }
7726:
7727: sub print_validation_rows {
7728: my ($caller,$dom,$settings,$rowtotal) = @_;
7729: my ($itemsref,$namesref,$fieldsref);
7730: if ($caller eq 'selfenroll') {
7731: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
7732: } elsif ($caller eq 'requestcourses') {
7733: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
7734: }
7735: my %currvalidation;
7736: if (ref($settings) eq 'HASH') {
7737: if (ref($settings->{'validation'}) eq 'HASH') {
7738: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 7739: }
1.235 raeburn 7740: }
7741: my $datatable;
7742: my $itemcount = 0;
7743: foreach my $item (@{$itemsref}) {
7744: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7745: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7746: $namesref->{$item}.
7747: '</span></td>'.
7748: '<td class="LC_left_item">';
7749: if (($item eq 'url') || ($item eq 'button')) {
7750: $datatable .= '<span class="LC_nobreak">'.
7751: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
7752: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
7753: } elsif ($item eq 'fields') {
7754: my @currfields;
7755: if (ref($currvalidation{$item}) eq 'ARRAY') {
7756: @currfields = @{$currvalidation{$item}};
7757: }
7758: foreach my $field (@{$fieldsref}) {
7759: my $check = '';
7760: if (grep(/^\Q$field\E$/,@currfields)) {
7761: $check = ' checked="checked"';
7762: }
7763: $datatable .= '<span class="LC_nobreak"><label>'.
7764: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
7765: ' value="'.$field.'"'.$check.' />'.$field.
7766: '</label></span> ';
7767: }
7768: } elsif ($item eq 'markup') {
1.334 raeburn 7769: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 7770: $currvalidation{$item}.
1.231 raeburn 7771: '</textarea>';
1.235 raeburn 7772: }
7773: $datatable .= '</td></tr>'."\n";
7774: if (ref($rowtotal)) {
1.231 raeburn 7775: $itemcount ++;
7776: }
7777: }
1.235 raeburn 7778: if ($caller eq 'requestcourses') {
7779: my %currhash;
1.248 raeburn 7780: if (ref($settings) eq 'HASH') {
7781: if (ref($settings->{'validation'}) eq 'HASH') {
7782: if ($settings->{'validation'}{'dc'} ne '') {
7783: $currhash{$settings->{'validation'}{'dc'}} = 1;
7784: }
1.235 raeburn 7785: }
7786: }
7787: my $numinrow = 2;
7788: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
7789: 'validationdc',%currhash);
1.247 raeburn 7790: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 7791: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 7792: if ($numdc > 1) {
1.247 raeburn 7793: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 7794: } else {
1.247 raeburn 7795: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 7796: }
1.247 raeburn 7797: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 7798: $itemcount ++;
7799: }
7800: if (ref($rowtotal)) {
7801: $$rowtotal += $itemcount;
7802: }
1.231 raeburn 7803: return $datatable;
7804: }
7805:
1.357 raeburn 7806: sub print_privacy {
7807: my ($position,$dom,$settings,$rowtotal) = @_;
7808: my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
7809: my $itemcount = 0;
1.417 raeburn 7810: if ($position eq 'top') {
7811: $numinrow = 2;
7812: } else {
1.357 raeburn 7813: @items = ('domain','author','course','community');
7814: %names = &Apache::lonlocal::texthash (
7815: domain => 'Assigned domain role(s)',
7816: author => 'Assigned co-author role(s)',
7817: course => 'Assigned course role(s)',
1.416 raeburn 7818: community => 'Assigned community role(s)',
1.357 raeburn 7819: );
7820: $numinrow = 4;
7821: ($othertitle,$usertypes,$types) =
7822: &Apache::loncommon::sorted_inst_types($dom);
7823: }
7824: if (($position eq 'top') || ($position eq 'middle')) {
7825: my (%by_ip,%by_location,@intdoms,@instdoms);
7826: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
7827: if ($position eq 'top') {
7828: my %curr;
7829: my @options = ('none','user','domain','auto');
7830: my %titles = &Apache::lonlocal::texthash (
7831: none => 'Not allowed',
7832: user => 'User authorizes',
7833: domain => 'DC authorizes',
7834: auto => 'Unrestricted',
7835: instdom => 'Other domain shares institution/provider',
7836: extdom => 'Other domain has different institution/provider',
1.418 raeburn 7837: notify => 'Notify when role needs authorization',
1.357 raeburn 7838: );
7839: my %names = &Apache::lonlocal::texthash (
7840: domain => 'Domain role',
7841: author => 'Co-author role',
7842: course => 'Course role',
7843: community => 'Community role',
7844: );
7845: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7846: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7847: foreach my $domtype ('instdom','extdom') {
7848: my (%checked,$skip);
7849: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7850: $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
7851: '<td class="LC_left_item">';
7852: if ($domtype eq 'instdom') {
7853: unless (@instdoms > 1) {
7854: $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
7855: $skip = 1;
7856: }
7857: } elsif ($domtype eq 'extdom') {
7858: if (keys(%by_location) == 0) {
7859: $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
7860: $skip = 1;
7861: }
7862: }
7863: unless ($skip) {
7864: foreach my $roletype ('domain','author','course','community') {
7865: $checked{'auto'} = ' checked="checked"';
7866: if (ref($settings) eq 'HASH') {
7867: if (ref($settings->{approval}) eq 'HASH') {
7868: if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
7869: if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
7870: $checked{$1} = ' checked="checked"';
7871: $checked{'auto'} = '';
7872: }
7873: }
7874: }
7875: }
7876: $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
7877: foreach my $option (@options) {
7878: $datatable .= '<span class="LC_nobreak"><label>'.
7879: '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
7880: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
7881: '</label></span> ';
7882: }
7883: $datatable .= '</fieldset>';
7884: }
7885: }
7886: $datatable .= '</td></tr>';
7887: $itemcount ++;
7888: }
1.417 raeburn 7889: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7890: $datatable .= '<tr'.$css_class.'><td>'.$titles{'notify'}.'</td>'.
7891: '<td class="LC_left_item">';
7892: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7893: my %curr;
7894: if (ref($settings) eq 'HASH') {
7895: if ($settings->{'notify'} ne '') {
7896: map {$curr{$_}=1;} split(/,/,$settings->{'notify'});
7897: }
7898: }
7899: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7900: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
7901: 'privacy_notify',%curr);
7902: if ($numdc > 0) {
7903: $datatable .= $table;
7904: } else {
7905: $datatable .= &mt('There are no active Domain Coordinators');
7906: }
7907: } else {
7908: $datatable .= &mt('Nothing to set here, as there are no other domains');
7909: }
7910: $datatable .='</td></tr>';
1.357 raeburn 7911: } elsif ($position eq 'middle') {
7912: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7913: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7914: foreach my $item (@{$types}) {
7915: $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
7916: $numinrow,$itemcount,'','','','','',
7917: '',$usertypes->{$item});
7918: $itemcount ++;
7919: }
7920: }
7921: $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
7922: $numinrow,$itemcount,'','','','','',
7923: '',$othertitle);
7924: $itemcount ++;
7925: } else {
1.360 raeburn 7926: my (@insttypes,%insttitles);
7927: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7928: @insttypes = @{$types};
7929: %insttitles = %{$usertypes};
7930: }
7931: foreach my $item (@insttypes,'default') {
7932: my $title;
7933: if ($item eq 'default') {
7934: $title = $othertitle;
7935: } else {
7936: $title = $insttitles{$item};
7937: }
7938: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7939: $datatable .= '<tr'.$css_class.'>'.
7940: '<td class="LC_left_item">'.$title.'</td>'.
7941: '<td class="LC_left_item">'.
7942: &mt('Nothing to set here, as there are no other domains').
7943: '</td></tr>';
7944: $itemcount ++;
7945: }
1.357 raeburn 7946: }
7947: }
7948: } else {
7949: my $prefix;
7950: if ($position eq 'lower') {
7951: $prefix = 'priv';
7952: } else {
7953: $prefix = 'unpriv';
7954: }
7955: foreach my $item (@items) {
7956: $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
7957: $numinrow,$itemcount,'','','','','',
7958: '',$names{$item});
7959: $itemcount ++;
7960: }
7961: }
7962: if (ref($rowtotal)) {
7963: $$rowtotal += $itemcount;
7964: }
7965: return $datatable;
7966: }
7967:
1.354 raeburn 7968: sub print_passwords {
7969: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
7970: my ($datatable,$css_class);
7971: my $itemcount = 0;
7972: my %titles = &Apache::lonlocal::texthash (
7973: captcha => '"Forgot Password" CAPTCHA validation',
7974: link => 'Reset link expiration (hours)',
7975: case => 'Case-sensitive usernames/e-mail',
7976: prelink => 'Information required (form 1)',
7977: postlink => 'Information required (form 2)',
7978: emailsrc => 'LON-CAPA e-mail address type(s)',
7979: customtext => 'Domain specific text (HTML)',
7980: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
7981: intauth_check => 'Check bcrypt cost if authenticated',
7982: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
7983: permanent => 'Permanent e-mail address',
7984: critical => 'Critical notification address',
7985: notify => 'Notification address',
7986: min => 'Minimum password length',
7987: max => 'Maximum password length',
7988: chars => 'Required characters',
7989: expire => 'Password expiration (days)',
1.356 raeburn 7990: numsaved => 'Number of previous passwords to save and disallow reuse',
1.354 raeburn 7991: );
7992: if ($position eq 'top') {
7993: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7994: my $shownlinklife = 2;
7995: my $prelink = 'both';
7996: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
7997: if (ref($settings) eq 'HASH') {
7998: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
7999: $shownlinklife = $settings->{resetlink};
8000: }
8001: if (ref($settings->{resetcase}) eq 'ARRAY') {
8002: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
8003: }
8004: if ($settings->{resetprelink} =~ /^(both|either)$/) {
8005: $prelink = $settings->{resetprelink};
8006: }
8007: if (ref($settings->{resetpostlink}) eq 'HASH') {
8008: %postlink = %{$settings->{resetpostlink}};
8009: }
8010: if (ref($settings->{resetemail}) eq 'ARRAY') {
8011: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
8012: }
8013: if ($settings->{resetremove}) {
8014: $nostdtext = 1;
8015: }
8016: if ($settings->{resetcustom}) {
8017: $customurl = $settings->{resetcustom};
8018: }
8019: } else {
8020: if (ref($types) eq 'ARRAY') {
8021: foreach my $item (@{$types}) {
8022: $casesens{$item} = 1;
8023: $postlink{$item} = ['username','email'];
8024: }
8025: }
8026: $casesens{'default'} = 1;
8027: $postlink{'default'} = ['username','email'];
8028: $prelink = 'both';
8029: %emailsrc = (
8030: permanent => 1,
8031: critical => 1,
8032: notify => 1,
8033: );
8034: }
8035: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
8036: $itemcount ++;
8037: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8038: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
8039: '<td class="LC_left_item">'.
8040: '<input type="textbox" value="'.$shownlinklife.'" '.
8041: 'name="passwords_link" size="3" /></td></tr>';
8042: $itemcount ++;
8043: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8044: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
8045: '<td class="LC_left_item">';
8046: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8047: foreach my $item (@{$types}) {
8048: my $checkedcase;
8049: if ($casesens{$item}) {
8050: $checkedcase = ' checked="checked"';
8051: }
8052: $datatable .= '<span class="LC_nobreak"><label>'.
8053: '<input type="checkbox" name="passwords_case_sensitive" value="'.
8054: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369 raeburn 8055: '</span> ';
1.354 raeburn 8056: }
8057: }
8058: my $checkedcase;
8059: if ($casesens{'default'}) {
8060: $checkedcase = ' checked="checked"';
8061: }
8062: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
8063: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
8064: $othertitle.'</label></span></td>';
8065: $itemcount ++;
8066: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8067: my %checkedpre = (
8068: both => ' checked="checked"',
8069: either => '',
8070: );
8071: if ($prelink eq 'either') {
8072: $checkedpre{either} = ' checked="checked"';
8073: $checkedpre{both} = '';
8074: }
8075: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
8076: '<td class="LC_left_item"><span class="LC_nobreak">'.
8077: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
8078: &mt('Both username and e-mail address').'</label></span> '.
8079: '<span class="LC_nobreak"><label>'.
8080: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
8081: &mt('Either username or e-mail address').'</label></span></td></tr>';
8082: $itemcount ++;
8083: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8084: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
8085: '<td class="LC_left_item">';
8086: my %postlinked;
8087: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8088: foreach my $item (@{$types}) {
8089: undef(%postlinked);
8090: $datatable .= '<fieldset style="display: inline-block;">'.
8091: '<legend>'.$usertypes->{$item}.'</legend>';
8092: if (ref($postlink{$item}) eq 'ARRAY') {
8093: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
8094: }
8095: foreach my $field ('email','username') {
8096: my $checked;
8097: if ($postlinked{$field}) {
8098: $checked = ' checked="checked"';
8099: }
8100: $datatable .= '<span class="LC_nobreak"><label>'.
8101: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
8102: $field.'"'.$checked.' />'.$field.'</label>'.
8103: '<span> ';
8104: }
8105: $datatable .= '</fieldset>';
8106: }
8107: }
8108: if (ref($postlink{'default'}) eq 'ARRAY') {
8109: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
8110: }
8111: $datatable .= '<fieldset style="display: inline-block;">'.
8112: '<legend>'.$othertitle.'</legend>';
8113: foreach my $field ('email','username') {
8114: my $checked;
8115: if ($postlinked{$field}) {
8116: $checked = ' checked="checked"';
8117: }
8118: $datatable .= '<span class="LC_nobreak"><label>'.
8119: '<input type="checkbox" name="passwords_postlink_default" value="'.
8120: $field.'"'.$checked.' />'.$field.'</label>'.
8121: '<span> ';
8122: }
8123: $datatable .= '</fieldset></td></tr>';
8124: $itemcount ++;
8125: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8126: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
8127: '<td class="LC_left_item">';
8128: foreach my $type ('permanent','critical','notify') {
8129: my $checkedemail;
8130: if ($emailsrc{$type}) {
8131: $checkedemail = ' checked="checked"';
8132: }
8133: $datatable .= '<span class="LC_nobreak"><label>'.
8134: '<input type="checkbox" name="passwords_emailsrc" value="'.
8135: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
8136: '<span> ';
8137: }
8138: $datatable .= '</td></tr>';
8139: $itemcount ++;
8140: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8141: my $switchserver = &check_switchserver($dom,$confname);
8142: my ($showstd,$noshowstd);
8143: if ($nostdtext) {
8144: $noshowstd = ' checked="checked"';
8145: } else {
8146: $showstd = ' checked="checked"';
8147: }
8148: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
8149: '<td class="LC_left_item"><span class="LC_nobreak">'.
8150: &mt('Retain standard text:').
8151: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
8152: &mt('Yes').'</label>'.' '.
8153: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
8154: &mt('No').'</label></span><br />'.
8155: '<span class="LC_fontsize_small">'.
8156: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
8157: &mt('Include custom text:');
8158: if ($customurl) {
1.369 raeburn 8159: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354 raeburn 8160: undef,undef,undef,undef,'background-color:#ffffff');
8161: $datatable .= '<span class="LC_nobreak"> '.$link.
8162: '<label><input type="checkbox" name="passwords_custom_del"'.
8163: ' value="1" />'.&mt('Delete?').'</label></span>'.
8164: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
8165: }
8166: if ($switchserver) {
8167: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
8168: } else {
8169: $datatable .='<span class="LC_nobreak"> '.
8170: '<input type="file" name="passwords_customfile" /></span>';
8171: }
8172: $datatable .= '</td></tr>';
8173: } elsif ($position eq 'middle') {
8174: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
8175: my @items = ('intauth_cost','intauth_check','intauth_switch');
8176: my %defaults;
8177: if (ref($domconf{'defaults'}) eq 'HASH') {
8178: %defaults = %{$domconf{'defaults'}};
8179: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
8180: $defaults{'intauth_cost'} = 10;
8181: }
8182: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
8183: $defaults{'intauth_check'} = 0;
8184: }
8185: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
8186: $defaults{'intauth_switch'} = 0;
8187: }
8188: } else {
8189: %defaults = (
8190: 'intauth_cost' => 10,
8191: 'intauth_check' => 0,
8192: 'intauth_switch' => 0,
8193: );
8194: }
8195: foreach my $item (@items) {
8196: if ($itemcount%2) {
8197: $css_class = '';
8198: } else {
8199: $css_class = ' class="LC_odd_row" ';
8200: }
8201: $datatable .= '<tr'.$css_class.'>'.
8202: '<td><span class="LC_nobreak">'.$titles{$item}.
8203: '</span></td><td class="LC_left_item" colspan="3">';
8204: if ($item eq 'intauth_switch') {
8205: my @options = (0,1,2);
8206: my %optiondesc = &Apache::lonlocal::texthash (
8207: 0 => 'No',
8208: 1 => 'Yes',
8209: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
8210: );
8211: $datatable .= '<table width="100%">';
8212: foreach my $option (@options) {
8213: my $checked = ' ';
8214: if ($defaults{$item} eq $option) {
8215: $checked = ' checked="checked"';
8216: }
8217: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8218: '<label><input type="radio" name="'.$item.
8219: '" value="'.$option.'"'.$checked.' />'.
8220: $optiondesc{$option}.'</label></span></td></tr>';
8221: }
8222: $datatable .= '</table>';
8223: } elsif ($item eq 'intauth_check') {
8224: my @options = (0,1,2);
8225: my %optiondesc = &Apache::lonlocal::texthash (
8226: 0 => 'No',
8227: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
8228: 2 => 'Yes, disallow login if stored cost is less than domain default',
8229: );
8230: $datatable .= '<table width="100%">';
8231: foreach my $option (@options) {
8232: my $checked = ' ';
8233: my $onclick;
8234: if ($defaults{$item} eq $option) {
8235: $checked = ' checked="checked"';
8236: }
8237: if ($option == 2) {
8238: $onclick = ' onclick="javascript:warnIntAuth(this);"';
8239: }
8240: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8241: '<label><input type="radio" name="'.$item.
8242: '" value="'.$option.'"'.$checked.$onclick.' />'.
8243: $optiondesc{$option}.'</label></span></td></tr>';
8244: }
8245: $datatable .= '</table>';
8246: } else {
8247: $datatable .= '<input type="text" name="'.$item.'" value="'.
8248: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
8249: }
8250: $datatable .= '</td></tr>';
8251: $itemcount ++;
8252: }
8253: } elsif ($position eq 'lower') {
1.405 raeburn 8254: $datatable .= &password_rules('passwords',\$itemcount,$settings);
1.354 raeburn 8255: } else {
1.359 raeburn 8256: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8257: my %ownerchg = (
8258: by => {},
8259: for => {},
8260: );
8261: my %ownertitles = &Apache::lonlocal::texthash (
8262: by => 'Course owner status(es) allowed',
8263: for => 'Student status(es) allowed',
8264: );
1.354 raeburn 8265: if (ref($settings) eq 'HASH') {
1.359 raeburn 8266: if (ref($settings->{crsownerchg}) eq 'HASH') {
8267: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
8268: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
8269: }
8270: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
8271: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
8272: }
1.354 raeburn 8273: }
8274: }
8275: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8276: $datatable .= '<tr '.$css_class.'>'.
8277: '<td>'.
8278: &mt('Requirements').'<ul>'.
1.359 raeburn 8279: '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354 raeburn 8280: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
8281: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359 raeburn 8282: '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354 raeburn 8283: '</ul>'.
8284: '</td>'.
1.359 raeburn 8285: '<td class="LC_left_item">';
8286: foreach my $item ('by','for') {
8287: $datatable .= '<fieldset style="display: inline-block;">'.
8288: '<legend>'.$ownertitles{$item}.'</legend>';
8289: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8290: foreach my $type (@{$types}) {
8291: my $checked;
8292: if ($ownerchg{$item}{$type}) {
8293: $checked = ' checked="checked"';
8294: }
8295: $datatable .= '<span class="LC_nobreak"><label>'.
8296: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
8297: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369 raeburn 8298: '</span> ';
1.359 raeburn 8299: }
8300: }
8301: my $checked;
8302: if ($ownerchg{$item}{'default'}) {
8303: $checked = ' checked="checked"';
8304: }
8305: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
8306: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
8307: $othertitle.'</label></span></fieldset>';
8308: }
8309: $datatable .= '</td></tr>';
1.354 raeburn 8310: }
8311: return $datatable;
8312: }
8313:
1.405 raeburn 8314: sub password_rules {
8315: my ($prefix,$itemcountref,$settings) = @_;
8316: my ($min,$max,%chars,$expire,$numsaved,$numinrow);
8317: my %titles;
8318: if ($prefix eq 'passwords') {
8319: %titles = &Apache::lonlocal::texthash (
8320: min => 'Minimum password length',
8321: max => 'Maximum password length',
8322: chars => 'Required characters',
8323: );
1.421 raeburn 8324: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 8325: %titles = &Apache::lonlocal::texthash (
8326: min => 'Minimum secret length',
8327: max => 'Maximum secret length',
8328: chars => 'Required characters',
8329: );
8330: }
8331: $min = $Apache::lonnet::passwdmin;
8332: my $datatable;
8333: my $itemcount;
8334: if (ref($itemcountref)) {
8335: $itemcount = $$itemcountref;
8336: }
8337: if (ref($settings) eq 'HASH') {
8338: if ($settings->{min}) {
8339: $min = $settings->{min};
8340: }
8341: if ($settings->{max}) {
8342: $max = $settings->{max};
8343: }
8344: if (ref($settings->{chars}) eq 'ARRAY') {
8345: map { $chars{$_} = 1; } (@{$settings->{chars}});
8346: }
1.425 raeburn 8347: if ($prefix eq 'passwords') {
1.405 raeburn 8348: if ($settings->{expire}) {
8349: $expire = $settings->{expire};
8350: }
8351: if ($settings->{numsaved}) {
8352: $numsaved = $settings->{numsaved};
8353: }
8354: }
8355: }
8356: my %rulenames = &Apache::lonlocal::texthash(
8357: uc => 'At least one upper case letter',
8358: lc => 'At least one lower case letter',
8359: num => 'At least one number',
8360: spec => 'At least one non-alphanumeric',
8361: );
8362: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
8363: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
8364: '<td class="LC_left_item"><span class="LC_nobreak">'.
8365: '<input type="text" name="'.$prefix.'_min" value="'.$min.'" size="3" '.
8366: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8367: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
8368: '</span></td></tr>';
8369: $itemcount ++;
8370: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8371: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
8372: '<td class="LC_left_item"><span class="LC_nobreak">'.
8373: '<input type="text" name="'.$prefix.'_max" value="'.$max.'" size="3" '.
8374: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8375: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
8376: '</span></td></tr>';
8377: $itemcount ++;
8378: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8379: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
8380: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
8381: '</span></td>';
8382: my $numinrow = 2;
8383: my @possrules = ('uc','lc','num','spec');
8384: $datatable .= '<td class="LC_left_item"><table>';
8385: for (my $i=0; $i<@possrules; $i++) {
8386: my ($rem,$checked);
8387: if ($chars{$possrules[$i]}) {
8388: $checked = ' checked="checked"';
8389: }
8390: $rem = $i%($numinrow);
8391: if ($rem == 0) {
8392: if ($i > 0) {
8393: $datatable .= '</tr>';
8394: }
8395: $datatable .= '<tr>';
8396: }
8397: $datatable .= '<td><span class="LC_nobreak"><label>'.
8398: '<input type="checkbox" name="'.$prefix.'_chars" value="'.$possrules[$i].'"'.$checked.' />'.
8399: $rulenames{$possrules[$i]}.'</label></span></td>';
8400: }
8401: my $rem = @possrules%($numinrow);
8402: my $colsleft = $numinrow - $rem;
8403: if ($colsleft > 1 ) {
8404: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8405: ' </td>';
8406: } elsif ($colsleft == 1) {
8407: $datatable .= '<td class="LC_left_item"> </td>';
8408: }
8409: $datatable .='</table></td></tr>';
8410: $itemcount ++;
8411: if ($prefix eq 'passwords') {
8412: $titles{'expire'} = &mt('Password expiration (days)');
8413: $titles{'numsaved'} = &mt('Number of previous passwords to save and disallow reuse');
8414: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8415: $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
8416: '<td class="LC_left_item"><span class="LC_nobreak">'.
8417: '<input type="text" name="'.$prefix.'_expire" value="'.$expire.'" size="4" '.
8418: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8419: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
8420: '</span></td></tr>';
8421: $itemcount ++;
8422: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8423: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
8424: '<td class="LC_left_item"><span class="LC_nobreak">'.
8425: '<input type="text" name="'.$prefix.'_numsaved" value="'.$numsaved.'" size="3" '.
8426: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8427: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
8428: '</span></td></tr>';
8429: $itemcount ++;
8430: }
8431: if (ref($itemcountref)) {
8432: $$itemcountref += $itemcount;
8433: }
8434: return $datatable;
8435: }
8436:
1.373 raeburn 8437: sub print_wafproxy {
8438: my ($position,$dom,$settings,$rowtotal) = @_;
8439: my $css_class;
8440: my $itemcount = 0;
8441: my $datatable;
8442: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 8443: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
1.374 raeburn 8444: my %lt = &wafproxy_titles();
1.373 raeburn 8445: foreach my $server (sort(keys(%servers))) {
8446: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
1.381 raeburn 8447: next if ($serverhome eq '');
1.373 raeburn 8448: my $serverdom;
8449: if ($serverhome ne $server) {
8450: $serverdom = &Apache::lonnet::host_domain($serverhome);
1.381 raeburn 8451: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
8452: $othercontrol{$server} = $serverdom;
8453: }
1.373 raeburn 8454: } else {
8455: $serverdom = &Apache::lonnet::host_domain($server);
1.381 raeburn 8456: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
1.373 raeburn 8457: if ($serverdom ne $dom) {
8458: $othercontrol{$server} = $serverdom;
8459: } else {
8460: $setdom = 1;
8461: if (ref($settings) eq 'HASH') {
8462: if (ref($settings->{'alias'}) eq 'HASH') {
8463: $aliases{$dom} = $settings->{'alias'};
1.381 raeburn 8464: if ($aliases{$dom} ne '') {
8465: $showdom = 1;
8466: }
1.373 raeburn 8467: }
1.388 raeburn 8468: if (ref($settings->{'saml'}) eq 'HASH') {
8469: $saml{$dom} = $settings->{'saml'};
8470: }
1.373 raeburn 8471: }
8472: }
8473: }
8474: }
1.381 raeburn 8475: if ($setdom) {
8476: %{$values{$dom}} = ();
8477: if (ref($settings) eq 'HASH') {
8478: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8479: $values{$dom}{$item} = $settings->{$item};
8480: }
8481: }
8482: }
1.373 raeburn 8483: if (keys(%othercontrol)) {
8484: %otherdoms = reverse(%othercontrol);
8485: foreach my $domain (keys(%otherdoms)) {
8486: %{$values{$domain}} = ();
8487: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
1.383 raeburn 8488: if (ref($config{'wafproxy'}) eq 'HASH') {
8489: $aliases{$domain} = $config{'wafproxy'}{'alias'};
1.425 raeburn 8490: if (exists($config{'wafproxy'}{'saml'})) {
1.388 raeburn 8491: $saml{$domain} = $config{'wafproxy'}{'saml'};
8492: }
1.383 raeburn 8493: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8494: $values{$domain}{$item} = $config{'wafproxy'}{$item};
1.373 raeburn 8495: }
8496: }
8497: }
8498: }
8499: if ($position eq 'top') {
8500: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.381 raeburn 8501: my %aliasinfo;
1.373 raeburn 8502: foreach my $server (sort(keys(%servers))) {
1.381 raeburn 8503: $itemcount ++;
8504: my $dom_in_effect;
8505: my $aliasrows = '<tr>'.
1.383 raeburn 8506: '<td class="LC_left_item" style="vertical-align: baseline;">'.
1.433 raeburn 8507: &mt('Hostname').': '.
8508: '<span class="LC_nobreak LC_cusr_emph">'.
8509: &Apache::lonnet::hostname($server).
8510: '</span></td><td> </td>';
1.373 raeburn 8511: if ($othercontrol{$server}) {
1.381 raeburn 8512: $dom_in_effect = $othercontrol{$server};
1.388 raeburn 8513: my ($current,$forsaml);
1.383 raeburn 8514: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
8515: $current = $aliases{$dom_in_effect}{$server};
1.373 raeburn 8516: }
1.388 raeburn 8517: if (ref($saml{$dom_in_effect}) eq 'HASH') {
8518: if ($saml{$dom_in_effect}{$server}) {
8519: $forsaml = 1;
8520: }
8521: }
1.383 raeburn 8522: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8523: &mt('Alias').': ';
1.373 raeburn 8524: if ($current) {
1.381 raeburn 8525: $aliasrows .= $current;
1.388 raeburn 8526: if ($forsaml) {
1.396 raeburn 8527: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
1.388 raeburn 8528: }
1.373 raeburn 8529: } else {
1.383 raeburn 8530: $aliasrows .= &mt('None');
1.373 raeburn 8531: }
1.383 raeburn 8532: $aliasrows .= ' <span class="LC_small">('.
8533: &mt('controlled by domain: [_1]',
8534: '<b>'.$dom_in_effect.'</b>').')</span></td>';
1.373 raeburn 8535: } else {
1.381 raeburn 8536: $dom_in_effect = $dom;
1.388 raeburn 8537: my ($current,$samlon,$samloff);
8538: $samloff = ' checked="checked"';
1.373 raeburn 8539: if (ref($aliases{$dom}) eq 'HASH') {
8540: if ($aliases{$dom}{$server}) {
8541: $current = $aliases{$dom}{$server};
8542: }
8543: }
1.388 raeburn 8544: if (ref($saml{$dom}) eq 'HASH') {
8545: if ($saml{$dom}{$server}) {
8546: $samlon = $samloff;
8547: undef($samloff);
8548: }
8549: }
1.383 raeburn 8550: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8551: &mt('Alias').': '.
1.381 raeburn 8552: '<input type="text" name="wafproxy_alias_'.$server.'" '.
1.388 raeburn 8553: 'value="'.$current.'" size="30" />'.
8554: (' 'x2).'<span class="LC_nobreak">'.
1.396 raeburn 8555: &mt('Alias used for SSO Auth').': <label>'.
1.388 raeburn 8556: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
1.425 raeburn 8557: &mt('No').'</label> <label>'.
1.388 raeburn 8558: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
8559: &mt('Yes').'</label></span>'.
1.425 raeburn 8560: '</td>';
1.381 raeburn 8561: }
8562: $aliasrows .= '</tr>';
8563: $aliasinfo{$dom_in_effect} .= $aliasrows;
8564: }
8565: if ($aliasinfo{$dom}) {
8566: my ($onclick,$wafon,$wafoff,$showtable);
8567: $onclick = ' onclick="javascript:toggleWAF();"';
8568: $wafoff = ' checked="checked"';
8569: $showtable = ' style="display:none";';
8570: if ($showdom) {
8571: $wafon = $wafoff;
8572: $wafoff = '';
8573: $showtable = ' style="display:inline;"';
8574: }
8575: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8576: $datatable = '<tr'.$css_class.'>'.
8577: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
8578: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
8579: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
8580: &mt('Yes').'</label>'.(' 'x2).'<label>'.
8581: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
8582: &mt('No').'</label></span></td>'.
8583: '<td class="LC_left_item">'.
8584: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
8585: '</table></td></tr>';
8586: $itemcount++;
8587: }
1.383 raeburn 8588: if (keys(%otherdoms)) {
8589: foreach my $key (sort(keys(%otherdoms))) {
1.381 raeburn 8590: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.383 raeburn 8591: $datatable .= '<tr'.$css_class.'>'.
8592: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
8593: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
8594: '</table></td></tr>';
1.381 raeburn 8595: $itemcount++;
1.373 raeburn 8596: }
8597: }
8598: } else {
1.383 raeburn 8599: my %ip_methods = &remoteip_methods();
1.373 raeburn 8600: if ($setdom) {
8601: $itemcount ++;
8602: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.381 raeburn 8603: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
1.382 raeburn 8604: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
1.381 raeburn 8605: $wafstyle = ' style="display:none;"';
8606: $nowafstyle = ' style="display:table-row;"';
8607: $currwafdisplay = ' style="display: none"';
8608: $wafrangestyle = ' style="display: none"';
8609: $curr_remotip = 'n';
1.382 raeburn 8610: $ssltossl = ' checked="checked"';
1.381 raeburn 8611: if ($showdom) {
8612: $wafstyle = ' style="display:table-row;"';
8613: $nowafstyle = ' style="display:none;"';
8614: if (keys(%{$values{$dom}})) {
8615: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
8616: $curr_remotip = $values{$dom}{remoteip};
8617: }
8618: if ($curr_remotip eq 'h') {
8619: $currwafdisplay = ' style="display:table-row"';
8620: $wafrangestyle = ' style="display:inline-block;"';
8621: }
1.382 raeburn 8622: if ($values{$dom}{'sslopt'}) {
8623: $alltossl = ' checked="checked"';
8624: $ssltossl = '';
8625: }
1.381 raeburn 8626: }
8627: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
8628: $vpndircheck = ' checked="checked"';
8629: $currwafvpn = ' style="display:table-row;"';
8630: $wafrangestyle = ' style="display:inline-block;"';
8631: } else {
8632: $vpnaliascheck = ' checked="checked"';
8633: $currwafvpn = ' style="display:none;"';
8634: }
8635: }
8636: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
8637: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
8638: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
8639: '</tr>'.
8640: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
1.374 raeburn 8641: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
1.381 raeburn 8642: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
1.393 raeburn 8643: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
8644: &mt('Range(s) stored in CIDR notation').'</div></td>'.
1.381 raeburn 8645: '<td class="LC_left_item"><table>'.
8646: '<tr>'.
8647: '<td valign="top">'.$lt{'remoteip'}.': '.
8648: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
8649: foreach my $option ('m','h','n') {
8650: my $sel;
8651: if ($option eq $curr_remotip) {
8652: $sel = ' selected="selected"';
8653: }
8654: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
8655: $ip_methods{$option}.'</option>';
8656: }
8657: $datatable .= '</select></td></tr>'."\n".
8658: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
8659: $lt{'ipheader'}.': '.
8660: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
8661: 'name="wafproxy_ipheader" />'.
8662: '</td></tr>'."\n".
8663: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
1.382 raeburn 8664: $lt{'trusted'}.':<br />'.
1.381 raeburn 8665: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
8666: $values{$dom}{'trusted'}.'</textarea>'.
8667: '</td></tr>'."\n".
8668: '<tr><td><hr /></td></tr>'."\n".
8669: '<tr>'.
8670: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
8671: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
8672: $lt{'vpndirect'}.'</label>'.(' 'x2).
8673: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
8674: $lt{'vpnaliased'}.'</label></span></td></tr>';
8675: foreach my $item ('vpnint','vpnext') {
8676: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
1.382 raeburn 8677: '<td valign="top">'.$lt{$item}.':<br />'.
1.381 raeburn 8678: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
8679: $values{$dom}{$item}.'</textarea>'.
8680: '</td></tr>'."\n";
1.373 raeburn 8681: }
1.382 raeburn 8682: $datatable .= '<tr><td><hr /></td></tr>'."\n".
8683: '<tr>'.
8684: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
8685: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
8686: $lt{'alltossl'}.'</label>'.(' 'x2).
8687: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
8688: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
8689: '</table></td></tr>';
1.373 raeburn 8690: }
8691: if (keys(%otherdoms)) {
8692: foreach my $domain (sort(keys(%otherdoms))) {
8693: $itemcount ++;
8694: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8695: $datatable .= '<tr'.$css_class.'>'.
1.383 raeburn 8696: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
1.374 raeburn 8697: '<td class="LC_left_item"><table>';
1.382 raeburn 8698: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 8699: my $showval = &mt('None');
1.382 raeburn 8700: if ($item eq 'ssl') {
8701: $showval = $lt{'ssltossl'};
8702: }
1.373 raeburn 8703: if ($values{$domain}{$item}) {
1.381 raeburn 8704: $showval = $values{$domain}{$item};
1.382 raeburn 8705: if ($item eq 'ssl') {
8706: $showval = $lt{'alltossl'};
1.383 raeburn 8707: } elsif ($item eq 'remoteip') {
8708: $showval = $ip_methods{$values{$domain}{$item}};
1.382 raeburn 8709: }
1.373 raeburn 8710: }
8711: $datatable .= '<tr>'.
8712: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
8713: }
1.381 raeburn 8714: $datatable .= '</table></td></tr>';
1.373 raeburn 8715: }
8716: }
8717: }
8718: $$rowtotal += $itemcount;
8719: return $datatable;
8720: }
8721:
8722: sub wafproxy_titles {
8723: return &Apache::lonlocal::texthash(
1.381 raeburn 8724: remoteip => "Method for determining user's IP",
8725: ipheader => 'Request header containing remote IP',
8726: trusted => 'Trusted IP range(s)',
8727: vpnaccess => 'Access from institutional VPN',
8728: vpndirect => 'via regular hostname (no WAF)',
8729: vpnaliased => 'via aliased hostname (WAF)',
8730: vpnint => 'Internal IP Range(s) for VPN sessions',
8731: vpnext => 'IP Range(s) for backend WAF connections',
1.382 raeburn 8732: sslopt => 'Forwarding http/https',
1.381 raeburn 8733: alltossl => 'WAF forwards both http and https requests to https',
8734: ssltossl => 'WAF forwards http requests to http and https to https',
8735: );
8736: }
8737:
8738: sub remoteip_methods {
8739: return &Apache::lonlocal::texthash(
8740: m => 'Use Apache mod_remoteip',
8741: h => 'Use headers parsed by LON-CAPA',
8742: n => 'Not in use',
1.373 raeburn 8743: );
8744: }
8745:
1.137 raeburn 8746: sub print_usersessions {
8747: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 8748: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 8749: my (%by_ip,%by_location,@intdoms,@instdoms);
8750: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 8751:
8752: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 8753: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 8754: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 8755: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 8756: if ($position eq 'top') {
1.152 raeburn 8757: if (keys(%serverhomes) > 1) {
1.145 raeburn 8758: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.371 raeburn 8759: my ($curroffloadnow,$curroffloadoth);
1.261 raeburn 8760: if (ref($settings) eq 'HASH') {
8761: if (ref($settings->{'offloadnow'}) eq 'HASH') {
8762: $curroffloadnow = $settings->{'offloadnow'};
8763: }
1.371 raeburn 8764: if (ref($settings->{'offloadoth'}) eq 'HASH') {
8765: $curroffloadoth = $settings->{'offloadoth'};
8766: }
1.261 raeburn 8767: }
1.371 raeburn 8768: my $other_insts = scalar(keys(%by_location));
8769: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
8770: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 8771: } else {
1.140 raeburn 8772: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 8773: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
8774: '</td></tr>';
1.140 raeburn 8775: }
1.137 raeburn 8776: } else {
1.279 raeburn 8777: my %titles = &usersession_titles();
8778: my ($prefix,@types);
8779: if ($position eq 'bottom') {
8780: $prefix = 'remote';
8781: @types = ('version','excludedomain','includedomain');
1.145 raeburn 8782: } else {
1.279 raeburn 8783: $prefix = 'hosted';
8784: @types = ('excludedomain','includedomain');
8785: }
8786: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8787: }
8788: $$rowtotal += $itemcount;
8789: return $datatable;
8790: }
8791:
8792: sub rules_by_location {
8793: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
8794: my ($datatable,$itemcount,$css_class);
8795: if (keys(%{$by_location}) == 0) {
8796: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8797: $datatable = '<tr'.$css_class.'><td colspan="2">'.
8798: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
8799: '</td></tr>';
8800: $itemcount = 1;
8801: } else {
8802: $itemcount = 0;
8803: my $numinrow = 5;
8804: my (%current,%checkedon,%checkedoff);
8805: my @locations = sort(keys(%{$by_location}));
8806: foreach my $type (@{$types}) {
8807: $checkedon{$type} = '';
8808: $checkedoff{$type} = ' checked="checked"';
8809: }
8810: if (ref($settings) eq 'HASH') {
8811: if (ref($settings->{$prefix}) eq 'HASH') {
8812: foreach my $key (keys(%{$settings->{$prefix}})) {
8813: $current{$key} = $settings->{$prefix}{$key};
8814: if ($key eq 'version') {
8815: if ($current{$key} ne '') {
1.145 raeburn 8816: $checkedon{$key} = ' checked="checked"';
8817: $checkedoff{$key} = '';
8818: }
1.279 raeburn 8819: } elsif (ref($current{$key}) eq 'ARRAY') {
8820: $checkedon{$key} = ' checked="checked"';
8821: $checkedoff{$key} = '';
1.137 raeburn 8822: }
8823: }
8824: }
1.279 raeburn 8825: }
8826: foreach my $type (@{$types}) {
8827: next if ($type ne 'version' && !@locations);
8828: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8829: $datatable .= '<tr'.$css_class.'>
8830: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
8831: <span class="LC_nobreak">
8832: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
8833: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
8834: if ($type eq 'version') {
8835: my @lcversions = &Apache::lonnet::all_loncaparevs();
8836: my $selector = '<select name="'.$prefix.'_version">';
8837: foreach my $version (@lcversions) {
8838: my $selected = '';
8839: if ($current{'version'} eq $version) {
8840: $selected = ' selected="selected"';
1.145 raeburn 8841: }
1.279 raeburn 8842: $selector .= ' <option value="'.$version.'"'.
8843: $selected.'>'.$version.'</option>';
8844: }
8845: $selector .= '</select> ';
8846: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
8847: } else {
8848: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
8849: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
8850: ' />'.(' 'x2).
8851: '<input type="button" value="'.&mt('uncheck all').'" '.
8852: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
8853: "\n".
8854: '</div><div><table>';
8855: my $rem;
8856: for (my $i=0; $i<@locations; $i++) {
8857: my ($showloc,$value,$checkedtype);
8858: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
8859: my $ip = $by_location->{$locations[$i]}->[0];
8860: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8861: $value = join(':',@{$by_ip->{$ip}});
8862: $showloc = join(', ',@{$by_ip->{$ip}});
8863: if (ref($current{$type}) eq 'ARRAY') {
8864: foreach my $loc (@{$by_ip->{$ip}}) {
8865: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
8866: $checkedtype = ' checked="checked"';
8867: last;
1.145 raeburn 8868: }
1.138 raeburn 8869: }
8870: }
8871: }
1.137 raeburn 8872: }
1.279 raeburn 8873: $rem = $i%($numinrow);
8874: if ($rem == 0) {
8875: if ($i > 0) {
8876: $datatable .= '</tr>';
8877: }
8878: $datatable .= '<tr>';
8879: }
8880: $datatable .= '<td class="LC_left_item">'.
8881: '<span class="LC_nobreak"><label>'.
8882: '<input type="checkbox" name="'.$prefix.'_'.$type.
8883: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
8884: '</label></span></td>';
8885: }
8886: $rem = @locations%($numinrow);
8887: my $colsleft = $numinrow - $rem;
8888: if ($colsleft > 1 ) {
8889: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8890: ' </td>';
8891: } elsif ($colsleft == 1) {
8892: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 8893: }
1.279 raeburn 8894: $datatable .= '</tr></table>';
1.137 raeburn 8895: }
1.279 raeburn 8896: $datatable .= '</td></tr>';
8897: $itemcount ++;
1.137 raeburn 8898: }
8899: }
1.279 raeburn 8900: return ($datatable,$itemcount);
1.137 raeburn 8901: }
8902:
1.275 raeburn 8903: sub print_ssl {
8904: my ($position,$dom,$settings,$rowtotal) = @_;
8905: my ($css_class,$datatable);
8906: my $itemcount = 1;
8907: if ($position eq 'top') {
1.281 raeburn 8908: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8909: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8910: my $same_institution;
8911: if ($intdom ne '') {
8912: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
8913: if (ref($internet_names) eq 'ARRAY') {
8914: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
8915: $same_institution = 1;
8916: }
8917: }
8918: }
1.275 raeburn 8919: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 8920: $datatable = '<tr'.$css_class.'><td colspan="2">';
8921: if ($same_institution) {
8922: my %domservers = &Apache::lonnet::get_servers($dom);
8923: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
8924: } else {
8925: $datatable .= &mt("You need to be logged into one of your own domain's servers to display information about the status of LON-CAPA SSL certificates.");
8926: }
8927: $datatable .= '</td></tr>';
1.275 raeburn 8928: $itemcount ++;
8929: } else {
8930: my %titles = &ssl_titles();
8931: my (%by_ip,%by_location,@intdoms,@instdoms);
8932: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8933: my @alldoms = &Apache::lonnet::all_domains();
8934: my %serverhomes = %Apache::lonnet::serverhomeIDs;
8935: my @domservers = &Apache::lonnet::get_servers($dom);
8936: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8937: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 8938: if (($position eq 'connto') || ($position eq 'connfrom')) {
8939: my $legacy;
8940: unless (ref($settings) eq 'HASH') {
8941: my $name;
8942: if ($position eq 'connto') {
8943: $name = 'loncAllowInsecure';
8944: } else {
8945: $name = 'londAllowInsecure';
8946: }
8947: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
8948: my @ids=&Apache::lonnet::current_machine_ids();
8949: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
8950: my %what = (
8951: $name => 1,
8952: );
8953: my ($result,$returnhash) =
8954: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
8955: if ($result eq 'ok') {
8956: if (ref($returnhash) eq 'HASH') {
8957: $legacy = $returnhash->{$name};
8958: }
8959: }
8960: } else {
8961: $legacy = $Apache::lonnet::perlvar{$name};
8962: }
8963: }
1.275 raeburn 8964: foreach my $type ('dom','intdom','other') {
8965: my %checked;
8966: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8967: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
8968: '<td class="LC_right_item">';
8969: my $skip;
8970: if ($type eq 'dom') {
8971: unless (keys(%servers) > 1) {
8972: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
8973: $skip = 1;
8974: }
8975: }
8976: if ($type eq 'intdom') {
8977: unless (@instdoms > 1) {
8978: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
8979: $skip = 1;
8980: }
8981: } elsif ($type eq 'other') {
8982: if (keys(%by_location) == 0) {
8983: $datatable .= &mt('Nothing to set here, as there are no other institutions');
8984: $skip = 1;
8985: }
8986: }
8987: unless ($skip) {
8988: $checked{'yes'} = ' checked="checked"';
8989: if (ref($settings) eq 'HASH') {
1.293 raeburn 8990: if (ref($settings->{$position}) eq 'HASH') {
8991: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 8992: $checked{$1} = $checked{'yes'};
8993: delete($checked{'yes'});
8994: }
8995: }
1.293 raeburn 8996: } else {
8997: if ($legacy == 0) {
8998: $checked{'req'} = $checked{'yes'};
8999: delete($checked{'yes'});
9000: }
1.275 raeburn 9001: }
9002: foreach my $option ('no','yes','req') {
9003: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 9004: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 9005: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
9006: '</label></span>'.(' 'x2);
9007: }
9008: }
9009: $datatable .= '</td></tr>';
9010: $itemcount ++;
9011: }
9012: } else {
9013: my $prefix = 'replication';
9014: my @types = ('certreq','nocertreq');
1.279 raeburn 9015: if (keys(%by_location) == 0) {
9016: $datatable .= '<tr'.$css_class.'><td>'.
9017: &mt('Nothing to set here, as there are no other institutions').
9018: '</td></tr>';
9019: $itemcount ++;
1.275 raeburn 9020: } else {
1.279 raeburn 9021: ($datatable,$itemcount) =
9022: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 9023: }
9024: }
9025: }
9026: $$rowtotal += $itemcount;
9027: return $datatable;
9028: }
9029:
9030: sub ssl_titles {
9031: return &Apache::lonlocal::texthash (
9032: dom => 'LON-CAPA servers/VMs from same domain',
9033: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
9034: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 9035: connto => 'Connections to other servers',
9036: connfrom => 'Connections from other servers',
1.275 raeburn 9037: replication => 'Replicating content to other institutions',
9038: certreq => 'Client certificate required, but specific domains exempt',
9039: nocertreq => 'No client certificate required, except for specific domains',
9040: no => 'SSL not used',
9041: yes => 'SSL Optional (used if available)',
9042: req => 'SSL Required',
9043: );
1.279 raeburn 9044: }
9045:
9046: sub print_trust {
9047: my ($prefix,$dom,$settings,$rowtotal) = @_;
9048: my ($css_class,$datatable,%checked,%choices);
9049: my (%by_ip,%by_location,@intdoms,@instdoms);
9050: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
9051: my $itemcount = 1;
9052: my %titles = &trust_titles();
9053: my @types = ('exc','inc');
9054: if ($prefix eq 'top') {
9055: $prefix = 'content';
9056: } elsif ($prefix eq 'bottom') {
9057: $prefix = 'msg';
9058: }
9059: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
9060: $$rowtotal += $itemcount;
9061: return $datatable;
9062: }
9063:
9064: sub trust_titles {
9065: return &Apache::lonlocal::texthash(
9066: content => "Access to this domain's content by others",
9067: shared => "Access to other domain's content by this domain",
9068: enroll => "Enrollment in this domain's courses by others",
9069: othcoau => "Co-author roles in this domain for others",
9070: coaurem => "Co-author roles for this domain's users elsewhere",
9071: domroles => "Domain roles in this domain assignable to others",
9072: catalog => "Course Catalog for this domain displayed elsewhere",
9073: reqcrs => "Requests for creation of courses in this domain by others",
9074: msg => "Users in other domains can send messages to this domain",
9075: exc => "Allow all, but exclude specific domains",
9076: inc => "Deny all, but include specific domains",
9077: );
1.275 raeburn 9078: }
9079:
1.138 raeburn 9080: sub build_location_hashes {
1.275 raeburn 9081: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 9082: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 9083: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 9084: my %iphost = &Apache::lonnet::get_iphost();
9085: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
9086: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
9087: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
9088: foreach my $id (@{$iphost{$primary_ip}}) {
9089: my $intdom = &Apache::lonnet::internet_dom($id);
9090: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
9091: push(@{$intdoms},$intdom);
9092: }
9093: }
9094: }
9095: foreach my $ip (keys(%iphost)) {
9096: if (ref($iphost{$ip}) eq 'ARRAY') {
9097: foreach my $id (@{$iphost{$ip}}) {
9098: my $location = &Apache::lonnet::internet_dom($id);
9099: if ($location) {
1.275 raeburn 9100: if (grep(/^\Q$location\E$/,@{$intdoms})) {
9101: my $dom = &Apache::lonnet::host_domain($id);
9102: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
9103: push(@{$instdoms},$dom);
9104: }
9105: next;
9106: }
1.138 raeburn 9107: if (ref($by_ip->{$ip}) eq 'ARRAY') {
9108: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
9109: push(@{$by_ip->{$ip}},$location);
9110: }
9111: } else {
9112: $by_ip->{$ip} = [$location];
9113: }
9114: }
9115: }
9116: }
9117: }
9118: foreach my $ip (sort(keys(%{$by_ip}))) {
9119: if (ref($by_ip->{$ip}) eq 'ARRAY') {
9120: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
9121: my $first = $by_ip->{$ip}->[0];
9122: if (ref($by_location->{$first}) eq 'ARRAY') {
9123: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
9124: push(@{$by_location->{$first}},$ip);
9125: }
9126: } else {
9127: $by_location->{$first} = [$ip];
9128: }
9129: }
9130: }
9131: return;
9132: }
9133:
1.145 raeburn 9134: sub current_offloads_to {
9135: my ($dom,$settings,$servers) = @_;
9136: my (%spareid,%otherdomconfigs);
1.152 raeburn 9137: if (ref($servers) eq 'HASH') {
1.145 raeburn 9138: foreach my $lonhost (sort(keys(%{$servers}))) {
9139: my $gotspares;
1.152 raeburn 9140: if (ref($settings) eq 'HASH') {
9141: if (ref($settings->{'spares'}) eq 'HASH') {
9142: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
9143: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
9144: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
9145: $gotspares = 1;
9146: }
1.145 raeburn 9147: }
9148: }
9149: unless ($gotspares) {
9150: my $gotspares;
9151: my $serverhomeID =
9152: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
9153: my $serverhomedom =
9154: &Apache::lonnet::host_domain($serverhomeID);
9155: if ($serverhomedom ne $dom) {
9156: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
9157: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
9158: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
9159: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
9160: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
9161: $gotspares = 1;
9162: }
9163: }
9164: } else {
9165: $otherdomconfigs{$serverhomedom} =
9166: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
9167: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
9168: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
9169: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
9170: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
9171: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
9172: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
9173: $gotspares = 1;
9174: }
9175: }
9176: }
9177: }
9178: }
9179: }
9180: }
9181: unless ($gotspares) {
9182: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
9183: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9184: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9185: } else {
9186: my $server_hostname = &Apache::lonnet::hostname($lonhost);
9187: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
9188: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
9189: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9190: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9191: } else {
1.150 raeburn 9192: my %what = (
9193: spareid => 1,
9194: );
9195: my ($result,$returnhash) =
9196: &Apache::lonnet::get_remote_globals($lonhost,\%what);
9197: if ($result eq 'ok') {
9198: if (ref($returnhash) eq 'HASH') {
9199: if (ref($returnhash->{'spareid'}) eq 'HASH') {
9200: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
9201: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
9202: }
9203: }
1.145 raeburn 9204: }
9205: }
9206: }
9207: }
9208: }
9209: }
9210: return %spareid;
9211: }
9212:
9213: sub spares_row {
1.371 raeburn 9214: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
9215: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 9216: my $css_class;
9217: my $numinrow = 4;
9218: my $itemcount = 1;
9219: my $datatable;
1.152 raeburn 9220: my %typetitles = &sparestype_titles();
9221: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 9222: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 9223: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
9224: my ($othercontrol,$serverdom);
9225: if ($serverhome ne $server) {
9226: $serverdom = &Apache::lonnet::host_domain($serverhome);
9227: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9228: } else {
9229: $serverdom = &Apache::lonnet::host_domain($server);
9230: if ($serverdom ne $dom) {
9231: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9232: }
9233: }
9234: next unless (ref($spareid->{$server}) eq 'HASH');
1.371 raeburn 9235: my ($checkednow,$checkedoth);
1.261 raeburn 9236: if (ref($curroffloadnow) eq 'HASH') {
9237: if ($curroffloadnow->{$server}) {
9238: $checkednow = ' checked="checked"';
9239: }
9240: }
1.371 raeburn 9241: if (ref($curroffloadoth) eq 'HASH') {
9242: if ($curroffloadoth->{$server}) {
9243: $checkedoth = ' checked="checked"';
9244: }
9245: }
1.145 raeburn 9246: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
9247: $datatable .= '<tr'.$css_class.'>
9248: <td rowspan="2">
1.183 bisitz 9249: <span class="LC_nobreak">'.
9250: &mt('[_1] when busy, offloads to:'
1.261 raeburn 9251: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 9252: '<span class="LC_nobreak">'."\n".
1.261 raeburn 9253: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.371 raeburn 9254: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.183 bisitz 9255: "\n";
1.371 raeburn 9256: if ($other_insts) {
9257: $datatable .= '<br />'.
9258: '<span class="LC_nobreak">'."\n".
9259: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
9260: ' '.&mt('Switch other institutions on next access').'</label></span>'.
9261: "\n";
9262: }
1.145 raeburn 9263: my (%current,%canselect);
1.152 raeburn 9264: my @choices =
9265: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
9266: foreach my $type ('primary','default') {
9267: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 9268: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
9269: my @spares = @{$spareid->{$server}{$type}};
9270: if (@spares > 0) {
1.152 raeburn 9271: if ($othercontrol) {
9272: $current{$type} = join(', ',@spares);
9273: } else {
9274: $current{$type} .= '<table>';
9275: my $numspares = scalar(@spares);
9276: for (my $i=0; $i<@spares; $i++) {
9277: my $rem = $i%($numinrow);
9278: if ($rem == 0) {
9279: if ($i > 0) {
9280: $current{$type} .= '</tr>';
9281: }
9282: $current{$type} .= '<tr>';
1.145 raeburn 9283: }
1.152 raeburn 9284: $current{$type} .= '<td><label><input type="checkbox" name="spare_'.$type.'_'.$server.'" id="spare_'.$type.'_'.$server.'_'.$i.'" checked="checked" value="'.$spareid->{$server}{$type}[$i].'" onclick="updateNewSpares(this.form,'."'$server'".');" /> '.
9285: $spareid->{$server}{$type}[$i].
9286: '</label></td>'."\n";
9287: }
9288: my $rem = @spares%($numinrow);
9289: my $colsleft = $numinrow - $rem;
9290: if ($colsleft > 1 ) {
9291: $current{$type} .= '<td colspan="'.$colsleft.
9292: '" class="LC_left_item">'.
9293: ' </td>';
9294: } elsif ($colsleft == 1) {
9295: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 9296: }
1.152 raeburn 9297: $current{$type} .= '</tr></table>';
1.150 raeburn 9298: }
1.145 raeburn 9299: }
9300: }
9301: if ($current{$type} eq '') {
9302: $current{$type} = &mt('None specified');
9303: }
1.152 raeburn 9304: if ($othercontrol) {
9305: if ($type eq 'primary') {
9306: $canselect{$type} = $othercontrol;
9307: }
9308: } else {
9309: $canselect{$type} =
9310: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
9311: '<select name="newspare_'.$type.'_'.$server.'" '.
9312: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
9313: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
9314: if (@choices > 0) {
9315: foreach my $lonhost (@choices) {
9316: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
9317: }
9318: }
9319: $canselect{$type} .= '</select>'."\n";
9320: }
9321: } else {
9322: $current{$type} = &mt('Could not be determined');
9323: if ($type eq 'primary') {
9324: $canselect{$type} = $othercontrol;
9325: }
1.145 raeburn 9326: }
1.152 raeburn 9327: if ($type eq 'default') {
9328: $datatable .= '<tr'.$css_class.'>';
9329: }
9330: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
9331: '<td>'.$current{$type}.'</td>'."\n".
9332: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 9333: }
9334: $itemcount ++;
9335: }
9336: }
9337: $$rowtotal += $itemcount;
9338: return $datatable;
9339: }
9340:
1.152 raeburn 9341: sub possible_newspares {
9342: my ($server,$currspares,$serverhomes,$altids) = @_;
9343: my $serverhostname = &Apache::lonnet::hostname($server);
9344: my %excluded;
9345: if ($serverhostname ne '') {
9346: %excluded = (
9347: $serverhostname => 1,
9348: );
9349: }
9350: if (ref($currspares) eq 'HASH') {
9351: foreach my $type (keys(%{$currspares})) {
9352: if (ref($currspares->{$type}) eq 'ARRAY') {
9353: if (@{$currspares->{$type}} > 0) {
9354: foreach my $curr (@{$currspares->{$type}}) {
9355: my $hostname = &Apache::lonnet::hostname($curr);
9356: $excluded{$hostname} = 1;
9357: }
9358: }
9359: }
9360: }
9361: }
9362: my @choices;
9363: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
9364: if (keys(%{$serverhomes}) > 1) {
9365: foreach my $name (sort(keys(%{$serverhomes}))) {
9366: unless ($excluded{$name}) {
9367: if (exists($altids->{$serverhomes->{$name}})) {
9368: push(@choices,$altids->{$serverhomes->{$name}});
9369: } else {
9370: push(@choices,$serverhomes->{$name});
1.145 raeburn 9371: }
9372: }
9373: }
9374: }
9375: }
1.152 raeburn 9376: return sort(@choices);
1.145 raeburn 9377: }
9378:
1.150 raeburn 9379: sub print_loadbalancing {
9380: my ($dom,$settings,$rowtotal) = @_;
9381: my $primary_id = &Apache::lonnet::domain($dom,'primary');
9382: my $intdom = &Apache::lonnet::internet_dom($primary_id);
9383: my $numinrow = 1;
9384: my $datatable;
9385: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 9386: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 9387: if (ref($settings) eq 'HASH') {
9388: %existing = %{$settings};
9389: }
9390: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
9391: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 9392: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 9393: } else {
9394: return;
9395: }
9396: my ($othertitle,$usertypes,$types) =
9397: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 9398: my $rownum = 8;
1.150 raeburn 9399: if (ref($types) eq 'ARRAY') {
9400: $rownum += scalar(@{$types});
9401: }
1.171 raeburn 9402: my @css_class = ('LC_odd_row','LC_even_row');
9403: my $balnum = 0;
9404: my $islast;
9405: my (@toshow,$disabledtext);
9406: if (keys(%currbalancer) > 0) {
9407: @toshow = sort(keys(%currbalancer));
9408: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
9409: push(@toshow,'');
9410: }
9411: } else {
9412: @toshow = ('');
9413: $disabledtext = &mt('No existing load balancer');
9414: }
9415: foreach my $lonhost (@toshow) {
9416: if ($balnum == scalar(@toshow)-1) {
9417: $islast = 1;
9418: } else {
9419: $islast = 0;
9420: }
9421: my $cssidx = $balnum%2;
9422: my $targets_div_style = 'display: none';
9423: my $disabled_div_style = 'display: block';
9424: my $homedom_div_style = 'display: none';
9425: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 9426: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9427: '<p>';
9428: if ($lonhost eq '') {
1.210 raeburn 9429: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 9430: if (keys(%currbalancer) > 0) {
9431: $datatable .= &mt('Add balancer:');
9432: } else {
9433: $datatable .= &mt('Enable balancer:');
9434: }
9435: $datatable .= ' '.
9436: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
9437: ' id="loadbalancing_lonhost_'.$balnum.'"'.
9438: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
9439: '<option value="" selected="selected">'.&mt('None').
9440: '</option>'."\n";
9441: foreach my $server (sort(keys(%servers))) {
9442: next if ($currbalancer{$server});
9443: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
9444: }
1.210 raeburn 9445: $datatable .=
1.171 raeburn 9446: '</select>'."\n".
9447: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
9448: } else {
9449: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
9450: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
9451: &mt('Stop balancing').'</label>'.
9452: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
9453: $targets_div_style = 'display: block';
9454: $disabled_div_style = 'display: none';
9455: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
9456: $homedom_div_style = 'display: block';
9457: }
9458: }
1.306 raeburn 9459: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9460: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
9461: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
9462: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
9463: my ($numspares,@spares) = &count_servers($lonhost,%servers);
9464: my @sparestypes = ('primary','default');
9465: my %typetitles = &sparestype_titles();
1.284 raeburn 9466: my %hostherechecked = (
9467: no => ' checked="checked"',
9468: );
1.342 raeburn 9469: my %balcookiechecked = (
1.425 raeburn 9470: no => ' checked="checked"',
1.342 raeburn 9471: );
1.171 raeburn 9472: foreach my $sparetype (@sparestypes) {
9473: my $targettable;
9474: for (my $i=0; $i<$numspares; $i++) {
9475: my $checked;
9476: if (ref($currtargets{$lonhost}) eq 'HASH') {
9477: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9478: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9479: $checked = ' checked="checked"';
9480: }
9481: }
9482: }
9483: my ($chkboxval,$disabled);
9484: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
9485: $chkboxval = $spares[$i];
9486: }
9487: if (exists($currbalancer{$spares[$i]})) {
9488: $disabled = ' disabled="disabled"';
9489: }
1.210 raeburn 9490: $targettable .=
1.253 raeburn 9491: '<td><span class="LC_nobreak"><label>'.
9492: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 9493: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
1.253 raeburn 9494: '</span></label></span></td>';
1.171 raeburn 9495: my $rem = $i%($numinrow);
9496: if ($rem == 0) {
9497: if (($i > 0) && ($i < $numspares-1)) {
9498: $targettable .= '</tr>';
9499: }
9500: if ($i < $numspares-1) {
9501: $targettable .= '<tr>';
1.150 raeburn 9502: }
9503: }
9504: }
1.171 raeburn 9505: if ($targettable ne '') {
9506: my $rem = $numspares%($numinrow);
9507: my $colsleft = $numinrow - $rem;
9508: if ($colsleft > 1 ) {
9509: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9510: ' </td>';
9511: } elsif ($colsleft == 1) {
9512: $targettable .= '<td class="LC_left_item"> </td>';
9513: }
9514: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
9515: '<table><tr>'.$targettable.'</tr></table><br />';
9516: }
1.284 raeburn 9517: $hostherechecked{$sparetype} = '';
9518: if (ref($currtargets{$lonhost}) eq 'HASH') {
9519: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9520: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9521: $hostherechecked{$sparetype} = ' checked="checked"';
9522: $hostherechecked{'no'} = '';
9523: }
9524: }
9525: }
9526: }
1.342 raeburn 9527: if ($currcookies{$lonhost}) {
9528: %balcookiechecked = (
9529: yes => ' checked="checked"',
9530: );
9531: }
1.284 raeburn 9532: $datatable .= &mt('Hosting on balancer itself').'<br />'.
9533: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
9534: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
9535: foreach my $sparetype (@sparestypes) {
9536: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
9537: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
9538: '</i></label><br />';
1.171 raeburn 9539: }
1.342 raeburn 9540: $datatable .= &mt('Use balancer cookie').'<br />'.
9541: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
9542: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
9543: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
9544: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
9545: '</div></td></tr>'.
1.171 raeburn 9546: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
9547: $othertitle,$usertypes,$types,\%servers,
9548: \%currbalancer,$lonhost,
9549: $targets_div_style,$homedom_div_style,
9550: $css_class[$cssidx],$balnum,$islast);
9551: $$rowtotal += $rownum;
9552: $balnum ++;
9553: }
9554: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
9555: return $datatable;
9556: }
9557:
9558: sub get_loadbalancers_config {
1.342 raeburn 9559: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 9560: return unless ((ref($servers) eq 'HASH') &&
9561: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 9562: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
9563: (ref($currcookies) eq 'HASH'));
1.171 raeburn 9564: if (keys(%{$existing}) > 0) {
9565: my $oldlonhost;
9566: foreach my $key (sort(keys(%{$existing}))) {
9567: if ($key eq 'lonhost') {
9568: $oldlonhost = $existing->{'lonhost'};
9569: $currbalancer->{$oldlonhost} = 1;
9570: } elsif ($key eq 'targets') {
9571: if ($oldlonhost) {
9572: $currtargets->{$oldlonhost} = $existing->{'targets'};
9573: }
9574: } elsif ($key eq 'rules') {
9575: if ($oldlonhost) {
9576: $currrules->{$oldlonhost} = $existing->{'rules'};
9577: }
9578: } elsif (ref($existing->{$key}) eq 'HASH') {
9579: $currbalancer->{$key} = 1;
9580: $currtargets->{$key} = $existing->{$key}{'targets'};
9581: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 9582: if ($existing->{$key}{'cookie'}) {
9583: $currcookies->{$key} = 1;
9584: }
1.150 raeburn 9585: }
9586: }
1.171 raeburn 9587: } else {
9588: my ($balancerref,$targetsref) =
9589: &Apache::lonnet::get_lonbalancer_config($servers);
9590: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
9591: foreach my $server (sort(keys(%{$balancerref}))) {
9592: $currbalancer->{$server} = 1;
9593: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 9594: }
9595: }
9596: }
1.171 raeburn 9597: return;
1.150 raeburn 9598: }
9599:
9600: sub loadbalancing_rules {
9601: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 9602: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
9603: $css_class,$balnum,$islast) = @_;
1.150 raeburn 9604: my $output;
1.171 raeburn 9605: my $num = 0;
1.210 raeburn 9606: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 9607: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
9608: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
9609: foreach my $type (@{$alltypes}) {
1.171 raeburn 9610: $num ++;
1.150 raeburn 9611: my $current;
9612: if (ref($currrules) eq 'HASH') {
9613: $current = $currrules->{$type};
9614: }
1.253 raeburn 9615: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 9616: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 9617: $current = '';
9618: }
9619: }
9620: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 9621: $servers,$currbalancer,$lonhost,$dom,
9622: $targets_div_style,$homedom_div_style,
9623: $css_class,$balnum,$num,$islast);
1.150 raeburn 9624: }
9625: }
9626: return $output;
9627: }
9628:
9629: sub loadbalancing_titles {
9630: my ($dom,$intdom,$usertypes,$types) = @_;
9631: my %othertypes = (
9632: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
9633: '_LC_author' => &mt('Users from [_1] with author role',$dom),
9634: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
9635: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 9636: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
9637: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 9638: );
1.209 raeburn 9639: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 9640: my @available;
1.150 raeburn 9641: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9642: @available = @{$types};
1.150 raeburn 9643: }
1.302 raeburn 9644: unless (grep(/^default$/,@available)) {
9645: push(@available,'default');
9646: }
9647: unshift(@alltypes,@available);
1.150 raeburn 9648: my %titles;
9649: foreach my $type (@alltypes) {
9650: if ($type =~ /^_LC_/) {
9651: $titles{$type} = $othertypes{$type};
9652: } elsif ($type eq 'default') {
9653: $titles{$type} = &mt('All users from [_1]',$dom);
9654: if (ref($types) eq 'ARRAY') {
9655: if (@{$types} > 0) {
9656: $titles{$type} = &mt('Other users from [_1]',$dom);
9657: }
9658: }
9659: } elsif (ref($usertypes) eq 'HASH') {
9660: $titles{$type} = $usertypes->{$type};
9661: }
9662: }
9663: return (\@alltypes,\%othertypes,\%titles);
9664: }
9665:
9666: sub loadbalance_rule_row {
1.171 raeburn 9667: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
9668: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 9669: my @rulenames;
1.150 raeburn 9670: my %ruletitles = &offloadtype_text();
1.209 raeburn 9671: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 9672: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 9673: } else {
1.209 raeburn 9674: @rulenames = ('default','homeserver');
9675: if ($type eq '_LC_external') {
9676: push(@rulenames,'externalbalancer');
9677: } else {
9678: push(@rulenames,'specific');
9679: }
9680: push(@rulenames,'none');
1.150 raeburn 9681: }
9682: my $style = $targets_div_style;
1.253 raeburn 9683: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 9684: $style = $homedom_div_style;
9685: }
1.171 raeburn 9686: my $space;
9687: if ($islast && $num == 1) {
1.317 raeburn 9688: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 9689: }
1.210 raeburn 9690: my $output =
1.306 raeburn 9691: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 9692: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
9693: '<td valaign="top">'.$space.
9694: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 9695: for (my $i=0; $i<@rulenames; $i++) {
9696: my $rule = $rulenames[$i];
9697: my ($checked,$extra);
9698: if ($rulenames[$i] eq 'default') {
9699: $rule = '';
9700: }
9701: if ($rulenames[$i] eq 'specific') {
9702: if (ref($servers) eq 'HASH') {
9703: my $default;
9704: if (($current ne '') && (exists($servers->{$current}))) {
9705: $checked = ' checked="checked"';
9706: }
9707: unless ($checked) {
9708: $default = ' selected="selected"';
9709: }
1.210 raeburn 9710: $extra =
1.171 raeburn 9711: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
9712: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
9713: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
9714: '<option value=""'.$default.'></option>'."\n";
9715: foreach my $server (sort(keys(%{$servers}))) {
9716: if (ref($currbalancer) eq 'HASH') {
9717: next if (exists($currbalancer->{$server}));
9718: }
1.150 raeburn 9719: my $selected;
1.171 raeburn 9720: if ($server eq $current) {
1.150 raeburn 9721: $selected = ' selected="selected"';
9722: }
1.171 raeburn 9723: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 9724: }
9725: $extra .= '</select>';
9726: }
9727: } elsif ($rule eq $current) {
9728: $checked = ' checked="checked"';
9729: }
9730: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 9731: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
9732: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
9733: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 9734: ')"'.$checked.' /> ';
9735: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
9736: $output .= $ruletitles{'particular'};
9737: } else {
9738: $output .= $ruletitles{$rulenames[$i]};
9739: }
9740: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 9741: }
9742: $output .= '</div></td></tr>'."\n";
9743: return $output;
9744: }
9745:
9746: sub offloadtype_text {
9747: my %ruletitles = &Apache::lonlocal::texthash (
9748: 'default' => 'Offloads to default destinations',
9749: 'homeserver' => "Offloads to user's home server",
9750: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
9751: 'specific' => 'Offloads to specific server',
1.161 raeburn 9752: 'none' => 'No offload',
1.209 raeburn 9753: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
9754: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 9755: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 9756: );
9757: return %ruletitles;
9758: }
9759:
9760: sub sparestype_titles {
9761: my %typestitles = &Apache::lonlocal::texthash (
9762: 'primary' => 'primary',
9763: 'default' => 'default',
9764: );
9765: return %typestitles;
9766: }
9767:
1.28 raeburn 9768: sub contact_titles {
9769: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 9770: 'supportemail' => 'Support E-mail address',
9771: 'adminemail' => 'Default Server Admin E-mail address',
9772: 'errormail' => 'Error reports to be e-mailed to',
9773: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 9774: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
9775: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 9776: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
9777: 'requestsmail' => 'E-mail from course requests requiring approval',
9778: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 9779: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350 raeburn 9780: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.378 raeburn 9781: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
9782: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.340 raeburn 9783: 'errorweights' => 'Weights used to compute error count',
9784: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 9785: );
9786: my %short_titles = &Apache::lonlocal::texthash (
9787: adminemail => 'Admin E-mail address',
9788: supportemail => 'Support E-mail',
9789: );
9790: return (\%titles,\%short_titles);
9791: }
9792:
1.286 raeburn 9793: sub helpform_fields {
9794: my %titles = &Apache::lonlocal::texthash (
9795: 'username' => 'Name',
9796: 'user' => 'Username/domain',
9797: 'phone' => 'Phone',
9798: 'cc' => 'Cc e-mail',
9799: 'course' => 'Course Details',
9800: 'section' => 'Sections',
1.289 raeburn 9801: 'screenshot' => 'File upload',
1.286 raeburn 9802: );
9803: my @fields = ('username','phone','user','course','section','cc','screenshot');
9804: my %possoptions = (
9805: username => ['yes','no','req'],
1.289 raeburn 9806: phone => ['yes','no','req'],
1.286 raeburn 9807: user => ['yes','no'],
1.289 raeburn 9808: cc => ['yes','no'],
1.286 raeburn 9809: course => ['yes','no'],
9810: section => ['yes','no'],
9811: screenshot => ['yes','no'],
9812: );
9813: my %fieldoptions = &Apache::lonlocal::texthash (
9814: 'yes' => 'Optional',
9815: 'req' => 'Required',
9816: 'no' => "Not shown",
9817: );
9818: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
9819: }
9820:
1.72 raeburn 9821: sub tool_titles {
9822: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 9823: aboutme => 'Personal web page',
1.86 raeburn 9824: blog => 'Blog',
9825: portfolio => 'Portfolio',
1.430 raeburn 9826: portaccess => 'Share portfolio files',
1.413 raeburn 9827: timezone => 'Can set time zone',
1.88 bisitz 9828: official => 'Official courses (with institutional codes)',
9829: unofficial => 'Unofficial courses',
1.98 raeburn 9830: community => 'Communities',
1.216 raeburn 9831: textbook => 'Textbook courses',
1.271 raeburn 9832: placement => 'Placement tests',
1.86 raeburn 9833: );
1.72 raeburn 9834: return %titles;
9835: }
9836:
1.101 raeburn 9837: sub courserequest_titles {
9838: my %titles = &Apache::lonlocal::texthash (
9839: official => 'Official',
9840: unofficial => 'Unofficial',
9841: community => 'Communities',
1.216 raeburn 9842: textbook => 'Textbook',
1.271 raeburn 9843: placement => 'Placement tests',
1.325 raeburn 9844: lti => 'LTI Provider',
1.101 raeburn 9845: norequest => 'Not allowed',
1.325 raeburn 9846: approval => 'Approval by DC',
1.101 raeburn 9847: validate => 'With validation',
9848: autolimit => 'Numerical limit',
1.103 raeburn 9849: unlimited => '(blank for unlimited)',
1.101 raeburn 9850: );
9851: return %titles;
9852: }
9853:
1.163 raeburn 9854: sub authorrequest_titles {
9855: my %titles = &Apache::lonlocal::texthash (
9856: norequest => 'Not allowed',
9857: approval => 'Approval by Dom. Coord.',
9858: automatic => 'Automatic approval',
9859: );
9860: return %titles;
1.210 raeburn 9861: }
1.163 raeburn 9862:
1.101 raeburn 9863: sub courserequest_conditions {
9864: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 9865: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 9866: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 9867: );
9868: return %conditions;
9869: }
9870:
9871:
1.27 raeburn 9872: sub print_usercreation {
1.30 raeburn 9873: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 9874: my $numinrow = 4;
1.28 raeburn 9875: my $datatable;
9876: if ($position eq 'top') {
1.30 raeburn 9877: $$rowtotal ++;
1.34 raeburn 9878: my $rowcount = 0;
1.32 raeburn 9879: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 9880: if (ref($rules) eq 'HASH') {
9881: if (keys(%{$rules}) > 0) {
1.32 raeburn 9882: $datatable .= &user_formats_row('username',$settings,$rules,
9883: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 9884: $$rowtotal ++;
1.32 raeburn 9885: $rowcount ++;
9886: }
9887: }
9888: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
9889: if (ref($idrules) eq 'HASH') {
9890: if (keys(%{$idrules}) > 0) {
9891: $datatable .= &user_formats_row('id',$settings,$idrules,
9892: $idruleorder,$numinrow,$rowcount);
9893: $$rowtotal ++;
9894: $rowcount ++;
1.28 raeburn 9895: }
9896: }
1.39 raeburn 9897: if ($rowcount == 0) {
9898: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
9899: $$rowtotal ++;
9900: $rowcount ++;
9901: }
1.34 raeburn 9902: } elsif ($position eq 'middle') {
1.224 raeburn 9903: my @creators = ('author','course','requestcrs');
1.37 raeburn 9904: my ($rules,$ruleorder) =
9905: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 9906: my %lt = &usercreation_types();
9907: my %checked;
9908: if (ref($settings) eq 'HASH') {
9909: if (ref($settings->{'cancreate'}) eq 'HASH') {
9910: foreach my $item (@creators) {
9911: $checked{$item} = $settings->{'cancreate'}{$item};
9912: }
9913: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
9914: foreach my $item (@creators) {
9915: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
9916: $checked{$item} = 'none';
9917: }
9918: }
9919: }
9920: }
9921: my $rownum = 0;
9922: foreach my $item (@creators) {
9923: $rownum ++;
1.224 raeburn 9924: if ($checked{$item} eq '') {
9925: $checked{$item} = 'any';
1.34 raeburn 9926: }
9927: my $css_class;
9928: if ($rownum%2) {
9929: $css_class = '';
9930: } else {
9931: $css_class = ' class="LC_odd_row" ';
9932: }
9933: $datatable .= '<tr'.$css_class.'>'.
9934: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 9935: '</span></td><td style="text-align: right">';
1.224 raeburn 9936: my @options = ('any');
9937: if (ref($rules) eq 'HASH') {
9938: if (keys(%{$rules}) > 0) {
9939: push(@options,('official','unofficial'));
1.37 raeburn 9940: }
9941: }
1.224 raeburn 9942: push(@options,'none');
1.37 raeburn 9943: foreach my $option (@options) {
1.50 raeburn 9944: my $type = 'radio';
1.34 raeburn 9945: my $check = ' ';
1.224 raeburn 9946: if ($checked{$item} eq $option) {
9947: $check = ' checked="checked" ';
1.34 raeburn 9948: }
9949: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 9950: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 9951: $item.'" value="'.$option.'"'.$check.'/> '.
9952: $lt{$option}.'</label> </span>';
9953: }
9954: $datatable .= '</td></tr>';
9955: }
1.28 raeburn 9956: } else {
9957: my @contexts = ('author','course','domain');
1.325 raeburn 9958: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 9959: my %checked;
9960: if (ref($settings) eq 'HASH') {
9961: if (ref($settings->{'authtypes'}) eq 'HASH') {
9962: foreach my $item (@contexts) {
9963: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
9964: foreach my $auth (@authtypes) {
9965: if ($settings->{'authtypes'}{$item}{$auth}) {
9966: $checked{$item}{$auth} = ' checked="checked" ';
9967: }
9968: }
9969: }
9970: }
1.27 raeburn 9971: }
1.35 raeburn 9972: } else {
9973: foreach my $item (@contexts) {
1.36 raeburn 9974: foreach my $auth (@authtypes) {
1.35 raeburn 9975: $checked{$item}{$auth} = ' checked="checked" ';
9976: }
9977: }
1.27 raeburn 9978: }
1.28 raeburn 9979: my %title = &context_names();
9980: my %authname = &authtype_names();
9981: my $rownum = 0;
9982: my $css_class;
9983: foreach my $item (@contexts) {
9984: if ($rownum%2) {
9985: $css_class = '';
9986: } else {
9987: $css_class = ' class="LC_odd_row" ';
9988: }
1.30 raeburn 9989: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 9990: '<td>'.$title{$item}.
9991: '</td><td class="LC_left_item">'.
9992: '<span class="LC_nobreak">';
9993: foreach my $auth (@authtypes) {
9994: $datatable .= '<label>'.
9995: '<input type="checkbox" name="'.$item.'_auth" '.
9996: $checked{$item}{$auth}.' value="'.$auth.'" />'.
9997: $authname{$auth}.'</label> ';
9998: }
9999: $datatable .= '</span></td></tr>';
10000: $rownum ++;
1.27 raeburn 10001: }
1.30 raeburn 10002: $$rowtotal += $rownum;
1.27 raeburn 10003: }
10004: return $datatable;
10005: }
10006:
1.224 raeburn 10007: sub print_selfcreation {
10008: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 10009: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
10010: $emaildomain,$datatable);
1.224 raeburn 10011: if (ref($settings) eq 'HASH') {
10012: if (ref($settings->{'cancreate'}) eq 'HASH') {
10013: $createsettings = $settings->{'cancreate'};
1.236 raeburn 10014: if (ref($createsettings) eq 'HASH') {
10015: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
10016: @selfcreate = @{$createsettings->{'selfcreate'}};
10017: } elsif ($createsettings->{'selfcreate'} ne '') {
10018: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
10019: @selfcreate = ('email','login','sso');
10020: } elsif ($createsettings->{'selfcreate'} ne 'none') {
10021: @selfcreate = ($createsettings->{'selfcreate'});
10022: }
10023: }
10024: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
10025: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 10026: }
1.305 raeburn 10027: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
10028: $emailoptions = $createsettings->{'emailoptions'};
10029: }
1.303 raeburn 10030: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
10031: $emailverified = $createsettings->{'emailverified'};
10032: }
10033: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
10034: $emaildomain = $createsettings->{'emaildomain'};
10035: }
1.224 raeburn 10036: }
10037: }
10038: }
10039: my %radiohash;
10040: my $numinrow = 4;
10041: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 10042: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 10043: if ($position eq 'top') {
10044: my %choices = &Apache::lonlocal::texthash (
10045: cancreate_login => 'Institutional Login',
10046: cancreate_sso => 'Institutional Single Sign On',
10047: );
10048: my @toggles = sort(keys(%choices));
10049: my %defaultchecked = (
10050: 'cancreate_login' => 'off',
10051: 'cancreate_sso' => 'off',
10052: );
1.228 raeburn 10053: my ($onclick,$itemcount);
1.224 raeburn 10054: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
10055: \%choices,$itemcount,$onclick);
1.228 raeburn 10056: $$rowtotal += $itemcount;
1.425 raeburn 10057:
1.224 raeburn 10058: if (ref($usertypes) eq 'HASH') {
10059: if (keys(%{$usertypes}) > 0) {
10060: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
10061: $dom,$numinrow,$othertitle,
1.305 raeburn 10062: 'statustocreate',$rowtotal);
1.224 raeburn 10063: $$rowtotal ++;
10064: }
10065: }
1.240 raeburn 10066: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
10067: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10068: $fieldtitles{'inststatus'} = &mt('Institutional status');
10069: my $rem;
10070: my $numperrow = 2;
10071: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
10072: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 10073: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 10074: '<td class="LC_left_item">'."\n".
1.334 raeburn 10075: '<table>'."\n";
1.240 raeburn 10076: for (my $i=0; $i<@fields; $i++) {
10077: $rem = $i%($numperrow);
10078: if ($rem == 0) {
10079: if ($i > 0) {
10080: $datatable .= '</tr>';
10081: }
10082: $datatable .= '<tr>';
10083: }
10084: my $currval;
1.248 raeburn 10085: if (ref($createsettings) eq 'HASH') {
10086: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
10087: $currval = $createsettings->{'shibenv'}{$fields[$i]};
10088: }
1.240 raeburn 10089: }
10090: $datatable .= '<td class="LC_left_item">'.
10091: '<span class="LC_nobreak">'.
10092: '<input type="text" name="shibenv_'.$fields[$i].'" '.
10093: 'value="'.$currval.'" size="10" /> '.
10094: $fieldtitles{$fields[$i]}.'</span></td>';
10095: }
10096: my $colsleft = $numperrow - $rem;
10097: if ($colsleft > 1 ) {
10098: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10099: ' </td>';
10100: } elsif ($colsleft == 1) {
10101: $datatable .= '<td class="LC_left_item"> </td>';
10102: }
10103: $datatable .= '</tr></table></td></tr>';
10104: $$rowtotal ++;
1.224 raeburn 10105: } elsif ($position eq 'middle') {
10106: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 10107: my @posstypes;
1.224 raeburn 10108: if (ref($types) eq 'ARRAY') {
1.302 raeburn 10109: @posstypes = @{$types};
10110: }
10111: unless (grep(/^default$/,@posstypes)) {
10112: push(@posstypes,'default');
10113: }
10114: my %usertypeshash;
10115: if (ref($usertypes) eq 'HASH') {
10116: %usertypeshash = %{$usertypes};
10117: }
10118: $usertypeshash{'default'} = $othertitle;
10119: foreach my $status (@posstypes) {
10120: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
10121: $numinrow,$$rowtotal,\%usertypeshash);
10122: $$rowtotal ++;
1.224 raeburn 10123: }
10124: } else {
1.236 raeburn 10125: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 10126: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 10127: );
10128: my @toggles = sort(keys(%choices));
10129: my %defaultchecked = (
10130: 'cancreate_email' => 'off',
10131: );
1.305 raeburn 10132: my $customclass = 'LC_selfcreate_email';
10133: my $classprefix = 'LC_canmodify_emailusername_';
10134: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 10135: my $display = 'none';
1.305 raeburn 10136: my $rowstyle = 'display:none';
1.236 raeburn 10137: if (grep(/^\Qemail\E$/,@selfcreate)) {
10138: $display = 'block';
1.305 raeburn 10139: $rowstyle = 'display:table-row';
1.236 raeburn 10140: }
1.305 raeburn 10141: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
10142: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
10143: \%choices,$$rowtotal,$onclick);
10144: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
10145: $rowstyle);
10146: $$rowtotal ++;
10147: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
10148: $rowstyle);
10149: $$rowtotal ++;
10150: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 10151: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 10152: my ($emailrules,$emailruleorder) =
10153: &Apache::lonnet::inst_userrules($dom,'email');
10154: my $primary_id = &Apache::lonnet::domain($dom,'primary');
10155: my $intdom = &Apache::lonnet::internet_dom($primary_id);
10156: if (ref($types) eq 'ARRAY') {
10157: @posstypes = @{$types};
10158: }
10159: if (@posstypes) {
10160: unless (grep(/^default$/,@posstypes)) {
10161: push(@posstypes,'default');
1.302 raeburn 10162: }
10163: if (ref($usertypes) eq 'HASH') {
10164: %usertypeshash = %{$usertypes};
10165: }
1.305 raeburn 10166: my $currassign;
10167: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
10168: $currassign = {
10169: selfassign => $domdefaults{'inststatusguest'},
10170: };
10171: @ordered = @{$domdefaults{'inststatusguest'}};
10172: } else {
10173: $currassign = { selfassign => [] };
10174: }
10175: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
10176: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
10177: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
10178: $numinrow,$othertitle,'selfassign',
10179: $rowtotal,$onclicktypes,$customclass,
10180: $rowstyle);
10181: $$rowtotal ++;
1.302 raeburn 10182: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10183: foreach my $status (@posstypes) {
10184: my $css_class;
10185: if ($$rowtotal%2) {
10186: $css_class = 'LC_odd_row ';
10187: }
10188: $css_class .= $customclass;
10189: my $rowid = $optionsprefix.$status;
10190: my $hidden = 1;
10191: my $currstyle = 'display:none';
10192: if (grep(/^\Q$status\E$/,@ordered)) {
10193: $currstyle = $rowstyle;
1.425 raeburn 10194: $hidden = 0;
1.305 raeburn 10195: }
10196: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10197: $emailrules,$emailruleorder,$settings,$status,$rowid,
10198: $usertypeshash{$status},$css_class,$currstyle,$intdom);
10199: unless ($hidden) {
10200: $$rowtotal ++;
10201: }
1.224 raeburn 10202: }
1.302 raeburn 10203: } else {
1.305 raeburn 10204: my $css_class;
10205: if ($$rowtotal%2) {
10206: $css_class = 'LC_odd_row ';
10207: }
10208: $css_class .= $customclass;
1.302 raeburn 10209: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10210: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10211: $emailrules,$emailruleorder,$settings,'default','',
10212: $othertitle,$css_class,$rowstyle,$intdom);
10213: $$rowtotal ++;
1.224 raeburn 10214: }
10215: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 10216: $numinrow = 1;
1.305 raeburn 10217: if (@posstypes) {
10218: foreach my $status (@posstypes) {
10219: my $rowid = $classprefix.$status;
10220: my $datarowstyle = 'display:none';
1.425 raeburn 10221: if (grep(/^\Q$status\E$/,@ordered)) {
10222: $datarowstyle = $rowstyle;
1.305 raeburn 10223: }
10224: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
10225: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10226: $infotitles,$rowid,$customclass,$datarowstyle);
10227: unless ($datarowstyle eq 'display:none') {
10228: $$rowtotal ++;
10229: }
1.224 raeburn 10230: }
1.305 raeburn 10231: } else {
10232: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
10233: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10234: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 10235: }
10236: }
10237: return $datatable;
10238: }
10239:
1.305 raeburn 10240: sub selfcreate_javascript {
10241: return <<"ENDSCRIPT";
10242:
10243: <script type="text/javascript">
10244: // <![CDATA[
10245:
10246: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
10247: var x = document.getElementsByClassName(target);
10248: var insttypes = 0;
10249: var insttypeRegExp = new RegExp(prefix);
10250: if ((x.length != undefined) && (x.length > 0)) {
10251: if (form.elements[radio].length != undefined) {
10252: for (var i=0; i<form.elements[radio].length; i++) {
10253: if (form.elements[radio][i].checked) {
10254: if (form.elements[radio][i].value == 1) {
10255: for (var j=0; j<x.length; j++) {
10256: if (x[j].id == 'undefined') {
10257: x[j].style.display = 'table-row';
10258: } else if (insttypeRegExp.test(x[j].id)) {
10259: insttypes ++;
10260: } else {
10261: x[j].style.display = 'table-row';
10262: }
10263: }
10264: } else {
10265: for (var j=0; j<x.length; j++) {
10266: x[j].style.display = 'none';
10267: }
1.236 raeburn 10268: }
1.305 raeburn 10269: break;
10270: }
10271: }
10272: if (insttypes > 0) {
10273: toggleDataRow(form,checkbox,target,altprefix);
10274: toggleDataRow(form,checkbox,target,prefix,1);
10275: }
10276: }
10277: }
10278: return;
10279: }
10280:
10281: function toggleDataRow(form,checkbox,target,prefix,docount) {
10282: if (form.elements[checkbox].length != undefined) {
10283: var count = 0;
10284: if (docount) {
10285: for (var i=0; i<form.elements[checkbox].length; i++) {
10286: if (form.elements[checkbox][i].checked) {
10287: count ++;
1.236 raeburn 10288: }
1.305 raeburn 10289: }
10290: }
10291: for (var i=0; i<form.elements[checkbox].length; i++) {
10292: var type = form.elements[checkbox][i].value;
10293: if (document.getElementById(prefix+type)) {
10294: if (form.elements[checkbox][i].checked) {
10295: document.getElementById(prefix+type).style.display = 'table-row';
10296: if (count % 2 == 1) {
10297: document.getElementById(prefix+type).className = target+' LC_odd_row';
10298: } else {
10299: document.getElementById(prefix+type).className = target;
1.236 raeburn 10300: }
1.305 raeburn 10301: count ++;
1.236 raeburn 10302: } else {
1.305 raeburn 10303: document.getElementById(prefix+type).style.display = 'none';
10304: }
10305: }
10306: }
10307: }
10308: return;
10309: }
10310:
10311: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
10312: var caller = radio+'_'+status;
10313: if (form.elements[caller].length != undefined) {
10314: for (var i=0; i<form.elements[caller].length; i++) {
10315: if (form.elements[caller][i].checked) {
10316: if (document.getElementById(altprefix+'_inst_'+status)) {
10317: var curr = form.elements[caller][i].value;
10318: if (prefix) {
10319: document.getElementById(prefix+'_'+status).style.display = 'none';
10320: }
10321: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
10322: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
10323: if (curr == 'custom') {
1.425 raeburn 10324: if (prefix) {
1.305 raeburn 10325: document.getElementById(prefix+'_'+status).style.display = 'inline';
10326: }
10327: } else if (curr == 'inst') {
10328: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
10329: } else if (curr == 'noninst') {
10330: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 10331: }
1.305 raeburn 10332: break;
1.236 raeburn 10333: }
10334: }
10335: }
10336: }
10337: }
10338:
1.305 raeburn 10339: // ]]>
10340: </script>
10341:
10342: ENDSCRIPT
10343: }
10344:
10345: sub noninst_users {
10346: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
1.425 raeburn 10347: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
1.305 raeburn 10348: my $class = 'LC_left_item';
10349: if ($css_class) {
1.425 raeburn 10350: $css_class = ' class="'.$css_class.'"';
1.305 raeburn 10351: }
10352: if ($rowid) {
10353: $rowid = ' id="'.$rowid.'"';
10354: }
10355: if ($rowstyle) {
10356: $rowstyle = ' style="'.$rowstyle.'"';
10357: }
10358: my ($output,$description);
10359: if ($type eq 'default') {
10360: $description = &mt('Requests for: [_1]',$typetitle);
10361: } else {
10362: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
10363: }
10364: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
1.425 raeburn 10365: "<td>$description</td>\n".
1.305 raeburn 10366: '<td class="'.$class.'" colspan="2">'.
10367: '<table><tr>';
1.425 raeburn 10368: my %headers = &Apache::lonlocal::texthash(
1.305 raeburn 10369: approve => 'Processing',
10370: email => 'E-mail',
10371: username => 'Username',
10372: );
10373: foreach my $item ('approve','email','username') {
10374: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 10375: }
1.305 raeburn 10376: $output .= '</tr><tr>';
10377: foreach my $item ('approve','email','username') {
1.306 raeburn 10378: $output .= '<td style="vertical-align: top">';
1.305 raeburn 10379: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
10380: if ($item eq 'approve') {
10381: %choices = &Apache::lonlocal::texthash (
10382: automatic => 'Automatically approved',
10383: approval => 'Queued for approval',
10384: );
10385: @options = ('automatic','approval');
10386: $hashref = $processing;
10387: $defoption = 'automatic';
10388: $name = 'cancreate_emailprocess_'.$type;
10389: } elsif ($item eq 'email') {
10390: %choices = &Apache::lonlocal::texthash (
10391: any => 'Any e-mail',
10392: inst => 'Institutional only',
10393: noninst => 'Non-institutional only',
10394: custom => 'Custom restrictions',
10395: );
10396: @options = ('any','inst','noninst');
10397: my $showcustom;
10398: if (ref($emailrules) eq 'HASH') {
10399: if (keys(%{$emailrules}) > 0) {
10400: push(@options,'custom');
10401: $showcustom = 'cancreate_emailrule';
10402: if (ref($settings) eq 'HASH') {
10403: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
10404: foreach my $rule (@{$settings->{'email_rule'}}) {
10405: if (exists($emailrules->{$rule})) {
10406: $hascustom ++;
10407: }
10408: }
10409: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
10410: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
10411: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
10412: if (exists($emailrules->{$rule})) {
10413: $hascustom ++;
10414: }
10415: }
10416: }
10417: }
10418: }
10419: }
10420: }
10421: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
10422: "'cancreate_emaildomain','$type'".');"';
10423: $hashref = $emailoptions;
10424: $defoption = 'any';
10425: $name = 'cancreate_emailoptions_'.$type;
10426: } elsif ($item eq 'username') {
10427: %choices = &Apache::lonlocal::texthash (
10428: all => 'Same as e-mail',
10429: first => 'Omit @domain',
10430: free => 'Free to choose',
10431: );
10432: @options = ('all','first','free');
10433: $hashref = $emailverified;
10434: $defoption = 'all';
10435: $name = 'cancreate_usernameoptions_'.$type;
10436: }
10437: foreach my $option (@options) {
10438: my $checked;
10439: if (ref($hashref) eq 'HASH') {
10440: if ($type eq '') {
10441: if (!exists($hashref->{'default'})) {
10442: if ($option eq $defoption) {
10443: $checked = ' checked="checked"';
10444: }
10445: } else {
10446: if ($hashref->{'default'} eq $option) {
10447: $checked = ' checked="checked"';
10448: }
1.303 raeburn 10449: }
10450: } else {
1.305 raeburn 10451: if (!exists($hashref->{$type})) {
10452: if ($option eq $defoption) {
10453: $checked = ' checked="checked"';
10454: }
10455: } else {
10456: if ($hashref->{$type} eq $option) {
10457: $checked = ' checked="checked"';
10458: }
1.303 raeburn 10459: }
10460: }
1.305 raeburn 10461: } elsif (($item eq 'email') && ($hascustom)) {
10462: if ($option eq 'custom') {
10463: $checked = ' checked="checked"';
10464: }
10465: } elsif ($option eq $defoption) {
10466: $checked = ' checked="checked"';
10467: }
10468: $output .= '<span class="LC_nobreak"><label>'.
10469: '<input type="radio" name="'.$name.'"'.
10470: $checked.' value="'.$option.'"'.$onclick.' />'.
10471: $choices{$option}.'</label></span><br />';
10472: if ($item eq 'email') {
10473: if ($option eq 'custom') {
10474: my $id = 'cancreate_emailrule_'.$type;
10475: my $display = 'none';
10476: if ($checked) {
10477: $display = 'inline';
1.303 raeburn 10478: }
1.305 raeburn 10479: my $numinrow = 2;
10480: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
10481: '<legend>'.&mt('Disallow').'</legend><table>'.
10482: &user_formats_row('email',$settings,$emailrules,
10483: $emailruleorder,$numinrow,'',$type);
10484: '</table></fieldset>';
10485: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
10486: my %text = &Apache::lonlocal::texthash (
10487: inst => 'must end:',
10488: noninst => 'cannot end:',
10489: );
10490: my $value;
10491: if (ref($emaildomain) eq 'HASH') {
10492: if (ref($emaildomain->{$type}) eq 'HASH') {
1.425 raeburn 10493: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 10494: }
10495: }
1.305 raeburn 10496: if ($value eq '') {
10497: $value = '@'.$intdom;
10498: }
10499: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
10500: my $display = 'none';
10501: if ($checked) {
10502: $display = 'inline';
10503: }
10504: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
10505: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
10506: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
10507: '</div>';
1.303 raeburn 10508: }
10509: }
10510: }
1.305 raeburn 10511: $output .= '</td>'."\n";
1.303 raeburn 10512: }
1.305 raeburn 10513: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 10514: return $output;
10515: }
10516:
1.165 raeburn 10517: sub captcha_choice {
1.305 raeburn 10518: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 10519: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
10520: $vertext,$currver);
1.165 raeburn 10521: my %lt = &captcha_phrases();
10522: $keyentry = 'hidden';
1.354 raeburn 10523: my $colspan=2;
1.165 raeburn 10524: if ($context eq 'cancreate') {
1.224 raeburn 10525: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 10526: } elsif ($context eq 'login') {
10527: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.354 raeburn 10528: } elsif ($context eq 'passwords') {
10529: $rowname = &mt('"Forgot Password" CAPTCHA validation');
10530: $colspan=1;
1.165 raeburn 10531: }
10532: if (ref($settings) eq 'HASH') {
10533: if ($settings->{'captcha'}) {
10534: $checked{$settings->{'captcha'}} = ' checked="checked"';
10535: } else {
10536: $checked{'original'} = ' checked="checked"';
10537: }
10538: if ($settings->{'captcha'} eq 'recaptcha') {
10539: $pubtext = $lt{'pub'};
10540: $privtext = $lt{'priv'};
10541: $keyentry = 'text';
1.269 raeburn 10542: $vertext = $lt{'ver'};
10543: $currver = $settings->{'recaptchaversion'};
10544: if ($currver ne '2') {
10545: $currver = 1;
10546: }
1.165 raeburn 10547: }
10548: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
10549: $currpub = $settings->{'recaptchakeys'}{'public'};
10550: $currpriv = $settings->{'recaptchakeys'}{'private'};
10551: }
10552: } else {
10553: $checked{'original'} = ' checked="checked"';
10554: }
1.305 raeburn 10555: my $css_class;
10556: if ($itemcount%2) {
10557: $css_class = 'LC_odd_row';
10558: }
10559: if ($customcss) {
10560: $css_class .= " $customcss";
10561: }
10562: $css_class =~ s/^\s+//;
10563: if ($css_class) {
10564: $css_class = ' class="'.$css_class.'"';
10565: }
10566: if ($rowstyle) {
10567: $css_class .= ' style="'.$rowstyle.'"';
10568: }
1.169 raeburn 10569: my $output = '<tr'.$css_class.'>'.
1.354 raeburn 10570: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165 raeburn 10571: '<table><tr><td>'."\n";
10572: foreach my $option ('original','recaptcha','notused') {
10573: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
10574: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
10575: $lt{$option}.'</label></span>';
10576: unless ($option eq 'notused') {
10577: $output .= (' 'x2)."\n";
10578: }
10579: }
10580: #
10581: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
10582: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 10583: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 10584: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 10585: #
1.165 raeburn 10586: $output .= '</td></tr>'."\n".
1.305 raeburn 10587: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 10588: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
10589: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
10590: $currpub.'" size="40" /></span><br />'."\n".
10591: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
10592: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 10593: $currpriv.'" size="40" /></span><br />'.
10594: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
10595: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
10596: $currver.'" size="3" /></span><br />'.
10597: '</td></tr></table>'."\n".
1.165 raeburn 10598: '</td></tr>';
10599: return $output;
10600: }
10601:
1.32 raeburn 10602: sub user_formats_row {
1.305 raeburn 10603: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 10604: my $output;
10605: my %text = (
10606: 'username' => 'new usernames',
10607: 'id' => 'IDs',
10608: );
1.409 raeburn 10609: unless (($type eq 'email') || ($type eq 'unamemap')) {
1.305 raeburn 10610: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
10611: $output = '<tr '.$css_class.'>'.
10612: '<td><span class="LC_nobreak">'.
10613: &mt("Format rules to check for $text{$type}: ").
10614: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 10615: }
1.27 raeburn 10616: my $rem;
10617: if (ref($ruleorder) eq 'ARRAY') {
10618: for (my $i=0; $i<@{$ruleorder}; $i++) {
10619: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
10620: my $rem = $i%($numinrow);
10621: if ($rem == 0) {
10622: if ($i > 0) {
10623: $output .= '</tr>';
10624: }
10625: $output .= '<tr>';
10626: }
10627: my $check = ' ';
1.39 raeburn 10628: if (ref($settings) eq 'HASH') {
10629: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
10630: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
10631: $check = ' checked="checked" ';
10632: }
1.305 raeburn 10633: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
10634: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
10635: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
10636: $check = ' checked="checked" ';
10637: }
10638: }
1.27 raeburn 10639: }
10640: }
1.305 raeburn 10641: my $name = $type.'_rule';
10642: if ($type eq 'email') {
10643: $name .= '_'.$status;
10644: }
1.27 raeburn 10645: $output .= '<td class="LC_left_item">'.
10646: '<span class="LC_nobreak"><label>'.
1.311 raeburn 10647: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 10648: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
10649: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
10650: }
10651: }
10652: $rem = @{$ruleorder}%($numinrow);
10653: }
1.305 raeburn 10654: my $colsleft;
10655: if ($rem) {
10656: $colsleft = $numinrow - $rem;
10657: }
1.27 raeburn 10658: if ($colsleft > 1 ) {
10659: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10660: ' </td>';
10661: } elsif ($colsleft == 1) {
10662: $output .= '<td class="LC_left_item"> </td>';
10663: }
1.409 raeburn 10664: $output .= '</tr>';
10665: unless (($type eq 'email') || ($type eq 'unamemap')) {
10666: $output .= '</table></td></tr>';
1.305 raeburn 10667: }
1.27 raeburn 10668: return $output;
10669: }
10670:
1.34 raeburn 10671: sub usercreation_types {
10672: my %lt = &Apache::lonlocal::texthash (
10673: author => 'When adding a co-author',
10674: course => 'When adding a user to a course',
1.100 raeburn 10675: requestcrs => 'When requesting a course',
1.34 raeburn 10676: any => 'Any',
10677: official => 'Institutional only ',
10678: unofficial => 'Non-institutional only',
10679: none => 'None',
10680: );
10681: return %lt;
1.48 raeburn 10682: }
1.34 raeburn 10683:
1.224 raeburn 10684: sub selfcreation_types {
10685: my %lt = &Apache::lonlocal::texthash (
10686: selfcreate => 'User creates own account',
10687: any => 'Any',
10688: official => 'Institutional only ',
10689: unofficial => 'Non-institutional only',
10690: email => 'E-mail address',
10691: login => 'Institutional Login',
10692: sso => 'SSO',
10693: );
10694: }
10695:
1.28 raeburn 10696: sub authtype_names {
10697: my %lt = &Apache::lonlocal::texthash(
10698: int => 'Internal',
10699: krb4 => 'Kerberos 4',
10700: krb5 => 'Kerberos 5',
10701: loc => 'Local',
1.325 raeburn 10702: lti => 'LTI',
1.28 raeburn 10703: );
10704: return %lt;
10705: }
10706:
10707: sub context_names {
10708: my %context_title = &Apache::lonlocal::texthash(
10709: author => 'Creating users when an Author',
10710: course => 'Creating users when in a course',
10711: domain => 'Creating users when a Domain Coordinator',
10712: );
10713: return %context_title;
10714: }
10715:
1.33 raeburn 10716: sub print_usermodification {
10717: my ($position,$dom,$settings,$rowtotal) = @_;
10718: my $numinrow = 4;
10719: my ($context,$datatable,$rowcount);
10720: if ($position eq 'top') {
10721: $rowcount = 0;
10722: $context = 'author';
10723: foreach my $role ('ca','aa') {
10724: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10725: $numinrow,$rowcount);
10726: $$rowtotal ++;
10727: $rowcount ++;
10728: }
1.443 raeburn 10729: } elsif ($position eq 'middle') {
10730: $rowcount = 0;
10731: $context = 'coauthor';
10732: foreach my $role ('ca','aa') {
10733: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10734: $numinrow,$rowcount);
10735: $$rowtotal ++;
10736: $rowcount ++;
10737: }
1.230 raeburn 10738: } elsif ($position eq 'bottom') {
1.33 raeburn 10739: $context = 'course';
10740: $rowcount = 0;
10741: foreach my $role ('st','ep','ta','in','cr') {
10742: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10743: $numinrow,$rowcount);
10744: $$rowtotal ++;
10745: $rowcount ++;
10746: }
10747: }
10748: return $datatable;
10749: }
10750:
1.43 raeburn 10751: sub print_defaults {
1.236 raeburn 10752: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 10753: my $rownum = 0;
1.294 raeburn 10754: my ($datatable,$css_class,$titles);
10755: unless ($position eq 'bottom') {
10756: $titles = &defaults_titles($dom);
10757: }
1.236 raeburn 10758: if ($position eq 'top') {
10759: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
10760: 'datelocale_def','portal_def');
10761: my %defaults;
10762: if (ref($settings) eq 'HASH') {
10763: %defaults = %{$settings};
1.43 raeburn 10764: } else {
1.236 raeburn 10765: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10766: foreach my $item (@items) {
10767: $defaults{$item} = $domdefaults{$item};
10768: }
1.43 raeburn 10769: }
1.236 raeburn 10770: foreach my $item (@items) {
10771: if ($rownum%2) {
10772: $css_class = '';
10773: } else {
10774: $css_class = ' class="LC_odd_row" ';
10775: }
10776: $datatable .= '<tr'.$css_class.'>'.
10777: '<td><span class="LC_nobreak">'.$titles->{$item}.
10778: '</span></td><td class="LC_right_item" colspan="3">';
10779: if ($item eq 'auth_def') {
1.325 raeburn 10780: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 10781: my %shortauth = (
10782: internal => 'int',
10783: krb4 => 'krb4',
10784: krb5 => 'krb5',
1.325 raeburn 10785: localauth => 'loc',
10786: lti => 'lti',
1.236 raeburn 10787: );
10788: my %authnames = &authtype_names();
10789: foreach my $auth (@authtypes) {
10790: my $checked = ' ';
10791: if ($defaults{$item} eq $auth) {
10792: $checked = ' checked="checked" ';
10793: }
10794: $datatable .= '<label><input type="radio" name="'.$item.
10795: '" value="'.$auth.'"'.$checked.'/>'.
10796: $authnames{$shortauth{$auth}}.'</label> ';
10797: }
10798: } elsif ($item eq 'timezone_def') {
10799: my $includeempty = 1;
10800: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
10801: } elsif ($item eq 'datelocale_def') {
10802: my $includeempty = 1;
10803: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
10804: } elsif ($item eq 'lang_def') {
1.263 raeburn 10805: my $includeempty = 1;
10806: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.414 raeburn 10807: } elsif ($item eq 'portal_def') {
10808: $datatable .= '<input type="text" name="'.$item.'" value="'.
10809: $defaults{$item}.'" size="25" onkeyup="portalExtras(this);" />';
10810: my $portalsty = 'none';
10811: if ($defaults{$item}) {
10812: $portalsty = 'block';
10813: }
10814: foreach my $field ('email','web') {
10815: my $checkedoff = ' checked="checked"';
10816: my $checkedon;
10817: if ($defaults{$item.'_'.$field}) {
10818: $checkedon = $checkedoff;
10819: $checkedoff = '';
1.425 raeburn 10820: }
1.414 raeburn 10821: $datatable .= '<div id="'.$item.'_'.$field.'_div" style="display:'.$portalsty.'">'.
10822: '<span class="LC_nobreak">'.$titles->{$field}.' '.
10823: '<label><input type="radio" name="'.$item.'_'.$field.'" value="1"'.$checkedon.'/>'.&mt('Yes').'</label>'.
10824: (' 'x2).
10825: '<label><input type="radio" name="'.$item.'_'.$field.'" value="0"'.$checkedoff.'/>'.&mt('No').'</label>'.
10826: '</div>';
10827: }
1.236 raeburn 10828: } else {
1.414 raeburn 10829: $datatable .= '<input type="text" name="'.$item.'" value="'.$defaults{$item}.'" />';
1.43 raeburn 10830: }
1.236 raeburn 10831: $datatable .= '</td></tr>';
10832: $rownum ++;
10833: }
1.409 raeburn 10834: } elsif ($position eq 'middle') {
1.294 raeburn 10835: my %defaults;
10836: if (ref($settings) eq 'HASH') {
1.354 raeburn 10837: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
10838: my $maxnum = @{$settings->{'inststatusorder'}};
10839: for (my $i=0; $i<$maxnum; $i++) {
10840: $css_class = $rownum%2?' class="LC_odd_row"':'';
10841: my $item = $settings->{'inststatusorder'}->[$i];
10842: my $title = $settings->{'inststatustypes'}->{$item};
10843: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
10844: $datatable .= '<tr'.$css_class.'>'.
10845: '<td><span class="LC_nobreak">'.
10846: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
10847: for (my $k=0; $k<=$maxnum; $k++) {
10848: my $vpos = $k+1;
10849: my $selstr;
10850: if ($k == $i) {
10851: $selstr = ' selected="selected" ';
10852: }
10853: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10854: }
10855: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
10856: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
10857: &mt('delete').'</span></td>'.
1.380 raeburn 10858: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.354 raeburn 10859: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
10860: '</span></td></tr>';
10861: }
10862: $css_class = $rownum%2?' class="LC_odd_row"':'';
10863: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
10864: $datatable .= '<tr '.$css_class.'>'.
10865: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
10866: for (my $k=0; $k<=$maxnum; $k++) {
10867: my $vpos = $k+1;
10868: my $selstr;
10869: if ($k == $maxnum) {
10870: $selstr = ' selected="selected" ';
10871: }
10872: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10873: }
10874: $datatable .= '</select> '.&mt('Internal ID:').
10875: '<input type="text" size="10" name="addinststatus" value="" />'.
10876: ' '.&mt('(new)').
10877: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.380 raeburn 10878: &mt('Name displayed').':'.
1.354 raeburn 10879: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
10880: '</tr>'."\n";
10881: $rownum ++;
1.294 raeburn 10882: }
1.354 raeburn 10883: }
1.409 raeburn 10884: } else {
10885: my ($unamemaprules,$ruleorder) =
10886: &Apache::lonnet::inst_userrules($dom,'unamemap');
10887: $css_class = $rownum%2?' class="LC_odd_row"':'';
10888: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10889: my $numinrow = 2;
10890: $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
10891: &user_formats_row('unamemap',$settings,$unamemaprules,
10892: $ruleorder,$numinrow).
10893: '</table></td></tr>';
10894: }
10895: if ($datatable eq '') {
10896: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
10897: &mt('No rules set for domain in customized localenroll.pm').
10898: '</td></tr>';
10899: }
1.354 raeburn 10900: }
10901: $$rowtotal += $rownum;
1.43 raeburn 10902: return $datatable;
10903: }
10904:
1.168 raeburn 10905: sub get_languages_hash {
10906: my %langchoices;
10907: foreach my $id (&Apache::loncommon::languageids()) {
10908: my $code = &Apache::loncommon::supportedlanguagecode($id);
10909: if ($code ne '') {
10910: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
10911: }
10912: }
10913: return %langchoices;
10914: }
10915:
1.43 raeburn 10916: sub defaults_titles {
1.141 raeburn 10917: my ($dom) = @_;
1.43 raeburn 10918: my %titles = &Apache::lonlocal::texthash (
10919: 'auth_def' => 'Default authentication type',
10920: 'auth_arg_def' => 'Default authentication argument',
10921: 'lang_def' => 'Default language',
1.54 raeburn 10922: 'timezone_def' => 'Default timezone',
1.68 raeburn 10923: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 10924: 'portal_def' => 'Portal/Default URL',
1.414 raeburn 10925: 'email' => 'Email links use portal URL',
10926: 'web' => 'Public web links use portal URL',
1.294 raeburn 10927: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
10928: 'intauth_check' => 'Check bcrypt cost if authenticated',
10929: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 10930: );
1.141 raeburn 10931: if ($dom) {
10932: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
10933: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
10934: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
10935: $protocol = 'http' if ($protocol ne 'https');
10936: if ($uint_dom) {
10937: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
10938: $uint_dom);
10939: }
10940: }
1.43 raeburn 10941: return (\%titles);
10942: }
10943:
1.346 raeburn 10944: sub print_scantron {
10945: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
10946: if ($position eq 'top') {
10947: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
10948: } else {
10949: return &print_scantronconfig($dom,$settings,\$rowtotal);
10950: }
10951: }
10952:
10953: sub scantron_javascript {
10954: return <<"ENDSCRIPT";
10955:
10956: <script type="text/javascript">
10957: // <![CDATA[
10958:
10959: function toggleScantron(form) {
1.347 raeburn 10960: var csvfieldset = new Array();
1.346 raeburn 10961: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 10962: csvfieldset.push(document.getElementById('scantroncsv_cols'));
10963: }
10964: if (document.getElementById('scantroncsv_options')) {
10965: csvfieldset.push(document.getElementById('scantroncsv_options'));
10966: }
10967: if (csvfieldset.length) {
1.346 raeburn 10968: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 10969: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 10970: if (scantroncsv.checked) {
1.347 raeburn 10971: for (var i=0; i<csvfieldset.length; i++) {
10972: csvfieldset[i].style.display = 'block';
10973: }
1.346 raeburn 10974: } else {
1.347 raeburn 10975: for (var i=0; i<csvfieldset.length; i++) {
10976: csvfieldset[i].style.display = 'none';
10977: }
1.346 raeburn 10978: var csvselects = document.getElementsByClassName('scantronconfig_csv');
10979: if (csvselects.length) {
10980: for (var j=0; j<csvselects.length; j++) {
10981: csvselects[j].selectedIndex = 0;
10982: }
10983: }
10984: }
10985: }
10986: }
10987: return;
10988: }
10989: // ]]>
10990: </script>
10991:
10992: ENDSCRIPT
10993:
10994: }
10995:
1.46 raeburn 10996: sub print_scantronformat {
10997: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
10998: my $itemcount = 1;
1.60 raeburn 10999: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
11000: %confhash);
1.46 raeburn 11001: my $switchserver = &check_switchserver($dom,$confname);
11002: my %lt = &Apache::lonlocal::texthash (
1.95 www 11003: default => 'Default bubblesheet format file error',
11004: custom => 'Custom bubblesheet format file error',
1.46 raeburn 11005: );
11006: my %scantronfiles = (
11007: default => 'default.tab',
11008: custom => 'custom.tab',
11009: );
11010: foreach my $key (keys(%scantronfiles)) {
11011: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
11012: .$scantronfiles{$key};
11013: }
11014: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
11015: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
11016: if (!$switchserver) {
11017: my $servadm = $r->dir_config('lonAdmEMail');
11018: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
11019: if ($configuserok eq 'ok') {
11020: if ($author_ok eq 'ok') {
11021: my %legacyfile = (
1.346 raeburn 11022: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
11023: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 11024: );
11025: my %md5chk;
11026: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 11027: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
11028: chomp($md5chk{$type});
1.46 raeburn 11029: }
11030: if ($md5chk{'default'} ne $md5chk{'custom'}) {
11031: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 11032: ($scantronurls{$type},my $error) =
1.46 raeburn 11033: &legacy_scantronformat($r,$dom,$confname,
11034: $type,$legacyfile{$type},
11035: $scantronurls{$type},
11036: $scantronfiles{$type});
1.60 raeburn 11037: if ($error ne '') {
11038: $error{$type} = $error;
11039: }
11040: }
11041: if (keys(%error) == 0) {
11042: $is_custom = 1;
1.346 raeburn 11043: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 11044: $scantronurls{'custom'};
1.346 raeburn 11045: my $putresult =
1.60 raeburn 11046: &Apache::lonnet::put_dom('configuration',
11047: \%confhash,$dom);
11048: if ($putresult ne 'ok') {
1.346 raeburn 11049: $error{'custom'} =
1.60 raeburn 11050: '<span class="LC_error">'.
11051: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
11052: }
1.46 raeburn 11053: }
11054: } else {
1.60 raeburn 11055: ($scantronurls{'default'},my $error) =
1.46 raeburn 11056: &legacy_scantronformat($r,$dom,$confname,
11057: 'default',$legacyfile{'default'},
11058: $scantronurls{'default'},
11059: $scantronfiles{'default'});
1.60 raeburn 11060: if ($error eq '') {
11061: $confhash{'scantron'}{'scantronformat'} = '';
11062: my $putresult =
11063: &Apache::lonnet::put_dom('configuration',
11064: \%confhash,$dom);
11065: if ($putresult ne 'ok') {
11066: $error{'default'} =
11067: '<span class="LC_error">'.
11068: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
11069: }
11070: } else {
11071: $error{'default'} = $error;
11072: }
1.46 raeburn 11073: }
11074: }
11075: }
11076: } else {
1.95 www 11077: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 11078: }
11079: }
11080: if (ref($settings) eq 'HASH') {
11081: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
11082: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
11083: if ((!@info) || ($info[0] eq 'no_such_dir')) {
11084: $scantronurl = '';
11085: } else {
11086: $scantronurl = $settings->{'scantronformat'};
11087: }
11088: $is_custom = 1;
11089: } else {
11090: $scantronurl = $scantronurls{'default'};
11091: }
11092: } else {
1.60 raeburn 11093: if ($is_custom) {
11094: $scantronurl = $scantronurls{'custom'};
11095: } else {
11096: $scantronurl = $scantronurls{'default'};
11097: }
1.46 raeburn 11098: }
11099: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11100: $datatable .= '<tr'.$css_class.'>';
11101: if (!$is_custom) {
1.65 raeburn 11102: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
11103: '<span class="LC_nobreak">';
1.46 raeburn 11104: if ($scantronurl) {
1.199 raeburn 11105: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
11106: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 11107: } else {
11108: $datatable = &mt('File unavailable for display');
11109: }
1.65 raeburn 11110: $datatable .= '</span></td>';
1.60 raeburn 11111: if (keys(%error) == 0) {
1.306 raeburn 11112: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 11113: if (!$switchserver) {
11114: $datatable .= &mt('Upload:').'<br />';
11115: }
11116: } else {
11117: my $errorstr;
11118: foreach my $key (sort(keys(%error))) {
11119: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
11120: }
11121: $datatable .= '<td>'.$errorstr;
11122: }
1.46 raeburn 11123: } else {
11124: if (keys(%error) > 0) {
11125: my $errorstr;
11126: foreach my $key (sort(keys(%error))) {
11127: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
11128: }
1.60 raeburn 11129: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 11130: } elsif ($scantronurl) {
1.199 raeburn 11131: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
11132: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 11133: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 11134: $link.
11135: '<label><input type="checkbox" name="scantronformat_del"'.
11136: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 11137: '<td><span class="LC_nobreak"> '.
11138: &mt('Replace:').'</span><br />';
1.46 raeburn 11139: }
11140: }
11141: if (keys(%error) == 0) {
11142: if ($switchserver) {
11143: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
11144: } else {
1.65 raeburn 11145: $datatable .='<span class="LC_nobreak"> '.
11146: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 11147: }
11148: }
11149: $datatable .= '</td></tr>';
11150: $$rowtotal ++;
11151: return $datatable;
11152: }
11153:
11154: sub legacy_scantronformat {
11155: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
11156: my ($url,$error);
11157: my @statinfo = &Apache::lonnet::stat_file($newurl);
11158: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
1.421 raeburn 11159: my $modified = [];
1.46 raeburn 11160: (my $result,$url) =
1.421 raeburn 11161: &Apache::lonconfigsettings::publishlogo($r,'copy',$legacyfile,$dom,$confname,
11162: 'scantron','','',$newfile,$modified);
11163: if ($result eq 'ok') {
11164: &update_modify_urls($r,$modified);
11165: } else {
1.130 raeburn 11166: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 11167: }
11168: }
11169: return ($url,$error);
11170: }
1.43 raeburn 11171:
1.346 raeburn 11172: sub print_scantronconfig {
11173: my ($dom,$settings,$rowtotal) = @_;
11174: my $itemcount = 2;
11175: my $is_checked = ' checked="checked"';
1.347 raeburn 11176: my %optionson = (
11177: hdr => ' checked="checked"',
11178: pad => ' checked="checked"',
11179: rem => ' checked="checked"',
11180: );
11181: my %optionsoff = (
11182: hdr => '',
11183: pad => '',
11184: rem => '',
11185: );
1.346 raeburn 11186: my $currcsvsty = 'none';
1.347 raeburn 11187: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 11188: my @fields = &scantroncsv_fields();
11189: my %titles = &scantronconfig_titles();
11190: if (ref($settings) eq 'HASH') {
11191: if (ref($settings->{config}) eq 'HASH') {
11192: if ($settings->{config}->{dat}) {
11193: $checked{'dat'} = $is_checked;
11194: }
11195: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 11196: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
11197: %csvfields = %{$settings->{config}->{csv}->{fields}};
11198: if (keys(%csvfields) > 0) {
11199: $checked{'csv'} = $is_checked;
11200: $currcsvsty = 'block';
11201: }
11202: }
11203: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
11204: %csvoptions = %{$settings->{config}->{csv}->{options}};
11205: foreach my $option (keys(%optionson)) {
11206: unless ($csvoptions{$option}) {
11207: $optionsoff{$option} = $optionson{$option};
11208: $optionson{$option} = '';
11209: }
11210: }
1.346 raeburn 11211: }
11212: }
11213: } else {
11214: $checked{'dat'} = $is_checked;
11215: }
11216: } else {
11217: $checked{'dat'} = $is_checked;
11218: }
11219: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
11220: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11221: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
11222: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
11223: foreach my $item ('dat','csv') {
11224: my $id;
11225: if ($item eq 'csv') {
11226: $id = 'id="scantronconfcsv" ';
1.347 raeburn 11227: }
1.346 raeburn 11228: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
11229: $titles{$item}.'</label>'.(' 'x3);
11230: if ($item eq 'csv') {
11231: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
11232: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
11233: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
11234: foreach my $col (@fields) {
11235: my $selnone;
11236: if ($csvfields{$col} eq '') {
11237: $selnone = ' selected="selected"';
11238: }
11239: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
11240: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
11241: '<option value=""'.$selnone.'></option>';
11242: for (my $i=0; $i<20; $i++) {
11243: my $shown = $i+1;
11244: my $sel;
11245: unless ($selnone) {
11246: if (exists($csvfields{$col})) {
11247: if ($csvfields{$col} == $i) {
11248: $sel = ' selected="selected"';
11249: }
11250: }
11251: }
11252: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
11253: }
11254: $datatable .= '</select></td></tr>';
11255: }
1.347 raeburn 11256: $datatable .= '</table></fieldset>'.
11257: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
11258: '<legend>'.&mt('CSV Options').'</legend>';
11259: foreach my $option ('hdr','pad','rem') {
11260: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
11261: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
11262: &mt('Yes').'</label>'.(' 'x2)."\n".
11263: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
11264: }
11265: $datatable .= '</fieldset>';
1.346 raeburn 11266: $itemcount ++;
11267: }
11268: }
11269: $datatable .= '</td></tr>';
11270: $$rowtotal ++;
11271: return $datatable;
11272: }
11273:
11274: sub scantronconfig_titles {
11275: return &Apache::lonlocal::texthash(
11276: dat => 'Standard format (.dat)',
11277: csv => 'Comma separated values (.csv)',
1.347 raeburn 11278: hdr => 'Remove first line in file (contains column titles)',
11279: pad => 'Prepend 0s to PaperID',
1.348 raeburn 11280: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 11281: CODE => 'CODE',
11282: ID => 'Student ID',
11283: PaperID => 'Paper ID',
11284: FirstName => 'First Name',
11285: LastName => 'Last Name',
11286: FirstQuestion => 'First Question Response',
11287: Section => 'Section',
11288: );
11289: }
11290:
11291: sub scantroncsv_fields {
11292: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
11293: }
11294:
1.49 raeburn 11295: sub print_coursecategories {
1.57 raeburn 11296: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
11297: my $datatable;
11298: if ($position eq 'top') {
1.238 raeburn 11299: my (%checked);
11300: my @catitems = ('unauth','auth');
11301: my @cattypes = ('std','domonly','codesrch','none');
11302: $checked{'unauth'} = 'std';
11303: $checked{'auth'} = 'std';
11304: if (ref($settings) eq 'HASH') {
11305: foreach my $type (@cattypes) {
11306: if ($type eq $settings->{'unauth'}) {
11307: $checked{'unauth'} = $type;
11308: }
11309: if ($type eq $settings->{'auth'}) {
11310: $checked{'auth'} = $type;
11311: }
11312: }
11313: }
11314: my %lt = &Apache::lonlocal::texthash (
11315: unauth => 'Catalog type for unauthenticated users',
11316: auth => 'Catalog type for authenticated users',
11317: none => 'No catalog',
11318: std => 'Standard catalog',
11319: domonly => 'Domain-only catalog',
11320: codesrch => "Code search form",
11321: );
11322: my $itemcount = 0;
11323: foreach my $item (@catitems) {
11324: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11325: $datatable .= '<tr '.$css_class.'>'.
11326: '<td>'.$lt{$item}.'</td>'.
11327: '<td class="LC_right_item"><span class="LC_nobreak">';
11328: foreach my $type (@cattypes) {
11329: my $ischecked;
11330: if ($checked{$item} eq $type) {
11331: $ischecked=' checked="checked"';
11332: }
11333: $datatable .= '<label>'.
11334: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
11335: ' />'.$lt{$type}.'</label> ';
11336: }
1.327 raeburn 11337: $datatable .= '</span></td></tr>';
1.238 raeburn 11338: $itemcount ++;
11339: }
11340: $$rowtotal += $itemcount;
11341: } elsif ($position eq 'middle') {
1.57 raeburn 11342: my $toggle_cats_crs = ' ';
11343: my $toggle_cats_dom = ' checked="checked" ';
11344: my $can_cat_crs = ' ';
11345: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 11346: my $toggle_catscomm_comm = ' ';
11347: my $toggle_catscomm_dom = ' checked="checked" ';
11348: my $can_catcomm_comm = ' ';
11349: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 11350: my $toggle_catsplace_place = ' ';
11351: my $toggle_catsplace_dom = ' checked="checked" ';
11352: my $can_catplace_place = ' ';
11353: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 11354:
1.57 raeburn 11355: if (ref($settings) eq 'HASH') {
11356: if ($settings->{'togglecats'} eq 'crs') {
11357: $toggle_cats_crs = $toggle_cats_dom;
11358: $toggle_cats_dom = ' ';
11359: }
11360: if ($settings->{'categorize'} eq 'crs') {
11361: $can_cat_crs = $can_cat_dom;
11362: $can_cat_dom = ' ';
11363: }
1.120 raeburn 11364: if ($settings->{'togglecatscomm'} eq 'comm') {
11365: $toggle_catscomm_comm = $toggle_catscomm_dom;
11366: $toggle_catscomm_dom = ' ';
11367: }
11368: if ($settings->{'categorizecomm'} eq 'comm') {
11369: $can_catcomm_comm = $can_catcomm_dom;
11370: $can_catcomm_dom = ' ';
11371: }
1.272 raeburn 11372: if ($settings->{'togglecatsplace'} eq 'place') {
11373: $toggle_catsplace_place = $toggle_catsplace_dom;
11374: $toggle_catsplace_dom = ' ';
11375: }
11376: if ($settings->{'categorizeplace'} eq 'place') {
11377: $can_catplace_place = $can_catplace_dom;
11378: $can_catplace_dom = ' ';
11379: }
1.57 raeburn 11380: }
11381: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 11382: togglecats => 'Show/Hide a course in catalog',
11383: togglecatscomm => 'Show/Hide a community in catalog',
11384: togglecatsplace => 'Show/Hide a placement test in catalog',
11385: categorize => 'Assign a category to a course',
11386: categorizecomm => 'Assign a category to a community',
11387: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 11388: );
11389: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 11390: dom => 'Set in Domain',
11391: crs => 'Set in Course',
11392: comm => 'Set in Community',
11393: place => 'Set in Placement Test',
1.57 raeburn 11394: );
11395: $datatable = '<tr class="LC_odd_row">'.
11396: '<td>'.$title{'togglecats'}.'</td>'.
11397: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11398: '<input type="radio" name="togglecats"'.
11399: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11400: '<label><input type="radio" name="togglecats"'.
11401: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
11402: '</tr><tr>'.
11403: '<td>'.$title{'categorize'}.'</td>'.
11404: '<td class="LC_right_item"><span class="LC_nobreak">'.
11405: '<label><input type="radio" name="categorize"'.
11406: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11407: '<label><input type="radio" name="categorize"'.
11408: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 11409: '</tr><tr class="LC_odd_row">'.
11410: '<td>'.$title{'togglecatscomm'}.'</td>'.
11411: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11412: '<input type="radio" name="togglecatscomm"'.
11413: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11414: '<label><input type="radio" name="togglecatscomm"'.
11415: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
11416: '</tr><tr>'.
11417: '<td>'.$title{'categorizecomm'}.'</td>'.
11418: '<td class="LC_right_item"><span class="LC_nobreak">'.
11419: '<label><input type="radio" name="categorizecomm"'.
11420: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11421: '<label><input type="radio" name="categorizecomm"'.
11422: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 11423: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 11424: '<td>'.$title{'togglecatsplace'}.'</td>'.
11425: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11426: '<input type="radio" name="togglecatsplace"'.
11427: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11428: '<label><input type="radio" name="togglecatscomm"'.
11429: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
11430: '</tr><tr>'.
11431: '<td>'.$title{'categorizeplace'}.'</td>'.
11432: '<td class="LC_right_item"><span class="LC_nobreak">'.
11433: '<label><input type="radio" name="categorizeplace"'.
11434: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11435: '<label><input type="radio" name="categorizeplace"'.
11436: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 11437: '</tr>';
1.272 raeburn 11438: $$rowtotal += 6;
1.57 raeburn 11439: } else {
11440: my $css_class;
11441: my $itemcount = 1;
11442: my $cathash;
11443: if (ref($settings) eq 'HASH') {
11444: $cathash = $settings->{'cats'};
11445: }
11446: if (ref($cathash) eq 'HASH') {
11447: my (@cats,@trails,%allitems,%idx,@jsarray);
11448: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
11449: \%allitems,\%idx,\@jsarray);
11450: my $maxdepth = scalar(@cats);
11451: my $colattrib = '';
11452: if ($maxdepth > 2) {
11453: $colattrib = ' colspan="2" ';
11454: }
11455: my @path;
11456: if (@cats > 0) {
11457: if (ref($cats[0]) eq 'ARRAY') {
11458: my $numtop = @{$cats[0]};
11459: my $maxnum = $numtop;
1.120 raeburn 11460: my %default_names = (
11461: instcode => &mt('Official courses'),
11462: communities => &mt('Communities'),
1.272 raeburn 11463: placement => &mt('Placement Tests'),
1.120 raeburn 11464: );
11465:
11466: if ((!grep(/^instcode$/,@{$cats[0]})) ||
11467: ($cathash->{'instcode::0'} eq '') ||
11468: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 11469: ($cathash->{'communities::0'} eq '') ||
11470: (!grep(/^placement$/,@{$cats[0]})) ||
11471: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 11472: $maxnum ++;
11473: }
11474: my $lastidx;
11475: for (my $i=0; $i<$numtop; $i++) {
11476: my $parent = $cats[0][$i];
11477: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11478: my $item = &escape($parent).'::0';
11479: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
11480: $lastidx = $idx{$item};
11481: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
11482: .'<select name="'.$item.'"'.$chgstr.'>';
11483: for (my $k=0; $k<=$maxnum; $k++) {
11484: my $vpos = $k+1;
11485: my $selstr;
11486: if ($k == $i) {
11487: $selstr = ' selected="selected" ';
11488: }
11489: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11490: }
1.214 raeburn 11491: $datatable .= '</select></span></td><td>';
1.272 raeburn 11492: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 11493: $datatable .= '<span class="LC_nobreak">'
11494: .$default_names{$parent}.'</span>';
11495: if ($parent eq 'instcode') {
11496: $datatable .= '<br /><span class="LC_nobreak">('
11497: .&mt('with institutional codes')
11498: .')</span></td><td'.$colattrib.'>';
11499: } else {
11500: $datatable .= '<table><tr><td>';
11501: }
11502: $datatable .= '<span class="LC_nobreak">'
11503: .'<label><input type="radio" name="'
11504: .$parent.'" value="1" checked="checked" />'
11505: .&mt('Display').'</label>';
11506: if ($parent eq 'instcode') {
11507: $datatable .= ' ';
11508: } else {
11509: $datatable .= '</span></td></tr><tr><td>'
11510: .'<span class="LC_nobreak">';
11511: }
11512: $datatable .= '<label><input type="radio" name="'
11513: .$parent.'" value="0" />'
11514: .&mt('Do not display').'</label></span>';
1.272 raeburn 11515: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 11516: $datatable .= '</td></tr></table>';
11517: }
11518: $datatable .= '</td>';
1.57 raeburn 11519: } else {
11520: $datatable .= $parent
1.214 raeburn 11521: .' <span class="LC_nobreak"><label>'
11522: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 11523: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
11524: }
11525: my $depth = 1;
11526: push(@path,$parent);
11527: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
11528: pop(@path);
11529: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
11530: $itemcount ++;
11531: }
1.48 raeburn 11532: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 11533: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
11534: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 11535: for (my $k=0; $k<=$maxnum; $k++) {
11536: my $vpos = $k+1;
11537: my $selstr;
1.57 raeburn 11538: if ($k == $numtop) {
1.48 raeburn 11539: $selstr = ' selected="selected" ';
11540: }
11541: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11542: }
1.59 bisitz 11543: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 11544: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
11545: .'</tr>'."\n";
1.48 raeburn 11546: $itemcount ++;
1.272 raeburn 11547: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11548: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
11549: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11550: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
11551: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
11552: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
11553: for (my $k=0; $k<=$maxnum; $k++) {
11554: my $vpos = $k+1;
11555: my $selstr;
11556: if ($k == $maxnum) {
11557: $selstr = ' selected="selected" ';
11558: }
11559: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 11560: }
1.120 raeburn 11561: $datatable .= '</select></span></td>'.
11562: '<td><span class="LC_nobreak">'.
11563: $default_names{$default}.'</span>';
11564: if ($default eq 'instcode') {
11565: $datatable .= '<br /><span class="LC_nobreak">('
11566: .&mt('with institutional codes').')</span>';
11567: }
11568: $datatable .= '</td>'
11569: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
11570: .&mt('Display').'</label> '
11571: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
11572: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 11573: }
11574: }
11575: }
1.57 raeburn 11576: } else {
11577: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 11578: }
11579: } else {
1.327 raeburn 11580: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 11581: .&initialize_categories($itemcount);
1.48 raeburn 11582: }
1.57 raeburn 11583: $$rowtotal += $itemcount;
1.48 raeburn 11584: }
11585: return $datatable;
11586: }
11587:
1.69 raeburn 11588: sub print_serverstatuses {
11589: my ($dom,$settings,$rowtotal) = @_;
11590: my $datatable;
11591: my @pages = &serverstatus_pages();
11592: my (%namedaccess,%machineaccess);
11593: foreach my $type (@pages) {
11594: $namedaccess{$type} = '';
11595: $machineaccess{$type}= '';
11596: }
11597: if (ref($settings) eq 'HASH') {
11598: foreach my $type (@pages) {
11599: if (exists($settings->{$type})) {
11600: if (ref($settings->{$type}) eq 'HASH') {
11601: foreach my $key (keys(%{$settings->{$type}})) {
11602: if ($key eq 'namedusers') {
11603: $namedaccess{$type} = $settings->{$type}->{$key};
11604: } elsif ($key eq 'machines') {
11605: $machineaccess{$type} = $settings->{$type}->{$key};
11606: }
11607: }
11608: }
11609: }
11610: }
11611: }
1.81 raeburn 11612: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11613: my $rownum = 0;
11614: my $css_class;
11615: foreach my $type (@pages) {
11616: $rownum ++;
11617: $css_class = $rownum%2?' class="LC_odd_row"':'';
11618: $datatable .= '<tr'.$css_class.'>'.
11619: '<td><span class="LC_nobreak">'.
11620: $titles->{$type}.'</span></td>'.
11621: '<td class="LC_left_item">'.
11622: '<input type="text" name="'.$type.'_namedusers" '.
11623: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
11624: '<td class="LC_right_item">'.
11625: '<span class="LC_nobreak">'.
11626: '<input type="text" name="'.$type.'_machines" '.
11627: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 11628: '</span></td></tr>'."\n";
1.69 raeburn 11629: }
11630: $$rowtotal += $rownum;
11631: return $datatable;
11632: }
11633:
11634: sub serverstatus_pages {
11635: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 11636: 'checksums','clusterstatus','certstatus','metadata_keywords',
11637: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
11638: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 11639: }
11640:
1.236 raeburn 11641: sub defaults_javascript {
11642: my ($settings) = @_;
1.354 raeburn 11643: return unless (ref($settings) eq 'HASH');
1.414 raeburn 11644: my $portal_js = <<"ENDPORTAL";
11645:
11646: function portalExtras(caller) {
11647: var x = caller.value;
11648: var y = new Array('email','web');
1.425 raeburn 11649: for (var i=0; i<y.length; i++) {
1.414 raeburn 11650: if (document.getElementById('portal_def_'+y[i]+'_div')) {
11651: var z = document.getElementById('portal_def_'+y[i]+'_div');
11652: if (x.length > 0) {
11653: z.style.display = 'block';
11654: } else {
11655: z.style.display = 'none';
11656: }
11657: }
11658: }
11659: }
11660: ENDPORTAL
1.236 raeburn 11661: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
11662: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
11663: if ($maxnum eq '') {
11664: $maxnum = 0;
11665: }
11666: $maxnum ++;
1.249 raeburn 11667: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 11668: return <<"ENDSCRIPT";
11669: <script type="text/javascript">
11670: // <![CDATA[
11671: function reorderTypes(form,caller) {
11672: var changedVal;
11673: $jstext
11674: var newpos = 'addinststatus_pos';
11675: var current = new Array;
11676: var maxh = $maxnum;
11677: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11678: var oldVal;
11679: if (caller == newpos) {
11680: changedVal = newitemVal;
11681: } else {
11682: var curritem = 'inststatus_pos_'+caller;
11683: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
11684: current[newitemVal] = newpos;
11685: }
11686: for (var i=0; i<inststatuses.length; i++) {
11687: if (inststatuses[i] != caller) {
11688: var elementName = 'inststatus_pos_'+inststatuses[i];
11689: if (form.elements[elementName]) {
11690: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11691: current[currVal] = elementName;
11692: }
11693: }
11694: }
11695: for (var j=0; j<maxh; j++) {
11696: if (current[j] == undefined) {
11697: oldVal = j;
11698: }
11699: }
11700: if (oldVal < changedVal) {
11701: for (var k=oldVal+1; k<=changedVal ; k++) {
11702: var elementName = current[k];
11703: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11704: }
11705: } else {
11706: for (var k=changedVal; k<oldVal; k++) {
11707: var elementName = current[k];
11708: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11709: }
11710: }
11711: return;
11712: }
11713:
1.414 raeburn 11714: $portal_js
11715:
11716: // ]]>
11717: </script>
11718:
11719: ENDSCRIPT
11720: } else {
11721: return <<"ENDSCRIPT";
11722: <script type="text/javascript">
11723: // <![CDATA[
11724: $portal_js
1.236 raeburn 11725: // ]]>
11726: </script>
11727:
11728: ENDSCRIPT
11729: }
1.354 raeburn 11730: return;
11731: }
11732:
11733: sub passwords_javascript {
1.405 raeburn 11734: my ($prefix) = @_;
11735: my %intalert;
11736: if ($prefix eq 'passwords') {
11737: %intalert = &Apache::lonlocal::texthash (
11738: authcheck => 'Warning: disallowing login for an authenticated user if the stored cost is less than the default will require a password reset by/for the user.',
11739: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
11740: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
11741: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
11742: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
11743: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
11744: );
1.421 raeburn 11745: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 11746: %intalert = &Apache::lonlocal::texthash (
11747: passmin => 'Warning: minimum secret length must be a positive integer greater than 6.',
11748: passmax => 'Warning: maximum secret length must be a positive integer (or blank).',
11749: );
11750: }
1.365 raeburn 11751: &js_escape(\%intalert);
11752: my $defmin = $Apache::lonnet::passwdmin;
1.425 raeburn 11753: my $intauthjs;
1.405 raeburn 11754: if ($prefix eq 'passwords') { $intauthjs = <<"ENDSCRIPT";
1.354 raeburn 11755:
11756: function warnIntAuth(field) {
11757: if (field.name == 'intauth_check') {
11758: if (field.value == '2') {
1.365 raeburn 11759: alert('$intalert{authcheck}');
1.354 raeburn 11760: }
11761: }
11762: if (field.name == 'intauth_cost') {
11763: field.value.replace(/\s/g,'');
11764: if (field.value != '') {
11765: var regexdigit=/^\\d+\$/;
11766: if (!regexdigit.test(field.value)) {
1.365 raeburn 11767: alert('$intalert{authcost}');
11768: }
11769: }
11770: }
11771: return;
11772: }
11773:
1.405 raeburn 11774: ENDSCRIPT
11775:
11776: }
11777:
11778: $intauthjs .= <<"ENDSCRIPT";
11779:
11780: function warnInt$prefix(field) {
1.365 raeburn 11781: field.value.replace(/^\s+/,'');
11782: field.value.replace(/\s+\$/,'');
11783: var regexdigit=/^\\d+\$/;
1.408 raeburn 11784: if (field.name == '${prefix}_min') {
1.365 raeburn 11785: if (field.value == '') {
11786: alert('$intalert{passmin}');
11787: field.value = '$defmin';
11788: } else {
11789: if (!regexdigit.test(field.value)) {
11790: alert('$intalert{passmin}');
11791: field.value = '$defmin';
11792: }
1.366 raeburn 11793: var minval = parseInt(field.value,10);
1.365 raeburn 11794: if (minval < $defmin) {
11795: alert('$intalert{passmin}');
11796: field.value = '$defmin';
11797: }
11798: }
11799: } else {
11800: if (field.value == '0') {
11801: field.value = '';
11802: }
11803: if (field.value != '') {
1.408 raeburn 11804: if (field.name == '${prefix}_expire') {
1.365 raeburn 11805: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
11806: if (!regexpposnum.test(field.value)) {
11807: alert('$intalert{passexp}');
11808: field.value = '';
11809: } else {
11810: var expval = parseFloat(field.value);
11811: if (expval == 0) {
11812: alert('$intalert{passexp}');
11813: field.value = '';
11814: }
11815: }
11816: } else {
11817: if (!regexdigit.test(field.value)) {
1.408 raeburn 11818: if (field.name == '${prefix}_max') {
1.365 raeburn 11819: alert('$intalert{passmax}');
11820: } else {
1.408 raeburn 11821: if (field.name == '${prefix}_numsaved') {
1.365 raeburn 11822: alert('$intalert{passnum}');
11823: }
11824: }
1.370 raeburn 11825: field.value = '';
1.365 raeburn 11826: }
1.354 raeburn 11827: }
11828: }
11829: }
11830: return;
11831: }
11832:
11833: ENDSCRIPT
11834: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 11835: }
11836:
1.49 raeburn 11837: sub coursecategories_javascript {
11838: my ($settings) = @_;
1.57 raeburn 11839: my ($output,$jstext,$cathash);
1.49 raeburn 11840: if (ref($settings) eq 'HASH') {
1.57 raeburn 11841: $cathash = $settings->{'cats'};
11842: }
11843: if (ref($cathash) eq 'HASH') {
1.49 raeburn 11844: my (@cats,@jsarray,%idx);
1.57 raeburn 11845: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 11846: if (@jsarray > 0) {
11847: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
11848: for (my $i=0; $i<@jsarray; $i++) {
11849: if (ref($jsarray[$i]) eq 'ARRAY') {
11850: my $catstr = join('","',@{$jsarray[$i]});
11851: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
11852: }
11853: }
11854: }
11855: } else {
11856: $jstext = ' var categories = Array(1);'."\n".
11857: ' categories[0] = Array("instcode_pos");'."\n";
11858: }
1.237 bisitz 11859: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
11860: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 11861: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 11862: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
11863: &js_escape(\$instcode_reserved);
11864: &js_escape(\$communities_reserved);
1.272 raeburn 11865: &js_escape(\$placement_reserved);
1.265 damieng 11866: &js_escape(\$choose_again);
1.49 raeburn 11867: $output = <<"ENDSCRIPT";
11868: <script type="text/javascript">
1.109 raeburn 11869: // <![CDATA[
1.49 raeburn 11870: function reorderCats(form,parent,item,idx) {
11871: var changedVal;
11872: $jstext
11873: var newpos = 'addcategory_pos';
11874: if (parent == '') {
11875: var has_instcode = 0;
11876: var maxtop = categories[idx].length;
11877: for (var j=0; j<maxtop; j++) {
11878: if (categories[idx][j] == 'instcode::0') {
11879: has_instcode == 1;
11880: }
11881: }
11882: if (has_instcode == 0) {
11883: categories[idx][maxtop] = 'instcode_pos';
11884: }
11885: } else {
11886: newpos += '_'+parent;
11887: }
11888: var maxh = 1 + categories[idx].length;
11889: var current = new Array;
11890: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11891: if (item == newpos) {
11892: changedVal = newitemVal;
11893: } else {
11894: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
11895: current[newitemVal] = newpos;
11896: }
11897: for (var i=0; i<categories[idx].length; i++) {
11898: var elementName = categories[idx][i];
11899: if (elementName != item) {
11900: if (form.elements[elementName]) {
11901: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11902: current[currVal] = elementName;
11903: }
11904: }
11905: }
11906: var oldVal;
11907: for (var j=0; j<maxh; j++) {
11908: if (current[j] == undefined) {
11909: oldVal = j;
11910: }
11911: }
11912: if (oldVal < changedVal) {
11913: for (var k=oldVal+1; k<=changedVal ; k++) {
11914: var elementName = current[k];
11915: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11916: }
11917: } else {
11918: for (var k=changedVal; k<oldVal; k++) {
11919: var elementName = current[k];
11920: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11921: }
11922: }
11923: return;
11924: }
1.120 raeburn 11925:
11926: function categoryCheck(form) {
11927: if (form.elements['addcategory_name'].value == 'instcode') {
11928: alert('$instcode_reserved\\n$choose_again');
11929: return false;
11930: }
11931: if (form.elements['addcategory_name'].value == 'communities') {
11932: alert('$communities_reserved\\n$choose_again');
11933: return false;
11934: }
1.272 raeburn 11935: if (form.elements['addcategory_name'].value == 'placement') {
11936: alert('$placement_reserved\\n$choose_again');
11937: return false;
11938: }
1.120 raeburn 11939: return true;
11940: }
11941:
1.109 raeburn 11942: // ]]>
1.49 raeburn 11943: </script>
11944:
11945: ENDSCRIPT
11946: return $output;
11947: }
11948:
1.48 raeburn 11949: sub initialize_categories {
11950: my ($itemcount) = @_;
1.120 raeburn 11951: my ($datatable,$css_class,$chgstr);
1.380 raeburn 11952: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 11953: instcode => 'Official courses (with institutional codes)',
11954: communities => 'Communities',
1.272 raeburn 11955: placement => 'Placement Tests',
1.120 raeburn 11956: );
1.328 raeburn 11957: my %selnum = (
11958: instcode => '0',
11959: communities => '1',
11960: placement => '2',
11961: );
11962: my %selected;
1.272 raeburn 11963: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11964: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 11965: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 11966: map { $selected{$selnum{$_}} = '' } keys(%selnum);
11967: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 11968: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 11969: .'<select name="'.$default.'_pos"'.$chgstr.'>'
11970: .'<option value="0"'.$selected{'0'}.'>1</option>'
11971: .'<option value="1"'.$selected{'1'}.'>2</option>'
11972: .'<option value="2"'.$selected{'2'}.'>3</option>'
11973: .'<option value="3">4</option></select> '
1.120 raeburn 11974: .$default_names{$default}
11975: .'</span></td><td><span class="LC_nobreak">'
11976: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
11977: .&mt('Display').'</label> <label>'
11978: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 11979: .'</label></span></td></tr>';
1.120 raeburn 11980: $itemcount ++;
11981: }
1.48 raeburn 11982: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 11983: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 11984: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 11985: .'<select name="addcategory_pos"'.$chgstr.'>'
11986: .'<option value="0">1</option>'
11987: .'<option value="1">2</option>'
1.328 raeburn 11988: .'<option value="2">3</option>'
11989: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 11990: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
11991: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
11992: .'</td></tr>';
1.48 raeburn 11993: return $datatable;
11994: }
11995:
11996: sub build_category_rows {
1.49 raeburn 11997: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
11998: my ($text,$name,$item,$chgstr);
1.48 raeburn 11999: if (ref($cats) eq 'ARRAY') {
12000: my $maxdepth = scalar(@{$cats});
12001: if (ref($cats->[$depth]) eq 'HASH') {
12002: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
12003: my $numchildren = @{$cats->[$depth]{$parent}};
12004: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 12005: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 12006: my ($idxnum,$parent_name,$parent_item);
12007: my $higher = $depth - 1;
12008: if ($higher == 0) {
12009: $parent_name = &escape($parent).'::'.$higher;
12010: } else {
12011: if (ref($path) eq 'ARRAY') {
12012: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
12013: }
12014: }
12015: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 12016: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 12017: if ($j < $numchildren) {
1.48 raeburn 12018: $name = $cats->[$depth]{$parent}[$j];
12019: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 12020: $idxnum = $idx->{$item};
12021: } else {
12022: $name = $parent_name;
12023: $item = $parent_item;
1.48 raeburn 12024: }
1.49 raeburn 12025: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
12026: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 12027: for (my $i=0; $i<=$numchildren; $i++) {
12028: my $vpos = $i+1;
12029: my $selstr;
12030: if ($j == $i) {
12031: $selstr = ' selected="selected" ';
12032: }
12033: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
12034: }
12035: $text .= '</select> ';
12036: if ($j < $numchildren) {
12037: my $deeper = $depth+1;
12038: $text .= $name.' '
12039: .'<label><input type="checkbox" name="deletecategory" value="'
12040: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
12041: if(ref($path) eq 'ARRAY') {
12042: push(@{$path},$name);
1.49 raeburn 12043: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 12044: pop(@{$path});
12045: }
12046: } else {
1.330 raeburn 12047: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 12048: if ($j == $numchildren) {
12049: $text .= $name;
12050: } else {
12051: $text .= $item;
12052: }
12053: $text .= '" value="" />';
12054: }
12055: $text .= '</td></tr>';
12056: }
12057: $text .= '</table></td>';
12058: } else {
12059: my $higher = $depth-1;
12060: if ($higher == 0) {
12061: $name = &escape($parent).'::'.$higher;
12062: } else {
12063: if (ref($path) eq 'ARRAY') {
12064: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
12065: }
12066: }
12067: my $colspan;
12068: if ($parent ne 'instcode') {
12069: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 12070: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 12071: }
12072: }
12073: }
12074: }
12075: return $text;
12076: }
12077:
1.33 raeburn 12078: sub modifiable_userdata_row {
1.305 raeburn 12079: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357 raeburn 12080: $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228 raeburn 12081: my ($role,$rolename,$statustype);
12082: $role = $item;
1.224 raeburn 12083: if ($context eq 'cancreate') {
1.305 raeburn 12084: if ($item =~ /^(emailusername)_(.+)$/) {
12085: $role = $1;
12086: $statustype = $2;
1.228 raeburn 12087: if (ref($usertypes) eq 'HASH') {
12088: if ($usertypes->{$statustype}) {
12089: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
12090: } else {
12091: $rolename = &mt('Data provided by user');
12092: }
12093: }
1.224 raeburn 12094: }
12095: } elsif ($context eq 'selfcreate') {
1.63 raeburn 12096: if (ref($usertypes) eq 'HASH') {
12097: $rolename = $usertypes->{$role};
12098: } else {
12099: $rolename = $role;
12100: }
1.325 raeburn 12101: } elsif ($context eq 'lti') {
12102: $rolename = &mt('Institutional data used (if available)');
1.357 raeburn 12103: } elsif ($context eq 'privacy') {
12104: $rolename = $itemdesc;
1.33 raeburn 12105: } else {
1.63 raeburn 12106: if ($role eq 'cr') {
12107: $rolename = &mt('Custom role');
12108: } else {
12109: $rolename = &Apache::lonnet::plaintext($role);
12110: }
1.33 raeburn 12111: }
1.224 raeburn 12112: my (@fields,%fieldtitles);
12113: if (ref($fieldsref) eq 'ARRAY') {
12114: @fields = @{$fieldsref};
12115: } else {
12116: @fields = ('lastname','firstname','middlename','generation',
12117: 'permanentemail','id');
12118: }
12119: if ((ref($titlesref) eq 'HASH')) {
12120: %fieldtitles = %{$titlesref};
12121: } else {
12122: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12123: }
1.33 raeburn 12124: my $output;
1.305 raeburn 12125: my $css_class;
12126: if ($rowcount%2) {
12127: $css_class = 'LC_odd_row';
12128: }
12129: if ($customcss) {
12130: $css_class .= " $customcss";
12131: }
12132: $css_class =~ s/^\s+//;
12133: if ($css_class) {
12134: $css_class = ' class="'.$css_class.'"';
12135: }
12136: if ($rowstyle) {
12137: $css_class .= ' style="'.$rowstyle.'"';
12138: }
12139: if ($rowid) {
12140: $rowid = ' id="'.$rowid.'"';
12141: }
12142: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 12143: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
12144: '<td class="LC_left_item" colspan="2"><table>';
12145: my $rem;
12146: my %checks;
12147: if (ref($settings) eq 'HASH') {
1.325 raeburn 12148: my $hashref;
12149: if ($context eq 'lti') {
12150: if (ref($settings) eq 'HASH') {
12151: $hashref = $settings->{'instdata'};
12152: }
1.357 raeburn 12153: } elsif ($context eq 'privacy') {
12154: my ($key,$inner) = split(/_/,$role);
12155: if (ref($settings) eq 'HASH') {
12156: if (ref($settings->{$key}) eq 'HASH') {
12157: $hashref = $settings->{$key}->{$inner};
12158: }
12159: }
1.325 raeburn 12160: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 12161: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 12162: $hashref = $settings->{'lti_instdata'};
12163: }
12164: if ($role eq 'emailusername') {
12165: if ($statustype) {
12166: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
12167: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 12168: }
1.325 raeburn 12169: }
12170: }
12171: }
1.425 raeburn 12172: if (ref($hashref) eq 'HASH') {
1.325 raeburn 12173: foreach my $field (@fields) {
12174: if ($hashref->{$field}) {
12175: if ($role eq 'emailusername') {
12176: $checks{$field} = $hashref->{$field};
12177: } else {
12178: $checks{$field} = ' checked="checked" ';
1.33 raeburn 12179: }
12180: }
12181: }
12182: }
12183: }
1.305 raeburn 12184: my $total = scalar(@fields);
12185: for (my $i=0; $i<$total; $i++) {
12186: $rem = $i%($numinrow);
1.33 raeburn 12187: if ($rem == 0) {
12188: if ($i > 0) {
12189: $output .= '</tr>';
12190: }
12191: $output .= '<tr>';
12192: }
12193: my $check = ' ';
1.228 raeburn 12194: unless ($role eq 'emailusername') {
12195: if (exists($checks{$fields[$i]})) {
1.354 raeburn 12196: $check = $checks{$fields[$i]};
1.357 raeburn 12197: } elsif ($context eq 'privacy') {
12198: if ($role =~ /^priv_(domain|course)$/) {
12199: if (ref($settings) ne 'HASH') {
12200: $check = ' checked="checked" ';
12201: }
12202: } elsif ($role =~ /^priv_(author|community)$/) {
12203: if (ref($settings) ne 'HASH') {
12204: unless ($fields[$i] eq 'id') {
12205: $check = ' checked="checked" ';
12206: }
12207: }
12208: } elsif ($role =~ /^(unpriv|othdom)_/) {
12209: if (ref($settings) ne 'HASH') {
12210: if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
12211: $check = ' checked="checked" ';
12212: }
12213: }
12214: }
1.325 raeburn 12215: } elsif ($context ne 'lti') {
1.228 raeburn 12216: if ($role eq 'st') {
12217: if (ref($settings) ne 'HASH') {
12218: $check = ' checked="checked" ';
12219: }
1.33 raeburn 12220: }
12221: }
12222: }
12223: $output .= '<td class="LC_left_item">'.
1.228 raeburn 12224: '<span class="LC_nobreak">';
1.325 raeburn 12225: my $prefix = 'canmodify';
1.228 raeburn 12226: if ($role eq 'emailusername') {
12227: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
12228: $checks{$fields[$i]} = 'omit';
12229: }
12230: foreach my $option ('required','optional','omit') {
12231: my $checked='';
12232: if ($checks{$fields[$i]} eq $option) {
12233: $checked='checked="checked" ';
12234: }
12235: $output .= '<label>'.
1.325 raeburn 12236: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 12237: &mt($option).'</label>'.(' ' x2);
12238: }
12239: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
12240: } else {
1.325 raeburn 12241: if ($context eq 'lti') {
12242: $prefix = 'lti';
1.443 raeburn 12243: } elsif ($context eq 'coauthor') {
12244: $prefix = 'cacanmodify';
1.357 raeburn 12245: } elsif ($context eq 'privacy') {
12246: $prefix = 'privacy';
1.325 raeburn 12247: }
1.228 raeburn 12248: $output .= '<label>'.
1.325 raeburn 12249: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 12250: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
12251: '</label>';
12252: }
12253: $output .= '</span></td>';
1.33 raeburn 12254: }
1.305 raeburn 12255: $rem = $total%$numinrow;
12256: my $colsleft;
12257: if ($rem) {
12258: $colsleft = $numinrow - $rem;
12259: }
12260: if ($colsleft > 1) {
1.33 raeburn 12261: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
12262: ' </td>';
12263: } elsif ($colsleft == 1) {
12264: $output .= '<td class="LC_left_item"> </td>';
12265: }
12266: $output .= '</tr></table></td></tr>';
12267: return $output;
12268: }
1.28 raeburn 12269:
1.93 raeburn 12270: sub insttypes_row {
1.305 raeburn 12271: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
12272: $customcss,$rowstyle) = @_;
1.93 raeburn 12273: my %lt = &Apache::lonlocal::texthash (
1.429 raeburn 12274: cansearch => 'Users allowed to search',
1.93 raeburn 12275: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.429 raeburn 12276: lockablenames => 'User preference to lock name',
12277: selfassign => 'Self-reportable affiliations',
12278: overrides => "Override domain's helpdesk settings based on requester's affiliation",
12279: webdav => 'WebDAV access available',
12280: authorquota => 'Authoring Space quota (MB)',
1.93 raeburn 12281: );
1.429 raeburn 12282: my ($showdom,$defaultquota);
1.93 raeburn 12283: if ($context eq 'cansearch') {
12284: $showdom = ' ('.$dom.')';
1.429 raeburn 12285: } elsif ($context eq 'authorquota') {
12286: $defaultquota = 500;
1.93 raeburn 12287: }
1.165 raeburn 12288: my $class = 'LC_left_item';
12289: if ($context eq 'statustocreate') {
12290: $class = 'LC_right_item';
12291: }
1.305 raeburn 12292: my $css_class;
12293: if ($$rowtotal%2) {
12294: $css_class = 'LC_odd_row';
12295: }
12296: if ($customcss) {
12297: $css_class .= ' '.$customcss;
12298: }
12299: $css_class =~ s/^\s+//;
12300: if ($css_class) {
12301: $css_class = ' class="'.$css_class.'"';
12302: }
12303: if ($rowstyle) {
12304: $css_class .= ' style="'.$rowstyle.'"';
12305: }
12306: if ($onclick) {
12307: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 12308: }
12309: my $output = '<tr'.$css_class.'>'.
12310: '<td>'.$lt{$context}.$showdom.
12311: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 12312: my $rem;
12313: if (ref($types) eq 'ARRAY') {
12314: for (my $i=0; $i<@{$types}; $i++) {
12315: if (defined($usertypes->{$types->[$i]})) {
12316: my $rem = $i%($numinrow);
12317: if ($rem == 0) {
12318: if ($i > 0) {
12319: $output .= '</tr>';
12320: }
12321: $output .= '<tr>';
1.23 raeburn 12322: }
1.429 raeburn 12323: if ($context eq 'authorquota') {
12324: my $currquota;
12325: if ($settings->{$context}->{$types->[$i]} =~ /^\d+$/) {
12326: $currquota = $settings->{$context}->{$types->[$i]};
12327: } else {
12328: $currquota = $defaultquota;
12329: }
12330: $output .= '<td class="LC_left_item">'."\n".
12331: '<label><span class="LC_nobreak">'."\n".
12332: $usertypes->{$types->[$i]}.'</span><br />'."\n".
12333: '<input type="text" name="'.$context.'_'.$types->[$i].'" '.
12334: 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
12335: '</label></td>';
12336: } else {
12337: my $check = ' ';
12338: if (ref($settings) eq 'HASH') {
12339: if (ref($settings->{$context}) eq 'ARRAY') {
12340: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
12341: $check = ' checked="checked" ';
12342: }
12343: } elsif (ref($settings->{$context}) eq 'HASH') {
12344: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
12345: $check = ' checked="checked" ';
12346: } elsif ($context eq 'webdav') {
12347: if ($settings->{$context}->{$types->[$i]}) {
12348: $check = ' checked="checked" ';
12349: }
12350: }
12351: } elsif ($context eq 'statustocreate') {
1.315 raeburn 12352: $check = ' checked="checked" ';
12353: }
1.26 raeburn 12354: }
1.429 raeburn 12355: $output .= '<td class="LC_left_item">'.
12356: '<span class="LC_nobreak"><label>'.
12357: '<input type="checkbox" name="'.$context.'" '.
12358: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
12359: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 12360: }
12361: }
12362: }
1.26 raeburn 12363: $rem = @{$types}%($numinrow);
1.23 raeburn 12364: }
12365: my $colsleft = $numinrow - $rem;
1.315 raeburn 12366: if ($context eq 'overrides') {
12367: if ($colsleft > 1) {
12368: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12369: } else {
12370: $output .= '<td class="LC_left_item">';
12371: }
1.425 raeburn 12372: $output .= ' ';
1.23 raeburn 12373: } else {
1.334 raeburn 12374: if ($rem == 0) {
1.315 raeburn 12375: $output .= '<tr>';
12376: }
12377: if ($colsleft > 1) {
12378: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12379: } else {
12380: $output .= '<td class="LC_left_item">';
12381: }
1.429 raeburn 12382: if ($context eq 'authorquota') {
12383: my $currquota = 500;
12384: if ((ref($settings) eq 'HASH') && (ref($settings->{$context}) eq 'HASH')) {
12385: if ($settings->{$context}{'default'} =~ /^\d+$/) {
12386: $currquota = $settings->{$context}{'default'};
12387: }
12388: }
12389: $output .= '<label><span class="LC_nobreak">'.$othertitle.'</span><br />'."\n".
12390: '<input type="text" name="'.$context.'_default" '.
12391: 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
12392: '</label>';
12393: } else {
12394: my $defcheck = ' ';
12395: if (ref($settings) eq 'HASH') {
12396: if (ref($settings->{$context}) eq 'ARRAY') {
12397: if (grep(/^default$/,@{$settings->{$context}})) {
12398: $defcheck = ' checked="checked" ';
12399: }
12400: } elsif (ref($settings->{$context}) eq 'HASH') {
12401: if (ref($settings->{$context}->{'default'}) eq 'HASH') {
12402: $defcheck = ' checked="checked" ';
12403: } elsif ($context eq 'webdav') {
12404: if ($settings->{$context}->{'default'}) {
12405: $defcheck = ' checked="checked" ';
12406: }
12407: }
12408: } elsif ($context eq 'statustocreate') {
1.315 raeburn 12409: $defcheck = ' checked="checked" ';
12410: }
1.99 raeburn 12411: }
1.429 raeburn 12412: $output .= '<span class="LC_nobreak"><label>'.
12413: '<input type="checkbox" name="'.$context.'" '.
12414: 'value="default"'.$defcheck.$onclick.'/>'.
12415: $othertitle.'</label></span>';
1.26 raeburn 12416: }
1.23 raeburn 12417: }
1.315 raeburn 12418: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 12419: return $output;
1.23 raeburn 12420: }
12421:
12422: sub sorted_searchtitles {
12423: my %searchtitles = &Apache::lonlocal::texthash(
12424: 'uname' => 'username',
12425: 'lastname' => 'last name',
12426: 'lastfirst' => 'last name, first name',
12427: );
12428: my @titleorder = ('uname','lastname','lastfirst');
12429: return (\%searchtitles,\@titleorder);
12430: }
12431:
1.25 raeburn 12432: sub sorted_searchtypes {
12433: my %srchtypes_desc = (
12434: exact => 'is exact match',
12435: contains => 'contains ..',
12436: begins => 'begins with ..',
12437: );
12438: my @srchtypeorder = ('exact','begins','contains');
12439: return (\%srchtypes_desc,\@srchtypeorder);
12440: }
12441:
1.3 raeburn 12442: sub usertype_update_row {
12443: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
12444: my $datatable;
12445: my $numinrow = 4;
12446: foreach my $type (@{$types}) {
12447: if (defined($usertypes->{$type})) {
12448: $$rownums ++;
12449: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
12450: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
12451: '</td><td class="LC_left_item"><table>';
12452: for (my $i=0; $i<@{$fields}; $i++) {
12453: my $rem = $i%($numinrow);
12454: if ($rem == 0) {
12455: if ($i > 0) {
12456: $datatable .= '</tr>';
12457: }
12458: $datatable .= '<tr>';
12459: }
12460: my $check = ' ';
1.39 raeburn 12461: if (ref($settings) eq 'HASH') {
12462: if (ref($settings->{'fields'}) eq 'HASH') {
12463: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
12464: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
12465: $check = ' checked="checked" ';
12466: }
1.3 raeburn 12467: }
12468: }
12469: }
12470:
12471: if ($i == @{$fields}-1) {
12472: my $colsleft = $numinrow - $rem;
12473: if ($colsleft > 1) {
12474: $datatable .= '<td colspan="'.$colsleft.'">';
12475: } else {
12476: $datatable .= '<td>';
12477: }
12478: } else {
12479: $datatable .= '<td>';
12480: }
1.8 raeburn 12481: $datatable .= '<span class="LC_nobreak"><label>'.
12482: '<input type="checkbox" name="updateable_'.$type.
12483: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
12484: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 12485: }
12486: $datatable .= '</tr></table></td></tr>';
12487: }
12488: }
12489: return $datatable;
1.1 raeburn 12490: }
12491:
12492: sub modify_login {
1.205 raeburn 12493: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 12494: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.386 raeburn 12495: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
1.412 raeburn 12496: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso);
1.168 raeburn 12497: %title = ( coursecatalog => 'Display course catalog',
12498: adminmail => 'Display administrator E-mail address',
1.188 raeburn 12499: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 12500: newuser => 'Link for visitors to create a user account',
1.386 raeburn 12501: loginheader => 'Log-in box header',
12502: saml => 'Dual SSO and non-SSO login');
1.168 raeburn 12503: @offon = ('off','on');
1.112 raeburn 12504: if (ref($domconfig{login}) eq 'HASH') {
12505: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
12506: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
12507: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
12508: }
12509: }
1.386 raeburn 12510: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
12511: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
12512: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
12513: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
12514: $saml{$lonhost} = 1;
12515: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
12516: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
12517: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
12518: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
12519: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
1.412 raeburn 12520: $samlwindow{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'window'};
1.386 raeburn 12521: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
12522: }
12523: }
12524: }
1.112 raeburn 12525: }
1.9 raeburn 12526: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
12527: \%domconfig,\%loginhash);
1.188 raeburn 12528: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12529: foreach my $item (@toggles) {
12530: $loginhash{login}{$item} = $env{'form.'.$item};
12531: }
1.41 raeburn 12532: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 12533: if (ref($colchanges{'login'}) eq 'HASH') {
12534: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
12535: \%loginhash);
12536: }
1.110 raeburn 12537:
1.149 raeburn 12538: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 12539: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 12540: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 12541: if (keys(%servers) > 1) {
12542: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 12543: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
12544: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
12545: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
12546: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
12547: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
12548: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12549: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12550: $changes{'loginvia'}{$lonhost} = 1;
12551: } else {
12552: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
12553: $changes{'loginvia'}{$lonhost} = 1;
12554: }
12555: } else {
12556: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12557: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12558: $changes{'loginvia'}{$lonhost} = 1;
12559: }
12560: }
12561: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
12562: foreach my $item (@loginvia_attribs) {
12563: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
12564: }
12565: } else {
12566: foreach my $item (@loginvia_attribs) {
12567: my $new = $env{'form.'.$lonhost.'_'.$item};
12568: if (($item eq 'serverpath') && ($new eq 'custom')) {
12569: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
12570: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12571: $new = '/';
12572: }
12573: }
12574: if (($item eq 'custompath') &&
12575: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12576: $new = '';
12577: }
12578: if ($new ne $curr_loginvia{$lonhost}{$item}) {
12579: $changes{'loginvia'}{$lonhost} = 1;
12580: }
12581: if ($item eq 'exempt') {
1.256 raeburn 12582: $new = &check_exempt_addresses($new);
1.128 raeburn 12583: }
12584: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12585: }
12586: }
1.112 raeburn 12587: } else {
1.128 raeburn 12588: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12589: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 12590: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 12591: foreach my $item (@loginvia_attribs) {
12592: my $new = $env{'form.'.$lonhost.'_'.$item};
12593: if (($item eq 'serverpath') && ($new eq 'custom')) {
12594: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12595: $new = '/';
12596: }
12597: }
12598: if (($item eq 'custompath') &&
12599: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12600: $new = '';
12601: }
12602: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12603: }
1.110 raeburn 12604: }
12605: }
12606: }
12607: }
1.119 raeburn 12608:
1.168 raeburn 12609: my $servadm = $r->dir_config('lonAdmEMail');
12610: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
12611: if (ref($domconfig{'login'}) eq 'HASH') {
12612: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
12613: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
12614: if ($lang eq 'nolang') {
12615: push(@currlangs,$lang);
12616: } elsif (defined($langchoices{$lang})) {
12617: push(@currlangs,$lang);
12618: } else {
12619: next;
12620: }
12621: }
12622: }
12623: }
12624: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
12625: if (@currlangs > 0) {
12626: foreach my $lang (@currlangs) {
12627: if (grep(/^\Q$lang\E$/,@delurls)) {
12628: $changes{'helpurl'}{$lang} = 1;
12629: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
12630: $changes{'helpurl'}{$lang} = 1;
12631: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
12632: push(@newlangs,$lang);
12633: } else {
12634: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12635: }
12636: }
12637: }
12638: unless (grep(/^nolang$/,@currlangs)) {
12639: if ($env{'form.loginhelpurl_nolang.filename'}) {
12640: $changes{'helpurl'}{'nolang'} = 1;
12641: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
12642: push(@newlangs,'nolang');
12643: }
12644: }
12645: if ($env{'form.loginhelpurl_add_lang'}) {
12646: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
12647: ($env{'form.loginhelpurl_add_file.filename'})) {
12648: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
12649: $addedfile = $env{'form.loginhelpurl_add_lang'};
12650: }
12651: }
12652: if ((@newlangs > 0) || ($addedfile)) {
12653: my $error;
12654: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12655: if ($configuserok eq 'ok') {
12656: if ($switchserver) {
12657: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
12658: } elsif ($author_ok eq 'ok') {
12659: my @allnew = @newlangs;
12660: if ($addedfile ne '') {
12661: push(@allnew,$addedfile);
12662: }
1.421 raeburn 12663: my $modified = [];
1.168 raeburn 12664: foreach my $lang (@allnew) {
12665: my $formelem = 'loginhelpurl_'.$lang;
12666: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
12667: $formelem = 'loginhelpurl_add_file';
12668: }
1.425 raeburn 12669: (my $result,$newurl{$lang}) =
1.421 raeburn 12670: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12671: "help/$lang",'','',$newfile{$lang},
12672: $modified);
1.168 raeburn 12673: if ($result eq 'ok') {
12674: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
12675: $changes{'helpurl'}{$lang} = 1;
12676: } else {
12677: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
12678: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 12679: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 12680: (!grep(/^\Q$lang\E$/,@delurls))) {
12681: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12682: }
12683: }
12684: }
1.421 raeburn 12685: &update_modify_urls($r,$modified);
1.168 raeburn 12686: } else {
12687: $error = &mt("Upload of custom log-in help file(s) failed because an author role could not be assigned to a Domain Configuration user ([_1]) in domain: [_2]. Error was: [_3].",$confname,$dom,$author_ok);
12688: }
12689: } else {
12690: $error = &mt("Upload of custom log-in help file(s) failed because a Domain Configuration user ([_1]) could not be created in domain: [_2]. Error was: [_3].",$confname,$dom,$configuserok);
12691: }
12692: if ($error) {
12693: &Apache::lonnet::logthis($error);
12694: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12695: }
12696: }
1.256 raeburn 12697:
12698: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
12699: if (ref($domconfig{'login'}) eq 'HASH') {
12700: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
12701: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
12702: if ($domservers{$lonhost}) {
12703: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12704: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 12705: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 12706: }
12707: }
12708: }
12709: }
12710: }
12711: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
12712: foreach my $lonhost (sort(keys(%domservers))) {
12713: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12714: $changes{'headtag'}{$lonhost} = 1;
12715: } else {
12716: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
12717: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
12718: }
12719: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
12720: push(@newhosts,$lonhost);
12721: } elsif ($currheadtagurls{$lonhost}) {
12722: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
12723: if ($currexempt{$lonhost}) {
1.289 raeburn 12724: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 12725: $changes{'headtag'}{$lonhost} = 1;
12726: }
12727: } elsif ($possexempt{$lonhost}) {
12728: $changes{'headtag'}{$lonhost} = 1;
12729: }
12730: if ($possexempt{$lonhost}) {
12731: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12732: }
12733: }
12734: }
12735: }
12736: if (@newhosts) {
12737: my $error;
12738: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12739: if ($configuserok eq 'ok') {
12740: if ($switchserver) {
12741: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
12742: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12743: my $modified = [];
1.256 raeburn 12744: foreach my $lonhost (@newhosts) {
12745: my $formelem = 'loginheadtag_'.$lonhost;
1.425 raeburn 12746: (my $result,$newheadtagurls{$lonhost}) =
1.421 raeburn 12747: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12748: "login/headtag/$lonhost",'','',
12749: $env{'form.loginheadtag_'.$lonhost.'.filename'},
12750: $modified);
1.256 raeburn 12751: if ($result eq 'ok') {
12752: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
12753: $changes{'headtag'}{$lonhost} = 1;
12754: if ($possexempt{$lonhost}) {
12755: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12756: }
12757: } else {
12758: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
12759: $newheadtagurls{$lonhost},$result);
12760: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12761: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
12762: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
12763: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
12764: }
12765: }
12766: }
1.421 raeburn 12767: &update_modify_urls($r,$modified);
1.256 raeburn 12768: } else {
12769: $error = &mt("Upload of custom markup file(s) failed because an author role could not be assigned to a Domain Configuration user ([_1]) in domain: [_2]. Error was: [_3].",$confname,$dom,$author_ok);
12770: }
12771: } else {
12772: $error = &mt("Upload of custom markup file(s) failed because a Domain Configuration user ([_1]) could not be created in domain: [_2]. Error was: [_3].",$confname,$dom,$configuserok);
12773: }
12774: if ($error) {
12775: &Apache::lonnet::logthis($error);
12776: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12777: }
12778: }
1.386 raeburn 12779: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
12780: my @newsamlimgs;
12781: foreach my $lonhost (keys(%domservers)) {
12782: if ($env{'form.saml_'.$lonhost}) {
12783: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
12784: push(@newsamlimgs,$lonhost);
12785: }
1.412 raeburn 12786: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12787: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
12788: }
12789: if ($saml{$lonhost}) {
1.412 raeburn 12790: if ($env{'form.saml_window_'.$lonhost} ne '1') {
12791: $env{'form.saml_window_'.$lonhost} = '';
12792: }
1.386 raeburn 12793: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
12794: #FIXME Need to obsolete published image
12795: delete($currsaml{$lonhost}{'img'});
12796: $changes{'saml'}{$lonhost} = 1;
12797: }
12798: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
12799: $changes{'saml'}{$lonhost} = 1;
12800: }
12801: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
12802: $changes{'saml'}{$lonhost} = 1;
12803: }
12804: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
12805: $changes{'saml'}{$lonhost} = 1;
12806: }
12807: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
12808: $changes{'saml'}{$lonhost} = 1;
12809: }
1.412 raeburn 12810: if ($env{'form.saml_window_'.$lonhost} ne $samlwindow{$lonhost}) {
12811: $changes{'saml'}{$lonhost} = 1;
12812: }
1.386 raeburn 12813: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
12814: $changes{'saml'}{$lonhost} = 1;
12815: }
12816: } else {
12817: $changes{'saml'}{$lonhost} = 1;
12818: }
1.412 raeburn 12819: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12820: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
12821: }
12822: } else {
1.425 raeburn 12823: if ($saml{$lonhost}) {
1.389 raeburn 12824: $changes{'saml'}{$lonhost} = 1;
12825: delete($currsaml{$lonhost});
12826: }
1.386 raeburn 12827: }
12828: }
12829: foreach my $posshost (keys(%currsaml)) {
1.425 raeburn 12830: unless (exists($domservers{$posshost})) {
12831: delete($currsaml{$posshost});
1.386 raeburn 12832: }
12833: }
12834: %{$loginhash{'login'}{'saml'}} = %currsaml;
12835: if (@newsamlimgs) {
12836: my $error;
12837: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12838: if ($configuserok eq 'ok') {
12839: if ($switchserver) {
12840: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
12841: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12842: my $modified = [];
1.386 raeburn 12843: foreach my $lonhost (@newsamlimgs) {
12844: my $formelem = 'saml_img_'.$lonhost;
1.425 raeburn 12845: my ($result,$imgurl) =
1.421 raeburn 12846: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12847: "login/saml/$lonhost",'','',
12848: $env{'form.saml_img_'.$lonhost.'.filename'},
12849: $modified);
1.386 raeburn 12850: if ($result eq 'ok') {
12851: $currsaml{$lonhost}{'img'} = $imgurl;
12852: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
12853: $changes{'saml'}{$lonhost} = 1;
12854: } else {
12855: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
12856: $lonhost,$result);
12857: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12858: }
12859: }
1.421 raeburn 12860: &update_modify_urls($r,$modified);
1.386 raeburn 12861: } else {
12862: $error = &mt("Upload of SSO button image file(s) failed because an author role could not be assigned to a Domain Configuration user ([_1]) in domain: [_2]. Error was: [_3].",$confname,$dom,$author_ok);
12863: }
12864: } else {
12865: $error = &mt("Upload of SSO button image file(s) failed because a Domain Configuration user ([_1]) could not be created in domain: [_2]. Error was: [_3].",$confname,$dom,$configuserok);
12866: }
12867: if ($error) {
12868: &Apache::lonnet::logthis($error);
12869: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12870: }
12871: }
1.169 raeburn 12872: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 12873:
12874: my $defaulthelpfile = '/adm/loginproblems.html';
12875: my $defaulttext = &mt('Default in use');
12876:
1.1 raeburn 12877: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
12878: $dom);
12879: if ($putresult eq 'ok') {
1.188 raeburn 12880: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12881: my %defaultchecked = (
12882: 'coursecatalog' => 'on',
1.188 raeburn 12883: 'helpdesk' => 'on',
1.42 raeburn 12884: 'adminmail' => 'off',
1.43 raeburn 12885: 'newuser' => 'off',
1.42 raeburn 12886: );
1.55 raeburn 12887: if (ref($domconfig{'login'}) eq 'HASH') {
12888: foreach my $item (@toggles) {
12889: if ($defaultchecked{$item} eq 'on') {
12890: if (($domconfig{'login'}{$item} eq '0') &&
12891: ($env{'form.'.$item} eq '1')) {
12892: $changes{$item} = 1;
12893: } elsif (($domconfig{'login'}{$item} eq '' ||
12894: $domconfig{'login'}{$item} eq '1') &&
12895: ($env{'form.'.$item} eq '0')) {
12896: $changes{$item} = 1;
12897: }
12898: } elsif ($defaultchecked{$item} eq 'off') {
12899: if (($domconfig{'login'}{$item} eq '1') &&
12900: ($env{'form.'.$item} eq '0')) {
12901: $changes{$item} = 1;
12902: } elsif (($domconfig{'login'}{$item} eq '' ||
12903: $domconfig{'login'}{$item} eq '0') &&
12904: ($env{'form.'.$item} eq '1')) {
12905: $changes{$item} = 1;
12906: }
1.42 raeburn 12907: }
12908: }
1.41 raeburn 12909: }
1.6 raeburn 12910: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 12911: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.386 raeburn 12912: if (exists($changes{'saml'})) {
12913: my $hostid_in_use;
12914: my @hosts = &Apache::lonnet::current_machine_ids();
12915: if (@hosts > 1) {
12916: foreach my $hostid (@hosts) {
12917: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
12918: $hostid_in_use = $hostid;
12919: last;
12920: }
12921: }
12922: } else {
12923: $hostid_in_use = $r->dir_config('lonHostID');
12924: }
12925: if (($hostid_in_use) &&
12926: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
1.387 raeburn 12927: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
1.386 raeburn 12928: }
12929: if (ref($lastactref) eq 'HASH') {
12930: if (ref($changes{'saml'}) eq 'HASH') {
12931: my %updates;
12932: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
12933: $lastactref->{'samllanding'} = \%updates;
12934: }
12935: }
12936: }
1.212 raeburn 12937: if (ref($lastactref) eq 'HASH') {
12938: $lastactref->{'domainconfig'} = 1;
12939: }
1.1 raeburn 12940: $resulttext = &mt('Changes made:').'<ul>';
12941: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 12942: if ($item eq 'loginvia') {
1.112 raeburn 12943: if (ref($changes{$item}) eq 'HASH') {
12944: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
12945: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 12946: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
12947: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
12948: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
12949: $protocol = 'http' if ($protocol ne 'https');
12950: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
12951:
12952: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
12953: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
12954: } else {
12955: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
12956: }
12957: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
12958: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
12959: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
12960: }
12961: $resulttext .= '</li>';
12962: } else {
12963: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
12964: }
1.112 raeburn 12965: } else {
1.128 raeburn 12966: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 12967: }
12968: }
1.128 raeburn 12969: $resulttext .= '</ul></li>';
1.112 raeburn 12970: }
1.168 raeburn 12971: } elsif ($item eq 'helpurl') {
12972: if (ref($changes{$item}) eq 'HASH') {
12973: foreach my $lang (sort(keys(%{$changes{$item}}))) {
12974: if (grep(/^\Q$lang\E$/,@delurls)) {
12975: my ($chg,$link);
12976: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
12977: if ($lang eq 'nolang') {
12978: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
12979: } else {
12980: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
12981: }
12982: $resulttext .= '<li>'.$chg.'</li>';
12983: } else {
12984: my $chg;
12985: if ($lang eq 'nolang') {
12986: $chg = &mt('custom log-in help file for no preferred language');
12987: } else {
12988: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
12989: }
12990: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
12991: $loginhash{'login'}{'helpurl'}{$lang}.
12992: '?inhibitmenu=yes',$chg,600,500).
12993: '</li>';
12994: }
12995: }
12996: }
1.256 raeburn 12997: } elsif ($item eq 'headtag') {
12998: if (ref($changes{$item}) eq 'HASH') {
12999: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
13000: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
13001: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
13002: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
13003: $resulttext .= '<li><a href="'.
13004: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
13005: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
13006: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
13007: if ($possexempt{$lonhost}) {
13008: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
13009: } else {
13010: $resulttext .= &mt('included for any client IP');
13011: }
13012: $resulttext .= '</li>';
13013: }
13014: }
13015: }
1.386 raeburn 13016: } elsif ($item eq 'saml') {
13017: if (ref($changes{$item}) eq 'HASH') {
13018: my %notlt = (
13019: text => 'Text for log-in by SSO',
13020: img => 'SSO button image',
13021: alt => 'Alt text for button image',
13022: url => 'SSO URL',
13023: title => 'Tooltip for SSO link',
1.412 raeburn 13024: window => 'Pop-up window if iframe',
1.386 raeburn 13025: notsso => 'Text for non-SSO log-in',
13026: );
13027: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
13028: if (ref($currsaml{$lonhost}) eq 'HASH') {
13029: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
13030: '<ul>';
1.412 raeburn 13031: foreach my $key ('text','img','alt','url','title','window','notsso') {
1.386 raeburn 13032: if ($currsaml{$lonhost}{$key} eq '') {
13033: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
13034: } else {
13035: my $value = "'$currsaml{$lonhost}{$key}'";
13036: if ($key eq 'img') {
13037: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
1.412 raeburn 13038: } elsif ($key eq 'window') {
13039: $value = 'On';
1.386 raeburn 13040: }
13041: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
13042: $value).'</li>';
13043: }
13044: }
13045: $resulttext .= '</ul></li>';
13046: } else {
13047: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
13048: }
13049: }
13050: }
1.169 raeburn 13051: } elsif ($item eq 'captcha') {
13052: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 13053: my $chgtxt;
1.169 raeburn 13054: if ($loginhash{'login'}{$item} eq 'notused') {
13055: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
13056: } else {
13057: my %captchas = &captcha_phrases();
13058: if ($captchas{$loginhash{'login'}{$item}}) {
13059: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
13060: } else {
13061: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
13062: }
13063: }
13064: $resulttext .= '<li>'.$chgtxt.'</li>';
13065: }
13066: } elsif ($item eq 'recaptchakeys') {
13067: if (ref($loginhash{'login'}) eq 'HASH') {
13068: my ($privkey,$pubkey);
13069: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
13070: $pubkey = $loginhash{'login'}{$item}{'public'};
13071: $privkey = $loginhash{'login'}{$item}{'private'};
13072: }
13073: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
13074: if (!$pubkey) {
13075: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
13076: } else {
13077: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
13078: }
13079: if (!$privkey) {
13080: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
13081: } else {
1.251 raeburn 13082: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 13083: }
13084: $chgtxt .= '</ul>';
13085: $resulttext .= '<li>'.$chgtxt.'</li>';
13086: }
1.269 raeburn 13087: } elsif ($item eq 'recaptchaversion') {
13088: if (ref($loginhash{'login'}) eq 'HASH') {
13089: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 13090: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 13091: '</li>';
13092: }
13093: }
1.41 raeburn 13094: } else {
13095: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
13096: }
1.1 raeburn 13097: }
1.6 raeburn 13098: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 13099: } else {
13100: $resulttext = &mt('No changes made to log-in page settings');
13101: }
13102: } else {
1.11 albertel 13103: $resulttext = '<span class="LC_error">'.
13104: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 13105: }
1.6 raeburn 13106: if ($errors) {
1.9 raeburn 13107: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 13108: $errors.'</ul>';
13109: }
13110: return $resulttext;
13111: }
13112:
1.256 raeburn 13113: sub check_exempt_addresses {
13114: my ($iplist) = @_;
13115: $iplist =~ s/^\s+//;
13116: $iplist =~ s/\s+$//;
13117: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
13118: my (@okips,$new);
13119: foreach my $ip (@poss_ips) {
13120: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
13121: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
13122: push(@okips,$ip);
13123: }
13124: }
13125: }
13126: if (@okips > 0) {
13127: $new = join(',',@okips);
13128: } else {
13129: $new = '';
13130: }
13131: return $new;
13132: }
13133:
1.6 raeburn 13134: sub color_font_choices {
13135: my %choices =
13136: &Apache::lonlocal::texthash (
13137: img => "Header",
13138: bgs => "Background colors",
13139: links => "Link colors",
1.55 raeburn 13140: images => "Images",
1.6 raeburn 13141: font => "Font color",
1.201 raeburn 13142: fontmenu => "Font menu",
1.76 raeburn 13143: pgbg => "Page",
1.6 raeburn 13144: tabbg => "Header",
13145: sidebg => "Border",
13146: link => "Link",
13147: alink => "Active link",
13148: vlink => "Visited link",
13149: );
13150: return %choices;
13151: }
13152:
1.394 raeburn 13153: sub modify_ipaccess {
13154: my ($dom,$lastactref,%domconfig) = @_;
13155: my (@allpos,%changes,%confhash,$errors,$resulttext);
13156: my (@items,%deletions,%itemids,@warnings);
13157: my ($typeorder,$types) = &commblocktype_text();
13158: if ($env{'form.ipaccess_add'}) {
13159: my $name = $env{'form.ipaccess_name_add'};
13160: my ($newid,$error) = &get_ipaccess_id($dom,$name);
13161: if ($newid) {
13162: $itemids{'add'} = $newid;
13163: push(@items,'add');
13164: $changes{$newid} = 1;
13165: } else {
13166: $error = &mt('Failed to acquire unique ID for new IP access control item');
13167: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13168: }
13169: }
13170: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
13171: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
13172: if (@todelete) {
13173: map { $deletions{$_} = 1; } @todelete;
13174: }
13175: my $maxnum = $env{'form.ipaccess_maxnum'};
13176: for (my $i=0; $i<$maxnum; $i++) {
13177: my $itemid = $env{'form.ipaccess_id_'.$i};
13178: $itemid =~ s/\D+//g;
13179: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13180: if ($deletions{$itemid}) {
13181: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
13182: } else {
13183: push(@items,$i);
13184: $itemids{$i} = $itemid;
13185: }
13186: }
13187: }
13188: }
13189: foreach my $idx (@items) {
13190: my $itemid = $itemids{$idx};
13191: next unless ($itemid);
13192: my %current;
13193: unless ($idx eq 'add') {
13194: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13195: %current = %{$domconfig{'ipaccess'}{$itemid}};
13196: }
13197: }
13198: my $position = $env{'form.ipaccess_pos_'.$itemid};
13199: $position =~ s/\D+//g;
13200: if ($position ne '') {
13201: $allpos[$position] = $itemid;
13202: }
13203: my $name = $env{'form.ipaccess_name_'.$idx};
13204: $name =~ s/^\s+|\s+$//g;
13205: $confhash{$itemid}{'name'} = $name;
13206: my $possrange = $env{'form.ipaccess_range_'.$idx};
13207: $possrange =~ s/^\s+|\s+$//g;
13208: unless ($possrange eq '') {
13209: $possrange =~ s/[\r\n]+/\s/g;
13210: $possrange =~ s/\s*-\s*/-/g;
13211: $possrange =~ s/\s+/,/g;
13212: $possrange =~ s/,+/,/g;
13213: if ($possrange ne '') {
13214: my (@ok,$count);
1.425 raeburn 13215: $count = 0;
1.394 raeburn 13216: foreach my $poss (split(/\,/,$possrange)) {
13217: $count ++;
13218: $poss = &validate_ip_pattern($poss);
13219: if ($poss ne '') {
13220: push(@ok,$poss);
13221: }
13222: }
13223: my $diff = $count - scalar(@ok);
13224: if ($diff) {
13225: $errors .= '<li><span class="LC_error">'.
13226: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
13227: $diff,$name).
13228: '</span></li>';
13229: }
13230: if (@ok) {
13231: my @cidr_list;
13232: foreach my $item (@ok) {
13233: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
13234: }
13235: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
13236: }
13237: }
13238: }
13239: foreach my $field ('name','ip') {
13240: unless (($idx eq 'add') || ($changes{$itemid})) {
13241: if ($current{$field} ne $confhash{$itemid}{$field}) {
13242: $changes{$itemid} = 1;
13243: last;
13244: }
13245: }
13246: }
13247: $confhash{$itemid}{'commblocks'} = {};
1.425 raeburn 13248:
1.394 raeburn 13249: my %commblocks;
1.425 raeburn 13250: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
1.394 raeburn 13251: foreach my $type (@{$typeorder}) {
13252: if ($commblocks{$type}) {
13253: $confhash{$itemid}{'commblocks'}{$type} = 'on';
13254: }
13255: unless (($idx eq 'add') || ($changes{$itemid})) {
13256: if (ref($current{'commblocks'}) eq 'HASH') {
13257: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
13258: $changes{$itemid} = 1;
13259: }
13260: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
13261: $changes{$itemid} = 1;
13262: }
13263: }
13264: }
13265: $confhash{$itemid}{'courses'} = {};
13266: my %crsdeletions;
13267: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
13268: if (@delcrs) {
13269: map { $crsdeletions{$_} = 1; } @delcrs;
13270: }
13271: if (ref($current{'courses'}) eq 'HASH') {
13272: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
13273: if ($crsdeletions{$cid}) {
13274: $changes{$itemid} = 1;
13275: } else {
13276: $confhash{$itemid}{'courses'}{$cid} = 1;
13277: }
13278: }
13279: }
13280: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
13281: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
1.425 raeburn 13282: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
1.394 raeburn 13283: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
13284: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
13285: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
13286: $errors .= '<li><span class="LC_error">'.
13287: &mt('Invalid courseID [_1] omitted from list of allowed courses',
13288: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
13289: '</span></li>';
13290: } else {
13291: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
13292: $changes{$itemid} = 1;
13293: }
13294: }
13295: }
13296: if (@allpos > 0) {
13297: my $idx = 0;
13298: foreach my $itemid (@allpos) {
13299: if ($itemid ne '') {
13300: $confhash{$itemid}{'order'} = $idx;
13301: unless ($changes{$itemid}) {
13302: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
13303: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13304: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
13305: $changes{$itemid} = 1;
13306: }
13307: }
13308: }
13309: }
13310: $idx ++;
13311: }
13312: }
13313: }
13314: if (keys(%changes)) {
13315: my %defaultshash = (
13316: ipaccess => \%confhash,
13317: );
13318: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13319: $dom);
13320: if ($putresult eq 'ok') {
13321: my $cachetime = 1800;
13322: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
13323: if (ref($lastactref) eq 'HASH') {
13324: $lastactref->{'ipaccess'} = 1;
13325: }
13326: $resulttext = &mt('Changes made:').'<ul>';
13327: my %bynum;
13328: foreach my $itemid (sort(keys(%changes))) {
13329: if (ref($confhash{$itemid}) eq 'HASH') {
13330: my $position = $confhash{$itemid}{'order'};
13331: if ($position =~ /^\d+$/) {
13332: $bynum{$position} = $itemid;
13333: }
13334: }
13335: }
13336: if (keys(%deletions)) {
13337: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
13338: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
13339: }
13340: }
13341: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
13342: my $itemid = $bynum{$pos};
13343: if (ref($confhash{$itemid}) eq 'HASH') {
13344: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
13345: my $position = $pos + 1;
13346: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
13347: if ($confhash{$itemid}{'ip'} eq '') {
13348: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
13349: } else {
13350: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
13351: }
13352: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
13353: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
13354: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
13355: '</li>';
13356: } else {
13357: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
13358: }
13359: if (keys(%{$confhash{$itemid}{'courses'}})) {
13360: my @courses;
13361: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
1.425 raeburn 13362: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1.394 raeburn 13363: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
13364: }
13365: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
13366: join('</li><li>',@courses).'</li></ul>';
13367: } else {
13368: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
13369: }
1.395 raeburn 13370: $resulttext .= '</ul></li>';
1.394 raeburn 13371: }
13372: }
1.395 raeburn 13373: $resulttext .= '</ul>';
1.394 raeburn 13374: } else {
13375: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13376: }
13377: } else {
13378: $resulttext = &mt('No changes made');
13379: }
13380: if ($errors) {
13381: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
13382: $errors.'</ul></p>';
13383: }
13384: return $resulttext;
13385: }
13386:
13387: sub get_ipaccess_id {
13388: my ($domain,$location) = @_;
13389: # get lock on ipaccess db
13390: my $lockhash = {
13391: lock => $env{'user.name'}.
13392: ':'.$env{'user.domain'},
13393: };
13394: my $tries = 0;
13395: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13396: my ($id,$error);
13397:
13398: while (($gotlock ne 'ok') && ($tries<10)) {
13399: $tries ++;
13400: sleep (0.1);
13401: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13402: }
13403: if ($gotlock eq 'ok') {
13404: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
13405: if ($currids{'lock'}) {
13406: delete($currids{'lock'});
13407: if (keys(%currids)) {
13408: my @curr = sort { $a <=> $b } keys(%currids);
13409: if ($curr[-1] =~ /^\d+$/) {
13410: $id = 1 + $curr[-1];
13411: }
13412: } else {
13413: $id = 1;
13414: }
13415: if ($id) {
13416: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
13417: $error = 'nostore';
13418: }
13419: } else {
13420: $error = 'nonumber';
13421: }
13422: }
13423: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
13424: } else {
13425: $error = 'nolock';
13426: }
13427: return ($id,$error);
13428: }
13429:
1.429 raeburn 13430: sub modify_authordefaults {
13431: my ($dom,$lastactref,%domconfig) = @_;
13432: #
13433: # Retrieve current domain configuration for webDAV and Authoring Space quotas from $domconfig{'quotas'}.
13434: #
13435: my (%curr_quotas,%save_quotas,%confhash,%changes,%newvalues);
13436: if (ref($domconfig{'quotas'}) eq 'HASH') {
13437: foreach my $key (keys(%{$domconfig{'quotas'}})) {
13438: if ($key =~ /^webdav|authorquota$/) {
13439: $curr_quotas{$key} = $domconfig{'quotas'}{$key};
13440: } else {
13441: $save_quotas{$key} = $domconfig{'quotas'}{$key};
13442: }
13443: }
13444: }
13445: my %staticdefaults = (
13446: 'copyright' => 'default',
13447: 'sourceavail' => 'closed',
13448: 'nocodemirror' => 'off',
1.437 raeburn 13449: 'daxecollapse' => 'off',
1.429 raeburn 13450: 'domcoordacc' => 'on',
1.439 raeburn 13451: 'editors' => ['edit','xml'],
1.429 raeburn 13452: 'authorquota' => 500,
13453: 'webdav' => 0,
1.440 raeburn 13454: 'archive' => 'off',
1.429 raeburn 13455: );
13456: my %titles = &authordefaults_titles();
1.440 raeburn 13457: foreach my $item ('nocodemirror','daxecollapse','domcoordacc','archive') {
1.429 raeburn 13458: if ($env{'form.'.$item} =~ /^(0|1)$/) {
13459: $confhash{$item} = $env{'form.'.$item};
13460: }
13461: }
13462: if ($env{'form.copyright'} =~ /^(default|domain|public)$/) {
13463: $confhash{'copyright'} = $1;
13464: }
13465: if ($env{'form.sourceavail'} =~ /^(closed|open)$/) {
13466: $confhash{'sourceavail'} = $1;
13467: }
13468: my @posseditors = &Apache::loncommon::get_env_multiple('form.author_editors');
13469: my @okeditors = ('edit','xml','daxe');
13470: my @editors;
13471: foreach my $item (@posseditors) {
13472: if (grep(/^\Q$item\E$/,@okeditors)) {
13473: push(@editors,$item);
13474: }
13475: }
13476: $confhash{'editors'} = \@editors;
1.436 raeburn 13477:
1.429 raeburn 13478: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13479: my @insttypes;
13480: if (ref($types) eq 'ARRAY') {
13481: @insttypes = @{$types};
13482: }
13483: my @webdavon = &Apache::loncommon::get_env_multiple('form.webdav');
13484: my %webdav;
13485: map { $webdav{$_} = 1; } @webdavon;
13486: foreach my $type (@insttypes,'default') {
13487: my $possquota = $env{'form.authorquota_'.$type};
13488: if ($possquota =~ /^\d+$/) {
13489: $save_quotas{'authorquota'}{$type} = $possquota;
13490: }
13491: if ($webdav{$type}) {
13492: $save_quotas{'webdav'}{$type} = 1;
13493: } else {
13494: $save_quotas{'webdav'}{$type} = 0;
13495: }
13496: }
13497: if ($env{'form.webdav_LC_adv'} =~ /^(0|1)$/) {
13498: $save_quotas{'webdav'}{'_LC_adv'} = $env{'form.webdav_LC_adv'};
13499: }
13500: if (ref($domconfig{'authordefaults'}) eq 'HASH') {
1.440 raeburn 13501: foreach my $item ('nocodemirror','daxecollapse','domcoordacc','copyright','sourceavail','archive') {
1.429 raeburn 13502: if ($domconfig{'authordefaults'}{$item} ne $confhash{$item}) {
13503: $changes{$item} = 1;
13504: }
13505: }
13506: if (ref($domconfig{'authordefaults'}{'editors'}) eq 'ARRAY') {
1.436 raeburn 13507: my @diffs =
1.429 raeburn 13508: &Apache::loncommon::compare_arrays($confhash{'editors'},
13509: $domconfig{'authordefaults'}{'editors'});
13510: unless (@diffs == 0) {
13511: $changes{'editors'} = 1;
13512: }
13513: } else {
13514: my @diffs =
13515: &Apache::loncommon::compare_arrays($confhash{'editors'},
13516: $staticdefaults{'editors'});
13517: unless (@diffs == 0) {
13518: $changes{'editors'} = 1;
13519: }
13520: }
13521: } else {
13522: my @offon = ('off','on');
1.440 raeburn 13523: foreach my $item ('nocodemirror','daxecollapse','domcoordacc','archive') {
1.436 raeburn 13524: if ($offon[$confhash{$item}] ne $staticdefaults{$item}) {
1.429 raeburn 13525: $changes{$item} = 1;
13526: }
13527: }
13528: foreach my $item ('copyright','sourceavail') {
13529: if ($confhash{$item} ne $staticdefaults{$item}) {
13530: $changes{$item} = 1;
13531: }
13532: }
1.439 raeburn 13533: my @diffs =
13534: &Apache::loncommon::compare_arrays($confhash{'editors'},
13535: $staticdefaults{'editors'});
13536: unless (@diffs == 0) {
13537: $changes{'editors'} = 1;
13538: }
1.429 raeburn 13539: }
13540: foreach my $key ('authorquota','webdav') {
13541: if (ref($curr_quotas{$key}) eq 'HASH') {
13542: foreach my $type (@insttypes,'default') {
13543: if (exists($save_quotas{$key}{$type})) {
13544: if ($save_quotas{$key}{$type} ne $curr_quotas{$key}{$type}) {
13545: $changes{$key}{$type} = 1;
13546: }
13547: } elsif (exists($curr_quotas{$key}{$type})) {
13548: $save_quotas{$key}{$type} = $curr_quotas{$key}{$type};
13549: } else {
13550: $save_quotas{$key}{$type} = $staticdefaults{$key};
13551: }
13552: }
13553: } else {
13554: foreach my $type (@insttypes,'default') {
13555: if (exists($save_quotas{$key}{$type})) {
13556: unless ($save_quotas{$key}{$type} eq $staticdefaults{$key}) {
13557: $changes{$key}{$type} = 1;
13558: }
13559: } else {
13560: $save_quotas{$key}{$type} = $staticdefaults{$key};
13561: }
13562: }
13563: }
13564: }
13565: if (ref($curr_quotas{'webdav'}) eq 'HASH') {
13566: if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
1.436 raeburn 13567: if ($save_quotas{'webdav'}{'_LC_adv'} ne $curr_quotas{'webdav'}{'_LC_adv'}) {
1.429 raeburn 13568: $changes{'webdav_LC_adv'} = 1;
13569: }
13570: } elsif (exists($curr_quotas{'webdav'}{'_LC_adv'})) {
13571: $changes{'webdav_LC_adv'} = 1;
13572: }
13573: } elsif (exists($save_quotas{'webdav'}{'_LC_adv'})) {
13574: $changes{'webdav_LC_adv'} = 1;
13575: }
13576: my %confighash = (
13577: quotas => \%save_quotas,
13578: authordefaults => \%confhash,
13579: );
13580: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,
13581: $dom);
13582: my $resulttext;
13583: if ($putresult eq 'ok') {
13584: if (keys(%changes)) {
1.431 raeburn 13585: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.429 raeburn 13586: if ((exists($changes{'authorquota'})) || (exists($changes{'webdav'})) ||
1.436 raeburn 13587: ($changes{'webdav_LC_adv'})) {
1.429 raeburn 13588: if ((exists($changes{'authorquota'})) && (ref($save_quotas{'authorquota'}) eq 'HASH')) {
13589: $domdefaults{'authorquota'} = $save_quotas{'authorquota'};
13590: }
13591: if (((exists($changes{'webdav'})) || ($changes{'webdav_LC_adv'})) &&
13592: (ref($save_quotas{'webdav'}) eq 'HASH')) {
13593: $domdefaults{'webdav'} = $save_quotas{'webdav'};
13594: }
13595: }
13596: $resulttext = &mt('Changes made:').'<ul>';
13597: my $authoroverride;
1.437 raeburn 13598: foreach my $key ('nocodemirror','daxecollapse','domcoordacc','copyright','sourceavail') {
1.429 raeburn 13599: if (exists($changes{$key})) {
1.431 raeburn 13600: $domdefaults{$key} = $confhash{$key};
1.429 raeburn 13601: my $shown;
13602: unless ($authoroverride) {
13603: $resulttext .= '<li>'.&mt('Defaults which can be overridden by Author').'<ul>';
13604: $authoroverride = 1;
13605: }
1.437 raeburn 13606: if (($key eq 'nocodemirror') || ($key eq 'daxecollapse') || ($key eq 'domcoordacc')) {
1.429 raeburn 13607: $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
13608: } elsif ($key eq 'copyright') {
13609: $shown = &Apache::loncommon::copyrightdescription($confhash{$key});
13610: } elsif ($key eq 'sourceavail') {
13611: $shown = &Apache::loncommon::source_copyrightdescription($confhash{$key});
13612: }
1.436 raeburn 13613: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
1.429 raeburn 13614: }
13615: }
13616: if ($authoroverride) {
13617: $resulttext .= '</ul></li>';
13618: }
13619: my $domcoordoverride;
1.440 raeburn 13620: foreach my $key ('editors','authorquota','webdav','webdav_LC_adv','archive') {
1.429 raeburn 13621: if (exists($changes{$key})) {
13622: my $shown;
13623: unless ($domcoordoverride) {
13624: $resulttext .= '<li>'.&mt('Defaults which can be overridden by a Domain Coodinator').'<ul>';
13625: $domcoordoverride = 1;
13626: }
13627: if ($key eq 'editors') {
1.431 raeburn 13628: if (ref($confhash{'editors'}) eq 'ARRAY') {
13629: $domdefaults{'editors'} = join(',',@{$confhash{'editors'}});
13630: if (@{$confhash{'editors'}}) {
13631: $shown = join(', ', map { $titles{$_} } @{$confhash{'editors'}});
13632: } else {
13633: $shown = &mt('None');
13634: }
1.429 raeburn 13635: }
13636: } elsif ($key eq 'authorquota') {
13637: foreach my $type (@insttypes) {
13638: $shown .= $usertypes->{$type}.' -- '.$save_quotas{$key}{$type}.', ';
13639: }
13640: $shown .= $othertitle.' -- '.$save_quotas{$key}{'default'};
13641: } elsif ($key eq 'webdav') {
13642: foreach my $type (@insttypes) {
13643: $shown .= $usertypes->{$type}.' -- '. ($save_quotas{$key}{$type} ? &mt('Yes') : &mt('No')).', ';
13644: }
13645: $shown .= $othertitle.' -- '. ($save_quotas{$key}{'default'} ? &mt('Yes') : &mt('No'));
13646: } elsif ($key eq 'webdav_LC_adv') {
13647: if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
13648: $shown = ($save_quotas{'webdav'}{'_LC_adv'} ? $titles{'overon'} : $titles{'overoff'});
13649: } else {
13650: $shown = $titles{'none'};
13651: }
1.440 raeburn 13652: } elsif ($key eq 'archive') {
1.441 raeburn 13653: $domdefaults{$key} = $confhash{$key};
1.440 raeburn 13654: $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
1.429 raeburn 13655: }
13656: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
1.436 raeburn 13657: }
1.429 raeburn 13658: }
13659: if ($domcoordoverride) {
13660: $resulttext .= '</ul></li>';
13661: }
1.439 raeburn 13662: $resulttext .= '</ul>';
1.431 raeburn 13663: my $cachetime = 24*60*60;
13664: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13665: if (ref($lastactref) eq 'HASH') {
13666: $lastactref->{'domdefaults'} = 1;
13667: }
1.429 raeburn 13668: } else {
13669: $resulttext = &mt('No changes made to Authoring Space defaults');
13670: }
13671: }
13672: return $resulttext;
13673: }
13674:
1.6 raeburn 13675: sub modify_rolecolors {
1.205 raeburn 13676: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 13677: my ($resulttext,%rolehash);
13678: $rolehash{'rolecolors'} = {};
1.55 raeburn 13679: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
13680: if ($domconfig{'rolecolors'} eq '') {
13681: $domconfig{'rolecolors'} = {};
13682: }
13683: }
1.9 raeburn 13684: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 13685: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
13686: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
13687: $dom);
13688: if ($putresult eq 'ok') {
13689: if (keys(%changes) > 0) {
1.41 raeburn 13690: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 13691: if (ref($lastactref) eq 'HASH') {
13692: $lastactref->{'domainconfig'} = 1;
13693: }
1.6 raeburn 13694: $resulttext = &display_colorchgs($dom,\%changes,$roles,
13695: $rolehash{'rolecolors'});
13696: } else {
13697: $resulttext = &mt('No changes made to default color schemes');
13698: }
13699: } else {
1.11 albertel 13700: $resulttext = '<span class="LC_error">'.
13701: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 13702: }
13703: if ($errors) {
13704: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
13705: $errors.'</ul>';
13706: }
13707: return $resulttext;
13708: }
13709:
13710: sub modify_colors {
1.9 raeburn 13711: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 13712: my (%changes,%choices);
1.51 raeburn 13713: my @bgs;
1.6 raeburn 13714: my @links = ('link','alink','vlink');
1.41 raeburn 13715: my @logintext;
1.6 raeburn 13716: my @images;
13717: my $servadm = $r->dir_config('lonAdmEMail');
13718: my $errors;
1.200 raeburn 13719: my %defaults;
1.6 raeburn 13720: foreach my $role (@{$roles}) {
13721: if ($role eq 'login') {
1.12 raeburn 13722: %choices = &login_choices();
1.41 raeburn 13723: @logintext = ('textcol','bgcol');
1.12 raeburn 13724: } else {
13725: %choices = &color_font_choices();
13726: }
13727: if ($role eq 'login') {
1.41 raeburn 13728: @images = ('img','logo','domlogo','login');
1.51 raeburn 13729: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 13730: } else {
13731: @images = ('img');
1.200 raeburn 13732: @bgs = ('pgbg','tabbg','sidebg');
13733: }
13734: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
1.444 ! raeburn 13735: $env{'form.'.$role.'_font'} = lc($env{'form.'.$role.'_font'});
! 13736: if ($env{'form.'.$role.'_font'} =~ /^\w+/) {
! 13737: $env{'form.'.$role.'_font'} = '#'.$env{'form.'.$role.'_font'};
! 13738: }
! 13739: unless ($env{'form.'.$role.'_font'} eq lc($defaults{'font'})) {
1.200 raeburn 13740: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
13741: }
13742: if ($role eq 'login') {
13743: foreach my $item (@logintext) {
1.234 raeburn 13744: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13745: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13746: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13747: }
13748: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 13749: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13750: }
13751: }
13752: } else {
1.234 raeburn 13753: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
13754: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
13755: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
13756: }
13757: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 13758: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
13759: }
1.6 raeburn 13760: }
1.200 raeburn 13761: foreach my $item (@bgs) {
1.234 raeburn 13762: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13763: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13764: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13765: }
13766: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 13767: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13768: }
13769: }
13770: foreach my $item (@links) {
1.234 raeburn 13771: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13772: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13773: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13774: }
13775: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 13776: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13777: }
1.6 raeburn 13778: }
1.46 raeburn 13779: my ($configuserok,$author_ok,$switchserver) =
13780: &config_check($dom,$confname,$servadm);
1.9 raeburn 13781: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 13782: if (ref($domconfig->{$role}) ne 'HASH') {
13783: $domconfig->{$role} = {};
13784: }
1.8 raeburn 13785: foreach my $img (@images) {
1.402 raeburn 13786: if ($role eq 'login') {
13787: if (($img eq 'img') || ($img eq 'logo')) {
13788: if (defined($env{'form.login_showlogo_'.$img})) {
13789: $confhash->{$role}{'showlogo'}{$img} = 1;
13790: } else {
13791: $confhash->{$role}{'showlogo'}{$img} = 0;
13792: }
13793: }
13794: if ($env{'form.login_alt_'.$img} ne '') {
13795: $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
1.70 raeburn 13796: }
1.402 raeburn 13797: }
1.18 albertel 13798: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
13799: && !defined($domconfig->{$role}{$img})
13800: && !$env{'form.'.$role.'_del_'.$img}
13801: && $env{'form.'.$role.'_import_'.$img}) {
13802: # import the old configured image from the .tab setting
13803: # if they haven't provided a new one
13804: $domconfig->{$role}{$img} =
13805: $env{'form.'.$role.'_import_'.$img};
13806: }
1.6 raeburn 13807: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 13808: my $error;
1.6 raeburn 13809: if ($configuserok eq 'ok') {
1.9 raeburn 13810: if ($switchserver) {
1.12 raeburn 13811: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 13812: } else {
13813: if ($author_ok eq 'ok') {
1.421 raeburn 13814: my $modified = [];
1.9 raeburn 13815: my ($result,$logourl) =
1.421 raeburn 13816: &Apache::lonconfigsettings::publishlogo($r,'upload',$role.'_'.$img,
13817: $dom,$confname,$img,$width,$height,
13818: '',$modified);
1.9 raeburn 13819: if ($result eq 'ok') {
13820: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 13821: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13822: &update_modify_urls($r,$modified);
1.9 raeburn 13823: } else {
1.12 raeburn 13824: $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 13825: }
13826: } else {
1.46 raeburn 13827: $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 13828: }
13829: }
13830: } else {
1.46 raeburn 13831: $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 13832: }
13833: if ($error) {
1.8 raeburn 13834: &Apache::lonnet::logthis($error);
1.11 albertel 13835: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 13836: }
13837: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 13838: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
13839: my $error;
13840: if ($configuserok eq 'ok') {
13841: # is confname an author?
13842: if ($switchserver eq '') {
13843: if ($author_ok eq 'ok') {
1.421 raeburn 13844: my $modified = [];
1.9 raeburn 13845: my ($result,$logourl) =
1.421 raeburn 13846: &Apache::lonconfigsettings::publishlogo($r,'copy',$domconfig->{$role}{$img},
13847: $dom,$confname,$img,$width,$height,
13848: '',$modified);
1.9 raeburn 13849: if ($result eq 'ok') {
13850: $confhash->{$role}{$img} = $logourl;
1.18 albertel 13851: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13852: &update_modify_urls($r,$modified);
1.9 raeburn 13853: }
13854: }
13855: }
13856: }
1.6 raeburn 13857: }
13858: }
13859: }
13860: if (ref($domconfig) eq 'HASH') {
13861: if (ref($domconfig->{$role}) eq 'HASH') {
13862: foreach my $img (@images) {
13863: if ($domconfig->{$role}{$img} ne '') {
13864: if ($env{'form.'.$role.'_del_'.$img}) {
13865: $confhash->{$role}{$img} = '';
1.12 raeburn 13866: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13867: } else {
1.9 raeburn 13868: if ($confhash->{$role}{$img} eq '') {
13869: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
13870: }
1.6 raeburn 13871: }
13872: } else {
13873: if ($env{'form.'.$role.'_del_'.$img}) {
13874: $confhash->{$role}{$img} = '';
1.12 raeburn 13875: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13876: }
13877: }
1.402 raeburn 13878: if ($role eq 'login') {
13879: if (($img eq 'logo') || ($img eq 'img')) {
13880: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
13881: if ($confhash->{$role}{'showlogo'}{$img} ne
13882: $domconfig->{$role}{'showlogo'}{$img}) {
13883: $changes{$role}{'showlogo'}{$img} = 1;
13884: }
13885: } else {
13886: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13887: $changes{$role}{'showlogo'}{$img} = 1;
13888: }
1.70 raeburn 13889: }
1.402 raeburn 13890: }
13891: if ($img ne 'login') {
13892: if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
13893: if ($confhash->{$role}{'alttext'}{$img} ne
13894: $domconfig->{$role}{'alttext'}{$img}) {
13895: $changes{$role}{'alttext'}{$img} = 1;
13896: }
13897: } else {
13898: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13899: $changes{$role}{'alttext'}{$img} = 1;
13900: }
1.70 raeburn 13901: }
13902: }
13903: }
13904: }
1.6 raeburn 13905: if ($domconfig->{$role}{'font'} ne '') {
13906: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
13907: $changes{$role}{'font'} = 1;
13908: }
13909: } else {
13910: if ($confhash->{$role}{'font'}) {
13911: $changes{$role}{'font'} = 1;
13912: }
13913: }
1.107 raeburn 13914: if ($role ne 'login') {
13915: if ($domconfig->{$role}{'fontmenu'} ne '') {
13916: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
13917: $changes{$role}{'fontmenu'} = 1;
13918: }
13919: } else {
13920: if ($confhash->{$role}{'fontmenu'}) {
13921: $changes{$role}{'fontmenu'} = 1;
13922: }
1.97 tempelho 13923: }
13924: }
1.6 raeburn 13925: foreach my $item (@bgs) {
13926: if ($domconfig->{$role}{$item} ne '') {
13927: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13928: $changes{$role}{'bgs'}{$item} = 1;
13929: }
13930: } else {
13931: if ($confhash->{$role}{$item}) {
13932: $changes{$role}{'bgs'}{$item} = 1;
13933: }
13934: }
13935: }
13936: foreach my $item (@links) {
13937: if ($domconfig->{$role}{$item} ne '') {
13938: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13939: $changes{$role}{'links'}{$item} = 1;
13940: }
13941: } else {
13942: if ($confhash->{$role}{$item}) {
13943: $changes{$role}{'links'}{$item} = 1;
13944: }
13945: }
13946: }
1.41 raeburn 13947: foreach my $item (@logintext) {
13948: if ($domconfig->{$role}{$item} ne '') {
13949: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13950: $changes{$role}{'logintext'}{$item} = 1;
13951: }
13952: } else {
13953: if ($confhash->{$role}{$item}) {
13954: $changes{$role}{'logintext'}{$item} = 1;
13955: }
13956: }
13957: }
1.6 raeburn 13958: } else {
13959: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13960: \@logintext,$confhash,\%changes);
1.6 raeburn 13961: }
13962: } else {
13963: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13964: \@logintext,$confhash,\%changes);
1.6 raeburn 13965: }
13966: }
13967: return ($errors,%changes);
13968: }
13969:
1.46 raeburn 13970: sub config_check {
13971: my ($dom,$confname,$servadm) = @_;
13972: my ($configuserok,$author_ok,$switchserver,%currroles);
13973: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
13974: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
13975: $confname,$servadm);
13976: if ($configuserok eq 'ok') {
13977: $switchserver = &check_switchserver($dom,$confname);
13978: if ($switchserver eq '') {
13979: $author_ok = &check_authorstatus($dom,$confname,%currroles);
13980: }
13981: }
13982: return ($configuserok,$author_ok,$switchserver);
13983: }
13984:
1.6 raeburn 13985: sub default_change_checker {
1.41 raeburn 13986: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 13987: foreach my $item (@{$links}) {
13988: if ($confhash->{$role}{$item}) {
13989: $changes->{$role}{'links'}{$item} = 1;
13990: }
13991: }
13992: foreach my $item (@{$bgs}) {
13993: if ($confhash->{$role}{$item}) {
13994: $changes->{$role}{'bgs'}{$item} = 1;
13995: }
13996: }
1.41 raeburn 13997: foreach my $item (@{$logintext}) {
13998: if ($confhash->{$role}{$item}) {
13999: $changes->{$role}{'logintext'}{$item} = 1;
14000: }
14001: }
1.6 raeburn 14002: foreach my $img (@{$images}) {
14003: if ($env{'form.'.$role.'_del_'.$img}) {
14004: $confhash->{$role}{$img} = '';
1.12 raeburn 14005: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 14006: }
1.70 raeburn 14007: if ($role eq 'login') {
14008: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
14009: $changes->{$role}{'showlogo'}{$img} = 1;
14010: }
1.402 raeburn 14011: if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
14012: if ($confhash->{$role}{'alttext'}{$img} ne '') {
14013: $changes->{$role}{'alttext'}{$img} = 1;
14014: }
14015: }
1.70 raeburn 14016: }
1.6 raeburn 14017: }
14018: if ($confhash->{$role}{'font'}) {
14019: $changes->{$role}{'font'} = 1;
14020: }
1.48 raeburn 14021: }
1.6 raeburn 14022:
14023: sub display_colorchgs {
14024: my ($dom,$changes,$roles,$confhash) = @_;
14025: my (%choices,$resulttext);
14026: if (!grep(/^login$/,@{$roles})) {
14027: $resulttext = &mt('Changes made:').'<br />';
14028: }
14029: foreach my $role (@{$roles}) {
14030: if ($role eq 'login') {
14031: %choices = &login_choices();
14032: } else {
14033: %choices = &color_font_choices();
14034: }
14035: if (ref($changes->{$role}) eq 'HASH') {
14036: if ($role ne 'login') {
14037: $resulttext .= '<h4>'.&mt($role).'</h4>';
14038: }
14039: foreach my $key (sort(keys(%{$changes->{$role}}))) {
14040: if ($role ne 'login') {
14041: $resulttext .= '<ul>';
14042: }
14043: if (ref($changes->{$role}{$key}) eq 'HASH') {
14044: if ($role ne 'login') {
14045: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
14046: }
14047: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 14048: if (($role eq 'login') && ($key eq 'showlogo')) {
14049: if ($confhash->{$role}{$key}{$item}) {
14050: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
14051: } else {
14052: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
14053: }
1.402 raeburn 14054: } elsif (($role eq 'login') && ($key eq 'alttext')) {
14055: if ($confhash->{$role}{$key}{$item} ne '') {
1.403 raeburn 14056: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
1.402 raeburn 14057: $confhash->{$role}{$key}{$item}).'</li>';
14058: } else {
14059: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
14060: }
1.70 raeburn 14061: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 14062: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
14063: } else {
1.12 raeburn 14064: my $newitem = $confhash->{$role}{$item};
14065: if ($key eq 'images') {
1.306 raeburn 14066: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 14067: }
14068: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 14069: }
14070: }
14071: if ($role ne 'login') {
14072: $resulttext .= '</ul></li>';
14073: }
14074: } else {
14075: if ($confhash->{$role}{$key} eq '') {
14076: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
14077: } else {
14078: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
14079: }
14080: }
14081: if ($role ne 'login') {
14082: $resulttext .= '</ul>';
14083: }
14084: }
14085: }
14086: }
1.3 raeburn 14087: return $resulttext;
1.1 raeburn 14088: }
14089:
1.9 raeburn 14090: sub thumb_dimensions {
14091: return ('200','50');
14092: }
14093:
1.16 raeburn 14094: sub check_dimensions {
14095: my ($inputfile) = @_;
14096: my ($fullwidth,$fullheight);
14097: if ($inputfile =~ m|^[/\w.\-]+$|) {
14098: if (open(PIPE,"identify $inputfile 2>&1 |")) {
14099: my $imageinfo = <PIPE>;
14100: if (!close(PIPE)) {
14101: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
14102: }
14103: chomp($imageinfo);
14104: my ($fullsize) =
1.21 raeburn 14105: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 14106: if ($fullsize) {
14107: ($fullwidth,$fullheight) = split(/x/,$fullsize);
14108: }
14109: }
14110: }
14111: return ($fullwidth,$fullheight);
14112: }
14113:
1.9 raeburn 14114: sub check_configuser {
14115: my ($uhome,$dom,$confname,$servadm) = @_;
14116: my ($configuserok,%currroles);
14117: if ($uhome eq 'no_host') {
14118: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.361 raeburn 14119: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 14120: $configuserok =
14121: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
14122: $configpass,'','','','','',undef,$servadm);
14123: } else {
14124: $configuserok = 'ok';
14125: %currroles =
14126: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
14127: }
14128: return ($configuserok,%currroles);
14129: }
14130:
14131: sub check_authorstatus {
14132: my ($dom,$confname,%currroles) = @_;
14133: my $author_ok;
1.40 raeburn 14134: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 14135: my $start = time;
14136: my $end = 0;
14137: $author_ok =
14138: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 14139: 'au',$end,$start,'','','domconfig');
1.9 raeburn 14140: } else {
14141: $author_ok = 'ok';
14142: }
14143: return $author_ok;
14144: }
14145:
1.421 raeburn 14146: sub update_modify_urls {
14147: my ($r,$modified) = @_;
14148: if ((ref($modified) eq 'ARRAY') && (@{$modified})) {
14149: push(@{$modified_urls},$modified);
14150: unless ($registered_cleanup) {
14151: my $handlers = $r->get_handlers('PerlCleanupHandler');
14152: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
14153: $registered_cleanup=1;
1.9 raeburn 14154: }
14155: }
1.155 raeburn 14156: }
14157:
14158: sub notifysubscribed {
14159: foreach my $targetsource (@{$modified_urls}){
14160: next unless (ref($targetsource) eq 'ARRAY');
14161: my ($target,$source)=@{$targetsource};
14162: if ($source ne '') {
1.316 raeburn 14163: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 14164: print $logfh "\nCleanup phase: Notifications\n";
14165: my @subscribed=&subscribed_hosts($target);
14166: foreach my $subhost (@subscribed) {
14167: print $logfh "\nNotifying host ".$subhost.':';
14168: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
14169: print $logfh $reply;
14170: }
14171: my @subscribedmeta=&subscribed_hosts("$target.meta");
14172: foreach my $subhost (@subscribedmeta) {
14173: print $logfh "\nNotifying host for metadata only ".$subhost.':';
14174: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
14175: $subhost);
14176: print $logfh $reply;
14177: }
14178: print $logfh "\n============ Done ============\n";
1.160 raeburn 14179: close($logfh);
1.155 raeburn 14180: }
14181: }
14182: }
14183: return OK;
14184: }
14185:
14186: sub subscribed_hosts {
14187: my ($target) = @_;
14188: my @subscribed;
1.316 raeburn 14189: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 14190: while (my $subline=<$fh>) {
14191: if ($subline =~ /^($match_lonid):/) {
14192: my $host = $1;
14193: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
14194: unless (grep(/^\Q$host\E$/,@subscribed)) {
14195: push(@subscribed,$host);
14196: }
14197: }
14198: }
14199: }
14200: }
14201: return @subscribed;
1.9 raeburn 14202: }
14203:
14204: sub check_switchserver {
14205: my ($dom,$confname) = @_;
1.424 raeburn 14206: my ($allowed,$switchserver,$home);
14207: if ($confname eq '') {
1.9 raeburn 14208: $home = &Apache::lonnet::domain($dom,'primary');
1.424 raeburn 14209: } else {
14210: $home = &Apache::lonnet::homeserver($confname,$dom);
14211: if ($home eq 'no_host') {
14212: $home = &Apache::lonnet::domain($dom,'primary');
14213: }
1.9 raeburn 14214: }
14215: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 14216: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
14217: if (!$allowed) {
1.426 raeburn 14218: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
14219: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
14220: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 14221: }
14222: return $switchserver;
14223: }
14224:
1.1 raeburn 14225: sub modify_quotas {
1.216 raeburn 14226: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 14227: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 14228: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 14229: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
14230: $validationfieldsref);
1.86 raeburn 14231: if ($action eq 'quotas') {
1.429 raeburn 14232: $context = 'tools';
1.163 raeburn 14233: } else {
1.86 raeburn 14234: $context = $action;
14235: }
14236: if ($context eq 'requestcourses') {
1.325 raeburn 14237: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 14238: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 14239: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
14240: %titles = &courserequest_titles();
14241: $toolregexp = join('|',@usertools);
14242: %conditions = &courserequest_conditions();
1.216 raeburn 14243: $confname = $dom.'-domainconfig';
14244: my $servadm = $r->dir_config('lonAdmEMail');
14245: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 14246: ($validationitemsref,$validationnamesref,$validationfieldsref) =
14247: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 14248: } elsif ($context eq 'requestauthor') {
14249: @usertools = ('author');
14250: %titles = &authorrequest_titles();
1.86 raeburn 14251: } else {
1.430 raeburn 14252: @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.101 raeburn 14253: %titles = &tool_titles();
1.86 raeburn 14254: }
1.212 raeburn 14255: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 14256: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 14257: foreach my $key (keys(%env)) {
1.101 raeburn 14258: if ($context eq 'requestcourses') {
14259: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
14260: my $item = $1;
14261: my $type = $2;
14262: if ($type =~ /^limit_(.+)/) {
14263: $limithash{$item}{$1} = $env{$key};
14264: } else {
14265: $confhash{$item}{$type} = $env{$key};
14266: }
14267: }
1.163 raeburn 14268: } elsif ($context eq 'requestauthor') {
14269: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
14270: $confhash{$1} = $env{$key};
14271: }
1.101 raeburn 14272: } else {
1.86 raeburn 14273: if ($key =~ /^form\.quota_(.+)$/) {
14274: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 14275: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 14276: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
14277: }
1.72 raeburn 14278: }
14279: }
1.163 raeburn 14280: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 14281: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 14282: @approvalnotify = sort(@approvalnotify);
14283: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 14284: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 14285: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
14286: foreach my $type (@hasuniquecode) {
14287: if (grep(/^\Q$type\E$/,@crstypes)) {
14288: $confhash{'uniquecode'}{$type} = 1;
14289: }
1.216 raeburn 14290: }
1.242 raeburn 14291: my (%newbook,%allpos);
1.216 raeburn 14292: if ($context eq 'requestcourses') {
1.242 raeburn 14293: foreach my $type ('textbooks','templates') {
14294: @{$allpos{$type}} = ();
14295: my $invalid;
14296: if ($type eq 'textbooks') {
14297: $invalid = &mt('Invalid LON-CAPA course for textbook');
14298: } else {
14299: $invalid = &mt('Invalid LON-CAPA course for template');
14300: }
14301: if ($env{'form.'.$type.'_addbook'}) {
14302: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
14303: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
14304: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
14305: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
14306: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
14307: } else {
14308: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
14309: my $position = $env{'form.'.$type.'_addbook_pos'};
14310: $position =~ s/\D+//g;
14311: if ($position ne '') {
14312: $allpos{$type}[$position] = $newbook{$type};
14313: }
1.216 raeburn 14314: }
1.242 raeburn 14315: } else {
14316: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 14317: }
14318: }
1.242 raeburn 14319: }
1.216 raeburn 14320: }
1.102 raeburn 14321: if (ref($domconfig{$action}) eq 'HASH') {
14322: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
14323: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
14324: $changes{'notify'}{'approval'} = 1;
14325: }
14326: } else {
1.144 raeburn 14327: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14328: $changes{'notify'}{'approval'} = 1;
14329: }
14330: }
1.218 raeburn 14331: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
14332: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14333: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
14334: unless ($confhash{'uniquecode'}{$crstype}) {
14335: $changes{'uniquecode'} = 1;
14336: }
14337: }
14338: unless ($changes{'uniquecode'}) {
14339: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
14340: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
14341: $changes{'uniquecode'} = 1;
14342: }
14343: }
14344: }
14345: } else {
14346: $changes{'uniquecode'} = 1;
14347: }
14348: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
14349: $changes{'uniquecode'} = 1;
1.216 raeburn 14350: }
14351: if ($context eq 'requestcourses') {
1.242 raeburn 14352: foreach my $type ('textbooks','templates') {
14353: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14354: my %deletions;
14355: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
14356: if (@todelete) {
14357: map { $deletions{$_} = 1; } @todelete;
14358: }
14359: my %imgdeletions;
14360: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
14361: if (@todeleteimages) {
14362: map { $imgdeletions{$_} = 1; } @todeleteimages;
14363: }
14364: my $maxnum = $env{'form.'.$type.'_maxnum'};
14365: for (my $i=0; $i<=$maxnum; $i++) {
14366: my $itemid = $env{'form.'.$type.'_id_'.$i};
14367: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
14368: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
14369: if ($deletions{$key}) {
14370: if ($domconfig{$action}{$type}{$key}{'image'}) {
14371: #FIXME need to obsolete item in RES space
14372: }
14373: next;
14374: } else {
14375: my $newpos = $env{'form.'.$itemid};
14376: $newpos =~ s/\D+//g;
1.243 raeburn 14377: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 14378: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 14379: ($type eq 'templates'));
1.242 raeburn 14380: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
14381: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
14382: $changes{$type}{$key} = 1;
14383: }
14384: }
14385: $allpos{$type}[$newpos] = $key;
14386: }
14387: if ($imgdeletions{$key}) {
14388: $changes{$type}{$key} = 1;
1.216 raeburn 14389: #FIXME need to obsolete item in RES space
1.242 raeburn 14390: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
14391: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 14392: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14393: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14394: } else {
14395: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
14396: $cdom,$cnum,$type,$configuserok,
14397: $switchserver,$author_ok);
14398: if ($imgurl) {
14399: $confhash{$type}{$key}{'image'} = $imgurl;
14400: $changes{$type}{$key} = 1;
14401: }
14402: if ($error) {
14403: &Apache::lonnet::logthis($error);
14404: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14405: }
14406: }
1.242 raeburn 14407: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
14408: $confhash{$type}{$key}{'image'} =
14409: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 14410: }
14411: }
14412: }
14413: }
14414: }
14415: }
1.102 raeburn 14416: } else {
1.144 raeburn 14417: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14418: $changes{'notify'}{'approval'} = 1;
14419: }
1.218 raeburn 14420: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 14421: $changes{'uniquecode'} = 1;
14422: }
14423: }
14424: if ($context eq 'requestcourses') {
1.242 raeburn 14425: foreach my $type ('textbooks','templates') {
14426: if ($newbook{$type}) {
14427: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 14428: foreach my $item ('subject','title','publisher','author') {
14429: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14430: ($type eq 'template'));
1.242 raeburn 14431: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
14432: if ($env{'form.'.$type.'_addbook_'.$item}) {
14433: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
14434: }
14435: }
14436: if ($type eq 'textbooks') {
14437: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
14438: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 14439: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14440: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14441: } else {
14442: my ($imageurl,$error) =
14443: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
14444: $configuserok,$switchserver,$author_ok);
14445: if ($imageurl) {
14446: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
14447: }
14448: if ($error) {
14449: &Apache::lonnet::logthis($error);
14450: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14451: }
1.242 raeburn 14452: }
14453: }
1.216 raeburn 14454: }
14455: }
1.242 raeburn 14456: if (@{$allpos{$type}} > 0) {
14457: my $idx = 0;
14458: foreach my $item (@{$allpos{$type}}) {
14459: if ($item ne '') {
14460: $confhash{$type}{$item}{'order'} = $idx;
14461: if (ref($domconfig{$action}) eq 'HASH') {
14462: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14463: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
14464: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
14465: $changes{$type}{$item} = 1;
14466: }
1.216 raeburn 14467: }
14468: }
14469: }
1.242 raeburn 14470: $idx ++;
1.216 raeburn 14471: }
14472: }
14473: }
14474: }
1.235 raeburn 14475: if (ref($validationitemsref) eq 'ARRAY') {
14476: foreach my $item (@{$validationitemsref}) {
14477: if ($item eq 'fields') {
14478: my @changed;
14479: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
14480: if (@{$confhash{'validation'}{$item}} > 0) {
14481: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
14482: }
1.266 raeburn 14483: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14484: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14485: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
14486: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
14487: $domconfig{'requestcourses'}{'validation'}{$item});
14488: } else {
14489: @changed = @{$confhash{'validation'}{$item}};
14490: }
1.235 raeburn 14491: } else {
14492: @changed = @{$confhash{'validation'}{$item}};
14493: }
14494: } else {
14495: @changed = @{$confhash{'validation'}{$item}};
14496: }
14497: if (@changed) {
14498: if ($confhash{'validation'}{$item}) {
14499: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
14500: } else {
14501: $changes{'validation'}{$item} = &mt('None');
14502: }
14503: }
14504: } else {
14505: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
14506: if ($item eq 'markup') {
14507: if ($env{'form.requestcourses_validation_'.$item}) {
14508: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
14509: }
14510: }
1.266 raeburn 14511: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14512: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14513: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
14514: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14515: }
14516: } else {
14517: if ($confhash{'validation'}{$item} ne '') {
14518: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14519: }
1.235 raeburn 14520: }
14521: } else {
14522: if ($confhash{'validation'}{$item} ne '') {
14523: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14524: }
14525: }
14526: }
14527: }
14528: }
14529: if ($env{'form.validationdc'}) {
14530: my $newval = $env{'form.validationdc'};
1.285 raeburn 14531: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 14532: if (exists($domcoords{$newval})) {
14533: $confhash{'validation'}{'dc'} = $newval;
14534: }
14535: }
14536: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 14537: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14538: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14539: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14540: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
14541: if ($confhash{'validation'}{'dc'} eq '') {
14542: $changes{'validation'}{'dc'} = &mt('None');
14543: } else {
14544: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14545: }
1.235 raeburn 14546: }
1.266 raeburn 14547: } elsif ($confhash{'validation'}{'dc'} ne '') {
14548: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 14549: }
14550: } elsif ($confhash{'validation'}{'dc'} ne '') {
14551: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14552: }
14553: } elsif ($confhash{'validation'}{'dc'} ne '') {
14554: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 14555: }
1.266 raeburn 14556: } else {
14557: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14558: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14559: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14560: $changes{'validation'}{'dc'} = &mt('None');
14561: }
14562: }
1.235 raeburn 14563: }
14564: }
1.102 raeburn 14565: }
14566: } else {
1.86 raeburn 14567: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
14568: }
1.72 raeburn 14569: foreach my $item (@usertools) {
14570: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 14571: my $unset;
1.101 raeburn 14572: if ($context eq 'requestcourses') {
1.104 raeburn 14573: $unset = '0';
14574: if ($type eq '_LC_adv') {
14575: $unset = '';
14576: }
1.101 raeburn 14577: if ($confhash{$item}{$type} eq 'autolimit') {
14578: $confhash{$item}{$type} .= '=';
14579: unless ($limithash{$item}{$type} =~ /\D/) {
14580: $confhash{$item}{$type} .= $limithash{$item}{$type};
14581: }
14582: }
1.163 raeburn 14583: } elsif ($context eq 'requestauthor') {
14584: $unset = '0';
14585: if ($type eq '_LC_adv') {
14586: $unset = '';
14587: }
1.72 raeburn 14588: } else {
1.101 raeburn 14589: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
14590: $confhash{$item}{$type} = 1;
14591: } else {
14592: $confhash{$item}{$type} = 0;
14593: }
1.72 raeburn 14594: }
1.86 raeburn 14595: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 14596: if ($action eq 'requestauthor') {
14597: if ($domconfig{$action}{$type} ne $confhash{$type}) {
14598: $changes{$type} = 1;
14599: }
14600: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 14601: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
14602: $changes{$item}{$type} = 1;
14603: }
14604: } else {
14605: if ($context eq 'requestcourses') {
1.104 raeburn 14606: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 14607: $changes{$item}{$type} = 1;
14608: }
14609: } else {
14610: if (!$confhash{$item}{$type}) {
14611: $changes{$item}{$type} = 1;
14612: }
14613: }
14614: }
14615: } else {
14616: if ($context eq 'requestcourses') {
1.104 raeburn 14617: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 14618: $changes{$item}{$type} = 1;
14619: }
1.163 raeburn 14620: } elsif ($context eq 'requestauthor') {
14621: if ($confhash{$type} ne $unset) {
14622: $changes{$type} = 1;
14623: }
1.72 raeburn 14624: } else {
14625: if (!$confhash{$item}{$type}) {
14626: $changes{$item}{$type} = 1;
14627: }
14628: }
14629: }
1.1 raeburn 14630: }
14631: }
1.163 raeburn 14632: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 14633: if (ref($domconfig{'quotas'}) eq 'HASH') {
14634: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14635: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
14636: if (exists($confhash{'defaultquota'}{$key})) {
14637: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
14638: $changes{'defaultquota'}{$key} = 1;
14639: }
14640: } else {
14641: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 14642: }
14643: }
1.86 raeburn 14644: } else {
14645: foreach my $key (keys(%{$domconfig{'quotas'}})) {
14646: if (exists($confhash{'defaultquota'}{$key})) {
14647: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
14648: $changes{'defaultquota'}{$key} = 1;
14649: }
14650: } else {
14651: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 14652: }
1.1 raeburn 14653: }
14654: }
1.197 raeburn 14655: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
1.429 raeburn 14656: $confhash{'authorquota'} = $domconfig{'quotas'}{'authorquota'};
14657: }
14658: if (ref($domconfig{'quotas'}{'webdav'}) eq 'HASH') {
14659: $confhash{'webdav'} = $domconfig{'quotas'}{'webdav'};
1.197 raeburn 14660: }
1.1 raeburn 14661: }
1.86 raeburn 14662: if (ref($confhash{'defaultquota'}) eq 'HASH') {
14663: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
14664: if (ref($domconfig{'quotas'}) eq 'HASH') {
14665: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14666: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
14667: $changes{'defaultquota'}{$key} = 1;
14668: }
14669: } else {
14670: if (!exists($domconfig{'quotas'}{$key})) {
14671: $changes{'defaultquota'}{$key} = 1;
14672: }
1.72 raeburn 14673: }
14674: } else {
1.86 raeburn 14675: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 14676: }
1.1 raeburn 14677: }
14678: }
14679: }
1.72 raeburn 14680:
1.163 raeburn 14681: if ($context eq 'requestauthor') {
14682: $domdefaults{'requestauthor'} = \%confhash;
14683: } else {
14684: foreach my $key (keys(%confhash)) {
1.242 raeburn 14685: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 14686: $domdefaults{$key} = $confhash{$key};
14687: }
1.163 raeburn 14688: }
1.72 raeburn 14689: }
1.163 raeburn 14690:
1.1 raeburn 14691: my %quotahash = (
1.86 raeburn 14692: $action => { %confhash }
1.1 raeburn 14693: );
14694: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
14695: $dom);
14696: if ($putresult eq 'ok') {
14697: if (keys(%changes) > 0) {
1.72 raeburn 14698: my $cachetime = 24*60*60;
14699: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 14700: if (ref($lastactref) eq 'HASH') {
14701: $lastactref->{'domdefaults'} = 1;
14702: }
1.1 raeburn 14703: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 14704: unless (($context eq 'requestcourses') ||
1.163 raeburn 14705: ($context eq 'requestauthor')) {
1.86 raeburn 14706: if (ref($changes{'defaultquota'}) eq 'HASH') {
14707: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
14708: foreach my $type (@{$types},'default') {
14709: if (defined($changes{'defaultquota'}{$type})) {
14710: my $typetitle = $usertypes->{$type};
14711: if ($type eq 'default') {
14712: $typetitle = $othertitle;
14713: }
1.213 raeburn 14714: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 14715: }
14716: }
1.86 raeburn 14717: $resulttext .= '</ul></li>';
1.72 raeburn 14718: }
14719: }
1.80 raeburn 14720: my %newenv;
1.72 raeburn 14721: foreach my $item (@usertools) {
1.163 raeburn 14722: my (%haschgs,%inconf);
14723: if ($context eq 'requestauthor') {
14724: %haschgs = %changes;
1.210 raeburn 14725: %inconf = %confhash;
1.163 raeburn 14726: } else {
14727: if (ref($changes{$item}) eq 'HASH') {
14728: %haschgs = %{$changes{$item}};
14729: }
14730: if (ref($confhash{$item}) eq 'HASH') {
14731: %inconf = %{$confhash{$item}};
14732: }
14733: }
14734: if (keys(%haschgs) > 0) {
1.80 raeburn 14735: my $newacc =
14736: &Apache::lonnet::usertools_access($env{'user.name'},
14737: $env{'user.domain'},
1.86 raeburn 14738: $item,'reload',$context);
1.210 raeburn 14739: if (($context eq 'requestcourses') ||
1.163 raeburn 14740: ($context eq 'requestauthor')) {
1.108 raeburn 14741: if ($env{'environment.canrequest.'.$item} ne $newacc) {
14742: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 14743: }
14744: } else {
14745: if ($env{'environment.availabletools.'.$item} ne $newacc) {
14746: $newenv{'environment.availabletools.'.$item} = $newacc;
14747: }
1.80 raeburn 14748: }
1.163 raeburn 14749: unless ($context eq 'requestauthor') {
14750: $resulttext .= '<li>'.$titles{$item}.'<ul>';
14751: }
1.72 raeburn 14752: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 14753: if ($haschgs{$type}) {
1.72 raeburn 14754: my $typetitle = $usertypes->{$type};
14755: if ($type eq 'default') {
14756: $typetitle = $othertitle;
14757: } elsif ($type eq '_LC_adv') {
14758: $typetitle = 'LON-CAPA Advanced Users';
14759: }
1.163 raeburn 14760: if ($inconf{$type}) {
1.101 raeburn 14761: if ($context eq 'requestcourses') {
14762: my $cond;
1.163 raeburn 14763: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 14764: if ($1 eq '') {
14765: $cond = &mt('(Automatic processing of any request).');
14766: } else {
14767: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
14768: }
14769: } else {
1.163 raeburn 14770: $cond = $conditions{$inconf{$type}};
1.101 raeburn 14771: }
14772: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 14773: } elsif ($context eq 'requestauthor') {
14774: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
14775: $titles{$inconf{$type}},$typetitle);
14776:
1.101 raeburn 14777: } else {
14778: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
14779: }
1.72 raeburn 14780: } else {
1.104 raeburn 14781: if ($type eq '_LC_adv') {
1.163 raeburn 14782: if ($inconf{$type} eq '0') {
1.104 raeburn 14783: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14784: } else {
14785: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
14786: }
14787: } else {
14788: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14789: }
1.72 raeburn 14790: }
14791: }
1.26 raeburn 14792: }
1.163 raeburn 14793: unless ($context eq 'requestauthor') {
14794: $resulttext .= '</ul></li>';
14795: }
1.26 raeburn 14796: }
1.1 raeburn 14797: }
1.163 raeburn 14798: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 14799: if (ref($changes{'notify'}) eq 'HASH') {
14800: if ($changes{'notify'}{'approval'}) {
14801: if (ref($confhash{'notify'}) eq 'HASH') {
14802: if ($confhash{'notify'}{'approval'}) {
14803: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
14804: } else {
1.163 raeburn 14805: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 14806: }
14807: }
14808: }
14809: }
14810: }
1.216 raeburn 14811: if ($action eq 'requestcourses') {
14812: my @offon = ('off','on');
14813: if ($changes{'uniquecode'}) {
1.218 raeburn 14814: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14815: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
14816: $resulttext .= '<li>'.
14817: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
14818: '</li>';
14819: } else {
14820: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
14821: '</li>';
14822: }
1.216 raeburn 14823: }
1.242 raeburn 14824: foreach my $type ('textbooks','templates') {
14825: if (ref($changes{$type}) eq 'HASH') {
14826: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
14827: foreach my $key (sort(keys(%{$changes{$type}}))) {
14828: my %coursehash = &Apache::lonnet::coursedescription($key);
14829: my $coursetitle = $coursehash{'description'};
14830: my $position = $confhash{$type}{$key}{'order'} + 1;
14831: $resulttext .= '<li>';
1.243 raeburn 14832: foreach my $item ('subject','title','publisher','author') {
14833: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14834: ($type eq 'templates'));
1.242 raeburn 14835: my $name = $item.':';
14836: $name =~ s/^(\w)/\U$1/;
14837: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
14838: }
14839: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
14840: if ($type eq 'textbooks') {
14841: if ($confhash{$type}{$key}{'image'}) {
14842: $resulttext .= ' '.&mt('Image: [_1]',
14843: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
14844: ' alt="Textbook cover" />').'<br />';
14845: }
14846: }
14847: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 14848: }
1.242 raeburn 14849: $resulttext .= '</ul></li>';
1.216 raeburn 14850: }
14851: }
1.235 raeburn 14852: if (ref($changes{'validation'}) eq 'HASH') {
14853: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
14854: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
14855: foreach my $item (@{$validationitemsref}) {
14856: if (exists($changes{'validation'}{$item})) {
14857: if ($item eq 'markup') {
14858: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14859: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
14860: } else {
14861: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14862: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
14863: }
14864: }
14865: }
14866: if (exists($changes{'validation'}{'dc'})) {
14867: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
14868: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
14869: }
1.442 raeburn 14870: $resulttext .= '</ul></li>';
1.235 raeburn 14871: }
14872: }
1.216 raeburn 14873: }
1.1 raeburn 14874: $resulttext .= '</ul>';
1.80 raeburn 14875: if (keys(%newenv)) {
14876: &Apache::lonnet::appenv(\%newenv);
14877: }
1.1 raeburn 14878: } else {
1.86 raeburn 14879: if ($context eq 'requestcourses') {
14880: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 14881: } elsif ($context eq 'requestauthor') {
14882: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 14883: } else {
1.90 weissno 14884: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 14885: }
1.1 raeburn 14886: }
14887: } else {
1.11 albertel 14888: $resulttext = '<span class="LC_error">'.
14889: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14890: }
1.216 raeburn 14891: if ($errors) {
14892: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
14893: '<ul>'.$errors.'</ul></p>';
14894: }
1.3 raeburn 14895: return $resulttext;
1.1 raeburn 14896: }
14897:
1.216 raeburn 14898: sub process_textbook_image {
1.242 raeburn 14899: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 14900: my $filename = $env{'form.'.$caller.'.filename'};
14901: my ($error,$url);
14902: my ($width,$height) = (50,50);
14903: if ($configuserok eq 'ok') {
14904: if ($switchserver) {
14905: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
14906: $switchserver);
14907: } elsif ($author_ok eq 'ok') {
1.421 raeburn 14908: my $modified = [];
1.216 raeburn 14909: my ($result,$imageurl) =
1.421 raeburn 14910: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
14911: "$type/$cdom/$cnum/cover",$width,$height,
14912: '',$modified);
1.216 raeburn 14913: if ($result eq 'ok') {
14914: $url = $imageurl;
1.421 raeburn 14915: &update_modify_urls($r,$modified);
1.216 raeburn 14916: } else {
14917: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14918: }
14919: } else {
14920: $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);
14921: }
14922: } else {
14923: $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);
14924: }
14925: return ($url,$error);
14926: }
14927:
1.267 raeburn 14928: sub modify_ltitools {
14929: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.421 raeburn 14930: my (%currtoolsec,%secchanges,%newtoolsec,%newkeyset);
14931: &fetch_secrets($dom,'toolsec',\%domconfig,\%currtoolsec,\%secchanges,\%newtoolsec,\%newkeyset);
14932:
1.267 raeburn 14933: my $confname = $dom.'-domainconfig';
14934: my $servadm = $r->dir_config('lonAdmEMail');
14935: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.421 raeburn 14936:
14937: my ($resulttext,$ltitoolsoutput,$is_home,$errors,%ltitoolschg,%newtoolsenc,%newltitools);
14938: my $toolserror =
14939: &Apache::courseprefs::process_ltitools($r,$dom,$confname,$domconfig{'ltitools'},\%ltitoolschg,'domain',
14940: $lastactref,$configuserok,$switchserver,$author_ok);
14941:
14942: my $home = &Apache::lonnet::domain($dom,'primary');
14943: unless (($home eq 'no_host') || ($home eq '')) {
14944: my @ids=&Apache::lonnet::current_machine_ids();
14945: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; last; } }
14946: }
14947:
14948: if (keys(%ltitoolschg)) {
14949: foreach my $id (keys(%ltitoolschg)) {
14950: if (ref($ltitoolschg{$id}) eq 'HASH') {
14951: foreach my $inner (keys(%{$ltitoolschg{$id}})) {
14952: if (($inner eq 'secret') || ($inner eq 'key')) {
14953: if ($is_home) {
14954: $newtoolsenc{$id}{$inner} = $ltitoolschg{$id}{$inner};
14955: }
14956: }
14957: }
1.267 raeburn 14958: }
1.421 raeburn 14959: }
14960: $ltitoolsoutput = &Apache::courseprefs::store_ltitools($dom,'','domain',\%ltitoolschg,$domconfig{'ltitools'});
14961: if (keys(%ltitoolschg)) {
14962: %newltitools = %ltitoolschg;
14963: }
14964: }
14965: if (ref($domconfig{'ltitools'}) eq 'HASH') {
14966: foreach my $id (%{$domconfig{'ltitools'}}) {
14967: next if ($id !~ /^\d+$/);
14968: unless (exists($ltitoolschg{$id})) {
14969: if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
14970: foreach my $inner (keys(%{$domconfig{'ltitools'}{$id}})) {
14971: if (($inner eq 'secret') || ($inner eq 'key')) {
14972: if ($is_home) {
14973: $newtoolsenc{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14974: }
14975: } else {
14976: $newltitools{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14977: }
14978: }
14979: } else {
14980: $newltitools{$id} = $domconfig{'ltitools'}{$id};
1.322 raeburn 14981: }
1.421 raeburn 14982: }
14983: }
14984: }
14985: if ($toolserror) {
14986: $errors = '<li>'.$toolserror.'</li>';
14987: }
14988: if ((keys(%ltitoolschg) == 0) && (keys(%secchanges) == 0)) {
14989: $resulttext = &mt('No changes made.');
14990: if ($errors) {
14991: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
14992: $errors.'</ul>';
14993: }
14994: return $resulttext;
14995: }
14996: my %ltitoolshash = (
14997: $action => { %newltitools }
14998: );
14999: if (keys(%secchanges)) {
15000: $ltitoolshash{'toolsec'} = \%newtoolsec;
15001: }
15002: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,$dom);
15003: if ($putresult eq 'ok') {
15004: my %keystore;
15005: if ($is_home) {
15006: my %toolsenchash = (
15007: $action => { %newtoolsenc }
15008: );
15009: &Apache::lonnet::put_dom('encconfig',\%toolsenchash,$dom,undef,1);
1.423 raeburn 15010: my $cachetime = 24*60*60;
15011: &Apache::lonnet::do_cache_new('ltitoolsenc',$dom,\%newtoolsenc,$cachetime);
1.421 raeburn 15012: &store_security($dom,'ltitools',\%secchanges,\%newkeyset,\%keystore,$lastactref);
15013: }
15014: $resulttext = &mt('Changes made:').'<ul>';
15015: if (keys(%secchanges) > 0) {
1.423 raeburn 15016: $resulttext .= <i_security_results($dom,'ltitools',\%secchanges,\%newtoolsec,\%newkeyset,\%keystore);
1.421 raeburn 15017: }
15018: if (keys(%ltitoolschg) > 0) {
15019: $resulttext .= $ltitoolsoutput;
15020: }
1.423 raeburn 15021: my $cachetime = 24*60*60;
15022: &Apache::lonnet::do_cache_new('ltitools',$dom,\%newltitools,$cachetime);
15023: if (ref($lastactref) eq 'HASH') {
15024: $lastactref->{'ltitools'} = 1;
15025: }
1.421 raeburn 15026: } else {
15027: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15028: }
15029: if ($errors) {
15030: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
15031: $errors.'</ul></p>';
15032: }
15033: return $resulttext;
15034: }
15035:
15036: sub fetch_secrets {
15037: my ($dom,$context,$domconfig,$currsec,$secchanges,$newsec,$newkeyset) = @_;
15038: my %keyset;
15039: %{$currsec} = ();
15040: $newsec->{'private'}{'keys'} = [];
15041: $newsec->{'encrypt'} = {};
15042: $newsec->{'rules'} = {};
15043: if ($context eq 'ltisec') {
15044: $newsec->{'linkprot'} = {};
15045: }
15046: if (ref($domconfig->{$context}) eq 'HASH') {
15047: %{$currsec} = %{$domconfig->{$context}};
15048: if ($context eq 'ltisec') {
15049: if (ref($currsec->{'linkprot'}) eq 'HASH') {
15050: foreach my $id (keys(%{$currsec->{'linkprot'}})) {
15051: unless ($id =~ /^\d+$/) {
15052: delete($currsec->{'linkprot'}{$id});
1.297 raeburn 15053: }
1.267 raeburn 15054: }
15055: }
1.421 raeburn 15056: }
15057: if (ref($currsec->{'private'}) eq 'HASH') {
15058: if (ref($currsec->{'private'}{'keys'}) eq 'ARRAY') {
15059: $newsec->{'private'}{'keys'} = $currsec->{'private'}{'keys'};
15060: map { $keyset{$_} = 1; } @{$currsec->{'private'}{'keys'}};
1.267 raeburn 15061: }
1.421 raeburn 15062: }
15063: }
15064: my @items= ('crs','dom');
15065: if ($context eq 'ltisec') {
15066: push(@items,'consumers');
15067: }
15068: foreach my $item (@items) {
15069: my $formelement;
15070: if (($context eq 'toolsec') || ($item eq 'consumers')) {
15071: $formelement = 'form.'.$context.'_'.$item;
15072: } else {
15073: $formelement = 'form.'.$context.'_'.$item.'linkprot';
15074: }
15075: if ($env{$formelement}) {
15076: $newsec->{'encrypt'}{$item} = 1;
15077: if (ref($currsec->{'encrypt'}) eq 'HASH') {
15078: unless ($currsec->{'encrypt'}{$item}) {
15079: $secchanges->{'encrypt'} = 1;
15080: }
15081: } else {
15082: $secchanges->{'encrypt'} = 1;
1.267 raeburn 15083: }
1.421 raeburn 15084: } elsif (ref($currsec->{'encrypt'}) eq 'HASH') {
15085: if ($currsec->{'encrypt'}{$item}) {
15086: $secchanges->{'encrypt'} = 1;
1.323 raeburn 15087: }
1.421 raeburn 15088: }
15089: }
15090: my $secrets;
15091: if ($context eq 'ltisec') {
15092: $secrets = 'ltisecrets';
15093: } else {
15094: $secrets = 'toolsecrets';
15095: }
15096: unless (exists($currsec->{'rules'})) {
15097: $currsec->{'rules'} = {};
15098: }
15099: &password_rule_changes($secrets,$newsec->{'rules'},$currsec->{'rules'},$secchanges);
15100:
15101: my @ids=&Apache::lonnet::current_machine_ids();
15102: my %servers = &Apache::lonnet::get_servers($dom,'library');
15103:
15104: foreach my $hostid (keys(%servers)) {
15105: if (($hostid ne '') && (grep(/^\Q$hostid\E$/,@ids))) {
15106: my $keyitem = 'form.'.$context.'_privkey_'.$hostid;
15107: if (exists($env{$keyitem})) {
15108: $env{$keyitem} =~ s/(`)/'/g;
15109: if ($keyset{$hostid}) {
15110: if ($env{'form.'.$context.'_changeprivkey_'.$hostid}) {
15111: if ($env{$keyitem} ne '') {
15112: $secchanges->{'private'} = 1;
15113: $newkeyset->{$hostid} = $env{$keyitem};
15114: }
1.296 raeburn 15115: }
1.421 raeburn 15116: } elsif ($env{$keyitem} ne '') {
15117: unless (grep(/^\Q$hostid\E$/,@{$newsec->{'private'}{'keys'}})) {
15118: push(@{$newsec->{'private'}{'keys'}},$hostid);
1.296 raeburn 15119: }
1.421 raeburn 15120: $secchanges->{'private'} = 1;
15121: $newkeyset->{$hostid} = $env{$keyitem};
1.267 raeburn 15122: }
15123: }
1.421 raeburn 15124: }
15125: }
15126: }
15127:
15128: sub store_security {
1.424 raeburn 15129: my ($dom,$context,$secchanges,$newkeyset,$keystore) = @_;
1.421 raeburn 15130: return unless ((ref($secchanges) eq 'HASH') && (ref($newkeyset) eq 'HASH') &&
15131: (ref($keystore) eq 'HASH'));
15132: if (keys(%{$secchanges})) {
15133: if ($secchanges->{'private'}) {
15134: my $who = &escape($env{'user.name'}.':'.$env{'user.domain'});
15135: foreach my $hostid (keys(%{$newkeyset})) {
15136: my $storehash = {
15137: key => $newkeyset->{$hostid},
15138: who => $env{'user.name'}.':'.$env{'user.domain'},
15139: };
15140: $keystore->{$hostid} = &Apache::lonnet::store_dom($storehash,$context,'private',
15141: $dom,$hostid);
15142: }
15143: }
15144: }
15145: }
15146:
15147: sub lti_security_results {
1.423 raeburn 15148: my ($dom,$context,$secchanges,$newsec,$newkeyset,$keystore) = @_;
1.421 raeburn 15149: my $output;
1.423 raeburn 15150: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
15151: my $needs_update;
1.421 raeburn 15152: foreach my $item (keys(%{$secchanges})) {
15153: if ($item eq 'encrypt') {
1.423 raeburn 15154: $needs_update = 1;
1.421 raeburn 15155: my %encrypted;
15156: if ($context eq 'lti') {
15157: %encrypted = (
15158: crs => {
15159: on => &mt('Encryption of stored link protection secrets defined in courses enabled'),
15160: off => &mt('Encryption of stored link protection secrets defined in courses disabled'),
15161: },
15162: dom => {
15163: on => &mt('Encryption of stored link protection secrets defined in domain enabled'),
15164: off => &mt('Encryption of stored link protection secrets defined in domain disabled'),
15165: },
15166: consumers => {
15167: on => &mt('Encryption of stored consumer secrets defined in domain enabled'),
15168: off => &mt('Encryption of stored consumer secrets defined in domain disabled'),
15169: },
15170: );
1.267 raeburn 15171: } else {
1.421 raeburn 15172: %encrypted = (
15173: crs => {
15174: on => &mt('Encryption of stored external tool secrets defined in courses enabled'),
15175: off => &mt('Encryption of stored external tool secrets defined in courses disabled'),
15176: },
15177: dom => {
15178: on => &mt('Encryption of stored external tool secrets defined in domain enabled'),
15179: off => &mt('Encryption of stored external tool secrets defined in domain disabled'),
15180: },
15181: );
15182: }
15183: my @types= ('crs','dom');
15184: if ($context eq 'lti') {
1.423 raeburn 15185: foreach my $type (@types) {
15186: undef($domdefaults{'linkprotenc_'.$type});
15187: }
1.421 raeburn 15188: push(@types,'consumers');
1.423 raeburn 15189: undef($domdefaults{'ltienc_consumers'});
15190: } elsif ($context eq 'ltitools') {
15191: foreach my $type (@types) {
15192: undef($domdefaults{'toolenc_'.$type});
15193: }
1.267 raeburn 15194: }
1.421 raeburn 15195: foreach my $type (@types) {
15196: my $shown = $encrypted{$type}{'off'};
15197: if (ref($newsec->{$item}) eq 'HASH') {
15198: if ($newsec->{$item}{$type}) {
1.423 raeburn 15199: if ($context eq 'lti') {
15200: if ($type eq 'consumers') {
15201: $domdefaults{'ltienc_consumers'} = 1;
15202: } else {
15203: $domdefaults{'linkprotenc_'.$type} = 1;
15204: }
15205: } elsif ($context eq 'ltitools') {
15206: $domdefaults{'toolenc_'.$type} = 1;
15207: }
1.421 raeburn 15208: $shown = $encrypted{$type}{'on'};
1.319 raeburn 15209: }
1.267 raeburn 15210: }
1.421 raeburn 15211: $output .= '<li>'.$shown.'</li>';
1.267 raeburn 15212: }
1.421 raeburn 15213: } elsif ($item eq 'rules') {
15214: my %titles = &Apache::lonlocal::texthash(
15215: min => 'Minimum password length',
15216: max => 'Maximum password length',
15217: chars => 'Required characters',
15218: );
15219: foreach my $rule ('min','max') {
15220: if ($newsec->{rules}{$rule} eq '') {
15221: if ($rule eq 'min') {
15222: $output .= '<li>'.&mt('[_1] not set.',$titles{$rule});
15223: ' '.&mt('Default of [_1] will be used',
15224: $Apache::lonnet::passwdmin).'</li>';
15225: } else {
15226: $output .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
15227: }
15228: } else {
15229: $output .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$newsec->{rules}{$rule}).'</li>';
15230: }
15231: }
15232: if (ref($newsec->{'rules'}{'chars'}) eq 'ARRAY') {
15233: if (@{$newsec->{'rules'}{'chars'}} > 0) {
15234: my %rulenames = &Apache::lonlocal::texthash(
15235: uc => 'At least one upper case letter',
15236: lc => 'At least one lower case letter',
15237: num => 'At least one number',
15238: spec => 'At least one non-alphanumeric',
15239: );
15240: my $needed = '<ul><li>'.
15241: join('</li><li>',map {$rulenames{$_} } @{$newsec->{'rules'}{'chars'}}).
15242: '</li></ul>';
15243: $output .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
15244: } else {
15245: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 15246: }
1.421 raeburn 15247: } else {
15248: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 15249: }
1.421 raeburn 15250: } elsif ($item eq 'private') {
1.423 raeburn 15251: $needs_update = 1;
15252: if ($context eq 'lti') {
15253: undef($domdefaults{'ltiprivhosts'});
15254: } elsif ($context eq 'ltitools') {
15255: undef($domdefaults{'toolprivhosts'});
15256: }
1.421 raeburn 15257: if (keys(%{$newkeyset})) {
1.423 raeburn 15258: my @privhosts;
1.421 raeburn 15259: foreach my $hostid (sort(keys(%{$newkeyset}))) {
15260: if ($keystore->{$hostid} eq 'ok') {
15261: $output .= '<li>'.&mt('Encryption key for storage of shared secrets saved for [_1]',$hostid).'</li>';
1.423 raeburn 15262: unless (grep(/^\Q$hostid\E$/,@privhosts)) {
15263: push(@privhosts,$hostid);
15264: }
15265: }
15266: }
15267: if (@privhosts) {
15268: if ($context eq 'lti') {
15269: $domdefaults{'ltiprivhosts'} = \@privhosts;
15270: } elsif ($context eq 'ltitools') {
15271: $domdefaults{'toolprivhosts'} = \@privhosts;
1.267 raeburn 15272: }
15273: }
15274: }
1.421 raeburn 15275: } elsif ($item eq 'linkprot') {
15276: next;
1.434 raeburn 15277: } elsif ($item eq 'suggested') {
15278: if ((ref($secchanges->{'suggested'}) eq 'HASH') &&
15279: (ref($newsec->{'suggested'}) eq 'HASH')) {
15280: my $suggestions;
15281: foreach my $id (sort { $a <=> $b } keys(%{$secchanges->{'suggested'}})) {
15282: if (ref($newsec->{'suggested'}->{$id}) eq 'HASH') {
15283: my $name = $newsec->{'suggested'}->{$id}->{'name'};
15284: my $info = $newsec->{'suggested'}->{$id}->{'info'};
15285: $suggestions .= '<li>'.&mt('Launcher: [_1]',$name).'<br />'.
15286: &mt('Recommend: [_1]','<pre>'.$info.'</pre>').
15287: '</li>';
15288: } else {
15289: $suggestions .= '<li>'.&mt('Recommendations deleted for Launcher: [_1]',
15290: $newsec->{'suggested'}->{$id}).'</li>';
15291: }
15292: }
15293: if ($suggestions) {
15294: $output .= '<li>'.&mt('Hints in Courses for Link Protector Configuration').
15295: '<ul>'.$suggestions.'</ul>'.
15296: '</li>';
15297: }
15298: }
1.267 raeburn 15299: }
15300: }
1.423 raeburn 15301: if ($needs_update) {
15302: my $cachetime = 24*60*60;
15303: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15304: }
1.421 raeburn 15305: return $output;
15306: }
15307:
15308: sub modify_proctoring {
15309: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15310: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15311: my (@allpos,%changes,%confhash,%encconfhash,$errors,$resulttext,%imgdeletions);
15312: my $confname = $dom.'-domainconfig';
15313: my $servadm = $r->dir_config('lonAdmEMail');
1.372 raeburn 15314: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
15315: my %providernames = &proctoring_providernames();
15316: my $maxnum = scalar(keys(%providernames));
15317:
15318: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
15319: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
15320: if (ref($requref) eq 'HASH') {
15321: %requserfields = %{$requref};
15322: }
15323: if (ref($opturef) eq 'HASH') {
15324: %optuserfields = %{$opturef};
15325: }
15326: if (ref($defref) eq 'HASH') {
15327: %defaults = %{$defref};
15328: }
15329: if (ref($extref) eq 'HASH') {
15330: %extended = %{$extref};
15331: }
15332: if (ref($crsref) eq 'HASH') {
15333: %crsconf = %{$crsref};
15334: }
15335: if (ref($rolesref) eq 'ARRAY') {
15336: @courseroles = @{$rolesref};
15337: }
15338: if (ref($ltiref) eq 'ARRAY') {
15339: @ltiroles = @{$ltiref};
15340: }
15341:
15342: if (ref($domconfig{$action}) eq 'HASH') {
15343: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.proctoring_image_del');
15344: if (@todeleteimages) {
15345: map { $imgdeletions{$_} = 1; } @todeleteimages;
15346: }
15347: }
15348: my %customadds;
15349: my @newcustom = &Apache::loncommon::get_env_multiple('form.proctoring_customadd');
15350: if (@newcustom) {
15351: map { $customadds{$_} = 1; } @newcustom;
15352: }
15353: foreach my $provider (sort(keys(%providernames))) {
15354: $confhash{$provider} = {};
15355: my $pos = $env{'form.proctoring_pos_'.$provider};
15356: $pos =~ s/\D+//g;
15357: $allpos[$pos] = $provider;
15358: my (%current,%currentenc);
15359: my $showroles = 0;
15360: if (ref($domconfig{$action}) eq 'HASH') {
15361: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15362: %current = %{$domconfig{$action}{$provider}};
15363: foreach my $item ('key','secret') {
15364: $currentenc{$item} = $current{$item};
15365: delete($current{$item});
15366: }
15367: }
15368: }
15369: if ($env{'form.proctoring_available_'.$provider}) {
15370: $confhash{$provider}{'available'} = 1;
15371: unless ($current{'available'}) {
15372: $changes{$provider} = 1;
15373: }
15374: } else {
15375: %{$confhash{$provider}} = %current;
15376: %{$encconfhash{$provider}} = %currentenc;
15377: $confhash{$provider}{'available'} = 0;
15378: if ($current{'available'}) {
15379: $changes{$provider} = 1;
15380: }
15381: }
15382: if ($confhash{$provider}{'available'}) {
15383: foreach my $field ('lifetime','version','sigmethod','url','key','secret') {
15384: my $possval = $env{'form.proctoring_'.$provider.'_'.$field};
15385: if ($field eq 'lifetime') {
15386: if ($possval =~ /^\d+$/) {
15387: $confhash{$provider}{$field} = $possval;
15388: }
15389: } elsif ($field eq 'version') {
15390: if ($possval =~ /^\d+\.\d+$/) {
15391: $confhash{$provider}{$field} = $possval;
15392: }
15393: } elsif ($field eq 'sigmethod') {
15394: if ($possval =~ /^\QHMAC-SHA\E(1|256)$/) {
15395: $confhash{$provider}{$field} = $possval;
15396: }
15397: } elsif ($field eq 'url') {
15398: $confhash{$provider}{$field} = $possval;
15399: } elsif (($field eq 'key') || ($field eq 'secret')) {
15400: $encconfhash{$provider}{$field} = $possval;
15401: unless ($currentenc{$field} eq $possval) {
15402: $changes{$provider} = 1;
15403: }
15404: }
15405: unless (($field eq 'key') || ($field eq 'secret')) {
15406: unless ($current{$field} eq $confhash{$provider}{$field}) {
15407: $changes{$provider} = 1;
15408: }
15409: }
15410: }
15411: if ($imgdeletions{$provider}) {
15412: $changes{$provider} = 1;
15413: } elsif ($env{'form.proctoring_image_'.$provider.'.filename'} ne '') {
15414: my ($imageurl,$error) =
15415: &process_proctoring_image($r,$dom,$confname,'proctoring_image_'.$provider,$provider,
15416: $configuserok,$switchserver,$author_ok);
15417: if ($imageurl) {
15418: $confhash{$provider}{'image'} = $imageurl;
15419: $changes{$provider} = 1;
15420: }
15421: if ($error) {
15422: &Apache::lonnet::logthis($error);
15423: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15424: }
15425: } elsif (exists($current{'image'})) {
15426: $confhash{$provider}{'image'} = $current{'image'};
15427: }
15428: if (ref($requserfields{$provider}) eq 'ARRAY') {
15429: if (@{$requserfields{$provider}} > 0) {
15430: if (grep(/^user$/,@{$requserfields{$provider}})) {
15431: if ($env{'form.proctoring_userincdom_'.$provider}) {
15432: $confhash{$provider}{'incdom'} = 1;
15433: }
15434: unless ($current{'incdom'} eq $confhash{$provider}{'incdom'}) {
15435: $changes{$provider} = 1;
15436: }
15437: }
15438: if (grep(/^roles$/,@{$requserfields{$provider}})) {
15439: $showroles = 1;
15440: }
15441: }
15442: }
15443: $confhash{$provider}{'fields'} = [];
15444: if (ref($optuserfields{$provider}) eq 'ARRAY') {
15445: if (@{$optuserfields{$provider}} > 0) {
15446: my @optfields = &Apache::loncommon::get_env_multiple('form.proctoring_optional_'.$provider);
15447: foreach my $field (@{$optuserfields{$provider}}) {
15448: if (grep(/^\Q$field\E$/,@optfields)) {
15449: push(@{$confhash{$provider}{'fields'}},$field);
15450: }
15451: }
15452: }
15453: if (ref($current{'fields'}) eq 'ARRAY') {
15454: unless ($changes{$provider}) {
15455: my @new = sort(@{$confhash{$provider}{'fields'}});
15456: my @old = sort(@{$current{'fields'}});
15457: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15458: if (@diffs) {
15459: $changes{$provider} = 1;
15460: }
15461: }
15462: } elsif (@{$confhash{$provider}{'fields'}}) {
15463: $changes{$provider} = 1;
15464: }
15465: }
15466: if (ref($defaults{$provider}) eq 'ARRAY') {
15467: if (@{$defaults{$provider}} > 0) {
15468: my %options;
15469: if (ref($extended{$provider}) eq 'HASH') {
15470: %options = %{$extended{$provider}};
15471: }
15472: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_defaults_'.$provider);
15473: foreach my $field (@{$defaults{$provider}}) {
15474: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
15475: my $poss = $env{'form.proctoring_defaults_'.$field.'_'.$provider};
15476: if (grep(/^\Q$poss\E$/,@{$options{$field}})) {
15477: push(@{$confhash{$provider}{'defaults'}},$poss);
15478: }
15479: } elsif ((exists($options{$field})) && (ref($options{$field}) eq 'HASH')) {
15480: foreach my $inner (keys(%{$options{$field}})) {
15481: if (ref($options{$field}{$inner}) eq 'ARRAY') {
15482: my $poss = $env{'form.proctoring_'.$inner.'_'.$provider};
15483: if (grep(/^\Q$poss\E$/,@{$options{$field}{$inner}})) {
15484: $confhash{$provider}{'defaults'}{$inner} = $poss;
15485: }
15486: } else {
15487: $confhash{$provider}{'defaults'}{$inner} = $env{'form.proctoring_'.$inner.'_'.$provider};
15488: }
15489: }
15490: } else {
15491: if (grep(/^\Q$field\E$/,@checked)) {
15492: push(@{$confhash{$provider}{'defaults'}},$field);
15493: }
15494: }
15495: }
15496: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15497: if (ref($current{'defaults'}) eq 'ARRAY') {
15498: unless ($changes{$provider}) {
15499: my @new = sort(@{$confhash{$provider}{'defaults'}});
15500: my @old = sort(@{$current{'defaults'}});
15501: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15502: if (@diffs) {
15503: $changes{$provider} = 1;
15504: }
15505: }
15506: } elsif (ref($current{'defaults'}) eq 'ARRAY') {
15507: if (@{$current{'defaults'}}) {
15508: $changes{$provider} = 1;
15509: }
15510: }
15511: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15512: if (ref($current{'defaults'}) eq 'HASH') {
15513: unless ($changes{$provider}) {
15514: foreach my $key (keys(%{$confhash{$provider}{'defaults'}})) {
15515: unless ($confhash{$provider}{'defaults'}{$key} eq $current{'defaults'}{$key}) {
15516: $changes{$provider} = 1;
15517: last;
15518: }
15519: }
15520: }
15521: unless ($changes{$provider}) {
15522: foreach my $key (keys(%{$current{'defaults'}})) {
15523: unless ($current{'defaults'}{$key} eq $confhash{$provider}{'defaults'}{$key}) {
15524: $changes{$provider} = 1;
15525: last;
15526: }
15527: }
15528: }
15529: } elsif (keys(%{$confhash{$provider}{'defaults'}})) {
15530: $changes{$provider} = 1;
15531: }
15532: }
15533: }
15534: }
15535: if (ref($crsconf{$provider}) eq 'ARRAY') {
15536: if (@{$crsconf{$provider}} > 0) {
15537: $confhash{$provider}{'crsconf'} = [];
15538: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_crsconf_'.$provider);
15539: foreach my $crsfield (@{$crsconf{$provider}}) {
15540: if (grep(/^\Q$crsfield\E$/,@checked)) {
15541: push(@{$confhash{$provider}{'crsconf'}},$crsfield);
15542: }
15543: }
15544: if (ref($current{'crsconf'}) eq 'ARRAY') {
15545: unless ($changes{$provider}) {
15546: my @new = sort(@{$confhash{$provider}{'crsconf'}});
15547: my @old = sort(@{$current{'crsconf'}});
15548: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15549: if (@diffs) {
15550: $changes{$provider} = 1;
15551: }
15552: }
15553: } elsif (@{$confhash{$provider}{'crsconf'}}) {
15554: $changes{$provider} = 1;
15555: }
15556: }
15557: }
15558: if ($showroles) {
15559: $confhash{$provider}{'roles'} = {};
15560: foreach my $role (@courseroles) {
15561: my $poss = $env{'form.proctoring_roles_'.$role.'_'.$provider};
15562: if (grep(/^\Q$poss\E$/,@ltiroles)) {
15563: $confhash{$provider}{'roles'}{$role} = $poss;
15564: }
15565: }
15566: unless ($changes{$provider}) {
15567: if (ref($current{'roles'}) eq 'HASH') {
15568: foreach my $role (keys(%{$current{'roles'}})) {
15569: unless ($current{'roles'}{$role} eq $confhash{$provider}{'roles'}{$role}) {
15570: $changes{$provider} = 1;
15571: last
15572: }
15573: }
15574: unless ($changes{$provider}) {
15575: foreach my $role (keys(%{$confhash{$provider}{'roles'}})) {
15576: unless ($confhash{$provider}{'roles'}{$role} eq $current{'roles'}{$role}) {
15577: $changes{$provider} = 1;
15578: last;
15579: }
15580: }
15581: }
15582: } elsif (keys(%{$confhash{$provider}{'roles'}})) {
15583: $changes{$provider} = 1;
15584: }
15585: }
15586: }
15587: if (ref($current{'custom'}) eq 'HASH') {
15588: my @customdels = &Apache::loncommon::get_env_multiple('form.proctoring_customdel_'.$provider);
15589: foreach my $key (keys(%{$current{'custom'}})) {
15590: if (grep(/^\Q$key\E$/,@customdels)) {
15591: $changes{$provider} = 1;
15592: } else {
15593: $confhash{$provider}{'custom'}{$key} = $env{'form.proctoring_customval_'.$key.'_'.$provider};
15594: if ($confhash{$provider}{'custom'}{$key} ne $current{'custom'}{$key}) {
15595: $changes{$provider} = 1;
15596: }
15597: }
15598: }
15599: }
15600: if ($customadds{$provider}) {
15601: my $name = $env{'form.proctoring_custom_name_'.$provider};
15602: $name =~ s/(`)/'/g;
15603: $name =~ s/^\s+//;
15604: $name =~ s/\s+$//;
15605: my $value = $env{'form.proctoring_custom_value_'.$provider};
15606: $value =~ s/(`)/'/g;
15607: $value =~ s/^\s+//;
15608: $value =~ s/\s+$//;
15609: if ($name ne '') {
15610: $confhash{$provider}{'custom'}{$name} = $value;
15611: $changes{$provider} = 1;
15612: }
15613: }
15614: }
15615: }
15616: if (@allpos > 0) {
15617: my $idx = 0;
15618: foreach my $provider (@allpos) {
15619: if ($provider ne '') {
15620: $confhash{$provider}{'order'} = $idx;
15621: unless ($changes{$provider}) {
15622: if (ref($domconfig{$action}) eq 'HASH') {
15623: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15624: if ($domconfig{$action}{$provider}{'order'} ne $idx) {
15625: $changes{$provider} = 1;
15626: }
15627: }
15628: }
15629: }
15630: $idx ++;
15631: }
15632: }
15633: }
15634: my %proc_hash = (
15635: $action => { %confhash }
15636: );
15637: my $putresult = &Apache::lonnet::put_dom('configuration',\%proc_hash,
15638: $dom);
15639: if ($putresult eq 'ok') {
15640: my %proc_enchash = (
15641: $action => { %encconfhash }
15642: );
1.384 raeburn 15643: &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom,undef,1);
1.372 raeburn 15644: if (keys(%changes) > 0) {
15645: my $cachetime = 24*60*60;
15646: my %procall = %confhash;
15647: foreach my $provider (keys(%procall)) {
15648: if (ref($encconfhash{$provider}) eq 'HASH') {
15649: foreach my $key ('key','secret') {
15650: $procall{$provider}{$key} = $encconfhash{$provider}{$key};
15651: }
15652: }
15653: }
15654: &Apache::lonnet::do_cache_new('proctoring',$dom,\%procall,$cachetime);
15655: if (ref($lastactref) eq 'HASH') {
15656: $lastactref->{'proctoring'} = 1;
15657: }
15658: $resulttext = &mt('Configuration for Provider(s) with changes:').'<ul>';
15659: my %bynum;
15660: foreach my $provider (sort(keys(%changes))) {
15661: my $position = $confhash{$provider}{'order'};
15662: $bynum{$position} = $provider;
15663: }
15664: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
15665: my $provider = $bynum{$pos};
15666: my %lt = &proctoring_titles($provider);
15667: my %fieldtitles = &proctoring_fieldtitles($provider);
15668: if (!$confhash{$provider}{'available'}) {
15669: $resulttext .= '<li>'.&mt('Proctoring integration unavailable for: [_1]','<b>'.$providernames{$provider}.'</b>').'</li>';
15670: } else {
15671: $resulttext .= '<li>'.&mt('Proctoring integration available for: [_1]','<b>'.$providernames{$provider}.'</b>');
15672: if ($confhash{$provider}{'image'}) {
15673: $resulttext .= ' '.
15674: '<img src="'.$confhash{$provider}{'image'}.'"'.
15675: ' alt="'.&mt('Proctoring icon').'" />';
15676: }
15677: $resulttext .= '<ul>';
15678: my $position = $pos + 1;
15679: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
15680: foreach my $key ('version','sigmethod','url','lifetime') {
15681: if ($confhash{$provider}{$key} ne '') {
15682: $resulttext .= '<li>'.$lt{$key}.': '.$confhash{$provider}{$key}.'</li>';
15683: }
15684: }
15685: if ($encconfhash{$provider}{'key'} ne '') {
15686: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfhash{$provider}{'key'}.'</li>';
15687: }
15688: if ($encconfhash{$provider}{'secret'} ne '') {
15689: $resulttext .= '<li>'.$lt{'secret'}.': ';
15690: my $num = length($encconfhash{$provider}{'secret'});
15691: $resulttext .= ('*'x$num).'</li>';
15692: }
15693: my (@fields,$showroles);
15694: if (ref($requserfields{$provider}) eq 'ARRAY') {
15695: push(@fields,@{$requserfields{$provider}});
15696: }
15697: if (ref($confhash{$provider}{'fields'}) eq 'ARRAY') {
15698: push(@fields,@{$confhash{$provider}{'fields'}});
15699: } elsif (ref($confhash{$provider}{'fields'}) eq 'HASH') {
15700: push(@fields,(keys(%{$confhash{$provider}{'fields'}})));
15701: }
15702: if (@fields) {
15703: if (grep(/^roles$/,@fields)) {
15704: $showroles = 1;
15705: }
15706: $resulttext .= '<li>'.$lt{'udsl'}.': "'.
15707: join('", "', map { $lt{$_}; } @fields).'"</li>';
15708: }
15709: if (ref($requserfields{$provider}) eq 'ARRAY') {
15710: if (grep(/^user$/,@{$requserfields{$provider}})) {
15711: if ($confhash{$provider}{'incdom'}) {
15712: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'uname:dom'}).'</li>';
15713: } else {
15714: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'username'}).'</li>';
15715: }
15716: }
15717: }
15718: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15719: if (@{$confhash{$provider}{'defaults'}} > 0) {
15720: $resulttext .= '<li>'.$lt{'defa'};
15721: foreach my $field (@{$confhash{$provider}{'defaults'}}) {
15722: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15723: }
15724: $resulttext =~ s/,$//;
15725: $resulttext .= '</li>';
15726: }
15727: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15728: if (keys(%{$confhash{$provider}{'defaults'}})) {
15729: $resulttext .= '<li>'.$lt{'defa'}.': <ul>';
15730: foreach my $key (sort(keys(%{$confhash{$provider}{'defaults'}}))) {
15731: if ($confhash{$provider}{'defaults'}{$key} ne '') {
15732: $resulttext .= '<li>'.$fieldtitles{$key}.' = '.$confhash{$provider}{'defaults'}{$key}.'</li>';
15733: }
15734: }
15735: $resulttext .= '</ul></li>';
15736: }
15737: }
15738: if (ref($crsconf{$provider}) eq 'ARRAY') {
15739: if (@{$crsconf{$provider}} > 0) {
15740: $resulttext .= '<li>'.&mt('Configurable in course:');
15741: my $numconfig = 0;
15742: if (ref($confhash{$provider}{'crsconf'}) eq 'ARRAY') {
15743: if (@{$confhash{$provider}{'crsconf'}} > 0) {
15744: foreach my $field (@{$confhash{$provider}{'crsconf'}}) {
15745: $numconfig ++;
15746: if ($provider eq 'examity') {
15747: $resulttext .= ' "'.$lt{'crs'.$field}.'",';
15748: } else {
15749: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15750: }
15751: }
15752: $resulttext =~ s/,$//;
15753: }
15754: }
15755: if (!$numconfig) {
15756: $resulttext .= ' '.&mt('None');
15757: }
15758: $resulttext .= '</li>';
15759: }
15760: }
15761: if ($showroles) {
15762: if (ref($confhash{$provider}{'roles'}) eq 'HASH') {
15763: my $rolemaps;
15764: foreach my $role (@courseroles) {
15765: if ($confhash{$provider}{'roles'}{$role}) {
15766: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
15767: $confhash{$provider}{'roles'}{$role}.',';
15768: }
15769: }
15770: if ($rolemaps) {
15771: $rolemaps =~ s/,$//;
15772: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
15773: }
15774: }
15775: }
15776: if (ref($confhash{$provider}{'custom'}) eq 'HASH') {
15777: my $customlist;
15778: if (keys(%{$confhash{$provider}{'custom'}})) {
15779: foreach my $key (sort(keys(%{$confhash{$provider}{'custom'}}))) {
15780: $customlist .= $key.'='.$confhash{$provider}{'custom'}{$key}.', ';
15781: }
15782: $customlist =~ s/,$//;
15783: }
15784: if ($customlist) {
15785: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
15786: }
15787: }
15788: $resulttext .= '</ul></li>';
15789: }
15790: }
15791: $resulttext .= '</ul>';
15792: } else {
15793: $resulttext = &mt('No changes made.');
15794: }
15795: } else {
15796: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15797: }
15798: if ($errors) {
15799: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15800: $errors.'</ul>';
15801: }
15802: return $resulttext;
15803: }
15804:
15805: sub process_proctoring_image {
15806: my ($r,$dom,$confname,$caller,$provider,$configuserok,$switchserver,$author_ok) = @_;
15807: my $filename = $env{'form.'.$caller.'.filename'};
15808: my ($error,$url);
15809: my ($width,$height) = (21,21);
15810: if ($configuserok eq 'ok') {
15811: if ($switchserver) {
15812: $error = &mt('Upload of Remote Proctoring Provider icon is not permitted to this server: [_1]',
15813: $switchserver);
15814: } elsif ($author_ok eq 'ok') {
1.421 raeburn 15815: my $modified = [];
1.372 raeburn 15816: my ($result,$imageurl,$madethumb) =
1.421 raeburn 15817: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
15818: "proctoring/$provider/icon",$width,$height,
15819: '',$modified);
1.372 raeburn 15820: if ($result eq 'ok') {
15821: if ($madethumb) {
15822: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
15823: my $imagethumb = "$path/tn-".$imagefile;
15824: $url = $imagethumb;
15825: } else {
15826: $url = $imageurl;
15827: }
1.421 raeburn 15828: &update_modify_urls($r,$modified);
1.372 raeburn 15829: } else {
15830: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
15831: }
15832: } else {
15833: $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);
15834: }
15835: } else {
15836: $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);
15837: }
15838: return ($url,$error);
15839: }
15840:
1.320 raeburn 15841: sub modify_lti {
15842: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15843: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.424 raeburn 15844: my ($newid,@allpos,%changes,%confhash,%ltienc,$errors,$resulttext);
1.320 raeburn 15845: my (%posslti,%posslticrs,%posscrstype);
15846: my @courseroles = ('cc','in','ta','ep','st');
15847: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
15848: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
1.392 raeburn 15849: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 15850: my %coursetypetitles = &Apache::lonlocal::texthash (
15851: official => 'Official',
15852: unofficial => 'Unofficial',
15853: community => 'Community',
15854: textbook => 'Textbook',
15855: placement => 'Placement Test',
1.392 raeburn 15856: lti => 'LTI Provider',
1.320 raeburn 15857: );
1.325 raeburn 15858: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 15859: my %lt = <i_names();
15860: map { $posslti{$_} = 1; } @ltiroles;
15861: map { $posslticrs{$_} = 1; } @lticourseroles;
15862: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 15863:
1.326 raeburn 15864: my %menutitles = <imenu_titles();
1.421 raeburn 15865: my (%currltisec,%secchanges,%newltisec,%newltienc,%newkeyset);
1.326 raeburn 15866:
1.421 raeburn 15867: &fetch_secrets($dom,'ltisec',\%domconfig,\%currltisec,\%secchanges,\%newltisec,\%newkeyset);
1.405 raeburn 15868:
1.406 raeburn 15869: my (%linkprotchg,$linkprotoutput,$is_home);
15870: my $proterror = &Apache::courseprefs::process_linkprot($dom,'',$currltisec{'linkprot'},
15871: \%linkprotchg,'domain');
15872: my $home = &Apache::lonnet::domain($dom,'primary');
15873: unless (($home eq 'no_host') || ($home eq '')) {
15874: my @ids=&Apache::lonnet::current_machine_ids();
15875: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; } }
15876: }
15877:
15878: if (keys(%linkprotchg)) {
15879: $secchanges{'linkprot'} = 1;
15880: my %oldlinkprot;
15881: if (ref($currltisec{'linkprot'}) eq 'HASH') {
15882: %oldlinkprot = %{$currltisec{'linkprot'}};
15883: }
15884: foreach my $id (keys(%linkprotchg)) {
15885: if (ref($linkprotchg{$id}) eq 'HASH') {
15886: foreach my $inner (keys(%{$linkprotchg{$id}})) {
15887: if (($inner eq 'secret') || ($inner eq 'key')) {
15888: if ($is_home) {
15889: $newltienc{$id}{$inner} = $linkprotchg{$id}{$inner};
15890: }
15891: }
15892: }
15893: } else {
15894: $newltisec{'linkprot'}{$id} = $linkprotchg{$id};
15895: }
15896: }
15897: $linkprotoutput = &Apache::courseprefs::store_linkprot($dom,'','domain',\%linkprotchg,\%oldlinkprot);
15898: if (keys(%linkprotchg)) {
15899: %{$newltisec{'linkprot'}} = %linkprotchg;
15900: }
15901: }
15902: if (ref($currltisec{'linkprot'}) eq 'HASH') {
1.434 raeburn 15903: foreach my $id (keys(%{$currltisec{'linkprot'}})) {
1.406 raeburn 15904: next if ($id !~ /^\d+$/);
15905: unless (exists($linkprotchg{$id})) {
15906: if (ref($currltisec{'linkprot'}{$id}) eq 'HASH') {
15907: foreach my $inner (keys(%{$currltisec{'linkprot'}{$id}})) {
15908: if (($inner eq 'secret') || ($inner eq 'key')) {
15909: if ($is_home) {
15910: $newltienc{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15911: }
15912: } else {
15913: $newltisec{'linkprot'}{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15914: }
15915: }
15916: } else {
15917: $newltisec{'linkprot'}{$id} = $currltisec{'linkprot'}{$id};
15918: }
15919: }
15920: }
15921: }
15922: if ($proterror) {
15923: $errors .= '<li>'.$proterror.'</li>';
15924: }
1.434 raeburn 15925:
15926: my (%delsuggested,%suggids,@suggested);;
15927: if (ref($currltisec{'suggested'}) eq 'HASH') {
15928: my $maxnum = $env{'form.linkprot_suggested_maxnum'};
15929: my @todelete = &Apache::loncommon::get_env_multiple('form.linkprot_suggested_del');
15930: for (my $i=0; $i<$maxnum; $i++) {
15931: my $itemid = $env{'form.linkprot_suggested_id_'.$i};
15932: $itemid =~ s/\D+//g;
15933: if ($itemid) {
15934: if (ref($currltisec{'suggested'}->{$itemid}) eq 'HASH') {
15935: push(@suggested,$i);
15936: $suggids{$i} = $itemid;
15937: if ((@todelete > 0) && (grep(/^$i$/,@todelete))) {
15938: if (ref($currltisec{'suggested'}{$itemid}) eq 'HASH') {
15939: $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
15940: }
15941: } else {
15942: if ($env{'form.linkprot_suggested_name_'.$i} eq '') {
15943: $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
15944: } else {
15945: $env{'form.linkprot_suggested_name_'.$i} =~ s/(`)/'/g;
15946: $env{'form.linkprot_suggested_info_'.$i} =~ s/(`)/'/g;
15947: $newltisec{'suggested'}{$itemid}{'name'} = $env{'form.linkprot_suggested_name_'.$i};
15948: $newltisec{'suggested'}{$itemid}{'info'} = $env{'form.linkprot_suggested_info_'.$i};
15949: if (($currltisec{'suggested'}{$itemid}{'name'} ne $newltisec{'suggested'}{$itemid}{'name'}) ||
15950: ($currltisec{'suggested'}{$itemid}{'info'} ne $newltisec{'suggested'}{$itemid}{'info'})) {
15951: $secchanges{'suggested'}{$itemid} = 1;
15952: }
15953: }
15954: }
15955: }
15956: }
15957: }
15958: }
15959: foreach my $key (keys(%delsuggested)) {
15960: $newltisec{'suggested'}{$key} = $delsuggested{$key};
15961: $secchanges{'suggested'}{$key} = 1;
15962: }
15963: if (($env{'form.linkprot_suggested_add'}) &&
15964: ($env{'form.linkprot_suggested_name_add'} ne '')) {
15965: $env{'form.linkprot_suggested_name_add'} =~ s/(`)/'/g;
15966: $env{'form.linkprot_suggested_info_add'} =~ s/(`)/'/g;
15967: my ($newsuggid,$errormsg) = &get_lti_id($dom,$env{'form.linkprot_suggested_name_add'},'suggested');
15968: if ($newsuggid) {
15969: $newltisec{'suggested'}{$newsuggid}{'name'} = $env{'form.linkprot_suggested_name_add'};
15970: $newltisec{'suggested'}{$newsuggid}{'info'} = $env{'form.linkprot_suggested_info_add'};
15971: $secchanges{'suggested'}{$newsuggid} = 1;
15972: } else {
15973: my $error = &mt('Failed to acquire unique ID for new Link Protectors in Courses Suggestion');
15974: if ($errormsg) {
15975: $error .= ' ('.$errormsg.')';
15976: }
15977: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15978: }
15979: }
1.320 raeburn 15980: my (@items,%deletions,%itemids);
15981: if ($env{'form.lti_add'}) {
15982: my $consumer = $env{'form.lti_consumer_add'};
15983: $consumer =~ s/(`)/'/g;
1.434 raeburn 15984: ($newid,my $errormsg) = &get_lti_id($dom,$consumer,'lti');
1.320 raeburn 15985: if ($newid) {
15986: $itemids{'add'} = $newid;
15987: push(@items,'add');
15988: $changes{$newid} = 1;
15989: } else {
15990: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
1.434 raeburn 15991: if ($errormsg) {
15992: $error .= ' ('.$errormsg.')';
15993: }
1.320 raeburn 15994: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15995: }
15996: }
15997: if (ref($domconfig{$action}) eq 'HASH') {
15998: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
15999: if (@todelete) {
16000: map { $deletions{$_} = 1; } @todelete;
16001: }
16002: my $maxnum = $env{'form.lti_maxnum'};
1.390 raeburn 16003: for (my $i=0; $i<$maxnum; $i++) {
1.320 raeburn 16004: my $itemid = $env{'form.lti_id_'.$i};
16005: $itemid =~ s/\D+//g;
16006: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
16007: if ($deletions{$itemid}) {
16008: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
16009: } else {
1.390 raeburn 16010: push(@items,$i);
16011: $itemids{$i} = $itemid;
1.320 raeburn 16012: }
16013: }
16014: }
16015: }
1.424 raeburn 16016: my (%keystore,$secstored);
16017: if ($is_home) {
16018: &store_security($dom,'lti',\%secchanges,\%newkeyset,\%keystore);
16019: }
16020:
16021: my ($cipher,$privnum);
16022: if ((@items > 0) && ($is_home)) {
16023: ($cipher,$privnum) = &get_priv_creds($dom,$home,$secchanges{'encrypt'},
16024: $newltisec{'encrypt'},$keystore{$home});
16025: }
1.320 raeburn 16026: foreach my $idx (@items) {
16027: my $itemid = $itemids{$idx};
16028: next unless ($itemid);
1.424 raeburn 16029: my %currlti;
16030: unless ($idx eq 'add') {
16031: if (ref($domconfig{$action}) eq 'HASH') {
16032: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
16033: %currlti = %{$domconfig{$action}{$itemid}};
16034: }
16035: }
16036: }
1.390 raeburn 16037: my $position = $env{'form.lti_pos_'.$itemid};
1.320 raeburn 16038: $position =~ s/\D+//g;
16039: if ($position ne '') {
16040: $allpos[$position] = $itemid;
16041: }
1.424 raeburn 16042: foreach my $item ('consumer','lifetime','requser','crsinc') {
1.320 raeburn 16043: my $formitem = 'form.lti_'.$item.'_'.$idx;
16044: $env{$formitem} =~ s/(`)/'/g;
16045: if ($item eq 'lifetime') {
16046: $env{$formitem} =~ s/[^\d.]//g;
16047: }
16048: if ($env{$formitem} ne '') {
1.424 raeburn 16049: $confhash{$itemid}{$item} = $env{$formitem};
16050: unless (($idx eq 'add') || ($changes{$itemid})) {
16051: if ($currlti{$item} ne $confhash{$itemid}{$item}) {
16052: $changes{$itemid} = 1;
1.320 raeburn 16053: }
16054: }
16055: }
16056: }
16057: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
16058: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
16059: }
1.345 raeburn 16060: if ($confhash{$itemid}{'requser'}) {
16061: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
1.405 raeburn 16062: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
1.345 raeburn 16063: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
16064: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
16065: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
16066: my $mapuser = $env{'form.lti_customuser_'.$idx};
16067: $mapuser =~ s/(`)/'/g;
1.405 raeburn 16068: $mapuser =~ s/^\s+|\s+$//g;
16069: $confhash{$itemid}{'mapuser'} = $mapuser;
1.345 raeburn 16070: }
16071: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
16072: my @makeuser;
16073: foreach my $ltirole (sort(@possmakeuser)) {
16074: if ($posslti{$ltirole}) {
16075: push(@makeuser,$ltirole);
16076: }
16077: }
16078: $confhash{$itemid}{'makeuser'} = \@makeuser;
16079: if (@makeuser) {
16080: my $lcauth = $env{'form.lti_lcauth_'.$idx};
16081: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
16082: $confhash{$itemid}{'lcauth'} = $lcauth;
16083: if ($lcauth ne 'internal') {
16084: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
16085: $lcauthparm =~ s/^(\s+|\s+)$//g;
16086: $lcauthparm =~ s/`//g;
16087: if ($lcauthparm ne '') {
16088: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
16089: }
16090: }
16091: } else {
16092: $confhash{$itemid}{'lcauth'} = 'lti';
16093: }
1.320 raeburn 16094: }
1.345 raeburn 16095: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
16096: if (@possinstdata) {
16097: foreach my $field (@possinstdata) {
16098: if (exists($fieldtitles{$field})) {
16099: push(@{$confhash{$itemid}{'instdata'}});
1.325 raeburn 16100: }
16101: }
16102: }
1.363 raeburn 16103: if ($env{'form.lti_callback_'.$idx}) {
16104: if ($env{'form.lti_callbackparam_'.$idx}) {
16105: my $callback = $env{'form.lti_callbackparam_'.$idx};
16106: $callback =~ s/^\s+|\s+$//g;
16107: $confhash{$itemid}{'callback'} = $callback;
16108: }
16109: }
1.391 raeburn 16110: foreach my $field ('topmenu','inlinemenu') {
1.345 raeburn 16111: if ($env{'form.lti_'.$field.'_'.$idx}) {
16112: $confhash{$itemid}{$field} = 1;
16113: }
1.320 raeburn 16114: }
1.345 raeburn 16115: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
16116: $confhash{$itemid}{lcmenu} = [];
16117: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
16118: foreach my $field (@possmenu) {
16119: if (exists($menutitles{$field})) {
16120: if ($field eq 'grades') {
16121: next unless ($env{'form.lti_inlinemenu_'.$idx});
16122: }
16123: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 16124: }
16125: }
16126: }
1.391 raeburn 16127: if ($confhash{$itemid}{'crsinc'}) {
16128: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
16129: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
16130: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
16131: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
16132: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
16133: $mapcrs =~ s/(`)/'/g;
16134: $mapcrs =~ s/^\s+|\s+$//g;
16135: $confhash{$itemid}{'mapcrs'} = $mapcrs;
16136: }
16137: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
16138: my @crstypes;
16139: foreach my $type (sort(@posstypes)) {
16140: if ($posscrstype{$type}) {
16141: push(@crstypes,$type);
16142: }
16143: }
16144: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
1.392 raeburn 16145: if ($env{'form.lti_storecrs_'.$idx}) {
16146: $confhash{$itemid}{'storecrs'} = 1;
16147: }
1.391 raeburn 16148: if ($env{'form.lti_makecrs_'.$idx}) {
16149: $confhash{$itemid}{'makecrs'} = 1;
16150: }
16151: foreach my $ltirole (@lticourseroles) {
16152: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
16153: if (grep(/^\Q$possrole\E$/,@courseroles)) {
16154: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
16155: }
16156: }
16157: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
16158: my @selfenroll;
16159: foreach my $type (sort(@possenroll)) {
16160: if ($posslticrs{$type}) {
16161: push(@selfenroll,$type);
16162: }
16163: }
16164: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
16165: if ($env{'form.lti_crssec_'.$idx}) {
16166: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
16167: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
16168: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
16169: my $section = $env{'form.lti_customsection_'.$idx};
16170: $section =~ s/(`)/'/g;
16171: $section =~ s/^\s+|\s+$//g;
16172: if ($section ne '') {
16173: $confhash{$itemid}{'section'} = $section;
16174: }
16175: }
16176: }
16177: foreach my $field ('passback','roster') {
16178: if ($env{'form.lti_'.$field.'_'.$idx}) {
16179: $confhash{$itemid}{$field} = 1;
16180: }
16181: }
16182: if ($env{'form.lti_passback_'.$idx}) {
16183: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
16184: $confhash{$itemid}{'passbackformat'} = '1.0';
16185: } else {
16186: $confhash{$itemid}{'passbackformat'} = '1.1';
1.337 raeburn 16187: }
16188: }
1.391 raeburn 16189: }
16190: unless (($idx eq 'add') || ($changes{$itemid})) {
16191: if ($confhash{$itemid}{'crsinc'}) {
1.392 raeburn 16192: foreach my $field ('mapcrs','storecrs','makecrs','section','passback','roster') {
1.424 raeburn 16193: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.320 raeburn 16194: $changes{$itemid} = 1;
16195: }
1.345 raeburn 16196: }
16197: unless ($changes{$itemid}) {
1.424 raeburn 16198: if ($currlti{'passback'} eq $confhash{$itemid}{'passback'}) {
16199: if ($currlti{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 16200: $changes{$itemid} = 1;
16201: }
16202: }
1.345 raeburn 16203: }
1.391 raeburn 16204: foreach my $field ('mapcrstype','selfenroll') {
16205: unless ($changes{$itemid}) {
1.424 raeburn 16206: if (ref($currlti{$field}) eq 'ARRAY') {
1.391 raeburn 16207: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424 raeburn 16208: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391 raeburn 16209: $confhash{$itemid}{$field});
16210: if (@diffs) {
16211: $changes{$itemid} = 1;
16212: }
1.424 raeburn 16213: } elsif (@{$currlti{$field}} > 0) {
1.391 raeburn 16214: $changes{$itemid} = 1;
16215: }
16216: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
16217: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 16218: $changes{$itemid} = 1;
16219: }
16220: }
1.391 raeburn 16221: }
16222: }
16223: unless ($changes{$itemid}) {
1.424 raeburn 16224: if (ref($currlti{'maproles'}) eq 'HASH') {
1.391 raeburn 16225: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
1.424 raeburn 16226: foreach my $ltirole (keys(%{$currlti{'maproles'}})) {
16227: if ($currlti{'maproles'}{$ltirole} ne
1.391 raeburn 16228: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.345 raeburn 16229: $changes{$itemid} = 1;
16230: last;
16231: }
16232: }
1.391 raeburn 16233: unless ($changes{$itemid}) {
16234: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
16235: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
1.424 raeburn 16236: $currlti{'maproles'}{$ltirole}) {
1.391 raeburn 16237: $changes{$itemid} = 1;
16238: last;
16239: }
16240: }
16241: }
1.424 raeburn 16242: } elsif (keys(%{$currlti{'maproles'}}) > 0) {
1.391 raeburn 16243: $changes{$itemid} = 1;
1.345 raeburn 16244: }
1.391 raeburn 16245: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16246: unless ($changes{$itemid}) {
16247: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
16248: $changes{$itemid} = 1;
16249: }
16250: }
16251: }
16252: }
16253: }
16254: unless ($changes{$itemid}) {
16255: foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
1.424 raeburn 16256: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.345 raeburn 16257: $changes{$itemid} = 1;
1.320 raeburn 16258: }
1.391 raeburn 16259: }
16260: unless ($changes{$itemid}) {
16261: foreach my $field ('makeuser','lcmenu') {
1.424 raeburn 16262: if (ref($currlti{$field}) eq 'ARRAY') {
1.391 raeburn 16263: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424 raeburn 16264: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391 raeburn 16265: $confhash{$itemid}{$field});
16266: if (@diffs) {
16267: $changes{$itemid} = 1;
16268: }
1.424 raeburn 16269: } elsif (@{$currlti{$field}} > 0) {
1.391 raeburn 16270: $changes{$itemid} = 1;
16271: }
16272: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
16273: if (@{$confhash{$itemid}{$field}} > 0) {
16274: $changes{$itemid} = 1;
16275: }
1.345 raeburn 16276: }
1.320 raeburn 16277: }
16278: }
16279: }
16280: }
16281: }
1.424 raeburn 16282: if ($is_home) {
16283: my $keyitem = 'form.lti_key_'.$idx;
16284: $env{$keyitem} =~ s/(`)/'/g;
16285: if ($env{$keyitem} ne '') {
16286: $ltienc{$itemid}{'key'} = $env{$keyitem};
16287: unless ($changes{$itemid}) {
16288: if ($currlti{'key'} ne $env{$keyitem}) {
16289: $changes{$itemid} = 1;
16290: }
16291: }
16292: }
16293: my $secretitem = 'form.lti_secret_'.$idx;
16294: $env{$secretitem} =~ s/(`)/'/g;
16295: if ($currlti{'usable'}) {
16296: if ($env{'form.lti_changesecret_'.$idx}) {
16297: if ($env{$secretitem} ne '') {
16298: if ($privnum && $cipher) {
16299: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
16300: $confhash{$itemid}{'cipher'} = $privnum;
16301: } else {
16302: $ltienc{$itemid}{'secret'} = $env{$secretitem};
16303: }
16304: $changes{$itemid} = 1;
16305: }
16306: } else {
16307: $ltienc{$itemid}{'secret'} = $currlti{'secret'};
16308: $confhash{$itemid}{'cipher'} = $currlti{'cipher'};
16309: }
16310: if (ref($ltienc{$itemid}) eq 'HASH') {
16311: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'secret'} ne '')) {
16312: $confhash{$itemid}{'usable'} = 1;
16313: }
16314: }
16315: } elsif ($env{$secretitem} ne '') {
16316: if ($privnum && $cipher) {
16317: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
16318: $confhash{$itemid}{'cipher'} = $privnum;
16319: } else {
16320: $ltienc{$itemid}{'secret'} = $env{$secretitem};
16321: }
16322: if (ref($ltienc{$itemid}) eq 'HASH') {
16323: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'key'} ne '')) {
16324: $confhash{$itemid}{'usable'} = 1;
16325: }
16326: }
16327: $changes{$itemid} = 1;
16328: }
16329: }
16330: unless ($changes{$itemid}) {
16331: foreach my $key (keys(%currlti)) {
16332: if (ref($currlti{$key}) eq 'HASH') {
16333: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
16334: foreach my $innerkey (keys(%{$currlti{$key}})) {
16335: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
16336: $changes{$itemid} = 1;
16337: last;
16338: }
16339: }
16340: } elsif (keys(%{$currlti{$key}}) > 0) {
16341: $changes{$itemid} = 1;
16342: }
16343: }
16344: last if ($changes{$itemid});
16345: }
16346: }
1.320 raeburn 16347: }
16348: if (@allpos > 0) {
16349: my $idx = 0;
16350: foreach my $itemid (@allpos) {
16351: if ($itemid ne '') {
16352: $confhash{$itemid}{'order'} = $idx;
16353: if (ref($domconfig{$action}) eq 'HASH') {
16354: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
16355: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
16356: $changes{$itemid} = 1;
16357: }
16358: }
16359: }
16360: $idx ++;
16361: }
16362: }
16363: }
1.424 raeburn 16364:
16365: if ((keys(%changes) == 0) && (keys(%secchanges) == 0)) {
16366: return &mt('No changes made.');
16367: }
16368:
1.320 raeburn 16369: my %ltihash = (
1.405 raeburn 16370: $action => { %confhash }
16371: );
1.424 raeburn 16372: my %ltienchash;
16373:
16374: if ($is_home) {
16375: %ltienchash = (
16376: $action => { %ltienc }
16377: );
16378: }
1.405 raeburn 16379: if (keys(%secchanges)) {
16380: $ltihash{'ltisec'} = \%newltisec;
1.406 raeburn 16381: if ($secchanges{'linkprot'}) {
16382: if ($is_home) {
16383: $ltienchash{'linkprot'} = \%newltienc;
16384: }
16385: }
1.405 raeburn 16386: }
16387: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,$dom);
1.320 raeburn 16388: if ($putresult eq 'ok') {
1.424 raeburn 16389: if (keys(%ltienchash)) {
16390: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.405 raeburn 16391: }
16392: $resulttext = &mt('Changes made:').'<ul>';
16393: if (keys(%secchanges) > 0) {
1.423 raeburn 16394: $resulttext .= <i_security_results($dom,'lti',\%secchanges,\%newltisec,\%newkeyset,\%keystore);
1.421 raeburn 16395: if (exists($secchanges{'linkprot'})) {
16396: $resulttext .= $linkprotoutput;
1.405 raeburn 16397: }
16398: }
1.320 raeburn 16399: if (keys(%changes) > 0) {
16400: my $cachetime = 24*60*60;
1.424 raeburn 16401: &Apache::lonnet::do_cache_new('lti',$dom,\%confhash,$cachetime);
1.320 raeburn 16402: if (ref($lastactref) eq 'HASH') {
16403: $lastactref->{'lti'} = 1;
16404: }
16405: my %bynum;
16406: foreach my $itemid (sort(keys(%changes))) {
1.424 raeburn 16407: if (ref($confhash{$itemid}) eq 'HASH') {
16408: my $position = $confhash{$itemid}{'order'};
16409: $bynum{$position} = $itemid;
16410: }
1.320 raeburn 16411: }
16412: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
16413: my $itemid = $bynum{$pos};
1.424 raeburn 16414: if (ref($confhash{$itemid}) eq 'HASH') {
1.390 raeburn 16415: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1.320 raeburn 16416: my $position = $pos + 1;
16417: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
16418: foreach my $item ('version','lifetime') {
16419: if ($confhash{$itemid}{$item} ne '') {
16420: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
16421: }
16422: }
1.424 raeburn 16423: if ($ltienc{$itemid}{'key'} ne '') {
16424: $resulttext .= '<li>'.$lt{'key'}.': '.$ltienc{$itemid}{'key'}.'</li>';
1.320 raeburn 16425: }
1.424 raeburn 16426: if ($ltienc{$itemid}{'secret'} ne '') {
16427: $resulttext .= '<li>'.$lt{'secret'}.': ['.&mt('not shown').']</li>';
1.320 raeburn 16428: }
1.345 raeburn 16429: if ($confhash{$itemid}{'requser'}) {
1.391 raeburn 16430: if ($confhash{$itemid}{'callback'}) {
16431: $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
16432: } else {
1.392 raeburn 16433: $resulttext .= '<li>'.&mt('Callback to logout LON-CAPA on log out from Consumer').'</li>';
1.391 raeburn 16434: }
1.345 raeburn 16435: if ($confhash{$itemid}{'mapuser'}) {
16436: my $shownmapuser;
16437: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
16438: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
16439: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
16440: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
16441: } else {
16442: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 16443: }
1.345 raeburn 16444: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 16445: }
1.345 raeburn 16446: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
16447: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
16448: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
16449: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
16450: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
16451: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
16452: } else {
16453: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
16454: $confhash{$itemid}{'lcauth'});
16455: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
16456: $resulttext .= '; '.&mt('a randomly generated password will be created');
16457: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
16458: if ($confhash{$itemid}{'lcauthparm'} ne '') {
16459: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
16460: }
16461: } else {
16462: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
16463: }
16464: }
16465: $resulttext .= '</li>';
16466: } else {
16467: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
16468: }
1.320 raeburn 16469: }
1.345 raeburn 16470: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
16471: if (@{$confhash{$itemid}{'instdata'}} > 0) {
16472: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
16473: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 16474: } else {
1.345 raeburn 16475: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325 raeburn 16476: }
1.320 raeburn 16477: }
1.391 raeburn 16478: foreach my $item ('topmenu','inlinemenu') {
1.345 raeburn 16479: $resulttext .= '<li>'.$lt{$item}.': ';
16480: if ($confhash{$itemid}{$item}) {
16481: $resulttext .= &mt('Yes');
16482: } else {
16483: $resulttext .= &mt('No');
1.337 raeburn 16484: }
1.345 raeburn 16485: $resulttext .= '</li>';
1.320 raeburn 16486: }
1.345 raeburn 16487: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16488: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16489: $resulttext .= '<li>'.&mt('Menu items:').' '.
1.391 raeburn 16490: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16491: } else {
16492: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16493: }
16494: }
16495: if ($confhash{$itemid}{'crsinc'}) {
16496: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16497: my $rolemaps;
16498: foreach my $role (@ltiroles) {
16499: if ($confhash{$itemid}{'maproles'}{$role}) {
16500: $rolemaps .= (' 'x2).$role.'='.
16501: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
16502: 'Course').',';
16503: }
16504: }
16505: if ($rolemaps) {
16506: $rolemaps =~ s/,$//;
16507: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
16508: }
16509: }
16510: if ($confhash{$itemid}{'mapcrs'}) {
16511: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
16512: }
16513: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
16514: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
16515: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
16516: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
16517: '</li>';
16518: } else {
16519: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
16520: }
16521: }
1.392 raeburn 16522: if ($confhash{$itemid}{'storecrs'}) {
16523: $resulttext .= '<li>'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.$confhash{$itemid}{'storecrs'}.'</li>';
16524: }
1.391 raeburn 16525: if ($confhash{$itemid}{'makecrs'}) {
16526: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
16527: } else {
16528: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
16529: }
16530: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
16531: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
16532: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
16533: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
16534: '</li>';
16535: } else {
16536: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
16537: }
16538: }
16539: if ($confhash{$itemid}{'section'}) {
16540: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
16541: $resulttext .= '<li>'.&mt('User section from standard field:').
16542: ' (course_section_sourcedid)'.'</li>';
16543: } else {
16544: $resulttext .= '<li>'.&mt('User section from:').' '.
16545: $confhash{$itemid}{'section'}.'</li>';
16546: }
1.345 raeburn 16547: } else {
1.391 raeburn 16548: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
16549: }
16550: foreach my $item ('passback','roster','topmenu','inlinemenu') {
16551: $resulttext .= '<li>'.$lt{$item}.': ';
16552: if ($confhash{$itemid}{$item}) {
16553: $resulttext .= &mt('Yes');
16554: if ($item eq 'passback') {
16555: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
16556: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
16557: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
16558: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
16559: }
16560: }
16561: } else {
16562: $resulttext .= &mt('No');
16563: }
16564: $resulttext .= '</li>';
16565: }
16566: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16567: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16568: $resulttext .= '<li>'.&mt('Menu items:').' '.
16569: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16570: } else {
16571: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16572: }
1.345 raeburn 16573: }
1.326 raeburn 16574: }
16575: }
1.320 raeburn 16576: $resulttext .= '</ul></li>';
16577: }
16578: }
1.424 raeburn 16579: if (keys(%deletions)) {
16580: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
16581: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
16582: }
16583: }
1.320 raeburn 16584: }
1.405 raeburn 16585: $resulttext .= '</ul>';
1.424 raeburn 16586: if (ref($lastactref) eq 'HASH') {
1.434 raeburn 16587: if (($secchanges{'encrypt'}) || ($secchanges{'private'}) || (exists($secchanges{'suggested'}))) {
16588: &Apache::lonnet::get_domain_defaults($dom,1);
1.424 raeburn 16589: $lastactref->{'domdefaults'} = 1;
16590: }
16591: }
1.320 raeburn 16592: } else {
16593: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
16594: }
16595: if ($errors) {
16596: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
16597: $errors.'</ul>';
16598: }
16599: return $resulttext;
16600: }
16601:
1.424 raeburn 16602: sub get_priv_creds {
16603: my ($dom,$home,$encchg,$encrypt,$storedsec) = @_;
16604: my ($needenc,$cipher,$privnum);
16605: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
16606: if (($encchg) && (ref($encrypt) eq 'HASH')) {
16607: $needenc = $encrypt->{'consumers'}
16608: } else {
16609: $needenc = $domdefs{'ltienc_consumers'};
16610: }
16611: if ($needenc) {
16612: if (($storedsec eq 'ok') || ((ref($domdefs{'ltiprivhosts'}) eq 'ARRAY') &&
16613: (grep(/^\Q$home\E$/,@{$domdefs{'ltiprivhosts'}})))) {
16614: my %privhash = &Apache::lonnet::restore_dom('lti','private',$dom,$home,1);
16615: my $privkey = $privhash{'key'};
16616: $privnum = $privhash{'version'};
16617: if (($privnum) && ($privkey ne '')) {
16618: $cipher = Crypt::CBC->new({'key' => $privkey,
16619: 'cipher' => 'DES'});
16620: }
16621: }
16622: }
16623: return ($cipher,$privnum);
16624: }
16625:
1.320 raeburn 16626: sub get_lti_id {
1.434 raeburn 16627: my ($domain,$consumer,$dbname) = @_;
16628: unless (($dbname eq 'lti') || ($dbname eq 'suggested')) {
16629: return ('','invalid db');
16630: }
16631: # get lock on db
1.320 raeburn 16632: my $lockhash = {
16633: lock => $env{'user.name'}.
16634: ':'.$env{'user.domain'},
16635: };
16636: my $tries = 0;
1.434 raeburn 16637: my $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1.320 raeburn 16638: my ($id,$error);
16639:
16640: while (($gotlock ne 'ok') && ($tries<10)) {
16641: $tries ++;
16642: sleep (0.1);
1.434 raeburn 16643: $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1.320 raeburn 16644: }
16645: if ($gotlock eq 'ok') {
1.434 raeburn 16646: my %currids = &Apache::lonnet::dump_dom($dbname,$domain);
1.320 raeburn 16647: if ($currids{'lock'}) {
16648: delete($currids{'lock'});
16649: if (keys(%currids)) {
16650: my @curr = sort { $a <=> $b } keys(%currids);
16651: if ($curr[-1] =~ /^\d+$/) {
16652: $id = 1 + $curr[-1];
16653: }
16654: } else {
16655: $id = 1;
16656: }
16657: if ($id) {
1.434 raeburn 16658: unless (&Apache::lonnet::newput_dom($dbname,{ $id => $consumer },$domain) eq 'ok') {
1.320 raeburn 16659: $error = 'nostore';
16660: }
16661: } else {
16662: $error = 'nonumber';
16663: }
16664: }
1.434 raeburn 16665: my $dellockoutcome = &Apache::lonnet::del_dom($dbname,['lock'],$domain);
1.320 raeburn 16666: } else {
16667: $error = 'nolock';
16668: }
16669: return ($id,$error);
16670: }
16671:
1.3 raeburn 16672: sub modify_autoenroll {
1.205 raeburn 16673: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 16674: my ($resulttext,%changes);
16675: my %currautoenroll;
16676: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
16677: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
16678: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
16679: }
16680: }
16681: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
16682: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 16683: sender => 'Sender for notification messages',
1.274 raeburn 16684: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.399 raeburn 16685: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 16686: my @offon = ('off','on');
1.17 raeburn 16687: my $sender_uname = $env{'form.sender_uname'};
16688: my $sender_domain = $env{'form.sender_domain'};
16689: if ($sender_domain eq '') {
16690: $sender_uname = '';
16691: } elsif ($sender_uname eq '') {
16692: $sender_domain = '';
16693: }
1.129 raeburn 16694: my $coowners = $env{'form.autoassign_coowners'};
1.399 raeburn 16695: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
16696: $autofailsafe =~ s{^\s+|\s+$}{}g;
16697: if ($autofailsafe =~ /\D/) {
16698: undef($autofailsafe);
16699: }
1.274 raeburn 16700: my $failsafe = $env{'form.autoenroll_failsafe'};
1.399 raeburn 16701: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
16702: $failsafe = 'off';
1.400 raeburn 16703: undef($autofailsafe);
1.274 raeburn 16704: }
1.1 raeburn 16705: my %autoenrollhash = (
1.129 raeburn 16706: autoenroll => { 'run' => $env{'form.autoenroll_run'},
16707: 'sender_uname' => $sender_uname,
16708: 'sender_domain' => $sender_domain,
16709: 'co-owners' => $coowners,
1.399 raeburn 16710: 'autofailsafe' => $autofailsafe,
1.400 raeburn 16711: 'failsafe' => $failsafe,
1.1 raeburn 16712: }
16713: );
1.4 raeburn 16714: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
16715: $dom);
1.1 raeburn 16716: if ($putresult eq 'ok') {
16717: if (exists($currautoenroll{'run'})) {
16718: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
16719: $changes{'run'} = 1;
16720: }
16721: } elsif ($autorun) {
16722: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 16723: $changes{'run'} = 1;
1.1 raeburn 16724: }
16725: }
1.17 raeburn 16726: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 16727: $changes{'sender'} = 1;
16728: }
1.17 raeburn 16729: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 16730: $changes{'sender'} = 1;
16731: }
1.129 raeburn 16732: if ($currautoenroll{'co-owners'} ne '') {
16733: if ($currautoenroll{'co-owners'} ne $coowners) {
16734: $changes{'coowners'} = 1;
16735: }
16736: } elsif ($coowners) {
16737: $changes{'coowners'} = 1;
1.274 raeburn 16738: }
1.399 raeburn 16739: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.274 raeburn 16740: $changes{'autofailsafe'} = 1;
16741: }
1.399 raeburn 16742: if ($currautoenroll{'failsafe'} ne $failsafe) {
16743: $changes{'failsafe'} = 1;
16744: }
1.1 raeburn 16745: if (keys(%changes) > 0) {
16746: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 16747: if ($changes{'run'}) {
1.1 raeburn 16748: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
16749: }
16750: if ($changes{'sender'}) {
1.17 raeburn 16751: if ($sender_uname eq '' || $sender_domain eq '') {
16752: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
16753: } else {
16754: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
16755: }
1.1 raeburn 16756: }
1.129 raeburn 16757: if ($changes{'coowners'}) {
16758: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
16759: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 16760: if (ref($lastactref) eq 'HASH') {
16761: $lastactref->{'domainconfig'} = 1;
16762: }
1.129 raeburn 16763: }
1.274 raeburn 16764: if ($changes{'autofailsafe'}) {
1.399 raeburn 16765: if ($autofailsafe ne '') {
16766: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.274 raeburn 16767: } else {
1.399 raeburn 16768: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.274 raeburn 16769: }
1.399 raeburn 16770: }
16771: if ($changes{'failsafe'}) {
16772: if ($failsafe eq 'off') {
16773: unless ($changes{'autofailsafe'}) {
16774: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
16775: }
16776: } elsif ($failsafe eq 'zero') {
16777: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
16778: } else {
16779: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
16780: }
16781: }
16782: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.274 raeburn 16783: &Apache::lonnet::get_domain_defaults($dom,1);
16784: if (ref($lastactref) eq 'HASH') {
16785: $lastactref->{'domdefaults'} = 1;
16786: }
16787: }
1.1 raeburn 16788: $resulttext .= '</ul>';
16789: } else {
16790: $resulttext = &mt('No changes made to auto-enrollment settings');
16791: }
16792: } else {
1.11 albertel 16793: $resulttext = '<span class="LC_error">'.
16794: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16795: }
1.3 raeburn 16796: return $resulttext;
1.1 raeburn 16797: }
16798:
16799: sub modify_autoupdate {
1.3 raeburn 16800: my ($dom,%domconfig) = @_;
1.1 raeburn 16801: my ($resulttext,%currautoupdate,%fields,%changes);
16802: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
16803: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
16804: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
16805: }
16806: }
16807: my @offon = ('off','on');
16808: my %title = &Apache::lonlocal::texthash (
1.385 raeburn 16809: run => 'Auto-update:',
16810: classlists => 'Updates to user information in classlists?',
16811: unexpired => 'Skip updates for users without active or future roles?',
16812: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 16813: );
1.44 raeburn 16814: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 16815: my %fieldtitles = &Apache::lonlocal::texthash (
16816: id => 'Student/Employee ID',
1.20 raeburn 16817: permanentemail => 'E-mail address',
1.1 raeburn 16818: lastname => 'Last Name',
16819: firstname => 'First Name',
16820: middlename => 'Middle Name',
1.132 raeburn 16821: generation => 'Generation',
1.1 raeburn 16822: );
1.142 raeburn 16823: $othertitle = &mt('All users');
1.1 raeburn 16824: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 16825: $othertitle = &mt('Other users');
1.1 raeburn 16826: }
16827: foreach my $key (keys(%env)) {
16828: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 16829: my ($usertype,$item) = ($1,$2);
16830: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
16831: if ($usertype eq 'default') {
16832: push(@{$fields{$1}},$2);
16833: } elsif (ref($types) eq 'ARRAY') {
16834: if (grep(/^\Q$usertype\E$/,@{$types})) {
16835: push(@{$fields{$1}},$2);
16836: }
16837: }
16838: }
1.1 raeburn 16839: }
16840: }
1.131 raeburn 16841: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
16842: @lockablenames = sort(@lockablenames);
16843: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
16844: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16845: if (@changed) {
16846: $changes{'lockablenames'} = 1;
16847: }
16848: } else {
16849: if (@lockablenames) {
16850: $changes{'lockablenames'} = 1;
16851: }
16852: }
1.1 raeburn 16853: my %updatehash = (
16854: autoupdate => { run => $env{'form.autoupdate_run'},
16855: classlists => $env{'form.classlists'},
1.385 raeburn 16856: unexpired => $env{'form.unexpired'},
1.1 raeburn 16857: fields => {%fields},
1.131 raeburn 16858: lockablenames => \@lockablenames,
1.1 raeburn 16859: }
16860: );
1.385 raeburn 16861: my $lastactivedays;
16862: if ($env{'form.lastactive'}) {
16863: $lastactivedays = $env{'form.lastactivedays'};
16864: $lastactivedays =~ s/^\s+|\s+$//g;
16865: unless ($lastactivedays =~ /^\d+$/) {
16866: undef($lastactivedays);
16867: $env{'form.lastactive'} = 0;
16868: }
16869: }
16870: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 16871: foreach my $key (keys(%currautoupdate)) {
1.385 raeburn 16872: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 16873: if (exists($updatehash{autoupdate}{$key})) {
16874: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
16875: $changes{$key} = 1;
16876: }
16877: }
16878: } elsif ($key eq 'fields') {
16879: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 16880: foreach my $item (@{$types},'default') {
1.1 raeburn 16881: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
16882: my $change = 0;
16883: foreach my $type (@{$currautoupdate{$key}{$item}}) {
16884: if (!exists($fields{$item})) {
16885: $change = 1;
1.132 raeburn 16886: last;
1.1 raeburn 16887: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 16888: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 16889: $change = 1;
1.132 raeburn 16890: last;
1.1 raeburn 16891: }
16892: }
16893: }
16894: if ($change) {
16895: push(@{$changes{$key}},$item);
16896: }
1.26 raeburn 16897: }
1.1 raeburn 16898: }
16899: }
1.131 raeburn 16900: } elsif ($key eq 'lockablenames') {
16901: if (ref($currautoupdate{$key}) eq 'ARRAY') {
16902: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16903: if (@changed) {
16904: $changes{'lockablenames'} = 1;
16905: }
16906: } else {
16907: if (@lockablenames) {
16908: $changes{'lockablenames'} = 1;
16909: }
16910: }
16911: }
16912: }
16913: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
16914: if (@lockablenames) {
16915: $changes{'lockablenames'} = 1;
1.1 raeburn 16916: }
16917: }
1.385 raeburn 16918: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
16919: if ($updatehash{'autoupdate'}{'unexpired'}) {
16920: $changes{'unexpired'} = 1;
16921: }
16922: }
16923: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
16924: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
16925: $changes{'lastactive'} = 1;
16926: }
16927: }
1.26 raeburn 16928: foreach my $item (@{$types},'default') {
16929: if (defined($fields{$item})) {
16930: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 16931: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
16932: my $change = 0;
16933: if (ref($fields{$item}) eq 'ARRAY') {
16934: foreach my $type (@{$fields{$item}}) {
16935: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
16936: $change = 1;
16937: last;
16938: }
16939: }
16940: }
16941: if ($change) {
16942: push(@{$changes{'fields'}},$item);
16943: }
16944: } else {
1.26 raeburn 16945: push(@{$changes{'fields'}},$item);
16946: }
16947: } else {
16948: push(@{$changes{'fields'}},$item);
1.1 raeburn 16949: }
16950: }
16951: }
16952: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
16953: $dom);
16954: if ($putresult eq 'ok') {
16955: if (keys(%changes) > 0) {
16956: $resulttext = &mt('Changes made:').'<ul>';
16957: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 16958: if ($key eq 'lockablenames') {
16959: $resulttext .= '<li>';
16960: if (@lockablenames) {
16961: $usertypes->{'default'} = $othertitle;
16962: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
16963: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
16964: } else {
16965: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
16966: }
16967: $resulttext .= '</li>';
16968: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 16969: foreach my $item (@{$changes{$key}}) {
16970: my @newvalues;
16971: foreach my $type (@{$fields{$item}}) {
16972: push(@newvalues,$fieldtitles{$type});
16973: }
1.3 raeburn 16974: my $newvaluestr;
16975: if (@newvalues > 0) {
16976: $newvaluestr = join(', ',@newvalues);
16977: } else {
16978: $newvaluestr = &mt('none');
1.6 raeburn 16979: }
1.1 raeburn 16980: if ($item eq 'default') {
1.26 raeburn 16981: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 16982: } else {
1.26 raeburn 16983: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 16984: }
16985: }
16986: } else {
16987: my $newvalue;
16988: if ($key eq 'run') {
16989: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.385 raeburn 16990: } elsif ($key eq 'lastactive') {
16991: $newvalue = $offon[$env{'form.lastactive'}];
16992: unless ($lastactivedays eq '') {
16993: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
16994: }
1.1 raeburn 16995: } else {
16996: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 16997: }
1.1 raeburn 16998: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
16999: }
17000: }
17001: $resulttext .= '</ul>';
17002: } else {
1.3 raeburn 17003: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 17004: }
17005: } else {
1.11 albertel 17006: $resulttext = '<span class="LC_error">'.
17007: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 17008: }
1.3 raeburn 17009: return $resulttext;
1.1 raeburn 17010: }
17011:
1.125 raeburn 17012: sub modify_autocreate {
17013: my ($dom,%domconfig) = @_;
17014: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
17015: if (ref($domconfig{'autocreate'}) eq 'HASH') {
17016: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
17017: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
17018: }
17019: }
17020: my %title= ( xml => 'Auto-creation of courses in XML course description files',
17021: req => 'Auto-creation of validated requests for official courses',
17022: xmldc => 'Identity of course creator of courses from XML files',
17023: );
17024: my @types = ('xml','req');
17025: foreach my $item (@types) {
17026: $newvals{$item} = $env{'form.autocreate_'.$item};
17027: $newvals{$item} =~ s/\D//g;
17028: $newvals{$item} = 0 if ($newvals{$item} eq '');
17029: }
17030: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 17031: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 17032: unless (exists($domcoords{$newvals{'xmldc'}})) {
17033: $newvals{'xmldc'} = '';
17034: }
17035: %autocreatehash = (
17036: autocreate => { xml => $newvals{'xml'},
17037: req => $newvals{'req'},
17038: }
17039: );
17040: if ($newvals{'xmldc'} ne '') {
17041: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
17042: }
17043: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
17044: $dom);
17045: if ($putresult eq 'ok') {
17046: my @items = @types;
17047: if ($newvals{'xml'}) {
17048: push(@items,'xmldc');
17049: }
17050: foreach my $item (@items) {
17051: if (exists($currautocreate{$item})) {
17052: if ($currautocreate{$item} ne $newvals{$item}) {
17053: $changes{$item} = 1;
17054: }
17055: } elsif ($newvals{$item}) {
17056: $changes{$item} = 1;
17057: }
17058: }
17059: if (keys(%changes) > 0) {
17060: my @offon = ('off','on');
17061: $resulttext = &mt('Changes made:').'<ul>';
17062: foreach my $item (@types) {
17063: if ($changes{$item}) {
17064: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 17065: $resulttext .= '<li>'.
17066: &mt("$title{$item} set to [_1]$newtxt [_2]",
17067: '<b>','</b>').
17068: '</li>';
1.125 raeburn 17069: }
17070: }
17071: if ($changes{'xmldc'}) {
17072: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
17073: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 17074: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 17075: }
17076: $resulttext .= '</ul>';
17077: } else {
17078: $resulttext = &mt('No changes made to auto-creation settings');
17079: }
17080: } else {
17081: $resulttext = '<span class="LC_error">'.
17082: &mt('An error occurred: [_1]',$putresult).'</span>';
17083: }
17084: return $resulttext;
17085: }
17086:
1.23 raeburn 17087: sub modify_directorysrch {
1.295 raeburn 17088: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 17089: my ($resulttext,%changes);
17090: my %currdirsrch;
17091: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
17092: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
17093: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
17094: }
17095: }
1.277 raeburn 17096: my %title = ( available => 'Institutional directory search available',
17097: localonly => 'Other domains can search institution',
17098: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 17099: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 17100: searchby => 'Search types',
17101: searchtypes => 'Search latitude');
17102: my @offon = ('off','on');
1.24 raeburn 17103: my @otherdoms = ('Yes','No');
1.23 raeburn 17104:
1.25 raeburn 17105: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 17106: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
17107: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
17108:
1.44 raeburn 17109: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 17110: if (keys(%{$usertypes}) == 0) {
17111: @cansearch = ('default');
17112: } else {
17113: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
17114: foreach my $type (@{$currdirsrch{'cansearch'}}) {
17115: if (!grep(/^\Q$type\E$/,@cansearch)) {
17116: push(@{$changes{'cansearch'}},$type);
17117: }
1.23 raeburn 17118: }
1.26 raeburn 17119: foreach my $type (@cansearch) {
17120: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
17121: push(@{$changes{'cansearch'}},$type);
17122: }
1.23 raeburn 17123: }
1.26 raeburn 17124: } else {
17125: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 17126: }
17127: }
17128:
17129: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
17130: foreach my $by (@{$currdirsrch{'searchby'}}) {
17131: if (!grep(/^\Q$by\E$/,@searchby)) {
17132: push(@{$changes{'searchby'}},$by);
17133: }
17134: }
17135: foreach my $by (@searchby) {
17136: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
17137: push(@{$changes{'searchby'}},$by);
17138: }
17139: }
17140: } else {
17141: push(@{$changes{'searchby'}},@searchby);
17142: }
1.25 raeburn 17143:
17144: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
17145: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
17146: if (!grep(/^\Q$type\E$/,@searchtypes)) {
17147: push(@{$changes{'searchtypes'}},$type);
17148: }
17149: }
17150: foreach my $type (@searchtypes) {
17151: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
17152: push(@{$changes{'searchtypes'}},$type);
17153: }
17154: }
17155: } else {
17156: if (exists($currdirsrch{'searchtypes'})) {
17157: foreach my $type (@searchtypes) {
17158: if ($type ne $currdirsrch{'searchtypes'}) {
17159: push(@{$changes{'searchtypes'}},$type);
17160: }
17161: }
17162: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
17163: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
17164: }
17165: } else {
17166: push(@{$changes{'searchtypes'}},@searchtypes);
17167: }
17168: }
17169:
1.23 raeburn 17170: my %dirsrch_hash = (
17171: directorysrch => { available => $env{'form.dirsrch_available'},
17172: cansearch => \@cansearch,
1.277 raeburn 17173: localonly => $env{'form.dirsrch_instlocalonly'},
17174: lclocalonly => $env{'form.dirsrch_domlocalonly'},
17175: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 17176: searchby => \@searchby,
1.25 raeburn 17177: searchtypes => \@searchtypes,
1.23 raeburn 17178: }
17179: );
17180: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
17181: $dom);
17182: if ($putresult eq 'ok') {
17183: if (exists($currdirsrch{'available'})) {
17184: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
17185: $changes{'available'} = 1;
17186: }
17187: } else {
17188: if ($env{'form.dirsrch_available'} eq '1') {
17189: $changes{'available'} = 1;
17190: }
17191: }
1.277 raeburn 17192: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 17193: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
17194: $changes{'lcavailable'} = 1;
17195: }
1.277 raeburn 17196: } else {
17197: if ($env{'form.dirsrch_lcavailable'} eq '1') {
17198: $changes{'lcavailable'} = 1;
17199: }
17200: }
1.24 raeburn 17201: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 17202: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
17203: $changes{'localonly'} = 1;
17204: }
1.24 raeburn 17205: } else {
1.277 raeburn 17206: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 17207: $changes{'localonly'} = 1;
17208: }
17209: }
1.277 raeburn 17210: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 17211: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
17212: $changes{'lclocalonly'} = 1;
17213: }
1.277 raeburn 17214: } else {
17215: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
17216: $changes{'lclocalonly'} = 1;
17217: }
17218: }
1.23 raeburn 17219: if (keys(%changes) > 0) {
17220: $resulttext = &mt('Changes made:').'<ul>';
17221: if ($changes{'available'}) {
17222: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
17223: }
1.277 raeburn 17224: if ($changes{'lcavailable'}) {
17225: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
17226: }
1.24 raeburn 17227: if ($changes{'localonly'}) {
1.277 raeburn 17228: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 17229: }
1.277 raeburn 17230: if ($changes{'lclocalonly'}) {
17231: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 17232: }
1.23 raeburn 17233: if (ref($changes{'cansearch'}) eq 'ARRAY') {
17234: my $chgtext;
1.26 raeburn 17235: if (ref($usertypes) eq 'HASH') {
17236: if (keys(%{$usertypes}) > 0) {
17237: foreach my $type (@{$types}) {
17238: if (grep(/^\Q$type\E$/,@cansearch)) {
17239: $chgtext .= $usertypes->{$type}.'; ';
17240: }
17241: }
17242: if (grep(/^default$/,@cansearch)) {
17243: $chgtext .= $othertitle;
17244: } else {
17245: $chgtext =~ s/\; $//;
17246: }
1.210 raeburn 17247: $resulttext .=
1.178 raeburn 17248: '<li>'.
17249: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
17250: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
17251: '</li>';
1.23 raeburn 17252: }
17253: }
17254: }
17255: if (ref($changes{'searchby'}) eq 'ARRAY') {
17256: my ($searchtitles,$titleorder) = &sorted_searchtitles();
17257: my $chgtext;
17258: foreach my $type (@{$titleorder}) {
17259: if (grep(/^\Q$type\E$/,@searchby)) {
17260: if (defined($searchtitles->{$type})) {
17261: $chgtext .= $searchtitles->{$type}.'; ';
17262: }
17263: }
17264: }
17265: $chgtext =~ s/\; $//;
17266: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
17267: }
1.25 raeburn 17268: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
17269: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
17270: my $chgtext;
17271: foreach my $type (@{$srchtypeorder}) {
17272: if (grep(/^\Q$type\E$/,@searchtypes)) {
17273: if (defined($srchtypes_desc->{$type})) {
17274: $chgtext .= $srchtypes_desc->{$type}.'; ';
17275: }
17276: }
17277: }
17278: $chgtext =~ s/\; $//;
1.178 raeburn 17279: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 17280: }
17281: $resulttext .= '</ul>';
1.295 raeburn 17282: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
17283: if (ref($lastactref) eq 'HASH') {
17284: $lastactref->{'directorysrch'} = 1;
17285: }
1.23 raeburn 17286: } else {
1.277 raeburn 17287: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 17288: }
17289: } else {
17290: $resulttext = '<span class="LC_error">'.
1.27 raeburn 17291: &mt('An error occurred: [_1]',$putresult).'</span>';
17292: }
17293: return $resulttext;
17294: }
17295:
1.28 raeburn 17296: sub modify_contacts {
1.205 raeburn 17297: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 17298: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
17299: if (ref($domconfig{'contacts'}) eq 'HASH') {
17300: foreach my $key (keys(%{$domconfig{'contacts'}})) {
17301: $currsetting{$key} = $domconfig{'contacts'}{$key};
17302: }
17303: }
1.286 raeburn 17304: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 17305: my @contacts = ('supportemail','adminemail');
1.286 raeburn 17306: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350 raeburn 17307: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340 raeburn 17308: my @toggles = ('reporterrors','reportupdates','reportstatus');
17309: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 17310: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 17311: foreach my $type (@mailings) {
17312: @{$newsetting{$type}} =
17313: &Apache::loncommon::get_env_multiple('form.'.$type);
17314: foreach my $item (@contacts) {
17315: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
17316: $contacts_hash{contacts}{$type}{$item} = 1;
17317: } else {
17318: $contacts_hash{contacts}{$type}{$item} = 0;
17319: }
1.289 raeburn 17320: }
1.28 raeburn 17321: $others{$type} = $env{'form.'.$type.'_others'};
17322: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 17323: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17324: $bcc{$type} = $env{'form.'.$type.'_bcc'};
17325: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 17326: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
17327: $includestr{$type} = $env{'form.'.$type.'_includestr'};
17328: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
17329: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17330: }
1.134 raeburn 17331: }
1.28 raeburn 17332: }
17333: foreach my $item (@contacts) {
17334: $to{$item} = $env{'form.'.$item};
17335: $contacts_hash{'contacts'}{$item} = $to{$item};
17336: }
1.203 raeburn 17337: foreach my $item (@toggles) {
17338: if ($env{'form.'.$item} =~ /^(0|1)$/) {
17339: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
17340: }
17341: }
1.340 raeburn 17342: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
17343: foreach my $item (@lonstatus) {
17344: if ($item eq 'excluded') {
17345: my (%serverhomes,@excluded);
17346: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
17347: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
17348: if (@possexcluded) {
17349: foreach my $id (sort(@possexcluded)) {
17350: if ($serverhomes{$id}) {
17351: push(@excluded,$id);
17352: }
17353: }
17354: }
17355: if (@excluded) {
17356: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
17357: }
17358: } elsif ($item eq 'weights') {
1.377 raeburn 17359: foreach my $type ('E','W','N','U') {
1.340 raeburn 17360: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
17361: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
17362: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
17363: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
17364: $env{'form.error'.$item.'_'.$type};
17365: }
17366: }
17367: }
17368: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
17369: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
17370: if ($env{'form.error'.$item} =~ /^\d+$/) {
17371: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
17372: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
17373: }
17374: }
17375: }
17376: }
1.286 raeburn 17377: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
17378: foreach my $field (@{$fields}) {
17379: if (ref($possoptions->{$field}) eq 'ARRAY') {
17380: my $value = $env{'form.helpform_'.$field};
17381: $value =~ s/^\s+|\s+$//g;
17382: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 17383: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 17384: if ($field eq 'screenshot') {
17385: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
17386: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 17387: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 17388: }
17389: }
17390: }
17391: }
17392: }
17393: }
1.315 raeburn 17394: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17395: my (@statuses,%usertypeshash,@overrides);
17396: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
17397: @statuses = @{$types};
17398: if (ref($usertypes) eq 'HASH') {
17399: %usertypeshash = %{$usertypes};
17400: }
17401: }
17402: if (@statuses) {
17403: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
17404: foreach my $type (@possoverrides) {
17405: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
17406: push(@overrides,$type);
17407: }
17408: }
17409: if (@overrides) {
17410: foreach my $type (@overrides) {
17411: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
17412: foreach my $item (@contacts) {
17413: if (grep(/^\Q$item\E$/,@standard)) {
17414: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
17415: $newsetting{'override_'.$type}{$item} = 1;
17416: } else {
17417: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
17418: $newsetting{'override_'.$type}{$item} = 0;
17419: }
17420: }
17421: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
17422: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17423: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
17424: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17425: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
17426: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
17427: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
17428: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17429: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
17430: }
1.425 raeburn 17431: }
1.315 raeburn 17432: }
17433: }
1.28 raeburn 17434: if (keys(%currsetting) > 0) {
17435: foreach my $item (@contacts) {
17436: if ($to{$item} ne $currsetting{$item}) {
17437: $changes{$item} = 1;
17438: }
17439: }
17440: foreach my $type (@mailings) {
17441: foreach my $item (@contacts) {
17442: if (ref($currsetting{$type}) eq 'HASH') {
17443: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
17444: push(@{$changes{$type}},$item);
17445: }
17446: } else {
17447: push(@{$changes{$type}},@{$newsetting{$type}});
17448: }
17449: }
17450: if ($others{$type} ne $currsetting{$type}{'others'}) {
17451: push(@{$changes{$type}},'others');
17452: }
1.289 raeburn 17453: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17454: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
17455: push(@{$changes{$type}},'bcc');
17456: }
1.286 raeburn 17457: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
17458: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
17459: push(@{$changes{$type}},'include');
17460: }
17461: }
17462: }
17463: if (ref($fields) eq 'ARRAY') {
17464: if (ref($currsetting{'helpform'}) eq 'HASH') {
17465: foreach my $field (@{$fields}) {
17466: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
17467: push(@{$changes{'helpform'}},$field);
17468: }
17469: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17470: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
17471: push(@{$changes{'helpform'}},'maxsize');
17472: }
17473: }
17474: }
17475: } else {
17476: foreach my $field (@{$fields}) {
17477: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17478: push(@{$changes{'helpform'}},$field);
17479: }
17480: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17481: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17482: push(@{$changes{'helpform'}},'maxsize');
17483: }
17484: }
17485: }
1.134 raeburn 17486: }
1.28 raeburn 17487: }
1.315 raeburn 17488: if (@statuses) {
1.425 raeburn 17489: if (ref($currsetting{'overrides'}) eq 'HASH') {
1.315 raeburn 17490: foreach my $key (keys(%{$currsetting{'overrides'}})) {
17491: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
17492: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
17493: foreach my $item (@contacts,'bcc','others','include') {
1.425 raeburn 17494: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
1.315 raeburn 17495: push(@{$changes{'overrides'}},$key);
17496: last;
17497: }
17498: }
17499: } else {
17500: push(@{$changes{'overrides'}},$key);
17501: }
17502: }
17503: }
17504: foreach my $key (@overrides) {
17505: unless (exists($currsetting{'overrides'}{$key})) {
17506: push(@{$changes{'overrides'}},$key);
17507: }
17508: }
17509: } else {
17510: foreach my $key (@overrides) {
1.425 raeburn 17511: push(@{$changes{'overrides'}},$key);
1.315 raeburn 17512: }
17513: }
17514: }
1.340 raeburn 17515: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
17516: foreach my $key ('excluded','weights','threshold','sysmail') {
17517: if ($key eq 'excluded') {
17518: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17519: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
17520: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17521: (@{$currsetting{'lonstatus'}{$key}})) {
17522: my @diffs =
17523: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
17524: $currsetting{'lonstatus'}{$key});
17525: if (@diffs) {
17526: push(@{$changes{'lonstatus'}},$key);
17527: }
17528: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
17529: push(@{$changes{'lonstatus'}},$key);
17530: }
17531: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17532: (@{$currsetting{'lonstatus'}{$key}})) {
17533: push(@{$changes{'lonstatus'}},$key);
17534: }
17535: } elsif ($key eq 'weights') {
17536: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17537: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
17538: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17539: foreach my $type ('E','W','N','U') {
1.340 raeburn 17540: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
17541: $currsetting{'lonstatus'}{$key}{$type}) {
17542: push(@{$changes{'lonstatus'}},$key);
17543: last;
17544: }
17545: }
17546: } else {
1.341 raeburn 17547: foreach my $type ('E','W','N','U') {
1.340 raeburn 17548: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
17549: push(@{$changes{'lonstatus'}},$key);
17550: last;
17551: }
17552: }
17553: }
17554: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17555: foreach my $type ('E','W','N','U') {
1.340 raeburn 17556: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
17557: push(@{$changes{'lonstatus'}},$key);
17558: last;
17559: }
17560: }
17561: }
17562: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
17563: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17564: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17565: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
17566: push(@{$changes{'lonstatus'}},$key);
17567: }
17568: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
17569: push(@{$changes{'lonstatus'}},$key);
17570: }
17571: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17572: push(@{$changes{'lonstatus'}},$key);
17573: }
17574: }
17575: }
17576: } else {
17577: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17578: foreach my $key ('excluded','weights','threshold','sysmail') {
17579: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17580: push(@{$changes{'lonstatus'}},$key);
17581: }
17582: }
17583: }
17584: }
1.28 raeburn 17585: } else {
17586: my %default;
17587: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
17588: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
17589: $default{'errormail'} = 'adminemail';
17590: $default{'packagesmail'} = 'adminemail';
17591: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 17592: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 17593: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 17594: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 17595: $default{'updatesmail'} = 'adminemail';
1.350 raeburn 17596: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 17597: foreach my $item (@contacts) {
17598: if ($to{$item} ne $default{$item}) {
1.286 raeburn 17599: $changes{$item} = 1;
1.203 raeburn 17600: }
1.28 raeburn 17601: }
17602: foreach my $type (@mailings) {
17603: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
17604: push(@{$changes{$type}},@{$newsetting{$type}});
17605: }
17606: if ($others{$type} ne '') {
17607: push(@{$changes{$type}},'others');
1.134 raeburn 17608: }
1.286 raeburn 17609: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17610: if ($bcc{$type} ne '') {
17611: push(@{$changes{$type}},'bcc');
17612: }
1.286 raeburn 17613: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
17614: push(@{$changes{$type}},'include');
17615: }
1.134 raeburn 17616: }
1.28 raeburn 17617: }
1.286 raeburn 17618: if (ref($fields) eq 'ARRAY') {
17619: foreach my $field (@{$fields}) {
17620: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17621: push(@{$changes{'helpform'}},$field);
17622: }
17623: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17624: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17625: push(@{$changes{'helpform'}},'maxsize');
17626: }
17627: }
17628: }
1.289 raeburn 17629: }
1.340 raeburn 17630: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17631: foreach my $key ('excluded','weights','threshold','sysmail') {
17632: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17633: push(@{$changes{'lonstatus'}},$key);
17634: }
17635: }
17636: }
1.28 raeburn 17637: }
1.203 raeburn 17638: foreach my $item (@toggles) {
17639: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
17640: $changes{$item} = 1;
17641: } elsif ((!$env{'form.'.$item}) &&
17642: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
17643: $changes{$item} = 1;
17644: }
17645: }
1.28 raeburn 17646: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
17647: $dom);
17648: if ($putresult eq 'ok') {
17649: if (keys(%changes) > 0) {
1.205 raeburn 17650: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 17651: if (ref($lastactref) eq 'HASH') {
17652: $lastactref->{'domainconfig'} = 1;
17653: }
1.28 raeburn 17654: my ($titles,$short_titles) = &contact_titles();
17655: $resulttext = &mt('Changes made:').'<ul>';
17656: foreach my $item (@contacts) {
17657: if ($changes{$item}) {
17658: $resulttext .= '<li>'.$titles->{$item}.
17659: &mt(' set to: ').
17660: '<span class="LC_cusr_emph">'.
17661: $to{$item}.'</span></li>';
17662: }
17663: }
17664: foreach my $type (@mailings) {
17665: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 17666: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 17667: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 17668: } else {
17669: $resulttext .= '<li>'.$titles->{$type}.': ';
17670: }
1.28 raeburn 17671: my @text;
17672: foreach my $item (@{$newsetting{$type}}) {
17673: push(@text,$short_titles->{$item});
17674: }
17675: if ($others{$type} ne '') {
17676: push(@text,$others{$type});
17677: }
1.286 raeburn 17678: if (@text) {
17679: $resulttext .= '<span class="LC_cusr_emph">'.
17680: join(', ',@text).'</span>';
17681: }
17682: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17683: if ($bcc{$type} ne '') {
1.286 raeburn 17684: my $bcctext;
17685: if (@text) {
1.289 raeburn 17686: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 17687: } else {
17688: $bcctext = '(Bcc)';
17689: }
17690: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
17691: } elsif (!@text) {
17692: $resulttext .= &mt('No one');
1.425 raeburn 17693: }
1.289 raeburn 17694: if ($includestr{$type} ne '') {
1.286 raeburn 17695: if ($includeloc{$type} eq 'b') {
17696: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
17697: } elsif ($includeloc{$type} eq 's') {
17698: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
17699: }
1.134 raeburn 17700: }
1.286 raeburn 17701: } elsif (!@text) {
17702: $resulttext .= &mt('No recipients');
1.134 raeburn 17703: }
17704: $resulttext .= '</li>';
1.28 raeburn 17705: }
17706: }
1.315 raeburn 17707: if (ref($changes{'overrides'}) eq 'ARRAY') {
17708: my @deletions;
17709: foreach my $type (@{$changes{'overrides'}}) {
17710: if ($usertypeshash{$type}) {
17711: if (grep(/^\Q$type\E/,@overrides)) {
17712: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
17713: $usertypeshash{$type}).'<ul><li>';
17714: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
17715: my @text;
17716: foreach my $item (@contacts) {
1.425 raeburn 17717: if ($newsetting{'override_'.$type}{$item}) {
1.315 raeburn 17718: push(@text,$short_titles->{$item});
17719: }
17720: }
17721: if ($newsetting{'override_'.$type}{'others'} ne '') {
17722: push(@text,$newsetting{'override_'.$type}{'others'});
17723: }
1.425 raeburn 17724:
1.315 raeburn 17725: if (@text) {
17726: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
17727: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
17728: }
17729: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
17730: my $bcctext;
17731: if (@text) {
17732: $bcctext = ' '.&mt('with Bcc to');
17733: } else {
17734: $bcctext = '(Bcc)';
17735: }
17736: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
17737: } elsif (!@text) {
17738: $resulttext .= &mt('Helpdesk e-mail sent to no one');
17739: }
17740: $resulttext .= '</li>';
17741: if ($newsetting{'override_'.$type}{'include'} ne '') {
17742: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
17743: if ($loc eq 'b') {
17744: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
17745: } elsif ($loc eq 's') {
17746: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
17747: }
17748: }
17749: }
17750: $resulttext .= '</li></ul></li>';
17751: } else {
17752: push(@deletions,$usertypeshash{$type});
17753: }
17754: }
17755: }
17756: if (@deletions) {
17757: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
17758: join(', ',@deletions)).'</li>';
17759: }
17760: }
1.203 raeburn 17761: my @offon = ('off','on');
1.340 raeburn 17762: my $corelink = &core_link_msu();
1.203 raeburn 17763: if ($changes{'reporterrors'}) {
17764: $resulttext .= '<li>'.
17765: &mt('E-mail error reports to [_1] set to "'.
17766: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 17767: $corelink).
1.203 raeburn 17768: '</li>';
17769: }
17770: if ($changes{'reportupdates'}) {
17771: $resulttext .= '<li>'.
17772: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
17773: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 17774: $corelink).
1.203 raeburn 17775: '</li>';
17776: }
1.340 raeburn 17777: if ($changes{'reportstatus'}) {
17778: $resulttext .= '<li>'.
17779: &mt('E-mail status if errors above threshold to [_1] set to "'.
17780: $offon[$env{'form.reportstatus'}].'".',
17781: $corelink).
17782: '</li>';
17783: }
17784: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
17785: $resulttext .= '<li>'.
17786: &mt('Nightly status check e-mail settings').':<ul>';
17787: my (%defval,%use_def,%shown);
17788: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
17789: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
17790: $defval{'weights'} =
1.341 raeburn 17791: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 17792: $defval{'excluded'} = &mt('None');
17793: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
17794: foreach my $item ('threshold','sysmail','weights','excluded') {
17795: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
17796: if (($item eq 'threshold') || ($item eq 'sysmail')) {
17797: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
17798: } elsif ($item eq 'weights') {
17799: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 17800: foreach my $type ('E','W','N','U') {
1.340 raeburn 17801: $shown{$item} .= $lonstatus_names->{$type}.'=';
17802: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
17803: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
17804: } else {
17805: $shown{$item} .= $lonstatus_defs->{$type};
17806: }
17807: $shown{$item} .= ', ';
17808: }
17809: $shown{$item} =~ s/, $//;
17810: } else {
17811: $shown{$item} = $defval{$item};
17812: }
17813: } elsif ($item eq 'excluded') {
17814: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
17815: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
17816: } else {
17817: $shown{$item} = $defval{$item};
17818: }
17819: }
17820: } else {
17821: $shown{$item} = $defval{$item};
17822: }
17823: }
17824: } else {
17825: foreach my $item ('threshold','weights','excluded','sysmail') {
17826: $shown{$item} = $defval{$item};
17827: }
17828: }
17829: foreach my $item ('threshold','weights','excluded','sysmail') {
17830: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
17831: $shown{$item}).'</li>';
17832: }
17833: $resulttext .= '</ul></li>';
17834: }
1.286 raeburn 17835: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
17836: my (@optional,@required,@unused,$maxsizechg);
17837: foreach my $field (@{$changes{'helpform'}}) {
17838: if ($field eq 'maxsize') {
17839: $maxsizechg = 1;
17840: next;
17841: }
17842: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 17843: push(@optional,$field);
1.286 raeburn 17844: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
17845: push(@unused,$field);
17846: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 17847: push(@required,$field);
1.286 raeburn 17848: }
17849: }
17850: if (@optional) {
17851: $resulttext .= '<li>'.
17852: &mt('Help form fields changed to "Optional": [_1].',
17853: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
17854: '</li>';
17855: }
17856: if (@required) {
17857: $resulttext .= '<li>'.
17858: &mt('Help form fields changed to "Required": [_1].',
17859: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
17860: '</li>';
17861: }
17862: if (@unused) {
17863: $resulttext .= '<li>'.
17864: &mt('Help form fields changed to "Not shown": [_1].',
17865: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
17866: '</li>';
17867: }
17868: if ($maxsizechg) {
17869: $resulttext .= '<li>'.
17870: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
17871: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
17872: '</li>';
17873: }
17874: }
1.28 raeburn 17875: $resulttext .= '</ul>';
17876: } else {
1.288 raeburn 17877: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 17878: }
17879: } else {
17880: $resulttext = '<span class="LC_error">'.
17881: &mt('An error occurred: [_1].',$putresult).'</span>';
17882: }
17883: return $resulttext;
17884: }
17885:
1.357 raeburn 17886: sub modify_privacy {
1.427 raeburn 17887: my ($dom,$lastactref,%domconfig) = @_;
1.357 raeburn 17888: my ($resulttext,%current,%changes);
17889: if (ref($domconfig{'privacy'}) eq 'HASH') {
17890: %current = %{$domconfig{'privacy'}};
17891: }
17892: my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
17893: my @items = ('domain','author','course','community');
17894: my %names = &Apache::lonlocal::texthash (
17895: domain => 'Assigned domain role(s)',
17896: author => 'Assigned co-author role(s)',
17897: course => 'Assigned course role(s)',
1.416 raeburn 17898: community => 'Assigned community role(s)',
1.357 raeburn 17899: );
17900: my %roles = &Apache::lonlocal::texthash (
17901: domain => 'Domain role',
17902: author => 'Co-author role',
17903: course => 'Course role',
17904: community => 'Community role',
17905: );
17906: my %titles = &Apache::lonlocal::texthash (
17907: approval => 'Approval for role in different domain',
17908: othdom => 'User information available in other domain',
17909: priv => 'Information viewable by privileged user in same domain',
17910: unpriv => 'Information viewable by unprivileged user in same domain',
17911: instdom => 'Other domain shares institution/provider',
17912: extdom => 'Other domain has different institution/provider',
17913: none => 'Not allowed',
17914: user => 'User authorizes',
17915: domain => 'Domain Coordinator authorizes',
17916: auto => 'Unrestricted',
1.418 raeburn 17917: notify => 'Notify when role needs authorization',
1.357 raeburn 17918: );
17919: my %fieldnames = &Apache::lonlocal::texthash (
17920: id => 'Student/Employee ID',
17921: permanentemail => 'E-mail address',
17922: lastname => 'Last Name',
17923: firstname => 'First Name',
17924: middlename => 'Middle Name',
17925: generation => 'Generation',
17926: );
17927: my ($othertitle,$usertypes,$types) =
17928: &Apache::loncommon::sorted_inst_types($dom);
17929: my (%by_ip,%by_location,@intdoms,@instdoms);
17930: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
17931:
17932: my %privacyhash = (
17933: 'approval' => {
17934: instdom => {},
17935: extdom => {},
17936: },
17937: 'othdom' => {},
17938: 'priv' => {},
17939: 'unpriv' => {},
17940: );
17941: foreach my $item (@items) {
17942: if (@instdoms > 1) {
1.416 raeburn 17943: if ($env{'form.privacy_approval_instdom_'.$item} =~ /^(none|user|domain|auto)$/) {
1.357 raeburn 17944: $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
17945: }
17946: if (ref($current{'approval'}) eq 'HASH') {
17947: if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
17948: unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
17949: $changes{'approval'} = 1;
17950: }
17951: }
17952: } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
17953: $changes{'approval'} = 1;
17954: }
17955: }
17956: if (keys(%by_location) > 0) {
17957: if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
17958: $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
17959: }
17960: if (ref($current{'approval'}) eq 'HASH') {
17961: if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
17962: unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
17963: $changes{'approval'} = 1;
17964: }
17965: }
17966: } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
17967: $changes{'approval'} = 1;
17968: }
17969: }
17970: foreach my $status ('priv','unpriv') {
17971: my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
17972: my @newvalues;
17973: foreach my $field (@possibles) {
17974: if (grep(/^\Q$field\E$/,@fields)) {
17975: $privacyhash{$status}{$item}{$field} = 1;
17976: push(@newvalues,$field);
17977: }
17978: }
17979: @newvalues = sort(@newvalues);
17980: if (ref($current{$status}) eq 'HASH') {
17981: if (ref($current{$status}{$item}) eq 'HASH') {
17982: my @currvalues = sort(keys(%{$current{$status}{$item}}));
17983: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
17984: if (@diffs > 0) {
17985: $changes{$status} = 1;
17986: }
17987: }
17988: } else {
17989: my @stdfields;
17990: foreach my $field (@fields) {
17991: if ($field eq 'id') {
17992: next if ($status eq 'unpriv');
17993: next if (($status eq 'priv') && ($item eq 'community'));
17994: }
17995: push(@stdfields,$field);
17996: }
17997: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
17998: if (@diffs > 0) {
17999: $changes{$status} = 1;
18000: }
18001: }
18002: }
18003: }
18004: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
18005: my @statuses;
18006: if (ref($types) eq 'ARRAY') {
18007: @statuses = @{$types};
18008: }
18009: foreach my $type (@statuses,'default') {
18010: my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
18011: my @newvalues;
18012: foreach my $field (sort(@possfields)) {
18013: if (grep(/^\Q$field\E$/,@fields)) {
18014: $privacyhash{'othdom'}{$type}{$field} = 1;
18015: push(@newvalues,$field);
18016: }
18017: }
18018: @newvalues = sort(@newvalues);
18019: if (ref($current{'othdom'}) eq 'HASH') {
18020: if (ref($current{'othdom'}{$type}) eq 'HASH') {
18021: my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
18022: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
18023: if (@diffs > 0) {
18024: $changes{'othdom'} = 1;
18025: }
18026: }
18027: } else {
18028: my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
18029: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
18030: if (@diffs > 0) {
18031: $changes{'othdom'} = 1;
18032: }
18033: }
18034: }
1.417 raeburn 18035: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
18036: my %notify;
18037: foreach my $possdc (&Apache::loncommon::get_env_multiple('form.privacy_notify')) {
18038: if (exists($domcoords{$possdc})) {
18039: $notify{$possdc} = 1;
18040: }
18041: }
18042: my $notify = join(',',sort(keys(%notify)));
18043: if ($current{'notify'} ne $notify) {
18044: $changes{'notify'} = 1;
18045: }
18046: $privacyhash{'notify'} = $notify;
1.357 raeburn 18047: }
18048: my %confighash = (
18049: privacy => \%privacyhash,
18050: );
18051: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
18052: if ($putresult eq 'ok') {
18053: if (keys(%changes) > 0) {
18054: $resulttext = &mt('Changes made: ').'<ul>';
1.417 raeburn 18055: foreach my $key ('approval','notify','othdom','priv','unpriv') {
1.357 raeburn 18056: if ($changes{$key}) {
18057: $resulttext .= '<li>'.$titles{$key}.':<ul>';
18058: if ($key eq 'approval') {
18059: if (keys(%{$privacyhash{$key}{instdom}})) {
18060: $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
18061: foreach my $item (@items) {
18062: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
18063: }
18064: $resulttext .= '</ul></li>';
18065: }
18066: if (keys(%{$privacyhash{$key}{extdom}})) {
18067: $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
18068: foreach my $item (@items) {
18069: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
18070: }
18071: $resulttext .= '</ul></li>';
18072: }
1.417 raeburn 18073: } elsif ($key eq 'notify') {
18074: if ($privacyhash{$key}) {
18075: foreach my $dc (split(/,/,$privacyhash{$key})) {
18076: my ($dcname,$dcdom) = split(/:/,$dc);
18077: $resulttext .= '<li>'.&Apache::loncommon::plainname($dcname,$dcdom).'</li>';
18078: }
18079: } else {
18080: $resulttext .= '<li>'.&mt('No DCs to notify').'</li>';
18081: }
1.357 raeburn 18082: } elsif ($key eq 'othdom') {
18083: my @statuses;
18084: if (ref($types) eq 'ARRAY') {
18085: @statuses = @{$types};
18086: }
18087: if (ref($privacyhash{$key}) eq 'HASH') {
18088: foreach my $status (@statuses,'default') {
18089: if ($status eq 'default') {
18090: $resulttext .= '<li>'.$othertitle.': ';
18091: } elsif (ref($usertypes) eq 'HASH') {
18092: $resulttext .= '<li>'.$usertypes->{$status}.': ';
18093: } else {
18094: next;
18095: }
18096: if (ref($privacyhash{$key}{$status}) eq 'HASH') {
18097: if (keys(%{$privacyhash{$key}{$status}})) {
18098: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
18099: } else {
18100: $resulttext .= &mt('none');
18101: }
18102: }
18103: $resulttext .= '</li>';
18104: }
18105: }
18106: } else {
18107: foreach my $item (@items) {
18108: if (ref($privacyhash{$key}{$item}) eq 'HASH') {
18109: $resulttext .= '<li>'.$names{$item}.': ';
18110: if (keys(%{$privacyhash{$key}{$item}})) {
18111: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
18112: } else {
18113: $resulttext .= &mt('none');
18114: }
18115: $resulttext .= '</li>';
18116: }
18117: }
18118: }
18119: $resulttext .= '</ul></li>';
18120: }
18121: }
1.421 raeburn 18122: $resulttext .= '</ul>';
1.427 raeburn 18123: if ($changes{'approval'}) {
18124: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
18125: delete($domdefaults{'userapprovals'});
18126: if (ref($privacyhash{'approval'}) eq 'HASH') {
18127: foreach my $domtype ('instdom','extdom') {
18128: if (ref($privacyhash{'approval'}{$domtype}) eq 'HASH') {
18129: foreach my $roletype ('domain','author','course','community') {
18130: if ($privacyhash{'approval'}{$domtype}{$roletype} eq 'user') {
18131: $domdefaults{'userapprovals'} = 1;
18132: last;
18133: }
18134: }
18135: }
18136: last if ($domdefaults{'userapprovals'});
18137: }
18138: }
18139: my $cachetime = 24*60*60;
18140: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18141: if (ref($lastactref) eq 'HASH') {
18142: $lastactref->{'domdefaults'} = 1;
18143: }
18144: }
1.357 raeburn 18145: } else {
18146: $resulttext = &mt('No changes made to user information settings');
18147: }
18148: } else {
18149: $resulttext = '<span class="LC_error">'.
18150: &mt('An error occurred: [_1]',$putresult).'</span>';
18151: }
18152: return $resulttext;
18153: }
18154:
1.354 raeburn 18155: sub modify_passwords {
18156: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 raeburn 18157: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
18158: $updatedefaults,$updateconf);
1.354 raeburn 18159: my $customfn = 'resetpw.html';
18160: if (ref($domconfig{'passwords'}) eq 'HASH') {
18161: %current = %{$domconfig{'passwords'}};
18162: }
18163: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
18164: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
18165: if (ref($types) eq 'ARRAY') {
18166: @oktypes = @{$types};
18167: }
18168: push(@oktypes,'default');
18169:
18170: my %titles = &Apache::lonlocal::texthash (
18171: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
18172: intauth_check => 'Check bcrypt cost if authenticated',
18173: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
18174: permanent => 'Permanent e-mail address',
18175: critical => 'Critical notification address',
18176: notify => 'Notification address',
18177: min => 'Minimum password length',
18178: max => 'Maximum password length',
18179: chars => 'Required characters',
18180: expire => 'Password expiration (days)',
1.356 raeburn 18181: numsaved => 'Number of previous passwords to save',
1.354 raeburn 18182: reset => 'Resetting Forgotten Password',
18183: intauth => 'Encryption of Stored Passwords (Internal Auth)',
18184: rules => 'Rules for LON-CAPA Passwords',
18185: crsownerchg => 'Course Owner Changing Student Passwords',
18186: username => 'Username',
18187: email => 'E-mail address',
18188: );
18189:
18190: #
18191: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
18192: #
18193: my (%curr_defaults,%save_defaults);
18194: if (ref($domconfig{'defaults'}) eq 'HASH') {
18195: foreach my $key (keys(%{$domconfig{'defaults'}})) {
18196: if ($key =~ /^intauth_(cost|check|switch)$/) {
18197: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
18198: } else {
18199: $save_defaults{$key} = $domconfig{'defaults'}{$key};
18200: }
18201: }
18202: }
18203: my %staticdefaults = (
18204: 'resetlink' => 2,
18205: 'resetcase' => \@oktypes,
18206: 'resetprelink' => 'both',
18207: 'resetemail' => ['critical','notify','permanent'],
18208: 'intauth_cost' => 10,
18209: 'intauth_check' => 0,
18210: 'intauth_switch' => 0,
18211: );
1.365 raeburn 18212: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354 raeburn 18213: foreach my $type (@oktypes) {
18214: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
18215: }
18216: my $linklife = $env{'form.passwords_link'};
18217: $linklife =~ s/^\s+|\s+$//g;
18218: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
18219: $newvalues{'resetlink'} = $linklife;
18220: if ($current{'resetlink'}) {
18221: if ($current{'resetlink'} ne $linklife) {
18222: $changes{'reset'} = 1;
18223: }
1.368 raeburn 18224: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18225: if ($staticdefaults{'resetlink'} ne $linklife) {
18226: $changes{'reset'} = 1;
18227: }
18228: }
18229: } elsif ($current{'resetlink'}) {
18230: $changes{'reset'} = 1;
18231: }
18232: my @casesens;
18233: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
18234: foreach my $case (sort(@posscase)) {
18235: if (grep(/^\Q$case\E$/,@oktypes)) {
18236: push(@casesens,$case);
18237: }
18238: }
18239: $newvalues{'resetcase'} = \@casesens;
18240: if (ref($current{'resetcase'}) eq 'ARRAY') {
18241: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
18242: if (@diffs > 0) {
18243: $changes{'reset'} = 1;
18244: }
1.368 raeburn 18245: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18246: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
18247: if (@diffs > 0) {
18248: $changes{'reset'} = 1;
18249: }
18250: }
18251: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
18252: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
18253: if (exists($current{'resetprelink'})) {
18254: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
18255: $changes{'reset'} = 1;
18256: }
1.368 raeburn 18257: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18258: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
18259: $changes{'reset'} = 1;
18260: }
18261: }
18262: } elsif ($current{'resetprelink'}) {
18263: $changes{'reset'} = 1;
18264: }
18265: foreach my $type (@oktypes) {
18266: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
18267: my @postlink;
18268: foreach my $item (sort(@possplink)) {
18269: if ($item =~ /^(email|username)$/) {
18270: push(@postlink,$item);
18271: }
18272: }
18273: $newvalues{'resetpostlink'}{$type} = \@postlink;
18274: unless ($changes{'reset'}) {
18275: if (ref($current{'resetpostlink'}) eq 'HASH') {
18276: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
18277: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
18278: if (@diffs > 0) {
18279: $changes{'reset'} = 1;
18280: }
18281: } else {
18282: $changes{'reset'} = 1;
18283: }
1.368 raeburn 18284: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18285: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
18286: if (@diffs > 0) {
18287: $changes{'reset'} = 1;
18288: }
18289: }
18290: }
18291: }
18292: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
18293: my @resetemail;
18294: foreach my $item (sort(@possemailsrc)) {
18295: if ($item =~ /^(permanent|critical|notify)$/) {
18296: push(@resetemail,$item);
18297: }
18298: }
18299: $newvalues{'resetemail'} = \@resetemail;
18300: unless ($changes{'reset'}) {
18301: if (ref($current{'resetemail'}) eq 'ARRAY') {
18302: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
18303: if (@diffs > 0) {
18304: $changes{'reset'} = 1;
18305: }
1.368 raeburn 18306: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18307: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
18308: if (@diffs > 0) {
18309: $changes{'reset'} = 1;
18310: }
18311: }
18312: }
18313: if ($env{'form.passwords_stdtext'} == 0) {
18314: $newvalues{'resetremove'} = 1;
18315: unless ($current{'resetremove'}) {
18316: $changes{'reset'} = 1;
18317: }
18318: } elsif ($current{'resetremove'}) {
18319: $changes{'reset'} = 1;
18320: }
18321: if ($env{'form.passwords_customfile.filename'} ne '') {
18322: my $servadm = $r->dir_config('lonAdmEMail');
18323: my ($configuserok,$author_ok,$switchserver) =
18324: &config_check($dom,$confname,$servadm);
18325: my $error;
18326: if ($configuserok eq 'ok') {
18327: if ($switchserver) {
18328: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
18329: } else {
18330: if ($author_ok eq 'ok') {
1.421 raeburn 18331: my $modified = [];
1.354 raeburn 18332: my ($result,$customurl) =
1.421 raeburn 18333: &Apache::lonconfigsettings::publishlogo($r,'upload','passwords_customfile',$dom,
18334: $confname,'customtext/resetpw','','',$customfn,
18335: $modified);
1.354 raeburn 18336: if ($result eq 'ok') {
18337: $newvalues{'resetcustom'} = $customurl;
18338: $changes{'reset'} = 1;
1.421 raeburn 18339: &update_modify_urls($r,$modified);
1.354 raeburn 18340: } else {
18341: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
18342: }
18343: } else {
18344: $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);
18345: }
18346: }
18347: } else {
18348: $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);
18349: }
18350: if ($error) {
18351: &Apache::lonnet::logthis($error);
18352: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
18353: }
18354: } elsif ($current{'resetcustom'}) {
18355: if ($env{'form.passwords_custom_del'}) {
18356: $changes{'reset'} = 1;
18357: } else {
18358: $newvalues{'resetcustom'} = $current{'resetcustom'};
18359: }
18360: }
18361: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
18362: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
18363: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
18364: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
18365: $changes{'intauth'} = 1;
18366: }
18367: } else {
18368: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
18369: }
18370: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
18371: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
18372: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
18373: $changes{'intauth'} = 1;
18374: }
18375: } else {
18376: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18377: }
18378: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
18379: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
18380: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
18381: $changes{'intauth'} = 1;
18382: }
18383: } else {
18384: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18385: }
18386: foreach my $item ('cost','check','switch') {
18387: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
18388: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
18389: $updatedefaults = 1;
18390: }
18391: }
1.405 raeburn 18392: &password_rule_changes('passwords',\%newvalues,\%current,\%changes);
1.359 raeburn 18393: my %crsownerchg = (
18394: by => [],
18395: for => [],
18396: );
18397: foreach my $item ('by','for') {
18398: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
18399: foreach my $type (sort(@posstypes)) {
18400: if (grep(/^\Q$type\E$/,@oktypes)) {
18401: push(@{$crsownerchg{$item}},$type);
18402: }
18403: }
18404: }
18405: $newvalues{'crsownerchg'} = \%crsownerchg;
18406: if (ref($current{'crsownerchg'}) eq 'HASH') {
18407: foreach my $item ('by','for') {
18408: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
18409: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
18410: if (@diffs > 0) {
18411: $changes{'crsownerchg'} = 1;
18412: last;
18413: }
18414: }
18415: }
1.368 raeburn 18416: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359 raeburn 18417: foreach my $item ('by','for') {
18418: if (@{$crsownerchg{$item}} > 0) {
18419: $changes{'crsownerchg'} = 1;
18420: last;
18421: }
1.354 raeburn 18422: }
18423: }
18424:
18425: my %confighash = (
18426: defaults => \%save_defaults,
18427: passwords => \%newvalues,
18428: );
18429: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
18430:
18431: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
18432: if ($putresult eq 'ok') {
18433: if (keys(%changes) > 0) {
18434: $resulttext = &mt('Changes made: ').'<ul>';
18435: foreach my $key ('reset','intauth','rules','crsownerchg') {
18436: if ($changes{$key}) {
1.355 raeburn 18437: unless ($key eq 'intauth') {
18438: $updateconf = 1;
18439: }
1.354 raeburn 18440: $resulttext .= '<li>'.$titles{$key}.':<ul>';
18441: if ($key eq 'reset') {
18442: if ($confighash{'passwords'}{'captcha'} eq 'original') {
18443: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
18444: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
18445: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369 raeburn 18446: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
18447: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
18448: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
18449: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
18450: }
1.354 raeburn 18451: } else {
18452: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
18453: }
18454: if ($confighash{'passwords'}{'resetlink'}) {
18455: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
18456: } else {
18457: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
18458: &mt('Will default to 2 hours').'</li>';
18459: }
18460: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
18461: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
18462: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
18463: } else {
18464: my $casesens;
18465: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
18466: if ($type eq 'default') {
18467: $casesens .= $othertitle.', ';
18468: } elsif ($usertypes->{$type} ne '') {
18469: $casesens .= $usertypes->{$type}.', ';
18470: }
18471: }
18472: $casesens =~ s/\Q, \E$//;
18473: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
18474: }
18475: } else {
18476: $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>';
18477: }
18478: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
18479: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
18480: } else {
18481: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
18482: }
18483: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
18484: my $output;
18485: if (ref($types) eq 'ARRAY') {
18486: foreach my $type (@{$types}) {
18487: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
18488: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
18489: $output .= $usertypes->{$type}.' -- '.&mt('none');
18490: } else {
18491: $output .= $usertypes->{$type}.' -- '.
18492: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
18493: }
18494: }
18495: }
18496: }
18497: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
18498: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
18499: $output .= $othertitle.' -- '.&mt('none');
18500: } else {
18501: $output .= $othertitle.' -- '.
18502: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
18503: }
18504: }
18505: if ($output) {
18506: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
18507: } else {
18508: $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>';
18509: }
18510: } else {
18511: $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>';
18512: }
18513: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
18514: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
18515: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
18516: } else {
18517: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
18518: }
18519: } else {
1.379 raeburn 18520: $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 18521: }
18522: if ($confighash{'passwords'}{'resetremove'}) {
18523: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
18524: } else {
18525: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
18526: }
18527: if ($confighash{'passwords'}{'resetcustom'}) {
18528: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369 raeburn 18529: &mt('custom text'),600,500,undef,undef,
18530: undef,undef,'background-color:#ffffff');
18531: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354 raeburn 18532: } else {
18533: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
18534: }
18535: } elsif ($key eq 'intauth') {
18536: foreach my $item ('cost','switch','check') {
18537: my $value = $save_defaults{$key.'_'.$item};
18538: if ($item eq 'switch') {
18539: my %optiondesc = &Apache::lonlocal::texthash (
18540: 0 => 'No',
18541: 1 => 'Yes',
18542: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
18543: );
18544: if ($value =~ /^(0|1|2)$/) {
18545: $value = $optiondesc{$value};
18546: } else {
18547: $value = &mt('none -- defaults to No');
18548: }
18549: } elsif ($item eq 'check') {
18550: my %optiondesc = &Apache::lonlocal::texthash (
18551: 0 => 'No',
18552: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
18553: 2 => 'Yes, disallow login if stored cost is less than domain default',
18554: );
18555: if ($value =~ /^(0|1|2)$/) {
18556: $value = $optiondesc{$value};
18557: } else {
18558: $value = &mt('none -- defaults to No');
18559: }
18560: }
18561: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
18562: }
18563: } elsif ($key eq 'rules') {
1.356 raeburn 18564: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 18565: if ($confighash{'passwords'}{$rule} eq '') {
18566: if ($rule eq 'min') {
1.356 raeburn 18567: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365 raeburn 18568: ' '.&mt('Default of [_1] will be used',
18569: $Apache::lonnet::passwdmin).'</li>';
1.356 raeburn 18570: } else {
18571: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354 raeburn 18572: }
18573: } else {
18574: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
18575: }
18576: }
1.370 raeburn 18577: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
18578: if (@{$confighash{'passwords'}{'chars'}} > 0) {
18579: my %rulenames = &Apache::lonlocal::texthash(
18580: uc => 'At least one upper case letter',
18581: lc => 'At least one lower case letter',
18582: num => 'At least one number',
18583: spec => 'At least one non-alphanumeric',
18584: );
18585: my $needed = '<ul><li>'.
18586: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
1.425 raeburn 18587: '</li></ul>';
1.370 raeburn 18588: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
18589: } else {
18590: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18591: }
18592: } else {
18593: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18594: }
1.354 raeburn 18595: } elsif ($key eq 'crsownerchg') {
1.359 raeburn 18596: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
18597: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
18598: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
18599: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
18600: } else {
18601: my %crsownerstr;
18602: foreach my $item ('by','for') {
18603: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
18604: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
18605: if ($type eq 'default') {
18606: $crsownerstr{$item} .= $othertitle.', ';
18607: } elsif ($usertypes->{$type} ne '') {
18608: $crsownerstr{$item} .= $usertypes->{$type}.', ';
18609: }
18610: }
18611: $crsownerstr{$item} =~ s/\Q, \E$//;
18612: }
18613: }
18614: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
18615: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
18616: }
1.354 raeburn 18617: } else {
1.359 raeburn 18618: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354 raeburn 18619: }
18620: }
18621: $resulttext .= '</ul></li>';
18622: }
18623: }
18624: $resulttext .= '</ul>';
18625: } else {
18626: $resulttext = &mt('No changes made to password settings');
18627: }
1.355 raeburn 18628: my $cachetime = 24*60*60;
1.354 raeburn 18629: if ($updatedefaults) {
18630: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18631: if (ref($lastactref) eq 'HASH') {
18632: $lastactref->{'domdefaults'} = 1;
18633: }
18634: }
1.355 raeburn 18635: if ($updateconf) {
18636: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
18637: if (ref($lastactref) eq 'HASH') {
18638: $lastactref->{'passwdconf'} = 1;
18639: }
18640: }
1.354 raeburn 18641: } else {
18642: $resulttext = '<span class="LC_error">'.
18643: &mt('An error occurred: [_1]',$putresult).'</span>';
18644: }
18645: if ($errors) {
18646: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
18647: $errors.'</ul></p>';
18648: }
18649: return $resulttext;
18650: }
18651:
1.405 raeburn 18652: sub password_rule_changes {
18653: my ($prefix,$newvalues,$current,$changes) = @_;
18654: return unless ((ref($newvalues) eq 'HASH') &&
18655: (ref($current) eq 'HASH') &&
18656: (ref($changes) eq 'HASH'));
18657: my (@rules,%staticdefaults);
18658: if ($prefix eq 'passwords') {
18659: @rules = ('min','max','expire','numsaved');
1.421 raeburn 18660: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 18661: @rules = ('min','max');
18662: }
18663: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
18664: foreach my $rule (@rules) {
18665: $env{'form.'.$prefix.'_'.$rule} =~ s/^\s+|\s+$//g;
18666: my $ruleok;
18667: if ($rule eq 'expire') {
18668: if (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+(|\.\d*)$/) &&
18669: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18670: $ruleok = 1;
18671: }
18672: } elsif ($rule eq 'min') {
18673: if ($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) {
18674: if ($env{'form.'.$prefix.'_'.$rule} >= $staticdefaults{$rule}) {
18675: $ruleok = 1;
18676: }
18677: }
18678: } elsif (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) &&
18679: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18680: $ruleok = 1;
18681: }
18682: if ($ruleok) {
18683: $newvalues->{$rule} = $env{'form.'.$prefix.'_'.$rule};
18684: if (exists($current->{$rule})) {
18685: if ($newvalues->{$rule} ne $current->{$rule}) {
18686: $changes->{'rules'} = 1;
18687: }
18688: } elsif ($rule eq 'min') {
18689: if ($staticdefaults{$rule} ne $newvalues->{$rule}) {
18690: $changes->{'rules'} = 1;
18691: }
18692: } else {
18693: $changes->{'rules'} = 1;
18694: }
18695: } elsif (exists($current->{$rule})) {
18696: $changes->{'rules'} = 1;
18697: }
18698: }
18699: my @posschars = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_chars');
18700: my @chars;
18701: foreach my $item (sort(@posschars)) {
18702: if ($item =~ /^(uc|lc|num|spec)$/) {
18703: push(@chars,$item);
18704: }
18705: }
18706: $newvalues->{'chars'} = \@chars;
18707: unless ($changes->{'rules'}) {
18708: if (ref($current->{'chars'}) eq 'ARRAY') {
18709: my @diffs = &Apache::loncommon::compare_arrays($current->{'chars'},\@chars);
18710: if (@diffs > 0) {
18711: $changes->{'rules'} = 1;
18712: }
18713: } else {
18714: if (@chars > 0) {
18715: $changes->{'rules'} = 1;
18716: }
18717: }
18718: }
18719: return;
18720: }
18721:
1.28 raeburn 18722: sub modify_usercreation {
1.27 raeburn 18723: my ($dom,%domconfig) = @_;
1.224 raeburn 18724: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 18725: my $warningmsg;
1.27 raeburn 18726: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18727: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 18728: if ($key eq 'cancreate') {
18729: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18730: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 18731: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
18732: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18733: } else {
1.224 raeburn 18734: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18735: }
18736: }
18737: }
18738: } elsif ($key eq 'email_rule') {
18739: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18740: } else {
18741: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18742: }
1.27 raeburn 18743: }
18744: }
18745: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 18746: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 18747: my @contexts = ('author','course','requestcrs');
1.34 raeburn 18748: foreach my $item(@contexts) {
1.224 raeburn 18749: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 18750: }
1.34 raeburn 18751: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
18752: foreach my $item (@contexts) {
1.224 raeburn 18753: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
18754: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 18755: }
1.27 raeburn 18756: }
1.34 raeburn 18757: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
18758: foreach my $item (@contexts) {
1.43 raeburn 18759: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 18760: if ($cancreate{$item} ne 'any') {
18761: push(@{$changes{'cancreate'}},$item);
18762: }
18763: } else {
18764: if ($cancreate{$item} ne 'none') {
18765: push(@{$changes{'cancreate'}},$item);
18766: }
1.27 raeburn 18767: }
18768: }
18769: } else {
1.43 raeburn 18770: foreach my $item (@contexts) {
1.34 raeburn 18771: push(@{$changes{'cancreate'}},$item);
18772: }
1.27 raeburn 18773: }
1.34 raeburn 18774:
1.27 raeburn 18775: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
18776: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
18777: if (!grep(/^\Q$type\E$/,@username_rule)) {
18778: push(@{$changes{'username_rule'}},$type);
18779: }
18780: }
18781: foreach my $type (@username_rule) {
18782: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
18783: push(@{$changes{'username_rule'}},$type);
18784: }
18785: }
18786: } else {
18787: push(@{$changes{'username_rule'}},@username_rule);
18788: }
18789:
1.32 raeburn 18790: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
18791: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
18792: if (!grep(/^\Q$type\E$/,@id_rule)) {
18793: push(@{$changes{'id_rule'}},$type);
18794: }
18795: }
18796: foreach my $type (@id_rule) {
18797: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
18798: push(@{$changes{'id_rule'}},$type);
18799: }
18800: }
18801: } else {
18802: push(@{$changes{'id_rule'}},@id_rule);
18803: }
18804:
1.43 raeburn 18805: my @authen_contexts = ('author','course','domain');
1.325 raeburn 18806: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 18807: my %authhash;
1.43 raeburn 18808: foreach my $item (@authen_contexts) {
1.28 raeburn 18809: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
18810: foreach my $auth (@authtypes) {
18811: if (grep(/^\Q$auth\E$/,@authallowed)) {
18812: $authhash{$item}{$auth} = 1;
18813: } else {
18814: $authhash{$item}{$auth} = 0;
18815: }
18816: }
18817: }
18818: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 18819: foreach my $item (@authen_contexts) {
1.28 raeburn 18820: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
18821: foreach my $auth (@authtypes) {
18822: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
18823: push(@{$changes{'authtypes'}},$item);
18824: last;
18825: }
18826: }
18827: }
18828: }
18829: } else {
1.43 raeburn 18830: foreach my $item (@authen_contexts) {
1.28 raeburn 18831: push(@{$changes{'authtypes'}},$item);
18832: }
18833: }
18834:
1.224 raeburn 18835: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
18836: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
18837: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
18838: $save_usercreate{'id_rule'} = \@id_rule;
18839: $save_usercreate{'username_rule'} = \@username_rule,
18840: $save_usercreate{'authtypes'} = \%authhash;
18841:
1.27 raeburn 18842: my %usercreation_hash = (
1.224 raeburn 18843: usercreation => \%save_usercreate,
18844: );
1.27 raeburn 18845:
18846: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
18847: $dom);
1.50 raeburn 18848:
1.224 raeburn 18849: if ($putresult eq 'ok') {
18850: if (keys(%changes) > 0) {
18851: $resulttext = &mt('Changes made:').'<ul>';
18852: if (ref($changes{'cancreate'}) eq 'ARRAY') {
18853: my %lt = &usercreation_types();
18854: foreach my $type (@{$changes{'cancreate'}}) {
18855: my $chgtext = $lt{$type}.', ';
18856: if ($cancreate{$type} eq 'none') {
18857: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
18858: } elsif ($cancreate{$type} eq 'any') {
18859: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
18860: } elsif ($cancreate{$type} eq 'official') {
18861: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
18862: } elsif ($cancreate{$type} eq 'unofficial') {
18863: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
18864: }
18865: $resulttext .= '<li>'.$chgtext.'</li>';
18866: }
18867: }
18868: if (ref($changes{'username_rule'}) eq 'ARRAY') {
18869: my ($rules,$ruleorder) =
18870: &Apache::lonnet::inst_userrules($dom,'username');
18871: my $chgtext = '<ul>';
18872: foreach my $type (@username_rule) {
18873: if (ref($rules->{$type}) eq 'HASH') {
18874: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
18875: }
18876: }
18877: $chgtext .= '</ul>';
18878: if (@username_rule > 0) {
18879: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18880: } else {
18881: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
18882: }
18883: }
18884: if (ref($changes{'id_rule'}) eq 'ARRAY') {
18885: my ($idrules,$idruleorder) =
18886: &Apache::lonnet::inst_userrules($dom,'id');
18887: my $chgtext = '<ul>';
18888: foreach my $type (@id_rule) {
18889: if (ref($idrules->{$type}) eq 'HASH') {
18890: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
18891: }
18892: }
18893: $chgtext .= '</ul>';
18894: if (@id_rule > 0) {
18895: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18896: } else {
18897: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
18898: }
18899: }
18900: my %authname = &authtype_names();
18901: my %context_title = &context_names();
18902: if (ref($changes{'authtypes'}) eq 'ARRAY') {
18903: my $chgtext = '<ul>';
18904: foreach my $type (@{$changes{'authtypes'}}) {
18905: my @allowed;
18906: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
18907: foreach my $auth (@authtypes) {
18908: if ($authhash{$type}{$auth}) {
18909: push(@allowed,$authname{$auth});
18910: }
18911: }
18912: if (@allowed > 0) {
18913: $chgtext .= join(', ',@allowed).'</li>';
18914: } else {
18915: $chgtext .= &mt('none').'</li>';
18916: }
18917: }
18918: $chgtext .= '</ul>';
18919: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
18920: $resulttext .= '</li>';
18921: }
18922: $resulttext .= '</ul>';
18923: } else {
18924: $resulttext = &mt('No changes made to user creation settings');
18925: }
18926: } else {
18927: $resulttext = '<span class="LC_error">'.
18928: &mt('An error occurred: [_1]',$putresult).'</span>';
18929: }
18930: if ($warningmsg ne '') {
18931: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
18932: }
18933: return $resulttext;
18934: }
18935:
18936: sub modify_selfcreation {
1.305 raeburn 18937: my ($dom,$lastactref,%domconfig) = @_;
18938: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
18939: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
18940: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 18941: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
18942: if (ref($typesref) eq 'ARRAY') {
18943: @types = @{$typesref};
18944: }
18945: if (ref($usertypesref) eq 'HASH') {
18946: %usertypes = %{$usertypesref};
1.228 raeburn 18947: }
1.303 raeburn 18948: $usertypes{'default'} = $othertitle;
1.224 raeburn 18949: #
18950: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
18951: #
18952: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18953: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
18954: if ($key eq 'cancreate') {
18955: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18956: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
18957: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 18958: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
18959: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
18960: ($item eq 'emailusername') || ($item eq 'shibenv') ||
18961: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 18962: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 18963: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18964: } else {
18965: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18966: }
18967: }
18968: }
18969: } elsif ($key eq 'email_rule') {
18970: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18971: } else {
18972: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18973: }
18974: }
18975: }
18976: #
18977: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
18978: #
18979: if (ref($domconfig{'usermodification'}) eq 'HASH') {
18980: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
18981: if ($key eq 'selfcreate') {
18982: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
18983: } else {
18984: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
18985: }
18986: }
18987: }
1.305 raeburn 18988: #
18989: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
18990: #
18991: if (ref($domconfig{'inststatus'}) eq 'HASH') {
18992: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
18993: if ($key eq 'inststatusguest') {
18994: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
18995: } else {
18996: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
18997: }
18998: }
18999: }
1.224 raeburn 19000:
19001: my @contexts = ('selfcreate');
19002: @{$cancreate{'selfcreate'}} = ();
19003: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 19004: if (@types) {
19005: @{$cancreate{'statustocreate'}} = ();
19006: }
1.236 raeburn 19007: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 19008: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 19009: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 19010: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 19011: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 19012: my %selfcreatetypes = (
19013: sso => 'users authenticated by institutional single sign on',
19014: login => 'users authenticated by institutional log-in',
1.303 raeburn 19015: email => 'users verified by e-mail',
1.50 raeburn 19016: );
1.224 raeburn 19017: #
19018: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
19019: # is permitted.
19020: #
1.305 raeburn 19021: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 19022:
1.305 raeburn 19023: my (@statuses,%email_rule);
1.228 raeburn 19024: foreach my $item ('login','sso','email') {
1.224 raeburn 19025: if ($item eq 'email') {
1.236 raeburn 19026: if ($env{'form.cancreate_email'}) {
1.305 raeburn 19027: if (@types) {
19028: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
19029: foreach my $status (@poss_statuses) {
19030: if (grep(/^\Q$status\E$/,(@types,'default'))) {
19031: push(@statuses,$status);
19032: }
19033: }
19034: $save_inststatus{'inststatusguest'} = \@statuses;
19035: } else {
19036: push(@statuses,'default');
19037: }
19038: if (@statuses) {
19039: my %curr_rule;
19040: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
19041: foreach my $type (@statuses) {
19042: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 19043: }
1.305 raeburn 19044: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
19045: foreach my $type (@statuses) {
19046: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
19047: }
19048: }
19049: push(@{$cancreate{'selfcreate'}},'email');
19050: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
19051: my %curremaildom;
19052: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
19053: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
19054: }
19055: foreach my $type (@statuses) {
19056: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
19057: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
19058: }
19059: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
19060: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
19061: }
19062: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
19063: #
19064: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
19065: #
19066: my $chosen = $1;
19067: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
19068: my $emaildom;
19069: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
1.425 raeburn 19070: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
1.305 raeburn 19071: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
19072: if (ref($curremaildom{$type}) eq 'HASH') {
19073: if (exists($curremaildom{$type}{$chosen})) {
19074: if ($curremaildom{$type}{$chosen} ne $emaildom) {
19075: push(@{$changes{'cancreate'}},'emaildomain');
19076: }
19077: } elsif ($emaildom ne '') {
19078: push(@{$changes{'cancreate'}},'emaildomain');
19079: }
19080: } elsif ($emaildom ne '') {
19081: push(@{$changes{'cancreate'}},'emaildomain');
1.425 raeburn 19082: }
1.305 raeburn 19083: }
19084: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
19085: } elsif ($chosen eq 'custom') {
19086: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
19087: $email_rule{$type} = [];
19088: if (ref($emailrules) eq 'HASH') {
19089: foreach my $rule (@possemail_rules) {
19090: if (exists($emailrules->{$rule})) {
19091: push(@{$email_rule{$type}},$rule);
19092: }
19093: }
19094: }
19095: if (@{$email_rule{$type}}) {
19096: $cancreate{'emailoptions'}{$type} = 'custom';
19097: if (ref($curr_rule{$type}) eq 'ARRAY') {
19098: if (@{$curr_rule{$type}} > 0) {
19099: foreach my $rule (@{$curr_rule{$type}}) {
19100: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
19101: push(@{$changes{'email_rule'}},$type);
19102: }
19103: }
19104: }
19105: foreach my $type (@{$email_rule{$type}}) {
19106: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
19107: push(@{$changes{'email_rule'}},$type);
19108: }
19109: }
19110: } else {
19111: push(@{$changes{'email_rule'}},$type);
19112: }
19113: }
19114: } else {
19115: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
19116: }
19117: }
19118: }
19119: if (@types) {
19120: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19121: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
19122: if (@changed) {
19123: push(@{$changes{'inststatus'}},'inststatusguest');
19124: }
19125: } else {
19126: push(@{$changes{'inststatus'}},'inststatusguest');
19127: }
19128: }
19129: } else {
19130: delete($env{'form.cancreate_email'});
19131: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19132: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
19133: push(@{$changes{'inststatus'}},'inststatusguest');
19134: }
19135: }
19136: }
19137: } else {
19138: $save_inststatus{'inststatusguest'} = [];
19139: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19140: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
19141: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 19142: }
19143: }
1.224 raeburn 19144: }
19145: } else {
19146: if ($env{'form.cancreate_'.$item}) {
19147: push(@{$cancreate{'selfcreate'}},$item);
19148: }
19149: }
19150: }
1.305 raeburn 19151: my (%userinfo,%savecaptcha);
1.224 raeburn 19152: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
19153: #
1.228 raeburn 19154: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
19155: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 19156: #
1.236 raeburn 19157:
1.244 raeburn 19158: if ($env{'form.cancreate_email'}) {
1.228 raeburn 19159: push(@contexts,'emailusername');
1.305 raeburn 19160: if (@statuses) {
19161: foreach my $type (@statuses) {
1.228 raeburn 19162: if (ref($infofields) eq 'ARRAY') {
19163: foreach my $field (@{$infofields}) {
19164: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
19165: $cancreate{'emailusername'}{$type}{$field} = $1;
19166: }
19167: }
1.224 raeburn 19168: }
19169: }
19170: }
19171: #
19172: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 19173: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 19174: #
19175:
19176: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
19177: @approvalnotify = sort(@approvalnotify);
19178: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
19179: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
19180: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
19181: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
19182: push(@{$changes{'cancreate'}},'notify');
19183: }
19184: } else {
19185: if ($cancreate{'notify'}{'approval'}) {
19186: push(@{$changes{'cancreate'}},'notify');
19187: }
19188: }
19189: } elsif ($cancreate{'notify'}{'approval'}) {
19190: push(@{$changes{'cancreate'}},'notify');
19191: }
19192:
19193: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
19194: }
19195: #
1.236 raeburn 19196: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 19197: # institutional log-in.
19198: #
19199: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
19200: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
19201: ($domdefaults{'auth_def'} eq 'localauth'))) {
19202: $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.').' '.
19203: &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.');
19204: }
19205: }
19206: my @fields = ('lastname','firstname','middlename','generation',
19207: 'permanentemail','id');
1.240 raeburn 19208: my @shibfields = (@fields,'inststatus');
1.224 raeburn 19209: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19210: #
19211: # Where usernames may created for institutional log-in and/or institutional single sign on:
19212: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
19213: # may self-create accounts
19214: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
19215: # which the user may supply, if institutional data is unavailable.
19216: #
19217: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 19218: if (@types) {
1.305 raeburn 19219: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
19220: push(@contexts,'statustocreate');
1.303 raeburn 19221: foreach my $type (@types) {
1.224 raeburn 19222: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
19223: foreach my $field (@fields) {
19224: if (grep(/^\Q$field\E$/,@modifiable)) {
19225: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
19226: } else {
19227: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
19228: }
19229: }
19230: }
19231: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 19232: foreach my $type (@types) {
1.224 raeburn 19233: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
19234: foreach my $field (@fields) {
19235: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
19236: $curr_usermodify{'selfcreate'}{$type}{$field}) {
19237: push(@{$changes{'selfcreate'}},$type);
19238: last;
19239: }
19240: }
19241: }
19242: }
19243: } else {
1.303 raeburn 19244: foreach my $type (@types) {
1.224 raeburn 19245: push(@{$changes{'selfcreate'}},$type);
19246: }
19247: }
19248: }
1.240 raeburn 19249: foreach my $field (@shibfields) {
19250: if ($env{'form.shibenv_'.$field} ne '') {
19251: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
19252: }
19253: }
19254: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
19255: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
19256: foreach my $field (@shibfields) {
19257: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
19258: push(@{$changes{'cancreate'}},'shibenv');
19259: }
19260: }
19261: } else {
19262: foreach my $field (@shibfields) {
19263: if ($env{'form.shibenv_'.$field}) {
19264: push(@{$changes{'cancreate'}},'shibenv');
19265: last;
19266: }
19267: }
19268: }
19269: }
1.224 raeburn 19270: }
19271: foreach my $item (@contexts) {
19272: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
19273: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
19274: if (ref($cancreate{$item}) eq 'ARRAY') {
19275: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
19276: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19277: push(@{$changes{'cancreate'}},$item);
19278: }
19279: }
19280: }
19281: }
19282: if (ref($cancreate{$item}) eq 'ARRAY') {
19283: foreach my $type (@{$cancreate{$item}}) {
19284: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
19285: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19286: push(@{$changes{'cancreate'}},$item);
19287: }
19288: }
19289: }
19290: }
19291: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
19292: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 19293: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
19294: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19295: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
19296: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19297: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19298: push(@{$changes{'cancreate'}},$item);
19299: }
19300: }
19301: }
1.305 raeburn 19302: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19303: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19304: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19305: push(@{$changes{'cancreate'}},$item);
19306: }
1.224 raeburn 19307: }
19308: }
19309: }
1.305 raeburn 19310: foreach my $type (keys(%{$cancreate{$item}})) {
19311: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19312: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19313: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19314: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19315: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19316: push(@{$changes{'cancreate'}},$item);
19317: }
19318: }
19319: } else {
19320: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19321: push(@{$changes{'cancreate'}},$item);
19322: }
19323: }
19324: }
1.305 raeburn 19325: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19326: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19327: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19328: push(@{$changes{'cancreate'}},$item);
19329: }
1.224 raeburn 19330: }
19331: }
19332: }
19333: }
19334: } elsif ($curr_usercreation{'cancreate'}{$item}) {
19335: if (ref($cancreate{$item}) eq 'ARRAY') {
19336: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
19337: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19338: push(@{$changes{'cancreate'}},$item);
19339: }
19340: }
1.305 raeburn 19341: }
19342: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19343: if (ref($cancreate{$item}) eq 'HASH') {
19344: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19345: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 19346: }
19347: }
19348: } elsif ($item eq 'emailusername') {
1.228 raeburn 19349: if (ref($cancreate{$item}) eq 'HASH') {
19350: foreach my $type (keys(%{$cancreate{$item}})) {
19351: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19352: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19353: if ($cancreate{$item}{$type}{$field}) {
19354: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19355: push(@{$changes{'cancreate'}},$item);
19356: }
19357: last;
19358: }
19359: }
19360: }
19361: }
1.224 raeburn 19362: }
19363: }
19364: }
19365: #
19366: # Populate %save_usercreate hash with updates to self-creation configuration.
19367: #
19368: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
19369: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 19370: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 19371: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
19372: if (ref($cancreate{'notify'}) eq 'HASH') {
19373: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
19374: }
1.236 raeburn 19375: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
19376: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
19377: }
1.303 raeburn 19378: if (ref($cancreate{'emailverified'}) eq 'HASH') {
19379: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
19380: }
1.305 raeburn 19381: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
19382: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
19383: }
1.303 raeburn 19384: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
19385: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
19386: }
1.224 raeburn 19387: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19388: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
19389: }
1.240 raeburn 19390: if (ref($cancreate{'shibenv'}) eq 'HASH') {
19391: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
19392: }
1.224 raeburn 19393: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 19394: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 19395:
19396: my %userconfig_hash = (
19397: usercreation => \%save_usercreate,
19398: usermodification => \%save_usermodify,
1.305 raeburn 19399: inststatus => \%save_inststatus,
1.224 raeburn 19400: );
1.305 raeburn 19401:
1.224 raeburn 19402: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
19403: $dom);
19404: #
1.305 raeburn 19405: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 19406: #
1.27 raeburn 19407: if ($putresult eq 'ok') {
19408: if (keys(%changes) > 0) {
19409: $resulttext = &mt('Changes made:').'<ul>';
19410: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 19411: my %lt = &selfcreation_types();
1.34 raeburn 19412: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 19413: my $chgtext = '';
1.45 raeburn 19414: if ($type eq 'selfcreate') {
1.50 raeburn 19415: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 19416: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 19417: } else {
1.224 raeburn 19418: $chgtext .= &mt('Self-creation of a new account is permitted for:').
19419: '<ul>';
1.50 raeburn 19420: foreach my $case (@{$cancreate{$type}}) {
19421: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
19422: }
19423: $chgtext .= '</ul>';
1.100 raeburn 19424: if (ref($cancreate{$type}) eq 'ARRAY') {
19425: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
19426: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19427: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 19428: $chgtext .= '<span class="LC_warning">'.
19429: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
19430: '</span><br />';
19431: }
19432: }
19433: }
19434: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 19435: if (!@statuses) {
19436: $chgtext .= '<span class="LC_warning">'.
19437: &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.").
19438: '</span><br />';
1.303 raeburn 19439:
1.100 raeburn 19440: }
19441: }
19442: }
1.43 raeburn 19443: }
1.240 raeburn 19444: } elsif ($type eq 'shibenv') {
19445: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 19446: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 19447: } else {
19448: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
19449: '<ul>';
19450: foreach my $field (@shibfields) {
19451: next if ($cancreate{$type}{$field} eq '');
19452: if ($field eq 'inststatus') {
19453: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
19454: } else {
19455: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
19456: }
19457: }
19458: $chgtext .= '</ul>';
1.303 raeburn 19459: }
1.93 raeburn 19460: } elsif ($type eq 'statustocreate') {
1.96 raeburn 19461: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
19462: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
19463: if (@{$cancreate{'selfcreate'}} > 0) {
19464: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 19465: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 19466: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 19467: $chgtext .= '<br />'.
19468: '<span class="LC_warning">'.
19469: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
19470: '</span>';
19471: }
1.303 raeburn 19472: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 19473: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 19474: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
19475: } else {
19476: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
19477: }
19478: $chgtext .= '<ul>';
19479: foreach my $case (@{$cancreate{$type}}) {
19480: if ($case eq 'default') {
19481: $chgtext .= '<li>'.$othertitle.'</li>';
19482: } else {
1.303 raeburn 19483: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 19484: }
19485: }
1.100 raeburn 19486: $chgtext .= '</ul>';
19487: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 19488: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 19489: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
19490: '</span>';
1.100 raeburn 19491: }
19492: }
19493: } else {
19494: if (@{$cancreate{$type}} == 0) {
19495: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
19496: } else {
19497: $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 19498: }
19499: }
1.303 raeburn 19500: $chgtext .= '<br />';
1.93 raeburn 19501: }
1.236 raeburn 19502: } elsif ($type eq 'selfcreateprocessing') {
19503: my %choices = &Apache::lonlocal::texthash (
19504: automatic => 'Automatic approval',
19505: approval => 'Queued for approval',
19506: );
1.305 raeburn 19507: if (@types) {
19508: if (@statuses) {
1.425 raeburn 19509: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 19510: '<ul>';
1.305 raeburn 19511: foreach my $status (@statuses) {
19512: if ($status eq 'default') {
19513: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19514: } else {
1.305 raeburn 19515: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19516: }
19517: }
19518: $chgtext .= '</ul>';
19519: }
19520: } else {
19521: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
19522: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
19523: }
19524: } elsif ($type eq 'emailverified') {
19525: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 19526: all => 'Same as e-mail',
19527: first => 'Omit @domain',
19528: free => 'Free to choose',
1.303 raeburn 19529: );
1.305 raeburn 19530: if (@types) {
19531: if (@statuses) {
1.303 raeburn 19532: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
19533: '<ul>';
1.305 raeburn 19534: foreach my $status (@statuses) {
1.362 raeburn 19535: if ($status eq 'default') {
1.305 raeburn 19536: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19537: } else {
1.305 raeburn 19538: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19539: }
19540: }
19541: $chgtext .= '</ul>';
19542: }
19543: } else {
1.305 raeburn 19544: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 19545: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 19546: }
1.305 raeburn 19547: } elsif ($type eq 'emailoptions') {
19548: my %options = &Apache::lonlocal::texthash (
19549: any => 'Any e-mail',
19550: inst => 'Institutional only',
19551: noninst => 'Non-institutional only',
19552: custom => 'Custom restrictions',
19553: );
19554: if (@types) {
19555: if (@statuses) {
19556: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
19557: '<ul>';
19558: foreach my $status (@statuses) {
19559: if ($type eq 'default') {
19560: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
19561: } else {
19562: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 19563: }
19564: }
1.305 raeburn 19565: $chgtext .= '</ul>';
19566: }
19567: } else {
19568: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
19569: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
19570: } else {
19571: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
19572: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 19573: }
1.305 raeburn 19574: }
19575: } elsif ($type eq 'emaildomain') {
19576: my $output;
19577: if (@statuses) {
19578: foreach my $type (@statuses) {
19579: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
19580: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
19581: if ($type eq 'default') {
19582: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19583: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19584: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19585: } else {
19586: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
19587: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
19588: }
1.303 raeburn 19589: } else {
1.305 raeburn 19590: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19591: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19592: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19593: } else {
19594: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
1.421 raeburn 19595: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
1.305 raeburn 19596: }
1.303 raeburn 19597: }
1.305 raeburn 19598: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
19599: if ($type eq 'default') {
19600: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19601: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19602: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19603: } else {
19604: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
19605: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
19606: }
1.303 raeburn 19607: } else {
1.305 raeburn 19608: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19609: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19610: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19611: } else {
19612: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
1.421 raeburn 19613: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
1.305 raeburn 19614: }
1.303 raeburn 19615: }
19616: }
19617: }
19618: }
1.305 raeburn 19619: }
19620: if ($output ne '') {
19621: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
19622: '<ul>'.$output.'</ul>';
1.236 raeburn 19623: }
1.165 raeburn 19624: } elsif ($type eq 'captcha') {
1.224 raeburn 19625: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 19626: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
19627: } else {
19628: my %captchas = &captcha_phrases();
1.224 raeburn 19629: if ($captchas{$savecaptcha{$type}}) {
19630: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 19631: } else {
1.210 raeburn 19632: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 19633: }
19634: }
19635: } elsif ($type eq 'recaptchakeys') {
19636: my ($privkey,$pubkey);
1.224 raeburn 19637: if (ref($savecaptcha{$type}) eq 'HASH') {
19638: $pubkey = $savecaptcha{$type}{'public'};
19639: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 19640: }
19641: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
19642: if (!$pubkey) {
19643: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
19644: } else {
19645: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
19646: }
19647: if (!$privkey) {
19648: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
19649: } else {
19650: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
19651: }
19652: $chgtext .= '</ul>';
1.269 raeburn 19653: } elsif ($type eq 'recaptchaversion') {
19654: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 19655: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 19656: }
1.224 raeburn 19657: } elsif ($type eq 'emailusername') {
19658: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 19659: if (@statuses) {
19660: foreach my $type (@statuses) {
1.228 raeburn 19661: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
19662: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 19663: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 19664: '<ul>';
19665: foreach my $field (@{$infofields}) {
19666: if ($cancreate{'emailusername'}{$type}{$field}) {
19667: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
19668: }
19669: }
1.245 raeburn 19670: $chgtext .= '</ul>';
19671: } else {
1.303 raeburn 19672: $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 19673: }
19674: } else {
1.303 raeburn 19675: $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 19676: }
19677: }
19678: }
19679: }
19680: } elsif ($type eq 'notify') {
1.303 raeburn 19681: my $numapprove = 0;
1.224 raeburn 19682: if (ref($changes{'cancreate'}) eq 'ARRAY') {
19683: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
19684: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 19685: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
19686: $numapprove ++;
1.224 raeburn 19687: }
19688: }
1.43 raeburn 19689: }
1.303 raeburn 19690: unless ($numapprove) {
19691: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
19692: }
1.34 raeburn 19693: }
1.224 raeburn 19694: if ($chgtext) {
19695: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 19696: }
19697: }
19698: }
1.305 raeburn 19699: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 19700: my ($emailrules,$emailruleorder) =
19701: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 19702: foreach my $type (@{$changes{'email_rule'}}) {
19703: if (ref($email_rule{$type}) eq 'ARRAY') {
19704: my $chgtext = '<ul>';
19705: foreach my $rule (@{$email_rule{$type}}) {
19706: if (ref($emailrules->{$rule}) eq 'HASH') {
19707: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
19708: }
19709: }
19710: $chgtext .= '</ul>';
1.310 raeburn 19711: my $typename;
1.305 raeburn 19712: if (@types) {
19713: if ($type eq 'default') {
19714: $typename = $othertitle;
19715: } else {
19716: $typename = $usertypes{$type};
1.425 raeburn 19717: }
1.305 raeburn 19718: $chgtext .= &mt('(Affiliation: [_1])',$typename);
19719: }
19720: if (@{$email_rule{$type}} > 0) {
19721: $resulttext .= '<li>'.
19722: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
19723: $usertypes{$type}).
19724: $chgtext.
19725: '</li>';
19726: } else {
19727: $resulttext .= '<li>'.
1.310 raeburn 19728: &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 19729: '</li>'.
1.310 raeburn 19730: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 19731: }
1.43 raeburn 19732: }
19733: }
1.305 raeburn 19734: }
19735: if (ref($changes{'inststatus'}) eq 'ARRAY') {
19736: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
19737: if (@{$save_inststatus{'inststatusguest'}} > 0) {
19738: my $chgtext = '<ul>';
19739: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
19740: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
19741: }
19742: $chgtext .= '</ul>';
19743: $resulttext .= '<li>'.
19744: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
19745: $chgtext.
19746: '</li>';
19747: } else {
19748: $resulttext .= '<li>'.
19749: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
19750: '</li>';
19751: }
1.43 raeburn 19752: }
19753: }
1.224 raeburn 19754: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
19755: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
19756: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19757: foreach my $type (@{$changes{'selfcreate'}}) {
19758: my $typename = $type;
1.303 raeburn 19759: if (keys(%usertypes) > 0) {
19760: if ($usertypes{$type} ne '') {
19761: $typename = $usertypes{$type};
1.224 raeburn 19762: }
19763: }
19764: my @modifiable;
19765: $resulttext .= '<li>'.
19766: &mt('Self-creation of account by users with status: [_1]',
19767: '<span class="LC_cusr_emph">'.$typename.'</span>').
19768: ' - '.&mt('modifiable fields (if institutional data blank): ');
19769: foreach my $field (@fields) {
19770: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
19771: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 19772: }
19773: }
1.224 raeburn 19774: if (@modifiable > 0) {
19775: $resulttext .= join(', ',@modifiable);
1.43 raeburn 19776: } else {
1.224 raeburn 19777: $resulttext .= &mt('none');
1.43 raeburn 19778: }
1.224 raeburn 19779: $resulttext .= '</li>';
1.28 raeburn 19780: }
1.224 raeburn 19781: $resulttext .= '</ul></li>';
1.28 raeburn 19782: }
1.27 raeburn 19783: $resulttext .= '</ul>';
1.305 raeburn 19784: my $cachetime = 24*60*60;
19785: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
19786: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19787: if (ref($lastactref) eq 'HASH') {
19788: $lastactref->{'domdefaults'} = 1;
19789: }
1.27 raeburn 19790: } else {
1.224 raeburn 19791: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 19792: }
19793: } else {
19794: $resulttext = '<span class="LC_error">'.
1.23 raeburn 19795: &mt('An error occurred: [_1]',$putresult).'</span>';
19796: }
1.43 raeburn 19797: if ($warningmsg ne '') {
19798: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
19799: }
1.23 raeburn 19800: return $resulttext;
19801: }
19802:
1.165 raeburn 19803: sub process_captcha {
1.369 raeburn 19804: my ($container,$changes,$newsettings,$currsettings) = @_;
19805: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165 raeburn 19806: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
19807: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
19808: $newsettings->{'captcha'} = 'original';
19809: }
1.369 raeburn 19810: my %current;
19811: if (ref($currsettings) eq 'HASH') {
19812: %current = %{$currsettings};
19813: }
19814: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 19815: if ($container eq 'cancreate') {
1.169 raeburn 19816: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19817: push(@{$changes->{'cancreate'}},'captcha');
19818: } elsif (!defined($changes->{'cancreate'})) {
19819: $changes->{'cancreate'} = ['captcha'];
19820: }
1.368 raeburn 19821: } elsif ($container eq 'passwords') {
19822: $changes->{'reset'} = 1;
1.169 raeburn 19823: } else {
19824: $changes->{'captcha'} = 1;
1.165 raeburn 19825: }
19826: }
1.269 raeburn 19827: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 19828: if ($newsettings->{'captcha'} eq 'recaptcha') {
19829: $newpub = $env{'form.'.$container.'_recaptchapub'};
19830: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 19831: $newpub =~ s/[^\w\-]//g;
19832: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 19833: $newsettings->{'recaptchakeys'} = {
19834: public => $newpub,
19835: private => $newpriv,
19836: };
1.269 raeburn 19837: $newversion = $env{'form.'.$container.'_recaptchaversion'};
19838: $newversion =~ s/\D//g;
19839: if ($newversion ne '2') {
19840: $newversion = 1;
19841: }
19842: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 19843: }
1.369 raeburn 19844: if (ref($current{'recaptchakeys'}) eq 'HASH') {
19845: $currpub = $current{'recaptchakeys'}{'public'};
19846: $currpriv = $current{'recaptchakeys'}{'private'};
1.179 raeburn 19847: unless ($newsettings->{'captcha'} eq 'recaptcha') {
19848: $newsettings->{'recaptchakeys'} = {
19849: public => '',
19850: private => '',
19851: }
19852: }
1.165 raeburn 19853: }
1.369 raeburn 19854: if ($current{'captcha'} eq 'recaptcha') {
19855: $currversion = $current{'recaptchaversion'};
1.269 raeburn 19856: if ($currversion ne '2') {
19857: $currversion = 1;
19858: }
19859: }
19860: if ($currversion ne $newversion) {
19861: if ($container eq 'cancreate') {
19862: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19863: push(@{$changes->{'cancreate'}},'recaptchaversion');
19864: } elsif (!defined($changes->{'cancreate'})) {
19865: $changes->{'cancreate'} = ['recaptchaversion'];
19866: }
1.368 raeburn 19867: } elsif ($container eq 'passwords') {
19868: $changes->{'reset'} = 1;
1.269 raeburn 19869: } else {
19870: $changes->{'recaptchaversion'} = 1;
19871: }
19872: }
1.165 raeburn 19873: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 19874: if ($container eq 'cancreate') {
19875: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19876: push(@{$changes->{'cancreate'}},'recaptchakeys');
19877: } elsif (!defined($changes->{'cancreate'})) {
19878: $changes->{'cancreate'} = ['recaptchakeys'];
19879: }
1.368 raeburn 19880: } elsif ($container eq 'passwords') {
19881: $changes->{'reset'} = 1;
1.169 raeburn 19882: } else {
1.210 raeburn 19883: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 19884: }
19885: }
19886: return;
19887: }
19888:
1.33 raeburn 19889: sub modify_usermodification {
19890: my ($dom,%domconfig) = @_;
1.224 raeburn 19891: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 19892: if (ref($domconfig{'usermodification'}) eq 'HASH') {
19893: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 19894: if ($key eq 'selfcreate') {
19895: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
19896: } else {
19897: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
19898: }
1.33 raeburn 19899: }
19900: }
1.443 raeburn 19901: my @contexts = ('author','coauthor','course');
1.33 raeburn 19902: my %context_title = (
19903: author => 'In author context',
1.443 raeburn 19904: coauthor => 'As co-author manager',
1.33 raeburn 19905: course => 'In course context',
19906: );
19907: my @fields = ('lastname','firstname','middlename','generation',
19908: 'permanentemail','id');
19909: my %roles = (
19910: author => ['ca','aa'],
1.443 raeburn 19911: coauthor => ['ca','aa'],
1.33 raeburn 19912: course => ['st','ep','ta','in','cr'],
19913: );
19914: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19915: foreach my $context (@contexts) {
1.443 raeburn 19916: my $prefix = 'canmodify';
19917: if ($context eq 'coauthor') {
19918: $prefix = 'cacanmodify';
19919: }
1.33 raeburn 19920: foreach my $role (@{$roles{$context}}) {
1.443 raeburn 19921: my @modifiable = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$role);
1.33 raeburn 19922: foreach my $item (@fields) {
19923: if (grep(/^\Q$item\E$/,@modifiable)) {
19924: $modifyhash{$context}{$role}{$item} = 1;
19925: } else {
19926: $modifyhash{$context}{$role}{$item} = 0;
19927: }
19928: }
19929: }
19930: if (ref($curr_usermodification{$context}) eq 'HASH') {
19931: foreach my $role (@{$roles{$context}}) {
19932: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
19933: foreach my $field (@fields) {
19934: if ($modifyhash{$context}{$role}{$field} ne
19935: $curr_usermodification{$context}{$role}{$field}) {
19936: push(@{$changes{$context}},$role);
19937: last;
19938: }
19939: }
19940: }
19941: }
19942: } else {
19943: foreach my $context (@contexts) {
19944: foreach my $role (@{$roles{$context}}) {
19945: push(@{$changes{$context}},$role);
19946: }
19947: }
19948: }
19949: }
19950: my %usermodification_hash = (
19951: usermodification => \%modifyhash,
19952: );
19953: my $putresult = &Apache::lonnet::put_dom('configuration',
19954: \%usermodification_hash,$dom);
19955: if ($putresult eq 'ok') {
19956: if (keys(%changes) > 0) {
19957: $resulttext = &mt('Changes made: ').'<ul>';
19958: foreach my $context (@contexts) {
19959: if (ref($changes{$context}) eq 'ARRAY') {
19960: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
19961: if (ref($changes{$context}) eq 'ARRAY') {
19962: foreach my $role (@{$changes{$context}}) {
19963: my $rolename;
1.224 raeburn 19964: if ($role eq 'cr') {
19965: $rolename = &mt('Custom');
1.33 raeburn 19966: } else {
1.224 raeburn 19967: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 19968: }
19969: my @modifiable;
1.224 raeburn 19970: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 19971: foreach my $field (@fields) {
19972: if ($modifyhash{$context}{$role}{$field}) {
19973: push(@modifiable,$fieldtitles{$field});
19974: }
19975: }
19976: if (@modifiable > 0) {
19977: $resulttext .= join(', ',@modifiable);
19978: } else {
19979: $resulttext .= &mt('none');
19980: }
19981: $resulttext .= '</li>';
19982: }
19983: $resulttext .= '</ul></li>';
19984: }
19985: }
19986: }
19987: $resulttext .= '</ul>';
19988: } else {
19989: $resulttext = &mt('No changes made to user modification settings');
19990: }
19991: } else {
19992: $resulttext = '<span class="LC_error">'.
19993: &mt('An error occurred: [_1]',$putresult).'</span>';
19994: }
19995: return $resulttext;
19996: }
19997:
1.43 raeburn 19998: sub modify_defaults {
1.212 raeburn 19999: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 20000: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 20001: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 20002: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 20003: 'portal_def');
1.325 raeburn 20004: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 20005: foreach my $item (@items) {
20006: $newvalues{$item} = $env{'form.'.$item};
20007: if ($item eq 'auth_def') {
20008: if ($newvalues{$item} ne '') {
20009: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
20010: push(@errors,$item);
20011: }
20012: }
20013: } elsif ($item eq 'lang_def') {
20014: if ($newvalues{$item} ne '') {
20015: if ($newvalues{$item} =~ /^(\w+)/) {
20016: my $langcode = $1;
1.103 raeburn 20017: if ($langcode ne 'x_chef') {
20018: if (code2language($langcode) eq '') {
20019: push(@errors,$item);
20020: }
1.43 raeburn 20021: }
20022: } else {
20023: push(@errors,$item);
20024: }
20025: }
1.54 raeburn 20026: } elsif ($item eq 'timezone_def') {
20027: if ($newvalues{$item} ne '') {
1.62 raeburn 20028: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 20029: push(@errors,$item);
20030: }
20031: }
1.68 raeburn 20032: } elsif ($item eq 'datelocale_def') {
20033: if ($newvalues{$item} ne '') {
20034: my @datelocale_ids = DateTime::Locale->ids();
20035: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
20036: push(@errors,$item);
20037: }
20038: }
1.141 raeburn 20039: } elsif ($item eq 'portal_def') {
20040: if ($newvalues{$item} ne '') {
1.414 raeburn 20041: 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])\/?$/) {
20042: foreach my $field ('email','web') {
20043: if ($env{'form.'.$item.'_'.$field}) {
20044: $newvalues{$item.'_'.$field} = $env{'form.'.$item.'_'.$field};
20045: }
20046: }
20047: } else {
1.141 raeburn 20048: push(@errors,$item);
20049: }
20050: }
1.43 raeburn 20051: }
20052: if (grep(/^\Q$item\E$/,@errors)) {
20053: $newvalues{$item} = $domdefaults{$item};
1.414 raeburn 20054: if ($item eq 'portal_def') {
20055: if ($domdefaults{$item}) {
20056: foreach my $field ('email','web') {
20057: if (exists($domdefaults{$item.'_'.$field})) {
20058: $newvalues{$item.'_'.$field} = $domdefaults{$item.'_'.$field};
20059: }
20060: }
20061: }
20062: }
1.43 raeburn 20063: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
20064: $changes{$item} = 1;
20065: }
1.414 raeburn 20066: if ($item eq 'portal_def') {
20067: unless (grep(/^\Q$item\E$/,@errors)) {
1.425 raeburn 20068: if ($newvalues{$item} eq '') {
1.414 raeburn 20069: foreach my $field ('email','web') {
20070: if (exists($domdefaults{$item.'_'.$field})) {
20071: delete($domdefaults{$item.'_'.$field});
20072: }
20073: }
20074: } else {
20075: unless ($changes{$item}) {
20076: foreach my $field ('email','web') {
20077: if ($domdefaults{$item.'_'.$field} ne $newvalues{$item.'_'.$field}) {
20078: $changes{$item} = 1;
20079: last;
20080: }
20081: }
20082: }
20083: foreach my $field ('email','web') {
20084: if ($newvalues{$item.'_'.$field}) {
20085: $domdefaults{$item.'_'.$field} = $newvalues{$item.'_'.$field};
20086: } elsif (exists($domdefaults{$item.'_'.$field})) {
20087: delete($domdefaults{$item.'_'.$field});
20088: }
20089: }
20090: }
20091: }
20092: }
1.72 raeburn 20093: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 20094: }
1.354 raeburn 20095: my %staticdefaults = (
20096: 'intauth_cost' => 10,
20097: 'intauth_check' => 0,
20098: 'intauth_switch' => 0,
20099: );
20100: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
20101: if (exists($domdefaults{$item})) {
20102: $newvalues{$item} = $domdefaults{$item};
20103: } else {
20104: $newvalues{$item} = $staticdefaults{$item};
20105: }
20106: }
1.409 raeburn 20107: my ($unamemaprules,$ruleorder);
20108: my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
20109: if (@possunamemaprules) {
20110: ($unamemaprules,$ruleorder) =
20111: &Apache::lonnet::inst_userrules($dom,'unamemap');
20112: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
20113: if (@{$ruleorder} > 0) {
20114: my %possrules;
20115: map { $possrules{$_} = 1; } @possunamemaprules;
20116: foreach my $rule (@{$ruleorder}) {
20117: if ($possrules{$rule}) {
20118: push(@{$newvalues{'unamemap_rule'}},$rule);
20119: }
20120: }
20121: }
20122: }
20123: }
20124: if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
20125: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20126: my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
20127: $newvalues{'unamemap_rule'});
20128: if (@rulediffs) {
20129: $changes{'unamemap_rule'} = 1;
20130: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
20131: }
20132: } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
20133: $changes{'unamemap_rule'} = 1;
20134: delete($domdefaults{'unamemap_rule'});
20135: }
20136: } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20137: if (@{$newvalues{'unamemap_rule'}} > 0) {
20138: $changes{'unamemap_rule'} = 1;
20139: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
20140: }
20141: }
1.43 raeburn 20142: my %defaults_hash = (
1.72 raeburn 20143: defaults => \%newvalues,
20144: );
1.43 raeburn 20145: my $title = &defaults_titles();
1.236 raeburn 20146:
20147: my $currinststatus;
20148: if (ref($domconfig{'inststatus'}) eq 'HASH') {
20149: $currinststatus = $domconfig{'inststatus'};
20150: } else {
20151: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
20152: $currinststatus = {
20153: inststatustypes => $usertypes,
20154: inststatusorder => $types,
20155: inststatusguest => [],
20156: };
20157: }
20158: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
20159: my @allpos;
20160: my %alltypes;
1.305 raeburn 20161: my @inststatusguest;
20162: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
20163: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
20164: unless (grep(/^\Q$type\E$/,@todelete)) {
20165: push(@inststatusguest,$type);
20166: }
20167: }
20168: }
20169: my ($currtitles,$currorder);
1.236 raeburn 20170: if (ref($currinststatus) eq 'HASH') {
20171: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
20172: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
20173: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
20174: if ($currinststatus->{inststatustypes}->{$type} ne '') {
20175: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
20176: }
20177: }
20178: unless (grep(/^\Q$type\E$/,@todelete)) {
20179: my $position = $env{'form.inststatus_pos_'.$type};
20180: $position =~ s/\D+//g;
20181: $allpos[$position] = $type;
20182: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
20183: $alltypes{$type} =~ s/`//g;
20184: }
20185: }
20186: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
20187: $currtitles =~ s/,$//;
20188: }
20189: }
20190: if ($env{'form.addinststatus'}) {
20191: my $newtype = $env{'form.addinststatus'};
20192: $newtype =~ s/\W//g;
20193: unless (exists($alltypes{$newtype})) {
20194: $alltypes{$newtype} = $env{'form.addinststatus_title'};
20195: $alltypes{$newtype} =~ s/`//g;
20196: my $position = $env{'form.addinststatus_pos'};
20197: $position =~ s/\D+//g;
20198: if ($position ne '') {
20199: $allpos[$position] = $newtype;
20200: }
20201: }
20202: }
1.305 raeburn 20203: my @orderedstatus;
1.236 raeburn 20204: foreach my $type (@allpos) {
20205: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
20206: push(@orderedstatus,$type);
20207: }
20208: }
20209: foreach my $type (keys(%alltypes)) {
20210: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
20211: delete($alltypes{$type});
20212: }
20213: }
20214: $defaults_hash{'inststatus'} = {
20215: inststatustypes => \%alltypes,
20216: inststatusorder => \@orderedstatus,
1.305 raeburn 20217: inststatusguest => \@inststatusguest,
1.236 raeburn 20218: };
20219: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
20220: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
20221: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
20222: }
20223: }
20224: if ($currorder ne join(',',@orderedstatus)) {
20225: $changes{'inststatus'}{'inststatusorder'} = 1;
20226: }
20227: my $newtitles;
20228: foreach my $item (@orderedstatus) {
20229: $newtitles .= $alltypes{$item}.',';
20230: }
20231: $newtitles =~ s/,$//;
20232: if ($currtitles ne $newtitles) {
20233: $changes{'inststatus'}{'inststatustypes'} = 1;
20234: }
1.43 raeburn 20235: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
20236: $dom);
20237: if ($putresult eq 'ok') {
20238: if (keys(%changes) > 0) {
20239: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 20240: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 20241: 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";
20242: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 20243: if ($item eq 'inststatus') {
20244: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 20245: if (@orderedstatus) {
1.236 raeburn 20246: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
20247: foreach my $type (@orderedstatus) {
20248: $resulttext .= $alltypes{$type}.', ';
20249: }
20250: $resulttext =~ s/, $//;
20251: $resulttext .= '</li>';
1.305 raeburn 20252: } else {
1.425 raeburn 20253: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 20254: }
20255: }
1.409 raeburn 20256: } elsif ($item eq 'unamemap_rule') {
20257: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20258: my @rulenames;
20259: if (ref($unamemaprules) eq 'HASH') {
20260: foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
20261: if (ref($unamemaprules->{$rule}) eq 'HASH') {
20262: push(@rulenames,$unamemaprules->{$rule}->{'name'});
20263: }
20264: }
20265: }
20266: if (@rulenames) {
20267: $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
20268: '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
20269: '</li>';
20270: } else {
20271: $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
20272: }
20273: } else {
20274: $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
20275: }
1.236 raeburn 20276: } else {
20277: my $value = $env{'form.'.$item};
20278: if ($value eq '') {
20279: $value = &mt('none');
20280: } elsif ($item eq 'auth_def') {
20281: my %authnames = &authtype_names();
20282: my %shortauth = (
20283: internal => 'int',
20284: krb4 => 'krb4',
20285: krb5 => 'krb5',
20286: localauth => 'loc',
1.325 raeburn 20287: lti => 'lti',
1.236 raeburn 20288: );
20289: $value = $authnames{$shortauth{$value}};
20290: }
20291: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
1.414 raeburn 20292: $mailmsgtext .= "$title->{$item} set to $value\n";
20293: if ($item eq 'portal_def') {
20294: if ($env{'form.'.$item} ne '') {
20295: foreach my $field ('email','web') {
20296: $value = $env{'form.'.$item.'_'.$field};
20297: if ($value) {
20298: $value = &mt('Yes');
20299: } else {
20300: $value = &mt('No');
20301: }
20302: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$field},$value).'</li>';
20303: }
20304: }
20305: }
1.43 raeburn 20306: }
20307: }
20308: $resulttext .= '</ul>';
20309: $mailmsgtext .= "\n";
20310: my $cachetime = 24*60*60;
1.72 raeburn 20311: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 20312: if (ref($lastactref) eq 'HASH') {
20313: $lastactref->{'domdefaults'} = 1;
20314: }
1.68 raeburn 20315: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 20316: my $notify = 1;
20317: if (ref($domconfig{'contacts'}) eq 'HASH') {
20318: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
20319: $notify = 0;
20320: }
20321: }
20322: if ($notify) {
20323: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
20324: "LON-CAPA Domain Settings Change - $dom",
20325: $mailmsgtext);
20326: }
1.54 raeburn 20327: }
1.43 raeburn 20328: } else {
1.54 raeburn 20329: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 20330: }
20331: } else {
20332: $resulttext = '<span class="LC_error">'.
20333: &mt('An error occurred: [_1]',$putresult).'</span>';
20334: }
20335: if (@errors > 0) {
20336: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
20337: foreach my $item (@errors) {
20338: $resulttext .= ' "'.$title->{$item}.'",';
20339: }
20340: $resulttext =~ s/,$//;
20341: }
20342: return $resulttext;
20343: }
20344:
1.46 raeburn 20345: sub modify_scantron {
1.205 raeburn 20346: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 20347: my ($resulttext,%confhash,%changes,$errors);
20348: my $custom = 'custom.tab';
20349: my $default = 'default.tab';
20350: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 20351: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 20352: &config_check($dom,$confname,$servadm);
20353: if ($env{'form.scantronformat.filename'} ne '') {
20354: my $error;
20355: if ($configuserok eq 'ok') {
20356: if ($switchserver) {
1.130 raeburn 20357: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 20358: } else {
20359: if ($author_ok eq 'ok') {
1.421 raeburn 20360: my $modified = [];
1.46 raeburn 20361: my ($result,$scantronurl) =
1.421 raeburn 20362: &Apache::lonconfigsettings::publishlogo($r,'upload','scantronformat',$dom,
20363: $confname,'scantron','','',$custom,
20364: $modified);
1.46 raeburn 20365: if ($result eq 'ok') {
20366: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 20367: $changes{'scantronformat'} = 1;
1.421 raeburn 20368: &update_modify_urls($r,$modified);
1.46 raeburn 20369: } else {
20370: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
20371: }
20372: } else {
20373: $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);
20374: }
20375: }
20376: } else {
20377: $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);
20378: }
20379: if ($error) {
20380: &Apache::lonnet::logthis($error);
20381: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
20382: }
20383: }
1.48 raeburn 20384: if (ref($domconfig{'scantron'}) eq 'HASH') {
20385: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
20386: if ($env{'form.scantronformat_del'}) {
20387: $confhash{'scantron'}{'scantronformat'} = '';
20388: $changes{'scantronformat'} = 1;
1.347 raeburn 20389: } else {
20390: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 20391: }
20392: }
20393: }
1.347 raeburn 20394: my @options = ('hdr','pad','rem');
1.346 raeburn 20395: my @fields = &scantroncsv_fields();
20396: my %titles = &scantronconfig_titles();
1.347 raeburn 20397: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 20398: my ($newdat,$currdat,%newcol,%currcol);
20399: if (grep(/^dat$/,@formats)) {
20400: $confhash{'scantron'}{config}{dat} = 1;
20401: $newdat = 1;
20402: } else {
20403: $newdat = 0;
20404: }
20405: if (grep(/^csv$/,@formats)) {
20406: my %bynum;
20407: foreach my $field (@fields) {
20408: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
20409: my $posscol = $1;
20410: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 20411: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 20412: $bynum{$posscol} = $field;
20413: $newcol{$field} = $posscol;
20414: }
20415: }
20416: }
1.347 raeburn 20417: if (keys(%newcol)) {
20418: foreach my $option (@options) {
20419: if ($env{'form.scantroncsv_'.$option}) {
20420: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
20421: }
20422: }
20423: }
1.346 raeburn 20424: }
20425: $currdat = 1;
20426: if (ref($domconfig{'scantron'}) eq 'HASH') {
20427: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 20428: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 20429: $currdat = 0;
20430: }
20431: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20432: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20433: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
20434: }
1.346 raeburn 20435: }
20436: }
20437: }
20438: if ($currdat != $newdat) {
20439: $changes{'config'} = 1;
20440: } else {
20441: foreach my $field (@fields) {
20442: if ($currcol{$field} ne '') {
20443: if ($currcol{$field} ne $newcol{$field}) {
20444: $changes{'config'} = 1;
20445: last;
1.347 raeburn 20446: }
1.346 raeburn 20447: } elsif ($newcol{$field} ne '') {
20448: $changes{'config'} = 1;
20449: last;
20450: }
20451: }
20452: }
1.46 raeburn 20453: if (keys(%confhash) > 0) {
20454: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
20455: $dom);
20456: if ($putresult eq 'ok') {
20457: if (keys(%changes) > 0) {
1.48 raeburn 20458: if (ref($confhash{'scantron'}) eq 'HASH') {
20459: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 20460: if ($changes{'scantronformat'}) {
20461: if ($confhash{'scantron'}{'scantronformat'} eq '') {
20462: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
20463: } else {
20464: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
20465: }
20466: }
1.347 raeburn 20467: if ($changes{'config'}) {
1.346 raeburn 20468: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
20469: if ($confhash{'scantron'}{'config'}{'dat'}) {
20470: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
20471: }
20472: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20473: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20474: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
20475: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
20476: foreach my $field (@fields) {
20477: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
20478: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
20479: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
20480: }
20481: }
20482: $resulttext .= '</ul></li>';
20483: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
20484: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
20485: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
20486: foreach my $option (@options) {
20487: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
20488: $resulttext .= '<li>'.$titles{$option}.'</li>';
20489: }
20490: }
20491: $resulttext .= '</ul></li>';
20492: }
1.346 raeburn 20493: }
20494: }
20495: }
20496: }
20497: } else {
20498: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
20499: }
1.46 raeburn 20500: }
1.48 raeburn 20501: $resulttext .= '</ul>';
20502: } else {
1.130 raeburn 20503: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 20504: }
20505: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 20506: if (ref($lastactref) eq 'HASH') {
20507: $lastactref->{'domainconfig'} = 1;
20508: }
1.46 raeburn 20509: } else {
1.346 raeburn 20510: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 20511: }
20512: } else {
20513: $resulttext = '<span class="LC_error">'.
20514: &mt('An error occurred: [_1]',$putresult).'</span>';
20515: }
20516: } else {
1.130 raeburn 20517: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 20518: }
20519: if ($errors) {
1.353 raeburn 20520: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
20521: $errors.'</ul></p>';
1.46 raeburn 20522: }
20523: return $resulttext;
20524: }
20525:
1.48 raeburn 20526: sub modify_coursecategories {
1.239 raeburn 20527: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 20528: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
20529: $cathash);
1.48 raeburn 20530: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 20531: my @catitems = ('unauth','auth');
20532: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 20533: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 20534: $cathash = $domconfig{'coursecategories'}{'cats'};
20535: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
20536: $changes{'togglecats'} = 1;
20537: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
20538: }
20539: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
20540: $changes{'categorize'} = 1;
20541: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
20542: }
1.120 raeburn 20543: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
20544: $changes{'togglecatscomm'} = 1;
20545: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
20546: }
20547: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
20548: $changes{'categorizecomm'} = 1;
20549: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 20550:
20551: }
20552: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
20553: $changes{'togglecatsplace'} = 1;
20554: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
20555: }
20556: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
20557: $changes{'categorizeplace'} = 1;
20558: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 20559: }
1.238 raeburn 20560: foreach my $item (@catitems) {
20561: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20562: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
20563: $changes{$item} = 1;
20564: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20565: }
20566: }
20567: }
1.57 raeburn 20568: } else {
20569: $changes{'togglecats'} = 1;
20570: $changes{'categorize'} = 1;
1.124 raeburn 20571: $changes{'togglecatscomm'} = 1;
20572: $changes{'categorizecomm'} = 1;
1.272 raeburn 20573: $changes{'togglecatsplace'} = 1;
20574: $changes{'categorizeplace'} = 1;
1.87 raeburn 20575: $domconfig{'coursecategories'} = {
20576: togglecats => $env{'form.togglecats'},
20577: categorize => $env{'form.categorize'},
1.124 raeburn 20578: togglecatscomm => $env{'form.togglecatscomm'},
20579: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 20580: togglecatsplace => $env{'form.togglecatsplace'},
20581: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 20582: };
1.238 raeburn 20583: foreach my $item (@catitems) {
20584: if ($env{'form.coursecat_'.$item} ne 'std') {
20585: $changes{$item} = 1;
20586: }
20587: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20588: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20589: }
20590: }
1.57 raeburn 20591: }
20592: if (ref($cathash) eq 'HASH') {
20593: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 20594: push (@deletecategory,'instcode::0');
20595: }
1.120 raeburn 20596: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
20597: push(@deletecategory,'communities::0');
20598: }
1.272 raeburn 20599: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
20600: push(@deletecategory,'placement::0');
20601: }
1.48 raeburn 20602: }
1.57 raeburn 20603: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
20604: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20605: if (@deletecategory > 0) {
20606: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 20607: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 20608: foreach my $item (@deletecategory) {
1.57 raeburn 20609: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
20610: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 20611: $deletions{$item} = 1;
1.57 raeburn 20612: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 20613: }
20614: }
20615: }
1.57 raeburn 20616: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 20617: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 20618: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 20619: $reorderings{$item} = 1;
1.57 raeburn 20620: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 20621: }
20622: if ($env{'form.addcategory_name_'.$item} ne '') {
20623: my $newcat = $env{'form.addcategory_name_'.$item};
20624: my $newdepth = $depth+1;
20625: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20626: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 20627: $adds{$newitem} = 1;
20628: }
20629: if ($env{'form.subcat_'.$item} ne '') {
20630: my $newcat = $env{'form.subcat_'.$item};
20631: my $newdepth = $depth+1;
20632: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20633: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 20634: $adds{$newitem} = 1;
20635: }
20636: }
20637: }
20638: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 20639: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20640: my $newitem = 'instcode::0';
1.57 raeburn 20641: if ($cathash->{$newitem} eq '') {
20642: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20643: $adds{$newitem} = 1;
20644: }
20645: } else {
20646: my $newitem = 'instcode::0';
1.57 raeburn 20647: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20648: $adds{$newitem} = 1;
20649: }
20650: }
1.120 raeburn 20651: if ($env{'form.communities'} eq '1') {
20652: if (ref($cathash) eq 'HASH') {
20653: my $newitem = 'communities::0';
20654: if ($cathash->{$newitem} eq '') {
20655: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20656: $adds{$newitem} = 1;
20657: }
20658: } else {
20659: my $newitem = 'communities::0';
20660: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20661: $adds{$newitem} = 1;
20662: }
20663: }
1.272 raeburn 20664: if ($env{'form.placement'} eq '1') {
20665: if (ref($cathash) eq 'HASH') {
20666: my $newitem = 'placement::0';
20667: if ($cathash->{$newitem} eq '') {
20668: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20669: $adds{$newitem} = 1;
20670: }
20671: } else {
20672: my $newitem = 'placement::0';
20673: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20674: $adds{$newitem} = 1;
20675: }
20676: }
1.48 raeburn 20677: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 20678: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 20679: ($env{'form.addcategory_name'} ne 'communities') &&
20680: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 20681: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
20682: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
20683: $adds{$newitem} = 1;
20684: }
1.48 raeburn 20685: }
1.57 raeburn 20686: my $putresult;
1.48 raeburn 20687: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20688: if (keys(%deletions) > 0) {
20689: foreach my $key (keys(%deletions)) {
20690: if ($predelallitems{$key} ne '') {
20691: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
20692: }
20693: }
20694: }
20695: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 20696: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 20697: if (ref($chkcats[0]) eq 'ARRAY') {
20698: my $depth = 0;
20699: my $chg = 0;
20700: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
20701: my $name = $chkcats[0][$i];
20702: my $item;
20703: if ($name eq '') {
20704: $chg ++;
20705: } else {
20706: $item = &escape($name).'::0';
20707: if ($chg) {
1.57 raeburn 20708: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 20709: }
20710: $depth ++;
1.57 raeburn 20711: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 20712: $depth --;
20713: }
20714: }
20715: }
1.57 raeburn 20716: }
20717: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20718: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 20719: if ($putresult eq 'ok') {
1.57 raeburn 20720: my %title = (
1.120 raeburn 20721: togglecats => 'Show/Hide a course in catalog',
20722: categorize => 'Assign a category to a course',
20723: togglecatscomm => 'Show/Hide a community in catalog',
20724: categorizecomm => 'Assign a category to a community',
1.57 raeburn 20725: );
20726: my %level = (
1.120 raeburn 20727: dom => 'set in Domain ("Modify Course/Community")',
20728: crs => 'set in Course ("Course Configuration")',
20729: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 20730: none => 'No catalog',
20731: std => 'Standard catalog',
20732: domonly => 'Domain-only catalog',
20733: codesrch => 'Code search form',
1.57 raeburn 20734: );
1.48 raeburn 20735: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 20736: if ($changes{'togglecats'}) {
20737: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
20738: }
20739: if ($changes{'categorize'}) {
20740: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 20741: }
1.120 raeburn 20742: if ($changes{'togglecatscomm'}) {
20743: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
20744: }
20745: if ($changes{'categorizecomm'}) {
20746: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
20747: }
1.238 raeburn 20748: if ($changes{'unauth'}) {
20749: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
20750: }
20751: if ($changes{'auth'}) {
20752: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
20753: }
1.57 raeburn 20754: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20755: my $cathash;
20756: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
20757: $cathash = $domconfig{'coursecategories'}{'cats'};
20758: } else {
20759: $cathash = {};
20760: }
20761: my (@cats,@trails,%allitems);
20762: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
20763: if (keys(%deletions) > 0) {
20764: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
20765: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
20766: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
20767: }
20768: $resulttext .= '</ul></li>';
20769: }
20770: if (keys(%reorderings) > 0) {
20771: my %sort_by_trail;
20772: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
20773: foreach my $key (keys(%reorderings)) {
20774: if ($allitems{$key} ne '') {
20775: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20776: }
1.48 raeburn 20777: }
1.57 raeburn 20778: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20779: $resulttext .= '<li>'.$trails[$trail].'</li>';
20780: }
20781: $resulttext .= '</ul></li>';
1.48 raeburn 20782: }
1.57 raeburn 20783: if (keys(%adds) > 0) {
20784: my %sort_by_trail;
20785: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
20786: foreach my $key (keys(%adds)) {
20787: if ($allitems{$key} ne '') {
20788: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20789: }
20790: }
20791: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20792: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 20793: }
1.57 raeburn 20794: $resulttext .= '</ul></li>';
1.48 raeburn 20795: }
1.364 raeburn 20796: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
20797: if (ref($lastactref) eq 'HASH') {
20798: $lastactref->{'cats'} = 1;
20799: }
1.48 raeburn 20800: }
20801: $resulttext .= '</ul>';
1.239 raeburn 20802: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 20803: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
20804: if ($changes{'auth'}) {
20805: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
20806: }
20807: if ($changes{'unauth'}) {
20808: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
20809: }
20810: my $cachetime = 24*60*60;
20811: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 20812: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 20813: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 20814: }
20815: }
1.48 raeburn 20816: } else {
20817: $resulttext = '<span class="LC_error">'.
1.57 raeburn 20818: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 20819: }
20820: } else {
1.120 raeburn 20821: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 20822: }
20823: return $resulttext;
20824: }
20825:
1.69 raeburn 20826: sub modify_serverstatuses {
20827: my ($dom,%domconfig) = @_;
20828: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
20829: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
20830: %currserverstatus = %{$domconfig{'serverstatuses'}};
20831: }
20832: my @pages = &serverstatus_pages();
20833: foreach my $type (@pages) {
20834: $newserverstatus{$type}{'namedusers'} = '';
20835: $newserverstatus{$type}{'machines'} = '';
20836: if (defined($env{'form.'.$type.'_namedusers'})) {
20837: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
20838: my @okusers;
20839: foreach my $user (@users) {
20840: my ($uname,$udom) = split(/:/,$user);
20841: if (($udom =~ /^$match_domain$/) &&
20842: (&Apache::lonnet::domain($udom)) &&
20843: ($uname =~ /^$match_username$/)) {
20844: if (!grep(/^\Q$user\E/,@okusers)) {
20845: push(@okusers,$user);
20846: }
20847: }
20848: }
20849: if (@okusers > 0) {
20850: @okusers = sort(@okusers);
20851: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
20852: }
20853: }
20854: if (defined($env{'form.'.$type.'_machines'})) {
20855: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
20856: my @okmachines;
20857: foreach my $ip (@machines) {
20858: my @parts = split(/\./,$ip);
20859: next if (@parts < 4);
20860: my $badip = 0;
20861: for (my $i=0; $i<4; $i++) {
20862: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
20863: $badip = 1;
20864: last;
20865: }
20866: }
20867: if (!$badip) {
20868: push(@okmachines,$ip);
20869: }
20870: }
20871: @okmachines = sort(@okmachines);
20872: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
20873: }
20874: }
20875: my %serverstatushash = (
20876: serverstatuses => \%newserverstatus,
20877: );
20878: foreach my $type (@pages) {
1.83 raeburn 20879: foreach my $setting ('namedusers','machines') {
1.84 raeburn 20880: my (@current,@new);
1.83 raeburn 20881: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 20882: if ($currserverstatus{$type}{$setting} ne '') {
20883: @current = split(/,/,$currserverstatus{$type}{$setting});
20884: }
20885: }
20886: if ($newserverstatus{$type}{$setting} ne '') {
20887: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 20888: }
20889: if (@current > 0) {
20890: if (@new > 0) {
20891: foreach my $item (@current) {
20892: if (!grep(/^\Q$item\E$/,@new)) {
20893: $changes{$type}{$setting} = 1;
1.82 raeburn 20894: last;
20895: }
20896: }
1.84 raeburn 20897: foreach my $item (@new) {
20898: if (!grep(/^\Q$item\E$/,@current)) {
20899: $changes{$type}{$setting} = 1;
20900: last;
1.82 raeburn 20901: }
20902: }
20903: } else {
1.83 raeburn 20904: $changes{$type}{$setting} = 1;
1.69 raeburn 20905: }
1.83 raeburn 20906: } elsif (@new > 0) {
20907: $changes{$type}{$setting} = 1;
1.69 raeburn 20908: }
20909: }
20910: }
20911: if (keys(%changes) > 0) {
1.81 raeburn 20912: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 20913: my $putresult = &Apache::lonnet::put_dom('configuration',
20914: \%serverstatushash,$dom);
20915: if ($putresult eq 'ok') {
20916: $resulttext .= &mt('Changes made:').'<ul>';
20917: foreach my $type (@pages) {
1.84 raeburn 20918: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 20919: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 20920: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 20921: if ($newserverstatus{$type}{'namedusers'} eq '') {
20922: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
20923: } else {
20924: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
20925: }
1.84 raeburn 20926: }
20927: if ($changes{$type}{'machines'}) {
1.69 raeburn 20928: if ($newserverstatus{$type}{'machines'} eq '') {
20929: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
20930: } else {
20931: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
20932: }
20933:
20934: }
20935: $resulttext .= '</ul></li>';
20936: }
20937: }
20938: $resulttext .= '</ul>';
20939: } else {
20940: $resulttext = '<span class="LC_error">'.
20941: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
20942:
20943: }
20944: } else {
20945: $resulttext = &mt('No changes made to access to server status pages');
20946: }
20947: return $resulttext;
20948: }
20949:
1.118 jms 20950: sub modify_helpsettings {
1.285 raeburn 20951: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 20952: my ($resulttext,$errors,%changes,%helphash);
20953: my %defaultchecked = ('submitbugs' => 'on');
20954: my @offon = ('off','on');
1.118 jms 20955: my @toggles = ('submitbugs');
1.285 raeburn 20956: my %current = ('submitbugs' => '',
20957: 'adhoc' => {},
20958: );
1.118 jms 20959: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 20960: %current = %{$domconfig{'helpsettings'}};
20961: }
1.285 raeburn 20962: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 20963: foreach my $item (@toggles) {
20964: if ($defaultchecked{$item} eq 'on') {
20965: if ($current{$item} eq '') {
20966: if ($env{'form.'.$item} eq '0') {
20967: $changes{$item} = 1;
20968: }
20969: } elsif ($current{$item} ne $env{'form.'.$item}) {
20970: $changes{$item} = 1;
20971: }
20972: } elsif ($defaultchecked{$item} eq 'off') {
20973: if ($current{$item} eq '') {
20974: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 20975: $changes{$item} = 1;
20976: }
1.282 raeburn 20977: } elsif ($current{$item} ne $env{'form.'.$item}) {
20978: $changes{$item} = 1;
20979: }
20980: }
20981: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
20982: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
20983: }
20984: }
1.285 raeburn 20985: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 20986: my $confname = $dom.'-domainconfig';
20987: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 20988: my (@allpos,%newsettings,%changedprivs,$newrole);
20989: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 20990: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 20991: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 20992: my %lt = &Apache::lonlocal::texthash(
20993: s => 'system',
20994: d => 'domain',
20995: order => 'Display order',
20996: access => 'Role usage',
1.291 raeburn 20997: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 20998: dh => 'All with domain helpdesk role',
20999: da => 'All with domain helpdesk assistant role',
1.285 raeburn 21000: none => 'None',
21001: status => 'Determined based on institutional status',
21002: inc => 'Include all, but exclude specific personnel',
21003: exc => 'Exclude all, but include specific personnel',
21004: );
21005: for (my $num=0; $num<=$maxnum; $num++) {
21006: my ($prefix,$identifier,$rolename,%curr);
21007: if ($num == $maxnum) {
21008: next unless ($env{'form.newcusthelp'} == $maxnum);
21009: $identifier = 'custhelp'.$num;
21010: $prefix = 'helproles_'.$num;
21011: $rolename = $env{'form.custhelpname'.$num};
21012: $rolename=~s/[^A-Za-z0-9]//gs;
21013: next if ($rolename eq '');
21014: next if (exists($existing{'rolesdef_'.$rolename}));
21015: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
21016: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
21017: $newprivs{'c'},$confname,$dom);
21018: if ($result ne 'ok') {
21019: $errors .= '<li><span class="LC_error">'.
21020: &mt('An error occurred storing the new custom role: [_1]',
21021: $result).'</span></li>';
21022: next;
21023: } else {
21024: $changedprivs{$rolename} = \%newprivs;
21025: $newrole = $rolename;
21026: }
21027: } else {
21028: $prefix = 'helproles_'.$num;
21029: $rolename = $env{'form.'.$prefix};
21030: next if ($rolename eq '');
21031: next unless (exists($existing{'rolesdef_'.$rolename}));
21032: $identifier = 'custhelp'.$num;
21033: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
21034: my %currprivs;
1.289 raeburn 21035: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 21036: split(/\_/,$existing{'rolesdef_'.$rolename});
21037: foreach my $level ('c','d','s') {
21038: if ($newprivs{$level} ne $currprivs{$level}) {
21039: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
21040: $newprivs{'c'},$confname,$dom);
21041: if ($result ne 'ok') {
21042: $errors .= '<li><span class="LC_error">'.
21043: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
21044: $rolename,$result).'</span></li>';
21045: } else {
21046: $changedprivs{$rolename} = \%newprivs;
21047: }
21048: last;
21049: }
21050: }
21051: if (ref($current{'adhoc'}) eq 'HASH') {
21052: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
21053: %curr = %{$current{'adhoc'}{$rolename}};
21054: }
21055: }
21056: }
21057: my $newpos = $env{'form.'.$prefix.'_pos'};
21058: $newpos =~ s/\D+//g;
21059: $allpos[$newpos] = $rolename;
21060: my $newdesc = $env{'form.'.$prefix.'_desc'};
21061: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
21062: if ($curr{'desc'}) {
21063: if ($curr{'desc'} ne $newdesc) {
21064: $changes{'customrole'}{$rolename}{'desc'} = 1;
21065: $newsettings{$rolename}{'desc'} = $newdesc;
21066: }
21067: } elsif ($newdesc ne '') {
21068: $changes{'customrole'}{$rolename}{'desc'} = 1;
21069: $newsettings{$rolename}{'desc'} = $newdesc;
21070: }
21071: my $access = $env{'form.'.$prefix.'_access'};
21072: if (grep(/^\Q$access\E$/,@accesstypes)) {
21073: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
21074: if ($access eq 'status') {
21075: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
21076: if (scalar(@statuses) == 0) {
1.289 raeburn 21077: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 21078: } else {
21079: my (@shownstatus,$numtypes);
21080: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
21081: if (ref($types) eq 'ARRAY') {
21082: $numtypes = scalar(@{$types});
21083: foreach my $type (sort(@statuses)) {
21084: if ($type eq 'default') {
21085: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
21086: } elsif (grep(/^\Q$type\E$/,@{$types})) {
21087: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
21088: push(@shownstatus,$usertypes->{$type});
21089: }
21090: }
21091: }
21092: if (grep(/^default$/,@statuses)) {
21093: push(@shownstatus,$othertitle);
21094: }
21095: if (scalar(@shownstatus) == 1+$numtypes) {
21096: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
21097: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
21098: } else {
21099: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
21100: if (ref($curr{'status'}) eq 'ARRAY') {
21101: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
21102: if (@diffs) {
21103: $changes{'customrole'}{$rolename}{$access} = 1;
21104: }
21105: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21106: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 21107: }
1.166 raeburn 21108: }
21109: }
1.285 raeburn 21110: } elsif (($access eq 'inc') || ($access eq 'exc')) {
21111: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
21112: my @newspecstaff;
21113: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
21114: foreach my $person (sort(@personnel)) {
21115: if ($domhelpdesk{$person}) {
21116: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
21117: }
21118: }
21119: if (ref($curr{$access}) eq 'ARRAY') {
21120: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
21121: if (@diffs) {
21122: $changes{'customrole'}{$rolename}{$access} = 1;
21123: }
21124: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21125: $changes{'customrole'}{$rolename}{$access} = 1;
21126: }
21127: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21128: my ($uname,$udom) = split(/:/,$person);
21129: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
21130: }
21131: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 21132: }
1.285 raeburn 21133: } else {
21134: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
21135: }
21136: unless ($curr{'access'} eq $access) {
21137: $changes{'customrole'}{$rolename}{'access'} = 1;
21138: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 21139: }
21140: }
1.285 raeburn 21141: if (@allpos > 0) {
21142: my $idx = 0;
21143: foreach my $rolename (@allpos) {
21144: if ($rolename ne '') {
21145: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
21146: if (ref($current{'adhoc'}) eq 'HASH') {
21147: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
21148: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
21149: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 21150: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 21151: }
21152: }
1.282 raeburn 21153: }
1.285 raeburn 21154: $idx ++;
1.166 raeburn 21155: }
21156: }
1.118 jms 21157: }
1.123 jms 21158: my $putresult;
21159: if (keys(%changes) > 0) {
1.166 raeburn 21160: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 21161: if ($putresult eq 'ok') {
1.285 raeburn 21162: if (ref($helphash{'helpsettings'}) eq 'HASH') {
21163: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
21164: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
21165: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
21166: }
21167: }
21168: my $cachetime = 24*60*60;
21169: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21170: if (ref($lastactref) eq 'HASH') {
21171: $lastactref->{'domdefaults'} = 1;
21172: }
21173: } else {
21174: $errors .= '<li><span class="LC_error">'.
21175: &mt('An error occurred storing the settings: [_1]',
21176: $putresult).'</span></li>';
21177: }
21178: }
21179: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
21180: $resulttext = &mt('Changes made:').'<ul>';
21181: my (%shownprivs,@levelorder);
21182: @levelorder = ('c','d','s');
21183: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 21184: foreach my $item (sort(keys(%changes))) {
21185: if ($item eq 'submitbugs') {
21186: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
21187: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
21188: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 21189: } elsif ($item eq 'customrole') {
21190: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 21191: my @keyorder = ('order','desc','access','status','exc','inc');
21192: my %keytext = &Apache::lonlocal::texthash(
21193: order => 'Order',
21194: desc => 'Role description',
21195: access => 'Role usage',
1.300 droeschl 21196: status => 'Allowed institutional types',
1.285 raeburn 21197: exc => 'Allowed personnel',
21198: inc => 'Disallowed personnel',
21199: );
1.282 raeburn 21200: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 21201: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
21202: if ($role eq $newrole) {
21203: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
21204: $role).'<ul>';
21205: } else {
21206: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
21207: $role).'<ul>';
21208: }
21209: foreach my $key (@keyorder) {
21210: if ($changes{'customrole'}{$role}{$key}) {
21211: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
21212: $keytext{$key},$newsettings{$role}{$key}).
21213: '</li>';
21214: }
21215: }
21216: if (ref($changedprivs{$role}) eq 'HASH') {
21217: $shownprivs{$role} = 1;
21218: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
21219: foreach my $level (@levelorder) {
21220: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
21221: next if ($item eq '');
21222: my ($priv) = split(/\&/,$item,2);
21223: if (&Apache::lonnet::plaintext($priv)) {
21224: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
21225: unless ($level eq 'c') {
21226: $resulttext .= ' ('.$lt{$level}.')';
21227: }
21228: $resulttext .= '</li>';
21229: }
21230: }
21231: }
21232: $resulttext .= '</ul>';
21233: }
21234: $resulttext .= '</ul></li>';
21235: }
21236: }
21237: }
21238: }
21239: }
21240: }
21241: if (keys(%changedprivs)) {
21242: foreach my $role (sort(keys(%changedprivs))) {
21243: unless ($shownprivs{$role}) {
21244: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
21245: $role).'<ul>'.
21246: '<li>'.&mt('Privileges set to :').'<ul>';
21247: foreach my $level (@levelorder) {
21248: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
21249: next if ($item eq '');
21250: my ($priv) = split(/\&/,$item,2);
21251: if (&Apache::lonnet::plaintext($priv)) {
21252: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
21253: unless ($level eq 'c') {
21254: $resulttext .= ' ('.$lt{$level}.')';
21255: }
21256: $resulttext .= '</li>';
21257: }
1.282 raeburn 21258: }
21259: }
1.285 raeburn 21260: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 21261: }
21262: }
21263: }
1.285 raeburn 21264: $resulttext .= '</ul>';
21265: } else {
21266: $resulttext = &mt('No changes made to help settings');
1.118 jms 21267: }
21268: if ($errors) {
1.168 raeburn 21269: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 21270: $errors.'</ul>';
1.118 jms 21271: }
21272: return $resulttext;
21273: }
21274:
1.121 raeburn 21275: sub modify_coursedefaults {
1.212 raeburn 21276: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 21277: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 21278: my %defaultchecked = (
21279: 'canuse_pdfforms' => 'off',
21280: 'uselcmath' => 'on',
1.398 raeburn 21281: 'usejsme' => 'on',
21282: 'inline_chem' => 'on',
1.404 raeburn 21283: 'ltiauth' => 'off',
1.257 raeburn 21284: );
1.404 raeburn 21285: my @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem','ltiauth');
1.198 raeburn 21286: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 21287: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
1.428 raeburn 21288: 'coursequota_official','coursequota_unofficial','coursequota_community',
21289: 'coursequota_textbook','coursequota_placement','mysqltables_official',
21290: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook',
21291: 'mysqltables_placement');
1.271 raeburn 21292: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 21293: my %staticdefaults = (
21294: anonsurvey_threshold => 10,
21295: uploadquota => 500,
1.428 raeburn 21296: coursequota => 20,
1.257 raeburn 21297: postsubmit => 60,
1.276 raeburn 21298: mysqltables => 172800,
1.422 raeburn 21299: domexttool => 1,
1.432 raeburn 21300: crsauthor => 1,
1.438 raeburn 21301: crseditors => ['edit','xml'],
1.198 raeburn 21302: );
1.314 raeburn 21303: my %texoptions = (
21304: MathJax => 'MathJax',
21305: mimetex => &mt('Convert to Images'),
21306: tth => &mt('TeX to HTML'),
21307: );
1.438 raeburn 21308:
21309: my @editors = ('edit','xml','daxe');
21310: my %editornames = &crseditor_titles();
21311:
1.121 raeburn 21312: $defaultshash{'coursedefaults'} = {};
21313:
21314: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
21315: if ($domconfig{'coursedefaults'} eq '') {
21316: $domconfig{'coursedefaults'} = {};
21317: }
21318: }
21319:
21320: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
21321: foreach my $item (@toggles) {
21322: if ($defaultchecked{$item} eq 'on') {
21323: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21324: ($env{'form.'.$item} eq '0')) {
21325: $changes{$item} = 1;
1.192 raeburn 21326: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 21327: $changes{$item} = 1;
21328: }
21329: } elsif ($defaultchecked{$item} eq 'off') {
21330: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21331: ($env{'form.'.$item} eq '1')) {
21332: $changes{$item} = 1;
21333: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
21334: $changes{$item} = 1;
21335: }
21336: }
21337: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
21338: }
1.198 raeburn 21339: foreach my $item (@numbers) {
21340: my ($currdef,$newdef);
1.208 raeburn 21341: $newdef = $env{'form.'.$item};
1.198 raeburn 21342: if ($item eq 'anonsurvey_threshold') {
21343: $currdef = $domconfig{'coursedefaults'}{$item};
21344: $newdef =~ s/\D//g;
21345: if ($newdef eq '' || $newdef < 1) {
21346: $newdef = 1;
21347: }
21348: $defaultshash{'coursedefaults'}{$item} = $newdef;
21349: } else {
1.428 raeburn 21350: my ($setting,$type) = ($item =~ /^(uploadquota|coursequota|mysqltables)_(\w+)$/);
1.276 raeburn 21351: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
21352: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 21353: }
21354: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 21355: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 21356: }
21357: if ($currdef ne $newdef) {
21358: if ($item eq 'anonsurvey_threshold') {
21359: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
21360: $changes{$item} = 1;
21361: }
1.428 raeburn 21362: } elsif ($item =~ /^(uploadquota|coursequota|mysqltables)_/) {
1.289 raeburn 21363: my $setting = $1;
1.276 raeburn 21364: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
21365: $changes{$setting} = 1;
1.198 raeburn 21366: }
21367: }
1.139 raeburn 21368: }
21369: }
1.314 raeburn 21370: my $texengine;
21371: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
21372: $texengine = $env{'form.texengine'};
1.349 raeburn 21373: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
21374: if ($currdef eq '') {
21375: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 21376: $changes{'texengine'} = 1;
21377: }
1.349 raeburn 21378: } elsif ($currdef ne $texengine) {
1.314 raeburn 21379: $changes{'texengine'} = 1;
21380: }
21381: }
21382: if ($texengine ne '') {
21383: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
21384: }
1.264 raeburn 21385: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
21386: my @currclonecode;
21387: if (ref($currclone) eq 'HASH') {
21388: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
21389: @currclonecode = @{$currclone->{'instcode'}};
21390: }
21391: }
21392: my $newclone;
1.289 raeburn 21393: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 21394: $newclone = $env{'form.canclone'};
21395: }
21396: if ($newclone eq 'instcode') {
21397: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
21398: my (%codedefaults,@code_order,@clonecode);
21399: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
21400: \@code_order);
21401: foreach my $item (@code_order) {
21402: if (grep(/^\Q$item\E$/,@newcodes)) {
21403: push(@clonecode,$item);
21404: }
21405: }
21406: if (@clonecode) {
21407: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
21408: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
21409: if (@diffs) {
21410: $changes{'canclone'} = 1;
21411: }
21412: } else {
21413: $newclone eq '';
21414: }
21415: } elsif ($newclone ne '') {
1.289 raeburn 21416: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
21417: }
1.264 raeburn 21418: if ($newclone ne $currclone) {
21419: $changes{'canclone'} = 1;
21420: }
1.257 raeburn 21421: my %credits;
21422: foreach my $type (@types) {
21423: unless ($type eq 'community') {
21424: $credits{$type} = $env{'form.'.$type.'_credits'};
21425: $credits{$type} =~ s/[^\d.]+//g;
21426: }
21427: }
21428: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
21429: ($env{'form.coursecredits'} eq '1')) {
21430: $changes{'coursecredits'} = 1;
21431: foreach my $type (keys(%credits)) {
21432: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21433: }
21434: } else {
1.289 raeburn 21435: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 21436: foreach my $type (@types) {
21437: unless ($type eq 'community') {
1.289 raeburn 21438: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 21439: $changes{'coursecredits'} = 1;
21440: }
21441: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21442: }
21443: }
21444: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21445: foreach my $type (@types) {
21446: unless ($type eq 'community') {
21447: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
21448: $changes{'coursecredits'} = 1;
21449: last;
21450: }
21451: }
21452: }
21453: }
21454: }
21455: if ($env{'form.postsubmit'} eq '1') {
21456: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
21457: my %currtimeout;
21458: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21459: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
21460: $changes{'postsubmit'} = 1;
21461: }
21462: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21463: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
21464: }
21465: } else {
21466: $changes{'postsubmit'} = 1;
21467: }
21468: foreach my $type (@types) {
21469: my $timeout = $env{'form.'.$type.'_timeout'};
21470: $timeout =~ s/\D//g;
21471: if ($timeout == $staticdefaults{'postsubmit'}) {
21472: $timeout = '';
21473: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
21474: $timeout = '0';
21475: }
21476: unless ($timeout eq '') {
21477: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
21478: }
21479: if (exists($currtimeout{$type})) {
21480: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 21481: $changes{'postsubmit'} = 1;
1.257 raeburn 21482: }
21483: } elsif ($timeout ne '') {
21484: $changes{'postsubmit'} = 1;
21485: }
21486: }
21487: } else {
21488: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
21489: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21490: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
21491: $changes{'postsubmit'} = 1;
21492: }
21493: } else {
21494: $changes{'postsubmit'} = 1;
21495: }
1.192 raeburn 21496: }
1.438 raeburn 21497: my (%newdomexttool,%newexttool,%newcrsauthor,%olddomexttool,%oldexttool,%oldcrsauthor,
21498: %posscrseditors);
1.422 raeburn 21499: map { $newdomexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.domexttool');
1.425 raeburn 21500: map { $newexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.exttool');
1.432 raeburn 21501: map { $newcrsauthor{$_} = 1; } &Apache::loncommon::get_env_multiple('form.crsauthor');
1.438 raeburn 21502: map { $posscrseditors{$_} = 1; } &Apache::loncommon::get_env_multiple('form.crseditors');
1.422 raeburn 21503: if (ref($domconfig{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21504: %olddomexttool = %{$domconfig{'coursedefaults'}{'domexttool'}};
21505: } else {
21506: foreach my $type (@types) {
21507: if ($staticdefaults{'domexttool'}) {
21508: $olddomexttool{$type} = 1;
21509: } else {
21510: $olddomexttool{$type} = 0;
21511: }
21512: }
21513: }
21514: if (ref($domconfig{'coursedefaults'}{'exttool'}) eq 'HASH') {
1.425 raeburn 21515: %oldexttool = %{$domconfig{'coursedefaults'}{'exttool'}};
1.422 raeburn 21516: } else {
21517: foreach my $type (@types) {
21518: if ($staticdefaults{'exttool'}) {
21519: $oldexttool{$type} = 1;
21520: } else {
21521: $oldexttool{$type} = 0;
21522: }
21523: }
21524: }
1.432 raeburn 21525: if (ref($domconfig{'coursedefaults'}{'crsauthor'}) eq 'HASH') {
21526: %oldcrsauthor = %{$domconfig{'coursedefaults'}{'crsauthor'}};
21527: } else {
21528: foreach my $type (@types) {
21529: if ($staticdefaults{'crsauthor'}) {
21530: $oldcrsauthor{$type} = 1;
21531: } else {
21532: $oldcrsauthor{$type} = 0;
21533: }
21534: }
21535: }
1.438 raeburn 21536: my @newcrseditors = ();
21537: foreach my $editor (@editors) {
21538: if ($posscrseditors{$editor}) {
21539: push(@newcrseditors,$editor);
21540: }
21541: }
21542: if (ref($domconfig{'coursedefaults'}{'crseditors'}) eq 'ARRAY') {
21543: my @diffs =
21544: &Apache::loncommon::compare_arrays($domconfig{'coursedefaults'}{'crseditors'},
21545: \@newcrseditors);
21546: if (@diffs) {
21547: $changes{'crseditors'} = 1;
21548: }
21549: } else {
21550: my @diffs =
21551: &Apache::loncommon::compare_arrays($staticdefaults{'crseditors'},
21552: \@newcrseditors);
21553: unless (@diffs == 0) {
21554: $changes{'crseditors'} = 1;
21555: }
21556: }
1.422 raeburn 21557: foreach my $type (@types) {
21558: unless ($newdomexttool{$type}) {
21559: $newdomexttool{$type} = 0;
21560: }
21561: unless ($newexttool{$type}) {
21562: $newexttool{$type} = 0;
21563: }
1.432 raeburn 21564: unless ($newcrsauthor{$type}) {
21565: $newcrsauthor{$type} = 0;
21566: }
1.422 raeburn 21567: if ($newdomexttool{$type} != $olddomexttool{$type}) {
21568: $changes{'domexttool'} = 1;
21569: }
21570: if ($newexttool{$type} != $oldexttool{$type}) {
21571: $changes{'exttool'} = 1;
21572: }
1.432 raeburn 21573: if ($newcrsauthor{$type} != $oldcrsauthor{$type}) {
21574: $changes{'crsauthor'} = 1;
21575: }
1.422 raeburn 21576: }
21577: $defaultshash{'coursedefaults'}{'domexttool'} = \%newdomexttool;
21578: $defaultshash{'coursedefaults'}{'exttool'} = \%newexttool;
1.432 raeburn 21579: $defaultshash{'coursedefaults'}{'crsauthor'} = \%newcrsauthor;
1.438 raeburn 21580: $defaultshash{'coursedefaults'}{'crseditors'} = \@newcrseditors;
1.121 raeburn 21581: }
21582: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21583: $dom);
21584: if ($putresult eq 'ok') {
21585: if (keys(%changes) > 0) {
1.213 raeburn 21586: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 21587: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 21588: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.398 raeburn 21589: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
1.422 raeburn 21590: ($changes{'inline_chem'}) || ($changes{'ltiauth'}) || ($changes{'domexttool'}) ||
1.432 raeburn 21591: ($changes{'exttool'}) || ($changes{'coursequota'}) || ($changes{'crsauthor'})) {
1.422 raeburn 21592: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','inline_chem','texengine',
21593: 'ltiauth') {
1.257 raeburn 21594: if ($changes{$item}) {
21595: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
21596: }
1.289 raeburn 21597: }
1.192 raeburn 21598: if ($changes{'coursecredits'}) {
21599: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 21600: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
21601: $domdefaults{$type.'credits'} =
21602: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
21603: }
21604: }
21605: }
21606: if ($changes{'postsubmit'}) {
21607: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21608: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
21609: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21610: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
21611: $domdefaults{$type.'postsubtimeout'} =
21612: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21613: }
21614: }
1.192 raeburn 21615: }
21616: }
1.198 raeburn 21617: if ($changes{'uploadquota'}) {
21618: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21619: foreach my $type (@types) {
21620: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
21621: }
21622: }
21623: }
1.428 raeburn 21624: if ($changes{'coursequota'}) {
21625: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
21626: foreach my $type (@types) {
21627: $domdefaults{$type.'coursequota'}=$defaultshash{'coursedefaults'}{'coursequota'}{$type};
21628: }
21629: }
21630: }
1.264 raeburn 21631: if ($changes{'canclone'}) {
21632: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21633: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21634: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
21635: if (@clonecodes) {
21636: $domdefaults{'canclone'} = join('+',@clonecodes);
21637: }
21638: }
21639: } else {
21640: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
21641: }
21642: }
1.422 raeburn 21643: if ($changes{'domexttool'}) {
21644: if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21645: foreach my $type (@types) {
21646: $domdefaults{$type.'domexttool'}=$defaultshash{'coursedefaults'}{'domexttool'}{$type};
21647: }
21648: }
21649: }
21650: if ($changes{'exttool'}) {
21651: if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
21652: foreach my $type (@types) {
21653: $domdefaults{$type.'exttool'}=$defaultshash{'coursedefaults'}{'exttool'}{$type};
21654: }
21655: }
21656: }
1.432 raeburn 21657: if ($changes{'crsauthor'}) {
21658: if (ref($defaultshash{'coursedefaults'}{'crsauthor'}) eq 'HASH') {
21659: foreach my $type (@types) {
21660: $domdefaults{$type.'crsauthor'}=$defaultshash{'coursedefaults'}{'crsauthor'}{$type};
21661: }
21662: }
21663: }
1.438 raeburn 21664: if ($changes{'crseditors'}) {
21665: if (ref($defaultshash{'coursedefaults'}{'crseditors'}) eq 'ARRAY') {
21666: $domdefaults{'crseditors'}=join(',',@{$defaultshash{'coursedefaults'}{'crseditors'}});
21667: }
21668: }
1.121 raeburn 21669: my $cachetime = 24*60*60;
21670: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 21671: if (ref($lastactref) eq 'HASH') {
21672: $lastactref->{'domdefaults'} = 1;
21673: }
1.121 raeburn 21674: }
21675: $resulttext = &mt('Changes made:').'<ul>';
21676: foreach my $item (sort(keys(%changes))) {
21677: if ($item eq 'canuse_pdfforms') {
21678: if ($env{'form.'.$item} eq '1') {
21679: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
21680: } else {
21681: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
21682: }
1.257 raeburn 21683: } elsif ($item eq 'uselcmath') {
21684: if ($env{'form.'.$item} eq '1') {
21685: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
21686: } else {
21687: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
21688: }
21689: } elsif ($item eq 'usejsme') {
21690: if ($env{'form.'.$item} eq '1') {
21691: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
21692: } else {
1.289 raeburn 21693: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 21694: }
1.398 raeburn 21695: } elsif ($item eq 'inline_chem') {
21696: if ($env{'form.'.$item} eq '1') {
21697: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
21698: } else {
21699: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
21700: }
1.314 raeburn 21701: } elsif ($item eq 'texengine') {
21702: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
21703: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
21704: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
21705: }
1.139 raeburn 21706: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 21707: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 21708: } elsif ($item eq 'uploadquota') {
21709: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21710: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
21711: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
21712: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 21713: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 21714: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 21715: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
21716: '</ul>'.
21717: '</li>';
21718: } else {
21719: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
21720: }
1.428 raeburn 21721: } elsif ($item eq 'coursequota') {
21722: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
21723: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course set as follows:').'<ul>'.
21724: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'official'}.'</b>').'</li>'.
21725: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'unofficial'}.'</b>').'</li>'.
21726: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'textbook'}.'</b>').'</li>'.
21727: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'placement'}.'</b>').'</li>'.
21728: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'community'}.'</b>').'</li>'.
21729: '</ul>'.
21730: '</li>';
21731: } else {
21732: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course remains default: [_1] MB',$staticdefaults{'coursequota'}).'</li>';
21733: }
1.276 raeburn 21734: } elsif ($item eq 'mysqltables') {
21735: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
21736: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
21737: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
21738: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
21739: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
21740: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
21741: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
21742: '</ul>'.
21743: '</li>';
21744: } else {
21745: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
21746: }
1.257 raeburn 21747: } elsif ($item eq 'postsubmit') {
21748: if ($domdefaults{'postsubmit'} eq 'off') {
21749: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
21750: } else {
21751: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 21752: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 21753: $resulttext .= &mt('durations:').'<ul>';
21754: foreach my $type (@types) {
21755: $resulttext .= '<li>';
21756: my $timeout;
21757: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21758: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21759: }
21760: my $display;
21761: if ($timeout eq '0') {
21762: $display = &mt('unlimited');
21763: } elsif ($timeout eq '') {
21764: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
21765: } else {
21766: $display = &mt('[quant,_1,second]',$timeout);
21767: }
21768: if ($type eq 'community') {
21769: $resulttext .= &mt('Communities');
21770: } elsif ($type eq 'official') {
21771: $resulttext .= &mt('Official courses');
21772: } elsif ($type eq 'unofficial') {
21773: $resulttext .= &mt('Unofficial courses');
21774: } elsif ($type eq 'textbook') {
21775: $resulttext .= &mt('Textbook courses');
1.271 raeburn 21776: } elsif ($type eq 'placement') {
21777: $resulttext .= &mt('Placement tests');
1.257 raeburn 21778: }
21779: $resulttext .= ' -- '.$display.'</li>';
21780: }
21781: $resulttext .= '</ul>';
21782: }
1.289 raeburn 21783: $resulttext .= '</li>';
1.257 raeburn 21784: }
1.192 raeburn 21785: } elsif ($item eq 'coursecredits') {
21786: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21787: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 21788: ($domdefaults{'unofficialcredits'} eq '') &&
21789: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 21790: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21791: } else {
21792: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
21793: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
21794: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 21795: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 21796: '</ul>'.
21797: '</li>';
21798: }
21799: } else {
21800: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21801: }
1.264 raeburn 21802: } elsif ($item eq 'canclone') {
21803: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21804: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21805: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
21806: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
21807: }
21808: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
21809: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
21810: } else {
1.289 raeburn 21811: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 21812: }
1.404 raeburn 21813: } elsif ($item eq 'ltiauth') {
21814: if ($env{'form.'.$item} eq '1') {
21815: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
21816: } else {
21817: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
21818: }
1.432 raeburn 21819: } elsif (($item eq 'domexttool') || ($item eq 'exttool') || ($item eq 'crsauthor')) {
1.422 raeburn 21820: my @noyes = (&mt('no'),&mt('yes'));
1.432 raeburn 21821: my %status = (
21822: domexttool => {
21823: ishash => &mt('External Tools defined in the domain may be used as follows:'),
21824: default => &mt('External Tools defined in the domain may be used in all course types, by default'),
21825: },
21826: exttool => {
21827: ishash => &mt('External Tools can be defined and configured in course containers as follows:'),
21828: default => &mt('External Tools can not be defined in any course types, by default'),
21829: },
21830: crsauthor => {
21831: ishash => &mt('Standard Problems can be created within course containers as follows:'),
21832: default => &mt('Standard Problems can be created within any course type, by default'),
21833: },
21834: );
21835:
21836: if (ref($defaultshash{'coursedefaults'}{$item}) eq 'HASH') {
21837: $resulttext .= '<li>'.$status{$item}{'ishash'}.'<ul>'.
21838: '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'official'}].'</b>').'</li>'.
21839: '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'unofficial'}].'</b>').'</li>'.
21840: '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'textbook'}].'</b>').'</li>'.
21841: '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'placement'}].'</b>').'</li>'.
21842: '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'community'}].'</b>').'</li>'.
1.422 raeburn 21843: '</ul>'.
21844: '</li>';
21845: } else {
1.432 raeburn 21846: $resulttext .= '<li>'.$status{$item}{'default'}.'</li>';
1.422 raeburn 21847: }
1.438 raeburn 21848: } elsif ($item eq 'crseditors') {
21849: if (ref($defaultshash{'coursedefaults'}{$item}) eq 'ARRAY') {
21850: my $shown;
21851: if (@{$defaultshash{'coursedefaults'}{$item}}) {
21852: $shown = join(', ', map { $editornames{$_} } @{$defaultshash{'coursedefaults'}{$item}});
21853: } else {
21854: $shown = &mt('None');
21855: }
21856: $resulttext .= '<li>'.&mt('Available editors for course/community resources: [_1]',$shown).'</li>';
21857: }
1.140 raeburn 21858: }
1.121 raeburn 21859: }
21860: $resulttext .= '</ul>';
21861: } else {
21862: $resulttext = &mt('No changes made to course defaults');
21863: }
21864: } else {
21865: $resulttext = '<span class="LC_error">'.
21866: &mt('An error occurred: [_1]',$putresult).'</span>';
21867: }
21868: return $resulttext;
21869: }
21870:
1.231 raeburn 21871: sub modify_selfenrollment {
21872: my ($dom,$lastactref,%domconfig) = @_;
21873: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 21874: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 21875: my %titles = &tool_titles();
1.232 raeburn 21876: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
21877: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 21878: $ordered{'default'} = ['types','registered','approval','limit'];
21879:
21880: my (%roles,%shown,%toplevel);
21881: $roles{'0'} = &Apache::lonnet::plaintext('dc');
21882:
21883: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
21884: if ($domconfig{'selfenrollment'} eq '') {
21885: $domconfig{'selfenrollment'} = {};
21886: }
21887: }
21888: %toplevel = (
21889: admin => 'Configuration Rights',
21890: default => 'Default settings',
21891: validation => 'Validation of self-enrollment requests',
21892: );
1.233 raeburn 21893: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 21894:
21895: if (ref($ordered{'admin'}) eq 'ARRAY') {
21896: foreach my $item (@{$ordered{'admin'}}) {
21897: foreach my $type (@types) {
21898: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
21899: $selfenrollhash{'admin'}{$type}{$item} = 1;
21900: } else {
21901: $selfenrollhash{'admin'}{$type}{$item} = 0;
21902: }
21903: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
21904: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
21905: if ($selfenrollhash{'admin'}{$type}{$item} ne
21906: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
21907: push(@{$changes{'admin'}{$type}},$item);
21908: }
21909: } else {
21910: if (!$selfenrollhash{'admin'}{$type}{$item}) {
21911: push(@{$changes{'admin'}{$type}},$item);
21912: }
21913: }
21914: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
21915: push(@{$changes{'admin'}{$type}},$item);
21916: }
21917: }
21918: }
21919: }
21920:
21921: foreach my $item (@{$ordered{'default'}}) {
21922: foreach my $type (@types) {
21923: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
21924: if ($item eq 'types') {
21925: unless (($value eq 'all') || ($value eq 'dom')) {
21926: $value = '';
21927: }
21928: } elsif ($item eq 'registered') {
21929: unless ($value eq '1') {
21930: $value = 0;
21931: }
21932: } elsif ($item eq 'approval') {
21933: unless ($value =~ /^[012]$/) {
21934: $value = 0;
21935: }
21936: } else {
21937: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21938: $value = 'none';
21939: }
21940: }
21941: $selfenrollhash{'default'}{$type}{$item} = $value;
21942: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
21943: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21944: if ($selfenrollhash{'default'}{$type}{$item} ne
21945: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
21946: push(@{$changes{'default'}{$type}},$item);
21947: }
21948: } else {
21949: push(@{$changes{'default'}{$type}},$item);
21950: }
21951: } else {
21952: push(@{$changes{'default'}{$type}},$item);
21953: }
21954: if ($item eq 'limit') {
21955: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21956: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
21957: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
21958: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
21959: }
21960: } else {
21961: $selfenrollhash{'default'}{$type}{'cap'} = '';
21962: }
21963: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21964: if ($selfenrollhash{'default'}{$type}{'cap'} ne
21965: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
21966: push(@{$changes{'default'}{$type}},'cap');
21967: }
21968: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
21969: push(@{$changes{'default'}{$type}},'cap');
21970: }
21971: }
21972: }
21973: }
21974:
21975: foreach my $item (@{$itemsref}) {
21976: if ($item eq 'fields') {
21977: my @changed;
21978: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
21979: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
21980: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
21981: }
21982: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21983: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
21984: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
21985: $domconfig{'selfenrollment'}{'validation'}{$item});
21986: } else {
21987: @changed = @{$selfenrollhash{'validation'}{$item}};
21988: }
21989: } else {
21990: @changed = @{$selfenrollhash{'validation'}{$item}};
21991: }
21992: if (@changed) {
21993: if ($selfenrollhash{'validation'}{$item}) {
21994: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
21995: } else {
21996: $changes{'validation'}{$item} = &mt('None');
21997: }
21998: }
21999: } else {
22000: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
22001: if ($item eq 'markup') {
22002: if ($env{'form.selfenroll_validation_'.$item}) {
22003: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
22004: }
22005: }
22006: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
22007: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
22008: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
22009: }
22010: }
22011: }
22012: }
22013:
22014: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
22015: $dom);
22016: if ($putresult eq 'ok') {
22017: if (keys(%changes) > 0) {
22018: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22019: $resulttext = &mt('Changes made:').'<ul>';
22020: foreach my $key ('admin','default','validation') {
22021: if (ref($changes{$key}) eq 'HASH') {
22022: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
22023: if ($key eq 'validation') {
22024: foreach my $item (@{$itemsref}) {
22025: if (exists($changes{$key}{$item})) {
22026: if ($item eq 'markup') {
22027: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
22028: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
22029: } else {
22030: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
22031: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
22032: }
22033: }
22034: }
22035: } else {
22036: foreach my $type (@types) {
22037: if ($type eq 'community') {
22038: $roles{'1'} = &mt('Community personnel');
22039: } else {
22040: $roles{'1'} = &mt('Course personnel');
22041: }
22042: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 22043: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
22044: if ($key eq 'admin') {
22045: my @mgrdc = ();
22046: if (ref($ordered{$key}) eq 'ARRAY') {
22047: foreach my $item (@{$ordered{'admin'}}) {
22048: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
22049: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
22050: push(@mgrdc,$item);
22051: }
22052: }
22053: }
22054: if (@mgrdc) {
22055: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
22056: } else {
22057: delete($domdefaults{$type.'selfenrolladmdc'});
22058: }
22059: }
22060: } else {
22061: if (ref($ordered{$key}) eq 'ARRAY') {
22062: foreach my $item (@{$ordered{$key}}) {
22063: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
22064: $domdefaults{$type.'selfenroll'.$item} =
22065: $selfenrollhash{$key}{$type}{$item};
22066: }
22067: }
22068: }
22069: }
22070: }
1.231 raeburn 22071: $resulttext .= '<li>'.$titles{$type}.'<ul>';
22072: foreach my $item (@{$ordered{$key}}) {
22073: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
22074: $resulttext .= '<li>';
22075: if ($key eq 'admin') {
22076: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
22077: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
22078: } else {
22079: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
22080: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
22081: }
22082: $resulttext .= '</li>';
22083: }
22084: }
22085: $resulttext .= '</ul></li>';
22086: }
22087: }
22088: $resulttext .= '</ul></li>';
22089: }
22090: }
1.305 raeburn 22091: }
22092: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
22093: my $cachetime = 24*60*60;
22094: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22095: if (ref($lastactref) eq 'HASH') {
22096: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 22097: }
1.231 raeburn 22098: }
22099: $resulttext .= '</ul>';
22100: } else {
22101: $resulttext = &mt('No changes made to self-enrollment settings');
22102: }
22103: } else {
22104: $resulttext = '<span class="LC_error">'.
22105: &mt('An error occurred: [_1]',$putresult).'</span>';
22106: }
22107: return $resulttext;
22108: }
22109:
1.373 raeburn 22110: sub modify_wafproxy {
22111: my ($dom,$action,$lastactref,%domconfig) = @_;
22112: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 22113: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
22114: %wafproxy,%changes,%expirecache,%expiresaml);
1.373 raeburn 22115: foreach my $server (sort(keys(%servers))) {
22116: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
22117: if ($serverhome eq $server) {
22118: my $serverdom = &Apache::lonnet::host_domain($server);
22119: if ($serverdom eq $dom) {
22120: $canset{$server} = 1;
22121: }
22122: }
22123: }
1.381 raeburn 22124: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
22125: %{$values{$dom}} = ();
22126: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
22127: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
22128: }
1.388 raeburn 22129: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
22130: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
22131: }
1.382 raeburn 22132: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.381 raeburn 22133: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
22134: }
22135: }
1.373 raeburn 22136: my $output;
22137: if (keys(%canset)) {
22138: %{$wafproxy{'alias'}} = ();
1.388 raeburn 22139: %{$wafproxy{'saml'}} = ();
1.373 raeburn 22140: foreach my $key (sort(keys(%canset))) {
1.381 raeburn 22141: if ($env{'form.wafproxy_'.$dom}) {
22142: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
22143: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
22144: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
22145: $changes{'alias'} = 1;
22146: }
1.388 raeburn 22147: if ($env{'form.wafproxy_alias_saml_'.$key}) {
22148: $wafproxy{'saml'}{$key} = 1;
22149: }
22150: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
22151: $changes{'saml'} = 1;
22152: }
1.381 raeburn 22153: } else {
22154: $wafproxy{'alias'}{$key} = '';
1.388 raeburn 22155: $wafproxy{'saml'}{$key} = '';
1.381 raeburn 22156: if ($curralias{$key}) {
22157: $changes{'alias'} = 1;
22158: }
1.388 raeburn 22159: if ($currsaml{$key}) {
22160: $changes{'saml'} = 1;
22161: }
1.373 raeburn 22162: }
22163: if ($wafproxy{'alias'}{$key} eq '') {
22164: if ($curralias{$key}) {
22165: $expirecache{$key} = 1;
22166: }
22167: delete($wafproxy{'alias'}{$key});
22168: }
1.388 raeburn 22169: if ($wafproxy{'saml'}{$key} eq '') {
22170: if ($currsaml{$key}) {
22171: $expiresaml{$key} = 1;
22172: }
22173: delete($wafproxy{'saml'}{$key});
22174: }
1.373 raeburn 22175: }
22176: unless (keys(%{$wafproxy{'alias'}})) {
22177: delete($wafproxy{'alias'});
22178: }
1.388 raeburn 22179: unless (keys(%{$wafproxy{'saml'}})) {
22180: delete($wafproxy{'saml'});
22181: }
22182: # Localization for values in %warn occurs in &mt() calls separately.
1.373 raeburn 22183: my %warn = (
22184: trusted => 'trusted IP range(s)',
1.381 raeburn 22185: vpnint => 'internal IP range(s) for VPN sessions(s)',
22186: vpnext => 'IP range(s) for backend WAF connections',
1.373 raeburn 22187: );
1.382 raeburn 22188: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22189: my $possible = $env{'form.wafproxy_'.$item};
22190: $possible =~ s/^\s+|\s+$//g;
22191: if ($possible ne '') {
1.381 raeburn 22192: if ($item eq 'remoteip') {
22193: if ($possible =~ /^[mhn]$/) {
22194: $wafproxy{$item} = $possible;
22195: }
22196: } elsif ($item eq 'ipheader') {
22197: if ($wafproxy{'remoteip'} eq 'h') {
22198: $wafproxy{$item} = $possible;
22199: }
1.382 raeburn 22200: } elsif ($item eq 'sslopt') {
22201: if ($possible =~ /^0|1$/) {
22202: $wafproxy{$item} = $possible;
22203: }
1.373 raeburn 22204: } else {
22205: my (@ok,$count);
1.381 raeburn 22206: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
22207: unless ($env{'form.wafproxy_vpnaccess'}) {
22208: $possible = '';
22209: }
22210: } elsif ($item eq 'trusted') {
22211: unless ($wafproxy{'remoteip'} eq 'h') {
22212: $possible = '';
22213: }
22214: }
22215: unless ($possible eq '') {
22216: $possible =~ s/[\r\n]+/\s/g;
22217: $possible =~ s/\s*-\s*/-/g;
22218: $possible =~ s/\s+/,/g;
1.393 raeburn 22219: $possible =~ s/,+/,/g;
1.381 raeburn 22220: }
1.373 raeburn 22221: $count = 0;
1.381 raeburn 22222: if ($possible ne '') {
1.373 raeburn 22223: foreach my $poss (split(/\,/,$possible)) {
22224: $count ++;
1.393 raeburn 22225: $poss = &validate_ip_pattern($poss);
22226: if ($poss ne '') {
1.373 raeburn 22227: push(@ok,$poss);
22228: }
22229: }
22230: my $diff = $count - scalar(@ok);
22231: if ($diff) {
22232: push(@warnings,'<li>'.
22233: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
22234: $diff,$warn{$item}).
22235: '</li>');
22236: }
1.393 raeburn 22237: if (@ok) {
22238: my @cidr_list;
22239: foreach my $item (@ok) {
22240: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
22241: }
22242: $wafproxy{$item} = join(',',@cidr_list);
22243: }
1.373 raeburn 22244: }
22245: }
1.381 raeburn 22246: if ($wafproxy{$item} ne $currvalue{$item}) {
1.373 raeburn 22247: $changes{$item} = 1;
22248: }
1.381 raeburn 22249: } elsif ($currvalue{$item}) {
22250: $changes{$item} = 1;
1.425 raeburn 22251: }
1.381 raeburn 22252: }
22253: } else {
22254: if (keys(%curralias)) {
22255: $changes{'alias'} = 1;
1.388 raeburn 22256: }
22257: if (keys(%currsaml)) {
22258: $changes{'saml'} = 1;
1.425 raeburn 22259: }
1.381 raeburn 22260: if (keys(%currvalue)) {
22261: foreach my $key (keys(%currvalue)) {
22262: $changes{$key} = 1;
1.373 raeburn 22263: }
22264: }
22265: }
22266: if (keys(%changes)) {
22267: my %defaultshash = (
22268: wafproxy => \%wafproxy,
1.425 raeburn 22269: );
1.373 raeburn 22270: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22271: $dom);
22272: if ($putresult eq 'ok') {
22273: my $cachetime = 24*60*60;
22274: my (%domdefaults,$updatedomdefs);
1.382 raeburn 22275: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22276: if ($changes{$item}) {
22277: unless ($updatedomdefs) {
22278: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
22279: $updatedomdefs = 1;
22280: }
22281: if ($wafproxy{$item}) {
22282: $domdefaults{'waf_'.$item} = $wafproxy{$item};
22283: } elsif (exists($domdefaults{'waf_'.$item})) {
22284: delete($domdefaults{'waf_'.$item});
1.425 raeburn 22285: }
1.373 raeburn 22286: }
22287: }
22288: if ($updatedomdefs) {
22289: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22290: if (ref($lastactref) eq 'HASH') {
22291: $lastactref->{'domdefaults'} = 1;
22292: }
22293: }
22294: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
22295: my %updates = %expirecache;
22296: foreach my $key (keys(%expirecache)) {
22297: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
22298: }
22299: if (ref($wafproxy{'alias'}) eq 'HASH') {
22300: my $cachetime = 24*60*60;
22301: foreach my $key (keys(%{$wafproxy{'alias'}})) {
22302: $updates{$key} = 1;
22303: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
22304: $cachetime);
22305: }
22306: }
22307: if (ref($lastactref) eq 'HASH') {
22308: $lastactref->{'proxyalias'} = \%updates;
22309: }
22310: }
1.388 raeburn 22311: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
22312: my %samlupdates = %expiresaml;
22313: foreach my $key (keys(%expiresaml)) {
22314: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
22315: }
22316: if (ref($wafproxy{'saml'}) eq 'HASH') {
22317: my $cachetime = 24*60*60;
22318: foreach my $key (keys(%{$wafproxy{'saml'}})) {
22319: $samlupdates{$key} = 1;
22320: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
22321: $cachetime);
22322: }
22323: }
22324: if (ref($lastactref) eq 'HASH') {
22325: $lastactref->{'proxysaml'} = \%samlupdates;
22326: }
22327: }
1.373 raeburn 22328: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.401 raeburn 22329: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22330: if ($changes{$item}) {
22331: if ($item eq 'alias') {
22332: my $numaliased = 0;
22333: if (ref($wafproxy{'alias'}) eq 'HASH') {
22334: my $shown;
22335: if (keys(%{$wafproxy{'alias'}})) {
22336: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
22337: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
22338: &Apache::lonnet::hostname($server),
22339: $wafproxy{'alias'}{$server}).'</li>';
22340: $numaliased ++;
22341: }
22342: if ($numaliased) {
22343: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
22344: '<ul>'.$shown.'</ul>').'</li>';
22345: }
22346: }
22347: }
22348: unless ($numaliased) {
22349: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
22350: }
1.388 raeburn 22351: } elsif ($item eq 'saml') {
1.425 raeburn 22352: my $shown;
1.388 raeburn 22353: if (ref($wafproxy{'saml'}) eq 'HASH') {
22354: if (keys(%{$wafproxy{'saml'}})) {
22355: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
22356: }
22357: }
22358: if ($shown) {
1.396 raeburn 22359: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
1.388 raeburn 22360: $shown).'</li>';
22361: } else {
1.396 raeburn 22362: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
1.388 raeburn 22363: }
1.373 raeburn 22364: } else {
1.381 raeburn 22365: if ($item eq 'remoteip') {
22366: my %ip_methods = &remoteip_methods();
22367: if ($wafproxy{$item} =~ /^[mh]$/) {
22368: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
22369: $ip_methods{$wafproxy{$item}}).'</li>';
22370: } else {
22371: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
22372: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
22373: '</li>';
22374: } else {
22375: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
22376: }
22377: }
22378: } elsif ($item eq 'ipheader') {
1.373 raeburn 22379: if ($wafproxy{$item}) {
1.381 raeburn 22380: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
1.373 raeburn 22381: $wafproxy{$item}).'</li>';
22382: } else {
1.381 raeburn 22383: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
1.373 raeburn 22384: }
22385: } elsif ($item eq 'trusted') {
22386: if ($wafproxy{$item}) {
1.381 raeburn 22387: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
1.373 raeburn 22388: $wafproxy{$item}).'</li>';
22389: } else {
22390: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
22391: }
1.381 raeburn 22392: } elsif ($item eq 'vpnint') {
22393: if ($wafproxy{$item}) {
22394: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
22395: $wafproxy{$item}).'</li>';
22396: } else {
22397: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
22398: }
22399: } elsif ($item eq 'vpnext') {
1.373 raeburn 22400: if ($wafproxy{$item}) {
1.381 raeburn 22401: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
1.373 raeburn 22402: $wafproxy{$item}).'</li>';
22403: } else {
1.381 raeburn 22404: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
1.373 raeburn 22405: }
1.382 raeburn 22406: } elsif ($item eq 'sslopt') {
22407: if ($wafproxy{$item}) {
22408: $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>';
22409: } else {
22410: $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>';
22411: }
1.373 raeburn 22412: }
22413: }
22414: }
22415: }
1.420 raeburn 22416: $output .= '</ul>';
1.373 raeburn 22417: } else {
22418: $output = '<span class="LC_error">'.
22419: &mt('An error occurred: [_1]',$putresult).'</span>';
22420: }
22421: } elsif (keys(%canset)) {
22422: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
22423: }
22424: if (@warnings) {
22425: $output .= '<br />'.&mt('Warnings:').'<ul>'.
22426: join("\n",@warnings).'</ul>';
22427: }
22428: return $output;
22429: }
22430:
22431: sub validate_ip_pattern {
22432: my ($pattern) = @_;
22433: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
22434: my ($start,$end) = ($1,$2);
22435: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
1.393 raeburn 22436: if (($start !~ m{/}) && ($end !~ m{/})) {
22437: return $start.'-'.$end;
22438: }
22439: }
22440: } elsif ($pattern ne '') {
22441: $pattern = &Net::CIDR::cidrvalidate($pattern);
22442: if ($pattern ne '') {
22443: return $pattern;
1.373 raeburn 22444: }
22445: }
1.393 raeburn 22446: return;
1.373 raeburn 22447: }
22448:
1.137 raeburn 22449: sub modify_usersessions {
1.212 raeburn 22450: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 22451: my @hostingtypes = ('version','excludedomain','includedomain');
22452: my @offloadtypes = ('primary','default');
22453: my %types = (
22454: remote => \@hostingtypes,
22455: hosted => \@hostingtypes,
22456: spares => \@offloadtypes,
22457: );
22458: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 22459: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 22460: my (%by_ip,%by_location,@intdoms,@instdoms);
22461: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 22462: my @locations = sort(keys(%by_location));
1.137 raeburn 22463: my (%defaultshash,%changes);
22464: foreach my $prefix (@prefixes) {
22465: $defaultshash{'usersessions'}{$prefix} = {};
22466: }
1.212 raeburn 22467: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 22468: my $resulttext;
1.138 raeburn 22469: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 22470: foreach my $prefix (@prefixes) {
1.145 raeburn 22471: next if ($prefix eq 'spares');
22472: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 22473: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22474: if ($type eq 'version') {
22475: my $value = $env{'form.'.$prefix.'_'.$type};
22476: my $okvalue;
22477: if ($value ne '') {
22478: if (grep(/^\Q$value\E$/,@lcversions)) {
22479: $okvalue = $value;
22480: }
22481: }
22482: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22483: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22484: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
22485: if ($inuse == 0) {
22486: $changes{$prefix}{$type} = 1;
22487: } else {
22488: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
22489: $changes{$prefix}{$type} = 1;
22490: }
22491: if ($okvalue ne '') {
22492: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22493: }
22494: }
22495: } else {
22496: if (($inuse == 1) && ($okvalue ne '')) {
22497: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22498: $changes{$prefix}{$type} = 1;
22499: }
22500: }
22501: } else {
22502: if (($inuse == 1) && ($okvalue ne '')) {
22503: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22504: $changes{$prefix}{$type} = 1;
22505: }
22506: }
22507: } else {
22508: if (($inuse == 1) && ($okvalue ne '')) {
22509: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22510: $changes{$prefix}{$type} = 1;
22511: }
22512: }
22513: } else {
22514: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22515: my @okvals;
22516: foreach my $val (@vals) {
1.138 raeburn 22517: if ($val =~ /:/) {
22518: my @items = split(/:/,$val);
22519: foreach my $item (@items) {
22520: if (ref($by_location{$item}) eq 'ARRAY') {
22521: push(@okvals,$item);
22522: }
22523: }
22524: } else {
22525: if (ref($by_location{$val}) eq 'ARRAY') {
22526: push(@okvals,$val);
22527: }
1.137 raeburn 22528: }
22529: }
22530: @okvals = sort(@okvals);
22531: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22532: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22533: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22534: if ($inuse == 0) {
22535: $changes{$prefix}{$type} = 1;
22536: } else {
22537: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22538: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
22539: if (@changed > 0) {
22540: $changes{$prefix}{$type} = 1;
22541: }
22542: }
22543: } else {
22544: if ($inuse == 1) {
22545: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22546: $changes{$prefix}{$type} = 1;
22547: }
22548: }
22549: } else {
22550: if ($inuse == 1) {
22551: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22552: $changes{$prefix}{$type} = 1;
22553: }
22554: }
22555: } else {
22556: if ($inuse == 1) {
22557: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22558: $changes{$prefix}{$type} = 1;
22559: }
22560: }
22561: }
22562: }
22563: }
1.145 raeburn 22564:
22565: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 22566: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 22567: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
22568: my $savespares;
22569:
22570: foreach my $lonhost (sort(keys(%servers))) {
22571: my $serverhomeID =
22572: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 22573: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 22574: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
22575: my %spareschg;
22576: foreach my $type (@{$types{'spares'}}) {
22577: my @okspares;
22578: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
22579: foreach my $server (@checked) {
1.152 raeburn 22580: if (&Apache::lonnet::hostname($server) ne '') {
22581: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
22582: unless (grep(/^\Q$server\E$/,@okspares)) {
22583: push(@okspares,$server);
22584: }
1.145 raeburn 22585: }
22586: }
22587: }
22588: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
22589: my $newspare;
1.152 raeburn 22590: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
22591: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 22592: $newspare = $new;
22593: }
22594: }
1.152 raeburn 22595: my @spares;
22596: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
22597: @spares = sort(@okspares,$newspare);
22598: } else {
22599: @spares = sort(@okspares);
22600: }
22601: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 22602: if (ref($spareid{$lonhost}) eq 'HASH') {
22603: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 22604: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 22605: if (@diffs > 0) {
22606: $spareschg{$type} = 1;
22607: }
22608: }
22609: }
22610: }
22611: if (keys(%spareschg) > 0) {
22612: $changes{'spares'}{$lonhost} = \%spareschg;
22613: }
22614: }
1.261 raeburn 22615: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371 raeburn 22616: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261 raeburn 22617: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
22618: my @okoffload;
22619: if (@offloadnow) {
22620: foreach my $server (@offloadnow) {
22621: if (&Apache::lonnet::hostname($server) ne '') {
22622: unless (grep(/^\Q$server\E$/,@okoffload)) {
22623: push(@okoffload,$server);
22624: }
22625: }
22626: }
22627: if (@okoffload) {
22628: foreach my $lonhost (@okoffload) {
22629: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
22630: }
22631: }
22632: }
1.371 raeburn 22633: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
22634: my @okoffloadoth;
22635: if (@offloadoth) {
22636: foreach my $server (@offloadoth) {
22637: if (&Apache::lonnet::hostname($server) ne '') {
22638: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
22639: push(@okoffloadoth,$server);
22640: }
22641: }
22642: }
22643: if (@okoffloadoth) {
22644: foreach my $lonhost (@okoffloadoth) {
22645: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
22646: }
22647: }
22648: }
1.145 raeburn 22649: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22650: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
22651: if (ref($changes{'spares'}) eq 'HASH') {
22652: if (keys(%{$changes{'spares'}}) > 0) {
22653: $savespares = 1;
22654: }
22655: }
22656: } else {
22657: $savespares = 1;
22658: }
1.371 raeburn 22659: foreach my $offload ('offloadnow','offloadoth') {
22660: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
22661: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
22662: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
22663: $changes{$offload} = 1;
22664: last;
22665: }
1.261 raeburn 22666: }
1.371 raeburn 22667: unless ($changes{$offload}) {
22668: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
22669: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
22670: $changes{$offload} = 1;
22671: last;
22672: }
1.261 raeburn 22673: }
22674: }
1.371 raeburn 22675: } else {
22676: if (($offload eq 'offloadnow') && (@okoffload)) {
22677: $changes{'offloadnow'} = 1;
22678: }
22679: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
22680: $changes{'offloadoth'} = 1;
22681: }
1.425 raeburn 22682: }
1.371 raeburn 22683: }
22684: } else {
22685: if (@okoffload) {
1.261 raeburn 22686: $changes{'offloadnow'} = 1;
22687: }
1.371 raeburn 22688: if (@okoffloadoth) {
22689: $changes{'offloadoth'} = 1;
22690: }
1.145 raeburn 22691: }
1.147 raeburn 22692: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
22693: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 22694: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22695: $dom);
22696: if ($putresult eq 'ok') {
22697: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22698: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
22699: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
22700: }
22701: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
22702: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
22703: }
1.261 raeburn 22704: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22705: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
22706: }
1.371 raeburn 22707: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22708: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
22709: }
1.137 raeburn 22710: }
22711: my $cachetime = 24*60*60;
22712: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 22713: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 22714: if (ref($lastactref) eq 'HASH') {
22715: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 22716: $lastactref->{'usersessions'} = 1;
1.212 raeburn 22717: }
1.147 raeburn 22718: if (keys(%changes) > 0) {
22719: my %lt = &usersession_titles();
22720: $resulttext = &mt('Changes made:').'<ul>';
22721: foreach my $prefix (@prefixes) {
22722: if (ref($changes{$prefix}) eq 'HASH') {
22723: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
22724: if ($prefix eq 'spares') {
22725: if (ref($changes{$prefix}) eq 'HASH') {
22726: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
22727: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 22728: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 22729: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
22730: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 22731: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
22732: foreach my $type (@{$types{$prefix}}) {
22733: if ($changes{$prefix}{$lonhost}{$type}) {
22734: my $offloadto = &mt('None');
22735: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
22736: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
22737: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
22738: }
1.145 raeburn 22739: }
1.147 raeburn 22740: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 22741: }
1.137 raeburn 22742: }
22743: }
1.147 raeburn 22744: $resulttext .= '</li>';
1.137 raeburn 22745: }
22746: }
1.147 raeburn 22747: } else {
22748: foreach my $type (@{$types{$prefix}}) {
22749: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22750: my ($newvalue,$notinuse);
1.147 raeburn 22751: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22752: if (ref($defaultshash{'usersessions'}{$prefix})) {
22753: if ($type eq 'version') {
22754: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 22755: } else {
22756: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22757: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
22758: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
22759: }
22760: } else {
22761: $notinuse = 1;
1.147 raeburn 22762: }
1.145 raeburn 22763: }
22764: }
22765: }
1.147 raeburn 22766: if ($newvalue eq '') {
22767: if ($type eq 'version') {
22768: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 22769: } elsif ($notinuse) {
22770: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 22771: } else {
22772: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
22773: }
1.145 raeburn 22774: } else {
1.147 raeburn 22775: if ($type eq 'version') {
1.344 raeburn 22776: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 22777: }
22778: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 22779: }
1.137 raeburn 22780: }
22781: }
22782: }
1.147 raeburn 22783: $resulttext .= '</ul>';
1.137 raeburn 22784: }
22785: }
1.261 raeburn 22786: if ($changes{'offloadnow'}) {
22787: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22788: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371 raeburn 22789: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261 raeburn 22790: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
22791: $resulttext .= '<li>'.$lonhost.'</li>';
22792: }
22793: $resulttext .= '</ul>';
22794: } else {
1.371 raeburn 22795: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
22796: }
22797: } else {
22798: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
22799: }
22800: }
22801: if ($changes{'offloadoth'}) {
22802: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22803: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
22804: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
22805: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
22806: $resulttext .= '<li>'.$lonhost.'</li>';
22807: }
22808: $resulttext .= '</ul>';
22809: } else {
22810: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261 raeburn 22811: }
22812: } else {
1.371 raeburn 22813: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261 raeburn 22814: }
22815: }
1.147 raeburn 22816: $resulttext .= '</ul>';
22817: } else {
22818: $resulttext = $nochgmsg;
1.137 raeburn 22819: }
22820: } else {
22821: $resulttext = '<span class="LC_error">'.
22822: &mt('An error occurred: [_1]',$putresult).'</span>';
22823: }
22824: } else {
1.147 raeburn 22825: $resulttext = $nochgmsg;
1.137 raeburn 22826: }
22827: return $resulttext;
22828: }
22829:
1.275 raeburn 22830: sub modify_ssl {
22831: my ($dom,$lastactref,%domconfig) = @_;
22832: my (%by_ip,%by_location,@intdoms,@instdoms);
22833: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
22834: my @locations = sort(keys(%by_location));
22835: my %servers = &Apache::lonnet::internet_dom_servers($dom);
22836: my (%defaultshash,%changes);
22837: my $action = 'ssl';
1.293 raeburn 22838: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 22839: foreach my $prefix (@prefixes) {
22840: $defaultshash{$action}{$prefix} = {};
22841: }
22842: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22843: my $resulttext;
22844: my %iphost = &Apache::lonnet::get_iphost();
22845: my @reptypes = ('certreq','nocertreq');
22846: my @connecttypes = ('dom','intdom','other');
22847: my %types = (
1.293 raeburn 22848: connto => \@connecttypes,
22849: connfrom => \@connecttypes,
22850: replication => \@reptypes,
1.275 raeburn 22851: );
22852: foreach my $prefix (sort(keys(%types))) {
22853: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 22854: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22855: my $value = 'yes';
22856: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
22857: $value = $env{'form.'.$prefix.'_'.$type};
22858: }
1.335 raeburn 22859: if (ref($domconfig{$action}) eq 'HASH') {
22860: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22861: if ($domconfig{$action}{$prefix}{$type} ne '') {
22862: if ($value ne $domconfig{$action}{$prefix}{$type}) {
22863: $changes{$prefix}{$type} = 1;
22864: }
22865: $defaultshash{$action}{$prefix}{$type} = $value;
22866: } else {
22867: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 22868: $changes{$prefix}{$type} = 1;
22869: }
22870: } else {
22871: $defaultshash{$action}{$prefix}{$type} = $value;
22872: $changes{$prefix}{$type} = 1;
22873: }
22874: } else {
22875: $defaultshash{$action}{$prefix}{$type} = $value;
22876: $changes{$prefix}{$type} = 1;
22877: }
22878: if (($type eq 'dom') && (keys(%servers) == 1)) {
22879: delete($changes{$prefix}{$type});
22880: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
22881: delete($changes{$prefix}{$type});
22882: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
22883: delete($changes{$prefix}{$type});
22884: }
22885: } elsif ($prefix eq 'replication') {
22886: if (@locations > 0) {
22887: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22888: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22889: my @okvals;
22890: foreach my $val (@vals) {
22891: if ($val =~ /:/) {
22892: my @items = split(/:/,$val);
22893: foreach my $item (@items) {
22894: if (ref($by_location{$item}) eq 'ARRAY') {
22895: push(@okvals,$item);
22896: }
22897: }
22898: } else {
22899: if (ref($by_location{$val}) eq 'ARRAY') {
22900: push(@okvals,$val);
22901: }
22902: }
22903: }
22904: @okvals = sort(@okvals);
22905: if (ref($domconfig{$action}) eq 'HASH') {
22906: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22907: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
22908: if ($inuse == 0) {
22909: $changes{$prefix}{$type} = 1;
22910: } else {
22911: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22912: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
22913: if (@changed > 0) {
22914: $changes{$prefix}{$type} = 1;
22915: }
22916: }
22917: } else {
22918: if ($inuse == 1) {
22919: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22920: $changes{$prefix}{$type} = 1;
22921: }
22922: }
22923: } else {
22924: if ($inuse == 1) {
22925: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22926: $changes{$prefix}{$type} = 1;
22927: }
22928: }
22929: } else {
22930: if ($inuse == 1) {
22931: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22932: $changes{$prefix}{$type} = 1;
22933: }
22934: }
22935: }
22936: }
22937: }
22938: }
1.336 raeburn 22939: if (keys(%changes)) {
22940: foreach my $prefix (keys(%changes)) {
22941: if (ref($changes{$prefix}) eq 'HASH') {
22942: if (scalar(keys(%{$changes{$prefix}})) == 0) {
22943: delete($changes{$prefix});
22944: }
22945: } else {
22946: delete($changes{$prefix});
22947: }
22948: }
22949: }
1.275 raeburn 22950: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
22951: if (keys(%changes) > 0) {
22952: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22953: $dom);
22954: if ($putresult eq 'ok') {
22955: if (ref($defaultshash{$action}) eq 'HASH') {
22956: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
22957: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
22958: }
1.293 raeburn 22959: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 22960: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 22961: }
22962: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 22963: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 22964: }
22965: }
22966: my $cachetime = 24*60*60;
22967: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22968: if (ref($lastactref) eq 'HASH') {
22969: $lastactref->{'domdefaults'} = 1;
22970: }
22971: if (keys(%changes) > 0) {
22972: my %titles = &ssl_titles();
22973: $resulttext = &mt('Changes made:').'<ul>';
22974: foreach my $prefix (@prefixes) {
22975: if (ref($changes{$prefix}) eq 'HASH') {
22976: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
22977: foreach my $type (@{$types{$prefix}}) {
22978: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22979: my ($newvalue,$notinuse);
1.275 raeburn 22980: if (ref($defaultshash{$action}) eq 'HASH') {
22981: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 22982: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22983: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 22984: } else {
22985: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
22986: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
22987: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
22988: }
22989: } else {
22990: $notinuse = 1;
1.275 raeburn 22991: }
22992: }
22993: }
1.344 raeburn 22994: if ($notinuse) {
22995: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
22996: } elsif ($newvalue eq '') {
1.275 raeburn 22997: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
22998: } else {
22999: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
23000: }
23001: }
23002: }
23003: }
23004: $resulttext .= '</ul>';
23005: }
23006: }
23007: } else {
23008: $resulttext = $nochgmsg;
23009: }
23010: } else {
23011: $resulttext = '<span class="LC_error">'.
23012: &mt('An error occurred: [_1]',$putresult).'</span>';
23013: }
23014: } else {
23015: $resulttext = $nochgmsg;
23016: }
23017: return $resulttext;
23018: }
23019:
1.279 raeburn 23020: sub modify_trust {
23021: my ($dom,$lastactref,%domconfig) = @_;
23022: my (%by_ip,%by_location,@intdoms,@instdoms);
23023: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
23024: my @locations = sort(keys(%by_location));
23025: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
23026: my @types = ('exc','inc');
23027: my (%defaultshash,%changes);
23028: foreach my $prefix (@prefixes) {
23029: $defaultshash{'trust'}{$prefix} = {};
23030: }
23031: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
23032: my $resulttext;
23033: foreach my $prefix (@prefixes) {
23034: foreach my $type (@types) {
23035: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
23036: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
23037: my @okvals;
23038: foreach my $val (@vals) {
23039: if ($val =~ /:/) {
23040: my @items = split(/:/,$val);
23041: foreach my $item (@items) {
23042: if (ref($by_location{$item}) eq 'ARRAY') {
23043: push(@okvals,$item);
23044: }
23045: }
23046: } else {
23047: if (ref($by_location{$val}) eq 'ARRAY') {
23048: push(@okvals,$val);
23049: }
23050: }
23051: }
23052: @okvals = sort(@okvals);
23053: if (ref($domconfig{'trust'}) eq 'HASH') {
23054: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
23055: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
23056: if ($inuse == 0) {
23057: $changes{$prefix}{$type} = 1;
23058: } else {
23059: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23060: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
23061: if (@changed > 0) {
23062: $changes{$prefix}{$type} = 1;
23063: }
23064: }
23065: } else {
23066: if ($inuse == 1) {
23067: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23068: $changes{$prefix}{$type} = 1;
23069: }
23070: }
23071: } else {
23072: if ($inuse == 1) {
23073: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23074: $changes{$prefix}{$type} = 1;
23075: }
23076: }
23077: } else {
23078: if ($inuse == 1) {
23079: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23080: $changes{$prefix}{$type} = 1;
23081: }
23082: }
23083: }
23084: }
23085: my $nochgmsg = &mt('No changes made to trust settings.');
23086: if (keys(%changes) > 0) {
23087: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
23088: $dom);
23089: if ($putresult eq 'ok') {
23090: if (ref($defaultshash{'trust'}) eq 'HASH') {
23091: foreach my $prefix (@prefixes) {
23092: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
23093: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
23094: }
23095: }
23096: }
23097: my $cachetime = 24*60*60;
23098: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.410 raeburn 23099: &Apache::lonnet::do_cache_new('trust',$dom,$defaultshash{'trust'},3600);
1.279 raeburn 23100: if (ref($lastactref) eq 'HASH') {
23101: $lastactref->{'domdefaults'} = 1;
1.410 raeburn 23102: $lastactref->{'trust'} = 1;
1.279 raeburn 23103: }
23104: if (keys(%changes) > 0) {
23105: my %lt = &trust_titles();
23106: $resulttext = &mt('Changes made:').'<ul>';
23107: foreach my $prefix (@prefixes) {
23108: if (ref($changes{$prefix}) eq 'HASH') {
23109: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
23110: foreach my $type (@types) {
23111: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 23112: my ($newvalue,$notinuse);
1.279 raeburn 23113: if (ref($defaultshash{'trust'}) eq 'HASH') {
23114: if (ref($defaultshash{'trust'}{$prefix})) {
23115: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
23116: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
23117: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
23118: }
1.344 raeburn 23119: } else {
23120: $notinuse = 1;
1.279 raeburn 23121: }
23122: }
23123: }
1.344 raeburn 23124: if ($notinuse) {
23125: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
23126: } elsif ($newvalue eq '') {
1.279 raeburn 23127: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
23128: } else {
23129: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
23130: }
23131: }
23132: }
23133: $resulttext .= '</ul>';
23134: }
23135: }
23136: $resulttext .= '</ul>';
23137: } else {
23138: $resulttext = $nochgmsg;
23139: }
23140: } else {
23141: $resulttext = '<span class="LC_error">'.
23142: &mt('An error occurred: [_1]',$putresult).'</span>';
23143: }
23144: } else {
23145: $resulttext = $nochgmsg;
23146: }
23147: return $resulttext;
23148: }
23149:
1.150 raeburn 23150: sub modify_loadbalancing {
23151: my ($dom,%domconfig) = @_;
23152: my $primary_id = &Apache::lonnet::domain($dom,'primary');
23153: my $intdom = &Apache::lonnet::internet_dom($primary_id);
23154: my ($othertitle,$usertypes,$types) =
23155: &Apache::loncommon::sorted_inst_types($dom);
23156: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 23157: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 23158: my @sparestypes = ('primary','default');
23159: my %typetitles = &sparestype_titles();
23160: my $resulttext;
1.342 raeburn 23161: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 23162: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
23163: %existing = %{$domconfig{'loadbalancing'}};
23164: }
23165: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 23166: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 23167: my ($saveloadbalancing,%defaultshash,%changes);
23168: my ($alltypes,$othertypes,$titles) =
23169: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
23170: my %ruletitles = &offloadtype_text();
23171: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
23172: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
23173: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
23174: if ($balancer eq '') {
23175: next;
23176: }
1.210 raeburn 23177: if (!exists($servers{$balancer})) {
1.171 raeburn 23178: if (exists($currbalancer{$balancer})) {
23179: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 23180: }
1.171 raeburn 23181: next;
23182: }
23183: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
23184: push(@{$changes{'delete'}},$balancer);
23185: next;
23186: }
23187: if (!exists($currbalancer{$balancer})) {
23188: push(@{$changes{'add'}},$balancer);
23189: }
23190: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
23191: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
23192: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
23193: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
23194: $saveloadbalancing = 1;
23195: }
23196: foreach my $sparetype (@sparestypes) {
23197: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
23198: my @offloadto;
23199: foreach my $target (@targets) {
23200: if (($servers{$target}) && ($target ne $balancer)) {
23201: if ($sparetype eq 'default') {
23202: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
23203: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 23204: }
23205: }
1.171 raeburn 23206: unless(grep(/^\Q$target\E$/,@offloadto)) {
23207: push(@offloadto,$target);
23208: }
1.150 raeburn 23209: }
23210: }
1.284 raeburn 23211: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
23212: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
23213: push(@offloadto,$balancer);
23214: }
23215: }
23216: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 23217: }
1.342 raeburn 23218: if ($env{'form.loadbalancing_cookie_'.$i}) {
23219: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
1.425 raeburn 23220: if (exists($currbalancer{$balancer})) {
1.342 raeburn 23221: unless ($currcookies{$balancer}) {
23222: $changes{'curr'}{$balancer}{'cookie'} = 1;
23223: }
23224: }
23225: } elsif (exists($currbalancer{$balancer})) {
23226: if ($currcookies{$balancer}) {
23227: $changes{'curr'}{$balancer}{'cookie'} = 1;
23228: }
23229: }
1.171 raeburn 23230: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 23231: foreach my $sparetype (@sparestypes) {
1.171 raeburn 23232: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
23233: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 23234: if (@targetdiffs > 0) {
1.171 raeburn 23235: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 23236: }
1.171 raeburn 23237: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23238: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23239: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 23240: }
23241: }
23242: }
23243: } else {
1.171 raeburn 23244: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 23245: foreach my $sparetype (@sparestypes) {
1.171 raeburn 23246: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23247: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23248: $changes{'curr'}{$balancer}{'targets'} = 1;
23249: }
1.150 raeburn 23250: }
23251: }
1.210 raeburn 23252: }
1.150 raeburn 23253: }
23254: my $ishomedom;
1.171 raeburn 23255: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
23256: $ishomedom = 1;
1.150 raeburn 23257: }
23258: if (ref($alltypes) eq 'ARRAY') {
23259: foreach my $type (@{$alltypes}) {
23260: my $rule;
1.210 raeburn 23261: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 23262: (!$ishomedom)) {
1.171 raeburn 23263: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
23264: }
23265: if ($rule eq 'specific') {
1.255 raeburn 23266: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 23267: if (exists($servers{$specifiedhost})) {
1.255 raeburn 23268: $rule = $specifiedhost;
23269: }
1.150 raeburn 23270: }
1.171 raeburn 23271: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
23272: if (ref($currrules{$balancer}) eq 'HASH') {
23273: if ($rule ne $currrules{$balancer}{$type}) {
23274: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 23275: }
23276: } elsif ($rule ne '') {
1.171 raeburn 23277: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 23278: }
23279: }
23280: }
1.171 raeburn 23281: }
23282: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
23283: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
23284: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
23285: $defaultshash{'loadbalancing'} = {};
23286: }
23287: my $putresult = &Apache::lonnet::put_dom('configuration',
23288: \%defaultshash,$dom);
23289: if ($putresult eq 'ok') {
23290: if (keys(%changes) > 0) {
1.252 raeburn 23291: my %toupdate;
1.171 raeburn 23292: if (ref($changes{'delete'}) eq 'ARRAY') {
23293: foreach my $balancer (sort(@{$changes{'delete'}})) {
23294: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 23295: $toupdate{$balancer} = 1;
1.150 raeburn 23296: }
1.171 raeburn 23297: }
23298: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 23299: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 23300: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 23301: $toupdate{$balancer} = 1;
1.171 raeburn 23302: }
23303: }
23304: if (ref($changes{'curr'}) eq 'HASH') {
23305: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 23306: $toupdate{$balancer} = 1;
1.171 raeburn 23307: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
23308: if ($changes{'curr'}{$balancer}{'targets'}) {
23309: my %offloadstr;
23310: foreach my $sparetype (@sparestypes) {
23311: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23312: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23313: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
23314: }
23315: }
1.150 raeburn 23316: }
1.171 raeburn 23317: if (keys(%offloadstr) == 0) {
23318: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 23319: } else {
1.171 raeburn 23320: my $showoffload;
23321: foreach my $sparetype (@sparestypes) {
23322: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
23323: if (defined($offloadstr{$sparetype})) {
23324: $showoffload .= $offloadstr{$sparetype};
23325: } else {
23326: $showoffload .= &mt('None');
23327: }
23328: $showoffload .= (' 'x3);
23329: }
23330: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 23331: }
23332: }
23333: }
1.171 raeburn 23334: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
23335: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
23336: foreach my $type (@{$alltypes}) {
23337: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
23338: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23339: my $balancetext;
23340: if ($rule eq '') {
23341: $balancetext = $ruletitles{'default'};
1.209 raeburn 23342: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 23343: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 23344: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 23345: foreach my $sparetype (@sparestypes) {
23346: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23347: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
23348: }
23349: }
1.253 raeburn 23350: foreach my $item (@{$alltypes}) {
23351: next if ($item =~ /^_LC_ipchange/);
23352: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
23353: if ($hasrule eq 'homeserver') {
23354: map { $toupdate{$_} = 1; } (keys(%libraryservers));
23355: } else {
23356: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
23357: if ($servers{$hasrule}) {
23358: $toupdate{$hasrule} = 1;
23359: }
23360: }
23361: }
23362: }
1.254 raeburn 23363: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
23364: $balancetext = $ruletitles{$rule};
23365: } else {
23366: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23367: $balancetext = $ruletitles{'particular'}.' '.$receiver;
23368: if ($receiver) {
23369: $toupdate{$receiver};
23370: }
23371: }
23372: } else {
23373: $balancetext = $ruletitles{$rule};
1.252 raeburn 23374: }
1.171 raeburn 23375: } else {
23376: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
23377: }
1.210 raeburn 23378: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 23379: }
23380: }
23381: }
23382: }
1.342 raeburn 23383: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.389 raeburn 23384: if ($currcookies{$balancer}) {
23385: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
23386: $balancer).'</li>';
23387: } else {
23388: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
23389: $balancer).'</li>';
23390: }
1.342 raeburn 23391: }
1.375 raeburn 23392: }
23393: }
23394: if (keys(%toupdate)) {
23395: my %thismachine;
23396: my $updatedhere;
23397: my $cachetime = 60*60*24;
23398: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
23399: foreach my $lonhost (keys(%toupdate)) {
23400: if ($thismachine{$lonhost}) {
23401: unless ($updatedhere) {
23402: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
23403: $defaultshash{'loadbalancing'},
23404: $cachetime);
23405: $updatedhere = 1;
1.252 raeburn 23406: }
1.375 raeburn 23407: } else {
23408: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
23409: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.252 raeburn 23410: }
1.150 raeburn 23411: }
1.171 raeburn 23412: }
23413: if ($resulttext ne '') {
23414: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 23415: } else {
23416: $resulttext = $nochgmsg;
23417: }
23418: } else {
1.171 raeburn 23419: $resulttext = $nochgmsg;
1.150 raeburn 23420: }
23421: } else {
1.171 raeburn 23422: $resulttext = '<span class="LC_error">'.
23423: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 23424: }
23425: } else {
1.171 raeburn 23426: $resulttext = $nochgmsg;
1.150 raeburn 23427: }
23428: return $resulttext;
23429: }
23430:
1.48 raeburn 23431: sub recurse_check {
23432: my ($chkcats,$categories,$depth,$name) = @_;
23433: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
23434: my $chg = 0;
23435: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
23436: my $category = $chkcats->[$depth]{$name}[$j];
23437: my $item;
23438: if ($category eq '') {
23439: $chg ++;
23440: } else {
23441: my $deeper = $depth + 1;
23442: $item = &escape($category).':'.&escape($name).':'.$depth;
23443: if ($chg) {
23444: $categories->{$item} -= $chg;
23445: }
23446: &recurse_check($chkcats,$categories,$deeper,$category);
23447: $deeper --;
23448: }
23449: }
23450: }
23451: return;
23452: }
23453:
23454: sub recurse_cat_deletes {
23455: my ($item,$coursecategories,$deletions) = @_;
23456: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
23457: my $subdepth = $depth + 1;
23458: if (ref($coursecategories) eq 'HASH') {
23459: foreach my $subitem (keys(%{$coursecategories})) {
23460: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
23461: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
23462: delete($coursecategories->{$subitem});
23463: $deletions->{$subitem} = 1;
23464: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 23465: }
1.48 raeburn 23466: }
23467: }
23468: return;
23469: }
23470:
1.125 raeburn 23471: sub active_dc_picker {
1.191 raeburn 23472: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 23473: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 23474: my @domcoord = keys(%domcoords);
23475: if (keys(%currhash)) {
23476: foreach my $dc (keys(%currhash)) {
23477: unless (exists($domcoords{$dc})) {
23478: push(@domcoord,$dc);
23479: }
23480: }
23481: }
23482: @domcoord = sort(@domcoord);
1.210 raeburn 23483: my $numdcs = scalar(@domcoord);
1.191 raeburn 23484: my $rows = 0;
23485: my $table;
1.125 raeburn 23486: if ($numdcs > 1) {
1.191 raeburn 23487: $table = '<table>';
23488: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 23489: my $rem = $i%($numinrow);
23490: if ($rem == 0) {
23491: if ($i > 0) {
1.191 raeburn 23492: $table .= '</tr>';
1.125 raeburn 23493: }
1.191 raeburn 23494: $table .= '<tr>';
23495: $rows ++;
1.125 raeburn 23496: }
1.191 raeburn 23497: my $check = '';
23498: if ($inputtype eq 'radio') {
23499: if (keys(%currhash) == 0) {
23500: if (!$i) {
23501: $check = ' checked="checked"';
23502: }
23503: } elsif (exists($currhash{$domcoord[$i]})) {
23504: $check = ' checked="checked"';
23505: }
23506: } else {
23507: if (exists($currhash{$domcoord[$i]})) {
23508: $check = ' checked="checked"';
1.125 raeburn 23509: }
23510: }
1.191 raeburn 23511: if ($i == @domcoord - 1) {
1.125 raeburn 23512: my $colsleft = $numinrow - $rem;
23513: if ($colsleft > 1) {
1.191 raeburn 23514: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 23515: } else {
1.191 raeburn 23516: $table .= '<td class="LC_left_item">';
1.125 raeburn 23517: }
23518: } else {
1.191 raeburn 23519: $table .= '<td class="LC_left_item">';
23520: }
23521: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
23522: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
23523: $table .= '<span class="LC_nobreak"><label>'.
23524: '<input type="'.$inputtype.'" name="'.$name.'"'.
23525: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
23526: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 23527: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 23528: }
1.219 raeburn 23529: $table .= '</label></span></td>';
1.191 raeburn 23530: }
23531: $table .= '</tr></table>';
23532: } elsif ($numdcs == 1) {
1.219 raeburn 23533: my ($dcname,$dcdom) = split(':',$domcoord[0]);
23534: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 23535: if ($inputtype eq 'radio') {
1.247 raeburn 23536: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 23537: if ($user ne $dcname.':'.$dcdom) {
23538: $table .= ' ('.$dcname.':'.$dcdom.')';
23539: }
1.191 raeburn 23540: } else {
23541: my $check;
23542: if (exists($currhash{$domcoord[0]})) {
23543: $check = ' checked="checked"';
1.125 raeburn 23544: }
1.247 raeburn 23545: $table = '<span class="LC_nobreak"><label>'.
23546: '<input type="checkbox" name="'.$name.'" '.
23547: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 23548: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 23549: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 23550: }
1.220 raeburn 23551: $table .= '</label></span>';
1.191 raeburn 23552: $rows ++;
1.125 raeburn 23553: }
23554: }
1.191 raeburn 23555: return ($numdcs,$table,$rows);
1.125 raeburn 23556: }
23557:
1.137 raeburn 23558: sub usersession_titles {
23559: return &Apache::lonlocal::texthash(
23560: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
23561: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 23562: spares => 'Servers offloaded to, when busy',
1.137 raeburn 23563: version => 'LON-CAPA version requirement',
1.138 raeburn 23564: excludedomain => 'Allow all, but exclude specific domains',
23565: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 23566: primary => 'Primary (checked first)',
1.154 raeburn 23567: default => 'Default',
1.137 raeburn 23568: );
23569: }
23570:
1.152 raeburn 23571: sub id_for_thisdom {
23572: my (%servers) = @_;
23573: my %altids;
23574: foreach my $server (keys(%servers)) {
23575: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
23576: if ($serverhome ne $server) {
23577: $altids{$serverhome} = $server;
23578: }
23579: }
23580: return %altids;
23581: }
23582:
1.150 raeburn 23583: sub count_servers {
23584: my ($currbalancer,%servers) = @_;
23585: my (@spares,$numspares);
23586: foreach my $lonhost (sort(keys(%servers))) {
23587: next if ($currbalancer eq $lonhost);
23588: push(@spares,$lonhost);
23589: }
23590: if ($currbalancer) {
23591: $numspares = scalar(@spares);
23592: } else {
23593: $numspares = scalar(@spares) - 1;
23594: }
23595: return ($numspares,@spares);
23596: }
23597:
23598: sub lonbalance_targets_js {
1.171 raeburn 23599: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 23600: my $select = &mt('Select');
23601: my ($alltargets,$allishome,$allinsttypes,@alltypes);
23602: if (ref($servers) eq 'HASH') {
23603: $alltargets = join("','",sort(keys(%{$servers})));
23604: my @homedoms;
23605: foreach my $server (sort(keys(%{$servers}))) {
23606: if (&Apache::lonnet::host_domain($server) eq $dom) {
23607: push(@homedoms,'1');
23608: } else {
23609: push(@homedoms,'0');
23610: }
23611: }
23612: $allishome = join("','",@homedoms);
23613: }
23614: if (ref($types) eq 'ARRAY') {
23615: if (@{$types} > 0) {
23616: @alltypes = @{$types};
23617: }
23618: }
23619: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
23620: $allinsttypes = join("','",@alltypes);
1.342 raeburn 23621: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 23622: if (ref($settings) eq 'HASH') {
23623: %existing = %{$settings};
23624: }
23625: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 23626: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 23627: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 23628: return <<"END";
23629:
23630: <script type="text/javascript">
23631: // <![CDATA[
23632:
1.171 raeburn 23633: currBalancers = new Array('$balancers');
23634:
23635: function toggleTargets(balnum) {
23636: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23637: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
23638: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
23639: var prevbalancer = prevhostitem.value;
23640: var baltotal = document.getElementById('loadbalancing_total').value;
23641: prevhostitem.value = balancer;
23642: if (prevbalancer != '') {
23643: var prevIdx = currBalancers.indexOf(prevbalancer);
23644: if (prevIdx != -1) {
23645: currBalancers.splice(prevIdx,1);
23646: }
23647: }
1.150 raeburn 23648: if (balancer == '') {
1.171 raeburn 23649: hideSpares(balnum);
1.150 raeburn 23650: } else {
1.171 raeburn 23651: var currIdx = currBalancers.indexOf(balancer);
23652: if (currIdx == -1) {
23653: currBalancers.push(balancer);
23654: }
1.150 raeburn 23655: var homedoms = new Array('$allishome');
1.171 raeburn 23656: var ishomedom = homedoms[lonhostitem.selectedIndex];
23657: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 23658: }
1.171 raeburn 23659: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 23660: return;
23661: }
23662:
1.171 raeburn 23663: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 23664: var alltargets = new Array('$alltargets');
23665: var insttypes = new Array('$allinsttypes');
1.151 raeburn 23666: var offloadtypes = new Array('primary','default');
23667:
1.171 raeburn 23668: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
23669: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 23670:
1.151 raeburn 23671: for (var i=0; i<offloadtypes.length; i++) {
23672: var count = 0;
23673: for (var j=0; j<alltargets.length; j++) {
23674: if (alltargets[j] != balancer) {
1.171 raeburn 23675: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
23676: item.value = alltargets[j];
23677: item.style.textAlign='left';
23678: item.style.textFace='normal';
23679: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
23680: if (currBalancers.indexOf(alltargets[j]) == -1) {
23681: item.disabled = '';
23682: } else {
23683: item.disabled = 'disabled';
23684: item.checked = false;
23685: }
1.151 raeburn 23686: count ++;
23687: }
1.150 raeburn 23688: }
23689: }
1.151 raeburn 23690: for (var k=0; k<insttypes.length; k++) {
23691: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 23692: if (ishomedom == 1) {
1.171 raeburn 23693: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23694: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23695: } else {
1.171 raeburn 23696: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23697: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 23698: }
23699: } else {
1.171 raeburn 23700: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23701: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23702: }
1.151 raeburn 23703: if ((insttypes[k] != '_LC_external') &&
23704: ((insttypes[k] != '_LC_internetdom') ||
23705: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 23706: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
23707: item.options.length = 0;
23708: item.options[0] = new Option("","",true,true);
1.210 raeburn 23709: var idx = 0;
1.151 raeburn 23710: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 23711: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
23712: idx ++;
23713: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 23714: }
23715: }
23716: }
23717: }
23718: return;
23719: }
23720:
1.171 raeburn 23721: function hideSpares(balnum) {
1.150 raeburn 23722: var alltargets = new Array('$alltargets');
23723: var insttypes = new Array('$allinsttypes');
23724: var offloadtypes = new Array('primary','default');
23725:
1.171 raeburn 23726: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
23727: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 23728:
23729: var total = alltargets.length - 1;
23730: for (var i=0; i<offloadtypes; i++) {
23731: for (var j=0; j<total; j++) {
1.171 raeburn 23732: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
23733: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
23734: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 23735: }
1.150 raeburn 23736: }
23737: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 23738: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23739: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 23740: if (insttypes[k] != '_LC_external') {
1.171 raeburn 23741: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
23742: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 23743: }
23744: }
23745: return;
23746: }
23747:
1.171 raeburn 23748: function checkOffloads(item,balnum,type) {
1.150 raeburn 23749: var alltargets = new Array('$alltargets');
23750: var offloadtypes = new Array('primary','default');
23751: if (item.checked) {
23752: var total = alltargets.length - 1;
23753: var other;
23754: if (type == offloadtypes[0]) {
1.151 raeburn 23755: other = offloadtypes[1];
1.150 raeburn 23756: } else {
1.151 raeburn 23757: other = offloadtypes[0];
1.150 raeburn 23758: }
23759: for (var i=0; i<total; i++) {
1.171 raeburn 23760: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 23761: if (server == item.value) {
1.171 raeburn 23762: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
23763: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 23764: }
23765: }
23766: }
23767: }
23768: return;
23769: }
23770:
1.171 raeburn 23771: function singleServerToggle(balnum,type) {
23772: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 23773: if (offloadtoSelIdx == 0) {
1.171 raeburn 23774: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
23775: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23776:
23777: } else {
1.171 raeburn 23778: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
23779: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 23780: }
23781: return;
23782: }
23783:
1.171 raeburn 23784: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 23785: if (type == '_LC_external') {
1.171 raeburn 23786: return;
1.150 raeburn 23787: }
1.171 raeburn 23788: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 23789: for (var i=0; i<typesRules.length; i++) {
23790: if (formname.elements[typesRules[i]].checked) {
23791: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 23792: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
23793: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23794: } else {
1.171 raeburn 23795: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
23796: }
23797: }
23798: }
23799: return;
23800: }
23801:
23802: function balancerDeleteChange(balnum) {
23803: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23804: var baltotal = document.getElementById('loadbalancing_total').value;
23805: var addtarget;
23806: var removetarget;
23807: var action = 'delete';
23808: if (document.getElementById('loadbalancing_delete_'+balnum)) {
23809: var lonhost = hostitem.value;
23810: var currIdx = currBalancers.indexOf(lonhost);
23811: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
23812: if (currIdx != -1) {
23813: currBalancers.splice(currIdx,1);
23814: }
23815: addtarget = lonhost;
23816: } else {
23817: if (currIdx == -1) {
23818: currBalancers.push(lonhost);
23819: }
23820: removetarget = lonhost;
23821: action = 'undelete';
23822: }
23823: balancerChange(balnum,baltotal,action,addtarget,removetarget);
23824: }
23825: return;
23826: }
23827:
23828: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
23829: if (baltotal > 1) {
23830: var offloadtypes = new Array('primary','default');
23831: var alltargets = new Array('$alltargets');
23832: var insttypes = new Array('$allinsttypes');
23833: for (var i=0; i<baltotal; i++) {
23834: if (i != balnum) {
23835: for (var j=0; j<offloadtypes.length; j++) {
23836: var total = alltargets.length - 1;
23837: for (var k=0; k<total; k++) {
23838: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
23839: var server = serveritem.value;
23840: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23841: if (server == addtarget) {
23842: serveritem.disabled = '';
23843: }
23844: }
23845: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23846: if (server == removetarget) {
23847: serveritem.disabled = 'disabled';
23848: serveritem.checked = false;
23849: }
23850: }
23851: }
23852: }
23853: for (var j=0; j<insttypes.length; j++) {
23854: if (insttypes[j] != '_LC_external') {
23855: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
23856: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
23857: var currSel = singleserver.selectedIndex;
23858: var currVal = singleserver.options[currSel].value;
23859: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23860: var numoptions = singleserver.options.length;
23861: var needsnew = 1;
23862: for (var k=0; k<numoptions; k++) {
23863: if (singleserver.options[k] == addtarget) {
23864: needsnew = 0;
23865: break;
23866: }
23867: }
23868: if (needsnew == 1) {
23869: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
23870: }
23871: }
23872: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23873: singleserver.options.length = 0;
23874: if ((currVal) && (currVal != removetarget)) {
23875: singleserver.options[0] = new Option("","",false,false);
23876: } else {
23877: singleserver.options[0] = new Option("","",true,true);
23878: }
23879: var idx = 0;
23880: for (var m=0; m<alltargets.length; m++) {
23881: if (currBalancers.indexOf(alltargets[m]) == -1) {
23882: idx ++;
23883: if (currVal == alltargets[m]) {
23884: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
23885: } else {
23886: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
23887: }
23888: }
23889: }
23890: }
23891: }
23892: }
23893: }
1.150 raeburn 23894: }
23895: }
23896: }
23897: return;
23898: }
23899:
1.152 raeburn 23900: // ]]>
23901: </script>
23902:
23903: END
23904: }
23905:
23906: sub new_spares_js {
23907: my @sparestypes = ('primary','default');
23908: my $types = join("','",@sparestypes);
23909: my $select = &mt('Select');
23910: return <<"END";
23911:
23912: <script type="text/javascript">
23913: // <![CDATA[
23914:
23915: function updateNewSpares(formname,lonhost) {
23916: var types = new Array('$types');
23917: var include = new Array();
23918: var exclude = new Array();
23919: for (var i=0; i<types.length; i++) {
23920: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
23921: for (var j=0; j<spareboxes.length; j++) {
23922: if (formname.elements[spareboxes[j]].checked) {
23923: exclude.push(formname.elements[spareboxes[j]].value);
23924: } else {
23925: include.push(formname.elements[spareboxes[j]].value);
23926: }
23927: }
23928: }
23929: for (var i=0; i<types.length; i++) {
23930: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
23931: var selIdx = newSpare.selectedIndex;
23932: var currnew = newSpare.options[selIdx].value;
23933: var okSpares = new Array();
23934: for (var j=0; j<newSpare.options.length; j++) {
23935: var possible = newSpare.options[j].value;
23936: if (possible != '') {
23937: if (exclude.indexOf(possible) == -1) {
23938: okSpares.push(possible);
23939: } else {
23940: if (currnew == possible) {
23941: selIdx = 0;
23942: }
23943: }
23944: }
23945: }
23946: for (var k=0; k<include.length; k++) {
23947: if (okSpares.indexOf(include[k]) == -1) {
23948: okSpares.push(include[k]);
23949: }
23950: }
23951: okSpares.sort();
23952: newSpare.options.length = 0;
23953: if (selIdx == 0) {
23954: newSpare.options[0] = new Option("$select","",true,true);
23955: } else {
23956: newSpare.options[0] = new Option("$select","",false,false);
23957: }
23958: for (var m=0; m<okSpares.length; m++) {
23959: var idx = m+1;
23960: var selThis = 0;
23961: if (selIdx != 0) {
23962: if (okSpares[m] == currnew) {
23963: selThis = 1;
23964: }
23965: }
23966: if (selThis == 1) {
23967: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
23968: } else {
23969: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
23970: }
23971: }
23972: }
23973: return;
23974: }
23975:
23976: function checkNewSpares(lonhost,type) {
23977: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
23978: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.372 raeburn 23979: if (chosen != '') {
1.152 raeburn 23980: var othertype;
23981: var othernewSpare;
23982: if (type == 'primary') {
23983: othernewSpare = document.getElementById('newspare_default_'+lonhost);
23984: }
23985: if (type == 'default') {
23986: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
23987: }
23988: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
23989: othernewSpare.selectedIndex = 0;
23990: }
23991: }
23992: return;
23993: }
23994:
23995: // ]]>
23996: </script>
23997:
23998: END
23999:
24000: }
24001:
24002: sub common_domprefs_js {
24003: return <<"END";
24004:
24005: <script type="text/javascript">
24006: // <![CDATA[
24007:
1.150 raeburn 24008: function getIndicesByName(formname,item) {
1.152 raeburn 24009: var group = new Array();
1.150 raeburn 24010: for (var i=0;i<formname.elements.length;i++) {
24011: if (formname.elements[i].name == item) {
1.152 raeburn 24012: group.push(formname.elements[i].id);
1.150 raeburn 24013: }
24014: }
1.152 raeburn 24015: return group;
1.150 raeburn 24016: }
24017:
24018: // ]]>
24019: </script>
24020:
24021: END
1.152 raeburn 24022:
1.150 raeburn 24023: }
24024:
1.165 raeburn 24025: sub recaptcha_js {
24026: my %lt = &captcha_phrases();
24027: return <<"END";
24028:
24029: <script type="text/javascript">
24030: // <![CDATA[
24031:
24032: function updateCaptcha(caller,context) {
24033: var privitem;
24034: var pubitem;
24035: var privtext;
24036: var pubtext;
1.269 raeburn 24037: var versionitem;
24038: var versiontext;
1.165 raeburn 24039: if (document.getElementById(context+'_recaptchapub')) {
24040: pubitem = document.getElementById(context+'_recaptchapub');
24041: } else {
24042: return;
24043: }
24044: if (document.getElementById(context+'_recaptchapriv')) {
24045: privitem = document.getElementById(context+'_recaptchapriv');
24046: } else {
24047: return;
24048: }
24049: if (document.getElementById(context+'_recaptchapubtxt')) {
24050: pubtext = document.getElementById(context+'_recaptchapubtxt');
24051: } else {
24052: return;
24053: }
24054: if (document.getElementById(context+'_recaptchaprivtxt')) {
24055: privtext = document.getElementById(context+'_recaptchaprivtxt');
24056: } else {
24057: return;
24058: }
1.269 raeburn 24059: if (document.getElementById(context+'_recaptchaversion')) {
24060: versionitem = document.getElementById(context+'_recaptchaversion');
24061: } else {
24062: return;
24063: }
24064: if (document.getElementById(context+'_recaptchavertxt')) {
24065: versiontext = document.getElementById(context+'_recaptchavertxt');
24066: } else {
24067: return;
24068: }
1.165 raeburn 24069: if (caller.checked) {
24070: if (caller.value == 'recaptcha') {
24071: pubitem.type = 'text';
24072: privitem.type = 'text';
24073: pubitem.size = '40';
24074: privitem.size = '40';
24075: pubtext.innerHTML = "$lt{'pub'}";
24076: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 24077: versionitem.type = 'text';
24078: versionitem.size = '3';
1.289 raeburn 24079: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 24080: } else {
24081: pubitem.type = 'hidden';
24082: privitem.type = 'hidden';
1.269 raeburn 24083: versionitem.type = 'hidden';
1.165 raeburn 24084: pubtext.innerHTML = '';
24085: privtext.innerHTML = '';
1.269 raeburn 24086: versiontext.innerHTML = '';
1.165 raeburn 24087: }
24088: }
24089: return;
24090: }
24091:
24092: // ]]>
24093: </script>
24094:
24095: END
24096:
24097: }
24098:
1.236 raeburn 24099: sub toggle_display_js {
1.192 raeburn 24100: return <<"END";
24101:
24102: <script type="text/javascript">
24103: // <![CDATA[
24104:
1.236 raeburn 24105: function toggleDisplay(domForm,caller) {
24106: if (document.getElementById(caller)) {
24107: var divitem = document.getElementById(caller);
24108: var optionsElement = domForm.coursecredits;
1.264 raeburn 24109: var checkval = 1;
24110: var dispval = 'block';
1.303 raeburn 24111: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 24112: if (caller == 'emailoptions') {
1.372 raeburn 24113: optionsElement = domForm.cancreate_email;
1.236 raeburn 24114: }
1.257 raeburn 24115: if (caller == 'studentsubmission') {
24116: optionsElement = domForm.postsubmit;
24117: }
1.264 raeburn 24118: if (caller == 'cloneinstcode') {
24119: optionsElement = domForm.canclone;
24120: checkval = 'instcode';
24121: }
1.303 raeburn 24122: if (selfcreateRegExp.test(caller)) {
24123: optionsElement = domForm.elements[caller];
24124: checkval = 'other';
24125: dispval = 'inline'
24126: }
1.236 raeburn 24127: if (optionsElement.length) {
1.192 raeburn 24128: var currval;
1.236 raeburn 24129: for (var i=0; i<optionsElement.length; i++) {
24130: if (optionsElement[i].checked) {
24131: currval = optionsElement[i].value;
1.192 raeburn 24132: }
24133: }
1.264 raeburn 24134: if (currval == checkval) {
24135: divitem.style.display = dispval;
1.192 raeburn 24136: } else {
1.236 raeburn 24137: divitem.style.display = 'none';
1.192 raeburn 24138: }
24139: }
24140: }
24141: return;
24142: }
24143:
24144: // ]]>
24145: </script>
24146:
24147: END
24148:
24149: }
24150:
1.165 raeburn 24151: sub captcha_phrases {
24152: return &Apache::lonlocal::texthash (
24153: priv => 'Private key',
24154: pub => 'Public key',
24155: original => 'original (CAPTCHA)',
24156: recaptcha => 'successor (ReCAPTCHA)',
24157: notused => 'unused',
1.289 raeburn 24158: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 24159: );
24160: }
24161:
1.205 raeburn 24162: sub devalidate_remote_domconfs {
1.212 raeburn 24163: my ($dom,$cachekeys) = @_;
24164: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 24165: my %servers = &Apache::lonnet::internet_dom_servers($dom);
24166: my %thismachine;
24167: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 raeburn 24168: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.394 raeburn 24169: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
1.410 raeburn 24170: 'ipaccess','trust');
1.386 raeburn 24171: my %cache_by_lonhost;
24172: if (exists($cachekeys->{'samllanding'})) {
24173: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
24174: my %landing = %{$cachekeys->{'samllanding'}};
24175: my %domservers = &Apache::lonnet::get_servers($dom);
24176: if (keys(%domservers)) {
24177: foreach my $server (keys(%domservers)) {
24178: my @cached;
24179: next if ($thismachine{$server});
24180: if ($landing{$server}) {
24181: push(@cached,&escape('samllanding').':'.&escape($server));
24182: }
24183: if (@cached) {
24184: $cache_by_lonhost{$server} = \@cached;
24185: }
24186: }
24187: }
24188: }
24189: }
1.260 raeburn 24190: if (keys(%servers)) {
1.205 raeburn 24191: foreach my $server (keys(%servers)) {
24192: next if ($thismachine{$server});
1.212 raeburn 24193: my @cached;
24194: foreach my $name (@posscached) {
24195: if ($cachekeys->{$name}) {
1.388 raeburn 24196: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
1.386 raeburn 24197: if (ref($cachekeys->{$name}) eq 'HASH') {
1.373 raeburn 24198: foreach my $key (keys(%{$cachekeys->{$name}})) {
24199: push(@cached,&escape($name).':'.&escape($key));
24200: }
24201: }
24202: } else {
24203: push(@cached,&escape($name).':'.&escape($dom));
24204: }
1.212 raeburn 24205: }
24206: }
1.386 raeburn 24207: if ((exists($cache_by_lonhost{$server})) &&
24208: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
24209: push(@cached,@{$cache_by_lonhost{$server}});
24210: }
1.212 raeburn 24211: if (@cached) {
24212: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
24213: }
1.205 raeburn 24214: }
24215: }
24216: return;
24217: }
24218:
1.3 raeburn 24219: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>