Annotation of loncom/interface/domainprefs.pm, revision 1.437
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.437 ! raeburn 4: # $Id: domainprefs.pm,v 1.436 2024/02/27 15:48:01 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
1.286 raeburn 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
1.1 raeburn 24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: ###############################################################
1.297 raeburn 30: ###############################################################
1.1 raeburn 31:
1.101 raeburn 32: =pod
33:
34: =head1 NAME
35:
36: Apache::domainprefs.pm
37:
38: =head1 SYNOPSIS
39:
40: Handles configuration of a LON-CAPA domain.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
45:
46: =head1 OVERVIEW
47:
48: Each institution using LON-CAPA will typically have a single domain designated
1.183 bisitz 49: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 50: may define a default set of logos and a color scheme which can be used to "brand"
51: the LON-CAPA instance. In addition, an institution will typically have a language
52: and timezone which are used for the majority of courses.
53:
54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
55: host of other domain-wide settings which determine the types of functionality
56: available to users and courses in the domain.
57:
58: There is also a mechanism to configure cataloging of courses in the domain, and
59: controls on the operation of automated processes which govern such things as
60: roster updates, user directory updates and processing of course requests.
61:
62: The domain coordination manual which is built dynamically on install/update of
63: LON-CAPA from the relevant help items provides more information about domain
64: configuration.
65:
66: Most of the domain settings are stored in the configuration.db GDBM file which is
67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
68: where $dom is the domain. The configuration.db stores settings in a number of
69: frozen hashes of hashes. In a few cases, domain information must be uploaded to
70: the domain as files (e.g., image files for logos etc., or plain text files for
71: bubblesheet formats). In this case the domainprefs.pm must be running in a user
72: session hosted on the primary library server in the domain, as these files are
73: stored in author space belonging to a special $dom-domainconfig user.
74:
75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
76: the current settings, and provides an interface to make modifications.
77:
78: =head1 SUBROUTINES
79:
80: =over
81:
82: =item print_quotas()
83:
84: Inputs: 4
85:
86: $dom,$settings,$rowtotal,$action.
87:
88: $dom is the domain, $settings is a reference to a hash of current settings for
89: the current context, $rowtotal is a reference to the scalar used to record the
1.210 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.163 raeburn 91: requestcourses or requestauthor).
1.101 raeburn 92:
93: The print_quotas routine was orginally created to display/store information
94: about default quota sizes for portfolio spaces for the different types of
95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
96: but is now also used to manage availability of user tools:
97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.429 raeburn 98: used by course owners to request creation of a course.
1.101 raeburn 99:
100: Outputs: 1
101:
102: $datatable - HTML containing form elements which allow settings to be changed.
103:
104: In the case of course requests, radio buttons are displayed for each institutional
105: affiliate type (and also default, and _LC_adv) for each of the course types
1.325 raeburn 106: (official, unofficial, community, textbook, placement, and lti).
1.425 raeburn 107: In each case the radio buttons allow the selection of one of four values:
1.101 raeburn 108:
1.104 raeburn 109: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 110: which have the following effects:
111:
112: 0
113:
114: =over
115:
116: - course requests are not allowed for this course types/affiliation
117:
118: =back
119:
1.104 raeburn 120: approval
1.101 raeburn 121:
122: =over
123:
124: - course requests must be approved by a Doman Coordinator in the
125: course's domain
126:
127: =back
128:
129: validate
130:
131: =over
132:
133: - an institutional validation (e.g., check requestor is instructor
134: of record) needs to be passed before the course will be created. The required
135: validation is in localenroll.pm on the primary library server for the course
136: domain.
137:
138: =back
139:
140: autolimit
141:
142: =over
143:
1.143 raeburn 144: - course requests will be processed automatically up to a limit of
1.101 raeburn 145: N requests for the course type for the particular requestor.
146: If N is undefined, there is no limit to the number of course requests
147: which a course owner may submit and have processed automatically.
148:
149: =back
150:
151: =item modify_quotas()
152:
153: =back
154:
155: =cut
156:
1.1 raeburn 157: package Apache::domainprefs;
158:
159: use strict;
160: use Apache::Constants qw(:common :http);
161: use Apache::lonnet;
162: use Apache::loncommon();
163: use Apache::lonhtmlcommon();
164: use Apache::lonlocal;
1.43 raeburn 165: use Apache::lonmsg();
1.91 raeburn 166: use Apache::lonconfigsettings;
1.232 raeburn 167: use Apache::lonuserutils();
1.235 raeburn 168: use Apache::loncoursequeueadmin();
1.419 raeburn 169: use Apache::courseprefs();
1.69 raeburn 170: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 171: use LONCAPA::Enrollment;
1.81 raeburn 172: use LONCAPA::lonauthcgi();
1.275 raeburn 173: use LONCAPA::SSL;
1.9 raeburn 174: use File::Copy;
1.43 raeburn 175: use Locale::Language;
1.62 raeburn 176: use DateTime::TimeZone;
1.68 raeburn 177: use DateTime::Locale;
1.267 raeburn 178: use Time::HiRes qw( sleep );
1.373 raeburn 179: use Net::CIDR;
1.424 raeburn 180: use Crypt::CBC;
1.1 raeburn 181:
1.155 raeburn 182: my $registered_cleanup;
183: my $modified_urls;
184:
1.1 raeburn 185: sub handler {
186: my $r=shift;
187: if ($r->header_only) {
188: &Apache::loncommon::content_type($r,'text/html');
189: $r->send_http_header;
190: return OK;
191: }
192:
1.91 raeburn 193: my $context = 'domain';
1.1 raeburn 194: my $dom = $env{'request.role.domain'};
1.5 albertel 195: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 196: if (&Apache::lonnet::allowed('mau',$dom)) {
197: &Apache::loncommon::content_type($r,'text/html');
198: $r->send_http_header;
199: } else {
200: $env{'user.error.msg'}=
201: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
202: return HTTP_NOT_ACCEPTABLE;
203: }
1.155 raeburn 204:
205: $registered_cleanup=0;
206: @{$modified_urls}=();
207:
1.1 raeburn 208: &Apache::lonhtmlcommon::clear_breadcrumbs();
209: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 210: ['phase','actions']);
1.30 raeburn 211: my $phase = 'pickactions';
1.3 raeburn 212: if ( exists($env{'form.phase'}) ) {
213: $phase = $env{'form.phase'};
214: }
1.150 raeburn 215: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 216: my %domconfig =
1.6 raeburn 217: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 218: 'quotas','autoenroll','autoupdate','autocreate',
219: 'directorysrch','usercreation','usermodification',
220: 'contacts','defaults','scantron','coursecategories',
221: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 222: 'coursedefaults','usersessions','loadbalancing',
1.267 raeburn 223: 'requestauthor','selfenrollment','inststatus',
1.421 raeburn 224: 'ltitools','toolsec','ssl','trust','lti','ltisec',
1.429 raeburn 225: 'privacy','passwords','proctoring','wafproxy',
226: 'ipaccess','authordefaults'],$dom);
1.320 raeburn 227: my %encconfig =
1.405 raeburn 228: &Apache::lonnet::get_dom('encconfig',['ltitools','lti','proctoring','linkprot'],$dom,undef,1);
1.424 raeburn 229: my ($checked_is_home,$is_home);
1.297 raeburn 230: if (ref($domconfig{'ltitools'}) eq 'HASH') {
231: if (ref($encconfig{'ltitools'}) eq 'HASH') {
1.423 raeburn 232: my $home = &Apache::lonnet::domain($dom,'primary');
233: unless (($home eq 'no_host') || ($home eq '')) {
234: my @ids=&Apache::lonnet::current_machine_ids();
235: if (grep(/^\Q$home\E$/,@ids)) {
236: $is_home = 1;
237: }
238: }
1.425 raeburn 239: $checked_is_home = 1;
1.297 raeburn 240: foreach my $id (keys(%{$domconfig{'ltitools'}})) {
1.320 raeburn 241: if ((ref($domconfig{'ltitools'}{$id}) eq 'HASH') &&
242: (ref($encconfig{'ltitools'}{$id}) eq 'HASH')) {
1.421 raeburn 243: $domconfig{'ltitools'}{$id}{'key'} = $encconfig{'ltitools'}{$id}{'key'};
1.423 raeburn 244: if (($is_home) && ($phase eq 'process')) {
245: $domconfig{'ltitools'}{$id}{'secret'} = $encconfig{'ltitools'}{$id}{'secret'};
246: }
1.297 raeburn 247: }
248: }
249: }
250: }
1.320 raeburn 251: if (ref($domconfig{'lti'}) eq 'HASH') {
252: if (ref($encconfig{'lti'}) eq 'HASH') {
1.424 raeburn 253: unless ($checked_is_home) {
254: my $home = &Apache::lonnet::domain($dom,'primary');
255: unless (($home eq 'no_host') || ($home eq '')) {
256: my @ids=&Apache::lonnet::current_machine_ids();
257: if (grep(/^\Q$home\E$/,@ids)) {
258: $is_home = 1;
259: }
260: }
261: $checked_is_home = 1;
262: }
1.320 raeburn 263: foreach my $id (keys(%{$domconfig{'lti'}})) {
264: if ((ref($domconfig{'lti'}{$id}) eq 'HASH') &&
265: (ref($encconfig{'lti'}{$id}) eq 'HASH')) {
1.424 raeburn 266: $domconfig{'lti'}{$id}{'key'} = $encconfig{'lti'}{$id}{'key'};
267: if (($is_home) && ($phase eq 'process')) {
268: $domconfig{'lti'}{$id}{'secret'} = $encconfig{'lti'}{$id}{'secret'};
1.320 raeburn 269: }
270: }
271: }
272: }
273: }
1.405 raeburn 274: if (ref($domconfig{'ltisec'}) eq 'HASH') {
1.406 raeburn 275: if (ref($domconfig{'ltisec'}{'linkprot'}) eq 'HASH') {
1.405 raeburn 276: if (ref($encconfig{'linkprot'}) eq 'HASH') {
1.406 raeburn 277: foreach my $id (keys(%{$domconfig{'ltisec'}{'linkprot'}})) {
278: unless ($id =~ /^\d+$/) {
279: delete($domconfig{'ltisec'}{'linkprot'}{$id});
280: }
281: if ((ref($domconfig{'ltisec'}{'linkprot'}{$id}) eq 'HASH') &&
1.405 raeburn 282: (ref($encconfig{'linkprot'}{$id}) eq 'HASH')) {
283: foreach my $item ('key','secret') {
1.406 raeburn 284: $domconfig{'ltisec'}{'linkprot'}{$id}{$item} = $encconfig{'linkprot'}{$id}{$item};
1.405 raeburn 285: }
286: }
287: }
288: }
289: }
290: }
1.372 raeburn 291: if (ref($domconfig{'proctoring'}) eq 'HASH') {
292: if (ref($encconfig{'proctoring'}) eq 'HASH') {
293: foreach my $provider (keys(%{$domconfig{'proctoring'}})) {
294: if ((ref($domconfig{'proctoring'}{$provider}) eq 'HASH') &&
295: (ref($encconfig{'proctoring'}{$provider}) eq 'HASH')) {
296: foreach my $item ('key','secret') {
297: $domconfig{'proctoring'}{$provider}{$item} = $encconfig{'proctoring'}{$provider}{$item};
298: }
299: }
300: }
301: }
302: }
1.394 raeburn 303: my @prefs_order = ('rolecolors','login','ipaccess','defaults','wafproxy','passwords',
304: 'quotas','autoenroll','autoupdate','autocreate','directorysrch',
1.373 raeburn 305: 'contacts','privacy','usercreation','selfcreation',
1.374 raeburn 306: 'usermodification','scantron','requestcourses','requestauthor',
1.373 raeburn 307: 'coursecategories','serverstatuses','helpsettings','coursedefaults',
1.429 raeburn 308: 'authordefaults','ltitools','proctoring','selfenrollment',
309: 'usersessions','ssl','trust','lti');
1.171 raeburn 310: my %existing;
311: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
312: %existing = %{$domconfig{'loadbalancing'}};
313: }
314: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 315: push(@prefs_order,'loadbalancing');
316: }
1.30 raeburn 317: my %prefs = (
318: 'rolecolors' =>
319: { text => 'Default color schemes',
1.67 raeburn 320: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 321: header => [{col1 => 'Student Settings',
322: col2 => '',},
323: {col1 => 'Coordinator Settings',
324: col2 => '',},
325: {col1 => 'Author Settings',
326: col2 => '',},
327: {col1 => 'Administrator Settings',
328: col2 => '',}],
1.230 raeburn 329: print => \&print_rolecolors,
330: modify => \&modify_rolecolors,
1.30 raeburn 331: },
1.110 raeburn 332: 'login' =>
1.30 raeburn 333: { text => 'Log-in page options',
1.67 raeburn 334: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 335: header => [{col1 => 'Log-in Page Items',
336: col2 => '',},
337: {col1 => 'Log-in Help',
1.256 raeburn 338: col2 => 'Value'},
339: {col1 => 'Custom HTML in document head',
1.386 raeburn 340: col2 => 'Value'},
341: {col1 => 'SSO',
342: col2 => 'Dual login: SSO and non-SSO options'},
343: ],
1.230 raeburn 344: print => \&print_login,
345: modify => \&modify_login,
1.30 raeburn 346: },
1.43 raeburn 347: 'defaults' =>
1.236 raeburn 348: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 349: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 350: header => [{col1 => 'Setting',
1.236 raeburn 351: col2 => 'Value'},
352: {col1 => 'Institutional user types',
1.409 raeburn 353: col2 => 'Name displayed'},
354: {col1 => 'Mapping for missing usernames via standard log-in',
355: col2 => 'Rules in use'}],
1.230 raeburn 356: print => \&print_defaults,
357: modify => \&modify_defaults,
1.43 raeburn 358: },
1.381 raeburn 359: 'wafproxy' =>
360: { text => 'Web Application Firewall/Reverse Proxy',
1.373 raeburn 361: help => 'Domain_Configuration_WAF_Proxy',
1.381 raeburn 362: header => [{col1 => 'Domain(s)',
363: col2 => 'Servers and WAF/Reverse Proxy alias(es)',
1.373 raeburn 364: },
1.381 raeburn 365: {col1 => 'Domain(s)',
366: col2 => 'WAF Configuration',}],
1.373 raeburn 367: print => \&print_wafproxy,
1.381 raeburn 368: modify => \&modify_wafproxy,
1.373 raeburn 369: },
1.354 raeburn 370: 'passwords' =>
371: { text => 'Passwords (Internal authentication)',
372: help => 'Domain_Configuration_Passwords',
373: header => [{col1 => 'Resetting Forgotten Password',
374: col2 => 'Settings'},
375: {col1 => 'Encryption of Stored Passwords (Internal Auth)',
376: col2 => 'Settings'},
377: {col1 => 'Rules for LON-CAPA Passwords',
378: col2 => 'Settings'},
379: {col1 => 'Course Owner Changing Student Passwords',
380: col2 => 'Settings'}],
381: print => \&print_passwords,
382: modify => \&modify_passwords,
383: },
1.30 raeburn 384: 'quotas' =>
1.429 raeburn 385: { text => 'Blogs, personal pages/timezones, portfolio/quotas',
1.67 raeburn 386: help => 'Domain_Configuration_Quotas',
1.77 raeburn 387: header => [{col1 => 'User affiliation',
1.72 raeburn 388: col2 => 'Available tools',
1.435 raeburn 389: col3 => 'Portfolio quota (MB)',}],
1.230 raeburn 390: print => \&print_quotas,
391: modify => \&modify_quotas,
1.30 raeburn 392: },
393: 'autoenroll' =>
394: { text => 'Auto-enrollment settings',
1.67 raeburn 395: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 396: header => [{col1 => 'Configuration setting',
397: col2 => 'Value(s)'}],
1.230 raeburn 398: print => \&print_autoenroll,
399: modify => \&modify_autoenroll,
1.30 raeburn 400: },
401: 'autoupdate' =>
402: { text => 'Auto-update settings',
1.67 raeburn 403: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 404: header => [{col1 => 'Setting',
405: col2 => 'Value',},
1.131 raeburn 406: {col1 => 'Setting',
407: col2 => 'Affiliation'},
1.43 raeburn 408: {col1 => 'User population',
1.227 bisitz 409: col2 => 'Updatable user data'}],
1.230 raeburn 410: print => \&print_autoupdate,
411: modify => \&modify_autoupdate,
1.30 raeburn 412: },
1.125 raeburn 413: 'autocreate' =>
414: { text => 'Auto-course creation settings',
415: help => 'Domain_Configuration_Auto_Creation',
416: header => [{col1 => 'Configuration Setting',
417: col2 => 'Value',}],
1.230 raeburn 418: print => \&print_autocreate,
419: modify => \&modify_autocreate,
1.125 raeburn 420: },
1.30 raeburn 421: 'directorysrch' =>
1.277 raeburn 422: { text => 'Directory searches',
1.67 raeburn 423: help => 'Domain_Configuration_InstDirectory_Search',
1.277 raeburn 424: header => [{col1 => 'Institutional Directory Setting',
425: col2 => 'Value',},
426: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 427: col2 => 'Value',}],
1.230 raeburn 428: print => \&print_directorysrch,
429: modify => \&modify_directorysrch,
1.30 raeburn 430: },
431: 'contacts' =>
1.286 raeburn 432: { text => 'E-mail addresses and helpform',
1.67 raeburn 433: help => 'Domain_Configuration_Contact_Info',
1.286 raeburn 434: header => [{col1 => 'Default e-mail addresses',
435: col2 => 'Value',},
436: {col1 => 'Recipient(s) for notifications',
437: col2 => 'Value',},
1.340 raeburn 438: {col1 => 'Nightly status check e-mail',
439: col2 => 'Settings',},
1.286 raeburn 440: {col1 => 'Ask helpdesk form settings',
441: col2 => 'Value',},],
1.230 raeburn 442: print => \&print_contacts,
443: modify => \&modify_contacts,
1.30 raeburn 444: },
445: 'usercreation' =>
446: { text => 'User creation',
1.67 raeburn 447: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 448: header => [{col1 => 'Format rule type',
449: col2 => 'Format rules in force'},
1.34 raeburn 450: {col1 => 'User account creation',
451: col2 => 'Usernames which may be created',},
1.30 raeburn 452: {col1 => 'Context',
1.43 raeburn 453: col2 => 'Assignable authentication types'}],
1.230 raeburn 454: print => \&print_usercreation,
455: modify => \&modify_usercreation,
1.30 raeburn 456: },
1.224 raeburn 457: 'selfcreation' =>
458: { text => 'Users self-creating accounts',
459: help => 'Domain_Configuration_Self_Creation',
460: header => [{col1 => 'Self-creation with institutional username',
461: col2 => 'Enabled?'},
462: {col1 => 'Institutional user type (login/SSO self-creation)',
463: col2 => 'Information user can enter'},
1.303 raeburn 464: {col1 => 'Self-creation with e-mail verification',
1.224 raeburn 465: col2 => 'Settings'}],
1.230 raeburn 466: print => \&print_selfcreation,
467: modify => \&modify_selfcreation,
1.224 raeburn 468: },
1.69 raeburn 469: 'usermodification' =>
1.33 raeburn 470: { text => 'User modification',
1.67 raeburn 471: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 472: header => [{col1 => 'Target user has role',
1.227 bisitz 473: col2 => 'User information updatable in author context'},
1.33 raeburn 474: {col1 => 'Target user has role',
1.227 bisitz 475: col2 => 'User information updatable in course context'}],
1.230 raeburn 476: print => \&print_usermodification,
477: modify => \&modify_usermodification,
1.33 raeburn 478: },
1.69 raeburn 479: 'scantron' =>
1.346 raeburn 480: { text => 'Bubblesheet format',
1.67 raeburn 481: help => 'Domain_Configuration_Scantron_Format',
1.346 raeburn 482: header => [ {col1 => 'Bubblesheet format file',
483: col2 => ''},
484: {col1 => 'Bubblesheet data upload formats',
485: col2 => 'Settings'}],
1.230 raeburn 486: print => \&print_scantron,
487: modify => \&modify_scantron,
1.46 raeburn 488: },
1.86 raeburn 489: 'requestcourses' =>
490: {text => 'Request creation of courses',
491: help => 'Domain_Configuration_Request_Courses',
492: header => [{col1 => 'User affiliation',
1.102 raeburn 493: col2 => 'Availability/Processing of requests',},
494: {col1 => 'Setting',
1.216 raeburn 495: col2 => 'Value'},
496: {col1 => 'Available textbooks',
1.235 raeburn 497: col2 => ''},
1.242 raeburn 498: {col1 => 'Available templates',
499: col2 => ''},
1.235 raeburn 500: {col1 => 'Validation (not official courses)',
501: col2 => 'Value'},],
1.230 raeburn 502: print => \&print_quotas,
503: modify => \&modify_quotas,
1.86 raeburn 504: },
1.163 raeburn 505: 'requestauthor' =>
1.223 bisitz 506: {text => 'Request Authoring Space',
1.163 raeburn 507: help => 'Domain_Configuration_Request_Author',
508: header => [{col1 => 'User affiliation',
509: col2 => 'Availability/Processing of requests',},
510: {col1 => 'Setting',
511: col2 => 'Value'}],
1.230 raeburn 512: print => \&print_quotas,
513: modify => \&modify_quotas,
1.163 raeburn 514: },
1.69 raeburn 515: 'coursecategories' =>
1.120 raeburn 516: { text => 'Cataloging of courses/communities',
1.67 raeburn 517: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 518: header => [{col1 => 'Catalog type/availability',
519: col2 => '',},
520: {col1 => 'Category settings for standard catalog',
1.57 raeburn 521: col2 => '',},
522: {col1 => 'Categories',
523: col2 => '',
524: }],
1.230 raeburn 525: print => \&print_coursecategories,
526: modify => \&modify_coursecategories,
1.69 raeburn 527: },
528: 'serverstatuses' =>
1.77 raeburn 529: {text => 'Access to server status pages',
1.69 raeburn 530: help => 'Domain_Configuration_Server_Status',
531: header => [{col1 => 'Status Page',
532: col2 => 'Other named users',
533: col3 => 'Specific IPs',
534: }],
1.230 raeburn 535: print => \&print_serverstatuses,
536: modify => \&modify_serverstatuses,
1.69 raeburn 537: },
1.118 jms 538: 'helpsettings' =>
1.282 raeburn 539: {text => 'Support settings',
1.118 jms 540: help => 'Domain_Configuration_Help_Settings',
1.282 raeburn 541: header => [{col1 => 'Help Page Settings (logged-in users)',
542: col2 => 'Value'},
543: {col1 => 'Helpdesk Roles',
544: col2 => 'Settings'},],
1.230 raeburn 545: print => \&print_helpsettings,
546: modify => \&modify_helpsettings,
1.118 jms 547: },
1.121 raeburn 548: 'coursedefaults' =>
549: {text => 'Course/Community defaults',
550: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 551: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
552: col2 => 'Value',},
553: {col1 => 'Defaults which can be overridden for each course by a DC',
554: col2 => 'Value',},],
1.230 raeburn 555: print => \&print_coursedefaults,
556: modify => \&modify_coursedefaults,
1.121 raeburn 557: },
1.231 raeburn 558: 'selfenrollment' =>
559: {text => 'Self-enrollment in Course/Community',
560: help => 'Domain_Configuration_Selfenrollment',
561: header => [{col1 => 'Configuration Rights',
562: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
563: {col1 => 'Defaults',
564: col2 => 'Value'},
565: {col1 => 'Self-enrollment validation (optional)',
566: col2 => 'Value'},],
567: print => \&print_selfenrollment,
568: modify => \&modify_selfenrollment,
569: },
1.120 raeburn 570: 'privacy' =>
1.427 raeburn 571: {text => 'Role assignments and user privacy',
1.120 raeburn 572: help => 'Domain_Configuration_User_Privacy',
1.357 raeburn 573: header => [{col1 => 'Role assigned in different domain',
574: col2 => 'Approval options'},
575: {col1 => 'Role assigned in different domain to user of type',
576: col2 => 'User information available in that domain'},
577: {col1 => "Role assigned in user's domain",
578: col2 => 'Information viewable by privileged user'},
579: {col1 => "Role assigned in user's domain",
580: col2 => 'Information viewable by unprivileged user'}],
1.230 raeburn 581: print => \&print_privacy,
582: modify => \&modify_privacy,
1.120 raeburn 583: },
1.141 raeburn 584: 'usersessions' =>
1.145 raeburn 585: {text => 'User session hosting/offloading',
1.137 raeburn 586: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 587: header => [{col1 => 'Domain server',
588: col2 => 'Servers to offload sessions to when busy'},
589: {col1 => 'Hosting of users from other domains',
1.137 raeburn 590: col2 => 'Rules'},
591: {col1 => "Hosting domain's own users elsewhere",
592: col2 => 'Rules'}],
1.230 raeburn 593: print => \&print_usersessions,
594: modify => \&modify_usersessions,
1.137 raeburn 595: },
1.279 raeburn 596: 'loadbalancing' =>
1.185 raeburn 597: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 598: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 599: header => [{col1 => 'Balancers',
1.150 raeburn 600: col2 => 'Default destinations',
1.183 bisitz 601: col3 => 'User affiliation',
1.150 raeburn 602: col4 => 'Overrides'},
603: ],
1.230 raeburn 604: print => \&print_loadbalancing,
605: modify => \&modify_loadbalancing,
1.150 raeburn 606: },
1.425 raeburn 607: 'ltitools' =>
1.267 raeburn 608: {text => 'External Tools (LTI)',
1.296 raeburn 609: help => 'Domain_Configuration_LTI_Tools',
1.421 raeburn 610: header => [{col1 => 'Encryption of shared secrets',
611: col2 => 'Settings'},
612: {col1 => 'Rules for shared secrets',
613: col2 => 'Settings'},
614: {col1 => 'Providers',
615: col2 => 'Settings',}],
1.267 raeburn 616: print => \&print_ltitools,
617: modify => \&modify_ltitools,
618: },
1.372 raeburn 619: 'proctoring' =>
620: {text => 'Remote Proctoring Integration',
621: help => 'Domain_Configuration_Proctoring',
622: header => [{col1 => 'Name',
623: col2 => 'Configuration'}],
624: print => \&print_proctoring,
625: modify => \&modify_proctoring,
626: },
1.279 raeburn 627: 'ssl' =>
1.275 raeburn 628: {text => 'LON-CAPA Network (SSL)',
629: help => 'Domain_Configuration_Network_SSL',
630: header => [{col1 => 'Server',
631: col2 => 'Certificate Status'},
632: {col1 => 'Connections to other servers',
633: col2 => 'Rules'},
1.293 raeburn 634: {col1 => 'Connections from other servers',
635: col2 => 'Rules'},
1.275 raeburn 636: {col1 => "Replicating domain's published content",
637: col2 => 'Rules'}],
638: print => \&print_ssl,
639: modify => \&modify_ssl,
640: },
1.279 raeburn 641: 'trust' =>
642: {text => 'Trust Settings',
643: help => 'Domain_Configuration_Trust',
644: header => [{col1 => "Access to this domain's content by others",
645: col2 => 'Rules'},
646: {col1 => "Access to other domain's content by this domain",
647: col2 => 'Rules'},
648: {col1 => "Enrollment in this domain's courses by others",
649: col2 => 'Rules',},
650: {col1 => "Co-author roles in this domain for others",
651: col2 => 'Rules',},
652: {col1 => "Co-author roles for this domain's users elsewhere",
653: col2 => 'Rules',},
654: {col1 => "Domain roles in this domain assignable to others",
655: col2 => 'Rules'},
656: {col1 => "Course catalog for this domain displayed elsewhere",
657: col2 => 'Rules'},
658: {col1 => "Requests for creation of courses in this domain by others",
659: col2 => 'Rules'},
660: {col1 => "Users in other domains can send messages to this domain",
661: col2 => 'Rules'},],
662: print => \&print_trust,
663: modify => \&modify_trust,
664: },
1.425 raeburn 665: 'lti' =>
1.405 raeburn 666: {text => 'LTI Link Protection and LTI Consumers',
1.320 raeburn 667: help => 'Domain_Configuration_LTI_Provider',
1.405 raeburn 668: header => [{col1 => 'Encryption of shared secrets',
669: col2 => 'Settings'},
1.425 raeburn 670: {col1 => 'Rules for shared secrets',
1.405 raeburn 671: col2 => 'Settings'},
1.434 raeburn 672: {col1 => 'Link Protectors in Courses',
1.436 raeburn 673: col2 => 'Values'},
1.406 raeburn 674: {col1 => 'Link Protectors',
1.405 raeburn 675: col2 => 'Settings'},
676: {col1 => 'Consumers',
677: col2 => 'Settings'},],
1.320 raeburn 678: print => \&print_lti,
679: modify => \&modify_lti,
680: },
1.425 raeburn 681: 'ipaccess' =>
1.394 raeburn 682: {text => 'IP-based access control',
683: help => 'Domain_Configuration_IP_Access',
684: header => [{col1 => 'Setting',
685: col2 => 'Value'},],
686: print => \&print_ipaccess,
687: modify => \&modify_ipaccess,
688: },
1.436 raeburn 689: 'authordefaults' =>
1.429 raeburn 690: {text => 'Authoring Space defaults',
691: help => 'Domain_Configuration_Author_Defaults',
692: header => [{col1 => 'Defaults which can be overridden by Author',
693: col2 => 'Settings',},
694: {col1 => 'Defaults which can be overridden by a Dom. Coord.',
695: col2 => 'Settings',},],
696: print => \&print_authordefaults,
697: modify => \&modify_authordefaults,
698: },
1.3 raeburn 699: );
1.110 raeburn 700: if (keys(%servers) > 1) {
701: $prefs{'login'} = { text => 'Log-in page options',
702: help => 'Domain_Configuration_Login_Page',
703: header => [{col1 => 'Log-in Service',
704: col2 => 'Server Setting',},
705: {col1 => 'Log-in Page Items',
1.405 raeburn 706: col2 => 'Settings'},
1.168 raeburn 707: {col1 => 'Log-in Help',
1.256 raeburn 708: col2 => 'Value'},
709: {col1 => 'Custom HTML in document head',
1.386 raeburn 710: col2 => 'Value'},
711: {col1 => 'SSO',
712: col2 => 'Dual login: SSO and non-SSO options'},
713: ],
1.230 raeburn 714: print => \&print_login,
715: modify => \&modify_login,
1.110 raeburn 716: };
717: }
1.174 foxr 718:
1.6 raeburn 719: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 720: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 721: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 722: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 723: text=>"Settings to display/modify"});
1.9 raeburn 724: my $confname = $dom.'-domainconfig';
1.174 foxr 725:
1.3 raeburn 726: if ($phase eq 'process') {
1.212 raeburn 727: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
728: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 729: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 730: $r->rflush();
1.212 raeburn 731: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 732: }
1.30 raeburn 733: } elsif ($phase eq 'display') {
1.192 raeburn 734: my $js = &recaptcha_js().
1.236 raeburn 735: &toggle_display_js();
1.171 raeburn 736: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 737: my ($othertitle,$usertypes,$types) =
738: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 739: $js .= &lonbalance_targets_js($dom,$types,\%servers,
740: $domconfig{'loadbalancing'}).
1.170 raeburn 741: &new_spares_js().
742: &common_domprefs_js().
743: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 744: }
1.216 raeburn 745: if (grep(/^requestcourses$/,@actions)) {
746: my $javascript_validations;
747: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
748: $js .= <<END;
749: <script type="text/javascript">
750: $javascript_validations
751: </script>
752: $coursebrowserjs
753: END
1.394 raeburn 754: } elsif (grep(/^ipaccess$/,@actions)) {
755: $js .= &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
1.216 raeburn 756: }
1.305 raeburn 757: if (grep(/^selfcreation$/,@actions)) {
758: $js .= &selfcreate_javascript();
759: }
1.286 raeburn 760: if (grep(/^contacts$/,@actions)) {
761: $js .= &contacts_javascript();
762: }
1.346 raeburn 763: if (grep(/^scantron$/,@actions)) {
764: $js .= &scantron_javascript();
765: }
1.150 raeburn 766: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 767: } else {
1.180 raeburn 768: # check if domconfig user exists for the domain.
769: my $servadm = $r->dir_config('lonAdmEMail');
770: my ($configuserok,$author_ok,$switchserver) =
771: &config_check($dom,$confname,$servadm);
772: unless ($configuserok eq 'ok') {
1.181 raeburn 773: &Apache::lonconfigsettings::print_header($r,$phase,$context);
774: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 775: $confname).
1.181 raeburn 776: '<br />'
777: );
1.180 raeburn 778: if ($switchserver) {
1.181 raeburn 779: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
780: '<br />'.
781: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
782: '<br />'.
783: &mt('The "[_1]" user can be created automatically when a Domain Coordinator visits the web-based "Set domain configuration" screen, in a session hosted on the primary library server.',$confname).
784: '<br />'.
785: &mt('To do that now, use the following link: [_1]',$switchserver)
786: );
787: } else {
788: $r->print(&mt('To create that user from the command line run the ./UPDATE script found in the top level directory of the extracted LON-CAPA tarball.').
789: '<br />'.
790: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
791: );
1.180 raeburn 792: }
793: $r->print(&Apache::loncommon::end_page());
794: return OK;
795: }
1.21 raeburn 796: if (keys(%domconfig) == 0) {
797: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 798: my @ids=&Apache::lonnet::current_machine_ids();
799: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 800: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 801: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 802: my $custom_img_count = 0;
803: foreach my $img (@loginimages) {
804: if ($designhash{$dom.'.login.'.$img} ne '') {
805: $custom_img_count ++;
806: }
807: }
808: foreach my $role (@roles) {
809: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
810: $custom_img_count ++;
811: }
812: }
813: if ($custom_img_count > 0) {
1.94 raeburn 814: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 815: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 816: $r->print(
817: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
818: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
819: &mt("Thereafter, (with a Domain Coordinator role selected in the domain) you will be able to update settings when logged in to any server in the LON-CAPA network.").'<br />'.
820: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
821: if ($switch_server) {
1.30 raeburn 822: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 823: }
1.91 raeburn 824: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 825: return OK;
826: }
827: }
828: }
1.91 raeburn 829: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 830: }
831: return OK;
832: }
833:
834: sub process_changes {
1.205 raeburn 835: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 836: my %domconfig;
837: if (ref($values) eq 'HASH') {
838: %domconfig = %{$values};
839: }
1.3 raeburn 840: my $output;
841: if ($action eq 'login') {
1.205 raeburn 842: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 843: } elsif ($action eq 'rolecolors') {
1.9 raeburn 844: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 845: $lastactref,%domconfig);
1.3 raeburn 846: } elsif ($action eq 'quotas') {
1.216 raeburn 847: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 848: } elsif ($action eq 'autoenroll') {
1.205 raeburn 849: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 850: } elsif ($action eq 'autoupdate') {
851: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 852: } elsif ($action eq 'autocreate') {
853: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 854: } elsif ($action eq 'directorysrch') {
1.295 raeburn 855: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 856: } elsif ($action eq 'usercreation') {
1.28 raeburn 857: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 858: } elsif ($action eq 'selfcreation') {
1.305 raeburn 859: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 860: } elsif ($action eq 'usermodification') {
861: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 862: } elsif ($action eq 'contacts') {
1.205 raeburn 863: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 864: } elsif ($action eq 'defaults') {
1.212 raeburn 865: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 866: } elsif ($action eq 'scantron') {
1.205 raeburn 867: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 868: } elsif ($action eq 'coursecategories') {
1.239 raeburn 869: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 870: } elsif ($action eq 'serverstatuses') {
871: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 872: } elsif ($action eq 'requestcourses') {
1.216 raeburn 873: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 874: } elsif ($action eq 'requestauthor') {
1.216 raeburn 875: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 876: } elsif ($action eq 'helpsettings') {
1.285 raeburn 877: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 878: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 879: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 880: } elsif ($action eq 'selfenrollment') {
881: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 882: } elsif ($action eq 'usersessions') {
1.212 raeburn 883: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 884: } elsif ($action eq 'loadbalancing') {
885: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 886: } elsif ($action eq 'ltitools') {
887: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.372 raeburn 888: } elsif ($action eq 'proctoring') {
889: $output = &modify_proctoring($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 890: } elsif ($action eq 'ssl') {
891: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 892: } elsif ($action eq 'trust') {
893: $output = &modify_trust($dom,$lastactref,%domconfig);
1.320 raeburn 894: } elsif ($action eq 'lti') {
895: $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.357 raeburn 896: } elsif ($action eq 'privacy') {
1.427 raeburn 897: $output = &modify_privacy($dom,$lastactref,%domconfig);
1.354 raeburn 898: } elsif ($action eq 'passwords') {
899: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.373 raeburn 900: } elsif ($action eq 'wafproxy') {
901: $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
1.394 raeburn 902: } elsif ($action eq 'ipaccess') {
903: $output = &modify_ipaccess($dom,$lastactref,%domconfig);
1.429 raeburn 904: } elsif ($action eq 'authordefaults') {
905: $output = &modify_authordefaults($dom,$lastactref,%domconfig);
1.3 raeburn 906: }
907: return $output;
908: }
909:
910: sub print_config_box {
1.9 raeburn 911: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 912: my $rowtotal = 0;
1.49 raeburn 913: my $output;
914: if ($action eq 'coursecategories') {
915: $output = &coursecategories_javascript($settings);
1.236 raeburn 916: } elsif ($action eq 'defaults') {
917: $output = &defaults_javascript($settings);
1.354 raeburn 918: } elsif ($action eq 'passwords') {
1.405 raeburn 919: $output = &passwords_javascript($action);
1.282 raeburn 920: } elsif ($action eq 'helpsettings') {
921: my (%privs,%levelscurrent);
922: my %full=();
923: my %levels=(
924: course => {},
925: domain => {},
926: system => {},
927: );
928: my $context = 'domain';
929: my $crstype = 'Course';
930: my $formname = 'display';
931: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
932: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
933: $output =
1.425 raeburn 934: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
1.282 raeburn 935: \@templateroles);
1.334 raeburn 936: } elsif ($action eq 'ltitools') {
1.421 raeburn 937: $output .= &Apache::lonconfigsettings::ltitools_javascript($settings);
1.334 raeburn 938: } elsif ($action eq 'lti') {
1.421 raeburn 939: $output .= &passwords_javascript('ltisecrets')."\n".
1.405 raeburn 940: <i_javascript($dom,$settings);
1.372 raeburn 941: } elsif ($action eq 'proctoring') {
942: $output .= &proctoring_javascript($settings);
1.381 raeburn 943: } elsif ($action eq 'wafproxy') {
944: $output .= &wafproxy_javascript($dom);
1.385 raeburn 945: } elsif ($action eq 'autoupdate') {
946: $output .= &autoupdate_javascript();
1.399 raeburn 947: } elsif ($action eq 'autoenroll') {
948: $output .= &autoenroll_javascript();
1.386 raeburn 949: } elsif ($action eq 'login') {
950: $output .= &saml_javascript();
1.394 raeburn 951: } elsif ($action eq 'ipaccess') {
952: $output .= &ipaccess_javascript($settings);
1.429 raeburn 953: } elsif ($action eq 'authordefaults') {
954: $output .= &authordefaults_javascript();
1.91 raeburn 955: }
1.236 raeburn 956: $output .=
1.30 raeburn 957: '<table class="LC_nested_outer">
1.3 raeburn 958: <tr>
1.306 raeburn 959: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 960: &mt($item->{text}).' '.
961: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
962: '</tr>';
1.30 raeburn 963: $rowtotal ++;
1.110 raeburn 964: my $numheaders = 1;
965: if (ref($item->{'header'}) eq 'ARRAY') {
966: $numheaders = scalar(@{$item->{'header'}});
967: }
968: if ($numheaders > 1) {
1.64 raeburn 969: my $colspan = '';
1.145 raeburn 970: my $rightcolspan = '';
1.369 raeburn 971: my $leftnobr = '';
1.238 raeburn 972: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 973: ($action eq 'directorysrch') ||
1.386 raeburn 974: (($action eq 'login') && ($numheaders < 5))) {
1.64 raeburn 975: $colspan = ' colspan="2"';
976: }
1.145 raeburn 977: if ($action eq 'usersessions') {
978: $rightcolspan = ' colspan="3"';
979: }
1.369 raeburn 980: if ($action eq 'passwords') {
981: $leftnobr = ' LC_nobreak';
982: }
1.30 raeburn 983: $output .= '
1.3 raeburn 984: <tr>
985: <td>
986: <table class="LC_nested">
987: <tr class="LC_info_row">
1.369 raeburn 988: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 989: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 990: </tr>';
1.69 raeburn 991: $rowtotal ++;
1.230 raeburn 992: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 993: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 994: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 995: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
1.421 raeburn 996: ($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'wafproxy') ||
1.429 raeburn 997: ($action eq 'lti') || ($action eq 'ltitools') || ($action eq 'authordefaults')) {
1.230 raeburn 998: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.354 raeburn 999: } elsif ($action eq 'passwords') {
1000: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 1001: } elsif ($action eq 'coursecategories') {
1.230 raeburn 1002: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.346 raeburn 1003: } elsif ($action eq 'scantron') {
1004: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 1005: } elsif ($action eq 'login') {
1.386 raeburn 1006: if ($numheaders == 5) {
1.168 raeburn 1007: $colspan = ' colspan="2"';
1008: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
1009: } else {
1010: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
1011: }
1.230 raeburn 1012: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 1013: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 1014: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1015: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 1016: }
1.30 raeburn 1017: $output .= '
1.6 raeburn 1018: </table>
1019: </td>
1020: </tr>
1021: <tr>
1022: <td>
1023: <table class="LC_nested">
1024: <tr class="LC_info_row">
1.230 raeburn 1025: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 1026: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 1027: </tr>';
1028: $rowtotal ++;
1.230 raeburn 1029: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
1030: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 1031: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.409 raeburn 1032: ($action eq 'trust') || ($action eq 'contacts') || ($action eq 'defaults') ||
1.421 raeburn 1033: ($action eq 'privacy') || ($action eq 'passwords') || ($action eq 'lti') ||
1034: ($action eq 'ltitools')) {
1.238 raeburn 1035: if ($action eq 'coursecategories') {
1036: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
1037: $colspan = ' colspan="2"';
1.279 raeburn 1038: } elsif ($action eq 'trust') {
1039: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.354 raeburn 1040: } elsif ($action eq 'passwords') {
1041: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.434 raeburn 1042: } elsif ($action eq 'lti') {
1043: $output .= $item->{'print'}->('upper',$dom,$settings,\$rowtotal).'
1044: </table>
1045: </td>
1046: </tr>
1047: <tr>
1048: <td>
1049: <table class="LC_nested">
1050: <tr class="LC_info_row">
1051: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1052: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1053: </tr>'."\n".
1054: $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
1.238 raeburn 1055: } else {
1056: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
1057: }
1.279 raeburn 1058: if ($action eq 'trust') {
1059: $output .= '
1060: </table>
1061: </td>
1062: </tr>';
1063: my @trusthdrs = qw(2 3 4 5 6 7);
1064: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
1065: for (my $i=0; $i<@trusthdrs; $i++) {
1066: $output .= '
1067: <tr>
1068: <td>
1069: <table class="LC_nested">
1070: <tr class="LC_info_row">
1071: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
1072: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
1073: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
1074: </table>
1075: </td>
1076: </tr>';
1077: }
1078: $output .= '
1079: <tr>
1080: <td>
1081: <table class="LC_nested">
1082: <tr class="LC_info_row">
1083: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
1084: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
1085: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1086: } else {
1.434 raeburn 1087: my $hdridx = 2;
1088: if ($action eq 'lti') {
1089: $hdridx = 3;
1090: }
1.279 raeburn 1091: $output .= '
1.63 raeburn 1092: </table>
1093: </td>
1094: </tr>
1095: <tr>
1096: <td>
1097: <table class="LC_nested">
1098: <tr class="LC_info_row">
1.434 raeburn 1099: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col1'}).'</td>
1100: <td class="LC_right_item">'.&mt($item->{'header'}->[$hdridx]->{'col2'}).'</td>
1.238 raeburn 1101: </tr>'."\n";
1.279 raeburn 1102: if ($action eq 'coursecategories') {
1103: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.405 raeburn 1104: } elsif (($action eq 'contacts') || ($action eq 'privacy') ||
1105: ($action eq 'passwords') || ($action eq 'lti')) {
1.354 raeburn 1106: if ($action eq 'passwords') {
1107: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
1108: } else {
1109: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
1110: }
1.434 raeburn 1111: $hdridx ++;
1.354 raeburn 1112: $output .= '
1.340 raeburn 1113: </tr>
1114: </table>
1115: </td>
1116: </tr>
1117: <tr>
1118: <td>
1119: <table class="LC_nested">
1120: <tr class="LC_info_row">
1.434 raeburn 1121: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col1'}).'</td>
1122: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col2'}).'</td></tr>'."\n";
1.354 raeburn 1123: if ($action eq 'passwords') {
1124: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
1125: } else {
1126: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1127: }
1128: $output .= '
1.340 raeburn 1129: </table>
1130: </td>
1131: </tr>
1132: <tr>';
1.279 raeburn 1133: } else {
1134: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1135: }
1.238 raeburn 1136: }
1.63 raeburn 1137: $rowtotal ++;
1.236 raeburn 1138: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.409 raeburn 1139: ($action eq 'directorysrch') || ($action eq 'helpsettings') ||
1.429 raeburn 1140: ($action eq 'wafproxy') || ($action eq 'authordefaults')) {
1.230 raeburn 1141: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.346 raeburn 1142: } elsif ($action eq 'scantron') {
1143: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.293 raeburn 1144: } elsif ($action eq 'ssl') {
1145: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
1146: </table>
1147: </td>
1148: </tr>
1149: <tr>
1150: <td>
1151: <table class="LC_nested">
1152: <tr class="LC_info_row">
1153: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1154: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1155: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
1156: </table>
1157: </td>
1158: </tr>
1159: <tr>
1160: <td>
1161: <table class="LC_nested">
1162: <tr class="LC_info_row">
1163: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1164: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
1165: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 1166: } elsif ($action eq 'login') {
1.386 raeburn 1167: if ($numheaders == 5) {
1.168 raeburn 1168: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
1169: </table>
1170: </td>
1171: </tr>
1172: <tr>
1173: <td>
1174: <table class="LC_nested">
1175: <tr class="LC_info_row">
1176: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 1177: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 1178: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1179: $rowtotal ++;
1180: } else {
1181: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1182: }
1.256 raeburn 1183: $output .= '
1184: </table>
1185: </td>
1186: </tr>
1187: <tr>
1188: <td>
1189: <table class="LC_nested">
1190: <tr class="LC_info_row">';
1.386 raeburn 1191: if ($numheaders == 5) {
1.256 raeburn 1192: $output .= '
1193: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1194: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1195: </tr>';
1196: } else {
1197: $output .= '
1198: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1199: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1200: </tr>';
1201: }
1202: $rowtotal ++;
1.386 raeburn 1203: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
1204: </table>
1205: </td>
1206: </tr>
1207: <tr>
1208: <td>
1209: <table class="LC_nested">
1210: <tr class="LC_info_row">';
1211: if ($numheaders == 5) {
1212: $output .= '
1213: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1214: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1215: </tr>';
1216: } else {
1217: $output .= '
1218: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1219: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1220: </tr>';
1221: }
1222: $rowtotal ++;
1223: $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 1224: } elsif ($action eq 'requestcourses') {
1.247 raeburn 1225: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1226: $rowtotal ++;
1227: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 1228: </table>
1229: </td>
1230: </tr>
1231: <tr>
1232: <td>
1233: <table class="LC_nested">
1234: <tr class="LC_info_row">
1235: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1236: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 1237: &textbookcourses_javascript($settings).
1238: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
1239: </table>
1240: </td>
1241: </tr>
1242: <tr>
1243: <td>
1244: <table class="LC_nested">
1245: <tr class="LC_info_row">
1246: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1247: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1248: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 1249: </table>
1250: </td>
1251: </tr>
1252: <tr>
1253: <td>
1254: <table class="LC_nested">
1255: <tr class="LC_info_row">
1.306 raeburn 1256: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1257: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 1258: </tr>'.
1259: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 1260: } elsif ($action eq 'requestauthor') {
1261: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 1262: $rowtotal ++;
1.122 jms 1263: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1264: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1265: </table>
1266: </td>
1267: </tr>
1268: <tr>
1269: <td>
1270: <table class="LC_nested">
1271: <tr class="LC_info_row">
1.306 raeburn 1272: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69 raeburn 1273: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306 raeburn 1274: <td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1275: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1276: </tr>'.
1.30 raeburn 1277: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1278: </table>
1279: </td>
1280: </tr>
1281: <tr>
1282: <td>
1283: <table class="LC_nested">
1284: <tr class="LC_info_row">
1.59 bisitz 1285: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1286: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1287: </tr>'.
1.30 raeburn 1288: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1289: $rowtotal += 2;
1.6 raeburn 1290: }
1.3 raeburn 1291: } else {
1.30 raeburn 1292: $output .= '
1.3 raeburn 1293: <tr>
1294: <td>
1295: <table class="LC_nested">
1.30 raeburn 1296: <tr class="LC_info_row">';
1.277 raeburn 1297: if ($action eq 'login') {
1.30 raeburn 1298: $output .= '
1.59 bisitz 1299: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1300: } elsif ($action eq 'serverstatuses') {
1301: $output .= '
1.306 raeburn 1302: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69 raeburn 1303: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1304:
1.6 raeburn 1305: } else {
1.30 raeburn 1306: $output .= '
1.306 raeburn 1307: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1308: }
1.72 raeburn 1309: if (defined($item->{'header'}->[0]->{'col3'})) {
1.306 raeburn 1310: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72 raeburn 1311: &mt($item->{'header'}->[0]->{'col2'});
1312: if ($action eq 'serverstatuses') {
1313: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1314: }
1.69 raeburn 1315: } else {
1.306 raeburn 1316: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1317: &mt($item->{'header'}->[0]->{'col2'});
1318: }
1319: $output .= '</td>';
1320: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1321: if (defined($item->{'header'}->[0]->{'col4'})) {
1.306 raeburn 1322: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150 raeburn 1323: &mt($item->{'header'}->[0]->{'col3'});
1324: } else {
1.306 raeburn 1325: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1326: &mt($item->{'header'}->[0]->{'col3'});
1327: }
1.69 raeburn 1328: if ($action eq 'serverstatuses') {
1329: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1330: }
1331: $output .= '</td>';
1.6 raeburn 1332: }
1.150 raeburn 1333: if ($item->{'header'}->[0]->{'col4'}) {
1.306 raeburn 1334: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1335: &mt($item->{'header'}->[0]->{'col4'});
1336: }
1.69 raeburn 1337: $output .= '</tr>';
1.48 raeburn 1338: $rowtotal ++;
1.168 raeburn 1339: if ($action eq 'quotas') {
1.86 raeburn 1340: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1341: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1342: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.421 raeburn 1343: ($action eq 'proctoring') || ($action eq 'ipaccess')) {
1.230 raeburn 1344: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1345: }
1.3 raeburn 1346: }
1.30 raeburn 1347: $output .= '
1.3 raeburn 1348: </table>
1349: </td>
1350: </tr>
1.30 raeburn 1351: </table><br />';
1352: return ($output,$rowtotal);
1.1 raeburn 1353: }
1354:
1.3 raeburn 1355: sub print_login {
1.168 raeburn 1356: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.386 raeburn 1357: my ($css_class,$datatable,$switchserver,%lt);
1.6 raeburn 1358: my %choices = &login_choices();
1.386 raeburn 1359: if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
1360: %lt = &login_file_options();
1361: $switchserver = &check_switchserver($dom,$confname);
1362: }
1.168 raeburn 1363: if ($caller eq 'service') {
1.149 raeburn 1364: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1365: my $choice = $choices{'disallowlogin'};
1366: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1367: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306 raeburn 1368: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1369: '<th>'.$choices{'server'}.'</th>'.
1370: '<th>'.$choices{'serverpath'}.'</th>'.
1371: '<th>'.$choices{'custompath'}.'</th>'.
1372: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1373: my %disallowed;
1374: if (ref($settings) eq 'HASH') {
1375: if (ref($settings->{'loginvia'}) eq 'HASH') {
1376: %disallowed = %{$settings->{'loginvia'}};
1377: }
1378: }
1379: foreach my $lonhost (sort(keys(%servers))) {
1380: my $direct = 'selected="selected"';
1.128 raeburn 1381: if (ref($disallowed{$lonhost}) eq 'HASH') {
1382: if ($disallowed{$lonhost}{'server'} ne '') {
1383: $direct = '';
1384: }
1.110 raeburn 1385: }
1.115 raeburn 1386: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1387: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1388: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1389: '</option>';
1.184 raeburn 1390: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1391: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1392: my $selected = '';
1.128 raeburn 1393: if (ref($disallowed{$lonhost}) eq 'HASH') {
1394: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1395: $selected = 'selected="selected"';
1396: }
1.110 raeburn 1397: }
1398: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1399: $servers{$hostid}.'</option>';
1400: }
1.128 raeburn 1401: $datatable .= '</select></td>'.
1402: '<td><select name="'.$lonhost.'_serverpath">';
1403: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1404: my $pathname = $path;
1405: if ($path eq 'custom') {
1406: $pathname = &mt('Custom Path').' ->';
1407: }
1408: my $selected = '';
1409: if (ref($disallowed{$lonhost}) eq 'HASH') {
1410: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1411: $selected = 'selected="selected"';
1412: }
1413: } elsif ($path eq '') {
1414: $selected = 'selected="selected"';
1415: }
1416: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1417: }
1418: $datatable .= '</select></td>';
1419: my ($custom,$exempt);
1420: if (ref($disallowed{$lonhost}) eq 'HASH') {
1421: $custom = $disallowed{$lonhost}{'custompath'};
1422: $exempt = $disallowed{$lonhost}{'exempt'};
1423: }
1424: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1425: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1426: '</tr>';
1.110 raeburn 1427: }
1428: $datatable .= '</table></td></tr>';
1429: return $datatable;
1.168 raeburn 1430: } elsif ($caller eq 'page') {
1431: my %defaultchecked = (
1432: 'coursecatalog' => 'on',
1.188 raeburn 1433: 'helpdesk' => 'on',
1.168 raeburn 1434: 'adminmail' => 'off',
1435: 'newuser' => 'off',
1436: );
1.188 raeburn 1437: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1438: my (%checkedon,%checkedoff);
1.42 raeburn 1439: foreach my $item (@toggles) {
1.168 raeburn 1440: if ($defaultchecked{$item} eq 'on') {
1441: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1442: $checkedoff{$item} = ' ';
1.168 raeburn 1443: } elsif ($defaultchecked{$item} eq 'off') {
1444: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1445: $checkedon{$item} = ' ';
1446: }
1.1 raeburn 1447: }
1.168 raeburn 1448: my @images = ('img','logo','domlogo','login');
1.402 raeburn 1449: my @alttext = ('img','logo','domlogo');
1.168 raeburn 1450: my @logintext = ('textcol','bgcol');
1451: my @bgs = ('pgbg','mainbg','sidebg');
1452: my @links = ('link','alink','vlink');
1453: my %designhash = &Apache::loncommon::get_domainconf($dom);
1454: my %defaultdesign = %Apache::loncommon::defaultdesign;
1455: my (%is_custom,%designs);
1456: my %defaults = (
1457: font => $defaultdesign{'login.font'},
1458: );
1.6 raeburn 1459: foreach my $item (@images) {
1.168 raeburn 1460: $defaults{$item} = $defaultdesign{'login.'.$item};
1461: $defaults{'showlogo'}{$item} = 1;
1462: }
1463: foreach my $item (@bgs) {
1464: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1465: }
1.41 raeburn 1466: foreach my $item (@logintext) {
1.168 raeburn 1467: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1468: }
1.168 raeburn 1469: foreach my $item (@links) {
1470: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1471: }
1.168 raeburn 1472: if (ref($settings) eq 'HASH') {
1473: foreach my $item (@toggles) {
1474: if ($settings->{$item} eq '1') {
1475: $checkedon{$item} = ' checked="checked" ';
1476: $checkedoff{$item} = ' ';
1477: } elsif ($settings->{$item} eq '0') {
1478: $checkedoff{$item} = ' checked="checked" ';
1479: $checkedon{$item} = ' ';
1480: }
1481: }
1482: foreach my $item (@images) {
1483: if (defined($settings->{$item})) {
1484: $designs{$item} = $settings->{$item};
1485: $is_custom{$item} = 1;
1486: }
1487: if (defined($settings->{'showlogo'}{$item})) {
1488: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1489: }
1490: }
1.402 raeburn 1491: foreach my $item (@alttext) {
1492: if (ref($settings->{'alttext'}) eq 'HASH') {
1493: if ($settings->{'alttext'}->{$item} ne '') {
1494: $designs{'alttext'}{$item} = $settings->{'alttext'}{$item};
1495: }
1496: }
1497: }
1.168 raeburn 1498: foreach my $item (@logintext) {
1499: if ($settings->{$item} ne '') {
1500: $designs{'logintext'}{$item} = $settings->{$item};
1501: $is_custom{$item} = 1;
1502: }
1503: }
1504: if ($settings->{'font'} ne '') {
1505: $designs{'font'} = $settings->{'font'};
1506: $is_custom{'font'} = 1;
1507: }
1508: foreach my $item (@bgs) {
1509: if ($settings->{$item} ne '') {
1510: $designs{'bgs'}{$item} = $settings->{$item};
1511: $is_custom{$item} = 1;
1512: }
1513: }
1514: foreach my $item (@links) {
1515: if ($settings->{$item} ne '') {
1516: $designs{'links'}{$item} = $settings->{$item};
1517: $is_custom{$item} = 1;
1518: }
1519: }
1520: } else {
1521: if ($designhash{$dom.'.login.font'} ne '') {
1522: $designs{'font'} = $designhash{$dom.'.login.font'};
1523: $is_custom{'font'} = 1;
1524: }
1525: foreach my $item (@images) {
1526: if ($designhash{$dom.'.login.'.$item} ne '') {
1527: $designs{$item} = $designhash{$dom.'.login.'.$item};
1528: $is_custom{$item} = 1;
1529: }
1530: }
1531: foreach my $item (@bgs) {
1532: if ($designhash{$dom.'.login.'.$item} ne '') {
1533: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1534: $is_custom{$item} = 1;
1535: }
1.6 raeburn 1536: }
1.168 raeburn 1537: foreach my $item (@links) {
1538: if ($designhash{$dom.'.login.'.$item} ne '') {
1539: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1540: $is_custom{$item} = 1;
1541: }
1.6 raeburn 1542: }
1543: }
1.168 raeburn 1544: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1545: logo => 'Institution Logo',
1546: domlogo => 'Domain Logo',
1547: login => 'Login box');
1548: my $itemcount = 1;
1549: foreach my $item (@toggles) {
1550: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1551: $datatable .=
1552: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1553: '</td><td>'.
1554: '<span class="LC_nobreak"><label><input type="radio" name="'.
1555: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1556: '</label> <label><input type="radio" name="'.$item.'"'.
1557: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1558: '</tr>';
1559: $itemcount ++;
1.6 raeburn 1560: }
1.168 raeburn 1561: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1562: $datatable .= '</tr></table></td></tr>';
1563: } elsif ($caller eq 'help') {
1.386 raeburn 1564: my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1.168 raeburn 1565: my $itemcount = 1;
1566: $defaulturl = '/adm/loginproblems.html';
1567: $defaulttype = 'default';
1568: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1569: my @currlangs;
1570: if (ref($settings) eq 'HASH') {
1571: if (ref($settings->{'helpurl'}) eq 'HASH') {
1572: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1573: next if ($settings->{'helpurl'}{$key} eq '');
1574: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1575: $type{$key} = 'custom';
1576: unless ($key eq 'nolang') {
1577: push(@currlangs,$key);
1578: }
1579: }
1580: } elsif ($settings->{'helpurl'} ne '') {
1581: $type{'nolang'} = 'custom';
1582: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1583: }
1584: }
1.168 raeburn 1585: foreach my $lang ('nolang',sort(@currlangs)) {
1586: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1587: $datatable .= '<tr'.$css_class.'>';
1588: if ($url{$lang} eq '') {
1589: $url{$lang} = $defaulturl;
1590: }
1591: if ($type{$lang} eq '') {
1592: $type{$lang} = $defaulttype;
1593: }
1594: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1595: if ($lang eq 'nolang') {
1596: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1597: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1598: } else {
1599: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1600: $langchoices{$lang},
1601: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1602: }
1603: $datatable .= '</span></td>'."\n".
1604: '<td class="LC_left_item">';
1605: if ($type{$lang} eq 'custom') {
1606: $datatable .= '<span class="LC_nobreak"><label>'.
1607: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1608: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1609: } else {
1610: $datatable .= $lt{'upl'};
1611: }
1612: $datatable .='<br />';
1613: if ($switchserver) {
1614: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1615: } else {
1616: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1617: }
1.168 raeburn 1618: $datatable .= '</td></tr>';
1619: $itemcount ++;
1.6 raeburn 1620: }
1.168 raeburn 1621: my @addlangs;
1622: foreach my $lang (sort(keys(%langchoices))) {
1623: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1624: push(@addlangs,$lang);
1625: }
1626: if (@addlangs > 0) {
1627: my %toadd;
1628: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1629: $toadd{''} = &mt('Select');
1630: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1631: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1632: &mt('Add log-in help page for a specific language:').' '.
1633: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1634: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1635: if ($switchserver) {
1636: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1637: } else {
1638: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1639: }
1.168 raeburn 1640: $datatable .= '</td></tr>';
1.169 raeburn 1641: $itemcount ++;
1.6 raeburn 1642: }
1.169 raeburn 1643: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1644: } elsif ($caller eq 'headtag') {
1645: my %domservers = &Apache::lonnet::get_servers($dom);
1646: my $choice = $choices{'headtag'};
1647: $css_class = ' class="LC_odd_row"';
1648: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306 raeburn 1649: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256 raeburn 1650: '<th>'.$choices{'current'}.'</th>'.
1651: '<th>'.$choices{'action'}.'</th>'.
1652: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1653: my (%currurls,%currexempt);
1654: if (ref($settings) eq 'HASH') {
1655: if (ref($settings->{'headtag'}) eq 'HASH') {
1656: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1657: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1658: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1659: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1660: }
1661: }
1662: }
1663: }
1664: foreach my $lonhost (sort(keys(%domservers))) {
1665: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1666: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1667: if ($currurls{$lonhost}) {
1668: $datatable .= '<td class="LC_right_item"><a href="'.
1669: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1670: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1671: '">'.$lt{'curr'}.'</a></td>'.
1672: '<td><span class="LC_nobreak"><label>'.
1673: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1674: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1675: } else {
1676: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1677: }
1678: $datatable .='<br />';
1679: if ($switchserver) {
1680: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1681: } else {
1682: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1683: }
1.330 raeburn 1684: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256 raeburn 1685: }
1686: $datatable .= '</table></td></tr>';
1.386 raeburn 1687: } elsif ($caller eq 'saml') {
1688: my %domservers = &Apache::lonnet::get_servers($dom);
1689: $datatable .= '<tr><td colspan="3" style="text-align: left">'.
1690: '<table><tr><th>'.$choices{'hostid'}.'</th>'.
1691: '<th>'.$choices{'samllanding'}.'</th>'.
1692: '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
1.412 raeburn 1693: my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso,%styleon,%styleoff);
1.386 raeburn 1694: foreach my $lonhost (keys(%domservers)) {
1695: $samlurl{$lonhost} = '/adm/sso';
1696: $styleon{$lonhost} = 'display:none';
1697: $styleoff{$lonhost} = '';
1698: }
1.411 raeburn 1699: if ((ref($settings) eq 'HASH') && (ref($settings->{'saml'}) eq 'HASH')) {
1.386 raeburn 1700: foreach my $lonhost (keys(%{$settings->{'saml'}})) {
1701: if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
1702: $saml{$lonhost} = 1;
1703: $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
1704: $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
1705: $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
1706: $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
1707: $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
1.412 raeburn 1708: $samlwindow{$lonhost} = $settings->{'saml'}{$lonhost}{'window'};
1.386 raeburn 1709: $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
1710: $styleon{$lonhost} = '';
1711: $styleoff{$lonhost} = 'display:none';
1712: } else {
1713: $styleon{$lonhost} = 'display:none';
1714: $styleoff{$lonhost} = '';
1715: }
1716: }
1717: }
1718: my $itemcount = 1;
1719: foreach my $lonhost (sort(keys(%domservers))) {
1720: my $samlon = ' ';
1721: my $samloff = ' checked="checked" ';
1722: if ($saml{$lonhost}) {
1723: $samlon = $samloff;
1724: $samloff = ' ';
1725: }
1.412 raeburn 1726: my $samlwinon = '';
1727: my $samlwinoff = ' checked="checked"';
1728: if ($samlwindow{$lonhost}) {
1729: $samlwinon = $samlwinoff;
1730: $samlwinoff = '';
1731: }
1.386 raeburn 1732: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1733: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
1734: '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
1735: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
1736: &mt('No').'</label>'.(' 'x2).
1737: '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
1738: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
1739: &mt('Yes').'</label></span></td>'.
1740: '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
1.412 raeburn 1741: '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th></tr>'.
1.386 raeburn 1742: '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
1.412 raeburn 1743: '<th>'.&mt('Alt Text').'</th></tr>'.
1744: '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="20" value="'.
1.386 raeburn 1745: $samltext{$lonhost}.'" /></td><td>';
1746: if ($samlimg{$lonhost}) {
1747: $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
1748: '<span class="LC_nobreak"><label>'.
1749: '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
1750: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1751: } else {
1752: $datatable .= $lt{'upl'};
1753: }
1754: $datatable .='<br />';
1755: if ($switchserver) {
1756: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1757: } else {
1758: $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
1759: }
1760: $datatable .= '</td>'.
1.412 raeburn 1761: '<td><input type="text" name="saml_alt_'.$lonhost.'" size="25" '.
1762: 'value="'.$samlalt{$lonhost}.'" /></td></tr></table><br />'.
1763: '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th><th align="center">'.
1764: '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
1765: '<tr><th>'.&mt('URL').'</th><th>'.&mt('Tool Tip').'</th>'.
1766: '<th>'.&mt('Pop-up if iframe').'</th><th>'.&mt('Text').'</th></tr>'.
1767: '<tr'.$css_class.'>'.
1768: '<td><input type="text" name="saml_url_'.$lonhost.'" size="30" '.
1.386 raeburn 1769: 'value="'.$samlurl{$lonhost}.'" /></td>'.
1.412 raeburn 1770: '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="20">'.
1.386 raeburn 1771: $samltitle{$lonhost}.'</textarea></td>'.
1.412 raeburn 1772: '<td><label><input type="radio" name="saml_window_'.$lonhost.'" value=""'.$samlwinoff.'>'.
1773: &mt('No').'</label>'.(' 'x2).'<label><input type="radio" '.
1774: 'name="saml_window_'.$lonhost.'" value="1"'.$samlwinon.'>'.&mt('Yes').'</label></td>'.
1775: '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="12" '.
1.386 raeburn 1776: 'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
1777: '</table></td>'.
1778: '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%"> </td></tr>';
1779: $itemcount ++;
1780: }
1781: $datatable .= '</table></td></tr>';
1.1 raeburn 1782: }
1.6 raeburn 1783: return $datatable;
1784: }
1785:
1786: sub login_choices {
1787: my %choices =
1788: &Apache::lonlocal::texthash (
1.116 bisitz 1789: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1790: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1791: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1792: disallowlogin => "Login page requests redirected",
1793: hostid => "Server",
1.128 raeburn 1794: server => "Redirect to:",
1795: serverpath => "Path",
1796: custompath => "Custom",
1797: exempt => "Exempt IP(s)",
1.110 raeburn 1798: directlogin => "No redirect",
1799: newuser => "Link to create a user account",
1800: img => "Header",
1801: logo => "Main Logo",
1802: domlogo => "Domain Logo",
1803: login => "Log-in Header",
1804: textcol => "Text color",
1805: bgcol => "Box color",
1806: bgs => "Background colors",
1807: links => "Link colors",
1808: font => "Font color",
1809: pgbg => "Header",
1810: mainbg => "Page",
1811: sidebg => "Login box",
1812: link => "Link",
1813: alink => "Active link",
1814: vlink => "Visited link",
1.256 raeburn 1815: headtag => "Custom markup",
1816: action => "Action",
1817: current => "Current",
1.386 raeburn 1818: samllanding => "Dual login?",
1819: samloptions => "Options",
1.402 raeburn 1820: alttext => "Alt text",
1.6 raeburn 1821: );
1822: return %choices;
1823: }
1824:
1.386 raeburn 1825: sub login_file_options {
1826: return &Apache::lonlocal::texthash(
1827: del => 'Delete?',
1828: rep => 'Replace:',
1829: upl => 'Upload:',
1830: curr => 'View contents',
1831: default => 'Default',
1832: custom => 'Custom',
1833: none => 'None',
1834: );
1835: }
1836:
1.394 raeburn 1837: sub print_ipaccess {
1838: my ($dom,$settings,$rowtotal) = @_;
1839: my $css_class;
1840: my $itemcount = 0;
1841: my $datatable;
1842: my %ordered;
1843: if (ref($settings) eq 'HASH') {
1844: foreach my $item (keys(%{$settings})) {
1845: if (ref($settings->{$item}) eq 'HASH') {
1846: my $num = $settings->{$item}{'order'};
1847: if ($num eq '') {
1848: $num = scalar(keys(%{$settings}));
1849: }
1850: $ordered{$num} = $item;
1851: }
1852: }
1853: }
1854: my $maxnum = scalar(keys(%ordered));
1855: if (keys(%ordered)) {
1856: my @items = sort { $a <=> $b } keys(%ordered);
1857: for (my $i=0; $i<@items; $i++) {
1858: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1859: my $item = $ordered{$items[$i]};
1860: my ($name,$ipranges,%commblocks,%courses);
1861: if (ref($settings->{$item}) eq 'HASH') {
1862: $name = $settings->{$item}->{'name'};
1863: $ipranges = $settings->{$item}->{'ip'};
1864: if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
1865: %commblocks = %{$settings->{$item}->{'commblocks'}};
1866: }
1867: if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
1868: %courses = %{$settings->{$item}->{'courses'}};
1869: }
1870: }
1871: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
1872: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1873: .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
1874: for (my $k=0; $k<=$maxnum; $k++) {
1875: my $vpos = $k+1;
1876: my $selstr;
1877: if ($k == $i) {
1878: $selstr = ' selected="selected" ';
1879: }
1880: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1881: }
1882: $datatable .= '</select>'.(' 'x2).
1883: '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
1884: &mt('Delete?').'</label></span></td>'.
1885: '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
1886: &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
1887: '</td></tr>';
1888: $itemcount ++;
1889: }
1890: }
1891: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1892: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
1893: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1894: '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
1895: '<select name="ipaccess_pos_add"'.$chgstr.'>';
1896: for (my $k=0; $k<$maxnum+1; $k++) {
1897: my $vpos = $k+1;
1898: my $selstr;
1899: if ($k == $maxnum) {
1900: $selstr = ' selected="selected" ';
1901: }
1902: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1903: }
1904: $datatable .= '</select> '."\n".
1905: '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1906: '<td colspan="2">'.
1907: &ipaccess_options('add',$itemcount,$dom).
1908: '</td>'."\n".
1909: '</tr>'."\n";
1910: $$rowtotal ++;
1911: return $datatable;
1912: }
1913:
1914: sub ipaccess_options {
1915: my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
1916: my (%currblocks,%currcourses,$output);
1917: if (ref($blocksref) eq 'HASH') {
1918: %currblocks = %{$blocksref};
1919: }
1920: if (ref($coursesref) eq 'HASH') {
1921: %currcourses = %{$coursesref};
1922: }
1923: $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
1924: '<span class="LC_nobreak">'.&mt('Name').': '.
1925: '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
1926: '</span></fieldset>'.
1927: '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
1928: &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
1929: &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
1930: '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
1931: $ipranges.'</textarea></fieldset>'.
1932: '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
1933: &blocker_checkboxes($num,$blocksref).'</fieldset>'.
1934: '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
1935: '<table>';
1936: foreach my $cid (sort(keys(%currcourses))) {
1937: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1938: $output .= '<tr><td><span class="LC_nobreak">'.
1939: '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
1940: &mt('Delete?').' <span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
1941: ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
1942: }
1943: $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').': '.
1944: '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
1945: &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
1946: '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
1947: '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
1948: '</span></td></tr></table>'."\n".
1949: '</fieldset>';
1950: return $output;
1951: }
1952:
1953: sub blocker_checkboxes {
1954: my ($num,$blocks) = @_;
1955: my ($typeorder,$types) = &commblocktype_text();
1956: my $numinrow = 6;
1957: my $output = '<table>';
1958: for (my $i=0; $i<@{$typeorder}; $i++) {
1959: my $block = $typeorder->[$i];
1960: my $blockstatus;
1961: if (ref($blocks) eq 'HASH') {
1962: if ($blocks->{$block} eq 'on') {
1963: $blockstatus = 'checked="checked"';
1964: }
1965: }
1966: my $rem = $i%($numinrow);
1967: if ($rem == 0) {
1968: if ($i > 0) {
1969: $output .= '</tr>';
1970: }
1971: $output .= '<tr>';
1972: }
1973: if ($i == scalar(@{$typeorder})-1) {
1974: my $colsleft = $numinrow-$rem;
1975: if ($colsleft > 1) {
1976: $output .= '<td colspan="'.$colsleft.'">';
1977: } else {
1978: $output .= '<td>';
1979: }
1980: } else {
1981: $output .= '<td>';
1982: }
1983: my $item = 'ipaccess_block_'.$num;
1984: if ($blockstatus) {
1985: $blockstatus = ' '.$blockstatus;
1986: }
1987: $output .= '<span class="LC_nobreak"><label>'."\n".
1988: '<input type="checkbox" name="'.$item.'"'.
1989: $blockstatus.' value="'.$block.'"'.' />'.
1990: $types->{$block}.'</label></span>'."\n".
1991: '<br /></td>';
1992: }
1993: $output .= '</tr></table>';
1994: return $output;
1995: }
1996:
1997: sub commblocktype_text {
1998: my %types = &Apache::lonlocal::texthash(
1999: 'com' => 'Messaging',
2000: 'chat' => 'Chat Room',
2001: 'boards' => 'Discussion',
2002: 'port' => 'Portfolio',
2003: 'groups' => 'Groups',
2004: 'blogs' => 'Blogs',
2005: 'about' => 'User Information',
2006: 'printout' => 'Printouts',
2007: 'passwd' => 'Change Password',
2008: 'grades' => 'Gradebook',
1.397 raeburn 2009: 'search' => 'Course search',
2010: 'wishlist' => 'Stored links',
2011: 'annotate' => 'Annotations',
1.394 raeburn 2012: );
1.397 raeburn 2013: my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','annotate','passwd'];
1.394 raeburn 2014: return ($typeorder,\%types);
2015: }
2016:
1.6 raeburn 2017: sub print_rolecolors {
1.30 raeburn 2018: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 2019: my %choices = &color_font_choices();
2020: my @bgs = ('pgbg','tabbg','sidebg');
2021: my @links = ('link','alink','vlink');
2022: my @images = ('img');
2023: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 2024: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 2025: my %defaultdesign = %Apache::loncommon::defaultdesign;
2026: my (%is_custom,%designs);
1.200 raeburn 2027: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 2028: if (ref($settings) eq 'HASH') {
2029: if (ref($settings->{$role}) eq 'HASH') {
2030: if ($settings->{$role}->{'img'} ne '') {
2031: $designs{'img'} = $settings->{$role}->{'img'};
2032: $is_custom{'img'} = 1;
2033: }
2034: if ($settings->{$role}->{'font'} ne '') {
2035: $designs{'font'} = $settings->{$role}->{'font'};
2036: $is_custom{'font'} = 1;
2037: }
1.97 tempelho 2038: if ($settings->{$role}->{'fontmenu'} ne '') {
2039: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
2040: $is_custom{'fontmenu'} = 1;
2041: }
1.6 raeburn 2042: foreach my $item (@bgs) {
2043: if ($settings->{$role}->{$item} ne '') {
2044: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
2045: $is_custom{$item} = 1;
2046: }
2047: }
2048: foreach my $item (@links) {
2049: if ($settings->{$role}->{$item} ne '') {
2050: $designs{'links'}{$item} = $settings->{$role}->{$item};
2051: $is_custom{$item} = 1;
2052: }
2053: }
2054: }
2055: } else {
2056: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
2057: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
2058: $is_custom{'img'} = 1;
2059: }
1.97 tempelho 2060: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
2061: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
2062: $is_custom{'fontmenu'} = 1;
2063: }
1.6 raeburn 2064: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
2065: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
2066: $is_custom{'font'} = 1;
2067: }
2068: foreach my $item (@bgs) {
2069: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
2070: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
2071: $is_custom{$item} = 1;
2072:
2073: }
2074: }
2075: foreach my $item (@links) {
2076: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
2077: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
2078: $is_custom{$item} = 1;
2079: }
2080: }
2081: }
2082: my $itemcount = 1;
1.30 raeburn 2083: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 2084: $datatable .= '</tr></table></td></tr>';
2085: return $datatable;
2086: }
2087:
1.200 raeburn 2088: sub role_defaults {
2089: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 2090: my %defaults;
2091: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 2092: return %defaults;
2093: }
2094: my %defaultdesign = %Apache::loncommon::defaultdesign;
2095: if ($role eq 'login') {
2096: %defaults = (
2097: font => $defaultdesign{$role.'.font'},
2098: );
2099: if (ref($logintext) eq 'ARRAY') {
2100: foreach my $item (@{$logintext}) {
2101: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
2102: }
2103: }
2104: foreach my $item (@{$images}) {
2105: $defaults{'showlogo'}{$item} = 1;
2106: }
2107: } else {
2108: %defaults = (
2109: img => $defaultdesign{$role.'.img'},
2110: font => $defaultdesign{$role.'.font'},
2111: fontmenu => $defaultdesign{$role.'.fontmenu'},
2112: );
2113: }
2114: foreach my $item (@{$bgs}) {
2115: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
2116: }
2117: foreach my $item (@{$links}) {
2118: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
2119: }
2120: foreach my $item (@{$images}) {
2121: $defaults{$item} = $defaultdesign{$role.'.'.$item};
2122: }
2123: return %defaults;
2124: }
2125:
1.6 raeburn 2126: sub display_color_options {
1.9 raeburn 2127: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 2128: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 2129: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 2130: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 2131: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 2132: '<td>'.$choices->{'font'}.'</td>';
2133: if (!$is_custom->{'font'}) {
1.329 raeburn 2134: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 2135: } else {
2136: $datatable .= '<td> </td>';
2137: }
1.174 foxr 2138: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
2139:
1.8 raeburn 2140: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2141: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 2142: ' value="'.$current_color.'" /> '.
1.329 raeburn 2143: ' </span></td></tr>';
1.107 raeburn 2144: unless ($role eq 'login') {
2145: $datatable .= '<tr'.$css_class.'>'.
2146: '<td>'.$choices->{'fontmenu'}.'</td>';
2147: if (!$is_custom->{'fontmenu'}) {
1.329 raeburn 2148: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 2149: } else {
2150: $datatable .= '<td> </td>';
2151: }
1.202 raeburn 2152: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 2153: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 2154: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2155: '<input class="colorchooser" type="text" size="10" name="'
2156: .$role.'_fontmenu"'.
2157: ' value="'.$current_color.'" /> '.
1.329 raeburn 2158: ' </span></td></tr>';
1.97 tempelho 2159: }
1.9 raeburn 2160: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 2161: foreach my $img (@{$images}) {
1.18 albertel 2162: $itemcount ++;
1.6 raeburn 2163: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 2164: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 2165: '<td>'.$choices->{$img};
1.402 raeburn 2166: my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext);
1.70 raeburn 2167: if ($role eq 'login') {
2168: if ($img eq 'login') {
2169: $login_hdr_pick =
1.135 bisitz 2170: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 2171: $logincolors =
2172: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 2173: $designs,$defaults);
1.402 raeburn 2174: } else {
2175: if ($img ne 'domlogo') {
2176: $datatable.= &logo_display_options($img,$defaults,$designs);
2177: }
2178: if (ref($designs->{'alttext'}) eq 'HASH') {
2179: $alttext = $designs->{'alttext'}{$img};
2180: }
1.70 raeburn 2181: }
2182: }
2183: $datatable .= '</td>';
1.6 raeburn 2184: if ($designs->{$img} ne '') {
2185: $imgfile = $designs->{$img};
1.18 albertel 2186: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 2187: } else {
2188: $imgfile = $defaults->{$img};
2189: }
2190: if ($imgfile) {
1.9 raeburn 2191: my ($showfile,$fullsize);
2192: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 2193: my $urldir = $1;
2194: my $filename = $2;
2195: my @info = &Apache::lonnet::stat_file($designs->{$img});
2196: if (@info) {
2197: my $thumbfile = 'tn-'.$filename;
2198: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
2199: if (@thumb) {
2200: $showfile = $urldir.'/'.$thumbfile;
2201: } else {
2202: $showfile = $imgfile;
2203: }
2204: } else {
2205: $showfile = '';
2206: }
2207: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 2208: $showfile = $imgfile;
1.6 raeburn 2209: my $imgdir = $1;
2210: my $filename = $2;
1.159 raeburn 2211: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 2212: $showfile = "/$imgdir/tn-".$filename;
2213: } else {
1.159 raeburn 2214: my $input = $londocroot.$imgfile;
2215: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 2216: if (!-e $output) {
1.9 raeburn 2217: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 2218: my ($fullwidth,$fullheight) = &check_dimensions($input);
2219: if ($fullwidth ne '' && $fullheight ne '') {
2220: if ($fullwidth > $width && $fullheight > $height) {
2221: my $size = $width.'x'.$height;
1.316 raeburn 2222: my @args = ('convert','-sample',$size,$input,$output);
2223: system({$args[0]} @args);
1.159 raeburn 2224: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 2225: }
2226: }
1.6 raeburn 2227: }
2228: }
1.16 raeburn 2229: }
1.6 raeburn 2230: if ($showfile) {
1.40 raeburn 2231: if ($showfile =~ m{^/(adm|res)/}) {
2232: if ($showfile =~ m{^/res/}) {
2233: my $local_showfile =
2234: &Apache::lonnet::filelocation('',$showfile);
2235: &Apache::lonnet::repcopy($local_showfile);
2236: }
2237: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
2238: }
2239: if ($imgfile) {
2240: if ($imgfile =~ m{^/(adm|res)/}) {
2241: if ($imgfile =~ m{^/res/}) {
2242: my $local_imgfile =
2243: &Apache::lonnet::filelocation('',$imgfile);
2244: &Apache::lonnet::repcopy($local_imgfile);
2245: }
2246: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
2247: } else {
2248: $fullsize = $imgfile;
2249: }
2250: }
1.41 raeburn 2251: $datatable .= '<td>';
2252: if ($img eq 'login') {
1.135 bisitz 2253: $datatable .= $login_hdr_pick;
2254: }
1.41 raeburn 2255: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
2256: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 2257: } else {
1.201 raeburn 2258: $datatable .= '<td> </td><td class="LC_left_item">'.
2259: &mt('Upload:').'<br />';
1.6 raeburn 2260: }
2261: } else {
1.201 raeburn 2262: $datatable .= '<td> </td><td class="LC_left_item">'.
2263: &mt('Upload:').'<br />';
1.6 raeburn 2264: }
1.9 raeburn 2265: if ($switchserver) {
2266: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2267: } else {
1.135 bisitz 2268: if ($img ne 'login') { # suppress file selection for Log-in header
2269: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
2270: }
1.9 raeburn 2271: }
1.402 raeburn 2272: if (($role eq 'login') && ($img ne 'login')) {
2273: $datatable .= (' ' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'.
2274: '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'.
2275: '</label></span>';
2276: }
1.9 raeburn 2277: $datatable .= '</td></tr>';
1.6 raeburn 2278: }
2279: $itemcount ++;
2280: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2281: $datatable .= '<tr'.$css_class.'>'.
2282: '<td>'.$choices->{'bgs'}.'</td>';
2283: my $bgs_def;
2284: foreach my $item (@{$bgs}) {
2285: if (!$is_custom->{$item}) {
1.329 raeburn 2286: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span class="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 2287: }
2288: }
2289: if ($bgs_def) {
1.8 raeburn 2290: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 2291: } else {
2292: $datatable .= '<td> </td>';
2293: }
2294: $datatable .= '<td class="LC_right_item">'.
2295: '<table border="0"><tr>';
1.174 foxr 2296:
1.6 raeburn 2297: foreach my $item (@{$bgs}) {
1.306 raeburn 2298: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 2299: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 2300: if ($designs->{'bgs'}{$item}) {
1.174 foxr 2301: $datatable .= ' ';
1.6 raeburn 2302: }
1.174 foxr 2303: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 2304: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 2305: }
2306: $datatable .= '</tr></table></td></tr>';
2307: $itemcount ++;
2308: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2309: $datatable .= '<tr'.$css_class.'>'.
2310: '<td>'.$choices->{'links'}.'</td>';
2311: my $links_def;
2312: foreach my $item (@{$links}) {
2313: if (!$is_custom->{$item}) {
1.329 raeburn 2314: $links_def .= '<td>'.$choices->{$item}.'<br /><span class="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 2315: }
2316: }
2317: if ($links_def) {
1.8 raeburn 2318: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 2319: } else {
2320: $datatable .= '<td> </td>';
2321: }
2322: $datatable .= '<td class="LC_right_item">'.
2323: '<table border="0"><tr>';
2324: foreach my $item (@{$links}) {
1.234 raeburn 2325: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 2326: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 2327: if ($designs->{'links'}{$item}) {
1.174 foxr 2328: $datatable.=' ';
1.6 raeburn 2329: }
1.174 foxr 2330: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 2331: '" /></td>';
2332: }
1.30 raeburn 2333: $$rowtotal += $itemcount;
1.3 raeburn 2334: return $datatable;
2335: }
2336:
1.70 raeburn 2337: sub logo_display_options {
2338: my ($img,$defaults,$designs) = @_;
2339: my $checkedon;
2340: if (ref($defaults) eq 'HASH') {
2341: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2342: if ($defaults->{'showlogo'}{$img}) {
2343: $checkedon = 'checked="checked" ';
2344: }
2345: }
2346: }
2347: if (ref($designs) eq 'HASH') {
2348: if (ref($designs->{'showlogo'}) eq 'HASH') {
2349: if (defined($designs->{'showlogo'}{$img})) {
2350: if ($designs->{'showlogo'}{$img} == 0) {
2351: $checkedon = '';
2352: } elsif ($designs->{'showlogo'}{$img} == 1) {
2353: $checkedon = 'checked="checked" ';
2354: }
2355: }
2356: }
2357: }
2358: return '<br /><label> <input type="checkbox" name="'.
2359: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2360: &mt('show').'</label>'."\n";
2361: }
2362:
1.41 raeburn 2363: sub login_header_options {
1.135 bisitz 2364: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2365: my $output = '';
1.41 raeburn 2366: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 2367: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 2368: if (!$is_custom->{'textcol'}) {
2369: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2370: ' ';
2371: }
2372: if (!$is_custom->{'bgcol'}) {
2373: $output .= $choices->{'bgcol'}.': '.
2374: '<span id="css_'.$role.'_font" style="background-color: '.
2375: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2376: }
2377: $output .= '<br />';
2378: }
2379: $output .='<br />';
2380: return $output;
2381: }
2382:
2383: sub login_text_colors {
1.201 raeburn 2384: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 2385: my $color_menu = '<table border="0"><tr>';
2386: foreach my $item (@{$logintext}) {
1.306 raeburn 2387: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 2388: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2389: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2390: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 2391: }
2392: $color_menu .= '</tr></table><br />';
2393: return $color_menu;
2394: }
2395:
2396: sub image_changes {
2397: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2398: my $output;
1.135 bisitz 2399: if ($img eq 'login') {
1.331 raeburn 2400: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 2401: } elsif (!$is_custom) {
1.70 raeburn 2402: if ($img ne 'domlogo') {
1.331 raeburn 2403: $output = &mt('Default image:').'<br />';
1.41 raeburn 2404: } else {
1.331 raeburn 2405: $output = &mt('Default in use:').'<br />';
1.41 raeburn 2406: }
2407: }
1.331 raeburn 2408: if ($img ne 'login') {
1.135 bisitz 2409: if ($img_import) {
2410: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2411: }
2412: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2413: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2414: if ($is_custom) {
2415: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2416: '<input type="checkbox" name="'.
2417: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2418: '</label> '.&mt('Replace:').'</span><br />';
2419: } else {
1.306 raeburn 2420: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 2421: }
1.41 raeburn 2422: }
2423: return $output;
2424: }
2425:
1.3 raeburn 2426: sub print_quotas {
1.86 raeburn 2427: my ($dom,$settings,$rowtotal,$action) = @_;
2428: my $context;
2429: if ($action eq 'quotas') {
2430: $context = 'tools';
2431: } else {
2432: $context = $action;
2433: }
1.429 raeburn 2434: my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44 raeburn 2435: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2436: my $typecount = 0;
1.101 raeburn 2437: my ($css_class,%titles);
1.86 raeburn 2438: if ($context eq 'requestcourses') {
1.325 raeburn 2439: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 2440: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2441: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2442: %titles = &courserequest_titles();
1.163 raeburn 2443: } elsif ($context eq 'requestauthor') {
2444: @usertools = ('author');
2445: @options = ('norequest','approval','automatic');
1.210 raeburn 2446: %titles = &authorrequest_titles();
1.86 raeburn 2447: } else {
1.430 raeburn 2448: @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.101 raeburn 2449: %titles = &tool_titles();
1.86 raeburn 2450: }
1.26 raeburn 2451: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2452: foreach my $type (@{$types}) {
1.429 raeburn 2453: my $currdefquota;
1.163 raeburn 2454: unless (($context eq 'requestcourses') ||
2455: ($context eq 'requestauthor')) {
1.86 raeburn 2456: if (ref($settings) eq 'HASH') {
2457: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 2458: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2459: } else {
2460: $currdefquota = $settings->{$type};
2461: }
1.78 raeburn 2462: }
1.72 raeburn 2463: }
1.3 raeburn 2464: if (defined($usertypes->{$type})) {
2465: $typecount ++;
2466: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2467: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2468: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2469: '<td class="LC_left_item">';
1.101 raeburn 2470: if ($context eq 'requestcourses') {
2471: $datatable .= '<table><tr>';
2472: }
2473: my %cell;
1.72 raeburn 2474: foreach my $item (@usertools) {
1.101 raeburn 2475: if ($context eq 'requestcourses') {
2476: my ($curroption,$currlimit);
2477: if (ref($settings) eq 'HASH') {
2478: if (ref($settings->{$item}) eq 'HASH') {
2479: $curroption = $settings->{$item}->{$type};
2480: if ($curroption =~ /^autolimit=(\d*)$/) {
2481: $currlimit = $1;
2482: }
2483: }
2484: }
2485: if (!$curroption) {
2486: $curroption = 'norequest';
2487: }
2488: $datatable .= '<th>'.$titles{$item}.'</th>';
2489: foreach my $option (@options) {
2490: my $val = $option;
2491: if ($option eq 'norequest') {
2492: $val = 0;
2493: }
2494: if ($option eq 'validate') {
2495: my $canvalidate = 0;
2496: if (ref($validations{$item}) eq 'HASH') {
2497: if ($validations{$item}{$type}) {
2498: $canvalidate = 1;
2499: }
2500: }
2501: next if (!$canvalidate);
2502: }
2503: my $checked = '';
2504: if ($option eq $curroption) {
2505: $checked = ' checked="checked"';
2506: } elsif ($option eq 'autolimit') {
2507: if ($curroption =~ /^autolimit/) {
2508: $checked = ' checked="checked"';
2509: }
2510: }
2511: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2512: '<input type="radio" name="crsreq_'.$item.
2513: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2514: $titles{$option}.'</label>';
1.101 raeburn 2515: if ($option eq 'autolimit') {
1.127 raeburn 2516: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2517: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2518: 'value="'.$currlimit.'" />';
1.101 raeburn 2519: }
1.127 raeburn 2520: $cell{$item} .= '</span> ';
1.103 raeburn 2521: if ($option eq 'autolimit') {
1.127 raeburn 2522: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2523: }
1.101 raeburn 2524: }
1.163 raeburn 2525: } elsif ($context eq 'requestauthor') {
2526: my $curroption;
2527: if (ref($settings) eq 'HASH') {
2528: $curroption = $settings->{$type};
2529: }
2530: if (!$curroption) {
2531: $curroption = 'norequest';
2532: }
2533: foreach my $option (@options) {
2534: my $val = $option;
2535: if ($option eq 'norequest') {
2536: $val = 0;
2537: }
2538: my $checked = '';
2539: if ($option eq $curroption) {
2540: $checked = ' checked="checked"';
2541: }
2542: $datatable .= '<span class="LC_nobreak"><label>'.
2543: '<input type="radio" name="authorreq_'.$type.
2544: '" value="'.$val.'"'.$checked.' />'.
2545: $titles{$option}.'</label></span> ';
2546: }
1.101 raeburn 2547: } else {
2548: my $checked = 'checked="checked" ';
1.413 raeburn 2549: if ($item eq 'timezone') {
2550: $checked = '';
2551: }
1.101 raeburn 2552: if (ref($settings) eq 'HASH') {
2553: if (ref($settings->{$item}) eq 'HASH') {
1.413 raeburn 2554: if (!$settings->{$item}->{$type}) {
1.101 raeburn 2555: $checked = '';
2556: } elsif ($settings->{$item}->{$type} == 1) {
2557: $checked = 'checked="checked" ';
2558: }
1.78 raeburn 2559: }
1.72 raeburn 2560: }
1.101 raeburn 2561: $datatable .= '<span class="LC_nobreak"><label>'.
2562: '<input type="checkbox" name="'.$context.'_'.$item.
2563: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2564: '</label></span> ';
1.72 raeburn 2565: }
1.101 raeburn 2566: }
2567: if ($context eq 'requestcourses') {
2568: $datatable .= '</tr><tr>';
2569: foreach my $item (@usertools) {
1.106 raeburn 2570: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2571: }
2572: $datatable .= '</tr></table>';
1.72 raeburn 2573: }
1.86 raeburn 2574: $datatable .= '</td>';
1.163 raeburn 2575: unless (($context eq 'requestcourses') ||
2576: ($context eq 'requestauthor')) {
1.86 raeburn 2577: $datatable .=
1.197 raeburn 2578: '<td class="LC_right_item">'.
1.429 raeburn 2579: '<span class="LC_nobreak">'.
1.3 raeburn 2580: '<input type="text" name="quota_'.$type.
1.72 raeburn 2581: '" value="'.$currdefquota.
1.197 raeburn 2582: '" size="5" /></span></td>';
1.86 raeburn 2583: }
2584: $datatable .= '</tr>';
1.3 raeburn 2585: }
2586: }
2587: }
1.163 raeburn 2588: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2589: $defaultquota = '20';
2590: if (ref($settings) eq 'HASH') {
2591: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2592: $defaultquota = $settings->{'defaultquota'}->{'default'};
2593: } elsif (defined($settings->{'default'})) {
2594: $defaultquota = $settings->{'default'};
2595: }
1.3 raeburn 2596: }
2597: }
2598: $typecount ++;
2599: $css_class = $typecount%2?' class="LC_odd_row"':'';
2600: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2601: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2602: '<td class="LC_left_item">';
1.101 raeburn 2603: if ($context eq 'requestcourses') {
2604: $datatable .= '<table><tr>';
2605: }
2606: my %defcell;
1.72 raeburn 2607: foreach my $item (@usertools) {
1.101 raeburn 2608: if ($context eq 'requestcourses') {
2609: my ($curroption,$currlimit);
2610: if (ref($settings) eq 'HASH') {
2611: if (ref($settings->{$item}) eq 'HASH') {
2612: $curroption = $settings->{$item}->{'default'};
2613: if ($curroption =~ /^autolimit=(\d*)$/) {
2614: $currlimit = $1;
2615: }
2616: }
2617: }
2618: if (!$curroption) {
2619: $curroption = 'norequest';
2620: }
2621: $datatable .= '<th>'.$titles{$item}.'</th>';
2622: foreach my $option (@options) {
2623: my $val = $option;
2624: if ($option eq 'norequest') {
2625: $val = 0;
2626: }
2627: if ($option eq 'validate') {
2628: my $canvalidate = 0;
2629: if (ref($validations{$item}) eq 'HASH') {
2630: if ($validations{$item}{'default'}) {
2631: $canvalidate = 1;
2632: }
2633: }
2634: next if (!$canvalidate);
2635: }
2636: my $checked = '';
2637: if ($option eq $curroption) {
2638: $checked = ' checked="checked"';
2639: } elsif ($option eq 'autolimit') {
2640: if ($curroption =~ /^autolimit/) {
2641: $checked = ' checked="checked"';
2642: }
2643: }
2644: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2645: '<input type="radio" name="crsreq_'.$item.
2646: '_default" value="'.$val.'"'.$checked.' />'.
2647: $titles{$option}.'</label>';
2648: if ($option eq 'autolimit') {
1.127 raeburn 2649: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2650: $item.'_limit_default" size="1" '.
2651: 'value="'.$currlimit.'" />';
2652: }
1.127 raeburn 2653: $defcell{$item} .= '</span> ';
1.104 raeburn 2654: if ($option eq 'autolimit') {
1.127 raeburn 2655: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2656: }
1.101 raeburn 2657: }
1.163 raeburn 2658: } elsif ($context eq 'requestauthor') {
2659: my $curroption;
2660: if (ref($settings) eq 'HASH') {
1.172 raeburn 2661: $curroption = $settings->{'default'};
1.163 raeburn 2662: }
2663: if (!$curroption) {
2664: $curroption = 'norequest';
2665: }
2666: foreach my $option (@options) {
2667: my $val = $option;
2668: if ($option eq 'norequest') {
2669: $val = 0;
2670: }
2671: my $checked = '';
2672: if ($option eq $curroption) {
2673: $checked = ' checked="checked"';
2674: }
2675: $datatable .= '<span class="LC_nobreak"><label>'.
2676: '<input type="radio" name="authorreq_default"'.
2677: ' value="'.$val.'"'.$checked.' />'.
2678: $titles{$option}.'</label></span> ';
2679: }
1.101 raeburn 2680: } else {
2681: my $checked = 'checked="checked" ';
2682: if (ref($settings) eq 'HASH') {
2683: if (ref($settings->{$item}) eq 'HASH') {
2684: if ($settings->{$item}->{'default'} == 0) {
2685: $checked = '';
2686: } elsif ($settings->{$item}->{'default'} == 1) {
2687: $checked = 'checked="checked" ';
2688: }
1.78 raeburn 2689: }
1.72 raeburn 2690: }
1.101 raeburn 2691: $datatable .= '<span class="LC_nobreak"><label>'.
2692: '<input type="checkbox" name="'.$context.'_'.$item.
2693: '" value="default" '.$checked.'/>'.$titles{$item}.
2694: '</label></span> ';
2695: }
2696: }
2697: if ($context eq 'requestcourses') {
2698: $datatable .= '</tr><tr>';
2699: foreach my $item (@usertools) {
1.106 raeburn 2700: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2701: }
1.101 raeburn 2702: $datatable .= '</tr></table>';
1.72 raeburn 2703: }
1.86 raeburn 2704: $datatable .= '</td>';
1.163 raeburn 2705: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2706: $datatable .= '<td class="LC_right_item">'.
1.429 raeburn 2707: '<span class="LC_nobreak">'.
1.86 raeburn 2708: '<input type="text" name="defaultquota" value="'.
1.429 raeburn 2709: $defaultquota.'" size="5" /></span></td>';
1.86 raeburn 2710: }
2711: $datatable .= '</tr>';
1.72 raeburn 2712: $typecount ++;
2713: $css_class = $typecount%2?' class="LC_odd_row"':'';
2714: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2715: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2716: if ($context eq 'requestcourses') {
1.109 raeburn 2717: $datatable .= &mt('(overrides affiliation, if set)').
2718: '</td>'.
2719: '<td class="LC_left_item">'.
2720: '<table><tr>';
1.101 raeburn 2721: } else {
1.109 raeburn 2722: $datatable .= &mt('(overrides affiliation, if checked)').
2723: '</td>'.
2724: '<td class="LC_left_item" colspan="2">'.
2725: '<br />';
1.101 raeburn 2726: }
2727: my %advcell;
1.72 raeburn 2728: foreach my $item (@usertools) {
1.101 raeburn 2729: if ($context eq 'requestcourses') {
2730: my ($curroption,$currlimit);
2731: if (ref($settings) eq 'HASH') {
2732: if (ref($settings->{$item}) eq 'HASH') {
2733: $curroption = $settings->{$item}->{'_LC_adv'};
2734: if ($curroption =~ /^autolimit=(\d*)$/) {
2735: $currlimit = $1;
2736: }
2737: }
2738: }
2739: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2740: my $checked = '';
2741: if ($curroption eq '') {
2742: $checked = ' checked="checked"';
2743: }
2744: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2745: '<input type="radio" name="crsreq_'.$item.
2746: '__LC_adv" value=""'.$checked.' />'.
2747: &mt('No override set').'</label></span> ';
1.101 raeburn 2748: foreach my $option (@options) {
2749: my $val = $option;
2750: if ($option eq 'norequest') {
2751: $val = 0;
2752: }
2753: if ($option eq 'validate') {
2754: my $canvalidate = 0;
2755: if (ref($validations{$item}) eq 'HASH') {
2756: if ($validations{$item}{'_LC_adv'}) {
2757: $canvalidate = 1;
2758: }
2759: }
2760: next if (!$canvalidate);
2761: }
2762: my $checked = '';
1.104 raeburn 2763: if ($val eq $curroption) {
1.101 raeburn 2764: $checked = ' checked="checked"';
2765: } elsif ($option eq 'autolimit') {
2766: if ($curroption =~ /^autolimit/) {
2767: $checked = ' checked="checked"';
2768: }
2769: }
2770: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2771: '<input type="radio" name="crsreq_'.$item.
2772: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2773: $titles{$option}.'</label>';
2774: if ($option eq 'autolimit') {
1.127 raeburn 2775: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2776: $item.'_limit__LC_adv" size="1" '.
2777: 'value="'.$currlimit.'" />';
2778: }
1.127 raeburn 2779: $advcell{$item} .= '</span> ';
1.104 raeburn 2780: if ($option eq 'autolimit') {
1.127 raeburn 2781: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2782: }
1.101 raeburn 2783: }
1.163 raeburn 2784: } elsif ($context eq 'requestauthor') {
2785: my $curroption;
2786: if (ref($settings) eq 'HASH') {
2787: $curroption = $settings->{'_LC_adv'};
2788: }
2789: my $checked = '';
2790: if ($curroption eq '') {
2791: $checked = ' checked="checked"';
2792: }
2793: $datatable .= '<span class="LC_nobreak"><label>'.
2794: '<input type="radio" name="authorreq__LC_adv"'.
2795: ' value=""'.$checked.' />'.
2796: &mt('No override set').'</label></span> ';
2797: foreach my $option (@options) {
2798: my $val = $option;
2799: if ($option eq 'norequest') {
2800: $val = 0;
2801: }
2802: my $checked = '';
2803: if ($val eq $curroption) {
2804: $checked = ' checked="checked"';
2805: }
2806: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2807: '<input type="radio" name="authorreq__LC_adv"'.
2808: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2809: $titles{$option}.'</label></span> ';
2810: }
1.101 raeburn 2811: } else {
2812: my $checked = 'checked="checked" ';
2813: if (ref($settings) eq 'HASH') {
2814: if (ref($settings->{$item}) eq 'HASH') {
2815: if ($settings->{$item}->{'_LC_adv'} == 0) {
2816: $checked = '';
2817: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2818: $checked = 'checked="checked" ';
2819: }
1.79 raeburn 2820: }
1.72 raeburn 2821: }
1.101 raeburn 2822: $datatable .= '<span class="LC_nobreak"><label>'.
2823: '<input type="checkbox" name="'.$context.'_'.$item.
2824: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2825: '</label></span> ';
2826: }
2827: }
2828: if ($context eq 'requestcourses') {
2829: $datatable .= '</tr><tr>';
2830: foreach my $item (@usertools) {
1.106 raeburn 2831: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2832: }
1.101 raeburn 2833: $datatable .= '</tr></table>';
1.72 raeburn 2834: }
1.98 raeburn 2835: $datatable .= '</td></tr>';
1.30 raeburn 2836: $$rowtotal += $typecount;
1.3 raeburn 2837: return $datatable;
2838: }
2839:
1.163 raeburn 2840: sub print_requestmail {
1.305 raeburn 2841: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2842: my ($now,$datatable,%currapp);
1.102 raeburn 2843: $now = time;
2844: if (ref($settings) eq 'HASH') {
2845: if (ref($settings->{'notify'}) eq 'HASH') {
2846: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2847: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2848: }
2849: }
2850: }
1.191 raeburn 2851: my $numinrow = 2;
1.224 raeburn 2852: my $css_class;
1.305 raeburn 2853: if ($$rowtotal%2) {
2854: $css_class = 'LC_odd_row';
2855: }
2856: if ($customcss) {
2857: $css_class .= " $customcss";
2858: }
2859: $css_class =~ s/^\s+//;
2860: if ($css_class) {
2861: $css_class = ' class="'.$css_class.'"';
2862: }
2863: if ($rowstyle) {
2864: $css_class .= ' style="'.$rowstyle.'"';
2865: }
1.163 raeburn 2866: my $text;
2867: if ($action eq 'requestcourses') {
2868: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2869: } elsif ($action eq 'requestauthor') {
2870: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2871: } else {
1.224 raeburn 2872: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2873: }
1.224 raeburn 2874: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2875: ' <td>'.$text.'</td>'.
1.102 raeburn 2876: ' <td class="LC_left_item">';
1.191 raeburn 2877: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2878: $action.'notifyapproval',%currapp);
1.191 raeburn 2879: if ($numdc > 0) {
2880: $datatable .= $table;
1.102 raeburn 2881: } else {
2882: $datatable .= &mt('There are no active Domain Coordinators');
2883: }
2884: $datatable .='</td></tr>';
2885: return $datatable;
2886: }
2887:
1.216 raeburn 2888: sub print_studentcode {
2889: my ($settings,$rowtotal) = @_;
2890: my $rownum = 0;
1.218 raeburn 2891: my ($output,%current);
1.325 raeburn 2892: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248 raeburn 2893: if (ref($settings) eq 'HASH') {
2894: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2895: foreach my $type (@crstypes) {
2896: $current{$type} = $settings->{'uniquecode'}{$type};
2897: }
1.218 raeburn 2898: }
2899: }
2900: $output .= '<tr>'.
2901: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2902: '<td class="LC_left_item">';
2903: foreach my $type (@crstypes) {
2904: my $check = ' ';
2905: if ($current{$type}) {
2906: $check = ' checked="checked" ';
2907: }
2908: $output .= '<span class="LC_nobreak"><label>'.
2909: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2910: &mt($type).'</label></span>'.(' 'x2).' ';
2911: }
2912: $output .= '</td></tr>';
2913: $$rowtotal ++;
2914: return $output;
1.216 raeburn 2915: }
2916:
2917: sub print_textbookcourses {
1.242 raeburn 2918: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2919: my $rownum = 0;
2920: my $css_class;
2921: my $itemcount = 1;
2922: my $maxnum = 0;
2923: my $bookshash;
2924: if (ref($settings) eq 'HASH') {
1.242 raeburn 2925: $bookshash = $settings->{$type};
1.216 raeburn 2926: }
2927: my %ordered;
2928: if (ref($bookshash) eq 'HASH') {
2929: foreach my $item (keys(%{$bookshash})) {
2930: if (ref($bookshash->{$item}) eq 'HASH') {
2931: my $num = $bookshash->{$item}{'order'};
2932: $ordered{$num} = $item;
2933: }
2934: }
2935: }
2936: my $confname = $dom.'-domainconfig';
2937: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2938: my $maxnum = scalar(keys(%ordered));
2939: my $datatable;
1.216 raeburn 2940: if (keys(%ordered)) {
2941: my @items = sort { $a <=> $b } keys(%ordered);
2942: for (my $i=0; $i<@items; $i++) {
2943: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2944: my $key = $ordered{$items[$i]};
2945: my %coursehash=&Apache::lonnet::coursedescription($key);
2946: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2947: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2948: if (ref($bookshash->{$key}) eq 'HASH') {
2949: $subject = $bookshash->{$key}->{'subject'};
2950: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2951: if ($type eq 'textbooks') {
1.243 raeburn 2952: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2953: $author = $bookshash->{$key}->{'author'};
2954: $image = $bookshash->{$key}->{'image'};
2955: if ($image ne '') {
2956: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2957: my $imagethumb = "$path/tn-".$imagefile;
2958: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2959: }
1.216 raeburn 2960: }
2961: }
1.242 raeburn 2962: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2963: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2964: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2965: for (my $k=0; $k<=$maxnum; $k++) {
2966: my $vpos = $k+1;
2967: my $selstr;
2968: if ($k == $i) {
2969: $selstr = ' selected="selected" ';
2970: }
2971: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2972: }
2973: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2974: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2975: &mt('Delete?').'</label></span></td>'.
2976: '<td colspan="2">'.
1.242 raeburn 2977: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2978: (' 'x2).
1.242 raeburn 2979: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2980: if ($type eq 'textbooks') {
2981: $datatable .= (' 'x2).
1.243 raeburn 2982: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2983: (' 'x2).
1.242 raeburn 2984: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2985: (' 'x2).
2986: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2987: if ($image) {
1.267 raeburn 2988: $datatable .= $imgsrc.
1.242 raeburn 2989: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2990: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2991: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2992: }
2993: if ($switchserver) {
2994: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2995: } else {
2996: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2997: }
1.216 raeburn 2998: }
1.242 raeburn 2999: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 3000: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
3001: $coursetitle.'</span></td></tr>'."\n";
3002: $itemcount ++;
3003: }
3004: }
3005: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 3006: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 3007: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 3008: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
3009: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 3010: for (my $k=0; $k<$maxnum+1; $k++) {
3011: my $vpos = $k+1;
3012: my $selstr;
3013: if ($k == $maxnum) {
3014: $selstr = ' selected="selected" ';
3015: }
3016: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3017: }
3018: $datatable .= '</select> '."\n".
1.334 raeburn 3019: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216 raeburn 3020: '<td colspan="2">'.
1.242 raeburn 3021: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 3022: (' 'x2).
1.242 raeburn 3023: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
3024: (' 'x2);
3025: if ($type eq 'textbooks') {
1.243 raeburn 3026: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
3027: (' 'x2).
3028: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 3029: (' 'x2).
3030: '<span class="LC_nobreak">'.&mt('Image:').' ';
3031: if ($switchserver) {
3032: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3033: } else {
3034: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
3035: }
1.334 raeburn 3036: $datatable .= '</span>'."\n";
1.216 raeburn 3037: }
1.334 raeburn 3038: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 3039: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
3040: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 3041: &Apache::loncommon::selectcourse_link
1.334 raeburn 3042: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216 raeburn 3043: '</span></td>'."\n".
3044: '</tr>'."\n";
3045: $itemcount ++;
3046: return $datatable;
3047: }
3048:
1.217 raeburn 3049: sub textbookcourses_javascript {
1.242 raeburn 3050: my ($settings) = @_;
3051: return unless(ref($settings) eq 'HASH');
3052: my (%ordered,%total,%jstext);
3053: foreach my $type ('textbooks','templates') {
3054: $total{$type} = 0;
3055: if (ref($settings->{$type}) eq 'HASH') {
3056: foreach my $item (keys(%{$settings->{$type}})) {
3057: if (ref($settings->{$type}->{$item}) eq 'HASH') {
3058: my $num = $settings->{$type}->{$item}{'order'};
3059: $ordered{$type}{$num} = $item;
3060: }
3061: }
3062: $total{$type} = scalar(keys(%{$settings->{$type}}));
3063: }
3064: my @jsarray = ();
3065: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
3066: push(@jsarray,$ordered{$type}{$item});
3067: }
3068: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 3069: }
3070: return <<"ENDSCRIPT";
3071: <script type="text/javascript">
3072: // <![CDATA[
1.242 raeburn 3073: function reorderBooks(form,item,caller) {
1.217 raeburn 3074: var changedVal;
1.242 raeburn 3075: $jstext{'textbooks'};
3076: $jstext{'templates'};
3077: var newpos;
3078: var maxh;
3079: if (caller == 'textbooks') {
3080: newpos = 'textbooks_addbook_pos';
3081: maxh = 1 + $total{'textbooks'};
3082: } else {
3083: newpos = 'templates_addbook_pos';
3084: maxh = 1 + $total{'templates'};
3085: }
1.217 raeburn 3086: var current = new Array;
3087: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3088: if (item == newpos) {
3089: changedVal = newitemVal;
3090: } else {
3091: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3092: current[newitemVal] = newpos;
3093: }
1.242 raeburn 3094: if (caller == 'textbooks') {
3095: for (var i=0; i<textbooks.length; i++) {
3096: var elementName = 'textbooks_'+textbooks[i];
3097: if (elementName != item) {
3098: if (form.elements[elementName]) {
3099: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3100: current[currVal] = elementName;
3101: }
3102: }
3103: }
3104: }
3105: if (caller == 'templates') {
3106: for (var i=0; i<templates.length; i++) {
3107: var elementName = 'templates_'+templates[i];
3108: if (elementName != item) {
3109: if (form.elements[elementName]) {
3110: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3111: current[currVal] = elementName;
3112: }
1.217 raeburn 3113: }
3114: }
3115: }
3116: var oldVal;
3117: for (var j=0; j<maxh; j++) {
3118: if (current[j] == undefined) {
3119: oldVal = j;
3120: }
3121: }
3122: if (oldVal < changedVal) {
3123: for (var k=oldVal+1; k<=changedVal ; k++) {
3124: var elementName = current[k];
3125: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3126: }
3127: } else {
3128: for (var k=changedVal; k<oldVal; k++) {
3129: var elementName = current[k];
3130: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3131: }
3132: }
3133: return;
3134: }
3135:
3136: // ]]>
3137: </script>
3138:
3139: ENDSCRIPT
3140: }
3141:
1.267 raeburn 3142: sub ltitools_javascript {
3143: my ($settings) = @_;
1.319 raeburn 3144: my $togglejs = <itools_toggle_js();
3145: unless (ref($settings) eq 'HASH') {
3146: return $togglejs;
3147: }
1.267 raeburn 3148: my (%ordered,$total,%jstext);
3149: $total = 0;
3150: foreach my $item (keys(%{$settings})) {
3151: if (ref($settings->{$item}) eq 'HASH') {
3152: my $num = $settings->{$item}{'order'};
3153: $ordered{$num} = $item;
3154: }
3155: }
3156: $total = scalar(keys(%{$settings}));
3157: my @jsarray = ();
3158: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3159: push(@jsarray,$ordered{$item});
3160: }
3161: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
3162: return <<"ENDSCRIPT";
3163: <script type="text/javascript">
3164: // <![CDATA[
1.319 raeburn 3165: function reorderLTITools(form,item) {
1.267 raeburn 3166: var changedVal;
3167: $jstext
3168: var newpos = 'ltitools_add_pos';
3169: var maxh = 1 + $total;
3170: var current = new Array;
3171: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3172: if (item == newpos) {
3173: changedVal = newitemVal;
3174: } else {
3175: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3176: current[newitemVal] = newpos;
3177: }
3178: for (var i=0; i<ltitools.length; i++) {
3179: var elementName = 'ltitools_'+ltitools[i];
3180: if (elementName != item) {
3181: if (form.elements[elementName]) {
3182: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3183: current[currVal] = elementName;
3184: }
3185: }
3186: }
3187: var oldVal;
3188: for (var j=0; j<maxh; j++) {
3189: if (current[j] == undefined) {
3190: oldVal = j;
3191: }
3192: }
3193: if (oldVal < changedVal) {
3194: for (var k=oldVal+1; k<=changedVal ; k++) {
3195: var elementName = current[k];
3196: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3197: }
3198: } else {
3199: for (var k=changedVal; k<oldVal; k++) {
3200: var elementName = current[k];
3201: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3202: }
3203: }
3204: return;
3205: }
3206:
3207: // ]]>
3208: </script>
3209:
1.319 raeburn 3210: $togglejs
3211:
3212: ENDSCRIPT
3213: }
3214:
3215: sub ltitools_toggle_js {
3216: return <<"ENDSCRIPT";
3217: <script type="text/javascript">
3218: // <![CDATA[
3219:
3220: function toggleLTITools(form,setting,item) {
3221: var radioname = '';
3222: var divid = '';
3223: if ((setting == 'passback') || (setting == 'roster')) {
3224: radioname = 'ltitools_'+setting+'_'+item;
3225: divid = 'ltitools_'+setting+'time_'+item;
3226: var num = form.elements[radioname].length;
3227: if (num) {
3228: var setvis = '';
3229: for (var i=0; i<num; i++) {
3230: if (form.elements[radioname][i].checked) {
3231: if (form.elements[radioname][i].value == '1') {
3232: if (document.getElementById(divid)) {
3233: document.getElementById(divid).style.display = 'inline-block';
3234: }
3235: setvis = 1;
3236: }
3237: break;
3238: }
3239: }
3240: }
3241: if (!setvis) {
3242: if (document.getElementById(divid)) {
3243: document.getElementById(divid).style.display = 'none';
3244: }
3245: }
3246: }
1.324 raeburn 3247: if (setting == 'user') {
3248: divid = 'ltitools_'+setting+'_div_'+item;
3249: var checkid = 'ltitools_'+setting+'_field_'+item;
3250: if (document.getElementById(divid)) {
3251: if (document.getElementById(checkid)) {
3252: if (document.getElementById(checkid).checked) {
3253: document.getElementById(divid).style.display = 'inline-block';
3254: } else {
3255: document.getElementById(divid).style.display = 'none';
3256: }
3257: }
3258: }
3259: }
1.319 raeburn 3260: return;
3261: }
3262: // ]]>
3263: </script>
3264:
1.267 raeburn 3265: ENDSCRIPT
3266: }
3267:
1.381 raeburn 3268: sub wafproxy_javascript {
3269: my ($dom) = @_;
3270: return <<"ENDSCRIPT";
3271: <script type="text/javascript">
3272: // <![CDATA[
3273: function updateWAF() {
3274: if (document.getElementById('wafproxy_remoteip')) {
3275: var wafremote = 0;
3276: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
3277: wafremote = 1;
3278: }
3279: var fields = new Array('header','trust');
3280: for (var i=0; i<fields.length; i++) {
3281: if (document.getElementById('wafproxy_'+fields[i])) {
3282: if (wafremote == 1) {
3283: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
3284: }
3285: else {
3286: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
3287: }
3288: }
3289: }
3290: if (document.getElementById('wafproxyranges_$dom')) {
3291: if (wafremote == 1) {
3292: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3293: } else {
3294: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3295: if (document.display.wafproxy_vpnaccess[i].checked) {
3296: if (document.display.wafproxy_vpnaccess[i].value == 0) {
3297: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3298: }
3299: }
3300: }
3301: }
3302: }
3303: }
3304: return;
3305: }
3306:
3307: function checkWAF() {
3308: if (document.getElementById('wafproxy_remoteip')) {
3309: var wafvpn = 0;
3310: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3311: if (document.display.wafproxy_vpnaccess[i].checked) {
3312: if (document.display.wafproxy_vpnaccess[i].value == 1) {
3313: wafvpn = 1;
3314: }
3315: break;
3316: }
3317: }
3318: var vpn = new Array('vpnint','vpnext');
3319: for (var i=0; i<vpn.length; i++) {
3320: if (document.getElementById('wafproxy_show_'+vpn[i])) {
3321: if (wafvpn == 1) {
3322: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
3323: }
3324: else {
3325: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
3326: }
3327: }
3328: }
3329: if (document.getElementById('wafproxyranges_$dom')) {
3330: if (wafvpn == 1) {
3331: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3332: }
3333: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
3334: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3335: }
3336: }
3337: }
3338: return;
3339: }
3340:
3341: function toggleWAF() {
3342: if (document.getElementById('wafproxy_table')) {
3343: var wafproxy = 0;
3344: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
3345: if (document.display.wafproxy_${dom}[i].checked) {
3346: if (document.display.wafproxy_${dom}[i].value == 1) {
3347: wafproxy = 1;
3348: break;
3349: }
3350: }
3351: }
3352: if (wafproxy == 1) {
3353: document.getElementById('wafproxy_table').style.display='inline';
3354: }
3355: else {
3356: document.getElementById('wafproxy_table').style.display='none';
3357: }
3358: if (document.getElementById('wafproxyrow_${dom}')) {
3359: if (wafproxy == 1) {
3360: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
3361: }
3362: else {
3363: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
3364: }
3365: }
3366: if (document.getElementById('nowafproxyrow_$dom')) {
3367: if (wafproxy == 1) {
3368: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
3369: }
3370: else {
3371: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
3372: }
3373: }
3374: }
3375: return;
3376: }
3377: // ]]>
3378: </script>
3379:
3380: ENDSCRIPT
3381: }
3382:
1.372 raeburn 3383: sub proctoring_javascript {
3384: my ($settings) = @_;
3385: my (%ordered,$total,%jstext);
3386: $total = 0;
3387: if (ref($settings) eq 'HASH') {
3388: foreach my $item (keys(%{$settings})) {
3389: if (ref($settings->{$item}) eq 'HASH') {
3390: my $num = $settings->{$item}{'order'};
3391: $ordered{$num} = $item;
3392: }
3393: }
3394: $total = scalar(keys(%{$settings}));
3395: } else {
3396: %ordered = (
3397: 0 => 'proctorio',
3398: 1 => 'examity',
3399: );
3400: $total = 2;
3401: }
3402: my @jsarray = ();
3403: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3404: push(@jsarray,$ordered{$item});
3405: }
3406: my $jstext = ' var proctors = Array('."'".join("','",@jsarray)."'".');'."\n";
3407: return <<"ENDSCRIPT";
3408: <script type="text/javascript">
3409: // <![CDATA[
3410: function reorderProctoring(form,item) {
3411: var changedVal;
3412: $jstext
3413: var maxh = $total;
3414: var current = new Array;
3415: var changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3416: for (var i=0; i<proctors.length; i++) {
3417: var elementName = 'proctoring_pos_'+proctors[i];
3418: if (elementName != item) {
3419: if (form.elements[elementName]) {
3420: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3421: current[currVal] = elementName;
3422: }
3423: }
3424: }
3425: var oldVal;
3426: for (var j=0; j<maxh; j++) {
3427: if (current[j] == undefined) {
3428: oldVal = j;
3429: }
3430: }
3431: if (oldVal < changedVal) {
3432: for (var k=oldVal+1; k<=changedVal ; k++) {
3433: var elementName = current[k];
3434: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3435: }
3436: } else {
3437: for (var k=changedVal; k<oldVal; k++) {
3438: var elementName = current[k];
3439: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3440: }
3441: }
3442: return;
3443: }
3444:
3445: function toggleProctoring(form,item) {
3446: var fieldsets = document.getElementsByClassName('proctoring_'+item);
3447: if (fieldsets.length) {
3448: var radioname = 'proctoring_available_'+item;
3449: var num = form.elements[radioname].length;
3450: if (num) {
3451: var setvis = '';
3452: for (var i=0; i<num; i++) {
3453: if (form.elements[radioname][i].checked) {
3454: if (form.elements[radioname][i].value == '1') {
3455: setvis = 1;
3456: break;
3457: }
3458: }
3459: }
3460: for (var j=0; j<fieldsets.length; j++) {
3461: if (setvis) {
3462: fieldsets[j].style.display = 'block';
3463: } else {
3464: fieldsets[j].style.display = 'none';
3465: }
3466: }
3467: }
3468: }
3469: return;
3470: }
3471:
3472: // ]]>
3473: </script>
3474:
3475: ENDSCRIPT
3476: }
3477:
3478:
1.320 raeburn 3479: sub lti_javascript {
1.405 raeburn 3480: my ($dom,$settings) = @_;
3481: my $togglejs = <i_toggle_js($dom);
1.419 raeburn 3482: my $linkprot_js = &Apache::courseprefs::linkprot_javascript();
1.320 raeburn 3483: unless (ref($settings) eq 'HASH') {
1.419 raeburn 3484: return $togglejs.'
3485: <script type="text/javascript">
3486: // <![CDATA[
3487:
3488: '.$linkprot_js.'
3489:
3490: // ]]>
3491: </script>
3492: ';
1.320 raeburn 3493: }
3494: my (%ordered,$total,%jstext);
1.390 raeburn 3495: $total = scalar(keys(%{$settings}));
1.320 raeburn 3496: foreach my $item (keys(%{$settings})) {
3497: if (ref($settings->{$item}) eq 'HASH') {
3498: my $num = $settings->{$item}{'order'};
1.390 raeburn 3499: if ($num eq '') {
3500: $num = $total - 1;
3501: }
1.320 raeburn 3502: $ordered{$num} = $item;
3503: }
3504: }
3505: my @jsarray = ();
3506: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3507: push(@jsarray,$ordered{$item});
3508: }
3509: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
3510: return <<"ENDSCRIPT";
3511: <script type="text/javascript">
3512: // <![CDATA[
3513: function reorderLTI(form,item) {
3514: var changedVal;
3515: $jstext
3516: var newpos = 'lti_pos_add';
3517: var maxh = 1 + $total;
3518: var current = new Array;
3519: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3520: if (item == newpos) {
3521: changedVal = newitemVal;
3522: } else {
3523: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3524: current[newitemVal] = newpos;
3525: }
3526: for (var i=0; i<lti.length; i++) {
3527: var elementName = 'lti_pos_'+lti[i];
3528: if (elementName != item) {
3529: if (form.elements[elementName]) {
3530: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3531: current[currVal] = elementName;
3532: }
3533: }
3534: }
3535: var oldVal;
3536: for (var j=0; j<maxh; j++) {
3537: if (current[j] == undefined) {
3538: oldVal = j;
3539: }
3540: }
3541: if (oldVal < changedVal) {
3542: for (var k=oldVal+1; k<=changedVal ; k++) {
3543: var elementName = current[k];
3544: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3545: }
3546: } else {
3547: for (var k=changedVal; k<oldVal; k++) {
3548: var elementName = current[k];
3549: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3550: }
3551: }
3552: return;
3553: }
1.406 raeburn 3554:
3555: $linkprot_js
3556:
1.320 raeburn 3557: // ]]>
3558: </script>
3559:
3560: $togglejs
3561:
3562: ENDSCRIPT
3563: }
3564:
3565: sub lti_toggle_js {
1.405 raeburn 3566: my ($dom) = @_;
1.325 raeburn 3567: my %lcauthparmtext = &Apache::lonlocal::texthash (
3568: localauth => 'Local auth argument',
3569: krb => 'Kerberos domain',
3570: );
1.391 raeburn 3571: my $crsincalert = &mt('"User\'s identity sent" needs to be set to "Yes" first,[_1] before setting "Course\'s identity sent" to "Yes"',"\n");
3572: &js_escape(\$crsincalert);
1.405 raeburn 3573: my %servers = &Apache::lonnet::get_servers($dom,'library');
3574: my $primary = &Apache::lonnet::domain($dom,'primary');
3575: my $course_servers = "'".join("','",keys(%servers))."'";
1.320 raeburn 3576: return <<"ENDSCRIPT";
3577: <script type="text/javascript">
3578: // <![CDATA[
3579:
3580: function toggleLTI(form,setting,item) {
1.391 raeburn 3581: if ((setting == 'requser') || (setting == 'crsinc')) {
3582: var usrfieldsets = document.getElementsByClassName('ltioption_usr_'+item);
3583: var setvis = '';
3584: var radioname = 'lti_requser_'+item;
3585: var num = form.elements[radioname].length;
3586: if (num) {
3587: for (var i=0; i<num; i++) {
3588: if (form.elements[radioname][i].checked) {
3589: if (form.elements[radioname][i].value == '1') {
3590: setvis = 1;
3591: break;
3592: }
3593: }
3594: }
3595: }
3596: if (usrfieldsets.length) {
3597: for (var j=0; j<usrfieldsets.length; j++) {
3598: if (setvis) {
3599: usrfieldsets[j].style.display = 'block';
3600: } else {
3601: usrfieldsets[j].style.display = 'none';
3602: }
3603: }
3604: }
3605: var crsfieldsets = document.getElementsByClassName('ltioption_crs_'+item);
3606: if (crsfieldsets.length) {
3607: radioname = 'lti_crsinc_'+item;
1.345 raeburn 3608: var num = form.elements[radioname].length;
3609: if (num) {
1.391 raeburn 3610: var crsvis = '';
1.345 raeburn 3611: for (var i=0; i<num; i++) {
3612: if (form.elements[radioname][i].checked) {
3613: if (form.elements[radioname][i].value == '1') {
1.391 raeburn 3614: if (setvis == '') {
3615: if (setting == 'crsinc'){
3616: alert("$crsincalert");
3617: form.elements[radioname][0].checked = true;
3618: }
3619: } else {
3620: crsvis = 1;
3621: }
3622: break;
1.345 raeburn 3623: }
3624: }
3625: }
1.391 raeburn 3626: setvis = crsvis;
3627: }
3628: for (var j=0; j<crsfieldsets.length; j++) {
3629: if (setvis) {
3630: crsfieldsets[j].style.display = 'block';
3631: } else {
3632: crsfieldsets[j].style.display = 'none';
1.345 raeburn 3633: }
3634: }
3635: }
1.363 raeburn 3636: } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
1.320 raeburn 3637: var radioname = '';
3638: var divid = '';
3639: if (setting == 'user') {
3640: radioname = 'lti_mapuser_'+item;
3641: divid = 'lti_userfield_'+item;
1.343 raeburn 3642: } else if (setting == 'crs') {
1.320 raeburn 3643: radioname = 'lti_mapcrs_'+item;
3644: divid = 'lti_crsfield_'+item;
1.363 raeburn 3645: } else if (setting == 'callback') {
3646: radioname = 'lti_callback_'+item;
3647: divid = 'lti_callbackfield_'+item;
1.337 raeburn 3648: } else {
1.351 raeburn 3649: radioname = 'lti_passback_'+item;
1.337 raeburn 3650: divid = 'lti_passback_'+item;
1.320 raeburn 3651: }
3652: var num = form.elements[radioname].length;
3653: if (num) {
3654: var setvis = '';
3655: for (var i=0; i<num; i++) {
3656: if (form.elements[radioname][i].checked) {
1.363 raeburn 3657: if ((setting == 'passback') || (setting == 'callback')) {
1.337 raeburn 3658: if (form.elements[radioname][i].value == '1') {
3659: if (document.getElementById(divid)) {
3660: document.getElementById(divid).style.display = 'inline-block';
3661: }
3662: setvis = 1;
3663: break;
3664: }
3665: } else {
3666: if (form.elements[radioname][i].value == 'other') {
3667: if (document.getElementById(divid)) {
3668: document.getElementById(divid).style.display = 'inline-block';
3669: }
3670: setvis = 1;
3671: break;
1.320 raeburn 3672: }
3673: }
1.425 raeburn 3674: }
1.320 raeburn 3675: }
3676: if (!setvis) {
3677: if (document.getElementById(divid)) {
3678: document.getElementById(divid).style.display = 'none';
3679: }
3680: }
3681: }
3682: } else if ((setting == 'sec') || (setting == 'secsrc')) {
3683: var numsec = form.elements['lti_crssec_'+item].length;
3684: if (numsec) {
3685: var setvis = '';
3686: for (var i=0; i<numsec; i++) {
3687: if (form.elements['lti_crssec_'+item][i].checked) {
3688: if (form.elements['lti_crssec_'+item][i].value == '1') {
3689: if (document.getElementById('lti_crssecfield_'+item)) {
3690: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
3691: setvis = 1;
3692: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
3693: if (numsrcsec) {
3694: var setsrcvis = '';
3695: for (var j=0; j<numsrcsec; j++) {
3696: if (form.elements['lti_crssecsrc_'+item][j].checked) {
3697: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
3698: if (document.getElementById('lti_secsrcfield_'+item)) {
3699: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
3700: setsrcvis = 1;
3701: }
3702: }
3703: }
3704: }
3705: if (!setsrcvis) {
3706: if (document.getElementById('lti_secsrcfield_'+item)) {
3707: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3708: }
3709: }
3710: }
3711: }
3712: }
3713: }
3714: }
3715: if (!setvis) {
3716: if (document.getElementById('lti_crssecfield_'+item)) {
3717: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
3718: }
3719: if (document.getElementById('lti_secsrcfield_'+item)) {
3720: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3721: }
3722: }
3723: }
1.325 raeburn 3724: } else if (setting == 'lcauth') {
3725: var numauth = form.elements['lti_lcauth_'+item].length;
3726: if (numauth) {
3727: for (var i=0; i<numauth; i++) {
3728: if (form.elements['lti_lcauth_'+item][i].checked) {
3729: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
3730: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
3731: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
3732: } else {
3733: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
3734: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
3735: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
3736: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
3737: } else {
3738: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
3739: }
3740: }
3741: }
3742: }
3743: }
3744: }
3745: }
1.326 raeburn 3746: } else if (setting == 'lcmenu') {
3747: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3748: var divid = 'lti_menufield_'+item;
3749: var setvis = '';
3750: for (var i=0; i<menus.length; i++) {
1.425 raeburn 3751: var radioname = menus[i];
1.326 raeburn 3752: var num = form.elements[radioname].length;
3753: if (num) {
3754: for (var j=0; j<num; j++) {
3755: if (form.elements[radioname][j].checked) {
3756: if (form.elements[radioname][j].value == '1') {
3757: if (document.getElementById(divid)) {
3758: document.getElementById(divid).style.display = 'inline-block';
3759: }
3760: setvis = 1;
3761: break;
3762: }
3763: }
3764: }
3765: }
3766: if (setvis == 1) {
3767: break;
3768: }
3769: }
3770: if (!setvis) {
3771: if (document.getElementById(divid)) {
3772: document.getElementById(divid).style.display = 'none';
3773: }
3774: }
1.320 raeburn 3775: }
3776: return;
3777: }
1.405 raeburn 3778:
1.320 raeburn 3779: // ]]>
3780: </script>
3781:
3782: ENDSCRIPT
3783: }
3784:
1.385 raeburn 3785: sub autoupdate_javascript {
3786: return <<"ENDSCRIPT";
3787: <script type="text/javascript">
3788: // <![CDATA[
3789: function toggleLastActiveDays(form) {
3790: var radioname = 'lastactive';
3791: var divid = 'lastactive_div';
3792: var num = form.elements[radioname].length;
3793: if (num) {
3794: var setvis = '';
3795: for (var i=0; i<num; i++) {
3796: if (form.elements[radioname][i].checked) {
3797: if (form.elements[radioname][i].value == '1') {
3798: if (document.getElementById(divid)) {
3799: document.getElementById(divid).style.display = 'inline-block';
3800: }
3801: setvis = 1;
3802: }
3803: break;
3804: }
3805: }
3806: if (!setvis) {
3807: if (document.getElementById(divid)) {
3808: document.getElementById(divid).style.display = 'none';
3809: }
3810: }
3811: }
3812: return;
3813: }
3814: // ]]>
3815: </script>
3816:
3817: ENDSCRIPT
3818: }
3819:
1.399 raeburn 3820: sub autoenroll_javascript {
3821: return <<"ENDSCRIPT";
3822: <script type="text/javascript">
3823: // <![CDATA[
3824: function toggleFailsafe(form) {
3825: var radioname = 'autoenroll_failsafe';
3826: var divid = 'autoenroll_failsafe_div';
3827: var num = form.elements[radioname].length;
3828: if (num) {
3829: var setvis = '';
3830: for (var i=0; i<num; i++) {
3831: if (form.elements[radioname][i].checked) {
3832: if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
3833: if (document.getElementById(divid)) {
3834: document.getElementById(divid).style.display = 'inline-block';
3835: }
3836: setvis = 1;
3837: }
3838: break;
3839: }
3840: }
3841: if (!setvis) {
3842: if (document.getElementById(divid)) {
3843: document.getElementById(divid).style.display = 'none';
3844: }
3845: }
3846: }
3847: return;
3848: }
3849: // ]]>
3850: </script>
3851:
3852: ENDSCRIPT
3853: }
3854:
1.386 raeburn 3855: sub saml_javascript {
3856: return <<"ENDSCRIPT";
3857: <script type="text/javascript">
3858: // <![CDATA[
1.425 raeburn 3859: function toggleSamlOptions(form,hostid) {
1.386 raeburn 3860: var radioname = 'saml_'+hostid;
3861: var tablecellon = 'samloptionson_'+hostid;
3862: var tablecelloff = 'samloptionsoff_'+hostid;
3863: var num = form.elements[radioname].length;
3864: if (num) {
1.425 raeburn 3865: var setvis = '';
1.386 raeburn 3866: for (var i=0; i<num; i++) {
3867: if (form.elements[radioname][i].checked) {
1.425 raeburn 3868: if (form.elements[radioname][i].value == '1') {
1.386 raeburn 3869: if (document.getElementById(tablecellon)) {
3870: document.getElementById(tablecellon).style.display='';
3871: }
3872: if (document.getElementById(tablecelloff)) {
3873: document.getElementById(tablecelloff).style.display='none';
3874: }
3875: setvis = 1;
3876: }
3877: break;
3878: }
3879: }
3880: if (!setvis) {
3881: if (document.getElementById(tablecellon)) {
3882: document.getElementById(tablecellon).style.display='none';
3883: }
3884: if (document.getElementById(tablecelloff)) {
3885: document.getElementById(tablecelloff).style.display='';
3886: }
3887: }
3888: }
3889: return;
3890: }
3891: // ]]>
3892: </script>
3893:
3894: ENDSCRIPT
3895: }
3896:
1.394 raeburn 3897: sub ipaccess_javascript {
3898: my ($settings) = @_;
3899: my (%ordered,$total,%jstext);
3900: $total = 0;
3901: if (ref($settings) eq 'HASH') {
3902: foreach my $item (keys(%{$settings})) {
3903: if (ref($settings->{$item}) eq 'HASH') {
3904: my $num = $settings->{$item}{'order'};
3905: $ordered{$num} = $item;
3906: }
3907: }
3908: $total = scalar(keys(%{$settings}));
3909: }
3910: my @jsarray = ();
3911: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3912: push(@jsarray,$ordered{$item});
3913: }
3914: my $jstext = ' var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
3915: return <<"ENDSCRIPT";
3916: <script type="text/javascript">
3917: // <![CDATA[
3918: function reorderIPaccess(form,item) {
3919: var changedVal;
3920: $jstext
3921: var newpos = 'ipaccess_pos_add';
3922: var maxh = 1 + $total;
3923: var current = new Array;
3924: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3925: if (item == newpos) {
3926: changedVal = newitemVal;
3927: } else {
3928: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3929: current[newitemVal] = newpos;
3930: }
3931: for (var i=0; i<ipaccess.length; i++) {
3932: var elementName = 'ipaccess_pos_'+ipaccess[i];
3933: if (elementName != item) {
3934: if (form.elements[elementName]) {
3935: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3936: current[currVal] = elementName;
3937: }
3938: }
3939: }
3940: var oldVal;
3941: for (var j=0; j<maxh; j++) {
3942: if (current[j] == undefined) {
3943: oldVal = j;
3944: }
3945: }
3946: if (oldVal < changedVal) {
3947: for (var k=oldVal+1; k<=changedVal ; k++) {
3948: var elementName = current[k];
3949: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3950: }
3951: } else {
3952: for (var k=changedVal; k<oldVal; k++) {
3953: var elementName = current[k];
3954: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3955: }
3956: }
3957: return;
3958: }
3959: // ]]>
3960: </script>
3961:
3962: ENDSCRIPT
3963: }
3964:
1.429 raeburn 3965: sub authordefaults_javascript {
3966: my %alert = &Apache::lonlocal::texthash (
3967: reqd => 'Warning: at least one editor needs to be available.',
3968: rest => 'Unchecking this editor disallowed while others unchecked.',
3969: );
3970: &js_escape(\%alert);
3971: return <<"ENDSCRIPT";
3972: <script type="text/javascript">
3973: // <![CDATA[
3974:
3975: function checkEditors(form,checkbox,current) {
3976: if (form.elements[checkbox].length != undefined) {
3977: var count = 0;
3978: for (var i=0; i<form.elements[checkbox].length; i++) {
3979: if (form.elements[checkbox][i].checked) {
3980: count ++;
3981: }
3982: }
3983: if (count == 0) {
3984: if (current.type =='radio') {
3985: current.checked = true;
3986: alert('$alert{reqd}\\n$alert{rest}');
3987: }
3988: }
3989: }
3990: return;
3991: }
3992: // ]]>
3993: </script>
3994:
3995: ENDSCRIPT
3996: }
3997:
1.3 raeburn 3998: sub print_autoenroll {
1.30 raeburn 3999: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 4000: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.399 raeburn 4001: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
4002: $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
4003: $failsafesty = 'none';
4004: %failsafechecked = (
4005: off => ' checked="checked"',
4006: );
1.3 raeburn 4007: if (ref($settings) eq 'HASH') {
4008: if (exists($settings->{'run'})) {
4009: if ($settings->{'run'} eq '0') {
4010: $runoff = ' checked="checked" ';
4011: $runon = ' ';
4012: } else {
4013: $runon = ' checked="checked" ';
4014: $runoff = ' ';
4015: }
4016: } else {
4017: if ($autorun) {
4018: $runon = ' checked="checked" ';
4019: $runoff = ' ';
4020: } else {
4021: $runoff = ' checked="checked" ';
4022: $runon = ' ';
4023: }
4024: }
1.129 raeburn 4025: if (exists($settings->{'co-owners'})) {
4026: if ($settings->{'co-owners'} eq '0') {
4027: $coownersoff = ' checked="checked" ';
4028: $coownerson = ' ';
4029: } else {
4030: $coownerson = ' checked="checked" ';
4031: $coownersoff = ' ';
4032: }
4033: } else {
4034: $coownersoff = ' checked="checked" ';
4035: $coownerson = ' ';
4036: }
1.3 raeburn 4037: if (exists($settings->{'sender_domain'})) {
4038: $defdom = $settings->{'sender_domain'};
4039: }
1.399 raeburn 4040: if (exists($settings->{'failsafe'})) {
4041: $failsafe = $settings->{'failsafe'};
4042: if ($failsafe eq 'zero') {
1.400 raeburn 4043: $failsafechecked{'zero'} = ' checked="checked"';
1.399 raeburn 4044: $failsafechecked{'off'} = '';
4045: $failsafesty = 'inline-block';
4046: } elsif ($failsafe eq 'any') {
4047: $failsafechecked{'any'} = ' checked="checked"';
4048: $failsafechecked{'off'} = '';
4049: }
4050: $autofailsafe = $settings->{'autofailsafe'};
4051: } elsif (exists($settings->{'autofailsafe'})) {
4052: $autofailsafe = $settings->{'autofailsafe'};
4053: if ($autofailsafe ne '') {
4054: $failsafechecked{'zero'} = ' checked="checked"';
4055: $failsafe = 'zero';
1.400 raeburn 4056: $failsafechecked{'off'} = '';
1.399 raeburn 4057: }
1.274 raeburn 4058: }
1.14 raeburn 4059: } else {
4060: if ($autorun) {
4061: $runon = ' checked="checked" ';
4062: $runoff = ' ';
4063: } else {
4064: $runoff = ' checked="checked" ';
4065: $runon = ' ';
4066: }
1.3 raeburn 4067: }
4068: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 4069: my $notif_sender;
4070: if (ref($settings) eq 'HASH') {
4071: $notif_sender = $settings->{'sender_uname'};
4072: }
1.3 raeburn 4073: my $datatable='<tr class="LC_odd_row">'.
4074: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 4075: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 4076: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 4077: $runon.' value="1" />'.&mt('Yes').'</label> '.
4078: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 4079: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 4080: '</tr><tr>'.
4081: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 4082: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 4083: &mt('username').': '.
4084: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 4085: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 4086: ': '.$domform.'</span></td></tr>'.
4087: '<tr class="LC_odd_row">'.
4088: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
4089: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4090: '<input type="radio" name="autoassign_coowners"'.
4091: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
4092: '<label><input type="radio" name="autoassign_coowners"'.
4093: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 4094: '</tr><tr>'.
4095: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
1.400 raeburn 4096: '<td class="LC_left_item"><span class="LC_nobreak">'.
4097: '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="off" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'off'}.' />'.&mt('Not in use').'</label></span> '.
4098: '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="zero" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'zero'}.' />'.&mt('Retrieved section enrollment is zero').'</label></span><br />'.
4099: '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="any" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'any'}.' />'.&mt('Retrieved section enrollment is zero or greater').'</label></span>'.
1.399 raeburn 4100: '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
4101: '<span class="LC_nobreak">'.
4102: &mt('Threshold for number of students in section to drop: [_1]',
4103: '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
4104: '</span></div></td></tr>';
1.274 raeburn 4105: $$rowtotal += 4;
1.3 raeburn 4106: return $datatable;
4107: }
4108:
4109: sub print_autoupdate {
1.30 raeburn 4110: my ($position,$dom,$settings,$rowtotal) = @_;
1.385 raeburn 4111: my ($enable,$datatable);
1.3 raeburn 4112: if ($position eq 'top') {
1.385 raeburn 4113: my %choices = &Apache::lonlocal::texthash (
4114: run => 'Auto-update active?',
4115: classlists => 'Update information in classlists?',
4116: unexpired => 'Skip updates for users without active or future roles?',
4117: lastactive => 'Skip updates for inactive users?',
4118: );
4119: my $itemcount = 0;
1.3 raeburn 4120: my $updateon = ' ';
4121: my $updateoff = ' checked="checked" ';
4122: if (ref($settings) eq 'HASH') {
4123: if ($settings->{'run'} eq '1') {
4124: $updateon = $updateoff;
4125: $updateoff = ' ';
4126: }
4127: }
1.385 raeburn 4128: $enable = '<tr class="LC_odd_row">'.
4129: '<td>'.$choices{'run'}.'</td>'.
4130: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 4131: '<input type="radio" name="autoupdate_run"'.
1.397 raeburn 4132: $updateoff.'value="0" />'.&mt('No').'</label> '.
1.8 raeburn 4133: '<label><input type="radio" name="autoupdate_run"'.
1.385 raeburn 4134: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 4135: '</tr>';
1.385 raeburn 4136: my @toggles = ('classlists','unexpired');
4137: my %defaultchecked = ('classlists' => 'off',
4138: 'unexpired' => 'off'
4139: );
4140: $$rowtotal ++;
4141: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4142: \%choices,$itemcount,'','','left','no');
4143: $datatable = $enable.$datatable;
4144: $$rowtotal += $itemcount;
4145: my $lastactiveon = ' ';
4146: my $lastactiveoff = ' checked="checked" ';
4147: my $lastactivestyle = 'none';
4148: my $lastactivedays;
4149: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
4150: if (ref($settings) eq 'HASH') {
4151: if ($settings->{'lastactive'} =~ /^\d+$/) {
4152: $lastactiveon = $lastactiveoff;
4153: $lastactiveoff = ' ';
4154: $lastactivestyle = 'inline-block';
4155: $lastactivedays = $settings->{'lastactive'};
4156: }
4157: }
4158: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4159: $datatable .= '<tr'.$css_class.'>'.
4160: '<td>'.$choices{'lastactive'}.'</td>'.
4161: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
4162: '<input type="radio" name="lastactive"'.
4163: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
4164: ' <label>'.
4165: '<input type="radio" name="lastactive"'.
4166: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
4167: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
4168: ': '.&mt('inactive = no activity in last [_1] days',
4169: '<input type="text" size="5" name="lastactivedays" value="'.
4170: $lastactivedays.'" />').
4171: '</span></td>'.
4172: '</tr>';
4173: $$rowtotal ++;
1.131 raeburn 4174: } elsif ($position eq 'middle') {
4175: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4176: my $numinrow = 3;
4177: my $locknamesettings;
4178: $datatable .= &insttypes_row($settings,$types,$usertypes,
4179: $dom,$numinrow,$othertitle,
1.305 raeburn 4180: 'lockablenames',$rowtotal);
1.131 raeburn 4181: $$rowtotal ++;
1.3 raeburn 4182: } else {
1.44 raeburn 4183: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 4184: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 4185: 'permanentemail','id');
1.33 raeburn 4186: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 4187: my $numrows = 0;
1.26 raeburn 4188: if (ref($types) eq 'ARRAY') {
4189: if (@{$types} > 0) {
4190: $datatable =
4191: &usertype_update_row($settings,$usertypes,\%fieldtitles,
4192: \@fields,$types,\$numrows);
1.30 raeburn 4193: $$rowtotal += @{$types};
1.26 raeburn 4194: }
1.3 raeburn 4195: }
4196: $datatable .=
4197: &usertype_update_row($settings,{'default' => $othertitle},
4198: \%fieldtitles,\@fields,['default'],
4199: \$numrows);
1.30 raeburn 4200: $$rowtotal ++;
1.3 raeburn 4201: }
4202: return $datatable;
4203: }
4204:
1.125 raeburn 4205: sub print_autocreate {
4206: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 4207: my (%createon,%createoff,%currhash);
1.125 raeburn 4208: my @types = ('xml','req');
4209: if (ref($settings) eq 'HASH') {
4210: foreach my $item (@types) {
4211: $createoff{$item} = ' checked="checked" ';
4212: $createon{$item} = ' ';
4213: if (exists($settings->{$item})) {
4214: if ($settings->{$item}) {
4215: $createon{$item} = ' checked="checked" ';
4216: $createoff{$item} = ' ';
4217: }
4218: }
4219: }
1.210 raeburn 4220: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 4221: $currhash{$settings->{'xmldc'}} = 1;
4222: }
1.125 raeburn 4223: } else {
4224: foreach my $item (@types) {
4225: $createoff{$item} = ' checked="checked" ';
4226: $createon{$item} = ' ';
4227: }
4228: }
4229: $$rowtotal += 2;
1.191 raeburn 4230: my $numinrow = 2;
1.125 raeburn 4231: my $datatable='<tr class="LC_odd_row">'.
4232: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
4233: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4234: '<input type="radio" name="autocreate_xml"'.
4235: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
4236: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 4237: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
4238: '</td></tr><tr>'.
4239: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
4240: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4241: '<input type="radio" name="autocreate_req"'.
4242: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
4243: '<label><input type="radio" name="autocreate_req"'.
4244: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 4245: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4246: 'autocreate_xmldc',%currhash);
1.247 raeburn 4247: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 4248: if ($numdc > 1) {
1.247 raeburn 4249: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
4250: '</td><td class="LC_left_item">';
1.125 raeburn 4251: } else {
1.247 raeburn 4252: $datatable .= &mt('Course creation processed as:').
4253: '</td><td class="LC_right_item">';
1.125 raeburn 4254: }
1.247 raeburn 4255: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 4256: $$rowtotal += $rows;
1.125 raeburn 4257: return $datatable;
4258: }
4259:
1.23 raeburn 4260: sub print_directorysrch {
1.277 raeburn 4261: my ($position,$dom,$settings,$rowtotal) = @_;
4262: my $datatable;
4263: if ($position eq 'top') {
4264: my $instsrchon = ' ';
4265: my $instsrchoff = ' checked="checked" ';
4266: my ($exacton,$containson,$beginson);
4267: my $instlocalon = ' ';
4268: my $instlocaloff = ' checked="checked" ';
4269: if (ref($settings) eq 'HASH') {
4270: if ($settings->{'available'} eq '1') {
4271: $instsrchon = $instsrchoff;
4272: $instsrchoff = ' ';
4273: }
4274: if ($settings->{'localonly'} eq '1') {
4275: $instlocalon = $instlocaloff;
4276: $instlocaloff = ' ';
4277: }
4278: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
4279: foreach my $type (@{$settings->{'searchtypes'}}) {
4280: if ($type eq 'exact') {
4281: $exacton = ' checked="checked" ';
4282: } elsif ($type eq 'contains') {
4283: $containson = ' checked="checked" ';
4284: } elsif ($type eq 'begins') {
4285: $beginson = ' checked="checked" ';
4286: }
4287: }
4288: } else {
4289: if ($settings->{'searchtypes'} eq 'exact') {
4290: $exacton = ' checked="checked" ';
4291: } elsif ($settings->{'searchtypes'} eq 'contains') {
4292: $containson = ' checked="checked" ';
4293: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 4294: $exacton = ' checked="checked" ';
4295: $containson = ' checked="checked" ';
4296: }
4297: }
1.277 raeburn 4298: }
4299: my ($searchtitles,$titleorder) = &sorted_searchtitles();
4300: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4301:
4302: my $numinrow = 4;
4303: my $cansrchrow = 0;
4304: $datatable='<tr class="LC_odd_row">'.
4305: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
4306: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4307: '<input type="radio" name="dirsrch_available"'.
4308: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
4309: '<label><input type="radio" name="dirsrch_available"'.
4310: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4311: '</tr><tr>'.
4312: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
4313: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4314: '<input type="radio" name="dirsrch_instlocalonly"'.
4315: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4316: '<label><input type="radio" name="dirsrch_instlocalonly"'.
4317: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4318: '</tr>';
4319: $$rowtotal += 2;
4320: if (ref($usertypes) eq 'HASH') {
4321: if (keys(%{$usertypes}) > 0) {
4322: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 4323: $numinrow,$othertitle,'cansearch',
4324: $rowtotal);
1.277 raeburn 4325: $cansrchrow = 1;
1.25 raeburn 4326: }
1.23 raeburn 4327: }
1.277 raeburn 4328: if ($cansrchrow) {
4329: $$rowtotal ++;
4330: $datatable .= '<tr>';
4331: } else {
4332: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 4333: }
1.277 raeburn 4334: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
4335: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
4336: foreach my $title (@{$titleorder}) {
4337: if (defined($searchtitles->{$title})) {
4338: my $check = ' ';
4339: if (ref($settings) eq 'HASH') {
4340: if (ref($settings->{'searchby'}) eq 'ARRAY') {
4341: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
4342: $check = ' checked="checked" ';
4343: }
1.39 raeburn 4344: }
1.25 raeburn 4345: }
1.277 raeburn 4346: $datatable .= '<td class="LC_left_item">'.
4347: '<span class="LC_nobreak"><label>'.
4348: '<input type="checkbox" name="searchby" '.
4349: 'value="'.$title.'"'.$check.'/>'.
4350: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 4351: }
4352: }
1.277 raeburn 4353: $datatable .= '</tr></table></td></tr>';
4354: $$rowtotal ++;
4355: if ($cansrchrow) {
4356: $datatable .= '<tr class="LC_odd_row">';
4357: } else {
4358: $datatable .= '<tr>';
4359: }
4360: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
4361: '<td class="LC_left_item" colspan="2">'.
4362: '<span class="LC_nobreak"><label>'.
4363: '<input type="checkbox" name="searchtypes" '.
4364: $exacton.' value="exact" />'.&mt('Exact match').
4365: '</label> '.
4366: '<label><input type="checkbox" name="searchtypes" '.
4367: $beginson.' value="begins" />'.&mt('Begins with').
4368: '</label> '.
4369: '<label><input type="checkbox" name="searchtypes" '.
4370: $containson.' value="contains" />'.&mt('Contains').
4371: '</label></span></td></tr>';
4372: $$rowtotal ++;
1.26 raeburn 4373: } else {
1.277 raeburn 4374: my $domsrchon = ' checked="checked" ';
4375: my $domsrchoff = ' ';
4376: my $domlocalon = ' ';
4377: my $domlocaloff = ' checked="checked" ';
4378: if (ref($settings) eq 'HASH') {
4379: if ($settings->{'lclocalonly'} eq '1') {
4380: $domlocalon = $domlocaloff;
4381: $domlocaloff = ' ';
4382: }
4383: if ($settings->{'lcavailable'} eq '0') {
4384: $domsrchoff = $domsrchon;
4385: $domsrchon = ' ';
4386: }
4387: }
4388: $datatable='<tr class="LC_odd_row">'.
4389: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
4390: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4391: '<input type="radio" name="dirsrch_domavailable"'.
4392: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
4393: '<label><input type="radio" name="dirsrch_domavailable"'.
4394: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4395: '</tr><tr>'.
4396: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
4397: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4398: '<input type="radio" name="dirsrch_domlocalonly"'.
4399: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4400: '<label><input type="radio" name="dirsrch_domlocalonly"'.
4401: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4402: '</tr>';
4403: $$rowtotal += 2;
1.26 raeburn 4404: }
1.25 raeburn 4405: return $datatable;
4406: }
4407:
1.28 raeburn 4408: sub print_contacts {
1.286 raeburn 4409: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 4410: my $datatable;
4411: my @contacts = ('adminemail','supportemail');
1.286 raeburn 4412: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340 raeburn 4413: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286 raeburn 4414: if ($position eq 'top') {
4415: if (ref($settings) eq 'HASH') {
4416: foreach my $item (@contacts) {
4417: if (exists($settings->{$item})) {
4418: $to{$item} = $settings->{$item};
4419: }
4420: }
4421: }
4422: } elsif ($position eq 'middle') {
4423: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350 raeburn 4424: 'updatesmail','idconflictsmail','hostipmail');
1.288 raeburn 4425: foreach my $type (@mailings) {
4426: $otheremails{$type} = '';
4427: }
1.340 raeburn 4428: } elsif ($position eq 'lower') {
4429: if (ref($settings) eq 'HASH') {
4430: if (ref($settings->{'lonstatus'}) eq 'HASH') {
4431: %lonstatus = %{$settings->{'lonstatus'}};
4432: }
4433: }
1.286 raeburn 4434: } else {
4435: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 4436: foreach my $type (@mailings) {
4437: $otheremails{$type} = '';
4438: }
1.286 raeburn 4439: $bccemails{'helpdeskmail'} = '';
4440: $bccemails{'otherdomsmail'} = '';
4441: $includestr{'helpdeskmail'} = '';
4442: $includestr{'otherdomsmail'} = '';
4443: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
4444: }
1.28 raeburn 4445: if (ref($settings) eq 'HASH') {
1.340 raeburn 4446: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4447: foreach my $type (@mailings) {
4448: if (exists($settings->{$type})) {
4449: if (ref($settings->{$type}) eq 'HASH') {
4450: foreach my $item (@contacts) {
4451: if ($settings->{$type}{$item}) {
4452: $checked{$type}{$item} = ' checked="checked" ';
4453: }
4454: }
4455: $otheremails{$type} = $settings->{$type}{'others'};
4456: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4457: $bccemails{$type} = $settings->{$type}{'bcc'};
4458: if ($settings->{$type}{'include'} ne '') {
4459: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4460: $includestr{$type} = &unescape($includestr{$type});
4461: }
4462: }
4463: }
4464: } elsif ($type eq 'lonstatusmail') {
4465: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
4466: }
1.28 raeburn 4467: }
4468: }
1.286 raeburn 4469: if ($position eq 'bottom') {
4470: foreach my $type (@mailings) {
4471: $bccemails{$type} = $settings->{$type}{'bcc'};
4472: if ($settings->{$type}{'include'} ne '') {
4473: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4474: $includestr{$type} = &unescape($includestr{$type});
4475: }
4476: }
4477: if (ref($settings->{'helpform'}) eq 'HASH') {
4478: if (ref($fields) eq 'ARRAY') {
4479: foreach my $field (@{$fields}) {
4480: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 4481: }
1.286 raeburn 4482: }
4483: if (exists($settings->{'helpform'}{'maxsize'})) {
4484: $maxsize = $settings->{'helpform'}{'maxsize'};
4485: } else {
1.289 raeburn 4486: $maxsize = '1.0';
1.286 raeburn 4487: }
4488: } else {
4489: if (ref($fields) eq 'ARRAY') {
4490: foreach my $field (@{$fields}) {
4491: $currfield{$field} = 'yes';
1.134 raeburn 4492: }
1.28 raeburn 4493: }
1.286 raeburn 4494: $maxsize = '1.0';
1.28 raeburn 4495: }
4496: }
4497: } else {
1.286 raeburn 4498: if ($position eq 'top') {
4499: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
4500: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
4501: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
4502: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 4503: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4504: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
4505: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
4506: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350 raeburn 4507: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4508: } elsif ($position eq 'bottom') {
4509: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
4510: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
4511: if (ref($fields) eq 'ARRAY') {
4512: foreach my $field (@{$fields}) {
4513: $currfield{$field} = 'yes';
4514: }
4515: }
4516: $maxsize = '1.0';
4517: }
1.28 raeburn 4518: }
4519: my ($titles,$short_titles) = &contact_titles();
4520: my $rownum = 0;
4521: my $css_class;
1.286 raeburn 4522: if ($position eq 'top') {
4523: foreach my $item (@contacts) {
4524: $css_class = $rownum%2?' class="LC_odd_row"':'';
4525: $datatable .= '<tr'.$css_class.'>'.
4526: '<td><span class="LC_nobreak">'.$titles->{$item}.
4527: '</span></td><td class="LC_right_item">'.
4528: '<input type="text" name="'.$item.'" value="'.
4529: $to{$item}.'" /></td></tr>';
4530: $rownum ++;
4531: }
1.315 raeburn 4532: } elsif ($position eq 'bottom') {
4533: $css_class = $rownum%2?' class="LC_odd_row"':'';
4534: $datatable .= '<tr'.$css_class.'>'.
4535: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
4536: &mt('(e-mail, subject, and description always shown)').
4537: '</td><td class="LC_left_item">';
4538: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
4539: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
4540: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
4541: foreach my $field (@{$fields}) {
4542: $datatable .= '<tr><td>'.$fieldtitles->{$field};
4543: if (($field eq 'screenshot') || ($field eq 'cc')) {
4544: $datatable .= ' '.&mt('(logged-in users)');
4545: }
4546: $datatable .='</td><td>';
4547: my $clickaction;
4548: if ($field eq 'screenshot') {
4549: $clickaction = ' onclick="screenshotSize(this);"';
4550: }
4551: if (ref($possoptions->{$field}) eq 'ARRAY') {
4552: foreach my $option (@{$possoptions->{$field}}) {
4553: my $checked;
4554: if ($currfield{$field} eq $option) {
4555: $checked = ' checked="checked"';
4556: }
4557: $datatable .= '<span class="LC_nobreak"><label>'.
4558: '<input type="radio" name="helpform_'.$field.'" '.
4559: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
4560: '</label></span>'.(' 'x2);
4561: }
4562: }
4563: if ($field eq 'screenshot') {
4564: my $display;
4565: if ($currfield{$field} eq 'no') {
4566: $display = ' style="display:none"';
4567: }
1.334 raeburn 4568: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315 raeburn 4569: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
4570: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
4571: }
4572: $datatable .= '</td></tr>';
4573: }
4574: $datatable .= '</table>';
4575: }
4576: $datatable .= '</td></tr>'."\n";
4577: $rownum ++;
4578: }
1.340 raeburn 4579: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4580: foreach my $type (@mailings) {
4581: $css_class = $rownum%2?' class="LC_odd_row"':'';
4582: $datatable .= '<tr'.$css_class.'>'.
4583: '<td><span class="LC_nobreak">'.
4584: $titles->{$type}.': </span></td>'.
4585: '<td class="LC_left_item">';
4586: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4587: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
4588: }
4589: $datatable .= '<span class="LC_nobreak">';
4590: foreach my $item (@contacts) {
4591: $datatable .= '<label>'.
4592: '<input type="checkbox" name="'.$type.'"'.
4593: $checked{$type}{$item}.
4594: ' value="'.$item.'" />'.$short_titles->{$item}.
4595: '</label> ';
4596: }
4597: $datatable .= '</span><br />'.&mt('Others').': '.
4598: '<input type="text" name="'.$type.'_others" '.
4599: 'value="'.$otheremails{$type}.'" />';
4600: my %locchecked;
4601: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4602: foreach my $loc ('s','b') {
4603: if ($includeloc{$type} eq $loc) {
4604: $locchecked{$loc} = ' checked="checked"';
4605: last;
4606: }
4607: }
4608: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
4609: '<input type="text" name="'.$type.'_bcc" '.
4610: 'value="'.$bccemails{$type}.'" /></fieldset>'.
4611: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4612: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4613: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286 raeburn 4614: '<span class="LC_nobreak">'.&mt('Location:').' '.
4615: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4616: (' 'x2).
4617: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4618: '</span></fieldset>';
4619: }
4620: $datatable .= '</td></tr>'."\n";
4621: $rownum ++;
4622: }
1.28 raeburn 4623: }
1.286 raeburn 4624: if ($position eq 'middle') {
4625: my %choices;
1.340 raeburn 4626: my $corelink = &core_link_msu();
4627: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286 raeburn 4628: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340 raeburn 4629: $corelink);
4630: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
4631: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286 raeburn 4632: my %defaultchecked = ('reporterrors' => 'on',
1.340 raeburn 4633: 'reportupdates' => 'on',
4634: 'reportstatus' => 'on');
1.286 raeburn 4635: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4636: \%choices,$rownum);
4637: $datatable .= $reports;
1.340 raeburn 4638: } elsif ($position eq 'lower') {
1.378 raeburn 4639: my (%current,%excluded,%weights);
1.340 raeburn 4640: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
4641: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.378 raeburn 4642: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.340 raeburn 4643: } else {
1.378 raeburn 4644: $current{'errorthreshold'} = $defaults->{'threshold'};
1.340 raeburn 4645: }
4646: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.378 raeburn 4647: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.340 raeburn 4648: } else {
1.378 raeburn 4649: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.340 raeburn 4650: }
4651: if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341 raeburn 4652: foreach my $type ('E','W','N','U') {
1.340 raeburn 4653: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
4654: $weights{$type} = $lonstatus{'weights'}{$type};
4655: } else {
4656: $weights{$type} = $defaults->{$type};
4657: }
4658: }
4659: } else {
1.341 raeburn 4660: foreach my $type ('E','W','N','U') {
1.340 raeburn 4661: $weights{$type} = $defaults->{$type};
4662: }
4663: }
4664: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
4665: if (@{$lonstatus{'excluded'}} > 0) {
4666: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
4667: }
4668: }
1.425 raeburn 4669: foreach my $item ('errorthreshold','errorsysmail') {
1.378 raeburn 4670: $css_class = $rownum%2?' class="LC_odd_row"':'';
4671: $datatable .= '<tr'.$css_class.'>'.
4672: '<td class="LC_left_item"><span class="LC_nobreak">'.
4673: $titles->{$item}.
4674: '</span></td><td class="LC_left_item">'.
4675: '<input type="text" name="'.$item.'" value="'.
4676: $current{$item}.'" size="5" /></td></tr>';
4677: $rownum ++;
4678: }
1.340 raeburn 4679: $css_class = $rownum%2?' class="LC_odd_row"':'';
4680: $datatable .= '<tr'.$css_class.'>'.
4681: '<td class="LC_left_item">'.
4682: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
4683: '</span></td><td class="LC_left_item"><table><tr>';
1.341 raeburn 4684: foreach my $type ('E','W','N','U') {
1.340 raeburn 4685: $datatable .= '<td>'.$names->{$type}.'<br />'.
4686: '<input type="text" name="errorweights_'.$type.'" value="'.
4687: $weights{$type}.'" size="5" /></td>';
4688: }
4689: $datatable .= '</tr></table></tr>';
4690: $rownum ++;
4691: $css_class = $rownum%2?' class="LC_odd_row"':'';
4692: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
4693: $titles->{'errorexcluded'}.'</td>'.
4694: '<td class="LC_left_item"><table>';
4695: my $numinrow = 4;
4696: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
4697: for (my $i=0; $i<@ids; $i++) {
4698: my $rem = $i%($numinrow);
4699: if ($rem == 0) {
4700: if ($i > 0) {
4701: $datatable .= '</tr>';
4702: }
4703: $datatable .= '<tr>';
4704: }
4705: my $check;
4706: if ($excluded{$ids[$i]}) {
4707: $check = ' checked="checked" ';
4708: }
4709: $datatable .= '<td class="LC_left_item">'.
4710: '<span class="LC_nobreak"><label>'.
4711: '<input type="checkbox" name="errorexcluded" '.
4712: 'value="'.$ids[$i].'"'.$check.' />'.
4713: $ids[$i].'</label></span></td>';
4714: }
4715: my $colsleft = $numinrow - @ids%($numinrow);
4716: if ($colsleft > 1 ) {
4717: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4718: ' </td>';
4719: } elsif ($colsleft == 1) {
4720: $datatable .= '<td class="LC_left_item"> </td>';
4721: }
4722: $datatable .= '</tr></table></td></tr>';
4723: $rownum ++;
1.286 raeburn 4724: } elsif ($position eq 'bottom') {
1.315 raeburn 4725: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4726: my (@posstypes,%usertypeshash);
4727: if (ref($types) eq 'ARRAY') {
4728: @posstypes = @{$types};
4729: }
4730: if (@posstypes) {
4731: if (ref($usertypes) eq 'HASH') {
4732: %usertypeshash = %{$usertypes};
4733: }
4734: my @overridden;
4735: my $numinrow = 4;
4736: if (ref($settings) eq 'HASH') {
4737: if (ref($settings->{'overrides'}) eq 'HASH') {
4738: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
4739: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
4740: push(@overridden,$key);
4741: foreach my $item (@contacts) {
4742: if ($settings->{'overrides'}{$key}{$item}) {
4743: $checked{'override_'.$key}{$item} = ' checked="checked" ';
4744: }
4745: }
4746: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
4747: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
4748: $includeloc{'override_'.$key} = '';
4749: $includestr{'override_'.$key} = '';
4750: if ($settings->{'overrides'}{$key}{'include'} ne '') {
1.425 raeburn 4751: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
1.315 raeburn 4752: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
4753: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
4754: }
1.286 raeburn 4755: }
4756: }
4757: }
1.315 raeburn 4758: }
4759: my $customclass = 'LC_helpdesk_override';
4760: my $optionsprefix = 'LC_options_helpdesk_';
4761:
4762: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
4763: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
4764: $numinrow,$othertitle,'overrides',
4765: \$rownum,$onclicktypes,$customclass);
4766: $rownum ++;
4767: $usertypeshash{'default'} = $othertitle;
4768: foreach my $status (@posstypes) {
4769: my $css_class;
4770: if ($rownum%2) {
4771: $css_class = 'LC_odd_row ';
4772: }
4773: $css_class .= $customclass;
4774: my $rowid = $optionsprefix.$status;
4775: my $hidden = 1;
4776: my $currstyle = 'display:none';
4777: if (grep(/^\Q$status\E$/,@overridden)) {
4778: $currstyle = 'display:table-row';
4779: $hidden = 0;
4780: }
4781: my $key = 'override_'.$status;
4782: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
4783: $includeloc{$key},$includestr{$key},$status,$rowid,
4784: $usertypeshash{$status},$css_class,$currstyle,
4785: \@contacts,$short_titles);
4786: unless ($hidden) {
4787: $rownum ++;
1.286 raeburn 4788: }
4789: }
1.134 raeburn 4790: }
1.28 raeburn 4791: }
1.30 raeburn 4792: $$rowtotal += $rownum;
1.28 raeburn 4793: return $datatable;
4794: }
4795:
1.340 raeburn 4796: sub core_link_msu {
4797: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
4798: &mt('LON-CAPA core group - MSU'),600,500);
4799: }
4800:
1.315 raeburn 4801: sub overridden_helpdesk {
4802: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
4803: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
4804: my $class = 'LC_left_item';
4805: if ($css_class) {
4806: $css_class = ' class="'.$css_class.'"';
4807: }
4808: if ($rowid) {
4809: $rowid = ' id="'.$rowid.'"';
4810: }
4811: if ($rowstyle) {
4812: $rowstyle = ' style="'.$rowstyle.'"';
4813: }
4814: my ($output,$description);
4815: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
4816: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
4817: "<td>$description</td>\n".
4818: '<td class="'.$class.'" colspan="2">'.
4819: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
4820: '<span class="LC_nobreak">';
4821: if (ref($contacts) eq 'ARRAY') {
4822: foreach my $item (@{$contacts}) {
4823: my $check;
4824: if (ref($checked) eq 'HASH') {
4825: $check = $checked->{$item};
4826: }
4827: my $title;
4828: if (ref($short_titles) eq 'HASH') {
1.425 raeburn 4829: $title = $short_titles->{$item};
1.315 raeburn 4830: }
4831: $output .= '<label>'.
4832: '<input type="checkbox" name="override_'.$type.'"'.$check.
4833: ' value="'.$item.'" />'.$title.'</label> ';
4834: }
4835: }
4836: $output .= '</span><br />'.&mt('Others').': '.
4837: '<input type="text" name="override_'.$type.'_others" '.
4838: 'value="'.$otheremails.'" />';
4839: my %locchecked;
4840: foreach my $loc ('s','b') {
4841: if ($includeloc eq $loc) {
4842: $locchecked{$loc} = ' checked="checked"';
4843: last;
4844: }
4845: }
4846: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4847: '<input type="text" name="override_'.$type.'_bcc" '.
4848: 'value="'.$bccemails.'" /></fieldset>'.
4849: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4850: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4851: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315 raeburn 4852: '<span class="LC_nobreak">'.&mt('Location:').' '.
4853: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4854: (' 'x2).
4855: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4856: '</span></fieldset>'.
4857: '</td></tr>'."\n";
4858: return $output;
4859: }
4860:
1.286 raeburn 4861: sub contacts_javascript {
4862: return <<"ENDSCRIPT";
4863:
4864: <script type="text/javascript">
4865: // <![CDATA[
4866:
4867: function screenshotSize(field) {
4868: if (document.getElementById('help_screenshotsize')) {
4869: if (field.value == 'no') {
1.289 raeburn 4870: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 4871: } else {
4872: document.getElementById('help_screenshotsize').style.display="";
4873: }
4874: }
4875: return;
4876: }
4877:
1.315 raeburn 4878: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4879: if (form.elements[checkbox].length != undefined) {
4880: var count = 0;
4881: if (docount) {
4882: for (var i=0; i<form.elements[checkbox].length; i++) {
4883: if (form.elements[checkbox][i].checked) {
4884: count ++;
4885: }
4886: }
4887: }
4888: for (var i=0; i<form.elements[checkbox].length; i++) {
4889: var type = form.elements[checkbox][i].value;
4890: if (document.getElementById(prefix+type)) {
4891: if (form.elements[checkbox][i].checked) {
4892: document.getElementById(prefix+type).style.display = 'table-row';
4893: if (count % 2 == 1) {
4894: document.getElementById(prefix+type).className = target+' LC_odd_row';
4895: } else {
4896: document.getElementById(prefix+type).className = target;
4897: }
4898: count ++;
4899: } else {
4900: document.getElementById(prefix+type).style.display = 'none';
4901: }
4902: }
4903: }
4904: }
4905: return;
4906: }
4907:
1.286 raeburn 4908: // ]]>
4909: </script>
4910:
4911: ENDSCRIPT
4912: }
4913:
1.118 jms 4914: sub print_helpsettings {
1.282 raeburn 4915: my ($position,$dom,$settings,$rowtotal) = @_;
4916: my $confname = $dom.'-domainconfig';
1.285 raeburn 4917: my $formname = 'display';
1.168 raeburn 4918: my ($datatable,$itemcount);
1.282 raeburn 4919: if ($position eq 'top') {
4920: $itemcount = 1;
4921: my (%choices,%defaultchecked,@toggles);
4922: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4923: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4924: &mt('LON-CAPA bug tracker'),600,500));
4925: %defaultchecked = ('submitbugs' => 'on');
4926: @toggles = ('submitbugs');
4927: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4928: \%choices,$itemcount);
4929: $$rowtotal ++;
4930: } else {
4931: my $css_class;
4932: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 4933: my (%customroles,%ordered,%current);
1.301 raeburn 4934: if (ref($settings) eq 'HASH') {
4935: if (ref($settings->{'adhoc'}) eq 'HASH') {
4936: %current = %{$settings->{'adhoc'}};
4937: }
1.285 raeburn 4938: }
4939: my $count = 0;
4940: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 4941: if ($key=~/^rolesdef\_(\w+)$/) {
4942: my $rolename = $1;
1.285 raeburn 4943: my (%privs,$order);
1.282 raeburn 4944: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4945: $customroles{$rolename} = \%privs;
1.285 raeburn 4946: if (ref($current{$rolename}) eq 'HASH') {
4947: $order = $current{$rolename}{'order'};
4948: }
4949: if ($order eq '') {
4950: $order = $count;
4951: }
4952: $ordered{$order} = $rolename;
4953: $count++;
4954: }
4955: }
4956: my $maxnum = scalar(keys(%ordered));
4957: my @roles_by_num = ();
4958: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4959: push(@roles_by_num,$item);
4960: }
4961: my $context = 'domprefs';
4962: my $crstype = 'Course';
4963: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 4964: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 4965: my ($numstatustypes,@jsarray);
4966: if (ref($types) eq 'ARRAY') {
4967: if (@{$types} > 0) {
4968: $numstatustypes = scalar(@{$types});
4969: push(@accesstypes,'status');
4970: @jsarray = ('bystatus');
1.282 raeburn 4971: }
4972: }
1.290 raeburn 4973: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 4974: if (keys(%domhelpdesk)) {
4975: push(@accesstypes,('inc','exc'));
4976: push(@jsarray,('notinc','notexc'));
4977: }
4978: my $hiddenstr = join("','",@jsarray);
1.282 raeburn 4979: my $context = 'domprefs';
4980: my $crstype = 'Course';
1.285 raeburn 4981: my $prefix = 'helproles_';
4982: my $add_class = 'LC_hidden';
4983: foreach my $num (@roles_by_num) {
4984: my $role = $ordered{$num};
4985: my ($desc,$access,@statuses);
4986: if (ref($current{$role}) eq 'HASH') {
4987: $desc = $current{$role}{'desc'};
4988: $access = $current{$role}{'access'};
4989: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4990: @statuses = @{$current{$role}{'insttypes'}};
4991: }
4992: }
4993: if ($desc eq '') {
4994: $desc = $role;
4995: }
4996: my $identifier = 'custhelp'.$num;
1.282 raeburn 4997: my %full=();
4998: my %levels= (
4999: course => {},
5000: domain => {},
5001: system => {},
5002: );
5003: my %levelscurrent=(
5004: course => {},
5005: domain => {},
5006: system => {},
5007: );
5008: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
5009: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
5010: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 5011: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 5012: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 5013: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
5014: for (my $k=0; $k<=$maxnum; $k++) {
5015: my $vpos = $k+1;
5016: my $selstr;
5017: if ($k == $num) {
5018: $selstr = ' selected="selected" ';
5019: }
5020: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5021: }
5022: $datatable .= '</select>'.(' 'x2).
5023: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
5024: '</td>'.
5025: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
5026: &mt('Name shown to users:').
5027: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
5028: '</fieldset>'.
5029: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
5030: $othertitle,$usertypes,$types,\%domhelpdesk).
5031: '<fieldset>'.
5032: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 5033: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 5034: \%levelscurrent,$identifier,
5035: 'LC_hidden',$prefix.$num.'_privs').
5036: '</fieldset></td>';
1.282 raeburn 5037: $itemcount ++;
5038: }
5039: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5040: my $newcust = 'custhelp'.$count;
5041: my (%privs,%levelscurrent);
5042: my %full=();
5043: my %levels= (
5044: course => {},
5045: domain => {},
5046: system => {},
5047: );
5048: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
5049: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 5050: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 5051: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 5052: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
5053: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
5054: for (my $k=0; $k<$maxnum+1; $k++) {
5055: my $vpos = $k+1;
5056: my $selstr;
5057: if ($k == $maxnum) {
5058: $selstr = ' selected="selected" ';
5059: }
5060: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5061: }
5062: $datatable .= '</select> '."\n".
1.282 raeburn 5063: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
5064: '</label></span></td>'.
1.285 raeburn 5065: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
5066: '<span class="LC_nobreak">'.
5067: &mt('Internal name:').
5068: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
5069: '</span>'.(' 'x4).
5070: '<span class="LC_nobreak">'.
5071: &mt('Name shown to users:').
5072: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
5073: '</span></fieldset>'.
5074: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
5075: $usertypes,$types,\%domhelpdesk).
5076: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 5077: &Apache::lonuserutils::custom_role_header($context,$crstype,
5078: \@templateroles,$newcust).
5079: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
5080: \%levelscurrent,$newcust).
1.334 raeburn 5081: '</fieldset>'.
5082: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
5083: '</td></tr>';
1.282 raeburn 5084: $count ++;
5085: $$rowtotal += $count;
5086: }
1.166 raeburn 5087: return $datatable;
1.121 raeburn 5088: }
5089:
1.285 raeburn 5090: sub adhocbutton {
5091: my ($prefix,$num,$field,$visibility) = @_;
5092: my %lt = &Apache::lonlocal::texthash(
5093: show => 'Show details',
5094: hide => 'Hide details',
5095: );
5096: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
5097: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
5098: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
5099: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
5100: }
5101:
5102: sub helpsettings_javascript {
5103: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
5104: return unless(ref($roles_by_num) eq 'ARRAY');
5105: my %html_js_lt = &Apache::lonlocal::texthash(
5106: show => 'Show details',
5107: hide => 'Hide details',
5108: );
5109: &html_escape(\%html_js_lt);
5110: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
5111: return <<"ENDSCRIPT";
5112: <script type="text/javascript">
5113: // <![CDATA[
5114:
5115: function reorderHelpRoles(form,item) {
5116: var changedVal;
5117: $jstext
5118: var newpos = 'helproles_${total}_pos';
5119: var maxh = 1 + $total;
5120: var current = new Array();
5121: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5122: if (item == newpos) {
5123: changedVal = newitemVal;
5124: } else {
5125: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5126: current[newitemVal] = newpos;
5127: }
5128: for (var i=0; i<helproles.length; i++) {
5129: var elementName = 'helproles_'+helproles[i]+'_pos';
5130: if (elementName != item) {
5131: if (form.elements[elementName]) {
5132: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5133: current[currVal] = elementName;
5134: }
5135: }
5136: }
5137: var oldVal;
5138: for (var j=0; j<maxh; j++) {
5139: if (current[j] == undefined) {
5140: oldVal = j;
5141: }
5142: }
5143: if (oldVal < changedVal) {
5144: for (var k=oldVal+1; k<=changedVal ; k++) {
5145: var elementName = current[k];
5146: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5147: }
5148: } else {
5149: for (var k=changedVal; k<oldVal; k++) {
5150: var elementName = current[k];
5151: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5152: }
5153: }
5154: return;
5155: }
5156:
5157: function helpdeskAccess(num) {
5158: var curraccess = null;
5159: if (document.$formname.elements['helproles_'+num+'_access'].length) {
5160: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
5161: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
5162: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
5163: }
5164: }
5165: }
5166: var shown = Array();
5167: var hidden = Array();
5168: if (curraccess == 'none') {
5169: hidden = Array('$hiddenstr');
5170: } else {
5171: if (curraccess == 'status') {
5172: shown = Array('bystatus');
5173: hidden = Array('notinc','notexc');
5174: } else {
5175: if (curraccess == 'exc') {
5176: shown = Array('notexc');
5177: hidden = Array('notinc','bystatus');
5178: }
5179: if (curraccess == 'inc') {
5180: shown = Array('notinc');
5181: hidden = Array('notexc','bystatus');
5182: }
1.293 raeburn 5183: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 5184: hidden = Array('notinc','notexc','bystatus');
5185: }
5186: }
5187: }
5188: if (hidden.length > 0) {
5189: for (var i=0; i<hidden.length; i++) {
5190: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
5191: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
5192: }
5193: }
5194: }
5195: if (shown.length > 0) {
5196: for (var i=0; i<shown.length; i++) {
5197: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
5198: if (shown[i] == 'privs') {
5199: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
5200: } else {
5201: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
5202: }
5203: }
5204: }
5205: }
5206: return;
5207: }
5208:
5209: function toggleHelpdeskItem(num,field) {
5210: if (document.getElementById('helproles_'+num+'_'+field)) {
5211: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 5212: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 5213: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
5214: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5215: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
5216: }
5217: } else {
5218: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
5219: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5220: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
5221: }
5222: }
5223: }
5224: return;
5225: }
5226:
5227: // ]]>
5228: </script>
5229:
5230: ENDSCRIPT
5231: }
5232:
5233: sub helpdeskroles_access {
5234: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
5235: $usertypes,$types,$domhelpdesk) = @_;
5236: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
5237: my %lt = &Apache::lonlocal::texthash(
5238: 'rou' => 'Role usage',
5239: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 5240: 'all' => 'All with domain helpdesk or helpdesk assistant role',
5241: 'dh' => 'All with domain helpdesk role',
5242: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 5243: 'none' => 'None',
5244: 'status' => 'Determined based on institutional status',
5245: 'inc' => 'Include all, but exclude specific personnel',
5246: 'exc' => 'Exclude all, but include specific personnel',
5247: );
5248: my %usecheck = (
5249: all => ' checked="checked"',
5250: );
5251: my %displaydiv = (
5252: status => 'none',
5253: inc => 'none',
5254: exc => 'none',
5255: priv => 'block',
5256: );
5257: my $output;
5258: if (ref($current) eq 'HASH') {
5259: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
5260: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
5261: $usecheck{$current->{access}} = $usecheck{'all'};
5262: delete($usecheck{'all'});
5263: if ($current->{access} =~ /^(status|inc|exc)$/) {
5264: my $access = $1;
5265: $displaydiv{$access} = 'inline';
5266: } elsif ($current->{access} eq 'none') {
5267: $displaydiv{'priv'} = 'none';
5268: }
5269: }
5270: }
5271: }
5272: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
5273: '<p>'.$lt{'whi'}.'</p>';
5274: foreach my $access (@{$accesstypes}) {
5275: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
5276: ' onclick="helpdeskAccess('."'$num'".');" />'.
5277: $lt{$access}.'</label>';
5278: if ($access eq 'status') {
5279: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
5280: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
5281: $othertitle,$usertypes,$types).
5282: '</div>';
5283: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
5284: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
5285: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5286: '</div>';
5287: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
5288: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
5289: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5290: '</div>';
5291: }
5292: $output .= '</p>';
5293: }
5294: $output .= '</fieldset>';
5295: return $output;
5296: }
5297:
1.121 raeburn 5298: sub radiobutton_prefs {
1.192 raeburn 5299: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.385 raeburn 5300: $additional,$align,$firstval) = @_;
1.121 raeburn 5301: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
5302: (ref($choices) eq 'HASH'));
5303:
1.170 raeburn 5304: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 5305:
5306: foreach my $item (@{$toggles}) {
5307: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 5308: $checkedon{$item} = ' checked="checked" ';
5309: $checkedoff{$item} = ' ';
1.121 raeburn 5310: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 5311: $checkedoff{$item} = ' checked="checked" ';
5312: $checkedon{$item} = ' ';
5313: }
5314: }
5315: if (ref($settings) eq 'HASH') {
1.121 raeburn 5316: foreach my $item (@{$toggles}) {
1.118 jms 5317: if ($settings->{$item} eq '1') {
5318: $checkedon{$item} = ' checked="checked" ';
5319: $checkedoff{$item} = ' ';
5320: } elsif ($settings->{$item} eq '0') {
5321: $checkedoff{$item} = ' checked="checked" ';
5322: $checkedon{$item} = ' ';
5323: }
5324: }
1.121 raeburn 5325: }
1.192 raeburn 5326: if ($onclick) {
5327: $onclick = ' onclick="'.$onclick.'"';
5328: }
1.121 raeburn 5329: foreach my $item (@{$toggles}) {
1.118 jms 5330: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 5331: $datatable .=
1.306 raeburn 5332: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 5333: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 5334: '</span></td>';
5335: if ($align eq 'left') {
5336: $datatable .= '<td class="LC_left_item">';
5337: } else {
5338: $datatable .= '<td class="LC_right_item">';
5339: }
1.385 raeburn 5340: $datatable .= '<span class="LC_nobreak">';
5341: if ($firstval eq 'no') {
5342: $datatable .=
5343: '<label><input type="radio" name="'.
5344: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
5345: '</label> <label><input type="radio" name="'.$item.'" '.
5346: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
5347: } else {
5348: $datatable .=
5349: '<label><input type="radio" name="'.
5350: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
5351: '</label> <label><input type="radio" name="'.$item.'" '.
5352: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
5353: }
5354: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 5355: $itemcount ++;
1.121 raeburn 5356: }
5357: return ($datatable,$itemcount);
5358: }
5359:
1.267 raeburn 5360: sub print_ltitools {
1.421 raeburn 5361: my ($position,$dom,$settings,$rowtotal) = @_;
5362: my (%rules,%encrypt,%privkeys,%linkprot);
1.267 raeburn 5363: if (ref($settings) eq 'HASH') {
1.421 raeburn 5364: if ($position eq 'top') {
5365: if (exists($settings->{'encrypt'})) {
5366: if (ref($settings->{'encrypt'}) eq 'HASH') {
5367: foreach my $key (keys(%{$settings->{'encrypt'}})) {
5368: $encrypt{'toolsec_'.$key} = $settings->{'encrypt'}{$key};
1.324 raeburn 5369: }
5370: }
1.267 raeburn 5371: }
1.421 raeburn 5372: if (exists($settings->{'private'})) {
5373: if (ref($settings->{'private'}) eq 'HASH') {
5374: if (ref($settings->{'private'}) eq 'HASH') {
5375: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
5376: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
1.267 raeburn 5377: }
5378: }
5379: }
5380: }
1.421 raeburn 5381: } elsif ($position eq 'middle') {
5382: if (exists($settings->{'rules'})) {
5383: if (ref($settings->{'rules'}) eq 'HASH') {
5384: %rules = %{$settings->{'rules'}};
1.273 raeburn 5385: }
5386: }
1.421 raeburn 5387: } else {
5388: foreach my $key ('encrypt','private','rules') {
5389: if (exists($settings->{$key})) {
5390: delete($settings->{$key});
1.267 raeburn 5391: }
5392: }
5393: }
5394: }
1.421 raeburn 5395: my $datatable;
5396: my $itemcount = 1;
5397: if ($position eq 'top') {
5398: $datatable = &secrets_form($dom,'toolsec',\%encrypt,\%privkeys,$rowtotal);
5399: } elsif ($position eq 'middle') {
5400: $datatable = &password_rules('toolsecrets',\$itemcount,\%rules);
5401: $$rowtotal += $itemcount;
5402: } else {
5403: $datatable = &Apache::courseprefs::print_ltitools($dom,'',$settings,\$rowtotal,'','','domain');
1.267 raeburn 5404: }
5405: return $datatable;
5406: }
5407:
5408: sub ltitools_names {
5409: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 5410: 'title' => 'Title',
5411: 'version' => 'Version',
5412: 'msgtype' => 'Message Type',
1.323 raeburn 5413: 'sigmethod' => 'Signature Method',
1.296 raeburn 5414: 'url' => 'URL',
5415: 'key' => 'Key',
1.322 raeburn 5416: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 5417: 'secret' => 'Secret',
1.425 raeburn 5418: 'icon' => 'Icon',
1.324 raeburn 5419: 'user' => 'User',
1.296 raeburn 5420: 'fullname' => 'Full Name',
5421: 'firstname' => 'First Name',
5422: 'lastname' => 'Last Name',
5423: 'email' => 'E-mail',
5424: 'roles' => 'Role',
1.298 raeburn 5425: 'window' => 'Window',
5426: 'tab' => 'Tab',
1.296 raeburn 5427: 'iframe' => 'iFrame',
5428: 'height' => 'Height',
5429: 'width' => 'Width',
5430: 'linktext' => 'Default Link Text',
5431: 'explanation' => 'Default Explanation',
5432: 'passback' => 'Tool can return grades:',
5433: 'roster' => 'Tool can retrieve roster:',
5434: 'crstarget' => 'Display target',
5435: 'crslabel' => 'Course label',
1.425 raeburn 5436: 'crstitle' => 'Course title',
1.296 raeburn 5437: 'crslinktext' => 'Link Text',
5438: 'crsexplanation' => 'Explanation',
1.318 raeburn 5439: 'crsappend' => 'Provider URL',
1.267 raeburn 5440: );
5441: return %lt;
5442: }
5443:
1.421 raeburn 5444: sub secrets_form {
5445: my ($dom,$context,$encrypt,$privkeys,$rowtotal) = @_;
5446: my @ids=&Apache::lonnet::current_machine_ids();
5447: my %servers = &Apache::lonnet::get_servers($dom,'library');
5448: my $primary = &Apache::lonnet::domain($dom,'primary');
5449: my ($css_class,$extra,$numshown,$itemcount,$output);
5450: $itemcount = 0;
5451: foreach my $hostid (sort(keys(%servers))) {
5452: my ($showextra,$divsty,$switch);
5453: if ($hostid eq $primary) {
5454: if ($context eq 'ltisec') {
5455: if (($encrypt->{'ltisec_consumers'}) || ($encrypt->{'ltisec_domlinkprot'})) {
5456: $showextra = 1;
5457: }
5458: if ($encrypt->{'ltisec_crslinkprot'}) {
5459: $showextra = 1;
5460: }
5461: } else {
5462: if (($encrypt->{'toolsec_crs'}) || ($encrypt->{'toolsec_dom'})) {
5463: $showextra = 1;
5464: }
5465: }
5466: unless (grep(/^\Q$hostid\E$/,@ids)) {
5467: $switch = 1;
5468: }
5469: if ($showextra) {
5470: $numshown ++;
5471: $divsty = 'display:inline-block';
5472: } else {
5473: $divsty = 'display:none';
5474: }
5475: $extra .= '<fieldset id="'.$context.'_info_'.$hostid.'" style="'.$divsty.'">'.
5476: '<legend>'.$hostid.'</legend>';
5477: if ($switch) {
5478: my $switchserver = '<a href="/adm/switchserver?otherserver='.$hostid.'&role='.
5479: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
5480: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
5481: if (exists($privkeys->{$hostid})) {
5482: $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" />'.
5483: '<span class="LC_nobreak">'.
5484: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5485: '<span class="LC_nobreak">'.&mt('Change?').
5486: '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5487: (' 'x2).
5488: '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5489: '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5490: '<span class="LC_nobreak"> - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5491: '</span></div>';
5492: } else {
5493: $extra .= '<span class="LC_nobreak">'.
5494: &mt('Key required').' - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5495: '</span>'."\n";
5496: }
5497: } elsif (exists($privkeys->{$hostid})) {
5498: $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" /><span class="LC_nobreak">'.
5499: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5500: '<span class="LC_nobreak">'.&mt('Change?').
5501: '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5502: (' 'x2).
5503: '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5504: '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5505: '<span class="LC_nobreak">'.&mt('New Key').':'.
5506: '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5507: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.'.$context.'_privkey_'.$hostid.'.type='."'text'".' } else { this.form.'.$context.'_privkey_'.$hostid.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
5508: '</span></div>';
5509: } else {
5510: $extra .= '<span class="LC_nobreak">'.&mt('Encryption Key').':'.
5511: '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5512: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.'.$context.'_privkey_'.$hostid.'.type='."'text'".' } else { this.form.'.$context.'_privkey_'.$hostid.'.type='."'password'".' }" />'.&mt('Visible input').'</label>';
5513: }
5514: $extra .= '</fieldset>';
5515: }
5516: }
5517: my (%choices,@toggles,%defaultchecked);
5518: if ($context eq 'ltisec') {
5519: %choices = &Apache::lonlocal::texthash (
5520: ltisec_crslinkprot => 'Encrypt stored link protection secrets defined in courses',
5521: ltisec_domlinkprot => 'Encrypt stored link protection secrets defined in domain',
5522: ltisec_consumers => 'Encrypt stored consumer secrets defined in domain',
5523: );
5524: @toggles = qw(ltisec_crslinkprot ltisec_domlinkprot ltisec_consumers);
5525: %defaultchecked = (
5526: 'ltisec_crslinkprot' => 'off',
5527: 'ltisec_domlinkprot' => 'off',
5528: 'ltisec_consumers' => 'off',
5529: );
5530: } else {
5531: %choices = &Apache::lonlocal::texthash (
5532: toolsec_crs => 'Encrypt stored external tool secrets defined in courses',
5533: toolsec_dom => 'Encrypt stored external tool secrets defined in domain',
5534: );
5535: @toggles = qw(toolsec_crs toolsec_dom);
5536: %defaultchecked = (
5537: 'toolsec_crs' => 'off',
5538: 'toolsec_dom' => 'off',
5539: );
5540: }
5541: my ($onclick,$itemcount);
5542: $onclick = 'javascript:toggleLTIEncKey(this.form,'."'$context'".');';
5543: ($output,$itemcount) = &radiobutton_prefs($encrypt,\@toggles,\%defaultchecked,
5544: \%choices,$itemcount,$onclick,'','left','no');
5545:
5546: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5547: my $noprivkeysty = 'display:inline-block';
5548: if ($numshown) {
5549: $noprivkeysty = 'display:none';
5550: }
5551: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.&mt('Encryption Key(s)').'</td>'.
5552: '<td><div id="'.$context.'_noprivkey" style="'.$noprivkeysty.'" >'.
5553: '<span class="LC_nobreak">'.&mt('Not in use').'</span></div>'.
5554: $extra.
5555: '</td></tr>';
5556: $itemcount ++;
5557: $$rowtotal += $itemcount;
5558: return $output;
5559: }
5560:
1.372 raeburn 5561: sub print_proctoring {
5562: my ($dom,$settings,$rowtotal) = @_;
5563: my $itemcount = 1;
5564: my (%ordered,%providernames,%current,%currentdef);
5565: my $confname = $dom.'-domainconfig';
5566: my $switchserver = &check_switchserver($dom,$confname);
5567: if (ref($settings) eq 'HASH') {
5568: foreach my $item (keys(%{$settings})) {
5569: if (ref($settings->{$item}) eq 'HASH') {
5570: my $num = $settings->{$item}{'order'};
5571: $ordered{$num} = $item;
5572: }
5573: }
5574: } else {
5575: %ordered = (
5576: 1 => 'proctorio',
5577: 2 => 'examity',
5578: );
5579: }
5580: %providernames = &proctoring_providernames();
5581: my $maxnum = scalar(keys(%ordered));
5582: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
5583: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
5584: if (ref($requref) eq 'HASH') {
5585: %requserfields = %{$requref};
5586: }
5587: if (ref($opturef) eq 'HASH') {
5588: %optuserfields = %{$opturef};
5589: }
5590: if (ref($defref) eq 'HASH') {
5591: %defaults = %{$defref};
5592: }
5593: if (ref($extref) eq 'HASH') {
5594: %extended = %{$extref};
5595: }
5596: if (ref($crsref) eq 'HASH') {
5597: %crsconf = %{$crsref};
5598: }
5599: if (ref($rolesref) eq 'ARRAY') {
5600: @courseroles = @{$rolesref};
5601: }
5602: if (ref($ltiref) eq 'ARRAY') {
5603: @ltiroles = @{$ltiref};
5604: }
5605: my $datatable;
5606: my $css_class;
5607: if (keys(%ordered)) {
5608: my @items = sort { $a <=> $b } keys(%ordered);
5609: for (my $i=0; $i<@items; $i++) {
5610: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5611: my $provider = $ordered{$items[$i]};
5612: my $optionsty = 'none';
5613: my ($available,$version,$lifetime,$imgsrc,$userincdom,$showroles,
5614: %checkedfields,%rolemaps,%inuse,%crsconfig,%current);
5615: if (ref($settings) eq 'HASH') {
5616: if (ref($settings->{$provider}) eq 'HASH') {
5617: %current = %{$settings->{$provider}};
5618: if ($current{'available'}) {
5619: $optionsty = 'block';
5620: $available = 1;
5621: }
5622: if ($current{'lifetime'} =~ /^\d+$/) {
5623: $lifetime = $current{'lifetime'};
5624: }
5625: if ($current{'version'} =~ /^\d+\.\d+$/) {
5626: $version = $current{'version'};
5627: }
5628: if ($current{'image'} ne '') {
5629: $imgsrc = '<img src="'.$current{'image'}.'" alt="'.&mt('Proctoring service icon').'" />';
5630: }
5631: if (ref($current{'fields'}) eq 'ARRAY') {
5632: map { $checkedfields{$_} = 1; } @{$current{'fields'}};
5633: }
5634: $userincdom = $current{'incdom'};
5635: if (ref($current{'roles'}) eq 'HASH') {
5636: %rolemaps = %{$current{'roles'}};
5637: $checkedfields{'roles'} = 1;
5638: }
5639: if (ref($current{'defaults'}) eq 'ARRAY') {
5640: foreach my $val (@{$current{'defaults'}}) {
5641: if (grep(/^\Q$val\E$/,@{$defaults{$provider}})) {
5642: $inuse{$val} = 1;
5643: } else {
5644: foreach my $poss (keys(%{$extended{$provider}})) {
5645: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5646: if (grep(/^\Q$val\E$/,@{$extended{$provider}{$poss}})) {
5647: $inuse{$poss} = $val;
5648: last;
5649: }
5650: }
5651: }
5652: }
5653: }
5654: } elsif (ref($current{'defaults'}) eq 'HASH') {
5655: foreach my $key (keys(%{$current{'defaults'}})) {
5656: my $currval = $current{'defaults'}{$key};
5657: if (grep(/^\Q$key\E$/,@{$defaults{$provider}})) {
5658: $inuse{$key} = 1;
5659: } else {
5660: my $match;
5661: foreach my $poss (keys(%{$extended{$provider}})) {
5662: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5663: if (grep(/^\Q$key\E$/,@{$extended{$provider}{$poss}})) {
5664: $inuse{$poss} = $key;
5665: last;
5666: }
5667: } elsif (ref($extended{$provider}{$poss}) eq 'HASH') {
5668: foreach my $inner (sort(keys(%{$extended{$provider}{$poss}}))) {
5669: if (ref($extended{$provider}{$poss}{$inner}) eq 'ARRAY') {
5670: if (grep(/^\Q$currval\E$/,@{$extended{$provider}{$poss}{$inner}})) {
5671: $currentdef{$inner} = $currval;
5672: $match = 1;
5673: last;
5674: }
5675: } elsif ($inner eq $key) {
5676: $currentdef{$key} = $currval;
5677: $match = 1;
5678: last;
5679: }
5680: }
5681: }
5682: last if ($match);
5683: }
5684: }
5685: }
5686: }
5687: if (ref($current{'crsconf'}) eq 'ARRAY') {
5688: map { $crsconfig{$_} = 1; } @{$current{'crsconf'}};
5689: }
5690: }
5691: }
5692: my %lt = &proctoring_titles($provider);
5693: my %fieldtitles = &proctoring_fieldtitles($provider);
5694: my $onclickavailable = ' onclick="toggleProctoring(this.form,'."'$provider'".');"';
5695: my %checkedavailable = (
5696: yes => '',
5697: no => ' checked="checked"',
5698: );
5699: if ($available) {
5700: $checkedavailable{'yes'} = $checkedavailable{'no'};
5701: $checkedavailable{'no'} = '';
5702: }
5703: my $chgstr = ' onchange="javascript:reorderProctoring(this.form,'."'proctoring_pos_".$provider."'".');"';
5704: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5705: .'<select name="proctoring_pos_'.$provider.'"'.$chgstr.'>';
5706: for (my $k=0; $k<$maxnum; $k++) {
5707: my $vpos = $k+1;
5708: my $selstr;
5709: if ($k == $i) {
5710: $selstr = ' selected="selected" ';
5711: }
5712: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5713: }
5714: if ($version eq '') {
5715: if ($provider eq 'proctorio') {
5716: $version = '1.0';
5717: } elsif ($provider eq 'examity') {
5718: $version = '1.1';
5719: }
5720: }
5721: if ($lifetime eq '') {
5722: $lifetime = '300';
5723: }
5724: $datatable .=
5725: '</select>'.(' 'x2).'<b>'.$providernames{$provider}.'</b></span><br />'.
5726: '<span class="LC_nobreak">'.$lt{'avai'}.' '.
5727: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="1"'.$onclickavailable.$checkedavailable{yes}.' />'.&mt('Yes').'</label> '."\n".
5728: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="0"'.$onclickavailable.$checkedavailable{no}.' />'.&mt('No').'</label></span>'."\n".
5729: '</td>'.
5730: '<td colspan="2">'.
5731: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'base'}.'</legend>'.
5732: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="proctoring_'.$provider.'_version">'.
5733: '<option value="'.$version.'" selected="selected">'.$version.'</option></select></span> '."\n".
5734: (' 'x2).
5735: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="proctoring_'.$provider.'_sigmethod">'.
5736: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5737: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
5738: (' 'x2).
5739: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="proctoring_'.$provider.'_lifetime" value="'.$lifetime.'" /></span> '."\n".
5740: '<br />'.
5741: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="proctoring_'.$provider.'_url" value="'.$current{'url'}.'" /></span> '."\n".
5742: '<br />'.
5743: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="proctoring_'.$provider.'_key" value="'.$current{'key'}.'" /></span> '."\n".
5744: (' 'x2).
5745: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="proctoring_'.$provider.'_secret" value="'.$current{'secret'}.'" />'.
5746: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.proctoring_'.$provider.'_secret.type='."'text'".' } else { this.form.proctoring_'.$provider.'_secret.type='."'password'".' }" />'.$lt{'visible'}.'</label></span><br />'."\n";
5747: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
5748: if ($imgsrc) {
5749: $datatable .= $imgsrc.
5750: '<label><input type="checkbox" name="proctoring_image_del"'.
5751: ' value="'.$provider.'" />'.&mt('Delete?').'</label></span> '.
5752: '<span class="LC_nobreak"> '.&mt('Replace:');
5753: }
5754: $datatable .= ' ';
5755: if ($switchserver) {
5756: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5757: } else {
5758: $datatable .= '<input type="file" name="proctoring_image_'.$provider.'" value="" />';
5759: }
5760: unless ($imgsrc) {
5761: $datatable .= '<br />('.&mt('if larger than 21x21 pixels, image will be scaled').')';
5762: }
5763: $datatable .= '</fieldset>'."\n";
5764: if (ref($requserfields{$provider}) eq 'ARRAY') {
5765: if (@{$requserfields{$provider}} > 0) {
5766: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'requ'}.'</legend>';
5767: foreach my $field (@{$requserfields{$provider}}) {
5768: $datatable .= '<span class="LC_nobreak">'.
5769: '<label><input type="checkbox" name="proctoring_reqd_'.$provider.'" value="'.$field.'" checked="checked" disabled="disabled" />'.
5770: $lt{$field}.'</label>';
5771: if ($field eq 'user') {
5772: my $seluserdom = '';
5773: my $unseluserdom = ' selected="selected"';
5774: if ($userincdom) {
5775: $seluserdom = $unseluserdom;
5776: $unseluserdom = '';
5777: }
5778: $datatable .= ': '.
5779: '<select name="proctoring_userincdom_'.$provider.'">'.
5780: '<option value="0"'.$unseluserdom.'>'.$lt{'username'}.'</option>'.
5781: '<option value="1"'.$seluserdom.'>'.$lt{'uname:dom'}.'</option>'.
5782: '</select> ';
5783: } else {
5784: $datatable .= ' ';
5785: if ($field eq 'roles') {
5786: $showroles = 1;
5787: }
5788: }
5789: $datatable .= '</span> ';
5790: }
5791: }
5792: $datatable .= '</fieldset>'."\n";
5793: }
5794: if (ref($optuserfields{$provider}) eq 'ARRAY') {
5795: if (@{$optuserfields{$provider}} > 0) {
5796: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'optu'}.'</legend>';
5797: foreach my $field (@{$optuserfields{$provider}}) {
5798: my $checked;
5799: if ($checkedfields{$field}) {
5800: $checked = ' checked="checked"';
5801: }
5802: $datatable .= '<span class="LC_nobreak">'.
5803: '<label><input type="checkbox" name="proctoring_optional_'.$provider.'" value="'.$field.'"'.$checked.' />'.$lt{$field}.'</label></span> ';
5804: }
5805: $datatable .= '</fieldset>'."\n";
5806: }
5807: }
5808: if (ref($defaults{$provider}) eq 'ARRAY') {
5809: if (@{$defaults{$provider}}) {
5810: my (%options,@selectboxes);
5811: if (ref($extended{$provider}) eq 'HASH') {
5812: %options = %{$extended{$provider}};
5813: }
5814: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'defa'}.'</legend>';
5815: my ($rem,$numinrow,$dropdowns);
5816: if ($provider eq 'proctorio') {
5817: $datatable .= '<table>';
5818: $numinrow = 4;
5819: }
5820: my $i = 0;
5821: foreach my $field (@{$defaults{$provider}}) {
5822: my $checked;
5823: if ($inuse{$field}) {
5824: $checked = ' checked="checked"';
5825: }
5826: if ($provider eq 'examity') {
5827: if ($field eq 'display') {
5828: $datatable .= '<span class="LC_nobreak">'.&mt('Display target:');
5829: foreach my $option ('iframe','tab','window') {
5830: my $checkdisp;
5831: if ($currentdef{'target'} eq $option) {
5832: $checkdisp = ' checked="checked"';
5833: }
5834: $datatable .= '<label><input type="radio" name="proctoring_target_'.$provider.'" value="'.$option.'"'.$checkdisp.' />'.
5835: $fieldtitles{$option}.'</label>'.(' 'x2);
5836: }
5837: $datatable .= (' 'x4);
5838: foreach my $dimen ('width','height') {
5839: $datatable .= '<label>'.$fieldtitles{$dimen}.' '.
5840: '<input type="text" name="proctoring_'.$dimen.'_'.$provider.'" size="5" '.
5841: 'value="'.$currentdef{$dimen}.'" /></label>'.
5842: (' 'x2);
5843: }
5844: $datatable .= '</span><br />'.
5845: '<div class="LC_left_float">'.$fieldtitles{'linktext'}.'<br />'.
5846: '<input type="text" name="proctoring_linktext_'.$provider.'" '.
5847: 'size="25" value="'.$currentdef{'linktext'}.'" /></div>'.
5848: '<div class="LC_left_float">'.$fieldtitles{'explanation'}.'<br />'.
5849: '<textarea name="proctoring_explanation_'.$provider.'" rows="5" cols="40">'.
5850: $currentdef{'explanation'}.
5851: '</textarea></div><div style=""></div><br />';
5852: }
5853: } else {
5854: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
5855: my ($output,$selnone);
5856: unless ($checked) {
5857: $selnone = ' selected="selected"';
5858: }
5859: $output .= '<span class="LC_nobreak">'.$fieldtitles{$field}.': '.
5860: '<select name="proctoring_defaults_'.$field.'_'.$provider.'">'.
5861: '<option value=""'.$selnone.'>'.&mt('Not in use').'</option>';
5862: foreach my $option (@{$options{$field}}) {
5863: my $sel;
5864: if ($inuse{$field} eq $option) {
5865: $sel = ' selected="selected"';
5866: }
5867: $output .= '<option value="'.$option.'"'.$sel.'>'.$fieldtitles{$option}.'</option>';
5868: }
5869: $output .= '</select></span>';
5870: push(@selectboxes,$output);
5871: } else {
5872: $rem = $i%($numinrow);
5873: if ($rem == 0) {
5874: if ($i > 0) {
5875: $datatable .= '</tr>';
5876: }
5877: $datatable .= '<tr>';
5878: }
5879: $datatable .= '<td class="LC_left_item">'.
5880: '<span class="LC_nobreak">'.
5881: '<label><input type="checkbox" name="proctoring_defaults_'.$provider.'" value="'.$field.'"'.$checked.' />'.
5882: $fieldtitles{$field}.'</label></span></td>';
5883: $i++;
5884: }
5885: }
5886: }
5887: if ($provider eq 'proctorio') {
5888: if ($numinrow) {
5889: $rem = $i%$numinrow;
5890: }
5891: my $colsleft = $numinrow - $rem;
5892: if ($colsleft > 1) {
5893: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5894: } else {
5895: $datatable .= '<td class="LC_left_item">';
5896: }
5897: $datatable .= ' '.
5898: '</td></tr></table>';
5899: if (@selectboxes) {
5900: $datatable .= '<hr /><table>';
5901: $numinrow = 2;
5902: for (my $i=0; $i<@selectboxes; $i++) {
5903: $rem = $i%($numinrow);
5904: if ($rem == 0) {
5905: if ($i > 0) {
5906: $datatable .= '</tr>';
5907: }
5908: $datatable .= '<tr>';
5909: }
5910: $datatable .= '<td class="LC_left_item">'.
5911: $selectboxes[$i].'</td>';
5912: }
5913: if ($numinrow) {
5914: $rem = $i%$numinrow;
5915: }
5916: $colsleft = $numinrow - $rem;
5917: if ($colsleft > 1) {
5918: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5919: } else {
5920: $datatable .= '<td class="LC_left_item">';
5921: }
5922: $datatable .= ' '.
5923: '</td></tr></table>';
5924: }
5925: }
5926: $datatable .= '</fieldset>';
5927: }
5928: if (ref($crsconf{$provider}) eq 'ARRAY') {
5929: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5930: '<legend>'.&mt('Configurable in course').'</legend>';
5931: my ($rem,$numinrow);
5932: if ($provider eq 'proctorio') {
5933: $datatable .= '<table>';
5934: $numinrow = 4;
5935: }
5936: my $i = 0;
5937: foreach my $item (@{$crsconf{$provider}}) {
5938: my $name;
5939: if ($provider eq 'examity') {
5940: $name = $lt{'crs'.$item};
5941: } elsif ($provider eq 'proctorio') {
5942: $name = $fieldtitles{$item};
5943: $rem = $i%($numinrow);
5944: if ($rem == 0) {
5945: if ($i > 0) {
5946: $datatable .= '</tr>';
5947: }
5948: $datatable .= '<tr>';
5949: }
5950: $datatable .= '<td class="LC_left_item>';
5951: }
5952: my $checked;
5953: if ($crsconfig{$item}) {
5954: $checked = ' checked="checked"';
5955: }
5956: $datatable .= '<span class="LC_nobreak"><label>'.
5957: '<input type="checkbox" name="proctoring_crsconf_'.$provider.'" value="'.$item.'"'.$checked.' />'.
5958: $name.'</label></span>';
5959: if ($provider eq 'examity') {
5960: $datatable .= ' ';
5961: }
5962: $datatable .= "\n";
5963: $i++;
5964: }
5965: if ($provider eq 'proctorio') {
5966: if ($numinrow) {
5967: $rem = $i%$numinrow;
5968: }
5969: my $colsleft = $numinrow - $rem;
5970: if ($colsleft > 1) {
5971: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5972: } else {
5973: $datatable .= '<td class="LC_left_item">';
5974: }
5975: $datatable .= ' '.
5976: '</td></tr></table>';
5977: }
5978: $datatable .= '</fieldset>';
5979: }
5980: if ($showroles) {
5981: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5982: '<legend>'.&mt('Role mapping').'</legend><table><tr>';
5983: foreach my $role (@courseroles) {
5984: my ($selected,$selectnone);
5985: if (!$rolemaps{$role}) {
5986: $selectnone = ' selected="selected"';
5987: }
5988: $datatable .= '<td style="text-align: center">'.
5989: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5990: '<select name="proctoring_roles_'.$role.'_'.$provider.'">'.
5991: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5992: foreach my $ltirole (@ltiroles) {
5993: unless ($selectnone) {
5994: if ($rolemaps{$role} eq $ltirole) {
5995: $selected = ' selected="selected"';
5996: } else {
5997: $selected = '';
5998: }
5999: }
6000: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
6001: }
6002: $datatable .= '</select></td>';
6003: }
6004: $datatable .= '</tr></table></fieldset>'.
6005: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
6006: '<legend>'.&mt('Custom items sent on launch').'</legend>'.
6007: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
6008: '<tr><td></td><td>lms</td>'.
6009: '<td><input type="text" name="proctoring_customval_lms_'.$provider.'"'.
6010: ' value="Loncapa" disabled="disabled"/></td></tr>';
6011: if ((ref($settings) eq 'HASH') && (ref($settings->{$provider}) eq 'HASH') &&
6012: (ref($settings->{$provider}->{'custom'}) eq 'HASH')) {
6013: my %custom = %{$settings->{$provider}->{'custom'}};
6014: if (keys(%custom) > 0) {
6015: foreach my $key (sort(keys(%custom))) {
6016: next if ($key eq 'lms');
6017: $datatable .= '<tr><td><span class="LC_nobreak">'.
6018: '<label><input type="checkbox" name="proctoring_customdel_'.$provider.'" value="'.
6019: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
6020: '<td><input type="text" name="proctoring_customval_'.$key.'_'.$provider.'"'.
6021: ' value="'.$custom{$key}.'" /></td></tr>';
6022: }
6023: }
6024: }
6025: $datatable .= '<tr><td><span class="LC_nobreak">'.
6026: '<label><input type="checkbox" name="proctoring_customadd" value="'.$provider.'" />'.
6027: &mt('Add more').'</label></span></td><td><input type="text" name="proctoring_custom_name_'.$provider.'" />'.
6028: '</td><td><input type="text" name="proctoring_custom_value_'.$provider.'" /></td></tr>'.
6029: '</table></fieldset></td></tr>'."\n";
6030: }
6031: $datatable .= '</td></tr>';
6032: }
6033: $itemcount ++;
6034: }
6035: }
6036: return $datatable;
6037: }
6038:
6039: sub proctoring_data {
6040: my $requserfields = {
6041: proctorio => ['user'],
6042: examity => ['roles','user'],
6043: };
6044: my $optuserfields = {
6045: proctorio => ['fullname'],
6046: examity => ['fullname','firstname','lastname','email'],
6047: };
6048: my $defaults = {
6049: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6050: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6051: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6052: 'closetabs','onescreen','print','downloads','cache','rightclick',
6053: 'reentry','calculator','whiteboard'],
6054: examity => ['display'],
6055: };
6056: my $extended = {
6057: proctorio => {
6058: verifyid => ['verifyidauto','verifyidlive'],
6059: fullscreen => ['fullscreenlenient','fullscreenmoderate','fullscreensever'],
6060: tabslinks => ['notabs','linksonly'],
6061: reentry => ['noreentry','agentreentry'],
6062: calculator => ['calculatorbasic','calculatorsci'],
6063: },
6064: examity => {
6065: display => {
6066: target => ['iframe','tab','window'],
6067: width => '',
6068: height => '',
6069: linktext => '',
6070: explanation => '',
6071: },
6072: },
6073: };
6074: my $crsconf = {
6075: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6076: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6077: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6078: 'closetabs','onescreen','print','downloads','cache','rightclick',
6079: 'reentry','calculator','whiteboard'],
6080: examity => ['label','title','target','linktext','explanation','append'],
6081: };
6082: my $courseroles = ['cc','in','ta','ep','st'];
6083: my $ltiroles = ['Instructor','ContentDeveloper','TeachingAssistant','Learner'];
6084: return ($requserfields,$optuserfields,$defaults,$extended,$crsconf,$courseroles,$ltiroles);
6085: }
6086:
6087: sub proctoring_titles {
6088: my ($item) = @_;
6089: my (%common_lt,%custom_lt);
6090: %common_lt = &Apache::lonlocal::texthash (
6091: 'avai' => 'Available?',
6092: 'base' => 'Basic Settings',
6093: 'requ' => 'User data required to be sent on launch',
6094: 'optu' => 'User data optionally sent on launch',
6095: 'udsl' => 'User data sent on launch',
6096: 'defa' => 'Defaults for items configurable in course',
6097: 'sigmethod' => 'Signature Method',
6098: 'key' => 'Key',
6099: 'lifetime' => 'Nonce lifetime (s)',
6100: 'secret' => 'Secret',
6101: 'icon' => 'Icon',
6102: 'fullname' => 'Full Name',
6103: 'visible' => 'Visible input',
6104: 'username' => 'username',
6105: 'user' => 'User',
6106: );
6107: if ($item eq 'proctorio') {
6108: %custom_lt = &Apache::lonlocal::texthash (
6109: 'version' => 'OAuth version',
6110: 'url' => 'API URL',
6111: 'uname:dom' => 'username-domain',
6112: );
6113: } elsif ($item eq 'examity') {
6114: %custom_lt = &Apache::lonlocal::texthash (
6115: 'version' => 'LTI Version',
6116: 'url' => 'URL',
6117: 'uname:dom' => 'username:domain',
6118: 'msgtype' => 'Message Type',
6119: 'firstname' => 'First Name',
6120: 'lastname' => 'Last Name',
6121: 'email' => 'E-mail',
6122: 'roles' => 'Role',
6123: 'crstarget' => 'Display target',
6124: 'crslabel' => 'Course label',
6125: 'crstitle' => 'Course title',
6126: 'crslinktext' => 'Link Text',
6127: 'crsexplanation' => 'Explanation',
6128: 'crsappend' => 'Provider URL',
6129: );
6130: }
6131: my %lt = (%common_lt,%custom_lt);
6132: return %lt;
6133: }
6134:
6135: sub proctoring_fieldtitles {
6136: my ($item) = @_;
6137: if ($item eq 'proctorio') {
6138: return &Apache::lonlocal::texthash (
6139: 'recordvideo' => 'Record video',
6140: 'recordaudio' => 'Record audio',
6141: 'recordscreen' => 'Record screen',
6142: 'recordwebtraffic' => 'Record web traffic',
6143: 'recordroomstart' => 'Record room scan',
6144: 'verifyvideo' => 'Verify webcam',
6145: 'verifyaudio' => 'Verify microphone',
6146: 'verifydesktop' => 'Verify desktop recording',
6147: 'verifyid' => 'Photo ID verification',
6148: 'verifysignature' => 'Require signature',
6149: 'fullscreen' => 'Fullscreen',
6150: 'clipboard' => 'Disable copy/paste',
6151: 'tabslinks' => 'New tabs/windows',
6152: 'closetabs' => 'Close other tabs',
6153: 'onescreen' => 'Limit to single screen',
6154: 'print' => 'Disable Printing',
6155: 'downloads' => 'Disable Downloads',
6156: 'cache' => 'Empty cache after exam',
6157: 'rightclick' => 'Disable right click',
6158: 'reentry' => 'Re-entry to exam',
6159: 'calculator' => 'Onscreen calculator',
6160: 'whiteboard' => 'Onscreen whiteboard',
6161: 'verifyidauto' => 'Automated verification',
6162: 'verifyidlive' => 'Live agent verification',
6163: 'fullscreenlenient' => 'Forced, but can navigate away for up to 30s',
6164: 'fullscreenmoderate' => 'Forced, but can navigate away for up to 15s',
6165: 'fullscreensever' => 'Forced, navigation away ends exam',
6166: 'notabs' => 'Disaallowed',
6167: 'linksonly' => 'Allowed from links in exam',
6168: 'noreentry' => 'Disallowed',
6169: 'agentreentry' => 'Agent required for re-entry',
6170: 'calculatorbasic' => 'Basic',
6171: 'calculatorsci' => 'Scientific',
6172: );
6173: } elsif ($item eq 'examity') {
6174: return &Apache::lonlocal::texthash (
6175: 'target' => 'Display target',
6176: 'window' => 'Window',
6177: 'tab' => 'Tab',
6178: 'iframe' => 'iFrame',
6179: 'height' => 'Height (pixels)',
6180: 'width' => 'Width (pixels)',
6181: 'linktext' => 'Default Link Text',
6182: 'explanation' => 'Default Explanation',
6183: 'append' => 'Provider URL',
6184: );
6185: }
6186: }
6187:
6188: sub proctoring_providernames {
6189: return (
6190: proctorio => 'Proctorio',
6191: examity => 'Examity',
6192: );
6193: }
6194:
1.320 raeburn 6195: sub print_lti {
1.405 raeburn 6196: my ($position,$dom,$settings,$rowtotal) = @_;
1.320 raeburn 6197: my $itemcount = 1;
1.405 raeburn 6198: my ($datatable,$css_class);
1.434 raeburn 6199: my (%rules,%encrypt,%privkeys,%linkprot,%suggestions);
1.320 raeburn 6200: if (ref($settings) eq 'HASH') {
1.405 raeburn 6201: if ($position eq 'top') {
6202: if (exists($settings->{'encrypt'})) {
6203: if (ref($settings->{'encrypt'}) eq 'HASH') {
6204: foreach my $key (keys(%{$settings->{'encrypt'}})) {
6205: if ($key eq 'consumers') {
6206: $encrypt{'ltisec_'.$key} = $settings->{'encrypt'}{$key};
6207: } else {
6208: $encrypt{'ltisec_'.$key.'linkprot'} = $settings->{'encrypt'}{$key};
6209: }
6210: }
6211: }
6212: }
6213: if (exists($settings->{'private'})) {
6214: if (ref($settings->{'private'}) eq 'HASH') {
6215: if (ref($settings->{'private'}) eq 'HASH') {
6216: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
6217: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
6218: }
6219: }
6220: }
6221: }
1.434 raeburn 6222: } elsif ($position eq 'upper') {
1.405 raeburn 6223: if (exists($settings->{'rules'})) {
6224: if (ref($settings->{'rules'}) eq 'HASH') {
6225: %rules = %{$settings->{'rules'}};
6226: }
6227: }
1.434 raeburn 6228: } elsif ($position eq 'middle') {
6229: if (exists($settings->{'suggested'})) {
6230: if (ref($settings->{'suggested'}) eq 'HASH') {
6231: %suggestions = %{$settings->{'suggested'}};
6232: }
6233: }
1.405 raeburn 6234: } elsif ($position eq 'lower') {
6235: if (exists($settings->{'linkprot'})) {
6236: if (ref($settings->{'linkprot'}) eq 'HASH') {
6237: %linkprot = %{$settings->{'linkprot'}};
1.406 raeburn 6238: if ($linkprot{'lock'}) {
6239: delete($linkprot{'lock'});
6240: }
1.405 raeburn 6241: }
6242: }
6243: } else {
1.434 raeburn 6244: foreach my $key ('encrypt','private','rules','linkprot','suggestions') {
1.405 raeburn 6245: if (exists($settings->{$key})) {
6246: delete($settings->{$key});
1.390 raeburn 6247: }
1.320 raeburn 6248: }
6249: }
6250: }
1.405 raeburn 6251: if ($position eq 'top') {
1.421 raeburn 6252: $datatable = &secrets_form($dom,'ltisec',\%encrypt,\%privkeys,$rowtotal);
1.434 raeburn 6253: } elsif ($position eq 'upper') {
6254: $datatable = &password_rules('ltisecrets',\$itemcount,\%rules);
6255: $$rowtotal += $itemcount;
1.421 raeburn 6256: } elsif ($position eq 'middle') {
1.434 raeburn 6257: $datatable = &linkprot_suggestions(\%suggestions,\$itemcount);
1.421 raeburn 6258: $$rowtotal += $itemcount;
6259: } elsif ($position eq 'lower') {
1.434 raeburn 6260: $datatable .= &Apache::courseprefs::print_linkprotection($dom,'',$settings,$rowtotal,'','','domain');
1.421 raeburn 6261: } else {
1.424 raeburn 6262: my ($switchserver,$switchmessage);
6263: $switchserver = &check_switchserver($dom);
6264: $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
1.421 raeburn 6265: my $maxnum = 0;
6266: my %ordered;
6267: if (ref($settings) eq 'HASH') {
6268: foreach my $item (keys(%{$settings})) {
6269: if (ref($settings->{$item}) eq 'HASH') {
6270: my $num = $settings->{$item}{'order'};
6271: if ($num eq '') {
6272: $num = scalar(keys(%{$settings}));
6273: }
6274: $ordered{$num} = $item;
1.405 raeburn 6275: }
1.352 raeburn 6276: }
1.405 raeburn 6277: }
6278: $maxnum = scalar(keys(%ordered));
6279: my %lt = <i_names();
6280: if (keys(%ordered)) {
6281: my @items = sort { $a <=> $b } keys(%ordered);
6282: for (my $i=0; $i<@items; $i++) {
6283: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6284: my $item = $ordered{$items[$i]};
1.424 raeburn 6285: my ($key,$secret,$usable,$lifetime,$consumer,$requser,$crsinc,$current);
1.405 raeburn 6286: if (ref($settings->{$item}) eq 'HASH') {
6287: $key = $settings->{$item}->{'key'};
1.424 raeburn 6288: $usable = $settings->{$item}->{'usable'};
1.405 raeburn 6289: $lifetime = $settings->{$item}->{'lifetime'};
6290: $consumer = $settings->{$item}->{'consumer'};
6291: $requser = $settings->{$item}->{'requser'};
6292: $crsinc = $settings->{$item}->{'crsinc'};
6293: $current = $settings->{$item};
6294: }
6295: my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
6296: my %checkedrequser = (
6297: yes => ' checked="checked"',
6298: no => '',
6299: );
6300: if (!$requser) {
6301: $checkedrequser{'no'} = $checkedrequser{'yes'};
6302: $checkedrequser{'yes'} = '';
6303: }
6304: my $onclickcrsinc = ' onclick="toggleLTI(this.form,'."'crsinc','$i'".');"';
6305: my %checkedcrsinc = (
1.391 raeburn 6306: yes => ' checked="checked"',
6307: no => '',
1.405 raeburn 6308: );
6309: if (!$crsinc) {
6310: $checkedcrsinc{'no'} = $checkedcrsinc{'yes'};
6311: $checkedcrsinc{'yes'} = '';
6312: }
6313: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
6314: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6315: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
6316: for (my $k=0; $k<=$maxnum; $k++) {
6317: my $vpos = $k+1;
6318: my $selstr;
6319: if ($k == $i) {
6320: $selstr = ' selected="selected" ';
6321: }
6322: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320 raeburn 6323: }
1.405 raeburn 6324: $datatable .= '</select>'.(' 'x2).
6325: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
6326: &mt('Delete?').'</label></span></td>'.
6327: '<td colspan="2">'.
6328: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6329: '<span class="LC_nobreak">'.$lt{'consumer'}.
6330: ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
6331: (' 'x2).
6332: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
6333: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
6334: (' 'x2).
6335: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
1.424 raeburn 6336: 'value="'.$lifetime.'" size="3" /></span><br /><br />';
6337: if ($key ne '') {
6338: $datatable .= '<span class="LC_nobreak">'.$lt{'key'};
6339: if ($switchserver) {
6340: $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
6341: } else {
6342: $datatable .= ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />';
6343: }
6344: $datatable .= '</span> '.(' 'x2);
6345: } elsif (!$switchserver) {
6346: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':'.
6347: '<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />'.
6348: '</span> '.(' 'x2);
6349: }
6350: if ($switchserver) {
6351: if ($usable ne '') {
6352: $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6353: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6354: '<span class="LC_nobreak">'.&mt('Change secret?').
6355: '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
6356: (' 'x2).
6357: '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').'</label>'.(' 'x2).
6358: '</span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
6359: '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
6360: '</div>';
6361: } elsif ($key eq '') {
6362: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6363: } else {
6364: $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
6365: }
6366: } else {
6367: if ($usable ne '') {
6368: $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6369: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6370: '<span class="LC_nobreak">'.&mt('Change?').
6371: '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
6372: (' 'x2).
6373: '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').
6374: '</label> </span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
6375: '<span class="LC_nobreak">'.&mt('New Secret').':'.
6376: '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
6377: '<label><input type="checkbox" name="lti_visible_'.$i.'" id="lti_visible_'.$i.'" onclick="if (this.checked) { this.form.lti_secret_'.$i.'.type='."'text'".' } else { this.form.lti_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label></span></div>';
6378: } else {
6379: $datatable .=
6380: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
6381: '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
6382: '<label><input type="checkbox" name="lti_visible_'.$i.'" id="lti_visible_'.$i.'" onclick="if (this.checked) { this.form.lti_secret_'.$i.'.type='."'text'".' } else { this.form.lti_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label>';
6383: }
6384: }
1.425 raeburn 6385: $datatable .= '<br /><br />'.
1.405 raeburn 6386: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6387: '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
6388: '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
6389: '<br /><br />'.
6390: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6391: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="1"'.$onclickcrsinc.$checkedcrsinc{yes}.' />'.&mt('Yes').'</label> '."\n".
6392: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="0"'.$onclickcrsinc.$checkedcrsinc{no}.' />'.&mt('No').'</label></span>'."\n".
6393: (' 'x4).
6394: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
6395: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
6396: $itemcount ++;
1.320 raeburn 6397: }
6398: }
1.405 raeburn 6399: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6400: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
6401: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6402: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
6403: '<select name="lti_pos_add"'.$chgstr.'>';
6404: for (my $k=0; $k<$maxnum+1; $k++) {
6405: my $vpos = $k+1;
6406: my $selstr;
6407: if ($k == $maxnum) {
6408: $selstr = ' selected="selected" ';
6409: }
6410: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320 raeburn 6411: }
1.405 raeburn 6412: $datatable .= '</select> '."\n".
6413: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6414: '<td colspan="2">'.
6415: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6416: '<span class="LC_nobreak">'.$lt{'consumer'}.
6417: ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
6418: (' 'x2).
6419: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
6420: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
6421: (' 'x2).
1.424 raeburn 6422: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span><br /><br />'."\n";
6423: if ($switchserver) {
6424: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6425: } else {
6426: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" autocomplete="off" /></span> '."\n".
6427: (' 'x2).
6428: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" autocomplete="new-password" />'.
6429: '<label><input type="checkbox" name="lti_add_visible" id="lti_add_visible" onclick="if (this.checked) { this.form.lti_secret_add.type='."'text'".' } else { this.form.lti_secret_add.type='."'password'".' }" />'.&mt('Visible input').'</label></span> '."\n";
6430: }
6431: $datatable .= '<br /><br />'.
1.405 raeburn 6432: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6433: '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6434: '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
6435: '<br /><br />'.
6436: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6437: '<label><input type="radio" name="lti_crsinc_add" value="1" onclick="toggleLTI(this.form,'."'crsinc','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6438: '<label><input type="radio" name="lti_crsinc_add" value="0" onclick="toggleLTI(this.form,'."'crsinc','add'".');" />'.&mt('No').'</label></span>'."\n".
6439: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
6440: '</td>'."\n".
6441: '</tr>'."\n";
6442: $itemcount ++;
1.320 raeburn 6443: }
1.405 raeburn 6444: $$rowtotal += $itemcount;
6445: return $datatable;
1.320 raeburn 6446: }
6447:
6448: sub lti_names {
6449: my %lt = &Apache::lonlocal::texthash(
6450: 'version' => 'LTI Version',
6451: 'url' => 'URL',
6452: 'key' => 'Key',
1.322 raeburn 6453: 'lifetime' => 'Nonce lifetime (s)',
1.345 raeburn 6454: 'consumer' => 'Consumer',
1.320 raeburn 6455: 'secret' => 'Secret',
1.345 raeburn 6456: 'requser' => "User's identity sent",
1.391 raeburn 6457: 'crsinc' => "Course's identity sent",
1.320 raeburn 6458: 'email' => 'Email address',
6459: 'sourcedid' => 'User ID',
6460: 'other' => 'Other',
6461: 'passback' => 'Can return grades to Consumer:',
6462: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 6463: 'topmenu' => 'Display LON-CAPA page header',
1.345 raeburn 6464: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 6465: );
6466: return %lt;
6467: }
6468:
6469: sub lti_options {
1.325 raeburn 6470: my ($num,$current,$itemcount,%lt) = @_;
1.363 raeburn 6471: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
1.320 raeburn 6472: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
6473: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
1.392 raeburn 6474: $checked{'storecrs'}{'Y'} = ' checked="checked"';
6475: $checked{'makecrs'}{'N'} = ' checked="checked"';
1.320 raeburn 6476: $checked{'mapcrstype'} = {};
6477: $checked{'makeuser'} = {};
6478: $checked{'selfenroll'} = {};
6479: $checked{'crssec'} = {};
6480: $checked{'crssecsrc'} = {};
1.325 raeburn 6481: $checked{'lcauth'} = {};
1.326 raeburn 6482: $checked{'menuitem'} = {};
1.325 raeburn 6483: if ($num eq 'add') {
6484: $checked{'lcauth'}{'lti'} = ' checked="checked"';
6485: }
1.320 raeburn 6486: my $userfieldsty = 'none';
6487: my $crsfieldsty = 'none';
6488: my $crssecfieldsty = 'none';
6489: my $secsrcfieldsty = 'none';
1.363 raeburn 6490: my $callbacksty = 'none';
1.337 raeburn 6491: my $passbacksty = 'none';
1.345 raeburn 6492: my $optionsty = 'block';
1.391 raeburn 6493: my $crssty = 'block';
1.325 raeburn 6494: my $lcauthparm;
6495: my $lcauthparmstyle = 'display:none';
6496: my $lcauthparmtext;
1.326 raeburn 6497: my $menusty;
1.325 raeburn 6498: my $numinrow = 4;
1.326 raeburn 6499: my %menutitles = <imenu_titles();
1.320 raeburn 6500:
6501: if (ref($current) eq 'HASH') {
1.345 raeburn 6502: if (!$current->{'requser'}) {
6503: $optionsty = 'none';
1.391 raeburn 6504: $crssty = 'none';
6505: } elsif (!$current->{'crsinc'}) {
6506: $crssty = 'none';
1.345 raeburn 6507: }
1.320 raeburn 6508: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
6509: $checked{'mapuser'}{'sourcedid'} = '';
6510: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
1.425 raeburn 6511: $checked{'mapuser'}{'email'} = ' checked="checked"';
1.320 raeburn 6512: } else {
6513: $checked{'mapuser'}{'other'} = ' checked="checked"';
6514: $userfield = $current->{'mapuser'};
6515: $userfieldsty = 'inline-block';
6516: }
6517: }
6518: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
6519: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
6520: if ($current->{'mapcrs'} eq 'context_id') {
1.425 raeburn 6521: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
1.320 raeburn 6522: } else {
6523: $checked{'mapcrs'}{'other'} = ' checked="checked"';
6524: $cidfield = $current->{'mapcrs'};
6525: $crsfieldsty = 'inline-block';
6526: }
6527: }
6528: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
6529: foreach my $type (@{$current->{'mapcrstype'}}) {
6530: $checked{'mapcrstype'}{$type} = ' checked="checked"';
6531: }
6532: }
1.392 raeburn 6533: if (!$current->{'storecrs'}) {
6534: $checked{'storecrs'}{'N'} = $checked{'storecrs'}{'Y'};
6535: $checked{'storecrs'}{'Y'} = '';
6536: }
1.345 raeburn 6537: if ($current->{'makecrs'}) {
1.320 raeburn 6538: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 6539: }
1.320 raeburn 6540: if (ref($current->{'makeuser'}) eq 'ARRAY') {
6541: foreach my $role (@{$current->{'makeuser'}}) {
6542: $checked{'makeuser'}{$role} = ' checked="checked"';
6543: }
6544: }
1.325 raeburn 6545: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
6546: $checked{'lcauth'}{$1} = ' checked="checked"';
6547: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
6548: $lcauthparm = $current->{'lcauthparm'};
1.425 raeburn 6549: $lcauthparmstyle = 'display:table-row';
1.325 raeburn 6550: if ($current->{'lcauth'} eq 'localauth') {
6551: $lcauthparmtext = &mt('Local auth argument');
6552: } else {
6553: $lcauthparmtext = &mt('Kerberos domain');
6554: }
6555: }
6556: }
1.320 raeburn 6557: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
6558: foreach my $role (@{$current->{'selfenroll'}}) {
6559: $checked{'selfenroll'}{$role} = ' checked="checked"';
6560: }
6561: }
6562: if (ref($current->{'maproles'}) eq 'HASH') {
6563: %rolemaps = %{$current->{'maproles'}};
6564: }
6565: if ($current->{'section'} ne '') {
1.425 raeburn 6566: $checked{'crssec'}{'Y'} = ' checked="checked"';
1.320 raeburn 6567: $crssecfieldsty = 'inline-block';
6568: if ($current->{'section'} eq 'course_section_sourcedid') {
6569: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
6570: } else {
6571: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
6572: $crssecsrc = $current->{'section'};
6573: $secsrcfieldsty = 'inline-block';
6574: }
6575: } else {
6576: $checked{'crssec'}{'N'} = ' checked="checked"';
6577: }
1.363 raeburn 6578: if ($current->{'callback'} ne '') {
6579: $callback = $current->{'callback'};
6580: $checked{'callback'}{'Y'} = ' checked="checked"';
6581: $callbacksty = 'inline-block';
6582: } else {
6583: $checked{'callback'}{'N'} = ' checked="checked"';
6584: }
1.326 raeburn 6585: if ($current->{'topmenu'}) {
6586: $checked{'topmenu'}{'Y'} = ' checked="checked"';
6587: } else {
6588: $checked{'topmenu'}{'N'} = ' checked="checked"';
6589: }
6590: if ($current->{'inlinemenu'}) {
6591: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
6592: } else {
6593: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
6594: }
6595: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
6596: $menusty = 'inline-block';
6597: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
6598: foreach my $item (@{$current->{'lcmenu'}}) {
6599: if (exists($menutitles{$item})) {
6600: $checked{'menuitem'}{$item} = ' checked="checked"';
6601: }
6602: }
6603: }
6604: } else {
6605: $menusty = 'none';
6606: }
1.320 raeburn 6607: } else {
6608: $checked{'makecrs'}{'N'} = ' checked="checked"';
6609: $checked{'crssec'}{'N'} = ' checked="checked"';
1.363 raeburn 6610: $checked{'callback'}{'N'} = ' checked="checked"';
1.326 raeburn 6611: $checked{'topmenu'}{'N'} = ' checked="checked"';
1.425 raeburn 6612: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
1.326 raeburn 6613: $checked{'menuitem'}{'grades'} = ' checked="checked"';
1.425 raeburn 6614: $menusty = 'inline-block';
1.320 raeburn 6615: }
1.325 raeburn 6616: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 6617: my %coursetypetitles = &Apache::lonlocal::texthash (
6618: official => 'Official',
6619: unofficial => 'Unofficial',
6620: community => 'Community',
6621: textbook => 'Textbook',
6622: placement => 'Placement Test',
1.325 raeburn 6623: lti => 'LTI Provider',
1.320 raeburn 6624: );
1.325 raeburn 6625: my @authtypes = ('internal','krb4','krb5','localauth');
6626: my %shortauth = (
6627: internal => 'int',
6628: krb4 => 'krb4',
6629: krb5 => 'krb5',
6630: localauth => 'loc'
6631: );
6632: my %authnames = &authtype_names();
1.320 raeburn 6633: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
6634: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
6635: my @courseroles = ('cc','in','ta','ep','st');
6636: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
6637: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
6638: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
1.363 raeburn 6639: my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
1.320 raeburn 6640: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 6641: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 6642: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.391 raeburn 6643: my $output = '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Logout options').'</legend>'.
1.392 raeburn 6644: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback to logout LON-CAPA on log out from Consumer').': '.
1.391 raeburn 6645: '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
6646: $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.(' 'x2).
6647: '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
6648: $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
6649: '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
6650: '<span class="LC_nobreak">'.&mt('Parameter').': '.
6651: '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
6652: '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
6653: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320 raeburn 6654: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
6655: foreach my $option ('sourcedid','email','other') {
6656: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
6657: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
6658: ($option eq 'other' ? '' : (' 'x2) );
6659: }
6660: $output .= '</span></div>'.
6661: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
6662: '<input type="text" name="lti_customuser_'.$num.'" '.
1.372 raeburn 6663: 'value="'.$userfield.'" /></div></fieldset>'.
1.391 raeburn 6664: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320 raeburn 6665: foreach my $ltirole (@ltiroles) {
6666: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
1.425 raeburn 6667: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
1.320 raeburn 6668: }
6669: $output .= '</fieldset>'.
1.391 raeburn 6670: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325 raeburn 6671: '<table>'.
6672: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
6673: '</table>'.
6674: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
6675: '<td class="LC_left_item">';
6676: foreach my $auth ('lti',@authtypes) {
6677: my $authtext;
6678: if ($auth eq 'lti') {
6679: $authtext = &mt('None');
6680: } else {
6681: $authtext = $authnames{$shortauth{$auth}};
6682: }
6683: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
6684: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
6685: $authtext.'</label></span> ';
6686: }
6687: $output .= '</td></tr>'.
6688: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
6689: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
6690: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
6691: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
6692: '</table></fieldset>'.
1.391 raeburn 6693: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.
6694: &mt('LON-CAPA menu items (Course Coordinator can override)').'</legend>'.
6695: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
6696: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
6697: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6698: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
6699: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
6700: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6701: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
6702: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
6703: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6704: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
6705: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
6706: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6707: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
6708: '<span class="LC_nobreak">'.&mt('Menu items').': ';
6709: foreach my $type ('fullname','coursetitle','role','logout','grades') {
6710: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
6711: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
6712: (' 'x2);
6713: }
6714: $output .= '</span></div></fieldset>'.
6715: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320 raeburn 6716: '<div class="LC_floatleft"><span class="LC_nobreak">'.
6717: &mt('Unique course identifier').': ';
6718: foreach my $option ('course_offering_sourcedid','context_id','other') {
6719: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
6720: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
6721: ($option eq 'other' ? '' : (' 'x2) );
6722: }
1.334 raeburn 6723: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320 raeburn 6724: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
6725: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
6726: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
6727: foreach my $type (@coursetypes) {
6728: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
6729: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
6730: (' 'x2);
6731: }
1.392 raeburn 6732: $output .= '</span><br /><br />'.
6733: '<span class="LC_nobreak">'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.
6734: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="0"'.
6735: $checked{'storecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6736: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="1"'.
6737: $checked{'storecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6738: '</fieldset>'.
1.391 raeburn 6739: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
6740: foreach my $ltirole (@lticourseroles) {
6741: my ($selected,$selectnone);
6742: if ($rolemaps{$ltirole} eq '') {
6743: $selectnone = ' selected="selected"';
6744: }
6745: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
6746: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
6747: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
6748: foreach my $role (@courseroles) {
6749: unless ($selectnone) {
6750: if ($rolemaps{$ltirole} eq $role) {
6751: $selected = ' selected="selected"';
6752: } else {
6753: $selected = '';
6754: }
6755: }
6756: $output .= '<option value="'.$role.'"'.$selected.'>'.
6757: &Apache::lonnet::plaintext($role,'Course').
6758: '</option>';
6759: }
6760: $output .= '</select></td>';
6761: }
6762: $output .= '</tr></table></fieldset>'.
6763: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320 raeburn 6764: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
6765: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
6766: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6767: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
6768: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6769: '</fieldset>'.
1.391 raeburn 6770: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320 raeburn 6771: foreach my $lticrsrole (@lticourseroles) {
6772: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
6773: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
6774: }
6775: $output .= '</fieldset>'.
1.391 raeburn 6776: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Course options').'</legend>'.
1.320 raeburn 6777: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
6778: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
6779: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
6780: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334 raeburn 6781: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320 raeburn 6782: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
6783: '<span class="LC_nobreak">'.&mt('From').':<label>'.
6784: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
6785: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
6786: &mt('Standard field').'</label>'.(' 'x2).
6787: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
6788: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334 raeburn 6789: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320 raeburn 6790: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337 raeburn 6791: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6792: my ($pb1p1chk,$pb1p0chk,$onclickpb);
6793: foreach my $extra ('roster','passback') {
1.320 raeburn 6794: my $checkedon = '';
6795: my $checkedoff = ' checked="checked"';
1.337 raeburn 6796: if ($extra eq 'passback') {
6797: $pb1p1chk = ' checked="checked"';
6798: $pb1p0chk = '';
1.425 raeburn 6799: $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
1.337 raeburn 6800: } else {
1.425 raeburn 6801: $onclickpb = '';
1.337 raeburn 6802: }
1.320 raeburn 6803: if (ref($current) eq 'HASH') {
6804: if (($current->{$extra})) {
6805: $checkedon = $checkedoff;
6806: $checkedoff = '';
1.337 raeburn 6807: if ($extra eq 'passback') {
6808: $passbacksty = 'inline-block';
6809: }
6810: if ($current->{'passbackformat'} eq '1.0') {
6811: $pb1p0chk = ' checked="checked"';
6812: $pb1p1chk = '';
6813: }
1.320 raeburn 6814: }
6815: }
6816: $output .= $lt{$extra}.' '.
1.337 raeburn 6817: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320 raeburn 6818: &mt('No').'</label>'.(' 'x2).
1.339 raeburn 6819: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320 raeburn 6820: &mt('Yes').'</label><br />';
6821: }
1.337 raeburn 6822: $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
6823: '<span class="LC_nobreak">'.&mt('Grade format').
6824: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
6825: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
6826: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
1.363 raeburn 6827: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
1.391 raeburn 6828: '<div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>';
1.334 raeburn 6829: $output .= '</span></div></fieldset>';
1.320 raeburn 6830: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
6831: #
6832: # $output .= '</fieldset>'.
6833: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
6834: return $output;
6835: }
6836:
1.326 raeburn 6837: sub ltimenu_titles {
6838: return &Apache::lonlocal::texthash(
6839: fullname => 'Full name',
6840: coursetitle => 'Course title',
6841: role => 'Role',
6842: logout => 'Logout',
6843: grades => 'Grades',
6844: );
6845: }
6846:
1.434 raeburn 6847: sub linkprot_suggestions {
6848: my ($suggested,$itemcount) = @_;
6849: my $count = 0;
6850: my $next = 1;
6851: my %lt = &Apache::lonlocal::texthash(
6852: 'name' => 'Suggested Launcher',
6853: 'info' => 'Recommendations',
6854: );
6855: my ($datatable,$css_class,$dest);
6856: if (ref($suggested) eq 'HASH') {
6857: my @current = sort { $a <=> $b } keys(%{$suggested});
6858: $next += $current[-1];
6859: for (my $i=0; $i<@current; $i++) {
6860: my $num = $current[$i];
6861: my %values;
6862: if (ref($suggested->{$num}) eq 'HASH') {
6863: %values = %{$suggested->{$num}};
6864: } else {
6865: next;
6866: }
6867: $css_class = $$itemcount%2?' class="LC_odd_row"':'';
6868: $datatable .=
6869: '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6870: '<label><input type="checkbox" name="linkprot_suggested_del" value="'.$i.'" />'."\n".
6871: &mt('Delete?').'</label></span></td><td>'."\n".
6872: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'name'}.'</legend>'."\n".
6873: '<input type="text" size="15" name="linkprot_suggested_name_'.$i.'" value="'.$values{'name'}.'" autocomplete="off" />'."\n".
6874: '</fieldset></div>'.
6875: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'info'}.'</legend>'."\n".
6876: '<textarea cols="55" rows="5" name="linkprot_suggested_info_'.$i.'">'.$values{'info'}.'</textarea>'.
6877: '</fieldset></div>'.
6878: '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
6879: '<input type="hidden" name="linkprot_suggested_id_'.$i.'" value="'.$num.'" /></td></tr>'."\n";
6880: $$itemcount ++;
6881: }
6882: }
6883: $css_class = $$itemcount%2?' class="LC_odd_row"':'';
6884: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6885: '<input type="hidden" name="linkprot_suggested_maxnum" value="'.$next.'" />'."\n".
6886: '<input type="checkbox" name="linkprot_suggested_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6887: '<td>'."\n".
6888: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'name'}.'</legend>'."\n".
6889: '<input type="text" size="15" name="linkprot_suggested_name_add" value="" autocomplete="off" />'."\n".
6890: '</fieldset></div>'.
6891: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'info'}.'</legend>'."\n".
6892: '<textarea cols="55" rows="5" name="linkprot_suggested_info_add"></textarea>'.
6893: '</fieldset></div>'.
6894: '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
6895: '</td></tr>'."\n";
6896: return $datatable;
6897: }
6898:
1.121 raeburn 6899: sub print_coursedefaults {
1.139 raeburn 6900: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 6901: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 6902: my $itemcount = 1;
1.192 raeburn 6903: my %choices = &Apache::lonlocal::texthash (
6904: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 6905: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.432 raeburn 6906: coursequota => 'Default cumulative quota for all group portfolio spaces in course (MB)',
1.192 raeburn 6907: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
6908: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 6909: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
6910: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.398 raeburn 6911: inline_chem => 'Use inline previewer for chemical reaction response in place of pop-up',
1.314 raeburn 6912: texengine => 'Default method to display mathematics',
1.257 raeburn 6913: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 6914: canclone => "People who may clone a course (besides course's owner and coordinators)",
6915: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.405 raeburn 6916: ltiauth => 'Student username in LTI launch of deep-linked URL can be accepted without re-authentication',
1.422 raeburn 6917: domexttool => 'External Tools defined in the domain may be used in courses/communities (by type)',
6918: exttool => 'External Tools can be defined and configured in courses/communities (by type)',
1.432 raeburn 6919: crsauthor => 'Standard LON-CAPA problems can be created within a course/community (by type)',
1.192 raeburn 6920: );
1.198 raeburn 6921: my %staticdefaults = (
6922: anonsurvey_threshold => 10,
6923: uploadquota => 500,
1.428 raeburn 6924: coursequota => 20,
1.257 raeburn 6925: postsubmit => 60,
1.276 raeburn 6926: mysqltables => 172800,
1.422 raeburn 6927: domexttool => 1,
6928: exttool => 0,
1.432 raeburn 6929: crsauthor => 1,
1.198 raeburn 6930: );
1.139 raeburn 6931: if ($position eq 'top') {
1.257 raeburn 6932: %defaultchecked = (
6933: 'canuse_pdfforms' => 'off',
6934: 'uselcmath' => 'on',
6935: 'usejsme' => 'on',
1.398 raeburn 6936: 'inline_chem' => 'on',
1.289 raeburn 6937: 'canclone' => 'none',
1.257 raeburn 6938: );
1.398 raeburn 6939: @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem');
1.349 raeburn 6940: my $deftex = $Apache::lonnet::deftex;
1.314 raeburn 6941: if (ref($settings) eq 'HASH') {
6942: if ($settings->{'texengine'}) {
6943: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
6944: $deftex = $settings->{'texengine'};
6945: }
6946: }
6947: }
6948: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6949: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
6950: '<span class="LC_nobreak">'.$choices{'texengine'}.
6951: '</span></td><td class="LC_right_item">'.
6952: '<select name="texengine">'."\n";
6953: my %texoptions = (
6954: MathJax => 'MathJax',
6955: mimetex => &mt('Convert to Images'),
6956: tth => &mt('TeX to HTML'),
6957: );
6958: foreach my $renderer ('MathJax','mimetex','tth') {
6959: my $selected = '';
6960: if ($renderer eq $deftex) {
6961: $selected = ' selected="selected"';
6962: }
6963: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
6964: }
6965: $mathdisp .= '</select></td></tr>'."\n";
6966: $itemcount ++;
1.139 raeburn 6967: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 6968: \%choices,$itemcount);
1.314 raeburn 6969: $datatable = $mathdisp.$datatable;
1.264 raeburn 6970: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6971: $datatable .=
1.306 raeburn 6972: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 6973: '<span class="LC_nobreak">'.$choices{'canclone'}.
6974: '</span></td><td class="LC_left_item">';
6975: my $currcanclone = 'none';
6976: my $onclick;
6977: my @cloneoptions = ('none','domain');
1.380 raeburn 6978: my %clonetitles = &Apache::lonlocal::texthash (
1.264 raeburn 6979: none => 'No additional course requesters',
6980: domain => "Any course requester in course's domain",
6981: instcode => 'Course requests for official courses ...',
6982: );
6983: my (%codedefaults,@code_order,@posscodes);
6984: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
6985: \@code_order) eq 'ok') {
6986: if (@code_order > 0) {
6987: push(@cloneoptions,'instcode');
6988: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
6989: }
6990: }
6991: if (ref($settings) eq 'HASH') {
6992: if ($settings->{'canclone'}) {
6993: if (ref($settings->{'canclone'}) eq 'HASH') {
6994: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
6995: if (@code_order > 0) {
6996: $currcanclone = 'instcode';
6997: @posscodes = @{$settings->{'canclone'}{'instcode'}};
6998: }
6999: }
7000: } elsif ($settings->{'canclone'} eq 'domain') {
7001: $currcanclone = $settings->{'canclone'};
7002: }
7003: }
1.289 raeburn 7004: }
1.264 raeburn 7005: foreach my $option (@cloneoptions) {
7006: my ($checked,$additional);
7007: if ($currcanclone eq $option) {
7008: $checked = ' checked="checked"';
7009: }
7010: if ($option eq 'instcode') {
7011: if (@code_order) {
7012: my $show = 'none';
7013: if ($checked) {
7014: $show = 'block';
7015: }
1.317 raeburn 7016: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 7017: &mt('Institutional codes for new and cloned course have identical:').
7018: '<br />';
7019: foreach my $item (@code_order) {
7020: my $codechk;
7021: if ($checked) {
7022: if (grep(/^\Q$item\E$/,@posscodes)) {
7023: $codechk = ' checked="checked"';
7024: }
7025: }
7026: $additional .= '<label>'.
7027: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
7028: $item.'</label>';
7029: }
7030: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
7031: }
7032: }
7033: $datatable .=
7034: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
7035: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
7036: '</label> '.$additional.'</span><br />';
7037: }
7038: $datatable .= '</td>'.
7039: '</tr>';
7040: $itemcount ++;
1.139 raeburn 7041: } else {
7042: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.428 raeburn 7043: my ($currdefresponder,%defcredits,%curruploadquota,%currcoursequota,
7044: %deftimeout,%currmysql);
1.192 raeburn 7045: my $currusecredits = 0;
1.257 raeburn 7046: my $postsubmitclient = 1;
1.405 raeburn 7047: my $ltiauth = 0;
1.422 raeburn 7048: my %domexttool;
7049: my %exttool;
1.432 raeburn 7050: my %crsauthor;
1.271 raeburn 7051: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 7052: if (ref($settings) eq 'HASH') {
1.404 raeburn 7053: if ($settings->{'ltiauth'}) {
7054: $ltiauth = 1;
1.405 raeburn 7055: }
1.422 raeburn 7056: if (ref($settings->{'domexttool'}) eq 'HASH') {
7057: foreach my $type (@types) {
7058: if ($settings->{'domexttool'}->{$type}) {
7059: $domexttool{$type} = ' checked="checked"';
7060: }
7061: }
7062: } else {
7063: foreach my $type (@types) {
7064: if ($staticdefaults{'domexttool'}) {
7065: $domexttool{$type} = ' checked="checked"';
7066: }
7067: }
7068: }
7069: if (ref($settings->{'exttool'}) eq 'HASH') {
7070: foreach my $type (@types) {
7071: if ($settings->{'exttool'}->{$type}) {
7072: $exttool{$type} = ' checked="checked"';
7073: }
7074: }
7075: }
1.432 raeburn 7076: if (ref($settings->{'crsauthor'}) eq 'HASH') {
7077: foreach my $type (@types) {
7078: if ($settings->{'crsauthor'}->{$type}) {
7079: $crsauthor{$type} = ' checked="checked"';
7080: }
7081: }
7082: } else {
7083: foreach my $type (@types) {
7084: if ($staticdefaults{'crsauthor'}) {
7085: $crsauthor{$type} = ' checked="checked"';
7086: }
7087: }
7088: }
1.139 raeburn 7089: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 7090: if (ref($settings->{'uploadquota'}) eq 'HASH') {
7091: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
7092: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
7093: }
7094: }
1.428 raeburn 7095: if (ref($settings->{'coursequota'}) eq 'HASH') {
7096: foreach my $type (keys(%{$settings->{'coursequota'}})) {
7097: $currcoursequota{$type} = $settings->{'coursequota'}{$type};
7098: }
7099: }
1.192 raeburn 7100: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 7101: foreach my $type (@types) {
7102: next if ($type eq 'community');
7103: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
7104: if ($defcredits{$type} ne '') {
7105: $currusecredits = 1;
7106: }
7107: }
7108: }
7109: if (ref($settings->{'postsubmit'}) eq 'HASH') {
7110: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
7111: $postsubmitclient = 0;
7112: foreach my $type (@types) {
7113: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7114: }
7115: } else {
7116: foreach my $type (@types) {
7117: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
7118: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 7119: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 7120: } else {
7121: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7122: }
7123: } else {
7124: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7125: }
7126: }
7127: }
7128: } else {
7129: foreach my $type (@types) {
7130: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 7131: }
7132: }
1.276 raeburn 7133: if (ref($settings->{'mysqltables'}) eq 'HASH') {
7134: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
7135: $currmysql{$type} = $settings->{'mysqltables'}{$type};
7136: }
7137: } else {
7138: foreach my $type (@types) {
7139: $currmysql{$type} = $staticdefaults{'mysqltables'};
7140: }
7141: }
1.258 raeburn 7142: } else {
7143: foreach my $type (@types) {
7144: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.422 raeburn 7145: if ($staticdefaults{'domexttool'}) {
7146: $domexttool{$type} = ' checked="checked"';
7147: }
1.432 raeburn 7148: if ($staticdefaults{'crsauthor'}) {
7149: $crsauthor{$type} = ' checked="checked"';
7150: }
1.258 raeburn 7151: }
1.139 raeburn 7152: }
7153: if (!$currdefresponder) {
1.198 raeburn 7154: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 7155: } elsif ($currdefresponder < 1) {
7156: $currdefresponder = 1;
7157: }
1.198 raeburn 7158: foreach my $type (@types) {
7159: if ($curruploadquota{$type} eq '') {
7160: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
7161: }
1.428 raeburn 7162: if ($currcoursequota{$type} eq '') {
7163: $currcoursequota{$type} = $staticdefaults{'coursequota'};
7164: }
1.198 raeburn 7165: }
1.139 raeburn 7166: $datatable .=
1.192 raeburn 7167: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7168: $choices{'anonsurvey_threshold'}.
1.139 raeburn 7169: '</span></td>'.
7170: '<td class="LC_right_item"><span class="LC_nobreak">'.
7171: '<input type="text" name="anonsurvey_threshold"'.
7172: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 7173: '</td></tr>'."\n";
7174: $itemcount ++;
7175: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7176: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7177: $choices{'uploadquota'}.
7178: '</span></td>'.
1.306 raeburn 7179: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 7180: '<table><tr>';
1.198 raeburn 7181: foreach my $type (@types) {
1.306 raeburn 7182: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 7183: '<input type="text" name="uploadquota_'.$type.'"'.
7184: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
7185: }
7186: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 7187: $itemcount ++;
1.428 raeburn 7188: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7189: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7190: $choices{'coursequota'}.
7191: '</span></td>'.
7192: '<td style="text-align: right" class="LC_right_item">'.
7193: '<table><tr>';
7194: foreach my $type (@types) {
7195: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
7196: '<input type="text" name="coursequota_'.$type.'"'.
7197: ' value="'.$currcoursequota{$type}.'" size="5" /></td>';
7198: }
7199: $datatable .= '</tr></table></td></tr>'."\n";
7200: $itemcount ++;
1.236 raeburn 7201: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 7202: my $display = 'none';
1.192 raeburn 7203: if ($currusecredits) {
7204: $display = 'block';
7205: }
7206: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 7207: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
7208: foreach my $type (@types) {
7209: next if ($type eq 'community');
1.306 raeburn 7210: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7211: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 7212: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 7213: }
7214: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 7215: %defaultchecked = ('coursecredits' => 'off');
7216: @toggles = ('coursecredits');
7217: my $current = {
7218: 'coursecredits' => $currusecredits,
7219: };
7220: (my $table,$itemcount) =
7221: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 7222: \%choices,$itemcount,$onclick,$additional,'left');
7223: $datatable .= $table;
7224: $onclick = "toggleDisplay(this.form,'studentsubmission');";
7225: my $display = 'none';
7226: if ($postsubmitclient) {
7227: $display = 'block';
7228: }
7229: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 7230: &mt('Number of seconds submit is disabled').'<br />'.
7231: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
7232: '<table><tr>';
1.257 raeburn 7233: foreach my $type (@types) {
1.306 raeburn 7234: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7235: '<input type="text" name="'.$type.'_timeout" value="'.
7236: $deftimeout{$type}.'" size="5" /></td>';
7237: }
7238: $additional .= '</tr></table></div>'."\n";
7239: %defaultchecked = ('postsubmit' => 'on');
7240: @toggles = ('postsubmit');
1.280 raeburn 7241: $current = {
7242: 'postsubmit' => $postsubmitclient,
7243: };
1.257 raeburn 7244: ($table,$itemcount) =
7245: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7246: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 7247: $datatable .= $table;
1.276 raeburn 7248: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7249: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7250: $choices{'mysqltables'}.
7251: '</span></td>'.
1.306 raeburn 7252: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 7253: '<table><tr>';
7254: foreach my $type (@types) {
1.306 raeburn 7255: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 7256: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 7257: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 7258: }
7259: $datatable .= '</tr></table></td></tr>'."\n";
7260: $itemcount ++;
1.404 raeburn 7261: %defaultchecked = ('ltiauth' => 'off');
7262: @toggles = ('ltiauth');
7263: $current = {
7264: 'ltiauth' => $ltiauth,
7265: };
7266: ($table,$itemcount) =
7267: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7268: \%choices,$itemcount,undef,undef,'left');
7269: $datatable .= $table;
1.422 raeburn 7270: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7271: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7272: $choices{'domexttool'}.
7273: '</span></td>'.
7274: '<td style="text-align: right" class="LC_right_item">'.
7275: '<table><tr>';
7276: foreach my $type (@types) {
7277: $datatable .= '<td style="text-align: left">'.
7278: '<span class="LC_nobreak">'.
7279: '<input type="checkbox" name="domexttool"'.
7280: ' value="'.$type.'"'.$domexttool{$type}.' />'.
7281: &mt($type).'</span></td>'."\n";
7282: }
7283: $datatable .= '</tr></table></td></tr>'."\n";
1.404 raeburn 7284: $itemcount ++;
1.422 raeburn 7285: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7286: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7287: $choices{'exttool'}.
7288: '</span></td>'.
7289: '<td style="text-align: right" class="LC_right_item">'.
7290: '<table><tr>';
7291: foreach my $type (@types) {
7292: $datatable .= '<td style="text-align: left">'.
7293: '<span class="LC_nobreak">'.
7294: '<input type="checkbox" name="exttool"'.
7295: ' value="'.$type.'"'.$exttool{$type}.' />'.
7296: &mt($type).'</span></td>'."\n";
7297: }
7298: $datatable .= '</tr></table></td></tr>'."\n";
1.432 raeburn 7299: $itemcount ++;
7300: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7301: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7302: $choices{'crsauthor'}.
7303: '</span></td>'.
7304: '<td style="text-align: right" class="LC_right_item">'.
7305: '<table><tr>';
7306: foreach my $type (@types) {
7307: $datatable .= '<td style="text-align: left">'.
7308: '<span class="LC_nobreak">'.
7309: '<input type="checkbox" name="crsauthor"'.
7310: ' value="'.$type.'"'.$crsauthor{$type}.' />'.
7311: &mt($type).'</span></td>'."\n";
7312: }
7313: $datatable .= '</tr></table></td></tr>'."\n";
1.139 raeburn 7314: }
1.192 raeburn 7315: $$rowtotal += $itemcount;
1.121 raeburn 7316: return $datatable;
1.118 jms 7317: }
7318:
1.429 raeburn 7319: sub print_authordefaults {
7320: my ($position,$dom,$settings,$rowtotal) = @_;
7321: my ($css_class,$datatable,%checkedon,%checkedoff);
7322: my $itemcount = 1;
7323: my %titles = &authordefaults_titles();
7324: if ($position eq 'top') {
7325: my %defaultchecked = (
7326: 'nocodemirror' => 'off',
1.437 ! raeburn 7327: 'daxecollapse' => 'off',
1.429 raeburn 7328: 'domcoordacc' => 'on',
7329: );
1.437 ! raeburn 7330: my @toggles = ('nocodemirror','daxecollapse','domcoordacc');
1.429 raeburn 7331: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
7332: \%titles,$itemcount);
7333: my %staticdefaults = (
7334: 'copyright' => 'default',
7335: 'sourceavail' => 'closed',
7336: );
7337: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7338: my %currrights;
7339: foreach my $item ('copyright','sourceavail') {
7340: $currrights{$item} = $staticdefaults{$item};
7341: if (ref($settings) eq 'HASH') {
7342: if (exists($settings->{$item})) {
7343: $currrights{$item} = $settings->{$item};
7344: }
7345: }
7346: }
7347: $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
7348: '<span class="LC_nobreak">'.$titles{'copyright'}.
7349: '</span></td><td class="LC_right_item">'.
7350: &selectbox('copyright',$currrights{'copyright'},'',
7351: \&Apache::loncommon::copyrightdescription,
7352: (grep !/^priv|custom$/,(&Apache::loncommon::copyrightids))).
7353: '</td></tr>'."\n";
7354: $itemcount ++;
7355: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7356: $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
7357: '<span class="LC_nobreak">'.$titles{'sourceavail'}.
7358: '</span></td><td class="LC_right_item">'.
7359: &selectbox('sourceavail',$currrights{'sourceavail'},'',
7360: \&Apache::loncommon::source_copyrightdescription,
7361: (&Apache::loncommon::source_copyrightids)).
7362: '</td></tr>'."\n";
7363: } else {
7364: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7365: my $curreditors;
7366: my %staticdefaults = (
7367: editors => ['edit','xml'],
7368: authorquota => 500,
7369: webdav => 0,
7370: );
7371: my $curreditors = $staticdefaults{'editors'};
7372: if ((ref($settings) eq 'HASH') &&
7373: (ref($settings->{'editors'}) eq 'ARRAY')) {
7374: $curreditors = $settings->{'editors'};
7375: } else {
7376: $curreditors = $staticdefaults{'editors'};
7377: }
7378: my @editors = ('edit','xml','daxe');
7379: $datatable = '<tr'.$css_class.'>'."\n".
7380: '<td>'.$titles{'editors'}.'</td>'."\n".
7381: '<td class="LC_left_item">'."\n".
7382: '<span class="LC_nobreak">';
7383: foreach my $editor (@editors) {
7384: my $checked;
7385: if (grep(/^\Q$editor\E$/,@{$curreditors})) {
7386: $checked = ' checked="checked"';
7387: }
7388: $datatable .= '<label>'.
7389: '<input type="checkbox" name="author_editors" '.
7390: $checked.' value="'.$editor.'" '.
7391: 'onclick="javascript:checkEditors(this.form,'."'author_editors'".',this);" />'.
7392: $titles{$editor}.'</label> ';
7393: }
7394: $datatable .= '</span>'."\n".'</td>'."\n".'</tr>'."\n";
7395: $itemcount ++;
7396: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7397: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7398: my @insttypes;
7399: if (ref($types) eq 'ARRAY') {
7400: @insttypes = @{$types};
7401: }
7402: my $typecount = 0;
7403: my %domconf = &Apache::lonnet::get_dom('configuration',['quotas'],$dom);
7404: my @items = ('webdav','authorquota');
7405: my %quotas;
7406: if (ref($domconf{'quotas'}) eq 'HASH') {
7407: %quotas = %{$domconf{'quotas'}};
7408: foreach my $item (@items) {
7409: if (ref($quotas{$item}) eq 'HASH') {
7410: foreach my $type (@insttypes,'default') {
7411: if ($item eq 'authorquota') {
7412: if ($quotas{$item}{$type} !~ /^\d+$/) {
7413: $quotas{$item}{$type} = $staticdefaults{$item};
7414: }
7415: } elsif ($item eq 'webdav') {
7416: if ($quotas{$item}{$type} !~ /^(0|1)$/) {
7417: $quotas{$item}{$type} = $staticdefaults{$item};
7418: }
7419: }
7420: }
7421: } else {
7422: foreach my $type (@insttypes,'default') {
7423: $quotas{$item}{$type} = $staticdefaults{$item};
7424: }
7425: }
7426: }
7427: } else {
7428: foreach my $item (@items) {
7429: foreach my $type (@insttypes,'default') {
7430: $quotas{$item}{$type} = $staticdefaults{$item};
7431: }
7432: }
7433: }
7434: if (ref($usertypes) eq 'HASH') {
7435: my $numinrow = 4;
7436: my $onclick = '';
7437: $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
7438: $numinrow,$othertitle,'authorquota',
7439: \$itemcount,$onclick);
7440: $itemcount ++;
7441: $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
7442: $numinrow,$othertitle,'webdav',
7443: \$itemcount);
7444: $itemcount ++;
7445: }
7446: my $checkedno = ' checked="checked"';
7447: my ($checkedon,$checkedoff);
7448: if (ref($quotas{'webdav'}) eq 'HASH') {
1.436 raeburn 7449: if ($quotas{'webdav'}{'_LC_adv'} =~ /^0|1$/) {
1.429 raeburn 7450: if ($quotas{'webdav'}{'_LC_adv'}) {
7451: $checkedon = $checkedno;
7452: } else {
7453: $checkedoff = $checkedno;
7454: }
7455: undef($checkedno);
7456: }
7457: }
7458: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7459: $datatable .= '<tr'.$css_class.'>'.
7460: '<td>'.$titles{'webdav_LC_adv'}.'<br />'.
7461: $titles{'webdav_LC_adv_over'}.
7462: '</td>'.
7463: '<td class="LC_left_item">';
7464: foreach my $option ('none','off','on') {
7465: my ($text,$val,$checked);
7466: if ($option eq 'none') {
7467: $text = $titles{'none'};
7468: $val = '';
7469: $checked = $checkedno;
7470: } elsif ($option eq 'off') {
7471: $text = $titles{'overoff'};
7472: $val = 0;
7473: $checked = $checkedoff;
7474: } elsif ($option eq 'on') {
7475: $text = $titles{'overon'};
7476: $val = 1;
7477: $checked = $checkedon;
1.436 raeburn 7478: }
1.429 raeburn 7479: $datatable .= '<span class="LC_nobreak"><label>'.
7480: '<input type="radio" name="webdav_LC_adv"'.
7481: ' value="'.$val.'"'.$checked.' />'.
7482: $text.'</label></span> ';
7483: }
7484: $datatable .= '</td></tr>';
7485: $itemcount ++;
7486: }
7487: $$rowtotal += $itemcount;
7488: return $datatable;
7489: }
7490:
7491: sub authordefaults_titles {
7492: return &Apache::lonlocal::texthash(
7493: copyright => 'Copyright/Distribution',
7494: sourceavail => ' Source Available',
7495: editors => 'Available Editors',
7496: webdav => 'WebDAV',
7497: authorquota => 'Authoring Space quotas (MB)',
7498: nocodemirror => 'Deactivate CodeMirror for EditXML editor',
1.437 ! raeburn 7499: daxecollapse => 'Daxe editor: LON-CAPA standard menus start collapsed',
1.429 raeburn 7500: domcoordacc => 'Dom. Coords. can enter Authoring Spaces in domain',
7501: edit => 'Standard editor (Edit)',
7502: xml => 'Text editor (EditXML)',
7503: daxe => 'Daxe editor (Daxe)',
7504: webdav_LC_adv => 'WebDAV access for LON-CAPA "advanced" users',
7505: webdav_LC_adv_over => '(overrides access based on affiliation, if set)',
7506: none => 'No override set',
7507: overon => 'Override -- webDAV on',
1.436 raeburn 7508: overoff => 'Override -- webDAV off',
1.429 raeburn 7509: );
7510: }
7511:
7512: sub selectbox {
7513: my ($name,$value,$readonly,$functionref,@idlist)=@_;
7514: my $selout = '<select name="'.$name.'">';
7515: foreach my $id (@idlist) {
7516: $selout.='<option value="'.$id.'"';
7517: if ($id eq $value) {
7518: $selout.=' selected="selected"';
7519: }
7520: if ($readonly) {
7521: $selout .= ' disabled="disabled"';
7522: }
7523: $selout.='>'.&{$functionref}($id).'</option>';
7524: }
7525: $selout.='</select>';
7526: return $selout;
7527: }
7528:
1.231 raeburn 7529: sub print_selfenrollment {
7530: my ($position,$dom,$settings,$rowtotal) = @_;
7531: my ($css_class,$datatable);
7532: my $itemcount = 1;
1.271 raeburn 7533: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 7534: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 7535: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
7536: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 7537: my @rows;
7538: my $key;
7539: if ($position eq 'top') {
7540: $key = 'admin';
7541: if (ref($rowsref) eq 'ARRAY') {
7542: @rows = @{$rowsref};
7543: }
7544: } elsif ($position eq 'middle') {
7545: $key = 'default';
7546: @rows = ('types','registered','approval','limit');
7547: }
7548: foreach my $row (@rows) {
7549: if (defined($titlesref->{$row})) {
7550: $itemcount ++;
7551: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7552: $datatable .= '<tr'.$css_class.'>'.
7553: '<td>'.$titlesref->{$row}.'</td>'.
7554: '<td class="LC_left_item">'.
7555: '<table><tr>';
7556: my (%current,%currentcap);
7557: if (ref($settings) eq 'HASH') {
7558: if (ref($settings->{$key}) eq 'HASH') {
7559: foreach my $type (@types) {
7560: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7561: $current{$type} = $settings->{$key}->{$type}->{$row};
7562: }
7563: if (($row eq 'limit') && ($key eq 'default')) {
7564: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7565: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
7566: }
7567: }
7568: }
7569: }
7570: }
7571: my %roles = (
7572: '0' => &Apache::lonnet::plaintext('dc'),
7573: );
7574:
7575: foreach my $type (@types) {
7576: unless (($row eq 'registered') && ($key eq 'default')) {
7577: $datatable .= '<th>'.&mt($type).'</th>';
7578: }
7579: }
7580: unless (($row eq 'registered') && ($key eq 'default')) {
7581: $datatable .= '</tr><tr>';
7582: }
7583: foreach my $type (@types) {
7584: if ($type eq 'community') {
7585: $roles{'1'} = &mt('Community personnel');
7586: } else {
7587: $roles{'1'} = &mt('Course personnel');
7588: }
7589: $datatable .= '<td style="vertical-align: top">';
7590: if ($position eq 'top') {
7591: my %checked;
7592: if ($current{$type} eq '0') {
7593: $checked{'0'} = ' checked="checked"';
7594: } else {
7595: $checked{'1'} = ' checked="checked"';
7596: }
7597: foreach my $role ('1','0') {
7598: $datatable .= '<span class="LC_nobreak"><label>'.
7599: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
7600: 'value="'.$role.'"'.$checked{$role}.' />'.
7601: $roles{$role}.'</label></span> ';
7602: }
7603: } else {
7604: if ($row eq 'types') {
7605: my %checked;
7606: if ($current{$type} =~ /^(all|dom)$/) {
7607: $checked{$1} = ' checked="checked"';
7608: } else {
7609: $checked{''} = ' checked="checked"';
7610: }
7611: foreach my $val ('','dom','all') {
7612: $datatable .= '<span class="LC_nobreak"><label>'.
7613: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7614: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7615: }
7616: } elsif ($row eq 'registered') {
7617: my %checked;
7618: if ($current{$type} eq '1') {
7619: $checked{'1'} = ' checked="checked"';
7620: } else {
7621: $checked{'0'} = ' checked="checked"';
7622: }
7623: foreach my $val ('0','1') {
7624: $datatable .= '<span class="LC_nobreak"><label>'.
7625: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7626: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7627: }
7628: } elsif ($row eq 'approval') {
7629: my %checked;
7630: if ($current{$type} =~ /^([12])$/) {
7631: $checked{$1} = ' checked="checked"';
7632: } else {
7633: $checked{'0'} = ' checked="checked"';
7634: }
7635: for my $val (0..2) {
7636: $datatable .= '<span class="LC_nobreak"><label>'.
7637: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7638: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7639: }
7640: } elsif ($row eq 'limit') {
7641: my %checked;
7642: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
7643: $checked{$1} = ' checked="checked"';
7644: } else {
7645: $checked{'none'} = ' checked="checked"';
7646: }
7647: my $cap;
7648: if ($currentcap{$type} =~ /^\d+$/) {
7649: $cap = $currentcap{$type};
7650: }
7651: foreach my $val ('none','allstudents','selfenrolled') {
7652: $datatable .= '<span class="LC_nobreak"><label>'.
7653: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7654: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7655: }
7656: $datatable .= '<br />'.
7657: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
7658: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
7659: '</span>';
7660: }
7661: }
7662: $datatable .= '</td>';
7663: }
7664: $datatable .= '</tr>';
7665: }
7666: $datatable .= '</table></td></tr>';
7667: }
7668: } elsif ($position eq 'bottom') {
1.235 raeburn 7669: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
7670: }
7671: $$rowtotal += $itemcount;
7672: return $datatable;
7673: }
7674:
7675: sub print_validation_rows {
7676: my ($caller,$dom,$settings,$rowtotal) = @_;
7677: my ($itemsref,$namesref,$fieldsref);
7678: if ($caller eq 'selfenroll') {
7679: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
7680: } elsif ($caller eq 'requestcourses') {
7681: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
7682: }
7683: my %currvalidation;
7684: if (ref($settings) eq 'HASH') {
7685: if (ref($settings->{'validation'}) eq 'HASH') {
7686: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 7687: }
1.235 raeburn 7688: }
7689: my $datatable;
7690: my $itemcount = 0;
7691: foreach my $item (@{$itemsref}) {
7692: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7693: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7694: $namesref->{$item}.
7695: '</span></td>'.
7696: '<td class="LC_left_item">';
7697: if (($item eq 'url') || ($item eq 'button')) {
7698: $datatable .= '<span class="LC_nobreak">'.
7699: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
7700: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
7701: } elsif ($item eq 'fields') {
7702: my @currfields;
7703: if (ref($currvalidation{$item}) eq 'ARRAY') {
7704: @currfields = @{$currvalidation{$item}};
7705: }
7706: foreach my $field (@{$fieldsref}) {
7707: my $check = '';
7708: if (grep(/^\Q$field\E$/,@currfields)) {
7709: $check = ' checked="checked"';
7710: }
7711: $datatable .= '<span class="LC_nobreak"><label>'.
7712: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
7713: ' value="'.$field.'"'.$check.' />'.$field.
7714: '</label></span> ';
7715: }
7716: } elsif ($item eq 'markup') {
1.334 raeburn 7717: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 7718: $currvalidation{$item}.
1.231 raeburn 7719: '</textarea>';
1.235 raeburn 7720: }
7721: $datatable .= '</td></tr>'."\n";
7722: if (ref($rowtotal)) {
1.231 raeburn 7723: $itemcount ++;
7724: }
7725: }
1.235 raeburn 7726: if ($caller eq 'requestcourses') {
7727: my %currhash;
1.248 raeburn 7728: if (ref($settings) eq 'HASH') {
7729: if (ref($settings->{'validation'}) eq 'HASH') {
7730: if ($settings->{'validation'}{'dc'} ne '') {
7731: $currhash{$settings->{'validation'}{'dc'}} = 1;
7732: }
1.235 raeburn 7733: }
7734: }
7735: my $numinrow = 2;
7736: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
7737: 'validationdc',%currhash);
1.247 raeburn 7738: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 7739: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 7740: if ($numdc > 1) {
1.247 raeburn 7741: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 7742: } else {
1.247 raeburn 7743: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 7744: }
1.247 raeburn 7745: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 7746: $itemcount ++;
7747: }
7748: if (ref($rowtotal)) {
7749: $$rowtotal += $itemcount;
7750: }
1.231 raeburn 7751: return $datatable;
7752: }
7753:
1.357 raeburn 7754: sub print_privacy {
7755: my ($position,$dom,$settings,$rowtotal) = @_;
7756: my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
7757: my $itemcount = 0;
1.417 raeburn 7758: if ($position eq 'top') {
7759: $numinrow = 2;
7760: } else {
1.357 raeburn 7761: @items = ('domain','author','course','community');
7762: %names = &Apache::lonlocal::texthash (
7763: domain => 'Assigned domain role(s)',
7764: author => 'Assigned co-author role(s)',
7765: course => 'Assigned course role(s)',
1.416 raeburn 7766: community => 'Assigned community role(s)',
1.357 raeburn 7767: );
7768: $numinrow = 4;
7769: ($othertitle,$usertypes,$types) =
7770: &Apache::loncommon::sorted_inst_types($dom);
7771: }
7772: if (($position eq 'top') || ($position eq 'middle')) {
7773: my (%by_ip,%by_location,@intdoms,@instdoms);
7774: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
7775: if ($position eq 'top') {
7776: my %curr;
7777: my @options = ('none','user','domain','auto');
7778: my %titles = &Apache::lonlocal::texthash (
7779: none => 'Not allowed',
7780: user => 'User authorizes',
7781: domain => 'DC authorizes',
7782: auto => 'Unrestricted',
7783: instdom => 'Other domain shares institution/provider',
7784: extdom => 'Other domain has different institution/provider',
1.418 raeburn 7785: notify => 'Notify when role needs authorization',
1.357 raeburn 7786: );
7787: my %names = &Apache::lonlocal::texthash (
7788: domain => 'Domain role',
7789: author => 'Co-author role',
7790: course => 'Course role',
7791: community => 'Community role',
7792: );
7793: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7794: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7795: foreach my $domtype ('instdom','extdom') {
7796: my (%checked,$skip);
7797: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7798: $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
7799: '<td class="LC_left_item">';
7800: if ($domtype eq 'instdom') {
7801: unless (@instdoms > 1) {
7802: $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
7803: $skip = 1;
7804: }
7805: } elsif ($domtype eq 'extdom') {
7806: if (keys(%by_location) == 0) {
7807: $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
7808: $skip = 1;
7809: }
7810: }
7811: unless ($skip) {
7812: foreach my $roletype ('domain','author','course','community') {
7813: $checked{'auto'} = ' checked="checked"';
7814: if (ref($settings) eq 'HASH') {
7815: if (ref($settings->{approval}) eq 'HASH') {
7816: if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
7817: if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
7818: $checked{$1} = ' checked="checked"';
7819: $checked{'auto'} = '';
7820: }
7821: }
7822: }
7823: }
7824: $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
7825: foreach my $option (@options) {
7826: $datatable .= '<span class="LC_nobreak"><label>'.
7827: '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
7828: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
7829: '</label></span> ';
7830: }
7831: $datatable .= '</fieldset>';
7832: }
7833: }
7834: $datatable .= '</td></tr>';
7835: $itemcount ++;
7836: }
1.417 raeburn 7837: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7838: $datatable .= '<tr'.$css_class.'><td>'.$titles{'notify'}.'</td>'.
7839: '<td class="LC_left_item">';
7840: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7841: my %curr;
7842: if (ref($settings) eq 'HASH') {
7843: if ($settings->{'notify'} ne '') {
7844: map {$curr{$_}=1;} split(/,/,$settings->{'notify'});
7845: }
7846: }
7847: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7848: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
7849: 'privacy_notify',%curr);
7850: if ($numdc > 0) {
7851: $datatable .= $table;
7852: } else {
7853: $datatable .= &mt('There are no active Domain Coordinators');
7854: }
7855: } else {
7856: $datatable .= &mt('Nothing to set here, as there are no other domains');
7857: }
7858: $datatable .='</td></tr>';
1.357 raeburn 7859: } elsif ($position eq 'middle') {
7860: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7861: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7862: foreach my $item (@{$types}) {
7863: $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
7864: $numinrow,$itemcount,'','','','','',
7865: '',$usertypes->{$item});
7866: $itemcount ++;
7867: }
7868: }
7869: $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
7870: $numinrow,$itemcount,'','','','','',
7871: '',$othertitle);
7872: $itemcount ++;
7873: } else {
1.360 raeburn 7874: my (@insttypes,%insttitles);
7875: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7876: @insttypes = @{$types};
7877: %insttitles = %{$usertypes};
7878: }
7879: foreach my $item (@insttypes,'default') {
7880: my $title;
7881: if ($item eq 'default') {
7882: $title = $othertitle;
7883: } else {
7884: $title = $insttitles{$item};
7885: }
7886: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7887: $datatable .= '<tr'.$css_class.'>'.
7888: '<td class="LC_left_item">'.$title.'</td>'.
7889: '<td class="LC_left_item">'.
7890: &mt('Nothing to set here, as there are no other domains').
7891: '</td></tr>';
7892: $itemcount ++;
7893: }
1.357 raeburn 7894: }
7895: }
7896: } else {
7897: my $prefix;
7898: if ($position eq 'lower') {
7899: $prefix = 'priv';
7900: } else {
7901: $prefix = 'unpriv';
7902: }
7903: foreach my $item (@items) {
7904: $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
7905: $numinrow,$itemcount,'','','','','',
7906: '',$names{$item});
7907: $itemcount ++;
7908: }
7909: }
7910: if (ref($rowtotal)) {
7911: $$rowtotal += $itemcount;
7912: }
7913: return $datatable;
7914: }
7915:
1.354 raeburn 7916: sub print_passwords {
7917: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
7918: my ($datatable,$css_class);
7919: my $itemcount = 0;
7920: my %titles = &Apache::lonlocal::texthash (
7921: captcha => '"Forgot Password" CAPTCHA validation',
7922: link => 'Reset link expiration (hours)',
7923: case => 'Case-sensitive usernames/e-mail',
7924: prelink => 'Information required (form 1)',
7925: postlink => 'Information required (form 2)',
7926: emailsrc => 'LON-CAPA e-mail address type(s)',
7927: customtext => 'Domain specific text (HTML)',
7928: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
7929: intauth_check => 'Check bcrypt cost if authenticated',
7930: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
7931: permanent => 'Permanent e-mail address',
7932: critical => 'Critical notification address',
7933: notify => 'Notification address',
7934: min => 'Minimum password length',
7935: max => 'Maximum password length',
7936: chars => 'Required characters',
7937: expire => 'Password expiration (days)',
1.356 raeburn 7938: numsaved => 'Number of previous passwords to save and disallow reuse',
1.354 raeburn 7939: );
7940: if ($position eq 'top') {
7941: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7942: my $shownlinklife = 2;
7943: my $prelink = 'both';
7944: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
7945: if (ref($settings) eq 'HASH') {
7946: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
7947: $shownlinklife = $settings->{resetlink};
7948: }
7949: if (ref($settings->{resetcase}) eq 'ARRAY') {
7950: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
7951: }
7952: if ($settings->{resetprelink} =~ /^(both|either)$/) {
7953: $prelink = $settings->{resetprelink};
7954: }
7955: if (ref($settings->{resetpostlink}) eq 'HASH') {
7956: %postlink = %{$settings->{resetpostlink}};
7957: }
7958: if (ref($settings->{resetemail}) eq 'ARRAY') {
7959: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
7960: }
7961: if ($settings->{resetremove}) {
7962: $nostdtext = 1;
7963: }
7964: if ($settings->{resetcustom}) {
7965: $customurl = $settings->{resetcustom};
7966: }
7967: } else {
7968: if (ref($types) eq 'ARRAY') {
7969: foreach my $item (@{$types}) {
7970: $casesens{$item} = 1;
7971: $postlink{$item} = ['username','email'];
7972: }
7973: }
7974: $casesens{'default'} = 1;
7975: $postlink{'default'} = ['username','email'];
7976: $prelink = 'both';
7977: %emailsrc = (
7978: permanent => 1,
7979: critical => 1,
7980: notify => 1,
7981: );
7982: }
7983: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
7984: $itemcount ++;
7985: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7986: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
7987: '<td class="LC_left_item">'.
7988: '<input type="textbox" value="'.$shownlinklife.'" '.
7989: 'name="passwords_link" size="3" /></td></tr>';
7990: $itemcount ++;
7991: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7992: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
7993: '<td class="LC_left_item">';
7994: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7995: foreach my $item (@{$types}) {
7996: my $checkedcase;
7997: if ($casesens{$item}) {
7998: $checkedcase = ' checked="checked"';
7999: }
8000: $datatable .= '<span class="LC_nobreak"><label>'.
8001: '<input type="checkbox" name="passwords_case_sensitive" value="'.
8002: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369 raeburn 8003: '</span> ';
1.354 raeburn 8004: }
8005: }
8006: my $checkedcase;
8007: if ($casesens{'default'}) {
8008: $checkedcase = ' checked="checked"';
8009: }
8010: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
8011: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
8012: $othertitle.'</label></span></td>';
8013: $itemcount ++;
8014: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8015: my %checkedpre = (
8016: both => ' checked="checked"',
8017: either => '',
8018: );
8019: if ($prelink eq 'either') {
8020: $checkedpre{either} = ' checked="checked"';
8021: $checkedpre{both} = '';
8022: }
8023: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
8024: '<td class="LC_left_item"><span class="LC_nobreak">'.
8025: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
8026: &mt('Both username and e-mail address').'</label></span> '.
8027: '<span class="LC_nobreak"><label>'.
8028: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
8029: &mt('Either username or e-mail address').'</label></span></td></tr>';
8030: $itemcount ++;
8031: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8032: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
8033: '<td class="LC_left_item">';
8034: my %postlinked;
8035: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8036: foreach my $item (@{$types}) {
8037: undef(%postlinked);
8038: $datatable .= '<fieldset style="display: inline-block;">'.
8039: '<legend>'.$usertypes->{$item}.'</legend>';
8040: if (ref($postlink{$item}) eq 'ARRAY') {
8041: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
8042: }
8043: foreach my $field ('email','username') {
8044: my $checked;
8045: if ($postlinked{$field}) {
8046: $checked = ' checked="checked"';
8047: }
8048: $datatable .= '<span class="LC_nobreak"><label>'.
8049: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
8050: $field.'"'.$checked.' />'.$field.'</label>'.
8051: '<span> ';
8052: }
8053: $datatable .= '</fieldset>';
8054: }
8055: }
8056: if (ref($postlink{'default'}) eq 'ARRAY') {
8057: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
8058: }
8059: $datatable .= '<fieldset style="display: inline-block;">'.
8060: '<legend>'.$othertitle.'</legend>';
8061: foreach my $field ('email','username') {
8062: my $checked;
8063: if ($postlinked{$field}) {
8064: $checked = ' checked="checked"';
8065: }
8066: $datatable .= '<span class="LC_nobreak"><label>'.
8067: '<input type="checkbox" name="passwords_postlink_default" value="'.
8068: $field.'"'.$checked.' />'.$field.'</label>'.
8069: '<span> ';
8070: }
8071: $datatable .= '</fieldset></td></tr>';
8072: $itemcount ++;
8073: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8074: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
8075: '<td class="LC_left_item">';
8076: foreach my $type ('permanent','critical','notify') {
8077: my $checkedemail;
8078: if ($emailsrc{$type}) {
8079: $checkedemail = ' checked="checked"';
8080: }
8081: $datatable .= '<span class="LC_nobreak"><label>'.
8082: '<input type="checkbox" name="passwords_emailsrc" value="'.
8083: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
8084: '<span> ';
8085: }
8086: $datatable .= '</td></tr>';
8087: $itemcount ++;
8088: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8089: my $switchserver = &check_switchserver($dom,$confname);
8090: my ($showstd,$noshowstd);
8091: if ($nostdtext) {
8092: $noshowstd = ' checked="checked"';
8093: } else {
8094: $showstd = ' checked="checked"';
8095: }
8096: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
8097: '<td class="LC_left_item"><span class="LC_nobreak">'.
8098: &mt('Retain standard text:').
8099: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
8100: &mt('Yes').'</label>'.' '.
8101: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
8102: &mt('No').'</label></span><br />'.
8103: '<span class="LC_fontsize_small">'.
8104: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
8105: &mt('Include custom text:');
8106: if ($customurl) {
1.369 raeburn 8107: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354 raeburn 8108: undef,undef,undef,undef,'background-color:#ffffff');
8109: $datatable .= '<span class="LC_nobreak"> '.$link.
8110: '<label><input type="checkbox" name="passwords_custom_del"'.
8111: ' value="1" />'.&mt('Delete?').'</label></span>'.
8112: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
8113: }
8114: if ($switchserver) {
8115: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
8116: } else {
8117: $datatable .='<span class="LC_nobreak"> '.
8118: '<input type="file" name="passwords_customfile" /></span>';
8119: }
8120: $datatable .= '</td></tr>';
8121: } elsif ($position eq 'middle') {
8122: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
8123: my @items = ('intauth_cost','intauth_check','intauth_switch');
8124: my %defaults;
8125: if (ref($domconf{'defaults'}) eq 'HASH') {
8126: %defaults = %{$domconf{'defaults'}};
8127: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
8128: $defaults{'intauth_cost'} = 10;
8129: }
8130: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
8131: $defaults{'intauth_check'} = 0;
8132: }
8133: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
8134: $defaults{'intauth_switch'} = 0;
8135: }
8136: } else {
8137: %defaults = (
8138: 'intauth_cost' => 10,
8139: 'intauth_check' => 0,
8140: 'intauth_switch' => 0,
8141: );
8142: }
8143: foreach my $item (@items) {
8144: if ($itemcount%2) {
8145: $css_class = '';
8146: } else {
8147: $css_class = ' class="LC_odd_row" ';
8148: }
8149: $datatable .= '<tr'.$css_class.'>'.
8150: '<td><span class="LC_nobreak">'.$titles{$item}.
8151: '</span></td><td class="LC_left_item" colspan="3">';
8152: if ($item eq 'intauth_switch') {
8153: my @options = (0,1,2);
8154: my %optiondesc = &Apache::lonlocal::texthash (
8155: 0 => 'No',
8156: 1 => 'Yes',
8157: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
8158: );
8159: $datatable .= '<table width="100%">';
8160: foreach my $option (@options) {
8161: my $checked = ' ';
8162: if ($defaults{$item} eq $option) {
8163: $checked = ' checked="checked"';
8164: }
8165: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8166: '<label><input type="radio" name="'.$item.
8167: '" value="'.$option.'"'.$checked.' />'.
8168: $optiondesc{$option}.'</label></span></td></tr>';
8169: }
8170: $datatable .= '</table>';
8171: } elsif ($item eq 'intauth_check') {
8172: my @options = (0,1,2);
8173: my %optiondesc = &Apache::lonlocal::texthash (
8174: 0 => 'No',
8175: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
8176: 2 => 'Yes, disallow login if stored cost is less than domain default',
8177: );
8178: $datatable .= '<table width="100%">';
8179: foreach my $option (@options) {
8180: my $checked = ' ';
8181: my $onclick;
8182: if ($defaults{$item} eq $option) {
8183: $checked = ' checked="checked"';
8184: }
8185: if ($option == 2) {
8186: $onclick = ' onclick="javascript:warnIntAuth(this);"';
8187: }
8188: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8189: '<label><input type="radio" name="'.$item.
8190: '" value="'.$option.'"'.$checked.$onclick.' />'.
8191: $optiondesc{$option}.'</label></span></td></tr>';
8192: }
8193: $datatable .= '</table>';
8194: } else {
8195: $datatable .= '<input type="text" name="'.$item.'" value="'.
8196: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
8197: }
8198: $datatable .= '</td></tr>';
8199: $itemcount ++;
8200: }
8201: } elsif ($position eq 'lower') {
1.405 raeburn 8202: $datatable .= &password_rules('passwords',\$itemcount,$settings);
1.354 raeburn 8203: } else {
1.359 raeburn 8204: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8205: my %ownerchg = (
8206: by => {},
8207: for => {},
8208: );
8209: my %ownertitles = &Apache::lonlocal::texthash (
8210: by => 'Course owner status(es) allowed',
8211: for => 'Student status(es) allowed',
8212: );
1.354 raeburn 8213: if (ref($settings) eq 'HASH') {
1.359 raeburn 8214: if (ref($settings->{crsownerchg}) eq 'HASH') {
8215: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
8216: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
8217: }
8218: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
8219: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
8220: }
1.354 raeburn 8221: }
8222: }
8223: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8224: $datatable .= '<tr '.$css_class.'>'.
8225: '<td>'.
8226: &mt('Requirements').'<ul>'.
1.359 raeburn 8227: '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354 raeburn 8228: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
8229: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359 raeburn 8230: '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354 raeburn 8231: '</ul>'.
8232: '</td>'.
1.359 raeburn 8233: '<td class="LC_left_item">';
8234: foreach my $item ('by','for') {
8235: $datatable .= '<fieldset style="display: inline-block;">'.
8236: '<legend>'.$ownertitles{$item}.'</legend>';
8237: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8238: foreach my $type (@{$types}) {
8239: my $checked;
8240: if ($ownerchg{$item}{$type}) {
8241: $checked = ' checked="checked"';
8242: }
8243: $datatable .= '<span class="LC_nobreak"><label>'.
8244: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
8245: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369 raeburn 8246: '</span> ';
1.359 raeburn 8247: }
8248: }
8249: my $checked;
8250: if ($ownerchg{$item}{'default'}) {
8251: $checked = ' checked="checked"';
8252: }
8253: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
8254: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
8255: $othertitle.'</label></span></fieldset>';
8256: }
8257: $datatable .= '</td></tr>';
1.354 raeburn 8258: }
8259: return $datatable;
8260: }
8261:
1.405 raeburn 8262: sub password_rules {
8263: my ($prefix,$itemcountref,$settings) = @_;
8264: my ($min,$max,%chars,$expire,$numsaved,$numinrow);
8265: my %titles;
8266: if ($prefix eq 'passwords') {
8267: %titles = &Apache::lonlocal::texthash (
8268: min => 'Minimum password length',
8269: max => 'Maximum password length',
8270: chars => 'Required characters',
8271: );
1.421 raeburn 8272: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 8273: %titles = &Apache::lonlocal::texthash (
8274: min => 'Minimum secret length',
8275: max => 'Maximum secret length',
8276: chars => 'Required characters',
8277: );
8278: }
8279: $min = $Apache::lonnet::passwdmin;
8280: my $datatable;
8281: my $itemcount;
8282: if (ref($itemcountref)) {
8283: $itemcount = $$itemcountref;
8284: }
8285: if (ref($settings) eq 'HASH') {
8286: if ($settings->{min}) {
8287: $min = $settings->{min};
8288: }
8289: if ($settings->{max}) {
8290: $max = $settings->{max};
8291: }
8292: if (ref($settings->{chars}) eq 'ARRAY') {
8293: map { $chars{$_} = 1; } (@{$settings->{chars}});
8294: }
1.425 raeburn 8295: if ($prefix eq 'passwords') {
1.405 raeburn 8296: if ($settings->{expire}) {
8297: $expire = $settings->{expire};
8298: }
8299: if ($settings->{numsaved}) {
8300: $numsaved = $settings->{numsaved};
8301: }
8302: }
8303: }
8304: my %rulenames = &Apache::lonlocal::texthash(
8305: uc => 'At least one upper case letter',
8306: lc => 'At least one lower case letter',
8307: num => 'At least one number',
8308: spec => 'At least one non-alphanumeric',
8309: );
8310: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
8311: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
8312: '<td class="LC_left_item"><span class="LC_nobreak">'.
8313: '<input type="text" name="'.$prefix.'_min" value="'.$min.'" size="3" '.
8314: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8315: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
8316: '</span></td></tr>';
8317: $itemcount ++;
8318: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8319: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
8320: '<td class="LC_left_item"><span class="LC_nobreak">'.
8321: '<input type="text" name="'.$prefix.'_max" value="'.$max.'" size="3" '.
8322: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8323: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
8324: '</span></td></tr>';
8325: $itemcount ++;
8326: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8327: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
8328: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
8329: '</span></td>';
8330: my $numinrow = 2;
8331: my @possrules = ('uc','lc','num','spec');
8332: $datatable .= '<td class="LC_left_item"><table>';
8333: for (my $i=0; $i<@possrules; $i++) {
8334: my ($rem,$checked);
8335: if ($chars{$possrules[$i]}) {
8336: $checked = ' checked="checked"';
8337: }
8338: $rem = $i%($numinrow);
8339: if ($rem == 0) {
8340: if ($i > 0) {
8341: $datatable .= '</tr>';
8342: }
8343: $datatable .= '<tr>';
8344: }
8345: $datatable .= '<td><span class="LC_nobreak"><label>'.
8346: '<input type="checkbox" name="'.$prefix.'_chars" value="'.$possrules[$i].'"'.$checked.' />'.
8347: $rulenames{$possrules[$i]}.'</label></span></td>';
8348: }
8349: my $rem = @possrules%($numinrow);
8350: my $colsleft = $numinrow - $rem;
8351: if ($colsleft > 1 ) {
8352: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8353: ' </td>';
8354: } elsif ($colsleft == 1) {
8355: $datatable .= '<td class="LC_left_item"> </td>';
8356: }
8357: $datatable .='</table></td></tr>';
8358: $itemcount ++;
8359: if ($prefix eq 'passwords') {
8360: $titles{'expire'} = &mt('Password expiration (days)');
8361: $titles{'numsaved'} = &mt('Number of previous passwords to save and disallow reuse');
8362: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8363: $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
8364: '<td class="LC_left_item"><span class="LC_nobreak">'.
8365: '<input type="text" name="'.$prefix.'_expire" value="'.$expire.'" size="4" '.
8366: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8367: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
8368: '</span></td></tr>';
8369: $itemcount ++;
8370: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8371: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
8372: '<td class="LC_left_item"><span class="LC_nobreak">'.
8373: '<input type="text" name="'.$prefix.'_numsaved" value="'.$numsaved.'" size="3" '.
8374: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8375: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
8376: '</span></td></tr>';
8377: $itemcount ++;
8378: }
8379: if (ref($itemcountref)) {
8380: $$itemcountref += $itemcount;
8381: }
8382: return $datatable;
8383: }
8384:
1.373 raeburn 8385: sub print_wafproxy {
8386: my ($position,$dom,$settings,$rowtotal) = @_;
8387: my $css_class;
8388: my $itemcount = 0;
8389: my $datatable;
8390: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 8391: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
1.374 raeburn 8392: my %lt = &wafproxy_titles();
1.373 raeburn 8393: foreach my $server (sort(keys(%servers))) {
8394: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
1.381 raeburn 8395: next if ($serverhome eq '');
1.373 raeburn 8396: my $serverdom;
8397: if ($serverhome ne $server) {
8398: $serverdom = &Apache::lonnet::host_domain($serverhome);
1.381 raeburn 8399: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
8400: $othercontrol{$server} = $serverdom;
8401: }
1.373 raeburn 8402: } else {
8403: $serverdom = &Apache::lonnet::host_domain($server);
1.381 raeburn 8404: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
1.373 raeburn 8405: if ($serverdom ne $dom) {
8406: $othercontrol{$server} = $serverdom;
8407: } else {
8408: $setdom = 1;
8409: if (ref($settings) eq 'HASH') {
8410: if (ref($settings->{'alias'}) eq 'HASH') {
8411: $aliases{$dom} = $settings->{'alias'};
1.381 raeburn 8412: if ($aliases{$dom} ne '') {
8413: $showdom = 1;
8414: }
1.373 raeburn 8415: }
1.388 raeburn 8416: if (ref($settings->{'saml'}) eq 'HASH') {
8417: $saml{$dom} = $settings->{'saml'};
8418: }
1.373 raeburn 8419: }
8420: }
8421: }
8422: }
1.381 raeburn 8423: if ($setdom) {
8424: %{$values{$dom}} = ();
8425: if (ref($settings) eq 'HASH') {
8426: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8427: $values{$dom}{$item} = $settings->{$item};
8428: }
8429: }
8430: }
1.373 raeburn 8431: if (keys(%othercontrol)) {
8432: %otherdoms = reverse(%othercontrol);
8433: foreach my $domain (keys(%otherdoms)) {
8434: %{$values{$domain}} = ();
8435: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
1.383 raeburn 8436: if (ref($config{'wafproxy'}) eq 'HASH') {
8437: $aliases{$domain} = $config{'wafproxy'}{'alias'};
1.425 raeburn 8438: if (exists($config{'wafproxy'}{'saml'})) {
1.388 raeburn 8439: $saml{$domain} = $config{'wafproxy'}{'saml'};
8440: }
1.383 raeburn 8441: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8442: $values{$domain}{$item} = $config{'wafproxy'}{$item};
1.373 raeburn 8443: }
8444: }
8445: }
8446: }
8447: if ($position eq 'top') {
8448: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.381 raeburn 8449: my %aliasinfo;
1.373 raeburn 8450: foreach my $server (sort(keys(%servers))) {
1.381 raeburn 8451: $itemcount ++;
8452: my $dom_in_effect;
8453: my $aliasrows = '<tr>'.
1.383 raeburn 8454: '<td class="LC_left_item" style="vertical-align: baseline;">'.
1.433 raeburn 8455: &mt('Hostname').': '.
8456: '<span class="LC_nobreak LC_cusr_emph">'.
8457: &Apache::lonnet::hostname($server).
8458: '</span></td><td> </td>';
1.373 raeburn 8459: if ($othercontrol{$server}) {
1.381 raeburn 8460: $dom_in_effect = $othercontrol{$server};
1.388 raeburn 8461: my ($current,$forsaml);
1.383 raeburn 8462: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
8463: $current = $aliases{$dom_in_effect}{$server};
1.373 raeburn 8464: }
1.388 raeburn 8465: if (ref($saml{$dom_in_effect}) eq 'HASH') {
8466: if ($saml{$dom_in_effect}{$server}) {
8467: $forsaml = 1;
8468: }
8469: }
1.383 raeburn 8470: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8471: &mt('Alias').': ';
1.373 raeburn 8472: if ($current) {
1.381 raeburn 8473: $aliasrows .= $current;
1.388 raeburn 8474: if ($forsaml) {
1.396 raeburn 8475: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
1.388 raeburn 8476: }
1.373 raeburn 8477: } else {
1.383 raeburn 8478: $aliasrows .= &mt('None');
1.373 raeburn 8479: }
1.383 raeburn 8480: $aliasrows .= ' <span class="LC_small">('.
8481: &mt('controlled by domain: [_1]',
8482: '<b>'.$dom_in_effect.'</b>').')</span></td>';
1.373 raeburn 8483: } else {
1.381 raeburn 8484: $dom_in_effect = $dom;
1.388 raeburn 8485: my ($current,$samlon,$samloff);
8486: $samloff = ' checked="checked"';
1.373 raeburn 8487: if (ref($aliases{$dom}) eq 'HASH') {
8488: if ($aliases{$dom}{$server}) {
8489: $current = $aliases{$dom}{$server};
8490: }
8491: }
1.388 raeburn 8492: if (ref($saml{$dom}) eq 'HASH') {
8493: if ($saml{$dom}{$server}) {
8494: $samlon = $samloff;
8495: undef($samloff);
8496: }
8497: }
1.383 raeburn 8498: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8499: &mt('Alias').': '.
1.381 raeburn 8500: '<input type="text" name="wafproxy_alias_'.$server.'" '.
1.388 raeburn 8501: 'value="'.$current.'" size="30" />'.
8502: (' 'x2).'<span class="LC_nobreak">'.
1.396 raeburn 8503: &mt('Alias used for SSO Auth').': <label>'.
1.388 raeburn 8504: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
1.425 raeburn 8505: &mt('No').'</label> <label>'.
1.388 raeburn 8506: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
8507: &mt('Yes').'</label></span>'.
1.425 raeburn 8508: '</td>';
1.381 raeburn 8509: }
8510: $aliasrows .= '</tr>';
8511: $aliasinfo{$dom_in_effect} .= $aliasrows;
8512: }
8513: if ($aliasinfo{$dom}) {
8514: my ($onclick,$wafon,$wafoff,$showtable);
8515: $onclick = ' onclick="javascript:toggleWAF();"';
8516: $wafoff = ' checked="checked"';
8517: $showtable = ' style="display:none";';
8518: if ($showdom) {
8519: $wafon = $wafoff;
8520: $wafoff = '';
8521: $showtable = ' style="display:inline;"';
8522: }
8523: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8524: $datatable = '<tr'.$css_class.'>'.
8525: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
8526: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
8527: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
8528: &mt('Yes').'</label>'.(' 'x2).'<label>'.
8529: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
8530: &mt('No').'</label></span></td>'.
8531: '<td class="LC_left_item">'.
8532: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
8533: '</table></td></tr>';
8534: $itemcount++;
8535: }
1.383 raeburn 8536: if (keys(%otherdoms)) {
8537: foreach my $key (sort(keys(%otherdoms))) {
1.381 raeburn 8538: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.383 raeburn 8539: $datatable .= '<tr'.$css_class.'>'.
8540: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
8541: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
8542: '</table></td></tr>';
1.381 raeburn 8543: $itemcount++;
1.373 raeburn 8544: }
8545: }
8546: } else {
1.383 raeburn 8547: my %ip_methods = &remoteip_methods();
1.373 raeburn 8548: if ($setdom) {
8549: $itemcount ++;
8550: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.381 raeburn 8551: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
1.382 raeburn 8552: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
1.381 raeburn 8553: $wafstyle = ' style="display:none;"';
8554: $nowafstyle = ' style="display:table-row;"';
8555: $currwafdisplay = ' style="display: none"';
8556: $wafrangestyle = ' style="display: none"';
8557: $curr_remotip = 'n';
1.382 raeburn 8558: $ssltossl = ' checked="checked"';
1.381 raeburn 8559: if ($showdom) {
8560: $wafstyle = ' style="display:table-row;"';
8561: $nowafstyle = ' style="display:none;"';
8562: if (keys(%{$values{$dom}})) {
8563: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
8564: $curr_remotip = $values{$dom}{remoteip};
8565: }
8566: if ($curr_remotip eq 'h') {
8567: $currwafdisplay = ' style="display:table-row"';
8568: $wafrangestyle = ' style="display:inline-block;"';
8569: }
1.382 raeburn 8570: if ($values{$dom}{'sslopt'}) {
8571: $alltossl = ' checked="checked"';
8572: $ssltossl = '';
8573: }
1.381 raeburn 8574: }
8575: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
8576: $vpndircheck = ' checked="checked"';
8577: $currwafvpn = ' style="display:table-row;"';
8578: $wafrangestyle = ' style="display:inline-block;"';
8579: } else {
8580: $vpnaliascheck = ' checked="checked"';
8581: $currwafvpn = ' style="display:none;"';
8582: }
8583: }
8584: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
8585: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
8586: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
8587: '</tr>'.
8588: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
1.374 raeburn 8589: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
1.381 raeburn 8590: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
1.393 raeburn 8591: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
8592: &mt('Range(s) stored in CIDR notation').'</div></td>'.
1.381 raeburn 8593: '<td class="LC_left_item"><table>'.
8594: '<tr>'.
8595: '<td valign="top">'.$lt{'remoteip'}.': '.
8596: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
8597: foreach my $option ('m','h','n') {
8598: my $sel;
8599: if ($option eq $curr_remotip) {
8600: $sel = ' selected="selected"';
8601: }
8602: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
8603: $ip_methods{$option}.'</option>';
8604: }
8605: $datatable .= '</select></td></tr>'."\n".
8606: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
8607: $lt{'ipheader'}.': '.
8608: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
8609: 'name="wafproxy_ipheader" />'.
8610: '</td></tr>'."\n".
8611: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
1.382 raeburn 8612: $lt{'trusted'}.':<br />'.
1.381 raeburn 8613: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
8614: $values{$dom}{'trusted'}.'</textarea>'.
8615: '</td></tr>'."\n".
8616: '<tr><td><hr /></td></tr>'."\n".
8617: '<tr>'.
8618: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
8619: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
8620: $lt{'vpndirect'}.'</label>'.(' 'x2).
8621: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
8622: $lt{'vpnaliased'}.'</label></span></td></tr>';
8623: foreach my $item ('vpnint','vpnext') {
8624: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
1.382 raeburn 8625: '<td valign="top">'.$lt{$item}.':<br />'.
1.381 raeburn 8626: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
8627: $values{$dom}{$item}.'</textarea>'.
8628: '</td></tr>'."\n";
1.373 raeburn 8629: }
1.382 raeburn 8630: $datatable .= '<tr><td><hr /></td></tr>'."\n".
8631: '<tr>'.
8632: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
8633: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
8634: $lt{'alltossl'}.'</label>'.(' 'x2).
8635: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
8636: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
8637: '</table></td></tr>';
1.373 raeburn 8638: }
8639: if (keys(%otherdoms)) {
8640: foreach my $domain (sort(keys(%otherdoms))) {
8641: $itemcount ++;
8642: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8643: $datatable .= '<tr'.$css_class.'>'.
1.383 raeburn 8644: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
1.374 raeburn 8645: '<td class="LC_left_item"><table>';
1.382 raeburn 8646: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 8647: my $showval = &mt('None');
1.382 raeburn 8648: if ($item eq 'ssl') {
8649: $showval = $lt{'ssltossl'};
8650: }
1.373 raeburn 8651: if ($values{$domain}{$item}) {
1.381 raeburn 8652: $showval = $values{$domain}{$item};
1.382 raeburn 8653: if ($item eq 'ssl') {
8654: $showval = $lt{'alltossl'};
1.383 raeburn 8655: } elsif ($item eq 'remoteip') {
8656: $showval = $ip_methods{$values{$domain}{$item}};
1.382 raeburn 8657: }
1.373 raeburn 8658: }
8659: $datatable .= '<tr>'.
8660: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
8661: }
1.381 raeburn 8662: $datatable .= '</table></td></tr>';
1.373 raeburn 8663: }
8664: }
8665: }
8666: $$rowtotal += $itemcount;
8667: return $datatable;
8668: }
8669:
8670: sub wafproxy_titles {
8671: return &Apache::lonlocal::texthash(
1.381 raeburn 8672: remoteip => "Method for determining user's IP",
8673: ipheader => 'Request header containing remote IP',
8674: trusted => 'Trusted IP range(s)',
8675: vpnaccess => 'Access from institutional VPN',
8676: vpndirect => 'via regular hostname (no WAF)',
8677: vpnaliased => 'via aliased hostname (WAF)',
8678: vpnint => 'Internal IP Range(s) for VPN sessions',
8679: vpnext => 'IP Range(s) for backend WAF connections',
1.382 raeburn 8680: sslopt => 'Forwarding http/https',
1.381 raeburn 8681: alltossl => 'WAF forwards both http and https requests to https',
8682: ssltossl => 'WAF forwards http requests to http and https to https',
8683: );
8684: }
8685:
8686: sub remoteip_methods {
8687: return &Apache::lonlocal::texthash(
8688: m => 'Use Apache mod_remoteip',
8689: h => 'Use headers parsed by LON-CAPA',
8690: n => 'Not in use',
1.373 raeburn 8691: );
8692: }
8693:
1.137 raeburn 8694: sub print_usersessions {
8695: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 8696: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 8697: my (%by_ip,%by_location,@intdoms,@instdoms);
8698: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 8699:
8700: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 8701: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 8702: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 8703: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 8704: if ($position eq 'top') {
1.152 raeburn 8705: if (keys(%serverhomes) > 1) {
1.145 raeburn 8706: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.371 raeburn 8707: my ($curroffloadnow,$curroffloadoth);
1.261 raeburn 8708: if (ref($settings) eq 'HASH') {
8709: if (ref($settings->{'offloadnow'}) eq 'HASH') {
8710: $curroffloadnow = $settings->{'offloadnow'};
8711: }
1.371 raeburn 8712: if (ref($settings->{'offloadoth'}) eq 'HASH') {
8713: $curroffloadoth = $settings->{'offloadoth'};
8714: }
1.261 raeburn 8715: }
1.371 raeburn 8716: my $other_insts = scalar(keys(%by_location));
8717: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
8718: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 8719: } else {
1.140 raeburn 8720: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 8721: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
8722: '</td></tr>';
1.140 raeburn 8723: }
1.137 raeburn 8724: } else {
1.279 raeburn 8725: my %titles = &usersession_titles();
8726: my ($prefix,@types);
8727: if ($position eq 'bottom') {
8728: $prefix = 'remote';
8729: @types = ('version','excludedomain','includedomain');
1.145 raeburn 8730: } else {
1.279 raeburn 8731: $prefix = 'hosted';
8732: @types = ('excludedomain','includedomain');
8733: }
8734: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8735: }
8736: $$rowtotal += $itemcount;
8737: return $datatable;
8738: }
8739:
8740: sub rules_by_location {
8741: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
8742: my ($datatable,$itemcount,$css_class);
8743: if (keys(%{$by_location}) == 0) {
8744: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8745: $datatable = '<tr'.$css_class.'><td colspan="2">'.
8746: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
8747: '</td></tr>';
8748: $itemcount = 1;
8749: } else {
8750: $itemcount = 0;
8751: my $numinrow = 5;
8752: my (%current,%checkedon,%checkedoff);
8753: my @locations = sort(keys(%{$by_location}));
8754: foreach my $type (@{$types}) {
8755: $checkedon{$type} = '';
8756: $checkedoff{$type} = ' checked="checked"';
8757: }
8758: if (ref($settings) eq 'HASH') {
8759: if (ref($settings->{$prefix}) eq 'HASH') {
8760: foreach my $key (keys(%{$settings->{$prefix}})) {
8761: $current{$key} = $settings->{$prefix}{$key};
8762: if ($key eq 'version') {
8763: if ($current{$key} ne '') {
1.145 raeburn 8764: $checkedon{$key} = ' checked="checked"';
8765: $checkedoff{$key} = '';
8766: }
1.279 raeburn 8767: } elsif (ref($current{$key}) eq 'ARRAY') {
8768: $checkedon{$key} = ' checked="checked"';
8769: $checkedoff{$key} = '';
1.137 raeburn 8770: }
8771: }
8772: }
1.279 raeburn 8773: }
8774: foreach my $type (@{$types}) {
8775: next if ($type ne 'version' && !@locations);
8776: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8777: $datatable .= '<tr'.$css_class.'>
8778: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
8779: <span class="LC_nobreak">
8780: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
8781: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
8782: if ($type eq 'version') {
8783: my @lcversions = &Apache::lonnet::all_loncaparevs();
8784: my $selector = '<select name="'.$prefix.'_version">';
8785: foreach my $version (@lcversions) {
8786: my $selected = '';
8787: if ($current{'version'} eq $version) {
8788: $selected = ' selected="selected"';
1.145 raeburn 8789: }
1.279 raeburn 8790: $selector .= ' <option value="'.$version.'"'.
8791: $selected.'>'.$version.'</option>';
8792: }
8793: $selector .= '</select> ';
8794: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
8795: } else {
8796: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
8797: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
8798: ' />'.(' 'x2).
8799: '<input type="button" value="'.&mt('uncheck all').'" '.
8800: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
8801: "\n".
8802: '</div><div><table>';
8803: my $rem;
8804: for (my $i=0; $i<@locations; $i++) {
8805: my ($showloc,$value,$checkedtype);
8806: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
8807: my $ip = $by_location->{$locations[$i]}->[0];
8808: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8809: $value = join(':',@{$by_ip->{$ip}});
8810: $showloc = join(', ',@{$by_ip->{$ip}});
8811: if (ref($current{$type}) eq 'ARRAY') {
8812: foreach my $loc (@{$by_ip->{$ip}}) {
8813: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
8814: $checkedtype = ' checked="checked"';
8815: last;
1.145 raeburn 8816: }
1.138 raeburn 8817: }
8818: }
8819: }
1.137 raeburn 8820: }
1.279 raeburn 8821: $rem = $i%($numinrow);
8822: if ($rem == 0) {
8823: if ($i > 0) {
8824: $datatable .= '</tr>';
8825: }
8826: $datatable .= '<tr>';
8827: }
8828: $datatable .= '<td class="LC_left_item">'.
8829: '<span class="LC_nobreak"><label>'.
8830: '<input type="checkbox" name="'.$prefix.'_'.$type.
8831: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
8832: '</label></span></td>';
8833: }
8834: $rem = @locations%($numinrow);
8835: my $colsleft = $numinrow - $rem;
8836: if ($colsleft > 1 ) {
8837: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8838: ' </td>';
8839: } elsif ($colsleft == 1) {
8840: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 8841: }
1.279 raeburn 8842: $datatable .= '</tr></table>';
1.137 raeburn 8843: }
1.279 raeburn 8844: $datatable .= '</td></tr>';
8845: $itemcount ++;
1.137 raeburn 8846: }
8847: }
1.279 raeburn 8848: return ($datatable,$itemcount);
1.137 raeburn 8849: }
8850:
1.275 raeburn 8851: sub print_ssl {
8852: my ($position,$dom,$settings,$rowtotal) = @_;
8853: my ($css_class,$datatable);
8854: my $itemcount = 1;
8855: if ($position eq 'top') {
1.281 raeburn 8856: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8857: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8858: my $same_institution;
8859: if ($intdom ne '') {
8860: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
8861: if (ref($internet_names) eq 'ARRAY') {
8862: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
8863: $same_institution = 1;
8864: }
8865: }
8866: }
1.275 raeburn 8867: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 8868: $datatable = '<tr'.$css_class.'><td colspan="2">';
8869: if ($same_institution) {
8870: my %domservers = &Apache::lonnet::get_servers($dom);
8871: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
8872: } else {
8873: $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.");
8874: }
8875: $datatable .= '</td></tr>';
1.275 raeburn 8876: $itemcount ++;
8877: } else {
8878: my %titles = &ssl_titles();
8879: my (%by_ip,%by_location,@intdoms,@instdoms);
8880: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8881: my @alldoms = &Apache::lonnet::all_domains();
8882: my %serverhomes = %Apache::lonnet::serverhomeIDs;
8883: my @domservers = &Apache::lonnet::get_servers($dom);
8884: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8885: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 8886: if (($position eq 'connto') || ($position eq 'connfrom')) {
8887: my $legacy;
8888: unless (ref($settings) eq 'HASH') {
8889: my $name;
8890: if ($position eq 'connto') {
8891: $name = 'loncAllowInsecure';
8892: } else {
8893: $name = 'londAllowInsecure';
8894: }
8895: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
8896: my @ids=&Apache::lonnet::current_machine_ids();
8897: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
8898: my %what = (
8899: $name => 1,
8900: );
8901: my ($result,$returnhash) =
8902: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
8903: if ($result eq 'ok') {
8904: if (ref($returnhash) eq 'HASH') {
8905: $legacy = $returnhash->{$name};
8906: }
8907: }
8908: } else {
8909: $legacy = $Apache::lonnet::perlvar{$name};
8910: }
8911: }
1.275 raeburn 8912: foreach my $type ('dom','intdom','other') {
8913: my %checked;
8914: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8915: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
8916: '<td class="LC_right_item">';
8917: my $skip;
8918: if ($type eq 'dom') {
8919: unless (keys(%servers) > 1) {
8920: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
8921: $skip = 1;
8922: }
8923: }
8924: if ($type eq 'intdom') {
8925: unless (@instdoms > 1) {
8926: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
8927: $skip = 1;
8928: }
8929: } elsif ($type eq 'other') {
8930: if (keys(%by_location) == 0) {
8931: $datatable .= &mt('Nothing to set here, as there are no other institutions');
8932: $skip = 1;
8933: }
8934: }
8935: unless ($skip) {
8936: $checked{'yes'} = ' checked="checked"';
8937: if (ref($settings) eq 'HASH') {
1.293 raeburn 8938: if (ref($settings->{$position}) eq 'HASH') {
8939: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 8940: $checked{$1} = $checked{'yes'};
8941: delete($checked{'yes'});
8942: }
8943: }
1.293 raeburn 8944: } else {
8945: if ($legacy == 0) {
8946: $checked{'req'} = $checked{'yes'};
8947: delete($checked{'yes'});
8948: }
1.275 raeburn 8949: }
8950: foreach my $option ('no','yes','req') {
8951: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 8952: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 8953: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
8954: '</label></span>'.(' 'x2);
8955: }
8956: }
8957: $datatable .= '</td></tr>';
8958: $itemcount ++;
8959: }
8960: } else {
8961: my $prefix = 'replication';
8962: my @types = ('certreq','nocertreq');
1.279 raeburn 8963: if (keys(%by_location) == 0) {
8964: $datatable .= '<tr'.$css_class.'><td>'.
8965: &mt('Nothing to set here, as there are no other institutions').
8966: '</td></tr>';
8967: $itemcount ++;
1.275 raeburn 8968: } else {
1.279 raeburn 8969: ($datatable,$itemcount) =
8970: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 8971: }
8972: }
8973: }
8974: $$rowtotal += $itemcount;
8975: return $datatable;
8976: }
8977:
8978: sub ssl_titles {
8979: return &Apache::lonlocal::texthash (
8980: dom => 'LON-CAPA servers/VMs from same domain',
8981: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
8982: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 8983: connto => 'Connections to other servers',
8984: connfrom => 'Connections from other servers',
1.275 raeburn 8985: replication => 'Replicating content to other institutions',
8986: certreq => 'Client certificate required, but specific domains exempt',
8987: nocertreq => 'No client certificate required, except for specific domains',
8988: no => 'SSL not used',
8989: yes => 'SSL Optional (used if available)',
8990: req => 'SSL Required',
8991: );
1.279 raeburn 8992: }
8993:
8994: sub print_trust {
8995: my ($prefix,$dom,$settings,$rowtotal) = @_;
8996: my ($css_class,$datatable,%checked,%choices);
8997: my (%by_ip,%by_location,@intdoms,@instdoms);
8998: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8999: my $itemcount = 1;
9000: my %titles = &trust_titles();
9001: my @types = ('exc','inc');
9002: if ($prefix eq 'top') {
9003: $prefix = 'content';
9004: } elsif ($prefix eq 'bottom') {
9005: $prefix = 'msg';
9006: }
9007: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
9008: $$rowtotal += $itemcount;
9009: return $datatable;
9010: }
9011:
9012: sub trust_titles {
9013: return &Apache::lonlocal::texthash(
9014: content => "Access to this domain's content by others",
9015: shared => "Access to other domain's content by this domain",
9016: enroll => "Enrollment in this domain's courses by others",
9017: othcoau => "Co-author roles in this domain for others",
9018: coaurem => "Co-author roles for this domain's users elsewhere",
9019: domroles => "Domain roles in this domain assignable to others",
9020: catalog => "Course Catalog for this domain displayed elsewhere",
9021: reqcrs => "Requests for creation of courses in this domain by others",
9022: msg => "Users in other domains can send messages to this domain",
9023: exc => "Allow all, but exclude specific domains",
9024: inc => "Deny all, but include specific domains",
9025: );
1.275 raeburn 9026: }
9027:
1.138 raeburn 9028: sub build_location_hashes {
1.275 raeburn 9029: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 9030: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 9031: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 9032: my %iphost = &Apache::lonnet::get_iphost();
9033: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
9034: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
9035: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
9036: foreach my $id (@{$iphost{$primary_ip}}) {
9037: my $intdom = &Apache::lonnet::internet_dom($id);
9038: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
9039: push(@{$intdoms},$intdom);
9040: }
9041: }
9042: }
9043: foreach my $ip (keys(%iphost)) {
9044: if (ref($iphost{$ip}) eq 'ARRAY') {
9045: foreach my $id (@{$iphost{$ip}}) {
9046: my $location = &Apache::lonnet::internet_dom($id);
9047: if ($location) {
1.275 raeburn 9048: if (grep(/^\Q$location\E$/,@{$intdoms})) {
9049: my $dom = &Apache::lonnet::host_domain($id);
9050: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
9051: push(@{$instdoms},$dom);
9052: }
9053: next;
9054: }
1.138 raeburn 9055: if (ref($by_ip->{$ip}) eq 'ARRAY') {
9056: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
9057: push(@{$by_ip->{$ip}},$location);
9058: }
9059: } else {
9060: $by_ip->{$ip} = [$location];
9061: }
9062: }
9063: }
9064: }
9065: }
9066: foreach my $ip (sort(keys(%{$by_ip}))) {
9067: if (ref($by_ip->{$ip}) eq 'ARRAY') {
9068: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
9069: my $first = $by_ip->{$ip}->[0];
9070: if (ref($by_location->{$first}) eq 'ARRAY') {
9071: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
9072: push(@{$by_location->{$first}},$ip);
9073: }
9074: } else {
9075: $by_location->{$first} = [$ip];
9076: }
9077: }
9078: }
9079: return;
9080: }
9081:
1.145 raeburn 9082: sub current_offloads_to {
9083: my ($dom,$settings,$servers) = @_;
9084: my (%spareid,%otherdomconfigs);
1.152 raeburn 9085: if (ref($servers) eq 'HASH') {
1.145 raeburn 9086: foreach my $lonhost (sort(keys(%{$servers}))) {
9087: my $gotspares;
1.152 raeburn 9088: if (ref($settings) eq 'HASH') {
9089: if (ref($settings->{'spares'}) eq 'HASH') {
9090: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
9091: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
9092: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
9093: $gotspares = 1;
9094: }
1.145 raeburn 9095: }
9096: }
9097: unless ($gotspares) {
9098: my $gotspares;
9099: my $serverhomeID =
9100: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
9101: my $serverhomedom =
9102: &Apache::lonnet::host_domain($serverhomeID);
9103: if ($serverhomedom ne $dom) {
9104: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
9105: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
9106: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
9107: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
9108: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
9109: $gotspares = 1;
9110: }
9111: }
9112: } else {
9113: $otherdomconfigs{$serverhomedom} =
9114: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
9115: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
9116: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
9117: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
9118: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
9119: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
9120: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
9121: $gotspares = 1;
9122: }
9123: }
9124: }
9125: }
9126: }
9127: }
9128: }
9129: unless ($gotspares) {
9130: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
9131: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9132: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9133: } else {
9134: my $server_hostname = &Apache::lonnet::hostname($lonhost);
9135: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
9136: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
9137: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9138: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9139: } else {
1.150 raeburn 9140: my %what = (
9141: spareid => 1,
9142: );
9143: my ($result,$returnhash) =
9144: &Apache::lonnet::get_remote_globals($lonhost,\%what);
9145: if ($result eq 'ok') {
9146: if (ref($returnhash) eq 'HASH') {
9147: if (ref($returnhash->{'spareid'}) eq 'HASH') {
9148: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
9149: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
9150: }
9151: }
1.145 raeburn 9152: }
9153: }
9154: }
9155: }
9156: }
9157: }
9158: return %spareid;
9159: }
9160:
9161: sub spares_row {
1.371 raeburn 9162: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
9163: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 9164: my $css_class;
9165: my $numinrow = 4;
9166: my $itemcount = 1;
9167: my $datatable;
1.152 raeburn 9168: my %typetitles = &sparestype_titles();
9169: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 9170: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 9171: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
9172: my ($othercontrol,$serverdom);
9173: if ($serverhome ne $server) {
9174: $serverdom = &Apache::lonnet::host_domain($serverhome);
9175: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9176: } else {
9177: $serverdom = &Apache::lonnet::host_domain($server);
9178: if ($serverdom ne $dom) {
9179: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9180: }
9181: }
9182: next unless (ref($spareid->{$server}) eq 'HASH');
1.371 raeburn 9183: my ($checkednow,$checkedoth);
1.261 raeburn 9184: if (ref($curroffloadnow) eq 'HASH') {
9185: if ($curroffloadnow->{$server}) {
9186: $checkednow = ' checked="checked"';
9187: }
9188: }
1.371 raeburn 9189: if (ref($curroffloadoth) eq 'HASH') {
9190: if ($curroffloadoth->{$server}) {
9191: $checkedoth = ' checked="checked"';
9192: }
9193: }
1.145 raeburn 9194: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
9195: $datatable .= '<tr'.$css_class.'>
9196: <td rowspan="2">
1.183 bisitz 9197: <span class="LC_nobreak">'.
9198: &mt('[_1] when busy, offloads to:'
1.261 raeburn 9199: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 9200: '<span class="LC_nobreak">'."\n".
1.261 raeburn 9201: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.371 raeburn 9202: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.183 bisitz 9203: "\n";
1.371 raeburn 9204: if ($other_insts) {
9205: $datatable .= '<br />'.
9206: '<span class="LC_nobreak">'."\n".
9207: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
9208: ' '.&mt('Switch other institutions on next access').'</label></span>'.
9209: "\n";
9210: }
1.145 raeburn 9211: my (%current,%canselect);
1.152 raeburn 9212: my @choices =
9213: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
9214: foreach my $type ('primary','default') {
9215: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 9216: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
9217: my @spares = @{$spareid->{$server}{$type}};
9218: if (@spares > 0) {
1.152 raeburn 9219: if ($othercontrol) {
9220: $current{$type} = join(', ',@spares);
9221: } else {
9222: $current{$type} .= '<table>';
9223: my $numspares = scalar(@spares);
9224: for (my $i=0; $i<@spares; $i++) {
9225: my $rem = $i%($numinrow);
9226: if ($rem == 0) {
9227: if ($i > 0) {
9228: $current{$type} .= '</tr>';
9229: }
9230: $current{$type} .= '<tr>';
1.145 raeburn 9231: }
1.152 raeburn 9232: $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'".');" /> '.
9233: $spareid->{$server}{$type}[$i].
9234: '</label></td>'."\n";
9235: }
9236: my $rem = @spares%($numinrow);
9237: my $colsleft = $numinrow - $rem;
9238: if ($colsleft > 1 ) {
9239: $current{$type} .= '<td colspan="'.$colsleft.
9240: '" class="LC_left_item">'.
9241: ' </td>';
9242: } elsif ($colsleft == 1) {
9243: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 9244: }
1.152 raeburn 9245: $current{$type} .= '</tr></table>';
1.150 raeburn 9246: }
1.145 raeburn 9247: }
9248: }
9249: if ($current{$type} eq '') {
9250: $current{$type} = &mt('None specified');
9251: }
1.152 raeburn 9252: if ($othercontrol) {
9253: if ($type eq 'primary') {
9254: $canselect{$type} = $othercontrol;
9255: }
9256: } else {
9257: $canselect{$type} =
9258: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
9259: '<select name="newspare_'.$type.'_'.$server.'" '.
9260: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
9261: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
9262: if (@choices > 0) {
9263: foreach my $lonhost (@choices) {
9264: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
9265: }
9266: }
9267: $canselect{$type} .= '</select>'."\n";
9268: }
9269: } else {
9270: $current{$type} = &mt('Could not be determined');
9271: if ($type eq 'primary') {
9272: $canselect{$type} = $othercontrol;
9273: }
1.145 raeburn 9274: }
1.152 raeburn 9275: if ($type eq 'default') {
9276: $datatable .= '<tr'.$css_class.'>';
9277: }
9278: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
9279: '<td>'.$current{$type}.'</td>'."\n".
9280: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 9281: }
9282: $itemcount ++;
9283: }
9284: }
9285: $$rowtotal += $itemcount;
9286: return $datatable;
9287: }
9288:
1.152 raeburn 9289: sub possible_newspares {
9290: my ($server,$currspares,$serverhomes,$altids) = @_;
9291: my $serverhostname = &Apache::lonnet::hostname($server);
9292: my %excluded;
9293: if ($serverhostname ne '') {
9294: %excluded = (
9295: $serverhostname => 1,
9296: );
9297: }
9298: if (ref($currspares) eq 'HASH') {
9299: foreach my $type (keys(%{$currspares})) {
9300: if (ref($currspares->{$type}) eq 'ARRAY') {
9301: if (@{$currspares->{$type}} > 0) {
9302: foreach my $curr (@{$currspares->{$type}}) {
9303: my $hostname = &Apache::lonnet::hostname($curr);
9304: $excluded{$hostname} = 1;
9305: }
9306: }
9307: }
9308: }
9309: }
9310: my @choices;
9311: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
9312: if (keys(%{$serverhomes}) > 1) {
9313: foreach my $name (sort(keys(%{$serverhomes}))) {
9314: unless ($excluded{$name}) {
9315: if (exists($altids->{$serverhomes->{$name}})) {
9316: push(@choices,$altids->{$serverhomes->{$name}});
9317: } else {
9318: push(@choices,$serverhomes->{$name});
1.145 raeburn 9319: }
9320: }
9321: }
9322: }
9323: }
1.152 raeburn 9324: return sort(@choices);
1.145 raeburn 9325: }
9326:
1.150 raeburn 9327: sub print_loadbalancing {
9328: my ($dom,$settings,$rowtotal) = @_;
9329: my $primary_id = &Apache::lonnet::domain($dom,'primary');
9330: my $intdom = &Apache::lonnet::internet_dom($primary_id);
9331: my $numinrow = 1;
9332: my $datatable;
9333: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 9334: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 9335: if (ref($settings) eq 'HASH') {
9336: %existing = %{$settings};
9337: }
9338: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
9339: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 9340: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 9341: } else {
9342: return;
9343: }
9344: my ($othertitle,$usertypes,$types) =
9345: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 9346: my $rownum = 8;
1.150 raeburn 9347: if (ref($types) eq 'ARRAY') {
9348: $rownum += scalar(@{$types});
9349: }
1.171 raeburn 9350: my @css_class = ('LC_odd_row','LC_even_row');
9351: my $balnum = 0;
9352: my $islast;
9353: my (@toshow,$disabledtext);
9354: if (keys(%currbalancer) > 0) {
9355: @toshow = sort(keys(%currbalancer));
9356: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
9357: push(@toshow,'');
9358: }
9359: } else {
9360: @toshow = ('');
9361: $disabledtext = &mt('No existing load balancer');
9362: }
9363: foreach my $lonhost (@toshow) {
9364: if ($balnum == scalar(@toshow)-1) {
9365: $islast = 1;
9366: } else {
9367: $islast = 0;
9368: }
9369: my $cssidx = $balnum%2;
9370: my $targets_div_style = 'display: none';
9371: my $disabled_div_style = 'display: block';
9372: my $homedom_div_style = 'display: none';
9373: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 9374: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9375: '<p>';
9376: if ($lonhost eq '') {
1.210 raeburn 9377: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 9378: if (keys(%currbalancer) > 0) {
9379: $datatable .= &mt('Add balancer:');
9380: } else {
9381: $datatable .= &mt('Enable balancer:');
9382: }
9383: $datatable .= ' '.
9384: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
9385: ' id="loadbalancing_lonhost_'.$balnum.'"'.
9386: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
9387: '<option value="" selected="selected">'.&mt('None').
9388: '</option>'."\n";
9389: foreach my $server (sort(keys(%servers))) {
9390: next if ($currbalancer{$server});
9391: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
9392: }
1.210 raeburn 9393: $datatable .=
1.171 raeburn 9394: '</select>'."\n".
9395: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
9396: } else {
9397: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
9398: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
9399: &mt('Stop balancing').'</label>'.
9400: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
9401: $targets_div_style = 'display: block';
9402: $disabled_div_style = 'display: none';
9403: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
9404: $homedom_div_style = 'display: block';
9405: }
9406: }
1.306 raeburn 9407: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9408: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
9409: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
9410: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
9411: my ($numspares,@spares) = &count_servers($lonhost,%servers);
9412: my @sparestypes = ('primary','default');
9413: my %typetitles = &sparestype_titles();
1.284 raeburn 9414: my %hostherechecked = (
9415: no => ' checked="checked"',
9416: );
1.342 raeburn 9417: my %balcookiechecked = (
1.425 raeburn 9418: no => ' checked="checked"',
1.342 raeburn 9419: );
1.171 raeburn 9420: foreach my $sparetype (@sparestypes) {
9421: my $targettable;
9422: for (my $i=0; $i<$numspares; $i++) {
9423: my $checked;
9424: if (ref($currtargets{$lonhost}) eq 'HASH') {
9425: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9426: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9427: $checked = ' checked="checked"';
9428: }
9429: }
9430: }
9431: my ($chkboxval,$disabled);
9432: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
9433: $chkboxval = $spares[$i];
9434: }
9435: if (exists($currbalancer{$spares[$i]})) {
9436: $disabled = ' disabled="disabled"';
9437: }
1.210 raeburn 9438: $targettable .=
1.253 raeburn 9439: '<td><span class="LC_nobreak"><label>'.
9440: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 9441: $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 9442: '</span></label></span></td>';
1.171 raeburn 9443: my $rem = $i%($numinrow);
9444: if ($rem == 0) {
9445: if (($i > 0) && ($i < $numspares-1)) {
9446: $targettable .= '</tr>';
9447: }
9448: if ($i < $numspares-1) {
9449: $targettable .= '<tr>';
1.150 raeburn 9450: }
9451: }
9452: }
1.171 raeburn 9453: if ($targettable ne '') {
9454: my $rem = $numspares%($numinrow);
9455: my $colsleft = $numinrow - $rem;
9456: if ($colsleft > 1 ) {
9457: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9458: ' </td>';
9459: } elsif ($colsleft == 1) {
9460: $targettable .= '<td class="LC_left_item"> </td>';
9461: }
9462: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
9463: '<table><tr>'.$targettable.'</tr></table><br />';
9464: }
1.284 raeburn 9465: $hostherechecked{$sparetype} = '';
9466: if (ref($currtargets{$lonhost}) eq 'HASH') {
9467: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9468: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9469: $hostherechecked{$sparetype} = ' checked="checked"';
9470: $hostherechecked{'no'} = '';
9471: }
9472: }
9473: }
9474: }
1.342 raeburn 9475: if ($currcookies{$lonhost}) {
9476: %balcookiechecked = (
9477: yes => ' checked="checked"',
9478: );
9479: }
1.284 raeburn 9480: $datatable .= &mt('Hosting on balancer itself').'<br />'.
9481: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
9482: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
9483: foreach my $sparetype (@sparestypes) {
9484: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
9485: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
9486: '</i></label><br />';
1.171 raeburn 9487: }
1.342 raeburn 9488: $datatable .= &mt('Use balancer cookie').'<br />'.
9489: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
9490: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
9491: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
9492: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
9493: '</div></td></tr>'.
1.171 raeburn 9494: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
9495: $othertitle,$usertypes,$types,\%servers,
9496: \%currbalancer,$lonhost,
9497: $targets_div_style,$homedom_div_style,
9498: $css_class[$cssidx],$balnum,$islast);
9499: $$rowtotal += $rownum;
9500: $balnum ++;
9501: }
9502: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
9503: return $datatable;
9504: }
9505:
9506: sub get_loadbalancers_config {
1.342 raeburn 9507: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 9508: return unless ((ref($servers) eq 'HASH') &&
9509: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 9510: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
9511: (ref($currcookies) eq 'HASH'));
1.171 raeburn 9512: if (keys(%{$existing}) > 0) {
9513: my $oldlonhost;
9514: foreach my $key (sort(keys(%{$existing}))) {
9515: if ($key eq 'lonhost') {
9516: $oldlonhost = $existing->{'lonhost'};
9517: $currbalancer->{$oldlonhost} = 1;
9518: } elsif ($key eq 'targets') {
9519: if ($oldlonhost) {
9520: $currtargets->{$oldlonhost} = $existing->{'targets'};
9521: }
9522: } elsif ($key eq 'rules') {
9523: if ($oldlonhost) {
9524: $currrules->{$oldlonhost} = $existing->{'rules'};
9525: }
9526: } elsif (ref($existing->{$key}) eq 'HASH') {
9527: $currbalancer->{$key} = 1;
9528: $currtargets->{$key} = $existing->{$key}{'targets'};
9529: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 9530: if ($existing->{$key}{'cookie'}) {
9531: $currcookies->{$key} = 1;
9532: }
1.150 raeburn 9533: }
9534: }
1.171 raeburn 9535: } else {
9536: my ($balancerref,$targetsref) =
9537: &Apache::lonnet::get_lonbalancer_config($servers);
9538: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
9539: foreach my $server (sort(keys(%{$balancerref}))) {
9540: $currbalancer->{$server} = 1;
9541: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 9542: }
9543: }
9544: }
1.171 raeburn 9545: return;
1.150 raeburn 9546: }
9547:
9548: sub loadbalancing_rules {
9549: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 9550: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
9551: $css_class,$balnum,$islast) = @_;
1.150 raeburn 9552: my $output;
1.171 raeburn 9553: my $num = 0;
1.210 raeburn 9554: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 9555: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
9556: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
9557: foreach my $type (@{$alltypes}) {
1.171 raeburn 9558: $num ++;
1.150 raeburn 9559: my $current;
9560: if (ref($currrules) eq 'HASH') {
9561: $current = $currrules->{$type};
9562: }
1.253 raeburn 9563: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 9564: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 9565: $current = '';
9566: }
9567: }
9568: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 9569: $servers,$currbalancer,$lonhost,$dom,
9570: $targets_div_style,$homedom_div_style,
9571: $css_class,$balnum,$num,$islast);
1.150 raeburn 9572: }
9573: }
9574: return $output;
9575: }
9576:
9577: sub loadbalancing_titles {
9578: my ($dom,$intdom,$usertypes,$types) = @_;
9579: my %othertypes = (
9580: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
9581: '_LC_author' => &mt('Users from [_1] with author role',$dom),
9582: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
9583: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 9584: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
9585: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 9586: );
1.209 raeburn 9587: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 9588: my @available;
1.150 raeburn 9589: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9590: @available = @{$types};
1.150 raeburn 9591: }
1.302 raeburn 9592: unless (grep(/^default$/,@available)) {
9593: push(@available,'default');
9594: }
9595: unshift(@alltypes,@available);
1.150 raeburn 9596: my %titles;
9597: foreach my $type (@alltypes) {
9598: if ($type =~ /^_LC_/) {
9599: $titles{$type} = $othertypes{$type};
9600: } elsif ($type eq 'default') {
9601: $titles{$type} = &mt('All users from [_1]',$dom);
9602: if (ref($types) eq 'ARRAY') {
9603: if (@{$types} > 0) {
9604: $titles{$type} = &mt('Other users from [_1]',$dom);
9605: }
9606: }
9607: } elsif (ref($usertypes) eq 'HASH') {
9608: $titles{$type} = $usertypes->{$type};
9609: }
9610: }
9611: return (\@alltypes,\%othertypes,\%titles);
9612: }
9613:
9614: sub loadbalance_rule_row {
1.171 raeburn 9615: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
9616: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 9617: my @rulenames;
1.150 raeburn 9618: my %ruletitles = &offloadtype_text();
1.209 raeburn 9619: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 9620: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 9621: } else {
1.209 raeburn 9622: @rulenames = ('default','homeserver');
9623: if ($type eq '_LC_external') {
9624: push(@rulenames,'externalbalancer');
9625: } else {
9626: push(@rulenames,'specific');
9627: }
9628: push(@rulenames,'none');
1.150 raeburn 9629: }
9630: my $style = $targets_div_style;
1.253 raeburn 9631: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 9632: $style = $homedom_div_style;
9633: }
1.171 raeburn 9634: my $space;
9635: if ($islast && $num == 1) {
1.317 raeburn 9636: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 9637: }
1.210 raeburn 9638: my $output =
1.306 raeburn 9639: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 9640: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
9641: '<td valaign="top">'.$space.
9642: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 9643: for (my $i=0; $i<@rulenames; $i++) {
9644: my $rule = $rulenames[$i];
9645: my ($checked,$extra);
9646: if ($rulenames[$i] eq 'default') {
9647: $rule = '';
9648: }
9649: if ($rulenames[$i] eq 'specific') {
9650: if (ref($servers) eq 'HASH') {
9651: my $default;
9652: if (($current ne '') && (exists($servers->{$current}))) {
9653: $checked = ' checked="checked"';
9654: }
9655: unless ($checked) {
9656: $default = ' selected="selected"';
9657: }
1.210 raeburn 9658: $extra =
1.171 raeburn 9659: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
9660: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
9661: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
9662: '<option value=""'.$default.'></option>'."\n";
9663: foreach my $server (sort(keys(%{$servers}))) {
9664: if (ref($currbalancer) eq 'HASH') {
9665: next if (exists($currbalancer->{$server}));
9666: }
1.150 raeburn 9667: my $selected;
1.171 raeburn 9668: if ($server eq $current) {
1.150 raeburn 9669: $selected = ' selected="selected"';
9670: }
1.171 raeburn 9671: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 9672: }
9673: $extra .= '</select>';
9674: }
9675: } elsif ($rule eq $current) {
9676: $checked = ' checked="checked"';
9677: }
9678: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 9679: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
9680: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
9681: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 9682: ')"'.$checked.' /> ';
9683: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
9684: $output .= $ruletitles{'particular'};
9685: } else {
9686: $output .= $ruletitles{$rulenames[$i]};
9687: }
9688: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 9689: }
9690: $output .= '</div></td></tr>'."\n";
9691: return $output;
9692: }
9693:
9694: sub offloadtype_text {
9695: my %ruletitles = &Apache::lonlocal::texthash (
9696: 'default' => 'Offloads to default destinations',
9697: 'homeserver' => "Offloads to user's home server",
9698: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
9699: 'specific' => 'Offloads to specific server',
1.161 raeburn 9700: 'none' => 'No offload',
1.209 raeburn 9701: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
9702: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 9703: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 9704: );
9705: return %ruletitles;
9706: }
9707:
9708: sub sparestype_titles {
9709: my %typestitles = &Apache::lonlocal::texthash (
9710: 'primary' => 'primary',
9711: 'default' => 'default',
9712: );
9713: return %typestitles;
9714: }
9715:
1.28 raeburn 9716: sub contact_titles {
9717: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 9718: 'supportemail' => 'Support E-mail address',
9719: 'adminemail' => 'Default Server Admin E-mail address',
9720: 'errormail' => 'Error reports to be e-mailed to',
9721: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 9722: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
9723: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 9724: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
9725: 'requestsmail' => 'E-mail from course requests requiring approval',
9726: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 9727: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350 raeburn 9728: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.378 raeburn 9729: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
9730: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.340 raeburn 9731: 'errorweights' => 'Weights used to compute error count',
9732: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 9733: );
9734: my %short_titles = &Apache::lonlocal::texthash (
9735: adminemail => 'Admin E-mail address',
9736: supportemail => 'Support E-mail',
9737: );
9738: return (\%titles,\%short_titles);
9739: }
9740:
1.286 raeburn 9741: sub helpform_fields {
9742: my %titles = &Apache::lonlocal::texthash (
9743: 'username' => 'Name',
9744: 'user' => 'Username/domain',
9745: 'phone' => 'Phone',
9746: 'cc' => 'Cc e-mail',
9747: 'course' => 'Course Details',
9748: 'section' => 'Sections',
1.289 raeburn 9749: 'screenshot' => 'File upload',
1.286 raeburn 9750: );
9751: my @fields = ('username','phone','user','course','section','cc','screenshot');
9752: my %possoptions = (
9753: username => ['yes','no','req'],
1.289 raeburn 9754: phone => ['yes','no','req'],
1.286 raeburn 9755: user => ['yes','no'],
1.289 raeburn 9756: cc => ['yes','no'],
1.286 raeburn 9757: course => ['yes','no'],
9758: section => ['yes','no'],
9759: screenshot => ['yes','no'],
9760: );
9761: my %fieldoptions = &Apache::lonlocal::texthash (
9762: 'yes' => 'Optional',
9763: 'req' => 'Required',
9764: 'no' => "Not shown",
9765: );
9766: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
9767: }
9768:
1.72 raeburn 9769: sub tool_titles {
9770: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 9771: aboutme => 'Personal web page',
1.86 raeburn 9772: blog => 'Blog',
9773: portfolio => 'Portfolio',
1.430 raeburn 9774: portaccess => 'Share portfolio files',
1.413 raeburn 9775: timezone => 'Can set time zone',
1.88 bisitz 9776: official => 'Official courses (with institutional codes)',
9777: unofficial => 'Unofficial courses',
1.98 raeburn 9778: community => 'Communities',
1.216 raeburn 9779: textbook => 'Textbook courses',
1.271 raeburn 9780: placement => 'Placement tests',
1.86 raeburn 9781: );
1.72 raeburn 9782: return %titles;
9783: }
9784:
1.101 raeburn 9785: sub courserequest_titles {
9786: my %titles = &Apache::lonlocal::texthash (
9787: official => 'Official',
9788: unofficial => 'Unofficial',
9789: community => 'Communities',
1.216 raeburn 9790: textbook => 'Textbook',
1.271 raeburn 9791: placement => 'Placement tests',
1.325 raeburn 9792: lti => 'LTI Provider',
1.101 raeburn 9793: norequest => 'Not allowed',
1.325 raeburn 9794: approval => 'Approval by DC',
1.101 raeburn 9795: validate => 'With validation',
9796: autolimit => 'Numerical limit',
1.103 raeburn 9797: unlimited => '(blank for unlimited)',
1.101 raeburn 9798: );
9799: return %titles;
9800: }
9801:
1.163 raeburn 9802: sub authorrequest_titles {
9803: my %titles = &Apache::lonlocal::texthash (
9804: norequest => 'Not allowed',
9805: approval => 'Approval by Dom. Coord.',
9806: automatic => 'Automatic approval',
9807: );
9808: return %titles;
1.210 raeburn 9809: }
1.163 raeburn 9810:
1.101 raeburn 9811: sub courserequest_conditions {
9812: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 9813: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 9814: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 9815: );
9816: return %conditions;
9817: }
9818:
9819:
1.27 raeburn 9820: sub print_usercreation {
1.30 raeburn 9821: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 9822: my $numinrow = 4;
1.28 raeburn 9823: my $datatable;
9824: if ($position eq 'top') {
1.30 raeburn 9825: $$rowtotal ++;
1.34 raeburn 9826: my $rowcount = 0;
1.32 raeburn 9827: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 9828: if (ref($rules) eq 'HASH') {
9829: if (keys(%{$rules}) > 0) {
1.32 raeburn 9830: $datatable .= &user_formats_row('username',$settings,$rules,
9831: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 9832: $$rowtotal ++;
1.32 raeburn 9833: $rowcount ++;
9834: }
9835: }
9836: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
9837: if (ref($idrules) eq 'HASH') {
9838: if (keys(%{$idrules}) > 0) {
9839: $datatable .= &user_formats_row('id',$settings,$idrules,
9840: $idruleorder,$numinrow,$rowcount);
9841: $$rowtotal ++;
9842: $rowcount ++;
1.28 raeburn 9843: }
9844: }
1.39 raeburn 9845: if ($rowcount == 0) {
9846: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
9847: $$rowtotal ++;
9848: $rowcount ++;
9849: }
1.34 raeburn 9850: } elsif ($position eq 'middle') {
1.224 raeburn 9851: my @creators = ('author','course','requestcrs');
1.37 raeburn 9852: my ($rules,$ruleorder) =
9853: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 9854: my %lt = &usercreation_types();
9855: my %checked;
9856: if (ref($settings) eq 'HASH') {
9857: if (ref($settings->{'cancreate'}) eq 'HASH') {
9858: foreach my $item (@creators) {
9859: $checked{$item} = $settings->{'cancreate'}{$item};
9860: }
9861: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
9862: foreach my $item (@creators) {
9863: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
9864: $checked{$item} = 'none';
9865: }
9866: }
9867: }
9868: }
9869: my $rownum = 0;
9870: foreach my $item (@creators) {
9871: $rownum ++;
1.224 raeburn 9872: if ($checked{$item} eq '') {
9873: $checked{$item} = 'any';
1.34 raeburn 9874: }
9875: my $css_class;
9876: if ($rownum%2) {
9877: $css_class = '';
9878: } else {
9879: $css_class = ' class="LC_odd_row" ';
9880: }
9881: $datatable .= '<tr'.$css_class.'>'.
9882: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 9883: '</span></td><td style="text-align: right">';
1.224 raeburn 9884: my @options = ('any');
9885: if (ref($rules) eq 'HASH') {
9886: if (keys(%{$rules}) > 0) {
9887: push(@options,('official','unofficial'));
1.37 raeburn 9888: }
9889: }
1.224 raeburn 9890: push(@options,'none');
1.37 raeburn 9891: foreach my $option (@options) {
1.50 raeburn 9892: my $type = 'radio';
1.34 raeburn 9893: my $check = ' ';
1.224 raeburn 9894: if ($checked{$item} eq $option) {
9895: $check = ' checked="checked" ';
1.34 raeburn 9896: }
9897: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 9898: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 9899: $item.'" value="'.$option.'"'.$check.'/> '.
9900: $lt{$option}.'</label> </span>';
9901: }
9902: $datatable .= '</td></tr>';
9903: }
1.28 raeburn 9904: } else {
9905: my @contexts = ('author','course','domain');
1.325 raeburn 9906: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 9907: my %checked;
9908: if (ref($settings) eq 'HASH') {
9909: if (ref($settings->{'authtypes'}) eq 'HASH') {
9910: foreach my $item (@contexts) {
9911: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
9912: foreach my $auth (@authtypes) {
9913: if ($settings->{'authtypes'}{$item}{$auth}) {
9914: $checked{$item}{$auth} = ' checked="checked" ';
9915: }
9916: }
9917: }
9918: }
1.27 raeburn 9919: }
1.35 raeburn 9920: } else {
9921: foreach my $item (@contexts) {
1.36 raeburn 9922: foreach my $auth (@authtypes) {
1.35 raeburn 9923: $checked{$item}{$auth} = ' checked="checked" ';
9924: }
9925: }
1.27 raeburn 9926: }
1.28 raeburn 9927: my %title = &context_names();
9928: my %authname = &authtype_names();
9929: my $rownum = 0;
9930: my $css_class;
9931: foreach my $item (@contexts) {
9932: if ($rownum%2) {
9933: $css_class = '';
9934: } else {
9935: $css_class = ' class="LC_odd_row" ';
9936: }
1.30 raeburn 9937: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 9938: '<td>'.$title{$item}.
9939: '</td><td class="LC_left_item">'.
9940: '<span class="LC_nobreak">';
9941: foreach my $auth (@authtypes) {
9942: $datatable .= '<label>'.
9943: '<input type="checkbox" name="'.$item.'_auth" '.
9944: $checked{$item}{$auth}.' value="'.$auth.'" />'.
9945: $authname{$auth}.'</label> ';
9946: }
9947: $datatable .= '</span></td></tr>';
9948: $rownum ++;
1.27 raeburn 9949: }
1.30 raeburn 9950: $$rowtotal += $rownum;
1.27 raeburn 9951: }
9952: return $datatable;
9953: }
9954:
1.224 raeburn 9955: sub print_selfcreation {
9956: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 9957: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
9958: $emaildomain,$datatable);
1.224 raeburn 9959: if (ref($settings) eq 'HASH') {
9960: if (ref($settings->{'cancreate'}) eq 'HASH') {
9961: $createsettings = $settings->{'cancreate'};
1.236 raeburn 9962: if (ref($createsettings) eq 'HASH') {
9963: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
9964: @selfcreate = @{$createsettings->{'selfcreate'}};
9965: } elsif ($createsettings->{'selfcreate'} ne '') {
9966: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
9967: @selfcreate = ('email','login','sso');
9968: } elsif ($createsettings->{'selfcreate'} ne 'none') {
9969: @selfcreate = ($createsettings->{'selfcreate'});
9970: }
9971: }
9972: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
9973: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 9974: }
1.305 raeburn 9975: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
9976: $emailoptions = $createsettings->{'emailoptions'};
9977: }
1.303 raeburn 9978: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
9979: $emailverified = $createsettings->{'emailverified'};
9980: }
9981: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
9982: $emaildomain = $createsettings->{'emaildomain'};
9983: }
1.224 raeburn 9984: }
9985: }
9986: }
9987: my %radiohash;
9988: my $numinrow = 4;
9989: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 9990: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 9991: if ($position eq 'top') {
9992: my %choices = &Apache::lonlocal::texthash (
9993: cancreate_login => 'Institutional Login',
9994: cancreate_sso => 'Institutional Single Sign On',
9995: );
9996: my @toggles = sort(keys(%choices));
9997: my %defaultchecked = (
9998: 'cancreate_login' => 'off',
9999: 'cancreate_sso' => 'off',
10000: );
1.228 raeburn 10001: my ($onclick,$itemcount);
1.224 raeburn 10002: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
10003: \%choices,$itemcount,$onclick);
1.228 raeburn 10004: $$rowtotal += $itemcount;
1.425 raeburn 10005:
1.224 raeburn 10006: if (ref($usertypes) eq 'HASH') {
10007: if (keys(%{$usertypes}) > 0) {
10008: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
10009: $dom,$numinrow,$othertitle,
1.305 raeburn 10010: 'statustocreate',$rowtotal);
1.224 raeburn 10011: $$rowtotal ++;
10012: }
10013: }
1.240 raeburn 10014: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
10015: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10016: $fieldtitles{'inststatus'} = &mt('Institutional status');
10017: my $rem;
10018: my $numperrow = 2;
10019: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
10020: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 10021: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 10022: '<td class="LC_left_item">'."\n".
1.334 raeburn 10023: '<table>'."\n";
1.240 raeburn 10024: for (my $i=0; $i<@fields; $i++) {
10025: $rem = $i%($numperrow);
10026: if ($rem == 0) {
10027: if ($i > 0) {
10028: $datatable .= '</tr>';
10029: }
10030: $datatable .= '<tr>';
10031: }
10032: my $currval;
1.248 raeburn 10033: if (ref($createsettings) eq 'HASH') {
10034: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
10035: $currval = $createsettings->{'shibenv'}{$fields[$i]};
10036: }
1.240 raeburn 10037: }
10038: $datatable .= '<td class="LC_left_item">'.
10039: '<span class="LC_nobreak">'.
10040: '<input type="text" name="shibenv_'.$fields[$i].'" '.
10041: 'value="'.$currval.'" size="10" /> '.
10042: $fieldtitles{$fields[$i]}.'</span></td>';
10043: }
10044: my $colsleft = $numperrow - $rem;
10045: if ($colsleft > 1 ) {
10046: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10047: ' </td>';
10048: } elsif ($colsleft == 1) {
10049: $datatable .= '<td class="LC_left_item"> </td>';
10050: }
10051: $datatable .= '</tr></table></td></tr>';
10052: $$rowtotal ++;
1.224 raeburn 10053: } elsif ($position eq 'middle') {
10054: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 10055: my @posstypes;
1.224 raeburn 10056: if (ref($types) eq 'ARRAY') {
1.302 raeburn 10057: @posstypes = @{$types};
10058: }
10059: unless (grep(/^default$/,@posstypes)) {
10060: push(@posstypes,'default');
10061: }
10062: my %usertypeshash;
10063: if (ref($usertypes) eq 'HASH') {
10064: %usertypeshash = %{$usertypes};
10065: }
10066: $usertypeshash{'default'} = $othertitle;
10067: foreach my $status (@posstypes) {
10068: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
10069: $numinrow,$$rowtotal,\%usertypeshash);
10070: $$rowtotal ++;
1.224 raeburn 10071: }
10072: } else {
1.236 raeburn 10073: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 10074: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 10075: );
10076: my @toggles = sort(keys(%choices));
10077: my %defaultchecked = (
10078: 'cancreate_email' => 'off',
10079: );
1.305 raeburn 10080: my $customclass = 'LC_selfcreate_email';
10081: my $classprefix = 'LC_canmodify_emailusername_';
10082: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 10083: my $display = 'none';
1.305 raeburn 10084: my $rowstyle = 'display:none';
1.236 raeburn 10085: if (grep(/^\Qemail\E$/,@selfcreate)) {
10086: $display = 'block';
1.305 raeburn 10087: $rowstyle = 'display:table-row';
1.236 raeburn 10088: }
1.305 raeburn 10089: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
10090: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
10091: \%choices,$$rowtotal,$onclick);
10092: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
10093: $rowstyle);
10094: $$rowtotal ++;
10095: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
10096: $rowstyle);
10097: $$rowtotal ++;
10098: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 10099: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 10100: my ($emailrules,$emailruleorder) =
10101: &Apache::lonnet::inst_userrules($dom,'email');
10102: my $primary_id = &Apache::lonnet::domain($dom,'primary');
10103: my $intdom = &Apache::lonnet::internet_dom($primary_id);
10104: if (ref($types) eq 'ARRAY') {
10105: @posstypes = @{$types};
10106: }
10107: if (@posstypes) {
10108: unless (grep(/^default$/,@posstypes)) {
10109: push(@posstypes,'default');
1.302 raeburn 10110: }
10111: if (ref($usertypes) eq 'HASH') {
10112: %usertypeshash = %{$usertypes};
10113: }
1.305 raeburn 10114: my $currassign;
10115: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
10116: $currassign = {
10117: selfassign => $domdefaults{'inststatusguest'},
10118: };
10119: @ordered = @{$domdefaults{'inststatusguest'}};
10120: } else {
10121: $currassign = { selfassign => [] };
10122: }
10123: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
10124: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
10125: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
10126: $numinrow,$othertitle,'selfassign',
10127: $rowtotal,$onclicktypes,$customclass,
10128: $rowstyle);
10129: $$rowtotal ++;
1.302 raeburn 10130: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10131: foreach my $status (@posstypes) {
10132: my $css_class;
10133: if ($$rowtotal%2) {
10134: $css_class = 'LC_odd_row ';
10135: }
10136: $css_class .= $customclass;
10137: my $rowid = $optionsprefix.$status;
10138: my $hidden = 1;
10139: my $currstyle = 'display:none';
10140: if (grep(/^\Q$status\E$/,@ordered)) {
10141: $currstyle = $rowstyle;
1.425 raeburn 10142: $hidden = 0;
1.305 raeburn 10143: }
10144: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10145: $emailrules,$emailruleorder,$settings,$status,$rowid,
10146: $usertypeshash{$status},$css_class,$currstyle,$intdom);
10147: unless ($hidden) {
10148: $$rowtotal ++;
10149: }
1.224 raeburn 10150: }
1.302 raeburn 10151: } else {
1.305 raeburn 10152: my $css_class;
10153: if ($$rowtotal%2) {
10154: $css_class = 'LC_odd_row ';
10155: }
10156: $css_class .= $customclass;
1.302 raeburn 10157: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10158: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10159: $emailrules,$emailruleorder,$settings,'default','',
10160: $othertitle,$css_class,$rowstyle,$intdom);
10161: $$rowtotal ++;
1.224 raeburn 10162: }
10163: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 10164: $numinrow = 1;
1.305 raeburn 10165: if (@posstypes) {
10166: foreach my $status (@posstypes) {
10167: my $rowid = $classprefix.$status;
10168: my $datarowstyle = 'display:none';
1.425 raeburn 10169: if (grep(/^\Q$status\E$/,@ordered)) {
10170: $datarowstyle = $rowstyle;
1.305 raeburn 10171: }
10172: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
10173: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10174: $infotitles,$rowid,$customclass,$datarowstyle);
10175: unless ($datarowstyle eq 'display:none') {
10176: $$rowtotal ++;
10177: }
1.224 raeburn 10178: }
1.305 raeburn 10179: } else {
10180: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
10181: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10182: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 10183: }
10184: }
10185: return $datatable;
10186: }
10187:
1.305 raeburn 10188: sub selfcreate_javascript {
10189: return <<"ENDSCRIPT";
10190:
10191: <script type="text/javascript">
10192: // <![CDATA[
10193:
10194: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
10195: var x = document.getElementsByClassName(target);
10196: var insttypes = 0;
10197: var insttypeRegExp = new RegExp(prefix);
10198: if ((x.length != undefined) && (x.length > 0)) {
10199: if (form.elements[radio].length != undefined) {
10200: for (var i=0; i<form.elements[radio].length; i++) {
10201: if (form.elements[radio][i].checked) {
10202: if (form.elements[radio][i].value == 1) {
10203: for (var j=0; j<x.length; j++) {
10204: if (x[j].id == 'undefined') {
10205: x[j].style.display = 'table-row';
10206: } else if (insttypeRegExp.test(x[j].id)) {
10207: insttypes ++;
10208: } else {
10209: x[j].style.display = 'table-row';
10210: }
10211: }
10212: } else {
10213: for (var j=0; j<x.length; j++) {
10214: x[j].style.display = 'none';
10215: }
1.236 raeburn 10216: }
1.305 raeburn 10217: break;
10218: }
10219: }
10220: if (insttypes > 0) {
10221: toggleDataRow(form,checkbox,target,altprefix);
10222: toggleDataRow(form,checkbox,target,prefix,1);
10223: }
10224: }
10225: }
10226: return;
10227: }
10228:
10229: function toggleDataRow(form,checkbox,target,prefix,docount) {
10230: if (form.elements[checkbox].length != undefined) {
10231: var count = 0;
10232: if (docount) {
10233: for (var i=0; i<form.elements[checkbox].length; i++) {
10234: if (form.elements[checkbox][i].checked) {
10235: count ++;
1.236 raeburn 10236: }
1.305 raeburn 10237: }
10238: }
10239: for (var i=0; i<form.elements[checkbox].length; i++) {
10240: var type = form.elements[checkbox][i].value;
10241: if (document.getElementById(prefix+type)) {
10242: if (form.elements[checkbox][i].checked) {
10243: document.getElementById(prefix+type).style.display = 'table-row';
10244: if (count % 2 == 1) {
10245: document.getElementById(prefix+type).className = target+' LC_odd_row';
10246: } else {
10247: document.getElementById(prefix+type).className = target;
1.236 raeburn 10248: }
1.305 raeburn 10249: count ++;
1.236 raeburn 10250: } else {
1.305 raeburn 10251: document.getElementById(prefix+type).style.display = 'none';
10252: }
10253: }
10254: }
10255: }
10256: return;
10257: }
10258:
10259: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
10260: var caller = radio+'_'+status;
10261: if (form.elements[caller].length != undefined) {
10262: for (var i=0; i<form.elements[caller].length; i++) {
10263: if (form.elements[caller][i].checked) {
10264: if (document.getElementById(altprefix+'_inst_'+status)) {
10265: var curr = form.elements[caller][i].value;
10266: if (prefix) {
10267: document.getElementById(prefix+'_'+status).style.display = 'none';
10268: }
10269: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
10270: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
10271: if (curr == 'custom') {
1.425 raeburn 10272: if (prefix) {
1.305 raeburn 10273: document.getElementById(prefix+'_'+status).style.display = 'inline';
10274: }
10275: } else if (curr == 'inst') {
10276: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
10277: } else if (curr == 'noninst') {
10278: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 10279: }
1.305 raeburn 10280: break;
1.236 raeburn 10281: }
10282: }
10283: }
10284: }
10285: }
10286:
1.305 raeburn 10287: // ]]>
10288: </script>
10289:
10290: ENDSCRIPT
10291: }
10292:
10293: sub noninst_users {
10294: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
1.425 raeburn 10295: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
1.305 raeburn 10296: my $class = 'LC_left_item';
10297: if ($css_class) {
1.425 raeburn 10298: $css_class = ' class="'.$css_class.'"';
1.305 raeburn 10299: }
10300: if ($rowid) {
10301: $rowid = ' id="'.$rowid.'"';
10302: }
10303: if ($rowstyle) {
10304: $rowstyle = ' style="'.$rowstyle.'"';
10305: }
10306: my ($output,$description);
10307: if ($type eq 'default') {
10308: $description = &mt('Requests for: [_1]',$typetitle);
10309: } else {
10310: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
10311: }
10312: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
1.425 raeburn 10313: "<td>$description</td>\n".
1.305 raeburn 10314: '<td class="'.$class.'" colspan="2">'.
10315: '<table><tr>';
1.425 raeburn 10316: my %headers = &Apache::lonlocal::texthash(
1.305 raeburn 10317: approve => 'Processing',
10318: email => 'E-mail',
10319: username => 'Username',
10320: );
10321: foreach my $item ('approve','email','username') {
10322: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 10323: }
1.305 raeburn 10324: $output .= '</tr><tr>';
10325: foreach my $item ('approve','email','username') {
1.306 raeburn 10326: $output .= '<td style="vertical-align: top">';
1.305 raeburn 10327: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
10328: if ($item eq 'approve') {
10329: %choices = &Apache::lonlocal::texthash (
10330: automatic => 'Automatically approved',
10331: approval => 'Queued for approval',
10332: );
10333: @options = ('automatic','approval');
10334: $hashref = $processing;
10335: $defoption = 'automatic';
10336: $name = 'cancreate_emailprocess_'.$type;
10337: } elsif ($item eq 'email') {
10338: %choices = &Apache::lonlocal::texthash (
10339: any => 'Any e-mail',
10340: inst => 'Institutional only',
10341: noninst => 'Non-institutional only',
10342: custom => 'Custom restrictions',
10343: );
10344: @options = ('any','inst','noninst');
10345: my $showcustom;
10346: if (ref($emailrules) eq 'HASH') {
10347: if (keys(%{$emailrules}) > 0) {
10348: push(@options,'custom');
10349: $showcustom = 'cancreate_emailrule';
10350: if (ref($settings) eq 'HASH') {
10351: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
10352: foreach my $rule (@{$settings->{'email_rule'}}) {
10353: if (exists($emailrules->{$rule})) {
10354: $hascustom ++;
10355: }
10356: }
10357: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
10358: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
10359: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
10360: if (exists($emailrules->{$rule})) {
10361: $hascustom ++;
10362: }
10363: }
10364: }
10365: }
10366: }
10367: }
10368: }
10369: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
10370: "'cancreate_emaildomain','$type'".');"';
10371: $hashref = $emailoptions;
10372: $defoption = 'any';
10373: $name = 'cancreate_emailoptions_'.$type;
10374: } elsif ($item eq 'username') {
10375: %choices = &Apache::lonlocal::texthash (
10376: all => 'Same as e-mail',
10377: first => 'Omit @domain',
10378: free => 'Free to choose',
10379: );
10380: @options = ('all','first','free');
10381: $hashref = $emailverified;
10382: $defoption = 'all';
10383: $name = 'cancreate_usernameoptions_'.$type;
10384: }
10385: foreach my $option (@options) {
10386: my $checked;
10387: if (ref($hashref) eq 'HASH') {
10388: if ($type eq '') {
10389: if (!exists($hashref->{'default'})) {
10390: if ($option eq $defoption) {
10391: $checked = ' checked="checked"';
10392: }
10393: } else {
10394: if ($hashref->{'default'} eq $option) {
10395: $checked = ' checked="checked"';
10396: }
1.303 raeburn 10397: }
10398: } else {
1.305 raeburn 10399: if (!exists($hashref->{$type})) {
10400: if ($option eq $defoption) {
10401: $checked = ' checked="checked"';
10402: }
10403: } else {
10404: if ($hashref->{$type} eq $option) {
10405: $checked = ' checked="checked"';
10406: }
1.303 raeburn 10407: }
10408: }
1.305 raeburn 10409: } elsif (($item eq 'email') && ($hascustom)) {
10410: if ($option eq 'custom') {
10411: $checked = ' checked="checked"';
10412: }
10413: } elsif ($option eq $defoption) {
10414: $checked = ' checked="checked"';
10415: }
10416: $output .= '<span class="LC_nobreak"><label>'.
10417: '<input type="radio" name="'.$name.'"'.
10418: $checked.' value="'.$option.'"'.$onclick.' />'.
10419: $choices{$option}.'</label></span><br />';
10420: if ($item eq 'email') {
10421: if ($option eq 'custom') {
10422: my $id = 'cancreate_emailrule_'.$type;
10423: my $display = 'none';
10424: if ($checked) {
10425: $display = 'inline';
1.303 raeburn 10426: }
1.305 raeburn 10427: my $numinrow = 2;
10428: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
10429: '<legend>'.&mt('Disallow').'</legend><table>'.
10430: &user_formats_row('email',$settings,$emailrules,
10431: $emailruleorder,$numinrow,'',$type);
10432: '</table></fieldset>';
10433: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
10434: my %text = &Apache::lonlocal::texthash (
10435: inst => 'must end:',
10436: noninst => 'cannot end:',
10437: );
10438: my $value;
10439: if (ref($emaildomain) eq 'HASH') {
10440: if (ref($emaildomain->{$type}) eq 'HASH') {
1.425 raeburn 10441: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 10442: }
10443: }
1.305 raeburn 10444: if ($value eq '') {
10445: $value = '@'.$intdom;
10446: }
10447: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
10448: my $display = 'none';
10449: if ($checked) {
10450: $display = 'inline';
10451: }
10452: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
10453: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
10454: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
10455: '</div>';
1.303 raeburn 10456: }
10457: }
10458: }
1.305 raeburn 10459: $output .= '</td>'."\n";
1.303 raeburn 10460: }
1.305 raeburn 10461: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 10462: return $output;
10463: }
10464:
1.165 raeburn 10465: sub captcha_choice {
1.305 raeburn 10466: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 10467: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
10468: $vertext,$currver);
1.165 raeburn 10469: my %lt = &captcha_phrases();
10470: $keyentry = 'hidden';
1.354 raeburn 10471: my $colspan=2;
1.165 raeburn 10472: if ($context eq 'cancreate') {
1.224 raeburn 10473: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 10474: } elsif ($context eq 'login') {
10475: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.354 raeburn 10476: } elsif ($context eq 'passwords') {
10477: $rowname = &mt('"Forgot Password" CAPTCHA validation');
10478: $colspan=1;
1.165 raeburn 10479: }
10480: if (ref($settings) eq 'HASH') {
10481: if ($settings->{'captcha'}) {
10482: $checked{$settings->{'captcha'}} = ' checked="checked"';
10483: } else {
10484: $checked{'original'} = ' checked="checked"';
10485: }
10486: if ($settings->{'captcha'} eq 'recaptcha') {
10487: $pubtext = $lt{'pub'};
10488: $privtext = $lt{'priv'};
10489: $keyentry = 'text';
1.269 raeburn 10490: $vertext = $lt{'ver'};
10491: $currver = $settings->{'recaptchaversion'};
10492: if ($currver ne '2') {
10493: $currver = 1;
10494: }
1.165 raeburn 10495: }
10496: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
10497: $currpub = $settings->{'recaptchakeys'}{'public'};
10498: $currpriv = $settings->{'recaptchakeys'}{'private'};
10499: }
10500: } else {
10501: $checked{'original'} = ' checked="checked"';
10502: }
1.305 raeburn 10503: my $css_class;
10504: if ($itemcount%2) {
10505: $css_class = 'LC_odd_row';
10506: }
10507: if ($customcss) {
10508: $css_class .= " $customcss";
10509: }
10510: $css_class =~ s/^\s+//;
10511: if ($css_class) {
10512: $css_class = ' class="'.$css_class.'"';
10513: }
10514: if ($rowstyle) {
10515: $css_class .= ' style="'.$rowstyle.'"';
10516: }
1.169 raeburn 10517: my $output = '<tr'.$css_class.'>'.
1.354 raeburn 10518: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165 raeburn 10519: '<table><tr><td>'."\n";
10520: foreach my $option ('original','recaptcha','notused') {
10521: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
10522: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
10523: $lt{$option}.'</label></span>';
10524: unless ($option eq 'notused') {
10525: $output .= (' 'x2)."\n";
10526: }
10527: }
10528: #
10529: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
10530: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 10531: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 10532: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 10533: #
1.165 raeburn 10534: $output .= '</td></tr>'."\n".
1.305 raeburn 10535: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 10536: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
10537: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
10538: $currpub.'" size="40" /></span><br />'."\n".
10539: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
10540: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 10541: $currpriv.'" size="40" /></span><br />'.
10542: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
10543: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
10544: $currver.'" size="3" /></span><br />'.
10545: '</td></tr></table>'."\n".
1.165 raeburn 10546: '</td></tr>';
10547: return $output;
10548: }
10549:
1.32 raeburn 10550: sub user_formats_row {
1.305 raeburn 10551: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 10552: my $output;
10553: my %text = (
10554: 'username' => 'new usernames',
10555: 'id' => 'IDs',
10556: );
1.409 raeburn 10557: unless (($type eq 'email') || ($type eq 'unamemap')) {
1.305 raeburn 10558: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
10559: $output = '<tr '.$css_class.'>'.
10560: '<td><span class="LC_nobreak">'.
10561: &mt("Format rules to check for $text{$type}: ").
10562: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 10563: }
1.27 raeburn 10564: my $rem;
10565: if (ref($ruleorder) eq 'ARRAY') {
10566: for (my $i=0; $i<@{$ruleorder}; $i++) {
10567: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
10568: my $rem = $i%($numinrow);
10569: if ($rem == 0) {
10570: if ($i > 0) {
10571: $output .= '</tr>';
10572: }
10573: $output .= '<tr>';
10574: }
10575: my $check = ' ';
1.39 raeburn 10576: if (ref($settings) eq 'HASH') {
10577: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
10578: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
10579: $check = ' checked="checked" ';
10580: }
1.305 raeburn 10581: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
10582: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
10583: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
10584: $check = ' checked="checked" ';
10585: }
10586: }
1.27 raeburn 10587: }
10588: }
1.305 raeburn 10589: my $name = $type.'_rule';
10590: if ($type eq 'email') {
10591: $name .= '_'.$status;
10592: }
1.27 raeburn 10593: $output .= '<td class="LC_left_item">'.
10594: '<span class="LC_nobreak"><label>'.
1.311 raeburn 10595: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 10596: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
10597: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
10598: }
10599: }
10600: $rem = @{$ruleorder}%($numinrow);
10601: }
1.305 raeburn 10602: my $colsleft;
10603: if ($rem) {
10604: $colsleft = $numinrow - $rem;
10605: }
1.27 raeburn 10606: if ($colsleft > 1 ) {
10607: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10608: ' </td>';
10609: } elsif ($colsleft == 1) {
10610: $output .= '<td class="LC_left_item"> </td>';
10611: }
1.409 raeburn 10612: $output .= '</tr>';
10613: unless (($type eq 'email') || ($type eq 'unamemap')) {
10614: $output .= '</table></td></tr>';
1.305 raeburn 10615: }
1.27 raeburn 10616: return $output;
10617: }
10618:
1.34 raeburn 10619: sub usercreation_types {
10620: my %lt = &Apache::lonlocal::texthash (
10621: author => 'When adding a co-author',
10622: course => 'When adding a user to a course',
1.100 raeburn 10623: requestcrs => 'When requesting a course',
1.34 raeburn 10624: any => 'Any',
10625: official => 'Institutional only ',
10626: unofficial => 'Non-institutional only',
10627: none => 'None',
10628: );
10629: return %lt;
1.48 raeburn 10630: }
1.34 raeburn 10631:
1.224 raeburn 10632: sub selfcreation_types {
10633: my %lt = &Apache::lonlocal::texthash (
10634: selfcreate => 'User creates own account',
10635: any => 'Any',
10636: official => 'Institutional only ',
10637: unofficial => 'Non-institutional only',
10638: email => 'E-mail address',
10639: login => 'Institutional Login',
10640: sso => 'SSO',
10641: );
10642: }
10643:
1.28 raeburn 10644: sub authtype_names {
10645: my %lt = &Apache::lonlocal::texthash(
10646: int => 'Internal',
10647: krb4 => 'Kerberos 4',
10648: krb5 => 'Kerberos 5',
10649: loc => 'Local',
1.325 raeburn 10650: lti => 'LTI',
1.28 raeburn 10651: );
10652: return %lt;
10653: }
10654:
10655: sub context_names {
10656: my %context_title = &Apache::lonlocal::texthash(
10657: author => 'Creating users when an Author',
10658: course => 'Creating users when in a course',
10659: domain => 'Creating users when a Domain Coordinator',
10660: );
10661: return %context_title;
10662: }
10663:
1.33 raeburn 10664: sub print_usermodification {
10665: my ($position,$dom,$settings,$rowtotal) = @_;
10666: my $numinrow = 4;
10667: my ($context,$datatable,$rowcount);
10668: if ($position eq 'top') {
10669: $rowcount = 0;
10670: $context = 'author';
10671: foreach my $role ('ca','aa') {
10672: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10673: $numinrow,$rowcount);
10674: $$rowtotal ++;
10675: $rowcount ++;
10676: }
1.230 raeburn 10677: } elsif ($position eq 'bottom') {
1.33 raeburn 10678: $context = 'course';
10679: $rowcount = 0;
10680: foreach my $role ('st','ep','ta','in','cr') {
10681: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10682: $numinrow,$rowcount);
10683: $$rowtotal ++;
10684: $rowcount ++;
10685: }
10686: }
10687: return $datatable;
10688: }
10689:
1.43 raeburn 10690: sub print_defaults {
1.236 raeburn 10691: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 10692: my $rownum = 0;
1.294 raeburn 10693: my ($datatable,$css_class,$titles);
10694: unless ($position eq 'bottom') {
10695: $titles = &defaults_titles($dom);
10696: }
1.236 raeburn 10697: if ($position eq 'top') {
10698: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
10699: 'datelocale_def','portal_def');
10700: my %defaults;
10701: if (ref($settings) eq 'HASH') {
10702: %defaults = %{$settings};
1.43 raeburn 10703: } else {
1.236 raeburn 10704: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10705: foreach my $item (@items) {
10706: $defaults{$item} = $domdefaults{$item};
10707: }
1.43 raeburn 10708: }
1.236 raeburn 10709: foreach my $item (@items) {
10710: if ($rownum%2) {
10711: $css_class = '';
10712: } else {
10713: $css_class = ' class="LC_odd_row" ';
10714: }
10715: $datatable .= '<tr'.$css_class.'>'.
10716: '<td><span class="LC_nobreak">'.$titles->{$item}.
10717: '</span></td><td class="LC_right_item" colspan="3">';
10718: if ($item eq 'auth_def') {
1.325 raeburn 10719: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 10720: my %shortauth = (
10721: internal => 'int',
10722: krb4 => 'krb4',
10723: krb5 => 'krb5',
1.325 raeburn 10724: localauth => 'loc',
10725: lti => 'lti',
1.236 raeburn 10726: );
10727: my %authnames = &authtype_names();
10728: foreach my $auth (@authtypes) {
10729: my $checked = ' ';
10730: if ($defaults{$item} eq $auth) {
10731: $checked = ' checked="checked" ';
10732: }
10733: $datatable .= '<label><input type="radio" name="'.$item.
10734: '" value="'.$auth.'"'.$checked.'/>'.
10735: $authnames{$shortauth{$auth}}.'</label> ';
10736: }
10737: } elsif ($item eq 'timezone_def') {
10738: my $includeempty = 1;
10739: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
10740: } elsif ($item eq 'datelocale_def') {
10741: my $includeempty = 1;
10742: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
10743: } elsif ($item eq 'lang_def') {
1.263 raeburn 10744: my $includeempty = 1;
10745: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.414 raeburn 10746: } elsif ($item eq 'portal_def') {
10747: $datatable .= '<input type="text" name="'.$item.'" value="'.
10748: $defaults{$item}.'" size="25" onkeyup="portalExtras(this);" />';
10749: my $portalsty = 'none';
10750: if ($defaults{$item}) {
10751: $portalsty = 'block';
10752: }
10753: foreach my $field ('email','web') {
10754: my $checkedoff = ' checked="checked"';
10755: my $checkedon;
10756: if ($defaults{$item.'_'.$field}) {
10757: $checkedon = $checkedoff;
10758: $checkedoff = '';
1.425 raeburn 10759: }
1.414 raeburn 10760: $datatable .= '<div id="'.$item.'_'.$field.'_div" style="display:'.$portalsty.'">'.
10761: '<span class="LC_nobreak">'.$titles->{$field}.' '.
10762: '<label><input type="radio" name="'.$item.'_'.$field.'" value="1"'.$checkedon.'/>'.&mt('Yes').'</label>'.
10763: (' 'x2).
10764: '<label><input type="radio" name="'.$item.'_'.$field.'" value="0"'.$checkedoff.'/>'.&mt('No').'</label>'.
10765: '</div>';
10766: }
1.236 raeburn 10767: } else {
1.414 raeburn 10768: $datatable .= '<input type="text" name="'.$item.'" value="'.$defaults{$item}.'" />';
1.43 raeburn 10769: }
1.236 raeburn 10770: $datatable .= '</td></tr>';
10771: $rownum ++;
10772: }
1.409 raeburn 10773: } elsif ($position eq 'middle') {
1.294 raeburn 10774: my %defaults;
10775: if (ref($settings) eq 'HASH') {
1.354 raeburn 10776: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
10777: my $maxnum = @{$settings->{'inststatusorder'}};
10778: for (my $i=0; $i<$maxnum; $i++) {
10779: $css_class = $rownum%2?' class="LC_odd_row"':'';
10780: my $item = $settings->{'inststatusorder'}->[$i];
10781: my $title = $settings->{'inststatustypes'}->{$item};
10782: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
10783: $datatable .= '<tr'.$css_class.'>'.
10784: '<td><span class="LC_nobreak">'.
10785: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
10786: for (my $k=0; $k<=$maxnum; $k++) {
10787: my $vpos = $k+1;
10788: my $selstr;
10789: if ($k == $i) {
10790: $selstr = ' selected="selected" ';
10791: }
10792: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10793: }
10794: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
10795: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
10796: &mt('delete').'</span></td>'.
1.380 raeburn 10797: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.354 raeburn 10798: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
10799: '</span></td></tr>';
10800: }
10801: $css_class = $rownum%2?' class="LC_odd_row"':'';
10802: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
10803: $datatable .= '<tr '.$css_class.'>'.
10804: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
10805: for (my $k=0; $k<=$maxnum; $k++) {
10806: my $vpos = $k+1;
10807: my $selstr;
10808: if ($k == $maxnum) {
10809: $selstr = ' selected="selected" ';
10810: }
10811: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10812: }
10813: $datatable .= '</select> '.&mt('Internal ID:').
10814: '<input type="text" size="10" name="addinststatus" value="" />'.
10815: ' '.&mt('(new)').
10816: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.380 raeburn 10817: &mt('Name displayed').':'.
1.354 raeburn 10818: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
10819: '</tr>'."\n";
10820: $rownum ++;
1.294 raeburn 10821: }
1.354 raeburn 10822: }
1.409 raeburn 10823: } else {
10824: my ($unamemaprules,$ruleorder) =
10825: &Apache::lonnet::inst_userrules($dom,'unamemap');
10826: $css_class = $rownum%2?' class="LC_odd_row"':'';
10827: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10828: my $numinrow = 2;
10829: $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
10830: &user_formats_row('unamemap',$settings,$unamemaprules,
10831: $ruleorder,$numinrow).
10832: '</table></td></tr>';
10833: }
10834: if ($datatable eq '') {
10835: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
10836: &mt('No rules set for domain in customized localenroll.pm').
10837: '</td></tr>';
10838: }
1.354 raeburn 10839: }
10840: $$rowtotal += $rownum;
1.43 raeburn 10841: return $datatable;
10842: }
10843:
1.168 raeburn 10844: sub get_languages_hash {
10845: my %langchoices;
10846: foreach my $id (&Apache::loncommon::languageids()) {
10847: my $code = &Apache::loncommon::supportedlanguagecode($id);
10848: if ($code ne '') {
10849: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
10850: }
10851: }
10852: return %langchoices;
10853: }
10854:
1.43 raeburn 10855: sub defaults_titles {
1.141 raeburn 10856: my ($dom) = @_;
1.43 raeburn 10857: my %titles = &Apache::lonlocal::texthash (
10858: 'auth_def' => 'Default authentication type',
10859: 'auth_arg_def' => 'Default authentication argument',
10860: 'lang_def' => 'Default language',
1.54 raeburn 10861: 'timezone_def' => 'Default timezone',
1.68 raeburn 10862: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 10863: 'portal_def' => 'Portal/Default URL',
1.414 raeburn 10864: 'email' => 'Email links use portal URL',
10865: 'web' => 'Public web links use portal URL',
1.294 raeburn 10866: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
10867: 'intauth_check' => 'Check bcrypt cost if authenticated',
10868: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 10869: );
1.141 raeburn 10870: if ($dom) {
10871: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
10872: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
10873: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
10874: $protocol = 'http' if ($protocol ne 'https');
10875: if ($uint_dom) {
10876: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
10877: $uint_dom);
10878: }
10879: }
1.43 raeburn 10880: return (\%titles);
10881: }
10882:
1.346 raeburn 10883: sub print_scantron {
10884: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
10885: if ($position eq 'top') {
10886: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
10887: } else {
10888: return &print_scantronconfig($dom,$settings,\$rowtotal);
10889: }
10890: }
10891:
10892: sub scantron_javascript {
10893: return <<"ENDSCRIPT";
10894:
10895: <script type="text/javascript">
10896: // <![CDATA[
10897:
10898: function toggleScantron(form) {
1.347 raeburn 10899: var csvfieldset = new Array();
1.346 raeburn 10900: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 10901: csvfieldset.push(document.getElementById('scantroncsv_cols'));
10902: }
10903: if (document.getElementById('scantroncsv_options')) {
10904: csvfieldset.push(document.getElementById('scantroncsv_options'));
10905: }
10906: if (csvfieldset.length) {
1.346 raeburn 10907: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 10908: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 10909: if (scantroncsv.checked) {
1.347 raeburn 10910: for (var i=0; i<csvfieldset.length; i++) {
10911: csvfieldset[i].style.display = 'block';
10912: }
1.346 raeburn 10913: } else {
1.347 raeburn 10914: for (var i=0; i<csvfieldset.length; i++) {
10915: csvfieldset[i].style.display = 'none';
10916: }
1.346 raeburn 10917: var csvselects = document.getElementsByClassName('scantronconfig_csv');
10918: if (csvselects.length) {
10919: for (var j=0; j<csvselects.length; j++) {
10920: csvselects[j].selectedIndex = 0;
10921: }
10922: }
10923: }
10924: }
10925: }
10926: return;
10927: }
10928: // ]]>
10929: </script>
10930:
10931: ENDSCRIPT
10932:
10933: }
10934:
1.46 raeburn 10935: sub print_scantronformat {
10936: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
10937: my $itemcount = 1;
1.60 raeburn 10938: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
10939: %confhash);
1.46 raeburn 10940: my $switchserver = &check_switchserver($dom,$confname);
10941: my %lt = &Apache::lonlocal::texthash (
1.95 www 10942: default => 'Default bubblesheet format file error',
10943: custom => 'Custom bubblesheet format file error',
1.46 raeburn 10944: );
10945: my %scantronfiles = (
10946: default => 'default.tab',
10947: custom => 'custom.tab',
10948: );
10949: foreach my $key (keys(%scantronfiles)) {
10950: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
10951: .$scantronfiles{$key};
10952: }
10953: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
10954: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
10955: if (!$switchserver) {
10956: my $servadm = $r->dir_config('lonAdmEMail');
10957: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
10958: if ($configuserok eq 'ok') {
10959: if ($author_ok eq 'ok') {
10960: my %legacyfile = (
1.346 raeburn 10961: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
10962: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 10963: );
10964: my %md5chk;
10965: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 10966: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
10967: chomp($md5chk{$type});
1.46 raeburn 10968: }
10969: if ($md5chk{'default'} ne $md5chk{'custom'}) {
10970: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 10971: ($scantronurls{$type},my $error) =
1.46 raeburn 10972: &legacy_scantronformat($r,$dom,$confname,
10973: $type,$legacyfile{$type},
10974: $scantronurls{$type},
10975: $scantronfiles{$type});
1.60 raeburn 10976: if ($error ne '') {
10977: $error{$type} = $error;
10978: }
10979: }
10980: if (keys(%error) == 0) {
10981: $is_custom = 1;
1.346 raeburn 10982: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 10983: $scantronurls{'custom'};
1.346 raeburn 10984: my $putresult =
1.60 raeburn 10985: &Apache::lonnet::put_dom('configuration',
10986: \%confhash,$dom);
10987: if ($putresult ne 'ok') {
1.346 raeburn 10988: $error{'custom'} =
1.60 raeburn 10989: '<span class="LC_error">'.
10990: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
10991: }
1.46 raeburn 10992: }
10993: } else {
1.60 raeburn 10994: ($scantronurls{'default'},my $error) =
1.46 raeburn 10995: &legacy_scantronformat($r,$dom,$confname,
10996: 'default',$legacyfile{'default'},
10997: $scantronurls{'default'},
10998: $scantronfiles{'default'});
1.60 raeburn 10999: if ($error eq '') {
11000: $confhash{'scantron'}{'scantronformat'} = '';
11001: my $putresult =
11002: &Apache::lonnet::put_dom('configuration',
11003: \%confhash,$dom);
11004: if ($putresult ne 'ok') {
11005: $error{'default'} =
11006: '<span class="LC_error">'.
11007: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
11008: }
11009: } else {
11010: $error{'default'} = $error;
11011: }
1.46 raeburn 11012: }
11013: }
11014: }
11015: } else {
1.95 www 11016: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 11017: }
11018: }
11019: if (ref($settings) eq 'HASH') {
11020: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
11021: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
11022: if ((!@info) || ($info[0] eq 'no_such_dir')) {
11023: $scantronurl = '';
11024: } else {
11025: $scantronurl = $settings->{'scantronformat'};
11026: }
11027: $is_custom = 1;
11028: } else {
11029: $scantronurl = $scantronurls{'default'};
11030: }
11031: } else {
1.60 raeburn 11032: if ($is_custom) {
11033: $scantronurl = $scantronurls{'custom'};
11034: } else {
11035: $scantronurl = $scantronurls{'default'};
11036: }
1.46 raeburn 11037: }
11038: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11039: $datatable .= '<tr'.$css_class.'>';
11040: if (!$is_custom) {
1.65 raeburn 11041: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
11042: '<span class="LC_nobreak">';
1.46 raeburn 11043: if ($scantronurl) {
1.199 raeburn 11044: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
11045: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 11046: } else {
11047: $datatable = &mt('File unavailable for display');
11048: }
1.65 raeburn 11049: $datatable .= '</span></td>';
1.60 raeburn 11050: if (keys(%error) == 0) {
1.306 raeburn 11051: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 11052: if (!$switchserver) {
11053: $datatable .= &mt('Upload:').'<br />';
11054: }
11055: } else {
11056: my $errorstr;
11057: foreach my $key (sort(keys(%error))) {
11058: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
11059: }
11060: $datatable .= '<td>'.$errorstr;
11061: }
1.46 raeburn 11062: } else {
11063: if (keys(%error) > 0) {
11064: my $errorstr;
11065: foreach my $key (sort(keys(%error))) {
11066: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
11067: }
1.60 raeburn 11068: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 11069: } elsif ($scantronurl) {
1.199 raeburn 11070: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
11071: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 11072: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 11073: $link.
11074: '<label><input type="checkbox" name="scantronformat_del"'.
11075: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 11076: '<td><span class="LC_nobreak"> '.
11077: &mt('Replace:').'</span><br />';
1.46 raeburn 11078: }
11079: }
11080: if (keys(%error) == 0) {
11081: if ($switchserver) {
11082: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
11083: } else {
1.65 raeburn 11084: $datatable .='<span class="LC_nobreak"> '.
11085: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 11086: }
11087: }
11088: $datatable .= '</td></tr>';
11089: $$rowtotal ++;
11090: return $datatable;
11091: }
11092:
11093: sub legacy_scantronformat {
11094: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
11095: my ($url,$error);
11096: my @statinfo = &Apache::lonnet::stat_file($newurl);
11097: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
1.421 raeburn 11098: my $modified = [];
1.46 raeburn 11099: (my $result,$url) =
1.421 raeburn 11100: &Apache::lonconfigsettings::publishlogo($r,'copy',$legacyfile,$dom,$confname,
11101: 'scantron','','',$newfile,$modified);
11102: if ($result eq 'ok') {
11103: &update_modify_urls($r,$modified);
11104: } else {
1.130 raeburn 11105: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 11106: }
11107: }
11108: return ($url,$error);
11109: }
1.43 raeburn 11110:
1.346 raeburn 11111: sub print_scantronconfig {
11112: my ($dom,$settings,$rowtotal) = @_;
11113: my $itemcount = 2;
11114: my $is_checked = ' checked="checked"';
1.347 raeburn 11115: my %optionson = (
11116: hdr => ' checked="checked"',
11117: pad => ' checked="checked"',
11118: rem => ' checked="checked"',
11119: );
11120: my %optionsoff = (
11121: hdr => '',
11122: pad => '',
11123: rem => '',
11124: );
1.346 raeburn 11125: my $currcsvsty = 'none';
1.347 raeburn 11126: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 11127: my @fields = &scantroncsv_fields();
11128: my %titles = &scantronconfig_titles();
11129: if (ref($settings) eq 'HASH') {
11130: if (ref($settings->{config}) eq 'HASH') {
11131: if ($settings->{config}->{dat}) {
11132: $checked{'dat'} = $is_checked;
11133: }
11134: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 11135: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
11136: %csvfields = %{$settings->{config}->{csv}->{fields}};
11137: if (keys(%csvfields) > 0) {
11138: $checked{'csv'} = $is_checked;
11139: $currcsvsty = 'block';
11140: }
11141: }
11142: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
11143: %csvoptions = %{$settings->{config}->{csv}->{options}};
11144: foreach my $option (keys(%optionson)) {
11145: unless ($csvoptions{$option}) {
11146: $optionsoff{$option} = $optionson{$option};
11147: $optionson{$option} = '';
11148: }
11149: }
1.346 raeburn 11150: }
11151: }
11152: } else {
11153: $checked{'dat'} = $is_checked;
11154: }
11155: } else {
11156: $checked{'dat'} = $is_checked;
11157: }
11158: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
11159: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11160: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
11161: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
11162: foreach my $item ('dat','csv') {
11163: my $id;
11164: if ($item eq 'csv') {
11165: $id = 'id="scantronconfcsv" ';
1.347 raeburn 11166: }
1.346 raeburn 11167: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
11168: $titles{$item}.'</label>'.(' 'x3);
11169: if ($item eq 'csv') {
11170: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
11171: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
11172: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
11173: foreach my $col (@fields) {
11174: my $selnone;
11175: if ($csvfields{$col} eq '') {
11176: $selnone = ' selected="selected"';
11177: }
11178: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
11179: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
11180: '<option value=""'.$selnone.'></option>';
11181: for (my $i=0; $i<20; $i++) {
11182: my $shown = $i+1;
11183: my $sel;
11184: unless ($selnone) {
11185: if (exists($csvfields{$col})) {
11186: if ($csvfields{$col} == $i) {
11187: $sel = ' selected="selected"';
11188: }
11189: }
11190: }
11191: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
11192: }
11193: $datatable .= '</select></td></tr>';
11194: }
1.347 raeburn 11195: $datatable .= '</table></fieldset>'.
11196: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
11197: '<legend>'.&mt('CSV Options').'</legend>';
11198: foreach my $option ('hdr','pad','rem') {
11199: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
11200: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
11201: &mt('Yes').'</label>'.(' 'x2)."\n".
11202: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
11203: }
11204: $datatable .= '</fieldset>';
1.346 raeburn 11205: $itemcount ++;
11206: }
11207: }
11208: $datatable .= '</td></tr>';
11209: $$rowtotal ++;
11210: return $datatable;
11211: }
11212:
11213: sub scantronconfig_titles {
11214: return &Apache::lonlocal::texthash(
11215: dat => 'Standard format (.dat)',
11216: csv => 'Comma separated values (.csv)',
1.347 raeburn 11217: hdr => 'Remove first line in file (contains column titles)',
11218: pad => 'Prepend 0s to PaperID',
1.348 raeburn 11219: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 11220: CODE => 'CODE',
11221: ID => 'Student ID',
11222: PaperID => 'Paper ID',
11223: FirstName => 'First Name',
11224: LastName => 'Last Name',
11225: FirstQuestion => 'First Question Response',
11226: Section => 'Section',
11227: );
11228: }
11229:
11230: sub scantroncsv_fields {
11231: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
11232: }
11233:
1.49 raeburn 11234: sub print_coursecategories {
1.57 raeburn 11235: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
11236: my $datatable;
11237: if ($position eq 'top') {
1.238 raeburn 11238: my (%checked);
11239: my @catitems = ('unauth','auth');
11240: my @cattypes = ('std','domonly','codesrch','none');
11241: $checked{'unauth'} = 'std';
11242: $checked{'auth'} = 'std';
11243: if (ref($settings) eq 'HASH') {
11244: foreach my $type (@cattypes) {
11245: if ($type eq $settings->{'unauth'}) {
11246: $checked{'unauth'} = $type;
11247: }
11248: if ($type eq $settings->{'auth'}) {
11249: $checked{'auth'} = $type;
11250: }
11251: }
11252: }
11253: my %lt = &Apache::lonlocal::texthash (
11254: unauth => 'Catalog type for unauthenticated users',
11255: auth => 'Catalog type for authenticated users',
11256: none => 'No catalog',
11257: std => 'Standard catalog',
11258: domonly => 'Domain-only catalog',
11259: codesrch => "Code search form",
11260: );
11261: my $itemcount = 0;
11262: foreach my $item (@catitems) {
11263: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11264: $datatable .= '<tr '.$css_class.'>'.
11265: '<td>'.$lt{$item}.'</td>'.
11266: '<td class="LC_right_item"><span class="LC_nobreak">';
11267: foreach my $type (@cattypes) {
11268: my $ischecked;
11269: if ($checked{$item} eq $type) {
11270: $ischecked=' checked="checked"';
11271: }
11272: $datatable .= '<label>'.
11273: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
11274: ' />'.$lt{$type}.'</label> ';
11275: }
1.327 raeburn 11276: $datatable .= '</span></td></tr>';
1.238 raeburn 11277: $itemcount ++;
11278: }
11279: $$rowtotal += $itemcount;
11280: } elsif ($position eq 'middle') {
1.57 raeburn 11281: my $toggle_cats_crs = ' ';
11282: my $toggle_cats_dom = ' checked="checked" ';
11283: my $can_cat_crs = ' ';
11284: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 11285: my $toggle_catscomm_comm = ' ';
11286: my $toggle_catscomm_dom = ' checked="checked" ';
11287: my $can_catcomm_comm = ' ';
11288: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 11289: my $toggle_catsplace_place = ' ';
11290: my $toggle_catsplace_dom = ' checked="checked" ';
11291: my $can_catplace_place = ' ';
11292: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 11293:
1.57 raeburn 11294: if (ref($settings) eq 'HASH') {
11295: if ($settings->{'togglecats'} eq 'crs') {
11296: $toggle_cats_crs = $toggle_cats_dom;
11297: $toggle_cats_dom = ' ';
11298: }
11299: if ($settings->{'categorize'} eq 'crs') {
11300: $can_cat_crs = $can_cat_dom;
11301: $can_cat_dom = ' ';
11302: }
1.120 raeburn 11303: if ($settings->{'togglecatscomm'} eq 'comm') {
11304: $toggle_catscomm_comm = $toggle_catscomm_dom;
11305: $toggle_catscomm_dom = ' ';
11306: }
11307: if ($settings->{'categorizecomm'} eq 'comm') {
11308: $can_catcomm_comm = $can_catcomm_dom;
11309: $can_catcomm_dom = ' ';
11310: }
1.272 raeburn 11311: if ($settings->{'togglecatsplace'} eq 'place') {
11312: $toggle_catsplace_place = $toggle_catsplace_dom;
11313: $toggle_catsplace_dom = ' ';
11314: }
11315: if ($settings->{'categorizeplace'} eq 'place') {
11316: $can_catplace_place = $can_catplace_dom;
11317: $can_catplace_dom = ' ';
11318: }
1.57 raeburn 11319: }
11320: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 11321: togglecats => 'Show/Hide a course in catalog',
11322: togglecatscomm => 'Show/Hide a community in catalog',
11323: togglecatsplace => 'Show/Hide a placement test in catalog',
11324: categorize => 'Assign a category to a course',
11325: categorizecomm => 'Assign a category to a community',
11326: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 11327: );
11328: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 11329: dom => 'Set in Domain',
11330: crs => 'Set in Course',
11331: comm => 'Set in Community',
11332: place => 'Set in Placement Test',
1.57 raeburn 11333: );
11334: $datatable = '<tr class="LC_odd_row">'.
11335: '<td>'.$title{'togglecats'}.'</td>'.
11336: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11337: '<input type="radio" name="togglecats"'.
11338: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11339: '<label><input type="radio" name="togglecats"'.
11340: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
11341: '</tr><tr>'.
11342: '<td>'.$title{'categorize'}.'</td>'.
11343: '<td class="LC_right_item"><span class="LC_nobreak">'.
11344: '<label><input type="radio" name="categorize"'.
11345: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11346: '<label><input type="radio" name="categorize"'.
11347: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 11348: '</tr><tr class="LC_odd_row">'.
11349: '<td>'.$title{'togglecatscomm'}.'</td>'.
11350: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11351: '<input type="radio" name="togglecatscomm"'.
11352: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11353: '<label><input type="radio" name="togglecatscomm"'.
11354: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
11355: '</tr><tr>'.
11356: '<td>'.$title{'categorizecomm'}.'</td>'.
11357: '<td class="LC_right_item"><span class="LC_nobreak">'.
11358: '<label><input type="radio" name="categorizecomm"'.
11359: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11360: '<label><input type="radio" name="categorizecomm"'.
11361: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 11362: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 11363: '<td>'.$title{'togglecatsplace'}.'</td>'.
11364: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11365: '<input type="radio" name="togglecatsplace"'.
11366: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11367: '<label><input type="radio" name="togglecatscomm"'.
11368: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
11369: '</tr><tr>'.
11370: '<td>'.$title{'categorizeplace'}.'</td>'.
11371: '<td class="LC_right_item"><span class="LC_nobreak">'.
11372: '<label><input type="radio" name="categorizeplace"'.
11373: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11374: '<label><input type="radio" name="categorizeplace"'.
11375: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 11376: '</tr>';
1.272 raeburn 11377: $$rowtotal += 6;
1.57 raeburn 11378: } else {
11379: my $css_class;
11380: my $itemcount = 1;
11381: my $cathash;
11382: if (ref($settings) eq 'HASH') {
11383: $cathash = $settings->{'cats'};
11384: }
11385: if (ref($cathash) eq 'HASH') {
11386: my (@cats,@trails,%allitems,%idx,@jsarray);
11387: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
11388: \%allitems,\%idx,\@jsarray);
11389: my $maxdepth = scalar(@cats);
11390: my $colattrib = '';
11391: if ($maxdepth > 2) {
11392: $colattrib = ' colspan="2" ';
11393: }
11394: my @path;
11395: if (@cats > 0) {
11396: if (ref($cats[0]) eq 'ARRAY') {
11397: my $numtop = @{$cats[0]};
11398: my $maxnum = $numtop;
1.120 raeburn 11399: my %default_names = (
11400: instcode => &mt('Official courses'),
11401: communities => &mt('Communities'),
1.272 raeburn 11402: placement => &mt('Placement Tests'),
1.120 raeburn 11403: );
11404:
11405: if ((!grep(/^instcode$/,@{$cats[0]})) ||
11406: ($cathash->{'instcode::0'} eq '') ||
11407: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 11408: ($cathash->{'communities::0'} eq '') ||
11409: (!grep(/^placement$/,@{$cats[0]})) ||
11410: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 11411: $maxnum ++;
11412: }
11413: my $lastidx;
11414: for (my $i=0; $i<$numtop; $i++) {
11415: my $parent = $cats[0][$i];
11416: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11417: my $item = &escape($parent).'::0';
11418: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
11419: $lastidx = $idx{$item};
11420: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
11421: .'<select name="'.$item.'"'.$chgstr.'>';
11422: for (my $k=0; $k<=$maxnum; $k++) {
11423: my $vpos = $k+1;
11424: my $selstr;
11425: if ($k == $i) {
11426: $selstr = ' selected="selected" ';
11427: }
11428: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11429: }
1.214 raeburn 11430: $datatable .= '</select></span></td><td>';
1.272 raeburn 11431: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 11432: $datatable .= '<span class="LC_nobreak">'
11433: .$default_names{$parent}.'</span>';
11434: if ($parent eq 'instcode') {
11435: $datatable .= '<br /><span class="LC_nobreak">('
11436: .&mt('with institutional codes')
11437: .')</span></td><td'.$colattrib.'>';
11438: } else {
11439: $datatable .= '<table><tr><td>';
11440: }
11441: $datatable .= '<span class="LC_nobreak">'
11442: .'<label><input type="radio" name="'
11443: .$parent.'" value="1" checked="checked" />'
11444: .&mt('Display').'</label>';
11445: if ($parent eq 'instcode') {
11446: $datatable .= ' ';
11447: } else {
11448: $datatable .= '</span></td></tr><tr><td>'
11449: .'<span class="LC_nobreak">';
11450: }
11451: $datatable .= '<label><input type="radio" name="'
11452: .$parent.'" value="0" />'
11453: .&mt('Do not display').'</label></span>';
1.272 raeburn 11454: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 11455: $datatable .= '</td></tr></table>';
11456: }
11457: $datatable .= '</td>';
1.57 raeburn 11458: } else {
11459: $datatable .= $parent
1.214 raeburn 11460: .' <span class="LC_nobreak"><label>'
11461: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 11462: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
11463: }
11464: my $depth = 1;
11465: push(@path,$parent);
11466: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
11467: pop(@path);
11468: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
11469: $itemcount ++;
11470: }
1.48 raeburn 11471: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 11472: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
11473: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 11474: for (my $k=0; $k<=$maxnum; $k++) {
11475: my $vpos = $k+1;
11476: my $selstr;
1.57 raeburn 11477: if ($k == $numtop) {
1.48 raeburn 11478: $selstr = ' selected="selected" ';
11479: }
11480: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11481: }
1.59 bisitz 11482: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 11483: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
11484: .'</tr>'."\n";
1.48 raeburn 11485: $itemcount ++;
1.272 raeburn 11486: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11487: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
11488: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11489: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
11490: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
11491: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
11492: for (my $k=0; $k<=$maxnum; $k++) {
11493: my $vpos = $k+1;
11494: my $selstr;
11495: if ($k == $maxnum) {
11496: $selstr = ' selected="selected" ';
11497: }
11498: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 11499: }
1.120 raeburn 11500: $datatable .= '</select></span></td>'.
11501: '<td><span class="LC_nobreak">'.
11502: $default_names{$default}.'</span>';
11503: if ($default eq 'instcode') {
11504: $datatable .= '<br /><span class="LC_nobreak">('
11505: .&mt('with institutional codes').')</span>';
11506: }
11507: $datatable .= '</td>'
11508: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
11509: .&mt('Display').'</label> '
11510: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
11511: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 11512: }
11513: }
11514: }
1.57 raeburn 11515: } else {
11516: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 11517: }
11518: } else {
1.327 raeburn 11519: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 11520: .&initialize_categories($itemcount);
1.48 raeburn 11521: }
1.57 raeburn 11522: $$rowtotal += $itemcount;
1.48 raeburn 11523: }
11524: return $datatable;
11525: }
11526:
1.69 raeburn 11527: sub print_serverstatuses {
11528: my ($dom,$settings,$rowtotal) = @_;
11529: my $datatable;
11530: my @pages = &serverstatus_pages();
11531: my (%namedaccess,%machineaccess);
11532: foreach my $type (@pages) {
11533: $namedaccess{$type} = '';
11534: $machineaccess{$type}= '';
11535: }
11536: if (ref($settings) eq 'HASH') {
11537: foreach my $type (@pages) {
11538: if (exists($settings->{$type})) {
11539: if (ref($settings->{$type}) eq 'HASH') {
11540: foreach my $key (keys(%{$settings->{$type}})) {
11541: if ($key eq 'namedusers') {
11542: $namedaccess{$type} = $settings->{$type}->{$key};
11543: } elsif ($key eq 'machines') {
11544: $machineaccess{$type} = $settings->{$type}->{$key};
11545: }
11546: }
11547: }
11548: }
11549: }
11550: }
1.81 raeburn 11551: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11552: my $rownum = 0;
11553: my $css_class;
11554: foreach my $type (@pages) {
11555: $rownum ++;
11556: $css_class = $rownum%2?' class="LC_odd_row"':'';
11557: $datatable .= '<tr'.$css_class.'>'.
11558: '<td><span class="LC_nobreak">'.
11559: $titles->{$type}.'</span></td>'.
11560: '<td class="LC_left_item">'.
11561: '<input type="text" name="'.$type.'_namedusers" '.
11562: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
11563: '<td class="LC_right_item">'.
11564: '<span class="LC_nobreak">'.
11565: '<input type="text" name="'.$type.'_machines" '.
11566: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 11567: '</span></td></tr>'."\n";
1.69 raeburn 11568: }
11569: $$rowtotal += $rownum;
11570: return $datatable;
11571: }
11572:
11573: sub serverstatus_pages {
11574: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 11575: 'checksums','clusterstatus','certstatus','metadata_keywords',
11576: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
11577: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 11578: }
11579:
1.236 raeburn 11580: sub defaults_javascript {
11581: my ($settings) = @_;
1.354 raeburn 11582: return unless (ref($settings) eq 'HASH');
1.414 raeburn 11583: my $portal_js = <<"ENDPORTAL";
11584:
11585: function portalExtras(caller) {
11586: var x = caller.value;
11587: var y = new Array('email','web');
1.425 raeburn 11588: for (var i=0; i<y.length; i++) {
1.414 raeburn 11589: if (document.getElementById('portal_def_'+y[i]+'_div')) {
11590: var z = document.getElementById('portal_def_'+y[i]+'_div');
11591: if (x.length > 0) {
11592: z.style.display = 'block';
11593: } else {
11594: z.style.display = 'none';
11595: }
11596: }
11597: }
11598: }
11599: ENDPORTAL
1.236 raeburn 11600: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
11601: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
11602: if ($maxnum eq '') {
11603: $maxnum = 0;
11604: }
11605: $maxnum ++;
1.249 raeburn 11606: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 11607: return <<"ENDSCRIPT";
11608: <script type="text/javascript">
11609: // <![CDATA[
11610: function reorderTypes(form,caller) {
11611: var changedVal;
11612: $jstext
11613: var newpos = 'addinststatus_pos';
11614: var current = new Array;
11615: var maxh = $maxnum;
11616: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11617: var oldVal;
11618: if (caller == newpos) {
11619: changedVal = newitemVal;
11620: } else {
11621: var curritem = 'inststatus_pos_'+caller;
11622: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
11623: current[newitemVal] = newpos;
11624: }
11625: for (var i=0; i<inststatuses.length; i++) {
11626: if (inststatuses[i] != caller) {
11627: var elementName = 'inststatus_pos_'+inststatuses[i];
11628: if (form.elements[elementName]) {
11629: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11630: current[currVal] = elementName;
11631: }
11632: }
11633: }
11634: for (var j=0; j<maxh; j++) {
11635: if (current[j] == undefined) {
11636: oldVal = j;
11637: }
11638: }
11639: if (oldVal < changedVal) {
11640: for (var k=oldVal+1; k<=changedVal ; k++) {
11641: var elementName = current[k];
11642: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11643: }
11644: } else {
11645: for (var k=changedVal; k<oldVal; k++) {
11646: var elementName = current[k];
11647: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11648: }
11649: }
11650: return;
11651: }
11652:
1.414 raeburn 11653: $portal_js
11654:
11655: // ]]>
11656: </script>
11657:
11658: ENDSCRIPT
11659: } else {
11660: return <<"ENDSCRIPT";
11661: <script type="text/javascript">
11662: // <![CDATA[
11663: $portal_js
1.236 raeburn 11664: // ]]>
11665: </script>
11666:
11667: ENDSCRIPT
11668: }
1.354 raeburn 11669: return;
11670: }
11671:
11672: sub passwords_javascript {
1.405 raeburn 11673: my ($prefix) = @_;
11674: my %intalert;
11675: if ($prefix eq 'passwords') {
11676: %intalert = &Apache::lonlocal::texthash (
11677: 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.',
11678: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
11679: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
11680: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
11681: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
11682: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
11683: );
1.421 raeburn 11684: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 11685: %intalert = &Apache::lonlocal::texthash (
11686: passmin => 'Warning: minimum secret length must be a positive integer greater than 6.',
11687: passmax => 'Warning: maximum secret length must be a positive integer (or blank).',
11688: );
11689: }
1.365 raeburn 11690: &js_escape(\%intalert);
11691: my $defmin = $Apache::lonnet::passwdmin;
1.425 raeburn 11692: my $intauthjs;
1.405 raeburn 11693: if ($prefix eq 'passwords') { $intauthjs = <<"ENDSCRIPT";
1.354 raeburn 11694:
11695: function warnIntAuth(field) {
11696: if (field.name == 'intauth_check') {
11697: if (field.value == '2') {
1.365 raeburn 11698: alert('$intalert{authcheck}');
1.354 raeburn 11699: }
11700: }
11701: if (field.name == 'intauth_cost') {
11702: field.value.replace(/\s/g,'');
11703: if (field.value != '') {
11704: var regexdigit=/^\\d+\$/;
11705: if (!regexdigit.test(field.value)) {
1.365 raeburn 11706: alert('$intalert{authcost}');
11707: }
11708: }
11709: }
11710: return;
11711: }
11712:
1.405 raeburn 11713: ENDSCRIPT
11714:
11715: }
11716:
11717: $intauthjs .= <<"ENDSCRIPT";
11718:
11719: function warnInt$prefix(field) {
1.365 raeburn 11720: field.value.replace(/^\s+/,'');
11721: field.value.replace(/\s+\$/,'');
11722: var regexdigit=/^\\d+\$/;
1.408 raeburn 11723: if (field.name == '${prefix}_min') {
1.365 raeburn 11724: if (field.value == '') {
11725: alert('$intalert{passmin}');
11726: field.value = '$defmin';
11727: } else {
11728: if (!regexdigit.test(field.value)) {
11729: alert('$intalert{passmin}');
11730: field.value = '$defmin';
11731: }
1.366 raeburn 11732: var minval = parseInt(field.value,10);
1.365 raeburn 11733: if (minval < $defmin) {
11734: alert('$intalert{passmin}');
11735: field.value = '$defmin';
11736: }
11737: }
11738: } else {
11739: if (field.value == '0') {
11740: field.value = '';
11741: }
11742: if (field.value != '') {
1.408 raeburn 11743: if (field.name == '${prefix}_expire') {
1.365 raeburn 11744: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
11745: if (!regexpposnum.test(field.value)) {
11746: alert('$intalert{passexp}');
11747: field.value = '';
11748: } else {
11749: var expval = parseFloat(field.value);
11750: if (expval == 0) {
11751: alert('$intalert{passexp}');
11752: field.value = '';
11753: }
11754: }
11755: } else {
11756: if (!regexdigit.test(field.value)) {
1.408 raeburn 11757: if (field.name == '${prefix}_max') {
1.365 raeburn 11758: alert('$intalert{passmax}');
11759: } else {
1.408 raeburn 11760: if (field.name == '${prefix}_numsaved') {
1.365 raeburn 11761: alert('$intalert{passnum}');
11762: }
11763: }
1.370 raeburn 11764: field.value = '';
1.365 raeburn 11765: }
1.354 raeburn 11766: }
11767: }
11768: }
11769: return;
11770: }
11771:
11772: ENDSCRIPT
11773: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 11774: }
11775:
1.49 raeburn 11776: sub coursecategories_javascript {
11777: my ($settings) = @_;
1.57 raeburn 11778: my ($output,$jstext,$cathash);
1.49 raeburn 11779: if (ref($settings) eq 'HASH') {
1.57 raeburn 11780: $cathash = $settings->{'cats'};
11781: }
11782: if (ref($cathash) eq 'HASH') {
1.49 raeburn 11783: my (@cats,@jsarray,%idx);
1.57 raeburn 11784: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 11785: if (@jsarray > 0) {
11786: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
11787: for (my $i=0; $i<@jsarray; $i++) {
11788: if (ref($jsarray[$i]) eq 'ARRAY') {
11789: my $catstr = join('","',@{$jsarray[$i]});
11790: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
11791: }
11792: }
11793: }
11794: } else {
11795: $jstext = ' var categories = Array(1);'."\n".
11796: ' categories[0] = Array("instcode_pos");'."\n";
11797: }
1.237 bisitz 11798: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
11799: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 11800: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 11801: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
11802: &js_escape(\$instcode_reserved);
11803: &js_escape(\$communities_reserved);
1.272 raeburn 11804: &js_escape(\$placement_reserved);
1.265 damieng 11805: &js_escape(\$choose_again);
1.49 raeburn 11806: $output = <<"ENDSCRIPT";
11807: <script type="text/javascript">
1.109 raeburn 11808: // <![CDATA[
1.49 raeburn 11809: function reorderCats(form,parent,item,idx) {
11810: var changedVal;
11811: $jstext
11812: var newpos = 'addcategory_pos';
11813: if (parent == '') {
11814: var has_instcode = 0;
11815: var maxtop = categories[idx].length;
11816: for (var j=0; j<maxtop; j++) {
11817: if (categories[idx][j] == 'instcode::0') {
11818: has_instcode == 1;
11819: }
11820: }
11821: if (has_instcode == 0) {
11822: categories[idx][maxtop] = 'instcode_pos';
11823: }
11824: } else {
11825: newpos += '_'+parent;
11826: }
11827: var maxh = 1 + categories[idx].length;
11828: var current = new Array;
11829: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11830: if (item == newpos) {
11831: changedVal = newitemVal;
11832: } else {
11833: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
11834: current[newitemVal] = newpos;
11835: }
11836: for (var i=0; i<categories[idx].length; i++) {
11837: var elementName = categories[idx][i];
11838: if (elementName != item) {
11839: if (form.elements[elementName]) {
11840: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11841: current[currVal] = elementName;
11842: }
11843: }
11844: }
11845: var oldVal;
11846: for (var j=0; j<maxh; j++) {
11847: if (current[j] == undefined) {
11848: oldVal = j;
11849: }
11850: }
11851: if (oldVal < changedVal) {
11852: for (var k=oldVal+1; k<=changedVal ; k++) {
11853: var elementName = current[k];
11854: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11855: }
11856: } else {
11857: for (var k=changedVal; k<oldVal; k++) {
11858: var elementName = current[k];
11859: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11860: }
11861: }
11862: return;
11863: }
1.120 raeburn 11864:
11865: function categoryCheck(form) {
11866: if (form.elements['addcategory_name'].value == 'instcode') {
11867: alert('$instcode_reserved\\n$choose_again');
11868: return false;
11869: }
11870: if (form.elements['addcategory_name'].value == 'communities') {
11871: alert('$communities_reserved\\n$choose_again');
11872: return false;
11873: }
1.272 raeburn 11874: if (form.elements['addcategory_name'].value == 'placement') {
11875: alert('$placement_reserved\\n$choose_again');
11876: return false;
11877: }
1.120 raeburn 11878: return true;
11879: }
11880:
1.109 raeburn 11881: // ]]>
1.49 raeburn 11882: </script>
11883:
11884: ENDSCRIPT
11885: return $output;
11886: }
11887:
1.48 raeburn 11888: sub initialize_categories {
11889: my ($itemcount) = @_;
1.120 raeburn 11890: my ($datatable,$css_class,$chgstr);
1.380 raeburn 11891: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 11892: instcode => 'Official courses (with institutional codes)',
11893: communities => 'Communities',
1.272 raeburn 11894: placement => 'Placement Tests',
1.120 raeburn 11895: );
1.328 raeburn 11896: my %selnum = (
11897: instcode => '0',
11898: communities => '1',
11899: placement => '2',
11900: );
11901: my %selected;
1.272 raeburn 11902: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11903: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 11904: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 11905: map { $selected{$selnum{$_}} = '' } keys(%selnum);
11906: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 11907: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 11908: .'<select name="'.$default.'_pos"'.$chgstr.'>'
11909: .'<option value="0"'.$selected{'0'}.'>1</option>'
11910: .'<option value="1"'.$selected{'1'}.'>2</option>'
11911: .'<option value="2"'.$selected{'2'}.'>3</option>'
11912: .'<option value="3">4</option></select> '
1.120 raeburn 11913: .$default_names{$default}
11914: .'</span></td><td><span class="LC_nobreak">'
11915: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
11916: .&mt('Display').'</label> <label>'
11917: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 11918: .'</label></span></td></tr>';
1.120 raeburn 11919: $itemcount ++;
11920: }
1.48 raeburn 11921: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 11922: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 11923: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 11924: .'<select name="addcategory_pos"'.$chgstr.'>'
11925: .'<option value="0">1</option>'
11926: .'<option value="1">2</option>'
1.328 raeburn 11927: .'<option value="2">3</option>'
11928: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 11929: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
11930: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
11931: .'</td></tr>';
1.48 raeburn 11932: return $datatable;
11933: }
11934:
11935: sub build_category_rows {
1.49 raeburn 11936: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
11937: my ($text,$name,$item,$chgstr);
1.48 raeburn 11938: if (ref($cats) eq 'ARRAY') {
11939: my $maxdepth = scalar(@{$cats});
11940: if (ref($cats->[$depth]) eq 'HASH') {
11941: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
11942: my $numchildren = @{$cats->[$depth]{$parent}};
11943: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 11944: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 11945: my ($idxnum,$parent_name,$parent_item);
11946: my $higher = $depth - 1;
11947: if ($higher == 0) {
11948: $parent_name = &escape($parent).'::'.$higher;
11949: } else {
11950: if (ref($path) eq 'ARRAY') {
11951: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
11952: }
11953: }
11954: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 11955: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 11956: if ($j < $numchildren) {
1.48 raeburn 11957: $name = $cats->[$depth]{$parent}[$j];
11958: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 11959: $idxnum = $idx->{$item};
11960: } else {
11961: $name = $parent_name;
11962: $item = $parent_item;
1.48 raeburn 11963: }
1.49 raeburn 11964: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
11965: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 11966: for (my $i=0; $i<=$numchildren; $i++) {
11967: my $vpos = $i+1;
11968: my $selstr;
11969: if ($j == $i) {
11970: $selstr = ' selected="selected" ';
11971: }
11972: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
11973: }
11974: $text .= '</select> ';
11975: if ($j < $numchildren) {
11976: my $deeper = $depth+1;
11977: $text .= $name.' '
11978: .'<label><input type="checkbox" name="deletecategory" value="'
11979: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
11980: if(ref($path) eq 'ARRAY') {
11981: push(@{$path},$name);
1.49 raeburn 11982: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 11983: pop(@{$path});
11984: }
11985: } else {
1.330 raeburn 11986: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 11987: if ($j == $numchildren) {
11988: $text .= $name;
11989: } else {
11990: $text .= $item;
11991: }
11992: $text .= '" value="" />';
11993: }
11994: $text .= '</td></tr>';
11995: }
11996: $text .= '</table></td>';
11997: } else {
11998: my $higher = $depth-1;
11999: if ($higher == 0) {
12000: $name = &escape($parent).'::'.$higher;
12001: } else {
12002: if (ref($path) eq 'ARRAY') {
12003: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
12004: }
12005: }
12006: my $colspan;
12007: if ($parent ne 'instcode') {
12008: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 12009: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 12010: }
12011: }
12012: }
12013: }
12014: return $text;
12015: }
12016:
1.33 raeburn 12017: sub modifiable_userdata_row {
1.305 raeburn 12018: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357 raeburn 12019: $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228 raeburn 12020: my ($role,$rolename,$statustype);
12021: $role = $item;
1.224 raeburn 12022: if ($context eq 'cancreate') {
1.305 raeburn 12023: if ($item =~ /^(emailusername)_(.+)$/) {
12024: $role = $1;
12025: $statustype = $2;
1.228 raeburn 12026: if (ref($usertypes) eq 'HASH') {
12027: if ($usertypes->{$statustype}) {
12028: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
12029: } else {
12030: $rolename = &mt('Data provided by user');
12031: }
12032: }
1.224 raeburn 12033: }
12034: } elsif ($context eq 'selfcreate') {
1.63 raeburn 12035: if (ref($usertypes) eq 'HASH') {
12036: $rolename = $usertypes->{$role};
12037: } else {
12038: $rolename = $role;
12039: }
1.325 raeburn 12040: } elsif ($context eq 'lti') {
12041: $rolename = &mt('Institutional data used (if available)');
1.357 raeburn 12042: } elsif ($context eq 'privacy') {
12043: $rolename = $itemdesc;
1.33 raeburn 12044: } else {
1.63 raeburn 12045: if ($role eq 'cr') {
12046: $rolename = &mt('Custom role');
12047: } else {
12048: $rolename = &Apache::lonnet::plaintext($role);
12049: }
1.33 raeburn 12050: }
1.224 raeburn 12051: my (@fields,%fieldtitles);
12052: if (ref($fieldsref) eq 'ARRAY') {
12053: @fields = @{$fieldsref};
12054: } else {
12055: @fields = ('lastname','firstname','middlename','generation',
12056: 'permanentemail','id');
12057: }
12058: if ((ref($titlesref) eq 'HASH')) {
12059: %fieldtitles = %{$titlesref};
12060: } else {
12061: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12062: }
1.33 raeburn 12063: my $output;
1.305 raeburn 12064: my $css_class;
12065: if ($rowcount%2) {
12066: $css_class = 'LC_odd_row';
12067: }
12068: if ($customcss) {
12069: $css_class .= " $customcss";
12070: }
12071: $css_class =~ s/^\s+//;
12072: if ($css_class) {
12073: $css_class = ' class="'.$css_class.'"';
12074: }
12075: if ($rowstyle) {
12076: $css_class .= ' style="'.$rowstyle.'"';
12077: }
12078: if ($rowid) {
12079: $rowid = ' id="'.$rowid.'"';
12080: }
12081: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 12082: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
12083: '<td class="LC_left_item" colspan="2"><table>';
12084: my $rem;
12085: my %checks;
12086: if (ref($settings) eq 'HASH') {
1.325 raeburn 12087: my $hashref;
12088: if ($context eq 'lti') {
12089: if (ref($settings) eq 'HASH') {
12090: $hashref = $settings->{'instdata'};
12091: }
1.357 raeburn 12092: } elsif ($context eq 'privacy') {
12093: my ($key,$inner) = split(/_/,$role);
12094: if (ref($settings) eq 'HASH') {
12095: if (ref($settings->{$key}) eq 'HASH') {
12096: $hashref = $settings->{$key}->{$inner};
12097: }
12098: }
1.325 raeburn 12099: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 12100: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 12101: $hashref = $settings->{'lti_instdata'};
12102: }
12103: if ($role eq 'emailusername') {
12104: if ($statustype) {
12105: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
12106: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 12107: }
1.325 raeburn 12108: }
12109: }
12110: }
1.425 raeburn 12111: if (ref($hashref) eq 'HASH') {
1.325 raeburn 12112: foreach my $field (@fields) {
12113: if ($hashref->{$field}) {
12114: if ($role eq 'emailusername') {
12115: $checks{$field} = $hashref->{$field};
12116: } else {
12117: $checks{$field} = ' checked="checked" ';
1.33 raeburn 12118: }
12119: }
12120: }
12121: }
12122: }
1.305 raeburn 12123: my $total = scalar(@fields);
12124: for (my $i=0; $i<$total; $i++) {
12125: $rem = $i%($numinrow);
1.33 raeburn 12126: if ($rem == 0) {
12127: if ($i > 0) {
12128: $output .= '</tr>';
12129: }
12130: $output .= '<tr>';
12131: }
12132: my $check = ' ';
1.228 raeburn 12133: unless ($role eq 'emailusername') {
12134: if (exists($checks{$fields[$i]})) {
1.354 raeburn 12135: $check = $checks{$fields[$i]};
1.357 raeburn 12136: } elsif ($context eq 'privacy') {
12137: if ($role =~ /^priv_(domain|course)$/) {
12138: if (ref($settings) ne 'HASH') {
12139: $check = ' checked="checked" ';
12140: }
12141: } elsif ($role =~ /^priv_(author|community)$/) {
12142: if (ref($settings) ne 'HASH') {
12143: unless ($fields[$i] eq 'id') {
12144: $check = ' checked="checked" ';
12145: }
12146: }
12147: } elsif ($role =~ /^(unpriv|othdom)_/) {
12148: if (ref($settings) ne 'HASH') {
12149: if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
12150: $check = ' checked="checked" ';
12151: }
12152: }
12153: }
1.325 raeburn 12154: } elsif ($context ne 'lti') {
1.228 raeburn 12155: if ($role eq 'st') {
12156: if (ref($settings) ne 'HASH') {
12157: $check = ' checked="checked" ';
12158: }
1.33 raeburn 12159: }
12160: }
12161: }
12162: $output .= '<td class="LC_left_item">'.
1.228 raeburn 12163: '<span class="LC_nobreak">';
1.325 raeburn 12164: my $prefix = 'canmodify';
1.228 raeburn 12165: if ($role eq 'emailusername') {
12166: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
12167: $checks{$fields[$i]} = 'omit';
12168: }
12169: foreach my $option ('required','optional','omit') {
12170: my $checked='';
12171: if ($checks{$fields[$i]} eq $option) {
12172: $checked='checked="checked" ';
12173: }
12174: $output .= '<label>'.
1.325 raeburn 12175: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 12176: &mt($option).'</label>'.(' ' x2);
12177: }
12178: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
12179: } else {
1.325 raeburn 12180: if ($context eq 'lti') {
12181: $prefix = 'lti';
1.357 raeburn 12182: } elsif ($context eq 'privacy') {
12183: $prefix = 'privacy';
1.325 raeburn 12184: }
1.228 raeburn 12185: $output .= '<label>'.
1.325 raeburn 12186: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 12187: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
12188: '</label>';
12189: }
12190: $output .= '</span></td>';
1.33 raeburn 12191: }
1.305 raeburn 12192: $rem = $total%$numinrow;
12193: my $colsleft;
12194: if ($rem) {
12195: $colsleft = $numinrow - $rem;
12196: }
12197: if ($colsleft > 1) {
1.33 raeburn 12198: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
12199: ' </td>';
12200: } elsif ($colsleft == 1) {
12201: $output .= '<td class="LC_left_item"> </td>';
12202: }
12203: $output .= '</tr></table></td></tr>';
12204: return $output;
12205: }
1.28 raeburn 12206:
1.93 raeburn 12207: sub insttypes_row {
1.305 raeburn 12208: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
12209: $customcss,$rowstyle) = @_;
1.93 raeburn 12210: my %lt = &Apache::lonlocal::texthash (
1.429 raeburn 12211: cansearch => 'Users allowed to search',
1.93 raeburn 12212: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.429 raeburn 12213: lockablenames => 'User preference to lock name',
12214: selfassign => 'Self-reportable affiliations',
12215: overrides => "Override domain's helpdesk settings based on requester's affiliation",
12216: webdav => 'WebDAV access available',
12217: authorquota => 'Authoring Space quota (MB)',
1.93 raeburn 12218: );
1.429 raeburn 12219: my ($showdom,$defaultquota);
1.93 raeburn 12220: if ($context eq 'cansearch') {
12221: $showdom = ' ('.$dom.')';
1.429 raeburn 12222: } elsif ($context eq 'authorquota') {
12223: $defaultquota = 500;
1.93 raeburn 12224: }
1.165 raeburn 12225: my $class = 'LC_left_item';
12226: if ($context eq 'statustocreate') {
12227: $class = 'LC_right_item';
12228: }
1.305 raeburn 12229: my $css_class;
12230: if ($$rowtotal%2) {
12231: $css_class = 'LC_odd_row';
12232: }
12233: if ($customcss) {
12234: $css_class .= ' '.$customcss;
12235: }
12236: $css_class =~ s/^\s+//;
12237: if ($css_class) {
12238: $css_class = ' class="'.$css_class.'"';
12239: }
12240: if ($rowstyle) {
12241: $css_class .= ' style="'.$rowstyle.'"';
12242: }
12243: if ($onclick) {
12244: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 12245: }
12246: my $output = '<tr'.$css_class.'>'.
12247: '<td>'.$lt{$context}.$showdom.
12248: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 12249: my $rem;
12250: if (ref($types) eq 'ARRAY') {
12251: for (my $i=0; $i<@{$types}; $i++) {
12252: if (defined($usertypes->{$types->[$i]})) {
12253: my $rem = $i%($numinrow);
12254: if ($rem == 0) {
12255: if ($i > 0) {
12256: $output .= '</tr>';
12257: }
12258: $output .= '<tr>';
1.23 raeburn 12259: }
1.429 raeburn 12260: if ($context eq 'authorquota') {
12261: my $currquota;
12262: if ($settings->{$context}->{$types->[$i]} =~ /^\d+$/) {
12263: $currquota = $settings->{$context}->{$types->[$i]};
12264: } else {
12265: $currquota = $defaultquota;
12266: }
12267: $output .= '<td class="LC_left_item">'."\n".
12268: '<label><span class="LC_nobreak">'."\n".
12269: $usertypes->{$types->[$i]}.'</span><br />'."\n".
12270: '<input type="text" name="'.$context.'_'.$types->[$i].'" '.
12271: 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
12272: '</label></td>';
12273: } else {
12274: my $check = ' ';
12275: if (ref($settings) eq 'HASH') {
12276: if (ref($settings->{$context}) eq 'ARRAY') {
12277: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
12278: $check = ' checked="checked" ';
12279: }
12280: } elsif (ref($settings->{$context}) eq 'HASH') {
12281: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
12282: $check = ' checked="checked" ';
12283: } elsif ($context eq 'webdav') {
12284: if ($settings->{$context}->{$types->[$i]}) {
12285: $check = ' checked="checked" ';
12286: }
12287: }
12288: } elsif ($context eq 'statustocreate') {
1.315 raeburn 12289: $check = ' checked="checked" ';
12290: }
1.26 raeburn 12291: }
1.429 raeburn 12292: $output .= '<td class="LC_left_item">'.
12293: '<span class="LC_nobreak"><label>'.
12294: '<input type="checkbox" name="'.$context.'" '.
12295: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
12296: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 12297: }
12298: }
12299: }
1.26 raeburn 12300: $rem = @{$types}%($numinrow);
1.23 raeburn 12301: }
12302: my $colsleft = $numinrow - $rem;
1.315 raeburn 12303: if ($context eq 'overrides') {
12304: if ($colsleft > 1) {
12305: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12306: } else {
12307: $output .= '<td class="LC_left_item">';
12308: }
1.425 raeburn 12309: $output .= ' ';
1.23 raeburn 12310: } else {
1.334 raeburn 12311: if ($rem == 0) {
1.315 raeburn 12312: $output .= '<tr>';
12313: }
12314: if ($colsleft > 1) {
12315: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12316: } else {
12317: $output .= '<td class="LC_left_item">';
12318: }
1.429 raeburn 12319: if ($context eq 'authorquota') {
12320: my $currquota = 500;
12321: if ((ref($settings) eq 'HASH') && (ref($settings->{$context}) eq 'HASH')) {
12322: if ($settings->{$context}{'default'} =~ /^\d+$/) {
12323: $currquota = $settings->{$context}{'default'};
12324: }
12325: }
12326: $output .= '<label><span class="LC_nobreak">'.$othertitle.'</span><br />'."\n".
12327: '<input type="text" name="'.$context.'_default" '.
12328: 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
12329: '</label>';
12330: } else {
12331: my $defcheck = ' ';
12332: if (ref($settings) eq 'HASH') {
12333: if (ref($settings->{$context}) eq 'ARRAY') {
12334: if (grep(/^default$/,@{$settings->{$context}})) {
12335: $defcheck = ' checked="checked" ';
12336: }
12337: } elsif (ref($settings->{$context}) eq 'HASH') {
12338: if (ref($settings->{$context}->{'default'}) eq 'HASH') {
12339: $defcheck = ' checked="checked" ';
12340: } elsif ($context eq 'webdav') {
12341: if ($settings->{$context}->{'default'}) {
12342: $defcheck = ' checked="checked" ';
12343: }
12344: }
12345: } elsif ($context eq 'statustocreate') {
1.315 raeburn 12346: $defcheck = ' checked="checked" ';
12347: }
1.99 raeburn 12348: }
1.429 raeburn 12349: $output .= '<span class="LC_nobreak"><label>'.
12350: '<input type="checkbox" name="'.$context.'" '.
12351: 'value="default"'.$defcheck.$onclick.'/>'.
12352: $othertitle.'</label></span>';
1.26 raeburn 12353: }
1.23 raeburn 12354: }
1.315 raeburn 12355: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 12356: return $output;
1.23 raeburn 12357: }
12358:
12359: sub sorted_searchtitles {
12360: my %searchtitles = &Apache::lonlocal::texthash(
12361: 'uname' => 'username',
12362: 'lastname' => 'last name',
12363: 'lastfirst' => 'last name, first name',
12364: );
12365: my @titleorder = ('uname','lastname','lastfirst');
12366: return (\%searchtitles,\@titleorder);
12367: }
12368:
1.25 raeburn 12369: sub sorted_searchtypes {
12370: my %srchtypes_desc = (
12371: exact => 'is exact match',
12372: contains => 'contains ..',
12373: begins => 'begins with ..',
12374: );
12375: my @srchtypeorder = ('exact','begins','contains');
12376: return (\%srchtypes_desc,\@srchtypeorder);
12377: }
12378:
1.3 raeburn 12379: sub usertype_update_row {
12380: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
12381: my $datatable;
12382: my $numinrow = 4;
12383: foreach my $type (@{$types}) {
12384: if (defined($usertypes->{$type})) {
12385: $$rownums ++;
12386: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
12387: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
12388: '</td><td class="LC_left_item"><table>';
12389: for (my $i=0; $i<@{$fields}; $i++) {
12390: my $rem = $i%($numinrow);
12391: if ($rem == 0) {
12392: if ($i > 0) {
12393: $datatable .= '</tr>';
12394: }
12395: $datatable .= '<tr>';
12396: }
12397: my $check = ' ';
1.39 raeburn 12398: if (ref($settings) eq 'HASH') {
12399: if (ref($settings->{'fields'}) eq 'HASH') {
12400: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
12401: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
12402: $check = ' checked="checked" ';
12403: }
1.3 raeburn 12404: }
12405: }
12406: }
12407:
12408: if ($i == @{$fields}-1) {
12409: my $colsleft = $numinrow - $rem;
12410: if ($colsleft > 1) {
12411: $datatable .= '<td colspan="'.$colsleft.'">';
12412: } else {
12413: $datatable .= '<td>';
12414: }
12415: } else {
12416: $datatable .= '<td>';
12417: }
1.8 raeburn 12418: $datatable .= '<span class="LC_nobreak"><label>'.
12419: '<input type="checkbox" name="updateable_'.$type.
12420: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
12421: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 12422: }
12423: $datatable .= '</tr></table></td></tr>';
12424: }
12425: }
12426: return $datatable;
1.1 raeburn 12427: }
12428:
12429: sub modify_login {
1.205 raeburn 12430: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 12431: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.386 raeburn 12432: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
1.412 raeburn 12433: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso);
1.168 raeburn 12434: %title = ( coursecatalog => 'Display course catalog',
12435: adminmail => 'Display administrator E-mail address',
1.188 raeburn 12436: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 12437: newuser => 'Link for visitors to create a user account',
1.386 raeburn 12438: loginheader => 'Log-in box header',
12439: saml => 'Dual SSO and non-SSO login');
1.168 raeburn 12440: @offon = ('off','on');
1.112 raeburn 12441: if (ref($domconfig{login}) eq 'HASH') {
12442: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
12443: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
12444: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
12445: }
12446: }
1.386 raeburn 12447: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
12448: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
12449: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
12450: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
12451: $saml{$lonhost} = 1;
12452: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
12453: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
12454: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
12455: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
12456: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
1.412 raeburn 12457: $samlwindow{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'window'};
1.386 raeburn 12458: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
12459: }
12460: }
12461: }
1.112 raeburn 12462: }
1.9 raeburn 12463: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
12464: \%domconfig,\%loginhash);
1.188 raeburn 12465: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12466: foreach my $item (@toggles) {
12467: $loginhash{login}{$item} = $env{'form.'.$item};
12468: }
1.41 raeburn 12469: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 12470: if (ref($colchanges{'login'}) eq 'HASH') {
12471: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
12472: \%loginhash);
12473: }
1.110 raeburn 12474:
1.149 raeburn 12475: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 12476: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 12477: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 12478: if (keys(%servers) > 1) {
12479: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 12480: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
12481: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
12482: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
12483: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
12484: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
12485: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12486: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12487: $changes{'loginvia'}{$lonhost} = 1;
12488: } else {
12489: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
12490: $changes{'loginvia'}{$lonhost} = 1;
12491: }
12492: } else {
12493: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12494: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12495: $changes{'loginvia'}{$lonhost} = 1;
12496: }
12497: }
12498: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
12499: foreach my $item (@loginvia_attribs) {
12500: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
12501: }
12502: } else {
12503: foreach my $item (@loginvia_attribs) {
12504: my $new = $env{'form.'.$lonhost.'_'.$item};
12505: if (($item eq 'serverpath') && ($new eq 'custom')) {
12506: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
12507: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12508: $new = '/';
12509: }
12510: }
12511: if (($item eq 'custompath') &&
12512: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12513: $new = '';
12514: }
12515: if ($new ne $curr_loginvia{$lonhost}{$item}) {
12516: $changes{'loginvia'}{$lonhost} = 1;
12517: }
12518: if ($item eq 'exempt') {
1.256 raeburn 12519: $new = &check_exempt_addresses($new);
1.128 raeburn 12520: }
12521: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12522: }
12523: }
1.112 raeburn 12524: } else {
1.128 raeburn 12525: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12526: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 12527: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 12528: foreach my $item (@loginvia_attribs) {
12529: my $new = $env{'form.'.$lonhost.'_'.$item};
12530: if (($item eq 'serverpath') && ($new eq 'custom')) {
12531: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12532: $new = '/';
12533: }
12534: }
12535: if (($item eq 'custompath') &&
12536: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12537: $new = '';
12538: }
12539: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12540: }
1.110 raeburn 12541: }
12542: }
12543: }
12544: }
1.119 raeburn 12545:
1.168 raeburn 12546: my $servadm = $r->dir_config('lonAdmEMail');
12547: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
12548: if (ref($domconfig{'login'}) eq 'HASH') {
12549: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
12550: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
12551: if ($lang eq 'nolang') {
12552: push(@currlangs,$lang);
12553: } elsif (defined($langchoices{$lang})) {
12554: push(@currlangs,$lang);
12555: } else {
12556: next;
12557: }
12558: }
12559: }
12560: }
12561: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
12562: if (@currlangs > 0) {
12563: foreach my $lang (@currlangs) {
12564: if (grep(/^\Q$lang\E$/,@delurls)) {
12565: $changes{'helpurl'}{$lang} = 1;
12566: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
12567: $changes{'helpurl'}{$lang} = 1;
12568: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
12569: push(@newlangs,$lang);
12570: } else {
12571: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12572: }
12573: }
12574: }
12575: unless (grep(/^nolang$/,@currlangs)) {
12576: if ($env{'form.loginhelpurl_nolang.filename'}) {
12577: $changes{'helpurl'}{'nolang'} = 1;
12578: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
12579: push(@newlangs,'nolang');
12580: }
12581: }
12582: if ($env{'form.loginhelpurl_add_lang'}) {
12583: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
12584: ($env{'form.loginhelpurl_add_file.filename'})) {
12585: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
12586: $addedfile = $env{'form.loginhelpurl_add_lang'};
12587: }
12588: }
12589: if ((@newlangs > 0) || ($addedfile)) {
12590: my $error;
12591: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12592: if ($configuserok eq 'ok') {
12593: if ($switchserver) {
12594: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
12595: } elsif ($author_ok eq 'ok') {
12596: my @allnew = @newlangs;
12597: if ($addedfile ne '') {
12598: push(@allnew,$addedfile);
12599: }
1.421 raeburn 12600: my $modified = [];
1.168 raeburn 12601: foreach my $lang (@allnew) {
12602: my $formelem = 'loginhelpurl_'.$lang;
12603: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
12604: $formelem = 'loginhelpurl_add_file';
12605: }
1.425 raeburn 12606: (my $result,$newurl{$lang}) =
1.421 raeburn 12607: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12608: "help/$lang",'','',$newfile{$lang},
12609: $modified);
1.168 raeburn 12610: if ($result eq 'ok') {
12611: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
12612: $changes{'helpurl'}{$lang} = 1;
12613: } else {
12614: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
12615: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 12616: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 12617: (!grep(/^\Q$lang\E$/,@delurls))) {
12618: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12619: }
12620: }
12621: }
1.421 raeburn 12622: &update_modify_urls($r,$modified);
1.168 raeburn 12623: } else {
12624: $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);
12625: }
12626: } else {
12627: $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);
12628: }
12629: if ($error) {
12630: &Apache::lonnet::logthis($error);
12631: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12632: }
12633: }
1.256 raeburn 12634:
12635: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
12636: if (ref($domconfig{'login'}) eq 'HASH') {
12637: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
12638: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
12639: if ($domservers{$lonhost}) {
12640: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12641: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 12642: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 12643: }
12644: }
12645: }
12646: }
12647: }
12648: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
12649: foreach my $lonhost (sort(keys(%domservers))) {
12650: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12651: $changes{'headtag'}{$lonhost} = 1;
12652: } else {
12653: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
12654: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
12655: }
12656: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
12657: push(@newhosts,$lonhost);
12658: } elsif ($currheadtagurls{$lonhost}) {
12659: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
12660: if ($currexempt{$lonhost}) {
1.289 raeburn 12661: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 12662: $changes{'headtag'}{$lonhost} = 1;
12663: }
12664: } elsif ($possexempt{$lonhost}) {
12665: $changes{'headtag'}{$lonhost} = 1;
12666: }
12667: if ($possexempt{$lonhost}) {
12668: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12669: }
12670: }
12671: }
12672: }
12673: if (@newhosts) {
12674: my $error;
12675: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12676: if ($configuserok eq 'ok') {
12677: if ($switchserver) {
12678: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
12679: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12680: my $modified = [];
1.256 raeburn 12681: foreach my $lonhost (@newhosts) {
12682: my $formelem = 'loginheadtag_'.$lonhost;
1.425 raeburn 12683: (my $result,$newheadtagurls{$lonhost}) =
1.421 raeburn 12684: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12685: "login/headtag/$lonhost",'','',
12686: $env{'form.loginheadtag_'.$lonhost.'.filename'},
12687: $modified);
1.256 raeburn 12688: if ($result eq 'ok') {
12689: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
12690: $changes{'headtag'}{$lonhost} = 1;
12691: if ($possexempt{$lonhost}) {
12692: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12693: }
12694: } else {
12695: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
12696: $newheadtagurls{$lonhost},$result);
12697: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12698: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
12699: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
12700: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
12701: }
12702: }
12703: }
1.421 raeburn 12704: &update_modify_urls($r,$modified);
1.256 raeburn 12705: } else {
12706: $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);
12707: }
12708: } else {
12709: $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);
12710: }
12711: if ($error) {
12712: &Apache::lonnet::logthis($error);
12713: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12714: }
12715: }
1.386 raeburn 12716: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
12717: my @newsamlimgs;
12718: foreach my $lonhost (keys(%domservers)) {
12719: if ($env{'form.saml_'.$lonhost}) {
12720: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
12721: push(@newsamlimgs,$lonhost);
12722: }
1.412 raeburn 12723: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12724: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
12725: }
12726: if ($saml{$lonhost}) {
1.412 raeburn 12727: if ($env{'form.saml_window_'.$lonhost} ne '1') {
12728: $env{'form.saml_window_'.$lonhost} = '';
12729: }
1.386 raeburn 12730: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
12731: #FIXME Need to obsolete published image
12732: delete($currsaml{$lonhost}{'img'});
12733: $changes{'saml'}{$lonhost} = 1;
12734: }
12735: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
12736: $changes{'saml'}{$lonhost} = 1;
12737: }
12738: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
12739: $changes{'saml'}{$lonhost} = 1;
12740: }
12741: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
12742: $changes{'saml'}{$lonhost} = 1;
12743: }
12744: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
12745: $changes{'saml'}{$lonhost} = 1;
12746: }
1.412 raeburn 12747: if ($env{'form.saml_window_'.$lonhost} ne $samlwindow{$lonhost}) {
12748: $changes{'saml'}{$lonhost} = 1;
12749: }
1.386 raeburn 12750: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
12751: $changes{'saml'}{$lonhost} = 1;
12752: }
12753: } else {
12754: $changes{'saml'}{$lonhost} = 1;
12755: }
1.412 raeburn 12756: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12757: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
12758: }
12759: } else {
1.425 raeburn 12760: if ($saml{$lonhost}) {
1.389 raeburn 12761: $changes{'saml'}{$lonhost} = 1;
12762: delete($currsaml{$lonhost});
12763: }
1.386 raeburn 12764: }
12765: }
12766: foreach my $posshost (keys(%currsaml)) {
1.425 raeburn 12767: unless (exists($domservers{$posshost})) {
12768: delete($currsaml{$posshost});
1.386 raeburn 12769: }
12770: }
12771: %{$loginhash{'login'}{'saml'}} = %currsaml;
12772: if (@newsamlimgs) {
12773: my $error;
12774: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12775: if ($configuserok eq 'ok') {
12776: if ($switchserver) {
12777: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
12778: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12779: my $modified = [];
1.386 raeburn 12780: foreach my $lonhost (@newsamlimgs) {
12781: my $formelem = 'saml_img_'.$lonhost;
1.425 raeburn 12782: my ($result,$imgurl) =
1.421 raeburn 12783: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12784: "login/saml/$lonhost",'','',
12785: $env{'form.saml_img_'.$lonhost.'.filename'},
12786: $modified);
1.386 raeburn 12787: if ($result eq 'ok') {
12788: $currsaml{$lonhost}{'img'} = $imgurl;
12789: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
12790: $changes{'saml'}{$lonhost} = 1;
12791: } else {
12792: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
12793: $lonhost,$result);
12794: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12795: }
12796: }
1.421 raeburn 12797: &update_modify_urls($r,$modified);
1.386 raeburn 12798: } else {
12799: $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);
12800: }
12801: } else {
12802: $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);
12803: }
12804: if ($error) {
12805: &Apache::lonnet::logthis($error);
12806: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12807: }
12808: }
1.169 raeburn 12809: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 12810:
12811: my $defaulthelpfile = '/adm/loginproblems.html';
12812: my $defaulttext = &mt('Default in use');
12813:
1.1 raeburn 12814: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
12815: $dom);
12816: if ($putresult eq 'ok') {
1.188 raeburn 12817: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12818: my %defaultchecked = (
12819: 'coursecatalog' => 'on',
1.188 raeburn 12820: 'helpdesk' => 'on',
1.42 raeburn 12821: 'adminmail' => 'off',
1.43 raeburn 12822: 'newuser' => 'off',
1.42 raeburn 12823: );
1.55 raeburn 12824: if (ref($domconfig{'login'}) eq 'HASH') {
12825: foreach my $item (@toggles) {
12826: if ($defaultchecked{$item} eq 'on') {
12827: if (($domconfig{'login'}{$item} eq '0') &&
12828: ($env{'form.'.$item} eq '1')) {
12829: $changes{$item} = 1;
12830: } elsif (($domconfig{'login'}{$item} eq '' ||
12831: $domconfig{'login'}{$item} eq '1') &&
12832: ($env{'form.'.$item} eq '0')) {
12833: $changes{$item} = 1;
12834: }
12835: } elsif ($defaultchecked{$item} eq 'off') {
12836: if (($domconfig{'login'}{$item} eq '1') &&
12837: ($env{'form.'.$item} eq '0')) {
12838: $changes{$item} = 1;
12839: } elsif (($domconfig{'login'}{$item} eq '' ||
12840: $domconfig{'login'}{$item} eq '0') &&
12841: ($env{'form.'.$item} eq '1')) {
12842: $changes{$item} = 1;
12843: }
1.42 raeburn 12844: }
12845: }
1.41 raeburn 12846: }
1.6 raeburn 12847: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 12848: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.386 raeburn 12849: if (exists($changes{'saml'})) {
12850: my $hostid_in_use;
12851: my @hosts = &Apache::lonnet::current_machine_ids();
12852: if (@hosts > 1) {
12853: foreach my $hostid (@hosts) {
12854: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
12855: $hostid_in_use = $hostid;
12856: last;
12857: }
12858: }
12859: } else {
12860: $hostid_in_use = $r->dir_config('lonHostID');
12861: }
12862: if (($hostid_in_use) &&
12863: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
1.387 raeburn 12864: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
1.386 raeburn 12865: }
12866: if (ref($lastactref) eq 'HASH') {
12867: if (ref($changes{'saml'}) eq 'HASH') {
12868: my %updates;
12869: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
12870: $lastactref->{'samllanding'} = \%updates;
12871: }
12872: }
12873: }
1.212 raeburn 12874: if (ref($lastactref) eq 'HASH') {
12875: $lastactref->{'domainconfig'} = 1;
12876: }
1.1 raeburn 12877: $resulttext = &mt('Changes made:').'<ul>';
12878: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 12879: if ($item eq 'loginvia') {
1.112 raeburn 12880: if (ref($changes{$item}) eq 'HASH') {
12881: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
12882: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 12883: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
12884: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
12885: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
12886: $protocol = 'http' if ($protocol ne 'https');
12887: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
12888:
12889: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
12890: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
12891: } else {
12892: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
12893: }
12894: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
12895: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
12896: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
12897: }
12898: $resulttext .= '</li>';
12899: } else {
12900: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
12901: }
1.112 raeburn 12902: } else {
1.128 raeburn 12903: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 12904: }
12905: }
1.128 raeburn 12906: $resulttext .= '</ul></li>';
1.112 raeburn 12907: }
1.168 raeburn 12908: } elsif ($item eq 'helpurl') {
12909: if (ref($changes{$item}) eq 'HASH') {
12910: foreach my $lang (sort(keys(%{$changes{$item}}))) {
12911: if (grep(/^\Q$lang\E$/,@delurls)) {
12912: my ($chg,$link);
12913: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
12914: if ($lang eq 'nolang') {
12915: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
12916: } else {
12917: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
12918: }
12919: $resulttext .= '<li>'.$chg.'</li>';
12920: } else {
12921: my $chg;
12922: if ($lang eq 'nolang') {
12923: $chg = &mt('custom log-in help file for no preferred language');
12924: } else {
12925: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
12926: }
12927: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
12928: $loginhash{'login'}{'helpurl'}{$lang}.
12929: '?inhibitmenu=yes',$chg,600,500).
12930: '</li>';
12931: }
12932: }
12933: }
1.256 raeburn 12934: } elsif ($item eq 'headtag') {
12935: if (ref($changes{$item}) eq 'HASH') {
12936: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12937: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12938: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
12939: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12940: $resulttext .= '<li><a href="'.
12941: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
12942: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
12943: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
12944: if ($possexempt{$lonhost}) {
12945: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
12946: } else {
12947: $resulttext .= &mt('included for any client IP');
12948: }
12949: $resulttext .= '</li>';
12950: }
12951: }
12952: }
1.386 raeburn 12953: } elsif ($item eq 'saml') {
12954: if (ref($changes{$item}) eq 'HASH') {
12955: my %notlt = (
12956: text => 'Text for log-in by SSO',
12957: img => 'SSO button image',
12958: alt => 'Alt text for button image',
12959: url => 'SSO URL',
12960: title => 'Tooltip for SSO link',
1.412 raeburn 12961: window => 'Pop-up window if iframe',
1.386 raeburn 12962: notsso => 'Text for non-SSO log-in',
12963: );
12964: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12965: if (ref($currsaml{$lonhost}) eq 'HASH') {
12966: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
12967: '<ul>';
1.412 raeburn 12968: foreach my $key ('text','img','alt','url','title','window','notsso') {
1.386 raeburn 12969: if ($currsaml{$lonhost}{$key} eq '') {
12970: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
12971: } else {
12972: my $value = "'$currsaml{$lonhost}{$key}'";
12973: if ($key eq 'img') {
12974: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
1.412 raeburn 12975: } elsif ($key eq 'window') {
12976: $value = 'On';
1.386 raeburn 12977: }
12978: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
12979: $value).'</li>';
12980: }
12981: }
12982: $resulttext .= '</ul></li>';
12983: } else {
12984: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
12985: }
12986: }
12987: }
1.169 raeburn 12988: } elsif ($item eq 'captcha') {
12989: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 12990: my $chgtxt;
1.169 raeburn 12991: if ($loginhash{'login'}{$item} eq 'notused') {
12992: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
12993: } else {
12994: my %captchas = &captcha_phrases();
12995: if ($captchas{$loginhash{'login'}{$item}}) {
12996: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
12997: } else {
12998: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
12999: }
13000: }
13001: $resulttext .= '<li>'.$chgtxt.'</li>';
13002: }
13003: } elsif ($item eq 'recaptchakeys') {
13004: if (ref($loginhash{'login'}) eq 'HASH') {
13005: my ($privkey,$pubkey);
13006: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
13007: $pubkey = $loginhash{'login'}{$item}{'public'};
13008: $privkey = $loginhash{'login'}{$item}{'private'};
13009: }
13010: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
13011: if (!$pubkey) {
13012: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
13013: } else {
13014: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
13015: }
13016: if (!$privkey) {
13017: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
13018: } else {
1.251 raeburn 13019: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 13020: }
13021: $chgtxt .= '</ul>';
13022: $resulttext .= '<li>'.$chgtxt.'</li>';
13023: }
1.269 raeburn 13024: } elsif ($item eq 'recaptchaversion') {
13025: if (ref($loginhash{'login'}) eq 'HASH') {
13026: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 13027: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 13028: '</li>';
13029: }
13030: }
1.41 raeburn 13031: } else {
13032: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
13033: }
1.1 raeburn 13034: }
1.6 raeburn 13035: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 13036: } else {
13037: $resulttext = &mt('No changes made to log-in page settings');
13038: }
13039: } else {
1.11 albertel 13040: $resulttext = '<span class="LC_error">'.
13041: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 13042: }
1.6 raeburn 13043: if ($errors) {
1.9 raeburn 13044: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 13045: $errors.'</ul>';
13046: }
13047: return $resulttext;
13048: }
13049:
1.256 raeburn 13050: sub check_exempt_addresses {
13051: my ($iplist) = @_;
13052: $iplist =~ s/^\s+//;
13053: $iplist =~ s/\s+$//;
13054: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
13055: my (@okips,$new);
13056: foreach my $ip (@poss_ips) {
13057: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
13058: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
13059: push(@okips,$ip);
13060: }
13061: }
13062: }
13063: if (@okips > 0) {
13064: $new = join(',',@okips);
13065: } else {
13066: $new = '';
13067: }
13068: return $new;
13069: }
13070:
1.6 raeburn 13071: sub color_font_choices {
13072: my %choices =
13073: &Apache::lonlocal::texthash (
13074: img => "Header",
13075: bgs => "Background colors",
13076: links => "Link colors",
1.55 raeburn 13077: images => "Images",
1.6 raeburn 13078: font => "Font color",
1.201 raeburn 13079: fontmenu => "Font menu",
1.76 raeburn 13080: pgbg => "Page",
1.6 raeburn 13081: tabbg => "Header",
13082: sidebg => "Border",
13083: link => "Link",
13084: alink => "Active link",
13085: vlink => "Visited link",
13086: );
13087: return %choices;
13088: }
13089:
1.394 raeburn 13090: sub modify_ipaccess {
13091: my ($dom,$lastactref,%domconfig) = @_;
13092: my (@allpos,%changes,%confhash,$errors,$resulttext);
13093: my (@items,%deletions,%itemids,@warnings);
13094: my ($typeorder,$types) = &commblocktype_text();
13095: if ($env{'form.ipaccess_add'}) {
13096: my $name = $env{'form.ipaccess_name_add'};
13097: my ($newid,$error) = &get_ipaccess_id($dom,$name);
13098: if ($newid) {
13099: $itemids{'add'} = $newid;
13100: push(@items,'add');
13101: $changes{$newid} = 1;
13102: } else {
13103: $error = &mt('Failed to acquire unique ID for new IP access control item');
13104: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13105: }
13106: }
13107: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
13108: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
13109: if (@todelete) {
13110: map { $deletions{$_} = 1; } @todelete;
13111: }
13112: my $maxnum = $env{'form.ipaccess_maxnum'};
13113: for (my $i=0; $i<$maxnum; $i++) {
13114: my $itemid = $env{'form.ipaccess_id_'.$i};
13115: $itemid =~ s/\D+//g;
13116: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13117: if ($deletions{$itemid}) {
13118: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
13119: } else {
13120: push(@items,$i);
13121: $itemids{$i} = $itemid;
13122: }
13123: }
13124: }
13125: }
13126: foreach my $idx (@items) {
13127: my $itemid = $itemids{$idx};
13128: next unless ($itemid);
13129: my %current;
13130: unless ($idx eq 'add') {
13131: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13132: %current = %{$domconfig{'ipaccess'}{$itemid}};
13133: }
13134: }
13135: my $position = $env{'form.ipaccess_pos_'.$itemid};
13136: $position =~ s/\D+//g;
13137: if ($position ne '') {
13138: $allpos[$position] = $itemid;
13139: }
13140: my $name = $env{'form.ipaccess_name_'.$idx};
13141: $name =~ s/^\s+|\s+$//g;
13142: $confhash{$itemid}{'name'} = $name;
13143: my $possrange = $env{'form.ipaccess_range_'.$idx};
13144: $possrange =~ s/^\s+|\s+$//g;
13145: unless ($possrange eq '') {
13146: $possrange =~ s/[\r\n]+/\s/g;
13147: $possrange =~ s/\s*-\s*/-/g;
13148: $possrange =~ s/\s+/,/g;
13149: $possrange =~ s/,+/,/g;
13150: if ($possrange ne '') {
13151: my (@ok,$count);
1.425 raeburn 13152: $count = 0;
1.394 raeburn 13153: foreach my $poss (split(/\,/,$possrange)) {
13154: $count ++;
13155: $poss = &validate_ip_pattern($poss);
13156: if ($poss ne '') {
13157: push(@ok,$poss);
13158: }
13159: }
13160: my $diff = $count - scalar(@ok);
13161: if ($diff) {
13162: $errors .= '<li><span class="LC_error">'.
13163: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
13164: $diff,$name).
13165: '</span></li>';
13166: }
13167: if (@ok) {
13168: my @cidr_list;
13169: foreach my $item (@ok) {
13170: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
13171: }
13172: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
13173: }
13174: }
13175: }
13176: foreach my $field ('name','ip') {
13177: unless (($idx eq 'add') || ($changes{$itemid})) {
13178: if ($current{$field} ne $confhash{$itemid}{$field}) {
13179: $changes{$itemid} = 1;
13180: last;
13181: }
13182: }
13183: }
13184: $confhash{$itemid}{'commblocks'} = {};
1.425 raeburn 13185:
1.394 raeburn 13186: my %commblocks;
1.425 raeburn 13187: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
1.394 raeburn 13188: foreach my $type (@{$typeorder}) {
13189: if ($commblocks{$type}) {
13190: $confhash{$itemid}{'commblocks'}{$type} = 'on';
13191: }
13192: unless (($idx eq 'add') || ($changes{$itemid})) {
13193: if (ref($current{'commblocks'}) eq 'HASH') {
13194: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
13195: $changes{$itemid} = 1;
13196: }
13197: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
13198: $changes{$itemid} = 1;
13199: }
13200: }
13201: }
13202: $confhash{$itemid}{'courses'} = {};
13203: my %crsdeletions;
13204: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
13205: if (@delcrs) {
13206: map { $crsdeletions{$_} = 1; } @delcrs;
13207: }
13208: if (ref($current{'courses'}) eq 'HASH') {
13209: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
13210: if ($crsdeletions{$cid}) {
13211: $changes{$itemid} = 1;
13212: } else {
13213: $confhash{$itemid}{'courses'}{$cid} = 1;
13214: }
13215: }
13216: }
13217: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
13218: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
1.425 raeburn 13219: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
1.394 raeburn 13220: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
13221: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
13222: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
13223: $errors .= '<li><span class="LC_error">'.
13224: &mt('Invalid courseID [_1] omitted from list of allowed courses',
13225: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
13226: '</span></li>';
13227: } else {
13228: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
13229: $changes{$itemid} = 1;
13230: }
13231: }
13232: }
13233: if (@allpos > 0) {
13234: my $idx = 0;
13235: foreach my $itemid (@allpos) {
13236: if ($itemid ne '') {
13237: $confhash{$itemid}{'order'} = $idx;
13238: unless ($changes{$itemid}) {
13239: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
13240: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13241: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
13242: $changes{$itemid} = 1;
13243: }
13244: }
13245: }
13246: }
13247: $idx ++;
13248: }
13249: }
13250: }
13251: if (keys(%changes)) {
13252: my %defaultshash = (
13253: ipaccess => \%confhash,
13254: );
13255: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13256: $dom);
13257: if ($putresult eq 'ok') {
13258: my $cachetime = 1800;
13259: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
13260: if (ref($lastactref) eq 'HASH') {
13261: $lastactref->{'ipaccess'} = 1;
13262: }
13263: $resulttext = &mt('Changes made:').'<ul>';
13264: my %bynum;
13265: foreach my $itemid (sort(keys(%changes))) {
13266: if (ref($confhash{$itemid}) eq 'HASH') {
13267: my $position = $confhash{$itemid}{'order'};
13268: if ($position =~ /^\d+$/) {
13269: $bynum{$position} = $itemid;
13270: }
13271: }
13272: }
13273: if (keys(%deletions)) {
13274: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
13275: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
13276: }
13277: }
13278: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
13279: my $itemid = $bynum{$pos};
13280: if (ref($confhash{$itemid}) eq 'HASH') {
13281: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
13282: my $position = $pos + 1;
13283: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
13284: if ($confhash{$itemid}{'ip'} eq '') {
13285: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
13286: } else {
13287: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
13288: }
13289: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
13290: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
13291: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
13292: '</li>';
13293: } else {
13294: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
13295: }
13296: if (keys(%{$confhash{$itemid}{'courses'}})) {
13297: my @courses;
13298: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
1.425 raeburn 13299: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1.394 raeburn 13300: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
13301: }
13302: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
13303: join('</li><li>',@courses).'</li></ul>';
13304: } else {
13305: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
13306: }
1.395 raeburn 13307: $resulttext .= '</ul></li>';
1.394 raeburn 13308: }
13309: }
1.395 raeburn 13310: $resulttext .= '</ul>';
1.394 raeburn 13311: } else {
13312: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13313: }
13314: } else {
13315: $resulttext = &mt('No changes made');
13316: }
13317: if ($errors) {
13318: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
13319: $errors.'</ul></p>';
13320: }
13321: return $resulttext;
13322: }
13323:
13324: sub get_ipaccess_id {
13325: my ($domain,$location) = @_;
13326: # get lock on ipaccess db
13327: my $lockhash = {
13328: lock => $env{'user.name'}.
13329: ':'.$env{'user.domain'},
13330: };
13331: my $tries = 0;
13332: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13333: my ($id,$error);
13334:
13335: while (($gotlock ne 'ok') && ($tries<10)) {
13336: $tries ++;
13337: sleep (0.1);
13338: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13339: }
13340: if ($gotlock eq 'ok') {
13341: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
13342: if ($currids{'lock'}) {
13343: delete($currids{'lock'});
13344: if (keys(%currids)) {
13345: my @curr = sort { $a <=> $b } keys(%currids);
13346: if ($curr[-1] =~ /^\d+$/) {
13347: $id = 1 + $curr[-1];
13348: }
13349: } else {
13350: $id = 1;
13351: }
13352: if ($id) {
13353: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
13354: $error = 'nostore';
13355: }
13356: } else {
13357: $error = 'nonumber';
13358: }
13359: }
13360: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
13361: } else {
13362: $error = 'nolock';
13363: }
13364: return ($id,$error);
13365: }
13366:
1.429 raeburn 13367: sub modify_authordefaults {
13368: my ($dom,$lastactref,%domconfig) = @_;
13369: #
13370: # Retrieve current domain configuration for webDAV and Authoring Space quotas from $domconfig{'quotas'}.
13371: #
13372: my (%curr_quotas,%save_quotas,%confhash,%changes,%newvalues);
13373: if (ref($domconfig{'quotas'}) eq 'HASH') {
13374: foreach my $key (keys(%{$domconfig{'quotas'}})) {
13375: if ($key =~ /^webdav|authorquota$/) {
13376: $curr_quotas{$key} = $domconfig{'quotas'}{$key};
13377: } else {
13378: $save_quotas{$key} = $domconfig{'quotas'}{$key};
13379: }
13380: }
13381: }
13382: my %staticdefaults = (
13383: 'copyright' => 'default',
13384: 'sourceavail' => 'closed',
13385: 'nocodemirror' => 'off',
1.437 ! raeburn 13386: 'daxecollapse' => 'off',
1.429 raeburn 13387: 'domcoordacc' => 'on',
13388: 'editors' => ['edit','xml'].
13389: 'authorquota' => 500,
13390: 'webdav' => 0,
13391: );
13392: my %titles = &authordefaults_titles();
1.437 ! raeburn 13393: foreach my $item ('nocodemirror','daxecollapse','domcoordacc') {
1.429 raeburn 13394: if ($env{'form.'.$item} =~ /^(0|1)$/) {
13395: $confhash{$item} = $env{'form.'.$item};
13396: }
13397: }
13398: if ($env{'form.copyright'} =~ /^(default|domain|public)$/) {
13399: $confhash{'copyright'} = $1;
13400: }
13401: if ($env{'form.sourceavail'} =~ /^(closed|open)$/) {
13402: $confhash{'sourceavail'} = $1;
13403: }
13404: my @posseditors = &Apache::loncommon::get_env_multiple('form.author_editors');
13405: my @okeditors = ('edit','xml','daxe');
13406: my @editors;
13407: foreach my $item (@posseditors) {
13408: if (grep(/^\Q$item\E$/,@okeditors)) {
13409: push(@editors,$item);
13410: }
13411: }
13412: $confhash{'editors'} = \@editors;
1.436 raeburn 13413:
1.429 raeburn 13414: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13415: my @insttypes;
13416: if (ref($types) eq 'ARRAY') {
13417: @insttypes = @{$types};
13418: }
13419: my @webdavon = &Apache::loncommon::get_env_multiple('form.webdav');
13420: my %webdav;
13421: map { $webdav{$_} = 1; } @webdavon;
13422: foreach my $type (@insttypes,'default') {
13423: my $possquota = $env{'form.authorquota_'.$type};
13424: if ($possquota =~ /^\d+$/) {
13425: $save_quotas{'authorquota'}{$type} = $possquota;
13426: }
13427: if ($webdav{$type}) {
13428: $save_quotas{'webdav'}{$type} = 1;
13429: } else {
13430: $save_quotas{'webdav'}{$type} = 0;
13431: }
13432: }
13433: if ($env{'form.webdav_LC_adv'} =~ /^(0|1)$/) {
13434: $save_quotas{'webdav'}{'_LC_adv'} = $env{'form.webdav_LC_adv'};
13435: }
13436: if (ref($domconfig{'authordefaults'}) eq 'HASH') {
1.437 ! raeburn 13437: foreach my $item ('nocodemirror','daxecollapse','domcoordacc','copyright','sourceavail') {
1.429 raeburn 13438: if ($domconfig{'authordefaults'}{$item} ne $confhash{$item}) {
13439: $changes{$item} = 1;
13440: }
13441: }
13442: if (ref($domconfig{'authordefaults'}{'editors'}) eq 'ARRAY') {
1.436 raeburn 13443: my @diffs =
1.429 raeburn 13444: &Apache::loncommon::compare_arrays($confhash{'editors'},
13445: $domconfig{'authordefaults'}{'editors'});
13446: unless (@diffs == 0) {
13447: $changes{'editors'} = 1;
13448: }
13449: } else {
13450: my @diffs =
13451: &Apache::loncommon::compare_arrays($confhash{'editors'},
13452: $staticdefaults{'editors'});
13453: unless (@diffs == 0) {
13454: $changes{'editors'} = 1;
13455: }
13456: }
13457: } else {
13458: my @offon = ('off','on');
1.437 ! raeburn 13459: foreach my $item ('nocodemirror','daxecollapse','domcoordacc') {
1.436 raeburn 13460: if ($offon[$confhash{$item}] ne $staticdefaults{$item}) {
1.429 raeburn 13461: $changes{$item} = 1;
13462: }
13463: }
13464: foreach my $item ('copyright','sourceavail') {
13465: if ($confhash{$item} ne $staticdefaults{$item}) {
13466: $changes{$item} = 1;
13467: }
13468: }
13469: }
13470: foreach my $key ('authorquota','webdav') {
13471: if (ref($curr_quotas{$key}) eq 'HASH') {
13472: foreach my $type (@insttypes,'default') {
13473: if (exists($save_quotas{$key}{$type})) {
13474: if ($save_quotas{$key}{$type} ne $curr_quotas{$key}{$type}) {
13475: $changes{$key}{$type} = 1;
13476: }
13477: } elsif (exists($curr_quotas{$key}{$type})) {
13478: $save_quotas{$key}{$type} = $curr_quotas{$key}{$type};
13479: } else {
13480: $save_quotas{$key}{$type} = $staticdefaults{$key};
13481: }
13482: }
13483: } else {
13484: foreach my $type (@insttypes,'default') {
13485: if (exists($save_quotas{$key}{$type})) {
13486: unless ($save_quotas{$key}{$type} eq $staticdefaults{$key}) {
13487: $changes{$key}{$type} = 1;
13488: }
13489: } else {
13490: $save_quotas{$key}{$type} = $staticdefaults{$key};
13491: }
13492: }
13493: }
13494: }
13495: if (ref($curr_quotas{'webdav'}) eq 'HASH') {
13496: if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
1.436 raeburn 13497: if ($save_quotas{'webdav'}{'_LC_adv'} ne $curr_quotas{'webdav'}{'_LC_adv'}) {
1.429 raeburn 13498: $changes{'webdav_LC_adv'} = 1;
13499: }
13500: } elsif (exists($curr_quotas{'webdav'}{'_LC_adv'})) {
13501: $changes{'webdav_LC_adv'} = 1;
13502: }
13503: } elsif (exists($save_quotas{'webdav'}{'_LC_adv'})) {
13504: $changes{'webdav_LC_adv'} = 1;
13505: }
13506: my %confighash = (
13507: quotas => \%save_quotas,
13508: authordefaults => \%confhash,
13509: );
13510: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,
13511: $dom);
13512: my $resulttext;
13513: if ($putresult eq 'ok') {
13514: if (keys(%changes)) {
1.431 raeburn 13515: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.429 raeburn 13516: if ((exists($changes{'authorquota'})) || (exists($changes{'webdav'})) ||
1.436 raeburn 13517: ($changes{'webdav_LC_adv'})) {
1.429 raeburn 13518: if ((exists($changes{'authorquota'})) && (ref($save_quotas{'authorquota'}) eq 'HASH')) {
13519: $domdefaults{'authorquota'} = $save_quotas{'authorquota'};
13520: }
13521: if (((exists($changes{'webdav'})) || ($changes{'webdav_LC_adv'})) &&
13522: (ref($save_quotas{'webdav'}) eq 'HASH')) {
13523: $domdefaults{'webdav'} = $save_quotas{'webdav'};
13524: }
13525: }
13526: $resulttext = &mt('Changes made:').'<ul>';
13527: my $authoroverride;
1.437 ! raeburn 13528: foreach my $key ('nocodemirror','daxecollapse','domcoordacc','copyright','sourceavail') {
1.429 raeburn 13529: if (exists($changes{$key})) {
1.431 raeburn 13530: $domdefaults{$key} = $confhash{$key};
1.429 raeburn 13531: my $shown;
13532: unless ($authoroverride) {
13533: $resulttext .= '<li>'.&mt('Defaults which can be overridden by Author').'<ul>';
13534: $authoroverride = 1;
13535: }
1.437 ! raeburn 13536: if (($key eq 'nocodemirror') || ($key eq 'daxecollapse') || ($key eq 'domcoordacc')) {
1.429 raeburn 13537: $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
13538: } elsif ($key eq 'copyright') {
13539: $shown = &Apache::loncommon::copyrightdescription($confhash{$key});
13540: } elsif ($key eq 'sourceavail') {
13541: $shown = &Apache::loncommon::source_copyrightdescription($confhash{$key});
13542: }
1.436 raeburn 13543: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
1.429 raeburn 13544: }
13545: }
13546: if ($authoroverride) {
13547: $resulttext .= '</ul></li>';
13548: }
13549: my $domcoordoverride;
13550: foreach my $key ('editors','authorquota','webdav','webdav_LC_adv') {
13551: if (exists($changes{$key})) {
13552: my $shown;
13553: unless ($domcoordoverride) {
13554: $resulttext .= '<li>'.&mt('Defaults which can be overridden by a Domain Coodinator').'<ul>';
13555: $domcoordoverride = 1;
13556: }
13557: if ($key eq 'editors') {
1.431 raeburn 13558: if (ref($confhash{'editors'}) eq 'ARRAY') {
13559: $domdefaults{'editors'} = join(',',@{$confhash{'editors'}});
13560: if (@{$confhash{'editors'}}) {
13561: $shown = join(', ', map { $titles{$_} } @{$confhash{'editors'}});
13562: } else {
13563: $shown = &mt('None');
13564: }
1.429 raeburn 13565: }
13566: } elsif ($key eq 'authorquota') {
13567: foreach my $type (@insttypes) {
13568: $shown .= $usertypes->{$type}.' -- '.$save_quotas{$key}{$type}.', ';
13569: }
13570: $shown .= $othertitle.' -- '.$save_quotas{$key}{'default'};
13571: } elsif ($key eq 'webdav') {
13572: foreach my $type (@insttypes) {
13573: $shown .= $usertypes->{$type}.' -- '. ($save_quotas{$key}{$type} ? &mt('Yes') : &mt('No')).', ';
13574: }
13575: $shown .= $othertitle.' -- '. ($save_quotas{$key}{'default'} ? &mt('Yes') : &mt('No'));
13576: } elsif ($key eq 'webdav_LC_adv') {
13577: if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
13578: $shown = ($save_quotas{'webdav'}{'_LC_adv'} ? $titles{'overon'} : $titles{'overoff'});
13579: } else {
13580: $shown = $titles{'none'};
13581: }
13582: }
13583: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
1.436 raeburn 13584: }
1.429 raeburn 13585: }
13586: if ($domcoordoverride) {
13587: $resulttext .= '</ul></li>';
13588: }
1.431 raeburn 13589: my $cachetime = 24*60*60;
13590: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13591: if (ref($lastactref) eq 'HASH') {
13592: $lastactref->{'domdefaults'} = 1;
13593: }
1.429 raeburn 13594: } else {
13595: $resulttext = &mt('No changes made to Authoring Space defaults');
13596: }
13597: }
13598: return $resulttext;
13599: }
13600:
1.6 raeburn 13601: sub modify_rolecolors {
1.205 raeburn 13602: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 13603: my ($resulttext,%rolehash);
13604: $rolehash{'rolecolors'} = {};
1.55 raeburn 13605: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
13606: if ($domconfig{'rolecolors'} eq '') {
13607: $domconfig{'rolecolors'} = {};
13608: }
13609: }
1.9 raeburn 13610: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 13611: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
13612: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
13613: $dom);
13614: if ($putresult eq 'ok') {
13615: if (keys(%changes) > 0) {
1.41 raeburn 13616: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 13617: if (ref($lastactref) eq 'HASH') {
13618: $lastactref->{'domainconfig'} = 1;
13619: }
1.6 raeburn 13620: $resulttext = &display_colorchgs($dom,\%changes,$roles,
13621: $rolehash{'rolecolors'});
13622: } else {
13623: $resulttext = &mt('No changes made to default color schemes');
13624: }
13625: } else {
1.11 albertel 13626: $resulttext = '<span class="LC_error">'.
13627: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 13628: }
13629: if ($errors) {
13630: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
13631: $errors.'</ul>';
13632: }
13633: return $resulttext;
13634: }
13635:
13636: sub modify_colors {
1.9 raeburn 13637: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 13638: my (%changes,%choices);
1.51 raeburn 13639: my @bgs;
1.6 raeburn 13640: my @links = ('link','alink','vlink');
1.41 raeburn 13641: my @logintext;
1.6 raeburn 13642: my @images;
13643: my $servadm = $r->dir_config('lonAdmEMail');
13644: my $errors;
1.200 raeburn 13645: my %defaults;
1.6 raeburn 13646: foreach my $role (@{$roles}) {
13647: if ($role eq 'login') {
1.12 raeburn 13648: %choices = &login_choices();
1.41 raeburn 13649: @logintext = ('textcol','bgcol');
1.12 raeburn 13650: } else {
13651: %choices = &color_font_choices();
13652: }
13653: if ($role eq 'login') {
1.41 raeburn 13654: @images = ('img','logo','domlogo','login');
1.51 raeburn 13655: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 13656: } else {
13657: @images = ('img');
1.200 raeburn 13658: @bgs = ('pgbg','tabbg','sidebg');
13659: }
13660: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
13661: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
13662: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
13663: }
13664: if ($role eq 'login') {
13665: foreach my $item (@logintext) {
1.234 raeburn 13666: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13667: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13668: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13669: }
13670: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 13671: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13672: }
13673: }
13674: } else {
1.234 raeburn 13675: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
13676: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
13677: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
13678: }
13679: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 13680: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
13681: }
1.6 raeburn 13682: }
1.200 raeburn 13683: foreach my $item (@bgs) {
1.234 raeburn 13684: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13685: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13686: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13687: }
13688: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 13689: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13690: }
13691: }
13692: foreach my $item (@links) {
1.234 raeburn 13693: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13694: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13695: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13696: }
13697: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 13698: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13699: }
1.6 raeburn 13700: }
1.46 raeburn 13701: my ($configuserok,$author_ok,$switchserver) =
13702: &config_check($dom,$confname,$servadm);
1.9 raeburn 13703: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 13704: if (ref($domconfig->{$role}) ne 'HASH') {
13705: $domconfig->{$role} = {};
13706: }
1.8 raeburn 13707: foreach my $img (@images) {
1.402 raeburn 13708: if ($role eq 'login') {
13709: if (($img eq 'img') || ($img eq 'logo')) {
13710: if (defined($env{'form.login_showlogo_'.$img})) {
13711: $confhash->{$role}{'showlogo'}{$img} = 1;
13712: } else {
13713: $confhash->{$role}{'showlogo'}{$img} = 0;
13714: }
13715: }
13716: if ($env{'form.login_alt_'.$img} ne '') {
13717: $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
1.70 raeburn 13718: }
1.402 raeburn 13719: }
1.18 albertel 13720: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
13721: && !defined($domconfig->{$role}{$img})
13722: && !$env{'form.'.$role.'_del_'.$img}
13723: && $env{'form.'.$role.'_import_'.$img}) {
13724: # import the old configured image from the .tab setting
13725: # if they haven't provided a new one
13726: $domconfig->{$role}{$img} =
13727: $env{'form.'.$role.'_import_'.$img};
13728: }
1.6 raeburn 13729: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 13730: my $error;
1.6 raeburn 13731: if ($configuserok eq 'ok') {
1.9 raeburn 13732: if ($switchserver) {
1.12 raeburn 13733: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 13734: } else {
13735: if ($author_ok eq 'ok') {
1.421 raeburn 13736: my $modified = [];
1.9 raeburn 13737: my ($result,$logourl) =
1.421 raeburn 13738: &Apache::lonconfigsettings::publishlogo($r,'upload',$role.'_'.$img,
13739: $dom,$confname,$img,$width,$height,
13740: '',$modified);
1.9 raeburn 13741: if ($result eq 'ok') {
13742: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 13743: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13744: &update_modify_urls($r,$modified);
1.9 raeburn 13745: } else {
1.12 raeburn 13746: $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 13747: }
13748: } else {
1.46 raeburn 13749: $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 13750: }
13751: }
13752: } else {
1.46 raeburn 13753: $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 13754: }
13755: if ($error) {
1.8 raeburn 13756: &Apache::lonnet::logthis($error);
1.11 albertel 13757: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 13758: }
13759: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 13760: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
13761: my $error;
13762: if ($configuserok eq 'ok') {
13763: # is confname an author?
13764: if ($switchserver eq '') {
13765: if ($author_ok eq 'ok') {
1.421 raeburn 13766: my $modified = [];
1.9 raeburn 13767: my ($result,$logourl) =
1.421 raeburn 13768: &Apache::lonconfigsettings::publishlogo($r,'copy',$domconfig->{$role}{$img},
13769: $dom,$confname,$img,$width,$height,
13770: '',$modified);
1.9 raeburn 13771: if ($result eq 'ok') {
13772: $confhash->{$role}{$img} = $logourl;
1.18 albertel 13773: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13774: &update_modify_urls($r,$modified);
1.9 raeburn 13775: }
13776: }
13777: }
13778: }
1.6 raeburn 13779: }
13780: }
13781: }
13782: if (ref($domconfig) eq 'HASH') {
13783: if (ref($domconfig->{$role}) eq 'HASH') {
13784: foreach my $img (@images) {
13785: if ($domconfig->{$role}{$img} ne '') {
13786: if ($env{'form.'.$role.'_del_'.$img}) {
13787: $confhash->{$role}{$img} = '';
1.12 raeburn 13788: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13789: } else {
1.9 raeburn 13790: if ($confhash->{$role}{$img} eq '') {
13791: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
13792: }
1.6 raeburn 13793: }
13794: } else {
13795: if ($env{'form.'.$role.'_del_'.$img}) {
13796: $confhash->{$role}{$img} = '';
1.12 raeburn 13797: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13798: }
13799: }
1.402 raeburn 13800: if ($role eq 'login') {
13801: if (($img eq 'logo') || ($img eq 'img')) {
13802: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
13803: if ($confhash->{$role}{'showlogo'}{$img} ne
13804: $domconfig->{$role}{'showlogo'}{$img}) {
13805: $changes{$role}{'showlogo'}{$img} = 1;
13806: }
13807: } else {
13808: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13809: $changes{$role}{'showlogo'}{$img} = 1;
13810: }
1.70 raeburn 13811: }
1.402 raeburn 13812: }
13813: if ($img ne 'login') {
13814: if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
13815: if ($confhash->{$role}{'alttext'}{$img} ne
13816: $domconfig->{$role}{'alttext'}{$img}) {
13817: $changes{$role}{'alttext'}{$img} = 1;
13818: }
13819: } else {
13820: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13821: $changes{$role}{'alttext'}{$img} = 1;
13822: }
1.70 raeburn 13823: }
13824: }
13825: }
13826: }
1.6 raeburn 13827: if ($domconfig->{$role}{'font'} ne '') {
13828: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
13829: $changes{$role}{'font'} = 1;
13830: }
13831: } else {
13832: if ($confhash->{$role}{'font'}) {
13833: $changes{$role}{'font'} = 1;
13834: }
13835: }
1.107 raeburn 13836: if ($role ne 'login') {
13837: if ($domconfig->{$role}{'fontmenu'} ne '') {
13838: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
13839: $changes{$role}{'fontmenu'} = 1;
13840: }
13841: } else {
13842: if ($confhash->{$role}{'fontmenu'}) {
13843: $changes{$role}{'fontmenu'} = 1;
13844: }
1.97 tempelho 13845: }
13846: }
1.6 raeburn 13847: foreach my $item (@bgs) {
13848: if ($domconfig->{$role}{$item} ne '') {
13849: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13850: $changes{$role}{'bgs'}{$item} = 1;
13851: }
13852: } else {
13853: if ($confhash->{$role}{$item}) {
13854: $changes{$role}{'bgs'}{$item} = 1;
13855: }
13856: }
13857: }
13858: foreach my $item (@links) {
13859: if ($domconfig->{$role}{$item} ne '') {
13860: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13861: $changes{$role}{'links'}{$item} = 1;
13862: }
13863: } else {
13864: if ($confhash->{$role}{$item}) {
13865: $changes{$role}{'links'}{$item} = 1;
13866: }
13867: }
13868: }
1.41 raeburn 13869: foreach my $item (@logintext) {
13870: if ($domconfig->{$role}{$item} ne '') {
13871: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13872: $changes{$role}{'logintext'}{$item} = 1;
13873: }
13874: } else {
13875: if ($confhash->{$role}{$item}) {
13876: $changes{$role}{'logintext'}{$item} = 1;
13877: }
13878: }
13879: }
1.6 raeburn 13880: } else {
13881: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13882: \@logintext,$confhash,\%changes);
1.6 raeburn 13883: }
13884: } else {
13885: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13886: \@logintext,$confhash,\%changes);
1.6 raeburn 13887: }
13888: }
13889: return ($errors,%changes);
13890: }
13891:
1.46 raeburn 13892: sub config_check {
13893: my ($dom,$confname,$servadm) = @_;
13894: my ($configuserok,$author_ok,$switchserver,%currroles);
13895: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
13896: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
13897: $confname,$servadm);
13898: if ($configuserok eq 'ok') {
13899: $switchserver = &check_switchserver($dom,$confname);
13900: if ($switchserver eq '') {
13901: $author_ok = &check_authorstatus($dom,$confname,%currroles);
13902: }
13903: }
13904: return ($configuserok,$author_ok,$switchserver);
13905: }
13906:
1.6 raeburn 13907: sub default_change_checker {
1.41 raeburn 13908: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 13909: foreach my $item (@{$links}) {
13910: if ($confhash->{$role}{$item}) {
13911: $changes->{$role}{'links'}{$item} = 1;
13912: }
13913: }
13914: foreach my $item (@{$bgs}) {
13915: if ($confhash->{$role}{$item}) {
13916: $changes->{$role}{'bgs'}{$item} = 1;
13917: }
13918: }
1.41 raeburn 13919: foreach my $item (@{$logintext}) {
13920: if ($confhash->{$role}{$item}) {
13921: $changes->{$role}{'logintext'}{$item} = 1;
13922: }
13923: }
1.6 raeburn 13924: foreach my $img (@{$images}) {
13925: if ($env{'form.'.$role.'_del_'.$img}) {
13926: $confhash->{$role}{$img} = '';
1.12 raeburn 13927: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 13928: }
1.70 raeburn 13929: if ($role eq 'login') {
13930: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13931: $changes->{$role}{'showlogo'}{$img} = 1;
13932: }
1.402 raeburn 13933: if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
13934: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13935: $changes->{$role}{'alttext'}{$img} = 1;
13936: }
13937: }
1.70 raeburn 13938: }
1.6 raeburn 13939: }
13940: if ($confhash->{$role}{'font'}) {
13941: $changes->{$role}{'font'} = 1;
13942: }
1.48 raeburn 13943: }
1.6 raeburn 13944:
13945: sub display_colorchgs {
13946: my ($dom,$changes,$roles,$confhash) = @_;
13947: my (%choices,$resulttext);
13948: if (!grep(/^login$/,@{$roles})) {
13949: $resulttext = &mt('Changes made:').'<br />';
13950: }
13951: foreach my $role (@{$roles}) {
13952: if ($role eq 'login') {
13953: %choices = &login_choices();
13954: } else {
13955: %choices = &color_font_choices();
13956: }
13957: if (ref($changes->{$role}) eq 'HASH') {
13958: if ($role ne 'login') {
13959: $resulttext .= '<h4>'.&mt($role).'</h4>';
13960: }
13961: foreach my $key (sort(keys(%{$changes->{$role}}))) {
13962: if ($role ne 'login') {
13963: $resulttext .= '<ul>';
13964: }
13965: if (ref($changes->{$role}{$key}) eq 'HASH') {
13966: if ($role ne 'login') {
13967: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
13968: }
13969: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 13970: if (($role eq 'login') && ($key eq 'showlogo')) {
13971: if ($confhash->{$role}{$key}{$item}) {
13972: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
13973: } else {
13974: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
13975: }
1.402 raeburn 13976: } elsif (($role eq 'login') && ($key eq 'alttext')) {
13977: if ($confhash->{$role}{$key}{$item} ne '') {
1.403 raeburn 13978: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
1.402 raeburn 13979: $confhash->{$role}{$key}{$item}).'</li>';
13980: } else {
13981: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
13982: }
1.70 raeburn 13983: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 13984: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
13985: } else {
1.12 raeburn 13986: my $newitem = $confhash->{$role}{$item};
13987: if ($key eq 'images') {
1.306 raeburn 13988: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 13989: }
13990: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 13991: }
13992: }
13993: if ($role ne 'login') {
13994: $resulttext .= '</ul></li>';
13995: }
13996: } else {
13997: if ($confhash->{$role}{$key} eq '') {
13998: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
13999: } else {
14000: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
14001: }
14002: }
14003: if ($role ne 'login') {
14004: $resulttext .= '</ul>';
14005: }
14006: }
14007: }
14008: }
1.3 raeburn 14009: return $resulttext;
1.1 raeburn 14010: }
14011:
1.9 raeburn 14012: sub thumb_dimensions {
14013: return ('200','50');
14014: }
14015:
1.16 raeburn 14016: sub check_dimensions {
14017: my ($inputfile) = @_;
14018: my ($fullwidth,$fullheight);
14019: if ($inputfile =~ m|^[/\w.\-]+$|) {
14020: if (open(PIPE,"identify $inputfile 2>&1 |")) {
14021: my $imageinfo = <PIPE>;
14022: if (!close(PIPE)) {
14023: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
14024: }
14025: chomp($imageinfo);
14026: my ($fullsize) =
1.21 raeburn 14027: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 14028: if ($fullsize) {
14029: ($fullwidth,$fullheight) = split(/x/,$fullsize);
14030: }
14031: }
14032: }
14033: return ($fullwidth,$fullheight);
14034: }
14035:
1.9 raeburn 14036: sub check_configuser {
14037: my ($uhome,$dom,$confname,$servadm) = @_;
14038: my ($configuserok,%currroles);
14039: if ($uhome eq 'no_host') {
14040: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.361 raeburn 14041: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 14042: $configuserok =
14043: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
14044: $configpass,'','','','','',undef,$servadm);
14045: } else {
14046: $configuserok = 'ok';
14047: %currroles =
14048: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
14049: }
14050: return ($configuserok,%currroles);
14051: }
14052:
14053: sub check_authorstatus {
14054: my ($dom,$confname,%currroles) = @_;
14055: my $author_ok;
1.40 raeburn 14056: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 14057: my $start = time;
14058: my $end = 0;
14059: $author_ok =
14060: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 14061: 'au',$end,$start,'','','domconfig');
1.9 raeburn 14062: } else {
14063: $author_ok = 'ok';
14064: }
14065: return $author_ok;
14066: }
14067:
1.421 raeburn 14068: sub update_modify_urls {
14069: my ($r,$modified) = @_;
14070: if ((ref($modified) eq 'ARRAY') && (@{$modified})) {
14071: push(@{$modified_urls},$modified);
14072: unless ($registered_cleanup) {
14073: my $handlers = $r->get_handlers('PerlCleanupHandler');
14074: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
14075: $registered_cleanup=1;
1.9 raeburn 14076: }
14077: }
1.155 raeburn 14078: }
14079:
14080: sub notifysubscribed {
14081: foreach my $targetsource (@{$modified_urls}){
14082: next unless (ref($targetsource) eq 'ARRAY');
14083: my ($target,$source)=@{$targetsource};
14084: if ($source ne '') {
1.316 raeburn 14085: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 14086: print $logfh "\nCleanup phase: Notifications\n";
14087: my @subscribed=&subscribed_hosts($target);
14088: foreach my $subhost (@subscribed) {
14089: print $logfh "\nNotifying host ".$subhost.':';
14090: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
14091: print $logfh $reply;
14092: }
14093: my @subscribedmeta=&subscribed_hosts("$target.meta");
14094: foreach my $subhost (@subscribedmeta) {
14095: print $logfh "\nNotifying host for metadata only ".$subhost.':';
14096: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
14097: $subhost);
14098: print $logfh $reply;
14099: }
14100: print $logfh "\n============ Done ============\n";
1.160 raeburn 14101: close($logfh);
1.155 raeburn 14102: }
14103: }
14104: }
14105: return OK;
14106: }
14107:
14108: sub subscribed_hosts {
14109: my ($target) = @_;
14110: my @subscribed;
1.316 raeburn 14111: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 14112: while (my $subline=<$fh>) {
14113: if ($subline =~ /^($match_lonid):/) {
14114: my $host = $1;
14115: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
14116: unless (grep(/^\Q$host\E$/,@subscribed)) {
14117: push(@subscribed,$host);
14118: }
14119: }
14120: }
14121: }
14122: }
14123: return @subscribed;
1.9 raeburn 14124: }
14125:
14126: sub check_switchserver {
14127: my ($dom,$confname) = @_;
1.424 raeburn 14128: my ($allowed,$switchserver,$home);
14129: if ($confname eq '') {
1.9 raeburn 14130: $home = &Apache::lonnet::domain($dom,'primary');
1.424 raeburn 14131: } else {
14132: $home = &Apache::lonnet::homeserver($confname,$dom);
14133: if ($home eq 'no_host') {
14134: $home = &Apache::lonnet::domain($dom,'primary');
14135: }
1.9 raeburn 14136: }
14137: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 14138: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
14139: if (!$allowed) {
1.426 raeburn 14140: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
14141: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
14142: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 14143: }
14144: return $switchserver;
14145: }
14146:
1.1 raeburn 14147: sub modify_quotas {
1.216 raeburn 14148: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 14149: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 14150: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 14151: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
14152: $validationfieldsref);
1.86 raeburn 14153: if ($action eq 'quotas') {
1.429 raeburn 14154: $context = 'tools';
1.163 raeburn 14155: } else {
1.86 raeburn 14156: $context = $action;
14157: }
14158: if ($context eq 'requestcourses') {
1.325 raeburn 14159: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 14160: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 14161: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
14162: %titles = &courserequest_titles();
14163: $toolregexp = join('|',@usertools);
14164: %conditions = &courserequest_conditions();
1.216 raeburn 14165: $confname = $dom.'-domainconfig';
14166: my $servadm = $r->dir_config('lonAdmEMail');
14167: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 14168: ($validationitemsref,$validationnamesref,$validationfieldsref) =
14169: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 14170: } elsif ($context eq 'requestauthor') {
14171: @usertools = ('author');
14172: %titles = &authorrequest_titles();
1.86 raeburn 14173: } else {
1.430 raeburn 14174: @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.101 raeburn 14175: %titles = &tool_titles();
1.86 raeburn 14176: }
1.212 raeburn 14177: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 14178: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 14179: foreach my $key (keys(%env)) {
1.101 raeburn 14180: if ($context eq 'requestcourses') {
14181: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
14182: my $item = $1;
14183: my $type = $2;
14184: if ($type =~ /^limit_(.+)/) {
14185: $limithash{$item}{$1} = $env{$key};
14186: } else {
14187: $confhash{$item}{$type} = $env{$key};
14188: }
14189: }
1.163 raeburn 14190: } elsif ($context eq 'requestauthor') {
14191: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
14192: $confhash{$1} = $env{$key};
14193: }
1.101 raeburn 14194: } else {
1.86 raeburn 14195: if ($key =~ /^form\.quota_(.+)$/) {
14196: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 14197: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 14198: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
14199: }
1.72 raeburn 14200: }
14201: }
1.163 raeburn 14202: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 14203: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 14204: @approvalnotify = sort(@approvalnotify);
14205: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 14206: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 14207: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
14208: foreach my $type (@hasuniquecode) {
14209: if (grep(/^\Q$type\E$/,@crstypes)) {
14210: $confhash{'uniquecode'}{$type} = 1;
14211: }
1.216 raeburn 14212: }
1.242 raeburn 14213: my (%newbook,%allpos);
1.216 raeburn 14214: if ($context eq 'requestcourses') {
1.242 raeburn 14215: foreach my $type ('textbooks','templates') {
14216: @{$allpos{$type}} = ();
14217: my $invalid;
14218: if ($type eq 'textbooks') {
14219: $invalid = &mt('Invalid LON-CAPA course for textbook');
14220: } else {
14221: $invalid = &mt('Invalid LON-CAPA course for template');
14222: }
14223: if ($env{'form.'.$type.'_addbook'}) {
14224: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
14225: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
14226: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
14227: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
14228: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
14229: } else {
14230: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
14231: my $position = $env{'form.'.$type.'_addbook_pos'};
14232: $position =~ s/\D+//g;
14233: if ($position ne '') {
14234: $allpos{$type}[$position] = $newbook{$type};
14235: }
1.216 raeburn 14236: }
1.242 raeburn 14237: } else {
14238: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 14239: }
14240: }
1.242 raeburn 14241: }
1.216 raeburn 14242: }
1.102 raeburn 14243: if (ref($domconfig{$action}) eq 'HASH') {
14244: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
14245: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
14246: $changes{'notify'}{'approval'} = 1;
14247: }
14248: } else {
1.144 raeburn 14249: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14250: $changes{'notify'}{'approval'} = 1;
14251: }
14252: }
1.218 raeburn 14253: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
14254: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14255: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
14256: unless ($confhash{'uniquecode'}{$crstype}) {
14257: $changes{'uniquecode'} = 1;
14258: }
14259: }
14260: unless ($changes{'uniquecode'}) {
14261: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
14262: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
14263: $changes{'uniquecode'} = 1;
14264: }
14265: }
14266: }
14267: } else {
14268: $changes{'uniquecode'} = 1;
14269: }
14270: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
14271: $changes{'uniquecode'} = 1;
1.216 raeburn 14272: }
14273: if ($context eq 'requestcourses') {
1.242 raeburn 14274: foreach my $type ('textbooks','templates') {
14275: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14276: my %deletions;
14277: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
14278: if (@todelete) {
14279: map { $deletions{$_} = 1; } @todelete;
14280: }
14281: my %imgdeletions;
14282: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
14283: if (@todeleteimages) {
14284: map { $imgdeletions{$_} = 1; } @todeleteimages;
14285: }
14286: my $maxnum = $env{'form.'.$type.'_maxnum'};
14287: for (my $i=0; $i<=$maxnum; $i++) {
14288: my $itemid = $env{'form.'.$type.'_id_'.$i};
14289: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
14290: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
14291: if ($deletions{$key}) {
14292: if ($domconfig{$action}{$type}{$key}{'image'}) {
14293: #FIXME need to obsolete item in RES space
14294: }
14295: next;
14296: } else {
14297: my $newpos = $env{'form.'.$itemid};
14298: $newpos =~ s/\D+//g;
1.243 raeburn 14299: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 14300: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 14301: ($type eq 'templates'));
1.242 raeburn 14302: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
14303: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
14304: $changes{$type}{$key} = 1;
14305: }
14306: }
14307: $allpos{$type}[$newpos] = $key;
14308: }
14309: if ($imgdeletions{$key}) {
14310: $changes{$type}{$key} = 1;
1.216 raeburn 14311: #FIXME need to obsolete item in RES space
1.242 raeburn 14312: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
14313: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 14314: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14315: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14316: } else {
14317: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
14318: $cdom,$cnum,$type,$configuserok,
14319: $switchserver,$author_ok);
14320: if ($imgurl) {
14321: $confhash{$type}{$key}{'image'} = $imgurl;
14322: $changes{$type}{$key} = 1;
14323: }
14324: if ($error) {
14325: &Apache::lonnet::logthis($error);
14326: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14327: }
14328: }
1.242 raeburn 14329: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
14330: $confhash{$type}{$key}{'image'} =
14331: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 14332: }
14333: }
14334: }
14335: }
14336: }
14337: }
1.102 raeburn 14338: } else {
1.144 raeburn 14339: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14340: $changes{'notify'}{'approval'} = 1;
14341: }
1.218 raeburn 14342: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 14343: $changes{'uniquecode'} = 1;
14344: }
14345: }
14346: if ($context eq 'requestcourses') {
1.242 raeburn 14347: foreach my $type ('textbooks','templates') {
14348: if ($newbook{$type}) {
14349: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 14350: foreach my $item ('subject','title','publisher','author') {
14351: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14352: ($type eq 'template'));
1.242 raeburn 14353: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
14354: if ($env{'form.'.$type.'_addbook_'.$item}) {
14355: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
14356: }
14357: }
14358: if ($type eq 'textbooks') {
14359: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
14360: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 14361: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14362: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14363: } else {
14364: my ($imageurl,$error) =
14365: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
14366: $configuserok,$switchserver,$author_ok);
14367: if ($imageurl) {
14368: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
14369: }
14370: if ($error) {
14371: &Apache::lonnet::logthis($error);
14372: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14373: }
1.242 raeburn 14374: }
14375: }
1.216 raeburn 14376: }
14377: }
1.242 raeburn 14378: if (@{$allpos{$type}} > 0) {
14379: my $idx = 0;
14380: foreach my $item (@{$allpos{$type}}) {
14381: if ($item ne '') {
14382: $confhash{$type}{$item}{'order'} = $idx;
14383: if (ref($domconfig{$action}) eq 'HASH') {
14384: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14385: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
14386: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
14387: $changes{$type}{$item} = 1;
14388: }
1.216 raeburn 14389: }
14390: }
14391: }
1.242 raeburn 14392: $idx ++;
1.216 raeburn 14393: }
14394: }
14395: }
14396: }
1.235 raeburn 14397: if (ref($validationitemsref) eq 'ARRAY') {
14398: foreach my $item (@{$validationitemsref}) {
14399: if ($item eq 'fields') {
14400: my @changed;
14401: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
14402: if (@{$confhash{'validation'}{$item}} > 0) {
14403: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
14404: }
1.266 raeburn 14405: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14406: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14407: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
14408: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
14409: $domconfig{'requestcourses'}{'validation'}{$item});
14410: } else {
14411: @changed = @{$confhash{'validation'}{$item}};
14412: }
1.235 raeburn 14413: } else {
14414: @changed = @{$confhash{'validation'}{$item}};
14415: }
14416: } else {
14417: @changed = @{$confhash{'validation'}{$item}};
14418: }
14419: if (@changed) {
14420: if ($confhash{'validation'}{$item}) {
14421: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
14422: } else {
14423: $changes{'validation'}{$item} = &mt('None');
14424: }
14425: }
14426: } else {
14427: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
14428: if ($item eq 'markup') {
14429: if ($env{'form.requestcourses_validation_'.$item}) {
14430: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
14431: }
14432: }
1.266 raeburn 14433: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14434: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14435: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
14436: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14437: }
14438: } else {
14439: if ($confhash{'validation'}{$item} ne '') {
14440: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14441: }
1.235 raeburn 14442: }
14443: } else {
14444: if ($confhash{'validation'}{$item} ne '') {
14445: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14446: }
14447: }
14448: }
14449: }
14450: }
14451: if ($env{'form.validationdc'}) {
14452: my $newval = $env{'form.validationdc'};
1.285 raeburn 14453: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 14454: if (exists($domcoords{$newval})) {
14455: $confhash{'validation'}{'dc'} = $newval;
14456: }
14457: }
14458: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 14459: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14460: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14461: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14462: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
14463: if ($confhash{'validation'}{'dc'} eq '') {
14464: $changes{'validation'}{'dc'} = &mt('None');
14465: } else {
14466: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14467: }
1.235 raeburn 14468: }
1.266 raeburn 14469: } elsif ($confhash{'validation'}{'dc'} ne '') {
14470: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 14471: }
14472: } elsif ($confhash{'validation'}{'dc'} ne '') {
14473: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14474: }
14475: } elsif ($confhash{'validation'}{'dc'} ne '') {
14476: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 14477: }
1.266 raeburn 14478: } else {
14479: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14480: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14481: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14482: $changes{'validation'}{'dc'} = &mt('None');
14483: }
14484: }
1.235 raeburn 14485: }
14486: }
1.102 raeburn 14487: }
14488: } else {
1.86 raeburn 14489: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
14490: }
1.72 raeburn 14491: foreach my $item (@usertools) {
14492: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 14493: my $unset;
1.101 raeburn 14494: if ($context eq 'requestcourses') {
1.104 raeburn 14495: $unset = '0';
14496: if ($type eq '_LC_adv') {
14497: $unset = '';
14498: }
1.101 raeburn 14499: if ($confhash{$item}{$type} eq 'autolimit') {
14500: $confhash{$item}{$type} .= '=';
14501: unless ($limithash{$item}{$type} =~ /\D/) {
14502: $confhash{$item}{$type} .= $limithash{$item}{$type};
14503: }
14504: }
1.163 raeburn 14505: } elsif ($context eq 'requestauthor') {
14506: $unset = '0';
14507: if ($type eq '_LC_adv') {
14508: $unset = '';
14509: }
1.72 raeburn 14510: } else {
1.101 raeburn 14511: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
14512: $confhash{$item}{$type} = 1;
14513: } else {
14514: $confhash{$item}{$type} = 0;
14515: }
1.72 raeburn 14516: }
1.86 raeburn 14517: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 14518: if ($action eq 'requestauthor') {
14519: if ($domconfig{$action}{$type} ne $confhash{$type}) {
14520: $changes{$type} = 1;
14521: }
14522: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 14523: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
14524: $changes{$item}{$type} = 1;
14525: }
14526: } else {
14527: if ($context eq 'requestcourses') {
1.104 raeburn 14528: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 14529: $changes{$item}{$type} = 1;
14530: }
14531: } else {
14532: if (!$confhash{$item}{$type}) {
14533: $changes{$item}{$type} = 1;
14534: }
14535: }
14536: }
14537: } else {
14538: if ($context eq 'requestcourses') {
1.104 raeburn 14539: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 14540: $changes{$item}{$type} = 1;
14541: }
1.163 raeburn 14542: } elsif ($context eq 'requestauthor') {
14543: if ($confhash{$type} ne $unset) {
14544: $changes{$type} = 1;
14545: }
1.72 raeburn 14546: } else {
14547: if (!$confhash{$item}{$type}) {
14548: $changes{$item}{$type} = 1;
14549: }
14550: }
14551: }
1.1 raeburn 14552: }
14553: }
1.163 raeburn 14554: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 14555: if (ref($domconfig{'quotas'}) eq 'HASH') {
14556: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14557: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
14558: if (exists($confhash{'defaultquota'}{$key})) {
14559: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
14560: $changes{'defaultquota'}{$key} = 1;
14561: }
14562: } else {
14563: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 14564: }
14565: }
1.86 raeburn 14566: } else {
14567: foreach my $key (keys(%{$domconfig{'quotas'}})) {
14568: if (exists($confhash{'defaultquota'}{$key})) {
14569: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
14570: $changes{'defaultquota'}{$key} = 1;
14571: }
14572: } else {
14573: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 14574: }
1.1 raeburn 14575: }
14576: }
1.197 raeburn 14577: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
1.429 raeburn 14578: $confhash{'authorquota'} = $domconfig{'quotas'}{'authorquota'};
14579: }
14580: if (ref($domconfig{'quotas'}{'webdav'}) eq 'HASH') {
14581: $confhash{'webdav'} = $domconfig{'quotas'}{'webdav'};
1.197 raeburn 14582: }
1.1 raeburn 14583: }
1.86 raeburn 14584: if (ref($confhash{'defaultquota'}) eq 'HASH') {
14585: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
14586: if (ref($domconfig{'quotas'}) eq 'HASH') {
14587: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14588: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
14589: $changes{'defaultquota'}{$key} = 1;
14590: }
14591: } else {
14592: if (!exists($domconfig{'quotas'}{$key})) {
14593: $changes{'defaultquota'}{$key} = 1;
14594: }
1.72 raeburn 14595: }
14596: } else {
1.86 raeburn 14597: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 14598: }
1.1 raeburn 14599: }
14600: }
14601: }
1.72 raeburn 14602:
1.163 raeburn 14603: if ($context eq 'requestauthor') {
14604: $domdefaults{'requestauthor'} = \%confhash;
14605: } else {
14606: foreach my $key (keys(%confhash)) {
1.242 raeburn 14607: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 14608: $domdefaults{$key} = $confhash{$key};
14609: }
1.163 raeburn 14610: }
1.72 raeburn 14611: }
1.163 raeburn 14612:
1.1 raeburn 14613: my %quotahash = (
1.86 raeburn 14614: $action => { %confhash }
1.1 raeburn 14615: );
14616: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
14617: $dom);
14618: if ($putresult eq 'ok') {
14619: if (keys(%changes) > 0) {
1.72 raeburn 14620: my $cachetime = 24*60*60;
14621: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 14622: if (ref($lastactref) eq 'HASH') {
14623: $lastactref->{'domdefaults'} = 1;
14624: }
1.1 raeburn 14625: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 14626: unless (($context eq 'requestcourses') ||
1.163 raeburn 14627: ($context eq 'requestauthor')) {
1.86 raeburn 14628: if (ref($changes{'defaultquota'}) eq 'HASH') {
14629: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
14630: foreach my $type (@{$types},'default') {
14631: if (defined($changes{'defaultquota'}{$type})) {
14632: my $typetitle = $usertypes->{$type};
14633: if ($type eq 'default') {
14634: $typetitle = $othertitle;
14635: }
1.213 raeburn 14636: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 14637: }
14638: }
1.86 raeburn 14639: $resulttext .= '</ul></li>';
1.72 raeburn 14640: }
14641: }
1.80 raeburn 14642: my %newenv;
1.72 raeburn 14643: foreach my $item (@usertools) {
1.163 raeburn 14644: my (%haschgs,%inconf);
14645: if ($context eq 'requestauthor') {
14646: %haschgs = %changes;
1.210 raeburn 14647: %inconf = %confhash;
1.163 raeburn 14648: } else {
14649: if (ref($changes{$item}) eq 'HASH') {
14650: %haschgs = %{$changes{$item}};
14651: }
14652: if (ref($confhash{$item}) eq 'HASH') {
14653: %inconf = %{$confhash{$item}};
14654: }
14655: }
14656: if (keys(%haschgs) > 0) {
1.80 raeburn 14657: my $newacc =
14658: &Apache::lonnet::usertools_access($env{'user.name'},
14659: $env{'user.domain'},
1.86 raeburn 14660: $item,'reload',$context);
1.210 raeburn 14661: if (($context eq 'requestcourses') ||
1.163 raeburn 14662: ($context eq 'requestauthor')) {
1.108 raeburn 14663: if ($env{'environment.canrequest.'.$item} ne $newacc) {
14664: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 14665: }
14666: } else {
14667: if ($env{'environment.availabletools.'.$item} ne $newacc) {
14668: $newenv{'environment.availabletools.'.$item} = $newacc;
14669: }
1.80 raeburn 14670: }
1.163 raeburn 14671: unless ($context eq 'requestauthor') {
14672: $resulttext .= '<li>'.$titles{$item}.'<ul>';
14673: }
1.72 raeburn 14674: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 14675: if ($haschgs{$type}) {
1.72 raeburn 14676: my $typetitle = $usertypes->{$type};
14677: if ($type eq 'default') {
14678: $typetitle = $othertitle;
14679: } elsif ($type eq '_LC_adv') {
14680: $typetitle = 'LON-CAPA Advanced Users';
14681: }
1.163 raeburn 14682: if ($inconf{$type}) {
1.101 raeburn 14683: if ($context eq 'requestcourses') {
14684: my $cond;
1.163 raeburn 14685: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 14686: if ($1 eq '') {
14687: $cond = &mt('(Automatic processing of any request).');
14688: } else {
14689: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
14690: }
14691: } else {
1.163 raeburn 14692: $cond = $conditions{$inconf{$type}};
1.101 raeburn 14693: }
14694: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 14695: } elsif ($context eq 'requestauthor') {
14696: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
14697: $titles{$inconf{$type}},$typetitle);
14698:
1.101 raeburn 14699: } else {
14700: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
14701: }
1.72 raeburn 14702: } else {
1.104 raeburn 14703: if ($type eq '_LC_adv') {
1.163 raeburn 14704: if ($inconf{$type} eq '0') {
1.104 raeburn 14705: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14706: } else {
14707: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
14708: }
14709: } else {
14710: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14711: }
1.72 raeburn 14712: }
14713: }
1.26 raeburn 14714: }
1.163 raeburn 14715: unless ($context eq 'requestauthor') {
14716: $resulttext .= '</ul></li>';
14717: }
1.26 raeburn 14718: }
1.1 raeburn 14719: }
1.163 raeburn 14720: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 14721: if (ref($changes{'notify'}) eq 'HASH') {
14722: if ($changes{'notify'}{'approval'}) {
14723: if (ref($confhash{'notify'}) eq 'HASH') {
14724: if ($confhash{'notify'}{'approval'}) {
14725: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
14726: } else {
1.163 raeburn 14727: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 14728: }
14729: }
14730: }
14731: }
14732: }
1.216 raeburn 14733: if ($action eq 'requestcourses') {
14734: my @offon = ('off','on');
14735: if ($changes{'uniquecode'}) {
1.218 raeburn 14736: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14737: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
14738: $resulttext .= '<li>'.
14739: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
14740: '</li>';
14741: } else {
14742: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
14743: '</li>';
14744: }
1.216 raeburn 14745: }
1.242 raeburn 14746: foreach my $type ('textbooks','templates') {
14747: if (ref($changes{$type}) eq 'HASH') {
14748: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
14749: foreach my $key (sort(keys(%{$changes{$type}}))) {
14750: my %coursehash = &Apache::lonnet::coursedescription($key);
14751: my $coursetitle = $coursehash{'description'};
14752: my $position = $confhash{$type}{$key}{'order'} + 1;
14753: $resulttext .= '<li>';
1.243 raeburn 14754: foreach my $item ('subject','title','publisher','author') {
14755: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14756: ($type eq 'templates'));
1.242 raeburn 14757: my $name = $item.':';
14758: $name =~ s/^(\w)/\U$1/;
14759: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
14760: }
14761: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
14762: if ($type eq 'textbooks') {
14763: if ($confhash{$type}{$key}{'image'}) {
14764: $resulttext .= ' '.&mt('Image: [_1]',
14765: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
14766: ' alt="Textbook cover" />').'<br />';
14767: }
14768: }
14769: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 14770: }
1.242 raeburn 14771: $resulttext .= '</ul></li>';
1.216 raeburn 14772: }
14773: }
1.235 raeburn 14774: if (ref($changes{'validation'}) eq 'HASH') {
14775: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
14776: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
14777: foreach my $item (@{$validationitemsref}) {
14778: if (exists($changes{'validation'}{$item})) {
14779: if ($item eq 'markup') {
14780: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14781: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
14782: } else {
14783: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14784: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
14785: }
14786: }
14787: }
14788: if (exists($changes{'validation'}{'dc'})) {
14789: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
14790: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
14791: }
14792: }
14793: }
1.216 raeburn 14794: }
1.1 raeburn 14795: $resulttext .= '</ul>';
1.80 raeburn 14796: if (keys(%newenv)) {
14797: &Apache::lonnet::appenv(\%newenv);
14798: }
1.1 raeburn 14799: } else {
1.86 raeburn 14800: if ($context eq 'requestcourses') {
14801: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 14802: } elsif ($context eq 'requestauthor') {
14803: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 14804: } else {
1.90 weissno 14805: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 14806: }
1.1 raeburn 14807: }
14808: } else {
1.11 albertel 14809: $resulttext = '<span class="LC_error">'.
14810: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14811: }
1.216 raeburn 14812: if ($errors) {
14813: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
14814: '<ul>'.$errors.'</ul></p>';
14815: }
1.3 raeburn 14816: return $resulttext;
1.1 raeburn 14817: }
14818:
1.216 raeburn 14819: sub process_textbook_image {
1.242 raeburn 14820: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 14821: my $filename = $env{'form.'.$caller.'.filename'};
14822: my ($error,$url);
14823: my ($width,$height) = (50,50);
14824: if ($configuserok eq 'ok') {
14825: if ($switchserver) {
14826: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
14827: $switchserver);
14828: } elsif ($author_ok eq 'ok') {
1.421 raeburn 14829: my $modified = [];
1.216 raeburn 14830: my ($result,$imageurl) =
1.421 raeburn 14831: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
14832: "$type/$cdom/$cnum/cover",$width,$height,
14833: '',$modified);
1.216 raeburn 14834: if ($result eq 'ok') {
14835: $url = $imageurl;
1.421 raeburn 14836: &update_modify_urls($r,$modified);
1.216 raeburn 14837: } else {
14838: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14839: }
14840: } else {
14841: $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);
14842: }
14843: } else {
14844: $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);
14845: }
14846: return ($url,$error);
14847: }
14848:
1.267 raeburn 14849: sub modify_ltitools {
14850: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.421 raeburn 14851: my (%currtoolsec,%secchanges,%newtoolsec,%newkeyset);
14852: &fetch_secrets($dom,'toolsec',\%domconfig,\%currtoolsec,\%secchanges,\%newtoolsec,\%newkeyset);
14853:
1.267 raeburn 14854: my $confname = $dom.'-domainconfig';
14855: my $servadm = $r->dir_config('lonAdmEMail');
14856: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.421 raeburn 14857:
14858: my ($resulttext,$ltitoolsoutput,$is_home,$errors,%ltitoolschg,%newtoolsenc,%newltitools);
14859: my $toolserror =
14860: &Apache::courseprefs::process_ltitools($r,$dom,$confname,$domconfig{'ltitools'},\%ltitoolschg,'domain',
14861: $lastactref,$configuserok,$switchserver,$author_ok);
14862:
14863: my $home = &Apache::lonnet::domain($dom,'primary');
14864: unless (($home eq 'no_host') || ($home eq '')) {
14865: my @ids=&Apache::lonnet::current_machine_ids();
14866: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; last; } }
14867: }
14868:
14869: if (keys(%ltitoolschg)) {
14870: foreach my $id (keys(%ltitoolschg)) {
14871: if (ref($ltitoolschg{$id}) eq 'HASH') {
14872: foreach my $inner (keys(%{$ltitoolschg{$id}})) {
14873: if (($inner eq 'secret') || ($inner eq 'key')) {
14874: if ($is_home) {
14875: $newtoolsenc{$id}{$inner} = $ltitoolschg{$id}{$inner};
14876: }
14877: }
14878: }
1.267 raeburn 14879: }
1.421 raeburn 14880: }
14881: $ltitoolsoutput = &Apache::courseprefs::store_ltitools($dom,'','domain',\%ltitoolschg,$domconfig{'ltitools'});
14882: if (keys(%ltitoolschg)) {
14883: %newltitools = %ltitoolschg;
14884: }
14885: }
14886: if (ref($domconfig{'ltitools'}) eq 'HASH') {
14887: foreach my $id (%{$domconfig{'ltitools'}}) {
14888: next if ($id !~ /^\d+$/);
14889: unless (exists($ltitoolschg{$id})) {
14890: if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
14891: foreach my $inner (keys(%{$domconfig{'ltitools'}{$id}})) {
14892: if (($inner eq 'secret') || ($inner eq 'key')) {
14893: if ($is_home) {
14894: $newtoolsenc{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14895: }
14896: } else {
14897: $newltitools{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14898: }
14899: }
14900: } else {
14901: $newltitools{$id} = $domconfig{'ltitools'}{$id};
1.322 raeburn 14902: }
1.421 raeburn 14903: }
14904: }
14905: }
14906: if ($toolserror) {
14907: $errors = '<li>'.$toolserror.'</li>';
14908: }
14909: if ((keys(%ltitoolschg) == 0) && (keys(%secchanges) == 0)) {
14910: $resulttext = &mt('No changes made.');
14911: if ($errors) {
14912: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
14913: $errors.'</ul>';
14914: }
14915: return $resulttext;
14916: }
14917: my %ltitoolshash = (
14918: $action => { %newltitools }
14919: );
14920: if (keys(%secchanges)) {
14921: $ltitoolshash{'toolsec'} = \%newtoolsec;
14922: }
14923: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,$dom);
14924: if ($putresult eq 'ok') {
14925: my %keystore;
14926: if ($is_home) {
14927: my %toolsenchash = (
14928: $action => { %newtoolsenc }
14929: );
14930: &Apache::lonnet::put_dom('encconfig',\%toolsenchash,$dom,undef,1);
1.423 raeburn 14931: my $cachetime = 24*60*60;
14932: &Apache::lonnet::do_cache_new('ltitoolsenc',$dom,\%newtoolsenc,$cachetime);
1.421 raeburn 14933: &store_security($dom,'ltitools',\%secchanges,\%newkeyset,\%keystore,$lastactref);
14934: }
14935: $resulttext = &mt('Changes made:').'<ul>';
14936: if (keys(%secchanges) > 0) {
1.423 raeburn 14937: $resulttext .= <i_security_results($dom,'ltitools',\%secchanges,\%newtoolsec,\%newkeyset,\%keystore);
1.421 raeburn 14938: }
14939: if (keys(%ltitoolschg) > 0) {
14940: $resulttext .= $ltitoolsoutput;
14941: }
1.423 raeburn 14942: my $cachetime = 24*60*60;
14943: &Apache::lonnet::do_cache_new('ltitools',$dom,\%newltitools,$cachetime);
14944: if (ref($lastactref) eq 'HASH') {
14945: $lastactref->{'ltitools'} = 1;
14946: }
1.421 raeburn 14947: } else {
14948: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
14949: }
14950: if ($errors) {
14951: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
14952: $errors.'</ul></p>';
14953: }
14954: return $resulttext;
14955: }
14956:
14957: sub fetch_secrets {
14958: my ($dom,$context,$domconfig,$currsec,$secchanges,$newsec,$newkeyset) = @_;
14959: my %keyset;
14960: %{$currsec} = ();
14961: $newsec->{'private'}{'keys'} = [];
14962: $newsec->{'encrypt'} = {};
14963: $newsec->{'rules'} = {};
14964: if ($context eq 'ltisec') {
14965: $newsec->{'linkprot'} = {};
14966: }
14967: if (ref($domconfig->{$context}) eq 'HASH') {
14968: %{$currsec} = %{$domconfig->{$context}};
14969: if ($context eq 'ltisec') {
14970: if (ref($currsec->{'linkprot'}) eq 'HASH') {
14971: foreach my $id (keys(%{$currsec->{'linkprot'}})) {
14972: unless ($id =~ /^\d+$/) {
14973: delete($currsec->{'linkprot'}{$id});
1.297 raeburn 14974: }
1.267 raeburn 14975: }
14976: }
1.421 raeburn 14977: }
14978: if (ref($currsec->{'private'}) eq 'HASH') {
14979: if (ref($currsec->{'private'}{'keys'}) eq 'ARRAY') {
14980: $newsec->{'private'}{'keys'} = $currsec->{'private'}{'keys'};
14981: map { $keyset{$_} = 1; } @{$currsec->{'private'}{'keys'}};
1.267 raeburn 14982: }
1.421 raeburn 14983: }
14984: }
14985: my @items= ('crs','dom');
14986: if ($context eq 'ltisec') {
14987: push(@items,'consumers');
14988: }
14989: foreach my $item (@items) {
14990: my $formelement;
14991: if (($context eq 'toolsec') || ($item eq 'consumers')) {
14992: $formelement = 'form.'.$context.'_'.$item;
14993: } else {
14994: $formelement = 'form.'.$context.'_'.$item.'linkprot';
14995: }
14996: if ($env{$formelement}) {
14997: $newsec->{'encrypt'}{$item} = 1;
14998: if (ref($currsec->{'encrypt'}) eq 'HASH') {
14999: unless ($currsec->{'encrypt'}{$item}) {
15000: $secchanges->{'encrypt'} = 1;
15001: }
15002: } else {
15003: $secchanges->{'encrypt'} = 1;
1.267 raeburn 15004: }
1.421 raeburn 15005: } elsif (ref($currsec->{'encrypt'}) eq 'HASH') {
15006: if ($currsec->{'encrypt'}{$item}) {
15007: $secchanges->{'encrypt'} = 1;
1.323 raeburn 15008: }
1.421 raeburn 15009: }
15010: }
15011: my $secrets;
15012: if ($context eq 'ltisec') {
15013: $secrets = 'ltisecrets';
15014: } else {
15015: $secrets = 'toolsecrets';
15016: }
15017: unless (exists($currsec->{'rules'})) {
15018: $currsec->{'rules'} = {};
15019: }
15020: &password_rule_changes($secrets,$newsec->{'rules'},$currsec->{'rules'},$secchanges);
15021:
15022: my @ids=&Apache::lonnet::current_machine_ids();
15023: my %servers = &Apache::lonnet::get_servers($dom,'library');
15024:
15025: foreach my $hostid (keys(%servers)) {
15026: if (($hostid ne '') && (grep(/^\Q$hostid\E$/,@ids))) {
15027: my $keyitem = 'form.'.$context.'_privkey_'.$hostid;
15028: if (exists($env{$keyitem})) {
15029: $env{$keyitem} =~ s/(`)/'/g;
15030: if ($keyset{$hostid}) {
15031: if ($env{'form.'.$context.'_changeprivkey_'.$hostid}) {
15032: if ($env{$keyitem} ne '') {
15033: $secchanges->{'private'} = 1;
15034: $newkeyset->{$hostid} = $env{$keyitem};
15035: }
1.296 raeburn 15036: }
1.421 raeburn 15037: } elsif ($env{$keyitem} ne '') {
15038: unless (grep(/^\Q$hostid\E$/,@{$newsec->{'private'}{'keys'}})) {
15039: push(@{$newsec->{'private'}{'keys'}},$hostid);
1.296 raeburn 15040: }
1.421 raeburn 15041: $secchanges->{'private'} = 1;
15042: $newkeyset->{$hostid} = $env{$keyitem};
1.267 raeburn 15043: }
15044: }
1.421 raeburn 15045: }
15046: }
15047: }
15048:
15049: sub store_security {
1.424 raeburn 15050: my ($dom,$context,$secchanges,$newkeyset,$keystore) = @_;
1.421 raeburn 15051: return unless ((ref($secchanges) eq 'HASH') && (ref($newkeyset) eq 'HASH') &&
15052: (ref($keystore) eq 'HASH'));
15053: if (keys(%{$secchanges})) {
15054: if ($secchanges->{'private'}) {
15055: my $who = &escape($env{'user.name'}.':'.$env{'user.domain'});
15056: foreach my $hostid (keys(%{$newkeyset})) {
15057: my $storehash = {
15058: key => $newkeyset->{$hostid},
15059: who => $env{'user.name'}.':'.$env{'user.domain'},
15060: };
15061: $keystore->{$hostid} = &Apache::lonnet::store_dom($storehash,$context,'private',
15062: $dom,$hostid);
15063: }
15064: }
15065: }
15066: }
15067:
15068: sub lti_security_results {
1.423 raeburn 15069: my ($dom,$context,$secchanges,$newsec,$newkeyset,$keystore) = @_;
1.421 raeburn 15070: my $output;
1.423 raeburn 15071: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
15072: my $needs_update;
1.421 raeburn 15073: foreach my $item (keys(%{$secchanges})) {
15074: if ($item eq 'encrypt') {
1.423 raeburn 15075: $needs_update = 1;
1.421 raeburn 15076: my %encrypted;
15077: if ($context eq 'lti') {
15078: %encrypted = (
15079: crs => {
15080: on => &mt('Encryption of stored link protection secrets defined in courses enabled'),
15081: off => &mt('Encryption of stored link protection secrets defined in courses disabled'),
15082: },
15083: dom => {
15084: on => &mt('Encryption of stored link protection secrets defined in domain enabled'),
15085: off => &mt('Encryption of stored link protection secrets defined in domain disabled'),
15086: },
15087: consumers => {
15088: on => &mt('Encryption of stored consumer secrets defined in domain enabled'),
15089: off => &mt('Encryption of stored consumer secrets defined in domain disabled'),
15090: },
15091: );
1.267 raeburn 15092: } else {
1.421 raeburn 15093: %encrypted = (
15094: crs => {
15095: on => &mt('Encryption of stored external tool secrets defined in courses enabled'),
15096: off => &mt('Encryption of stored external tool secrets defined in courses disabled'),
15097: },
15098: dom => {
15099: on => &mt('Encryption of stored external tool secrets defined in domain enabled'),
15100: off => &mt('Encryption of stored external tool secrets defined in domain disabled'),
15101: },
15102: );
15103: }
15104: my @types= ('crs','dom');
15105: if ($context eq 'lti') {
1.423 raeburn 15106: foreach my $type (@types) {
15107: undef($domdefaults{'linkprotenc_'.$type});
15108: }
1.421 raeburn 15109: push(@types,'consumers');
1.423 raeburn 15110: undef($domdefaults{'ltienc_consumers'});
15111: } elsif ($context eq 'ltitools') {
15112: foreach my $type (@types) {
15113: undef($domdefaults{'toolenc_'.$type});
15114: }
1.267 raeburn 15115: }
1.421 raeburn 15116: foreach my $type (@types) {
15117: my $shown = $encrypted{$type}{'off'};
15118: if (ref($newsec->{$item}) eq 'HASH') {
15119: if ($newsec->{$item}{$type}) {
1.423 raeburn 15120: if ($context eq 'lti') {
15121: if ($type eq 'consumers') {
15122: $domdefaults{'ltienc_consumers'} = 1;
15123: } else {
15124: $domdefaults{'linkprotenc_'.$type} = 1;
15125: }
15126: } elsif ($context eq 'ltitools') {
15127: $domdefaults{'toolenc_'.$type} = 1;
15128: }
1.421 raeburn 15129: $shown = $encrypted{$type}{'on'};
1.319 raeburn 15130: }
1.267 raeburn 15131: }
1.421 raeburn 15132: $output .= '<li>'.$shown.'</li>';
1.267 raeburn 15133: }
1.421 raeburn 15134: } elsif ($item eq 'rules') {
15135: my %titles = &Apache::lonlocal::texthash(
15136: min => 'Minimum password length',
15137: max => 'Maximum password length',
15138: chars => 'Required characters',
15139: );
15140: foreach my $rule ('min','max') {
15141: if ($newsec->{rules}{$rule} eq '') {
15142: if ($rule eq 'min') {
15143: $output .= '<li>'.&mt('[_1] not set.',$titles{$rule});
15144: ' '.&mt('Default of [_1] will be used',
15145: $Apache::lonnet::passwdmin).'</li>';
15146: } else {
15147: $output .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
15148: }
15149: } else {
15150: $output .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$newsec->{rules}{$rule}).'</li>';
15151: }
15152: }
15153: if (ref($newsec->{'rules'}{'chars'}) eq 'ARRAY') {
15154: if (@{$newsec->{'rules'}{'chars'}} > 0) {
15155: my %rulenames = &Apache::lonlocal::texthash(
15156: uc => 'At least one upper case letter',
15157: lc => 'At least one lower case letter',
15158: num => 'At least one number',
15159: spec => 'At least one non-alphanumeric',
15160: );
15161: my $needed = '<ul><li>'.
15162: join('</li><li>',map {$rulenames{$_} } @{$newsec->{'rules'}{'chars'}}).
15163: '</li></ul>';
15164: $output .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
15165: } else {
15166: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 15167: }
1.421 raeburn 15168: } else {
15169: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 15170: }
1.421 raeburn 15171: } elsif ($item eq 'private') {
1.423 raeburn 15172: $needs_update = 1;
15173: if ($context eq 'lti') {
15174: undef($domdefaults{'ltiprivhosts'});
15175: } elsif ($context eq 'ltitools') {
15176: undef($domdefaults{'toolprivhosts'});
15177: }
1.421 raeburn 15178: if (keys(%{$newkeyset})) {
1.423 raeburn 15179: my @privhosts;
1.421 raeburn 15180: foreach my $hostid (sort(keys(%{$newkeyset}))) {
15181: if ($keystore->{$hostid} eq 'ok') {
15182: $output .= '<li>'.&mt('Encryption key for storage of shared secrets saved for [_1]',$hostid).'</li>';
1.423 raeburn 15183: unless (grep(/^\Q$hostid\E$/,@privhosts)) {
15184: push(@privhosts,$hostid);
15185: }
15186: }
15187: }
15188: if (@privhosts) {
15189: if ($context eq 'lti') {
15190: $domdefaults{'ltiprivhosts'} = \@privhosts;
15191: } elsif ($context eq 'ltitools') {
15192: $domdefaults{'toolprivhosts'} = \@privhosts;
1.267 raeburn 15193: }
15194: }
15195: }
1.421 raeburn 15196: } elsif ($item eq 'linkprot') {
15197: next;
1.434 raeburn 15198: } elsif ($item eq 'suggested') {
15199: if ((ref($secchanges->{'suggested'}) eq 'HASH') &&
15200: (ref($newsec->{'suggested'}) eq 'HASH')) {
15201: my $suggestions;
15202: foreach my $id (sort { $a <=> $b } keys(%{$secchanges->{'suggested'}})) {
15203: if (ref($newsec->{'suggested'}->{$id}) eq 'HASH') {
15204: my $name = $newsec->{'suggested'}->{$id}->{'name'};
15205: my $info = $newsec->{'suggested'}->{$id}->{'info'};
15206: $suggestions .= '<li>'.&mt('Launcher: [_1]',$name).'<br />'.
15207: &mt('Recommend: [_1]','<pre>'.$info.'</pre>').
15208: '</li>';
15209: } else {
15210: $suggestions .= '<li>'.&mt('Recommendations deleted for Launcher: [_1]',
15211: $newsec->{'suggested'}->{$id}).'</li>';
15212: }
15213: }
15214: if ($suggestions) {
15215: $output .= '<li>'.&mt('Hints in Courses for Link Protector Configuration').
15216: '<ul>'.$suggestions.'</ul>'.
15217: '</li>';
15218: }
15219: }
1.267 raeburn 15220: }
15221: }
1.423 raeburn 15222: if ($needs_update) {
15223: my $cachetime = 24*60*60;
15224: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15225: }
1.421 raeburn 15226: return $output;
15227: }
15228:
15229: sub modify_proctoring {
15230: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15231: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15232: my (@allpos,%changes,%confhash,%encconfhash,$errors,$resulttext,%imgdeletions);
15233: my $confname = $dom.'-domainconfig';
15234: my $servadm = $r->dir_config('lonAdmEMail');
1.372 raeburn 15235: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
15236: my %providernames = &proctoring_providernames();
15237: my $maxnum = scalar(keys(%providernames));
15238:
15239: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
15240: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
15241: if (ref($requref) eq 'HASH') {
15242: %requserfields = %{$requref};
15243: }
15244: if (ref($opturef) eq 'HASH') {
15245: %optuserfields = %{$opturef};
15246: }
15247: if (ref($defref) eq 'HASH') {
15248: %defaults = %{$defref};
15249: }
15250: if (ref($extref) eq 'HASH') {
15251: %extended = %{$extref};
15252: }
15253: if (ref($crsref) eq 'HASH') {
15254: %crsconf = %{$crsref};
15255: }
15256: if (ref($rolesref) eq 'ARRAY') {
15257: @courseroles = @{$rolesref};
15258: }
15259: if (ref($ltiref) eq 'ARRAY') {
15260: @ltiroles = @{$ltiref};
15261: }
15262:
15263: if (ref($domconfig{$action}) eq 'HASH') {
15264: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.proctoring_image_del');
15265: if (@todeleteimages) {
15266: map { $imgdeletions{$_} = 1; } @todeleteimages;
15267: }
15268: }
15269: my %customadds;
15270: my @newcustom = &Apache::loncommon::get_env_multiple('form.proctoring_customadd');
15271: if (@newcustom) {
15272: map { $customadds{$_} = 1; } @newcustom;
15273: }
15274: foreach my $provider (sort(keys(%providernames))) {
15275: $confhash{$provider} = {};
15276: my $pos = $env{'form.proctoring_pos_'.$provider};
15277: $pos =~ s/\D+//g;
15278: $allpos[$pos] = $provider;
15279: my (%current,%currentenc);
15280: my $showroles = 0;
15281: if (ref($domconfig{$action}) eq 'HASH') {
15282: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15283: %current = %{$domconfig{$action}{$provider}};
15284: foreach my $item ('key','secret') {
15285: $currentenc{$item} = $current{$item};
15286: delete($current{$item});
15287: }
15288: }
15289: }
15290: if ($env{'form.proctoring_available_'.$provider}) {
15291: $confhash{$provider}{'available'} = 1;
15292: unless ($current{'available'}) {
15293: $changes{$provider} = 1;
15294: }
15295: } else {
15296: %{$confhash{$provider}} = %current;
15297: %{$encconfhash{$provider}} = %currentenc;
15298: $confhash{$provider}{'available'} = 0;
15299: if ($current{'available'}) {
15300: $changes{$provider} = 1;
15301: }
15302: }
15303: if ($confhash{$provider}{'available'}) {
15304: foreach my $field ('lifetime','version','sigmethod','url','key','secret') {
15305: my $possval = $env{'form.proctoring_'.$provider.'_'.$field};
15306: if ($field eq 'lifetime') {
15307: if ($possval =~ /^\d+$/) {
15308: $confhash{$provider}{$field} = $possval;
15309: }
15310: } elsif ($field eq 'version') {
15311: if ($possval =~ /^\d+\.\d+$/) {
15312: $confhash{$provider}{$field} = $possval;
15313: }
15314: } elsif ($field eq 'sigmethod') {
15315: if ($possval =~ /^\QHMAC-SHA\E(1|256)$/) {
15316: $confhash{$provider}{$field} = $possval;
15317: }
15318: } elsif ($field eq 'url') {
15319: $confhash{$provider}{$field} = $possval;
15320: } elsif (($field eq 'key') || ($field eq 'secret')) {
15321: $encconfhash{$provider}{$field} = $possval;
15322: unless ($currentenc{$field} eq $possval) {
15323: $changes{$provider} = 1;
15324: }
15325: }
15326: unless (($field eq 'key') || ($field eq 'secret')) {
15327: unless ($current{$field} eq $confhash{$provider}{$field}) {
15328: $changes{$provider} = 1;
15329: }
15330: }
15331: }
15332: if ($imgdeletions{$provider}) {
15333: $changes{$provider} = 1;
15334: } elsif ($env{'form.proctoring_image_'.$provider.'.filename'} ne '') {
15335: my ($imageurl,$error) =
15336: &process_proctoring_image($r,$dom,$confname,'proctoring_image_'.$provider,$provider,
15337: $configuserok,$switchserver,$author_ok);
15338: if ($imageurl) {
15339: $confhash{$provider}{'image'} = $imageurl;
15340: $changes{$provider} = 1;
15341: }
15342: if ($error) {
15343: &Apache::lonnet::logthis($error);
15344: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15345: }
15346: } elsif (exists($current{'image'})) {
15347: $confhash{$provider}{'image'} = $current{'image'};
15348: }
15349: if (ref($requserfields{$provider}) eq 'ARRAY') {
15350: if (@{$requserfields{$provider}} > 0) {
15351: if (grep(/^user$/,@{$requserfields{$provider}})) {
15352: if ($env{'form.proctoring_userincdom_'.$provider}) {
15353: $confhash{$provider}{'incdom'} = 1;
15354: }
15355: unless ($current{'incdom'} eq $confhash{$provider}{'incdom'}) {
15356: $changes{$provider} = 1;
15357: }
15358: }
15359: if (grep(/^roles$/,@{$requserfields{$provider}})) {
15360: $showroles = 1;
15361: }
15362: }
15363: }
15364: $confhash{$provider}{'fields'} = [];
15365: if (ref($optuserfields{$provider}) eq 'ARRAY') {
15366: if (@{$optuserfields{$provider}} > 0) {
15367: my @optfields = &Apache::loncommon::get_env_multiple('form.proctoring_optional_'.$provider);
15368: foreach my $field (@{$optuserfields{$provider}}) {
15369: if (grep(/^\Q$field\E$/,@optfields)) {
15370: push(@{$confhash{$provider}{'fields'}},$field);
15371: }
15372: }
15373: }
15374: if (ref($current{'fields'}) eq 'ARRAY') {
15375: unless ($changes{$provider}) {
15376: my @new = sort(@{$confhash{$provider}{'fields'}});
15377: my @old = sort(@{$current{'fields'}});
15378: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15379: if (@diffs) {
15380: $changes{$provider} = 1;
15381: }
15382: }
15383: } elsif (@{$confhash{$provider}{'fields'}}) {
15384: $changes{$provider} = 1;
15385: }
15386: }
15387: if (ref($defaults{$provider}) eq 'ARRAY') {
15388: if (@{$defaults{$provider}} > 0) {
15389: my %options;
15390: if (ref($extended{$provider}) eq 'HASH') {
15391: %options = %{$extended{$provider}};
15392: }
15393: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_defaults_'.$provider);
15394: foreach my $field (@{$defaults{$provider}}) {
15395: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
15396: my $poss = $env{'form.proctoring_defaults_'.$field.'_'.$provider};
15397: if (grep(/^\Q$poss\E$/,@{$options{$field}})) {
15398: push(@{$confhash{$provider}{'defaults'}},$poss);
15399: }
15400: } elsif ((exists($options{$field})) && (ref($options{$field}) eq 'HASH')) {
15401: foreach my $inner (keys(%{$options{$field}})) {
15402: if (ref($options{$field}{$inner}) eq 'ARRAY') {
15403: my $poss = $env{'form.proctoring_'.$inner.'_'.$provider};
15404: if (grep(/^\Q$poss\E$/,@{$options{$field}{$inner}})) {
15405: $confhash{$provider}{'defaults'}{$inner} = $poss;
15406: }
15407: } else {
15408: $confhash{$provider}{'defaults'}{$inner} = $env{'form.proctoring_'.$inner.'_'.$provider};
15409: }
15410: }
15411: } else {
15412: if (grep(/^\Q$field\E$/,@checked)) {
15413: push(@{$confhash{$provider}{'defaults'}},$field);
15414: }
15415: }
15416: }
15417: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15418: if (ref($current{'defaults'}) eq 'ARRAY') {
15419: unless ($changes{$provider}) {
15420: my @new = sort(@{$confhash{$provider}{'defaults'}});
15421: my @old = sort(@{$current{'defaults'}});
15422: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15423: if (@diffs) {
15424: $changes{$provider} = 1;
15425: }
15426: }
15427: } elsif (ref($current{'defaults'}) eq 'ARRAY') {
15428: if (@{$current{'defaults'}}) {
15429: $changes{$provider} = 1;
15430: }
15431: }
15432: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15433: if (ref($current{'defaults'}) eq 'HASH') {
15434: unless ($changes{$provider}) {
15435: foreach my $key (keys(%{$confhash{$provider}{'defaults'}})) {
15436: unless ($confhash{$provider}{'defaults'}{$key} eq $current{'defaults'}{$key}) {
15437: $changes{$provider} = 1;
15438: last;
15439: }
15440: }
15441: }
15442: unless ($changes{$provider}) {
15443: foreach my $key (keys(%{$current{'defaults'}})) {
15444: unless ($current{'defaults'}{$key} eq $confhash{$provider}{'defaults'}{$key}) {
15445: $changes{$provider} = 1;
15446: last;
15447: }
15448: }
15449: }
15450: } elsif (keys(%{$confhash{$provider}{'defaults'}})) {
15451: $changes{$provider} = 1;
15452: }
15453: }
15454: }
15455: }
15456: if (ref($crsconf{$provider}) eq 'ARRAY') {
15457: if (@{$crsconf{$provider}} > 0) {
15458: $confhash{$provider}{'crsconf'} = [];
15459: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_crsconf_'.$provider);
15460: foreach my $crsfield (@{$crsconf{$provider}}) {
15461: if (grep(/^\Q$crsfield\E$/,@checked)) {
15462: push(@{$confhash{$provider}{'crsconf'}},$crsfield);
15463: }
15464: }
15465: if (ref($current{'crsconf'}) eq 'ARRAY') {
15466: unless ($changes{$provider}) {
15467: my @new = sort(@{$confhash{$provider}{'crsconf'}});
15468: my @old = sort(@{$current{'crsconf'}});
15469: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15470: if (@diffs) {
15471: $changes{$provider} = 1;
15472: }
15473: }
15474: } elsif (@{$confhash{$provider}{'crsconf'}}) {
15475: $changes{$provider} = 1;
15476: }
15477: }
15478: }
15479: if ($showroles) {
15480: $confhash{$provider}{'roles'} = {};
15481: foreach my $role (@courseroles) {
15482: my $poss = $env{'form.proctoring_roles_'.$role.'_'.$provider};
15483: if (grep(/^\Q$poss\E$/,@ltiroles)) {
15484: $confhash{$provider}{'roles'}{$role} = $poss;
15485: }
15486: }
15487: unless ($changes{$provider}) {
15488: if (ref($current{'roles'}) eq 'HASH') {
15489: foreach my $role (keys(%{$current{'roles'}})) {
15490: unless ($current{'roles'}{$role} eq $confhash{$provider}{'roles'}{$role}) {
15491: $changes{$provider} = 1;
15492: last
15493: }
15494: }
15495: unless ($changes{$provider}) {
15496: foreach my $role (keys(%{$confhash{$provider}{'roles'}})) {
15497: unless ($confhash{$provider}{'roles'}{$role} eq $current{'roles'}{$role}) {
15498: $changes{$provider} = 1;
15499: last;
15500: }
15501: }
15502: }
15503: } elsif (keys(%{$confhash{$provider}{'roles'}})) {
15504: $changes{$provider} = 1;
15505: }
15506: }
15507: }
15508: if (ref($current{'custom'}) eq 'HASH') {
15509: my @customdels = &Apache::loncommon::get_env_multiple('form.proctoring_customdel_'.$provider);
15510: foreach my $key (keys(%{$current{'custom'}})) {
15511: if (grep(/^\Q$key\E$/,@customdels)) {
15512: $changes{$provider} = 1;
15513: } else {
15514: $confhash{$provider}{'custom'}{$key} = $env{'form.proctoring_customval_'.$key.'_'.$provider};
15515: if ($confhash{$provider}{'custom'}{$key} ne $current{'custom'}{$key}) {
15516: $changes{$provider} = 1;
15517: }
15518: }
15519: }
15520: }
15521: if ($customadds{$provider}) {
15522: my $name = $env{'form.proctoring_custom_name_'.$provider};
15523: $name =~ s/(`)/'/g;
15524: $name =~ s/^\s+//;
15525: $name =~ s/\s+$//;
15526: my $value = $env{'form.proctoring_custom_value_'.$provider};
15527: $value =~ s/(`)/'/g;
15528: $value =~ s/^\s+//;
15529: $value =~ s/\s+$//;
15530: if ($name ne '') {
15531: $confhash{$provider}{'custom'}{$name} = $value;
15532: $changes{$provider} = 1;
15533: }
15534: }
15535: }
15536: }
15537: if (@allpos > 0) {
15538: my $idx = 0;
15539: foreach my $provider (@allpos) {
15540: if ($provider ne '') {
15541: $confhash{$provider}{'order'} = $idx;
15542: unless ($changes{$provider}) {
15543: if (ref($domconfig{$action}) eq 'HASH') {
15544: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15545: if ($domconfig{$action}{$provider}{'order'} ne $idx) {
15546: $changes{$provider} = 1;
15547: }
15548: }
15549: }
15550: }
15551: $idx ++;
15552: }
15553: }
15554: }
15555: my %proc_hash = (
15556: $action => { %confhash }
15557: );
15558: my $putresult = &Apache::lonnet::put_dom('configuration',\%proc_hash,
15559: $dom);
15560: if ($putresult eq 'ok') {
15561: my %proc_enchash = (
15562: $action => { %encconfhash }
15563: );
1.384 raeburn 15564: &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom,undef,1);
1.372 raeburn 15565: if (keys(%changes) > 0) {
15566: my $cachetime = 24*60*60;
15567: my %procall = %confhash;
15568: foreach my $provider (keys(%procall)) {
15569: if (ref($encconfhash{$provider}) eq 'HASH') {
15570: foreach my $key ('key','secret') {
15571: $procall{$provider}{$key} = $encconfhash{$provider}{$key};
15572: }
15573: }
15574: }
15575: &Apache::lonnet::do_cache_new('proctoring',$dom,\%procall,$cachetime);
15576: if (ref($lastactref) eq 'HASH') {
15577: $lastactref->{'proctoring'} = 1;
15578: }
15579: $resulttext = &mt('Configuration for Provider(s) with changes:').'<ul>';
15580: my %bynum;
15581: foreach my $provider (sort(keys(%changes))) {
15582: my $position = $confhash{$provider}{'order'};
15583: $bynum{$position} = $provider;
15584: }
15585: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
15586: my $provider = $bynum{$pos};
15587: my %lt = &proctoring_titles($provider);
15588: my %fieldtitles = &proctoring_fieldtitles($provider);
15589: if (!$confhash{$provider}{'available'}) {
15590: $resulttext .= '<li>'.&mt('Proctoring integration unavailable for: [_1]','<b>'.$providernames{$provider}.'</b>').'</li>';
15591: } else {
15592: $resulttext .= '<li>'.&mt('Proctoring integration available for: [_1]','<b>'.$providernames{$provider}.'</b>');
15593: if ($confhash{$provider}{'image'}) {
15594: $resulttext .= ' '.
15595: '<img src="'.$confhash{$provider}{'image'}.'"'.
15596: ' alt="'.&mt('Proctoring icon').'" />';
15597: }
15598: $resulttext .= '<ul>';
15599: my $position = $pos + 1;
15600: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
15601: foreach my $key ('version','sigmethod','url','lifetime') {
15602: if ($confhash{$provider}{$key} ne '') {
15603: $resulttext .= '<li>'.$lt{$key}.': '.$confhash{$provider}{$key}.'</li>';
15604: }
15605: }
15606: if ($encconfhash{$provider}{'key'} ne '') {
15607: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfhash{$provider}{'key'}.'</li>';
15608: }
15609: if ($encconfhash{$provider}{'secret'} ne '') {
15610: $resulttext .= '<li>'.$lt{'secret'}.': ';
15611: my $num = length($encconfhash{$provider}{'secret'});
15612: $resulttext .= ('*'x$num).'</li>';
15613: }
15614: my (@fields,$showroles);
15615: if (ref($requserfields{$provider}) eq 'ARRAY') {
15616: push(@fields,@{$requserfields{$provider}});
15617: }
15618: if (ref($confhash{$provider}{'fields'}) eq 'ARRAY') {
15619: push(@fields,@{$confhash{$provider}{'fields'}});
15620: } elsif (ref($confhash{$provider}{'fields'}) eq 'HASH') {
15621: push(@fields,(keys(%{$confhash{$provider}{'fields'}})));
15622: }
15623: if (@fields) {
15624: if (grep(/^roles$/,@fields)) {
15625: $showroles = 1;
15626: }
15627: $resulttext .= '<li>'.$lt{'udsl'}.': "'.
15628: join('", "', map { $lt{$_}; } @fields).'"</li>';
15629: }
15630: if (ref($requserfields{$provider}) eq 'ARRAY') {
15631: if (grep(/^user$/,@{$requserfields{$provider}})) {
15632: if ($confhash{$provider}{'incdom'}) {
15633: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'uname:dom'}).'</li>';
15634: } else {
15635: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'username'}).'</li>';
15636: }
15637: }
15638: }
15639: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15640: if (@{$confhash{$provider}{'defaults'}} > 0) {
15641: $resulttext .= '<li>'.$lt{'defa'};
15642: foreach my $field (@{$confhash{$provider}{'defaults'}}) {
15643: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15644: }
15645: $resulttext =~ s/,$//;
15646: $resulttext .= '</li>';
15647: }
15648: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15649: if (keys(%{$confhash{$provider}{'defaults'}})) {
15650: $resulttext .= '<li>'.$lt{'defa'}.': <ul>';
15651: foreach my $key (sort(keys(%{$confhash{$provider}{'defaults'}}))) {
15652: if ($confhash{$provider}{'defaults'}{$key} ne '') {
15653: $resulttext .= '<li>'.$fieldtitles{$key}.' = '.$confhash{$provider}{'defaults'}{$key}.'</li>';
15654: }
15655: }
15656: $resulttext .= '</ul></li>';
15657: }
15658: }
15659: if (ref($crsconf{$provider}) eq 'ARRAY') {
15660: if (@{$crsconf{$provider}} > 0) {
15661: $resulttext .= '<li>'.&mt('Configurable in course:');
15662: my $numconfig = 0;
15663: if (ref($confhash{$provider}{'crsconf'}) eq 'ARRAY') {
15664: if (@{$confhash{$provider}{'crsconf'}} > 0) {
15665: foreach my $field (@{$confhash{$provider}{'crsconf'}}) {
15666: $numconfig ++;
15667: if ($provider eq 'examity') {
15668: $resulttext .= ' "'.$lt{'crs'.$field}.'",';
15669: } else {
15670: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15671: }
15672: }
15673: $resulttext =~ s/,$//;
15674: }
15675: }
15676: if (!$numconfig) {
15677: $resulttext .= ' '.&mt('None');
15678: }
15679: $resulttext .= '</li>';
15680: }
15681: }
15682: if ($showroles) {
15683: if (ref($confhash{$provider}{'roles'}) eq 'HASH') {
15684: my $rolemaps;
15685: foreach my $role (@courseroles) {
15686: if ($confhash{$provider}{'roles'}{$role}) {
15687: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
15688: $confhash{$provider}{'roles'}{$role}.',';
15689: }
15690: }
15691: if ($rolemaps) {
15692: $rolemaps =~ s/,$//;
15693: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
15694: }
15695: }
15696: }
15697: if (ref($confhash{$provider}{'custom'}) eq 'HASH') {
15698: my $customlist;
15699: if (keys(%{$confhash{$provider}{'custom'}})) {
15700: foreach my $key (sort(keys(%{$confhash{$provider}{'custom'}}))) {
15701: $customlist .= $key.'='.$confhash{$provider}{'custom'}{$key}.', ';
15702: }
15703: $customlist =~ s/,$//;
15704: }
15705: if ($customlist) {
15706: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
15707: }
15708: }
15709: $resulttext .= '</ul></li>';
15710: }
15711: }
15712: $resulttext .= '</ul>';
15713: } else {
15714: $resulttext = &mt('No changes made.');
15715: }
15716: } else {
15717: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15718: }
15719: if ($errors) {
15720: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15721: $errors.'</ul>';
15722: }
15723: return $resulttext;
15724: }
15725:
15726: sub process_proctoring_image {
15727: my ($r,$dom,$confname,$caller,$provider,$configuserok,$switchserver,$author_ok) = @_;
15728: my $filename = $env{'form.'.$caller.'.filename'};
15729: my ($error,$url);
15730: my ($width,$height) = (21,21);
15731: if ($configuserok eq 'ok') {
15732: if ($switchserver) {
15733: $error = &mt('Upload of Remote Proctoring Provider icon is not permitted to this server: [_1]',
15734: $switchserver);
15735: } elsif ($author_ok eq 'ok') {
1.421 raeburn 15736: my $modified = [];
1.372 raeburn 15737: my ($result,$imageurl,$madethumb) =
1.421 raeburn 15738: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
15739: "proctoring/$provider/icon",$width,$height,
15740: '',$modified);
1.372 raeburn 15741: if ($result eq 'ok') {
15742: if ($madethumb) {
15743: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
15744: my $imagethumb = "$path/tn-".$imagefile;
15745: $url = $imagethumb;
15746: } else {
15747: $url = $imageurl;
15748: }
1.421 raeburn 15749: &update_modify_urls($r,$modified);
1.372 raeburn 15750: } else {
15751: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
15752: }
15753: } else {
15754: $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);
15755: }
15756: } else {
15757: $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);
15758: }
15759: return ($url,$error);
15760: }
15761:
1.320 raeburn 15762: sub modify_lti {
15763: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15764: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.424 raeburn 15765: my ($newid,@allpos,%changes,%confhash,%ltienc,$errors,$resulttext);
1.320 raeburn 15766: my (%posslti,%posslticrs,%posscrstype);
15767: my @courseroles = ('cc','in','ta','ep','st');
15768: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
15769: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
1.392 raeburn 15770: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 15771: my %coursetypetitles = &Apache::lonlocal::texthash (
15772: official => 'Official',
15773: unofficial => 'Unofficial',
15774: community => 'Community',
15775: textbook => 'Textbook',
15776: placement => 'Placement Test',
1.392 raeburn 15777: lti => 'LTI Provider',
1.320 raeburn 15778: );
1.325 raeburn 15779: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 15780: my %lt = <i_names();
15781: map { $posslti{$_} = 1; } @ltiroles;
15782: map { $posslticrs{$_} = 1; } @lticourseroles;
15783: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 15784:
1.326 raeburn 15785: my %menutitles = <imenu_titles();
1.421 raeburn 15786: my (%currltisec,%secchanges,%newltisec,%newltienc,%newkeyset);
1.326 raeburn 15787:
1.421 raeburn 15788: &fetch_secrets($dom,'ltisec',\%domconfig,\%currltisec,\%secchanges,\%newltisec,\%newkeyset);
1.405 raeburn 15789:
1.406 raeburn 15790: my (%linkprotchg,$linkprotoutput,$is_home);
15791: my $proterror = &Apache::courseprefs::process_linkprot($dom,'',$currltisec{'linkprot'},
15792: \%linkprotchg,'domain');
15793: my $home = &Apache::lonnet::domain($dom,'primary');
15794: unless (($home eq 'no_host') || ($home eq '')) {
15795: my @ids=&Apache::lonnet::current_machine_ids();
15796: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; } }
15797: }
15798:
15799: if (keys(%linkprotchg)) {
15800: $secchanges{'linkprot'} = 1;
15801: my %oldlinkprot;
15802: if (ref($currltisec{'linkprot'}) eq 'HASH') {
15803: %oldlinkprot = %{$currltisec{'linkprot'}};
15804: }
15805: foreach my $id (keys(%linkprotchg)) {
15806: if (ref($linkprotchg{$id}) eq 'HASH') {
15807: foreach my $inner (keys(%{$linkprotchg{$id}})) {
15808: if (($inner eq 'secret') || ($inner eq 'key')) {
15809: if ($is_home) {
15810: $newltienc{$id}{$inner} = $linkprotchg{$id}{$inner};
15811: }
15812: }
15813: }
15814: } else {
15815: $newltisec{'linkprot'}{$id} = $linkprotchg{$id};
15816: }
15817: }
15818: $linkprotoutput = &Apache::courseprefs::store_linkprot($dom,'','domain',\%linkprotchg,\%oldlinkprot);
15819: if (keys(%linkprotchg)) {
15820: %{$newltisec{'linkprot'}} = %linkprotchg;
15821: }
15822: }
15823: if (ref($currltisec{'linkprot'}) eq 'HASH') {
1.434 raeburn 15824: foreach my $id (keys(%{$currltisec{'linkprot'}})) {
1.406 raeburn 15825: next if ($id !~ /^\d+$/);
15826: unless (exists($linkprotchg{$id})) {
15827: if (ref($currltisec{'linkprot'}{$id}) eq 'HASH') {
15828: foreach my $inner (keys(%{$currltisec{'linkprot'}{$id}})) {
15829: if (($inner eq 'secret') || ($inner eq 'key')) {
15830: if ($is_home) {
15831: $newltienc{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15832: }
15833: } else {
15834: $newltisec{'linkprot'}{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15835: }
15836: }
15837: } else {
15838: $newltisec{'linkprot'}{$id} = $currltisec{'linkprot'}{$id};
15839: }
15840: }
15841: }
15842: }
15843: if ($proterror) {
15844: $errors .= '<li>'.$proterror.'</li>';
15845: }
1.434 raeburn 15846:
15847: my (%delsuggested,%suggids,@suggested);;
15848: if (ref($currltisec{'suggested'}) eq 'HASH') {
15849: my $maxnum = $env{'form.linkprot_suggested_maxnum'};
15850: my @todelete = &Apache::loncommon::get_env_multiple('form.linkprot_suggested_del');
15851: for (my $i=0; $i<$maxnum; $i++) {
15852: my $itemid = $env{'form.linkprot_suggested_id_'.$i};
15853: $itemid =~ s/\D+//g;
15854: if ($itemid) {
15855: if (ref($currltisec{'suggested'}->{$itemid}) eq 'HASH') {
15856: push(@suggested,$i);
15857: $suggids{$i} = $itemid;
15858: if ((@todelete > 0) && (grep(/^$i$/,@todelete))) {
15859: if (ref($currltisec{'suggested'}{$itemid}) eq 'HASH') {
15860: $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
15861: }
15862: } else {
15863: if ($env{'form.linkprot_suggested_name_'.$i} eq '') {
15864: $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
15865: } else {
15866: $env{'form.linkprot_suggested_name_'.$i} =~ s/(`)/'/g;
15867: $env{'form.linkprot_suggested_info_'.$i} =~ s/(`)/'/g;
15868: $newltisec{'suggested'}{$itemid}{'name'} = $env{'form.linkprot_suggested_name_'.$i};
15869: $newltisec{'suggested'}{$itemid}{'info'} = $env{'form.linkprot_suggested_info_'.$i};
15870: if (($currltisec{'suggested'}{$itemid}{'name'} ne $newltisec{'suggested'}{$itemid}{'name'}) ||
15871: ($currltisec{'suggested'}{$itemid}{'info'} ne $newltisec{'suggested'}{$itemid}{'info'})) {
15872: $secchanges{'suggested'}{$itemid} = 1;
15873: }
15874: }
15875: }
15876: }
15877: }
15878: }
15879: }
15880: foreach my $key (keys(%delsuggested)) {
15881: $newltisec{'suggested'}{$key} = $delsuggested{$key};
15882: $secchanges{'suggested'}{$key} = 1;
15883: }
15884: if (($env{'form.linkprot_suggested_add'}) &&
15885: ($env{'form.linkprot_suggested_name_add'} ne '')) {
15886: $env{'form.linkprot_suggested_name_add'} =~ s/(`)/'/g;
15887: $env{'form.linkprot_suggested_info_add'} =~ s/(`)/'/g;
15888: my ($newsuggid,$errormsg) = &get_lti_id($dom,$env{'form.linkprot_suggested_name_add'},'suggested');
15889: if ($newsuggid) {
15890: $newltisec{'suggested'}{$newsuggid}{'name'} = $env{'form.linkprot_suggested_name_add'};
15891: $newltisec{'suggested'}{$newsuggid}{'info'} = $env{'form.linkprot_suggested_info_add'};
15892: $secchanges{'suggested'}{$newsuggid} = 1;
15893: } else {
15894: my $error = &mt('Failed to acquire unique ID for new Link Protectors in Courses Suggestion');
15895: if ($errormsg) {
15896: $error .= ' ('.$errormsg.')';
15897: }
15898: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15899: }
15900: }
1.320 raeburn 15901: my (@items,%deletions,%itemids);
15902: if ($env{'form.lti_add'}) {
15903: my $consumer = $env{'form.lti_consumer_add'};
15904: $consumer =~ s/(`)/'/g;
1.434 raeburn 15905: ($newid,my $errormsg) = &get_lti_id($dom,$consumer,'lti');
1.320 raeburn 15906: if ($newid) {
15907: $itemids{'add'} = $newid;
15908: push(@items,'add');
15909: $changes{$newid} = 1;
15910: } else {
15911: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
1.434 raeburn 15912: if ($errormsg) {
15913: $error .= ' ('.$errormsg.')';
15914: }
1.320 raeburn 15915: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15916: }
15917: }
15918: if (ref($domconfig{$action}) eq 'HASH') {
15919: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
15920: if (@todelete) {
15921: map { $deletions{$_} = 1; } @todelete;
15922: }
15923: my $maxnum = $env{'form.lti_maxnum'};
1.390 raeburn 15924: for (my $i=0; $i<$maxnum; $i++) {
1.320 raeburn 15925: my $itemid = $env{'form.lti_id_'.$i};
15926: $itemid =~ s/\D+//g;
15927: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
15928: if ($deletions{$itemid}) {
15929: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
15930: } else {
1.390 raeburn 15931: push(@items,$i);
15932: $itemids{$i} = $itemid;
1.320 raeburn 15933: }
15934: }
15935: }
15936: }
1.424 raeburn 15937: my (%keystore,$secstored);
15938: if ($is_home) {
15939: &store_security($dom,'lti',\%secchanges,\%newkeyset,\%keystore);
15940: }
15941:
15942: my ($cipher,$privnum);
15943: if ((@items > 0) && ($is_home)) {
15944: ($cipher,$privnum) = &get_priv_creds($dom,$home,$secchanges{'encrypt'},
15945: $newltisec{'encrypt'},$keystore{$home});
15946: }
1.320 raeburn 15947: foreach my $idx (@items) {
15948: my $itemid = $itemids{$idx};
15949: next unless ($itemid);
1.424 raeburn 15950: my %currlti;
15951: unless ($idx eq 'add') {
15952: if (ref($domconfig{$action}) eq 'HASH') {
15953: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
15954: %currlti = %{$domconfig{$action}{$itemid}};
15955: }
15956: }
15957: }
1.390 raeburn 15958: my $position = $env{'form.lti_pos_'.$itemid};
1.320 raeburn 15959: $position =~ s/\D+//g;
15960: if ($position ne '') {
15961: $allpos[$position] = $itemid;
15962: }
1.424 raeburn 15963: foreach my $item ('consumer','lifetime','requser','crsinc') {
1.320 raeburn 15964: my $formitem = 'form.lti_'.$item.'_'.$idx;
15965: $env{$formitem} =~ s/(`)/'/g;
15966: if ($item eq 'lifetime') {
15967: $env{$formitem} =~ s/[^\d.]//g;
15968: }
15969: if ($env{$formitem} ne '') {
1.424 raeburn 15970: $confhash{$itemid}{$item} = $env{$formitem};
15971: unless (($idx eq 'add') || ($changes{$itemid})) {
15972: if ($currlti{$item} ne $confhash{$itemid}{$item}) {
15973: $changes{$itemid} = 1;
1.320 raeburn 15974: }
15975: }
15976: }
15977: }
15978: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
15979: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
15980: }
1.345 raeburn 15981: if ($confhash{$itemid}{'requser'}) {
15982: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
1.405 raeburn 15983: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
1.345 raeburn 15984: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
15985: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
15986: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
15987: my $mapuser = $env{'form.lti_customuser_'.$idx};
15988: $mapuser =~ s/(`)/'/g;
1.405 raeburn 15989: $mapuser =~ s/^\s+|\s+$//g;
15990: $confhash{$itemid}{'mapuser'} = $mapuser;
1.345 raeburn 15991: }
15992: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
15993: my @makeuser;
15994: foreach my $ltirole (sort(@possmakeuser)) {
15995: if ($posslti{$ltirole}) {
15996: push(@makeuser,$ltirole);
15997: }
15998: }
15999: $confhash{$itemid}{'makeuser'} = \@makeuser;
16000: if (@makeuser) {
16001: my $lcauth = $env{'form.lti_lcauth_'.$idx};
16002: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
16003: $confhash{$itemid}{'lcauth'} = $lcauth;
16004: if ($lcauth ne 'internal') {
16005: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
16006: $lcauthparm =~ s/^(\s+|\s+)$//g;
16007: $lcauthparm =~ s/`//g;
16008: if ($lcauthparm ne '') {
16009: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
16010: }
16011: }
16012: } else {
16013: $confhash{$itemid}{'lcauth'} = 'lti';
16014: }
1.320 raeburn 16015: }
1.345 raeburn 16016: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
16017: if (@possinstdata) {
16018: foreach my $field (@possinstdata) {
16019: if (exists($fieldtitles{$field})) {
16020: push(@{$confhash{$itemid}{'instdata'}});
1.325 raeburn 16021: }
16022: }
16023: }
1.363 raeburn 16024: if ($env{'form.lti_callback_'.$idx}) {
16025: if ($env{'form.lti_callbackparam_'.$idx}) {
16026: my $callback = $env{'form.lti_callbackparam_'.$idx};
16027: $callback =~ s/^\s+|\s+$//g;
16028: $confhash{$itemid}{'callback'} = $callback;
16029: }
16030: }
1.391 raeburn 16031: foreach my $field ('topmenu','inlinemenu') {
1.345 raeburn 16032: if ($env{'form.lti_'.$field.'_'.$idx}) {
16033: $confhash{$itemid}{$field} = 1;
16034: }
1.320 raeburn 16035: }
1.345 raeburn 16036: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
16037: $confhash{$itemid}{lcmenu} = [];
16038: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
16039: foreach my $field (@possmenu) {
16040: if (exists($menutitles{$field})) {
16041: if ($field eq 'grades') {
16042: next unless ($env{'form.lti_inlinemenu_'.$idx});
16043: }
16044: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 16045: }
16046: }
16047: }
1.391 raeburn 16048: if ($confhash{$itemid}{'crsinc'}) {
16049: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
16050: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
16051: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
16052: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
16053: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
16054: $mapcrs =~ s/(`)/'/g;
16055: $mapcrs =~ s/^\s+|\s+$//g;
16056: $confhash{$itemid}{'mapcrs'} = $mapcrs;
16057: }
16058: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
16059: my @crstypes;
16060: foreach my $type (sort(@posstypes)) {
16061: if ($posscrstype{$type}) {
16062: push(@crstypes,$type);
16063: }
16064: }
16065: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
1.392 raeburn 16066: if ($env{'form.lti_storecrs_'.$idx}) {
16067: $confhash{$itemid}{'storecrs'} = 1;
16068: }
1.391 raeburn 16069: if ($env{'form.lti_makecrs_'.$idx}) {
16070: $confhash{$itemid}{'makecrs'} = 1;
16071: }
16072: foreach my $ltirole (@lticourseroles) {
16073: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
16074: if (grep(/^\Q$possrole\E$/,@courseroles)) {
16075: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
16076: }
16077: }
16078: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
16079: my @selfenroll;
16080: foreach my $type (sort(@possenroll)) {
16081: if ($posslticrs{$type}) {
16082: push(@selfenroll,$type);
16083: }
16084: }
16085: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
16086: if ($env{'form.lti_crssec_'.$idx}) {
16087: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
16088: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
16089: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
16090: my $section = $env{'form.lti_customsection_'.$idx};
16091: $section =~ s/(`)/'/g;
16092: $section =~ s/^\s+|\s+$//g;
16093: if ($section ne '') {
16094: $confhash{$itemid}{'section'} = $section;
16095: }
16096: }
16097: }
16098: foreach my $field ('passback','roster') {
16099: if ($env{'form.lti_'.$field.'_'.$idx}) {
16100: $confhash{$itemid}{$field} = 1;
16101: }
16102: }
16103: if ($env{'form.lti_passback_'.$idx}) {
16104: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
16105: $confhash{$itemid}{'passbackformat'} = '1.0';
16106: } else {
16107: $confhash{$itemid}{'passbackformat'} = '1.1';
1.337 raeburn 16108: }
16109: }
1.391 raeburn 16110: }
16111: unless (($idx eq 'add') || ($changes{$itemid})) {
16112: if ($confhash{$itemid}{'crsinc'}) {
1.392 raeburn 16113: foreach my $field ('mapcrs','storecrs','makecrs','section','passback','roster') {
1.424 raeburn 16114: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.320 raeburn 16115: $changes{$itemid} = 1;
16116: }
1.345 raeburn 16117: }
16118: unless ($changes{$itemid}) {
1.424 raeburn 16119: if ($currlti{'passback'} eq $confhash{$itemid}{'passback'}) {
16120: if ($currlti{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 16121: $changes{$itemid} = 1;
16122: }
16123: }
1.345 raeburn 16124: }
1.391 raeburn 16125: foreach my $field ('mapcrstype','selfenroll') {
16126: unless ($changes{$itemid}) {
1.424 raeburn 16127: if (ref($currlti{$field}) eq 'ARRAY') {
1.391 raeburn 16128: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424 raeburn 16129: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391 raeburn 16130: $confhash{$itemid}{$field});
16131: if (@diffs) {
16132: $changes{$itemid} = 1;
16133: }
1.424 raeburn 16134: } elsif (@{$currlti{$field}} > 0) {
1.391 raeburn 16135: $changes{$itemid} = 1;
16136: }
16137: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
16138: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 16139: $changes{$itemid} = 1;
16140: }
16141: }
1.391 raeburn 16142: }
16143: }
16144: unless ($changes{$itemid}) {
1.424 raeburn 16145: if (ref($currlti{'maproles'}) eq 'HASH') {
1.391 raeburn 16146: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
1.424 raeburn 16147: foreach my $ltirole (keys(%{$currlti{'maproles'}})) {
16148: if ($currlti{'maproles'}{$ltirole} ne
1.391 raeburn 16149: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.345 raeburn 16150: $changes{$itemid} = 1;
16151: last;
16152: }
16153: }
1.391 raeburn 16154: unless ($changes{$itemid}) {
16155: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
16156: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
1.424 raeburn 16157: $currlti{'maproles'}{$ltirole}) {
1.391 raeburn 16158: $changes{$itemid} = 1;
16159: last;
16160: }
16161: }
16162: }
1.424 raeburn 16163: } elsif (keys(%{$currlti{'maproles'}}) > 0) {
1.391 raeburn 16164: $changes{$itemid} = 1;
1.345 raeburn 16165: }
1.391 raeburn 16166: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16167: unless ($changes{$itemid}) {
16168: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
16169: $changes{$itemid} = 1;
16170: }
16171: }
16172: }
16173: }
16174: }
16175: unless ($changes{$itemid}) {
16176: foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
1.424 raeburn 16177: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.345 raeburn 16178: $changes{$itemid} = 1;
1.320 raeburn 16179: }
1.391 raeburn 16180: }
16181: unless ($changes{$itemid}) {
16182: foreach my $field ('makeuser','lcmenu') {
1.424 raeburn 16183: if (ref($currlti{$field}) eq 'ARRAY') {
1.391 raeburn 16184: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424 raeburn 16185: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391 raeburn 16186: $confhash{$itemid}{$field});
16187: if (@diffs) {
16188: $changes{$itemid} = 1;
16189: }
1.424 raeburn 16190: } elsif (@{$currlti{$field}} > 0) {
1.391 raeburn 16191: $changes{$itemid} = 1;
16192: }
16193: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
16194: if (@{$confhash{$itemid}{$field}} > 0) {
16195: $changes{$itemid} = 1;
16196: }
1.345 raeburn 16197: }
1.320 raeburn 16198: }
16199: }
16200: }
16201: }
16202: }
1.424 raeburn 16203: if ($is_home) {
16204: my $keyitem = 'form.lti_key_'.$idx;
16205: $env{$keyitem} =~ s/(`)/'/g;
16206: if ($env{$keyitem} ne '') {
16207: $ltienc{$itemid}{'key'} = $env{$keyitem};
16208: unless ($changes{$itemid}) {
16209: if ($currlti{'key'} ne $env{$keyitem}) {
16210: $changes{$itemid} = 1;
16211: }
16212: }
16213: }
16214: my $secretitem = 'form.lti_secret_'.$idx;
16215: $env{$secretitem} =~ s/(`)/'/g;
16216: if ($currlti{'usable'}) {
16217: if ($env{'form.lti_changesecret_'.$idx}) {
16218: if ($env{$secretitem} ne '') {
16219: if ($privnum && $cipher) {
16220: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
16221: $confhash{$itemid}{'cipher'} = $privnum;
16222: } else {
16223: $ltienc{$itemid}{'secret'} = $env{$secretitem};
16224: }
16225: $changes{$itemid} = 1;
16226: }
16227: } else {
16228: $ltienc{$itemid}{'secret'} = $currlti{'secret'};
16229: $confhash{$itemid}{'cipher'} = $currlti{'cipher'};
16230: }
16231: if (ref($ltienc{$itemid}) eq 'HASH') {
16232: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'secret'} ne '')) {
16233: $confhash{$itemid}{'usable'} = 1;
16234: }
16235: }
16236: } elsif ($env{$secretitem} ne '') {
16237: if ($privnum && $cipher) {
16238: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
16239: $confhash{$itemid}{'cipher'} = $privnum;
16240: } else {
16241: $ltienc{$itemid}{'secret'} = $env{$secretitem};
16242: }
16243: if (ref($ltienc{$itemid}) eq 'HASH') {
16244: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'key'} ne '')) {
16245: $confhash{$itemid}{'usable'} = 1;
16246: }
16247: }
16248: $changes{$itemid} = 1;
16249: }
16250: }
16251: unless ($changes{$itemid}) {
16252: foreach my $key (keys(%currlti)) {
16253: if (ref($currlti{$key}) eq 'HASH') {
16254: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
16255: foreach my $innerkey (keys(%{$currlti{$key}})) {
16256: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
16257: $changes{$itemid} = 1;
16258: last;
16259: }
16260: }
16261: } elsif (keys(%{$currlti{$key}}) > 0) {
16262: $changes{$itemid} = 1;
16263: }
16264: }
16265: last if ($changes{$itemid});
16266: }
16267: }
1.320 raeburn 16268: }
16269: if (@allpos > 0) {
16270: my $idx = 0;
16271: foreach my $itemid (@allpos) {
16272: if ($itemid ne '') {
16273: $confhash{$itemid}{'order'} = $idx;
16274: if (ref($domconfig{$action}) eq 'HASH') {
16275: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
16276: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
16277: $changes{$itemid} = 1;
16278: }
16279: }
16280: }
16281: $idx ++;
16282: }
16283: }
16284: }
1.424 raeburn 16285:
16286: if ((keys(%changes) == 0) && (keys(%secchanges) == 0)) {
16287: return &mt('No changes made.');
16288: }
16289:
1.320 raeburn 16290: my %ltihash = (
1.405 raeburn 16291: $action => { %confhash }
16292: );
1.424 raeburn 16293: my %ltienchash;
16294:
16295: if ($is_home) {
16296: %ltienchash = (
16297: $action => { %ltienc }
16298: );
16299: }
1.405 raeburn 16300: if (keys(%secchanges)) {
16301: $ltihash{'ltisec'} = \%newltisec;
1.406 raeburn 16302: if ($secchanges{'linkprot'}) {
16303: if ($is_home) {
16304: $ltienchash{'linkprot'} = \%newltienc;
16305: }
16306: }
1.405 raeburn 16307: }
16308: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,$dom);
1.320 raeburn 16309: if ($putresult eq 'ok') {
1.424 raeburn 16310: if (keys(%ltienchash)) {
16311: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.405 raeburn 16312: }
16313: $resulttext = &mt('Changes made:').'<ul>';
16314: if (keys(%secchanges) > 0) {
1.423 raeburn 16315: $resulttext .= <i_security_results($dom,'lti',\%secchanges,\%newltisec,\%newkeyset,\%keystore);
1.421 raeburn 16316: if (exists($secchanges{'linkprot'})) {
16317: $resulttext .= $linkprotoutput;
1.405 raeburn 16318: }
16319: }
1.320 raeburn 16320: if (keys(%changes) > 0) {
16321: my $cachetime = 24*60*60;
1.424 raeburn 16322: &Apache::lonnet::do_cache_new('lti',$dom,\%confhash,$cachetime);
1.320 raeburn 16323: if (ref($lastactref) eq 'HASH') {
16324: $lastactref->{'lti'} = 1;
16325: }
16326: my %bynum;
16327: foreach my $itemid (sort(keys(%changes))) {
1.424 raeburn 16328: if (ref($confhash{$itemid}) eq 'HASH') {
16329: my $position = $confhash{$itemid}{'order'};
16330: $bynum{$position} = $itemid;
16331: }
1.320 raeburn 16332: }
16333: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
16334: my $itemid = $bynum{$pos};
1.424 raeburn 16335: if (ref($confhash{$itemid}) eq 'HASH') {
1.390 raeburn 16336: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1.320 raeburn 16337: my $position = $pos + 1;
16338: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
16339: foreach my $item ('version','lifetime') {
16340: if ($confhash{$itemid}{$item} ne '') {
16341: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
16342: }
16343: }
1.424 raeburn 16344: if ($ltienc{$itemid}{'key'} ne '') {
16345: $resulttext .= '<li>'.$lt{'key'}.': '.$ltienc{$itemid}{'key'}.'</li>';
1.320 raeburn 16346: }
1.424 raeburn 16347: if ($ltienc{$itemid}{'secret'} ne '') {
16348: $resulttext .= '<li>'.$lt{'secret'}.': ['.&mt('not shown').']</li>';
1.320 raeburn 16349: }
1.345 raeburn 16350: if ($confhash{$itemid}{'requser'}) {
1.391 raeburn 16351: if ($confhash{$itemid}{'callback'}) {
16352: $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
16353: } else {
1.392 raeburn 16354: $resulttext .= '<li>'.&mt('Callback to logout LON-CAPA on log out from Consumer').'</li>';
1.391 raeburn 16355: }
1.345 raeburn 16356: if ($confhash{$itemid}{'mapuser'}) {
16357: my $shownmapuser;
16358: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
16359: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
16360: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
16361: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
16362: } else {
16363: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 16364: }
1.345 raeburn 16365: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 16366: }
1.345 raeburn 16367: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
16368: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
16369: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
16370: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
16371: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
16372: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
16373: } else {
16374: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
16375: $confhash{$itemid}{'lcauth'});
16376: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
16377: $resulttext .= '; '.&mt('a randomly generated password will be created');
16378: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
16379: if ($confhash{$itemid}{'lcauthparm'} ne '') {
16380: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
16381: }
16382: } else {
16383: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
16384: }
16385: }
16386: $resulttext .= '</li>';
16387: } else {
16388: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
16389: }
1.320 raeburn 16390: }
1.345 raeburn 16391: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
16392: if (@{$confhash{$itemid}{'instdata'}} > 0) {
16393: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
16394: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 16395: } else {
1.345 raeburn 16396: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325 raeburn 16397: }
1.320 raeburn 16398: }
1.391 raeburn 16399: foreach my $item ('topmenu','inlinemenu') {
1.345 raeburn 16400: $resulttext .= '<li>'.$lt{$item}.': ';
16401: if ($confhash{$itemid}{$item}) {
16402: $resulttext .= &mt('Yes');
16403: } else {
16404: $resulttext .= &mt('No');
1.337 raeburn 16405: }
1.345 raeburn 16406: $resulttext .= '</li>';
1.320 raeburn 16407: }
1.345 raeburn 16408: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16409: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16410: $resulttext .= '<li>'.&mt('Menu items:').' '.
1.391 raeburn 16411: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16412: } else {
16413: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16414: }
16415: }
16416: if ($confhash{$itemid}{'crsinc'}) {
16417: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16418: my $rolemaps;
16419: foreach my $role (@ltiroles) {
16420: if ($confhash{$itemid}{'maproles'}{$role}) {
16421: $rolemaps .= (' 'x2).$role.'='.
16422: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
16423: 'Course').',';
16424: }
16425: }
16426: if ($rolemaps) {
16427: $rolemaps =~ s/,$//;
16428: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
16429: }
16430: }
16431: if ($confhash{$itemid}{'mapcrs'}) {
16432: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
16433: }
16434: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
16435: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
16436: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
16437: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
16438: '</li>';
16439: } else {
16440: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
16441: }
16442: }
1.392 raeburn 16443: if ($confhash{$itemid}{'storecrs'}) {
16444: $resulttext .= '<li>'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.$confhash{$itemid}{'storecrs'}.'</li>';
16445: }
1.391 raeburn 16446: if ($confhash{$itemid}{'makecrs'}) {
16447: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
16448: } else {
16449: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
16450: }
16451: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
16452: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
16453: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
16454: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
16455: '</li>';
16456: } else {
16457: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
16458: }
16459: }
16460: if ($confhash{$itemid}{'section'}) {
16461: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
16462: $resulttext .= '<li>'.&mt('User section from standard field:').
16463: ' (course_section_sourcedid)'.'</li>';
16464: } else {
16465: $resulttext .= '<li>'.&mt('User section from:').' '.
16466: $confhash{$itemid}{'section'}.'</li>';
16467: }
1.345 raeburn 16468: } else {
1.391 raeburn 16469: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
16470: }
16471: foreach my $item ('passback','roster','topmenu','inlinemenu') {
16472: $resulttext .= '<li>'.$lt{$item}.': ';
16473: if ($confhash{$itemid}{$item}) {
16474: $resulttext .= &mt('Yes');
16475: if ($item eq 'passback') {
16476: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
16477: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
16478: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
16479: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
16480: }
16481: }
16482: } else {
16483: $resulttext .= &mt('No');
16484: }
16485: $resulttext .= '</li>';
16486: }
16487: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16488: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16489: $resulttext .= '<li>'.&mt('Menu items:').' '.
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: }
1.345 raeburn 16494: }
1.326 raeburn 16495: }
16496: }
1.320 raeburn 16497: $resulttext .= '</ul></li>';
16498: }
16499: }
1.424 raeburn 16500: if (keys(%deletions)) {
16501: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
16502: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
16503: }
16504: }
1.320 raeburn 16505: }
1.405 raeburn 16506: $resulttext .= '</ul>';
1.424 raeburn 16507: if (ref($lastactref) eq 'HASH') {
1.434 raeburn 16508: if (($secchanges{'encrypt'}) || ($secchanges{'private'}) || (exists($secchanges{'suggested'}))) {
16509: &Apache::lonnet::get_domain_defaults($dom,1);
1.424 raeburn 16510: $lastactref->{'domdefaults'} = 1;
16511: }
16512: }
1.320 raeburn 16513: } else {
16514: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
16515: }
16516: if ($errors) {
16517: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
16518: $errors.'</ul>';
16519: }
16520: return $resulttext;
16521: }
16522:
1.424 raeburn 16523: sub get_priv_creds {
16524: my ($dom,$home,$encchg,$encrypt,$storedsec) = @_;
16525: my ($needenc,$cipher,$privnum);
16526: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
16527: if (($encchg) && (ref($encrypt) eq 'HASH')) {
16528: $needenc = $encrypt->{'consumers'}
16529: } else {
16530: $needenc = $domdefs{'ltienc_consumers'};
16531: }
16532: if ($needenc) {
16533: if (($storedsec eq 'ok') || ((ref($domdefs{'ltiprivhosts'}) eq 'ARRAY') &&
16534: (grep(/^\Q$home\E$/,@{$domdefs{'ltiprivhosts'}})))) {
16535: my %privhash = &Apache::lonnet::restore_dom('lti','private',$dom,$home,1);
16536: my $privkey = $privhash{'key'};
16537: $privnum = $privhash{'version'};
16538: if (($privnum) && ($privkey ne '')) {
16539: $cipher = Crypt::CBC->new({'key' => $privkey,
16540: 'cipher' => 'DES'});
16541: }
16542: }
16543: }
16544: return ($cipher,$privnum);
16545: }
16546:
1.320 raeburn 16547: sub get_lti_id {
1.434 raeburn 16548: my ($domain,$consumer,$dbname) = @_;
16549: unless (($dbname eq 'lti') || ($dbname eq 'suggested')) {
16550: return ('','invalid db');
16551: }
16552: # get lock on db
1.320 raeburn 16553: my $lockhash = {
16554: lock => $env{'user.name'}.
16555: ':'.$env{'user.domain'},
16556: };
16557: my $tries = 0;
1.434 raeburn 16558: my $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1.320 raeburn 16559: my ($id,$error);
16560:
16561: while (($gotlock ne 'ok') && ($tries<10)) {
16562: $tries ++;
16563: sleep (0.1);
1.434 raeburn 16564: $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1.320 raeburn 16565: }
16566: if ($gotlock eq 'ok') {
1.434 raeburn 16567: my %currids = &Apache::lonnet::dump_dom($dbname,$domain);
1.320 raeburn 16568: if ($currids{'lock'}) {
16569: delete($currids{'lock'});
16570: if (keys(%currids)) {
16571: my @curr = sort { $a <=> $b } keys(%currids);
16572: if ($curr[-1] =~ /^\d+$/) {
16573: $id = 1 + $curr[-1];
16574: }
16575: } else {
16576: $id = 1;
16577: }
16578: if ($id) {
1.434 raeburn 16579: unless (&Apache::lonnet::newput_dom($dbname,{ $id => $consumer },$domain) eq 'ok') {
1.320 raeburn 16580: $error = 'nostore';
16581: }
16582: } else {
16583: $error = 'nonumber';
16584: }
16585: }
1.434 raeburn 16586: my $dellockoutcome = &Apache::lonnet::del_dom($dbname,['lock'],$domain);
1.320 raeburn 16587: } else {
16588: $error = 'nolock';
16589: }
16590: return ($id,$error);
16591: }
16592:
1.3 raeburn 16593: sub modify_autoenroll {
1.205 raeburn 16594: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 16595: my ($resulttext,%changes);
16596: my %currautoenroll;
16597: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
16598: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
16599: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
16600: }
16601: }
16602: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
16603: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 16604: sender => 'Sender for notification messages',
1.274 raeburn 16605: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.399 raeburn 16606: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 16607: my @offon = ('off','on');
1.17 raeburn 16608: my $sender_uname = $env{'form.sender_uname'};
16609: my $sender_domain = $env{'form.sender_domain'};
16610: if ($sender_domain eq '') {
16611: $sender_uname = '';
16612: } elsif ($sender_uname eq '') {
16613: $sender_domain = '';
16614: }
1.129 raeburn 16615: my $coowners = $env{'form.autoassign_coowners'};
1.399 raeburn 16616: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
16617: $autofailsafe =~ s{^\s+|\s+$}{}g;
16618: if ($autofailsafe =~ /\D/) {
16619: undef($autofailsafe);
16620: }
1.274 raeburn 16621: my $failsafe = $env{'form.autoenroll_failsafe'};
1.399 raeburn 16622: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
16623: $failsafe = 'off';
1.400 raeburn 16624: undef($autofailsafe);
1.274 raeburn 16625: }
1.1 raeburn 16626: my %autoenrollhash = (
1.129 raeburn 16627: autoenroll => { 'run' => $env{'form.autoenroll_run'},
16628: 'sender_uname' => $sender_uname,
16629: 'sender_domain' => $sender_domain,
16630: 'co-owners' => $coowners,
1.399 raeburn 16631: 'autofailsafe' => $autofailsafe,
1.400 raeburn 16632: 'failsafe' => $failsafe,
1.1 raeburn 16633: }
16634: );
1.4 raeburn 16635: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
16636: $dom);
1.1 raeburn 16637: if ($putresult eq 'ok') {
16638: if (exists($currautoenroll{'run'})) {
16639: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
16640: $changes{'run'} = 1;
16641: }
16642: } elsif ($autorun) {
16643: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 16644: $changes{'run'} = 1;
1.1 raeburn 16645: }
16646: }
1.17 raeburn 16647: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 16648: $changes{'sender'} = 1;
16649: }
1.17 raeburn 16650: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 16651: $changes{'sender'} = 1;
16652: }
1.129 raeburn 16653: if ($currautoenroll{'co-owners'} ne '') {
16654: if ($currautoenroll{'co-owners'} ne $coowners) {
16655: $changes{'coowners'} = 1;
16656: }
16657: } elsif ($coowners) {
16658: $changes{'coowners'} = 1;
1.274 raeburn 16659: }
1.399 raeburn 16660: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.274 raeburn 16661: $changes{'autofailsafe'} = 1;
16662: }
1.399 raeburn 16663: if ($currautoenroll{'failsafe'} ne $failsafe) {
16664: $changes{'failsafe'} = 1;
16665: }
1.1 raeburn 16666: if (keys(%changes) > 0) {
16667: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 16668: if ($changes{'run'}) {
1.1 raeburn 16669: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
16670: }
16671: if ($changes{'sender'}) {
1.17 raeburn 16672: if ($sender_uname eq '' || $sender_domain eq '') {
16673: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
16674: } else {
16675: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
16676: }
1.1 raeburn 16677: }
1.129 raeburn 16678: if ($changes{'coowners'}) {
16679: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
16680: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 16681: if (ref($lastactref) eq 'HASH') {
16682: $lastactref->{'domainconfig'} = 1;
16683: }
1.129 raeburn 16684: }
1.274 raeburn 16685: if ($changes{'autofailsafe'}) {
1.399 raeburn 16686: if ($autofailsafe ne '') {
16687: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.274 raeburn 16688: } else {
1.399 raeburn 16689: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.274 raeburn 16690: }
1.399 raeburn 16691: }
16692: if ($changes{'failsafe'}) {
16693: if ($failsafe eq 'off') {
16694: unless ($changes{'autofailsafe'}) {
16695: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
16696: }
16697: } elsif ($failsafe eq 'zero') {
16698: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
16699: } else {
16700: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
16701: }
16702: }
16703: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.274 raeburn 16704: &Apache::lonnet::get_domain_defaults($dom,1);
16705: if (ref($lastactref) eq 'HASH') {
16706: $lastactref->{'domdefaults'} = 1;
16707: }
16708: }
1.1 raeburn 16709: $resulttext .= '</ul>';
16710: } else {
16711: $resulttext = &mt('No changes made to auto-enrollment settings');
16712: }
16713: } else {
1.11 albertel 16714: $resulttext = '<span class="LC_error">'.
16715: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16716: }
1.3 raeburn 16717: return $resulttext;
1.1 raeburn 16718: }
16719:
16720: sub modify_autoupdate {
1.3 raeburn 16721: my ($dom,%domconfig) = @_;
1.1 raeburn 16722: my ($resulttext,%currautoupdate,%fields,%changes);
16723: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
16724: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
16725: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
16726: }
16727: }
16728: my @offon = ('off','on');
16729: my %title = &Apache::lonlocal::texthash (
1.385 raeburn 16730: run => 'Auto-update:',
16731: classlists => 'Updates to user information in classlists?',
16732: unexpired => 'Skip updates for users without active or future roles?',
16733: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 16734: );
1.44 raeburn 16735: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 16736: my %fieldtitles = &Apache::lonlocal::texthash (
16737: id => 'Student/Employee ID',
1.20 raeburn 16738: permanentemail => 'E-mail address',
1.1 raeburn 16739: lastname => 'Last Name',
16740: firstname => 'First Name',
16741: middlename => 'Middle Name',
1.132 raeburn 16742: generation => 'Generation',
1.1 raeburn 16743: );
1.142 raeburn 16744: $othertitle = &mt('All users');
1.1 raeburn 16745: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 16746: $othertitle = &mt('Other users');
1.1 raeburn 16747: }
16748: foreach my $key (keys(%env)) {
16749: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 16750: my ($usertype,$item) = ($1,$2);
16751: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
16752: if ($usertype eq 'default') {
16753: push(@{$fields{$1}},$2);
16754: } elsif (ref($types) eq 'ARRAY') {
16755: if (grep(/^\Q$usertype\E$/,@{$types})) {
16756: push(@{$fields{$1}},$2);
16757: }
16758: }
16759: }
1.1 raeburn 16760: }
16761: }
1.131 raeburn 16762: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
16763: @lockablenames = sort(@lockablenames);
16764: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
16765: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16766: if (@changed) {
16767: $changes{'lockablenames'} = 1;
16768: }
16769: } else {
16770: if (@lockablenames) {
16771: $changes{'lockablenames'} = 1;
16772: }
16773: }
1.1 raeburn 16774: my %updatehash = (
16775: autoupdate => { run => $env{'form.autoupdate_run'},
16776: classlists => $env{'form.classlists'},
1.385 raeburn 16777: unexpired => $env{'form.unexpired'},
1.1 raeburn 16778: fields => {%fields},
1.131 raeburn 16779: lockablenames => \@lockablenames,
1.1 raeburn 16780: }
16781: );
1.385 raeburn 16782: my $lastactivedays;
16783: if ($env{'form.lastactive'}) {
16784: $lastactivedays = $env{'form.lastactivedays'};
16785: $lastactivedays =~ s/^\s+|\s+$//g;
16786: unless ($lastactivedays =~ /^\d+$/) {
16787: undef($lastactivedays);
16788: $env{'form.lastactive'} = 0;
16789: }
16790: }
16791: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 16792: foreach my $key (keys(%currautoupdate)) {
1.385 raeburn 16793: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 16794: if (exists($updatehash{autoupdate}{$key})) {
16795: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
16796: $changes{$key} = 1;
16797: }
16798: }
16799: } elsif ($key eq 'fields') {
16800: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 16801: foreach my $item (@{$types},'default') {
1.1 raeburn 16802: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
16803: my $change = 0;
16804: foreach my $type (@{$currautoupdate{$key}{$item}}) {
16805: if (!exists($fields{$item})) {
16806: $change = 1;
1.132 raeburn 16807: last;
1.1 raeburn 16808: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 16809: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 16810: $change = 1;
1.132 raeburn 16811: last;
1.1 raeburn 16812: }
16813: }
16814: }
16815: if ($change) {
16816: push(@{$changes{$key}},$item);
16817: }
1.26 raeburn 16818: }
1.1 raeburn 16819: }
16820: }
1.131 raeburn 16821: } elsif ($key eq 'lockablenames') {
16822: if (ref($currautoupdate{$key}) eq 'ARRAY') {
16823: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16824: if (@changed) {
16825: $changes{'lockablenames'} = 1;
16826: }
16827: } else {
16828: if (@lockablenames) {
16829: $changes{'lockablenames'} = 1;
16830: }
16831: }
16832: }
16833: }
16834: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
16835: if (@lockablenames) {
16836: $changes{'lockablenames'} = 1;
1.1 raeburn 16837: }
16838: }
1.385 raeburn 16839: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
16840: if ($updatehash{'autoupdate'}{'unexpired'}) {
16841: $changes{'unexpired'} = 1;
16842: }
16843: }
16844: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
16845: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
16846: $changes{'lastactive'} = 1;
16847: }
16848: }
1.26 raeburn 16849: foreach my $item (@{$types},'default') {
16850: if (defined($fields{$item})) {
16851: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 16852: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
16853: my $change = 0;
16854: if (ref($fields{$item}) eq 'ARRAY') {
16855: foreach my $type (@{$fields{$item}}) {
16856: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
16857: $change = 1;
16858: last;
16859: }
16860: }
16861: }
16862: if ($change) {
16863: push(@{$changes{'fields'}},$item);
16864: }
16865: } else {
1.26 raeburn 16866: push(@{$changes{'fields'}},$item);
16867: }
16868: } else {
16869: push(@{$changes{'fields'}},$item);
1.1 raeburn 16870: }
16871: }
16872: }
16873: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
16874: $dom);
16875: if ($putresult eq 'ok') {
16876: if (keys(%changes) > 0) {
16877: $resulttext = &mt('Changes made:').'<ul>';
16878: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 16879: if ($key eq 'lockablenames') {
16880: $resulttext .= '<li>';
16881: if (@lockablenames) {
16882: $usertypes->{'default'} = $othertitle;
16883: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
16884: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
16885: } else {
16886: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
16887: }
16888: $resulttext .= '</li>';
16889: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 16890: foreach my $item (@{$changes{$key}}) {
16891: my @newvalues;
16892: foreach my $type (@{$fields{$item}}) {
16893: push(@newvalues,$fieldtitles{$type});
16894: }
1.3 raeburn 16895: my $newvaluestr;
16896: if (@newvalues > 0) {
16897: $newvaluestr = join(', ',@newvalues);
16898: } else {
16899: $newvaluestr = &mt('none');
1.6 raeburn 16900: }
1.1 raeburn 16901: if ($item eq 'default') {
1.26 raeburn 16902: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 16903: } else {
1.26 raeburn 16904: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 16905: }
16906: }
16907: } else {
16908: my $newvalue;
16909: if ($key eq 'run') {
16910: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.385 raeburn 16911: } elsif ($key eq 'lastactive') {
16912: $newvalue = $offon[$env{'form.lastactive'}];
16913: unless ($lastactivedays eq '') {
16914: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
16915: }
1.1 raeburn 16916: } else {
16917: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 16918: }
1.1 raeburn 16919: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
16920: }
16921: }
16922: $resulttext .= '</ul>';
16923: } else {
1.3 raeburn 16924: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 16925: }
16926: } else {
1.11 albertel 16927: $resulttext = '<span class="LC_error">'.
16928: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16929: }
1.3 raeburn 16930: return $resulttext;
1.1 raeburn 16931: }
16932:
1.125 raeburn 16933: sub modify_autocreate {
16934: my ($dom,%domconfig) = @_;
16935: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
16936: if (ref($domconfig{'autocreate'}) eq 'HASH') {
16937: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
16938: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
16939: }
16940: }
16941: my %title= ( xml => 'Auto-creation of courses in XML course description files',
16942: req => 'Auto-creation of validated requests for official courses',
16943: xmldc => 'Identity of course creator of courses from XML files',
16944: );
16945: my @types = ('xml','req');
16946: foreach my $item (@types) {
16947: $newvals{$item} = $env{'form.autocreate_'.$item};
16948: $newvals{$item} =~ s/\D//g;
16949: $newvals{$item} = 0 if ($newvals{$item} eq '');
16950: }
16951: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 16952: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 16953: unless (exists($domcoords{$newvals{'xmldc'}})) {
16954: $newvals{'xmldc'} = '';
16955: }
16956: %autocreatehash = (
16957: autocreate => { xml => $newvals{'xml'},
16958: req => $newvals{'req'},
16959: }
16960: );
16961: if ($newvals{'xmldc'} ne '') {
16962: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
16963: }
16964: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
16965: $dom);
16966: if ($putresult eq 'ok') {
16967: my @items = @types;
16968: if ($newvals{'xml'}) {
16969: push(@items,'xmldc');
16970: }
16971: foreach my $item (@items) {
16972: if (exists($currautocreate{$item})) {
16973: if ($currautocreate{$item} ne $newvals{$item}) {
16974: $changes{$item} = 1;
16975: }
16976: } elsif ($newvals{$item}) {
16977: $changes{$item} = 1;
16978: }
16979: }
16980: if (keys(%changes) > 0) {
16981: my @offon = ('off','on');
16982: $resulttext = &mt('Changes made:').'<ul>';
16983: foreach my $item (@types) {
16984: if ($changes{$item}) {
16985: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 16986: $resulttext .= '<li>'.
16987: &mt("$title{$item} set to [_1]$newtxt [_2]",
16988: '<b>','</b>').
16989: '</li>';
1.125 raeburn 16990: }
16991: }
16992: if ($changes{'xmldc'}) {
16993: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
16994: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 16995: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 16996: }
16997: $resulttext .= '</ul>';
16998: } else {
16999: $resulttext = &mt('No changes made to auto-creation settings');
17000: }
17001: } else {
17002: $resulttext = '<span class="LC_error">'.
17003: &mt('An error occurred: [_1]',$putresult).'</span>';
17004: }
17005: return $resulttext;
17006: }
17007:
1.23 raeburn 17008: sub modify_directorysrch {
1.295 raeburn 17009: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 17010: my ($resulttext,%changes);
17011: my %currdirsrch;
17012: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
17013: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
17014: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
17015: }
17016: }
1.277 raeburn 17017: my %title = ( available => 'Institutional directory search available',
17018: localonly => 'Other domains can search institution',
17019: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 17020: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 17021: searchby => 'Search types',
17022: searchtypes => 'Search latitude');
17023: my @offon = ('off','on');
1.24 raeburn 17024: my @otherdoms = ('Yes','No');
1.23 raeburn 17025:
1.25 raeburn 17026: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 17027: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
17028: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
17029:
1.44 raeburn 17030: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 17031: if (keys(%{$usertypes}) == 0) {
17032: @cansearch = ('default');
17033: } else {
17034: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
17035: foreach my $type (@{$currdirsrch{'cansearch'}}) {
17036: if (!grep(/^\Q$type\E$/,@cansearch)) {
17037: push(@{$changes{'cansearch'}},$type);
17038: }
1.23 raeburn 17039: }
1.26 raeburn 17040: foreach my $type (@cansearch) {
17041: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
17042: push(@{$changes{'cansearch'}},$type);
17043: }
1.23 raeburn 17044: }
1.26 raeburn 17045: } else {
17046: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 17047: }
17048: }
17049:
17050: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
17051: foreach my $by (@{$currdirsrch{'searchby'}}) {
17052: if (!grep(/^\Q$by\E$/,@searchby)) {
17053: push(@{$changes{'searchby'}},$by);
17054: }
17055: }
17056: foreach my $by (@searchby) {
17057: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
17058: push(@{$changes{'searchby'}},$by);
17059: }
17060: }
17061: } else {
17062: push(@{$changes{'searchby'}},@searchby);
17063: }
1.25 raeburn 17064:
17065: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
17066: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
17067: if (!grep(/^\Q$type\E$/,@searchtypes)) {
17068: push(@{$changes{'searchtypes'}},$type);
17069: }
17070: }
17071: foreach my $type (@searchtypes) {
17072: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
17073: push(@{$changes{'searchtypes'}},$type);
17074: }
17075: }
17076: } else {
17077: if (exists($currdirsrch{'searchtypes'})) {
17078: foreach my $type (@searchtypes) {
17079: if ($type ne $currdirsrch{'searchtypes'}) {
17080: push(@{$changes{'searchtypes'}},$type);
17081: }
17082: }
17083: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
17084: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
17085: }
17086: } else {
17087: push(@{$changes{'searchtypes'}},@searchtypes);
17088: }
17089: }
17090:
1.23 raeburn 17091: my %dirsrch_hash = (
17092: directorysrch => { available => $env{'form.dirsrch_available'},
17093: cansearch => \@cansearch,
1.277 raeburn 17094: localonly => $env{'form.dirsrch_instlocalonly'},
17095: lclocalonly => $env{'form.dirsrch_domlocalonly'},
17096: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 17097: searchby => \@searchby,
1.25 raeburn 17098: searchtypes => \@searchtypes,
1.23 raeburn 17099: }
17100: );
17101: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
17102: $dom);
17103: if ($putresult eq 'ok') {
17104: if (exists($currdirsrch{'available'})) {
17105: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
17106: $changes{'available'} = 1;
17107: }
17108: } else {
17109: if ($env{'form.dirsrch_available'} eq '1') {
17110: $changes{'available'} = 1;
17111: }
17112: }
1.277 raeburn 17113: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 17114: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
17115: $changes{'lcavailable'} = 1;
17116: }
1.277 raeburn 17117: } else {
17118: if ($env{'form.dirsrch_lcavailable'} eq '1') {
17119: $changes{'lcavailable'} = 1;
17120: }
17121: }
1.24 raeburn 17122: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 17123: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
17124: $changes{'localonly'} = 1;
17125: }
1.24 raeburn 17126: } else {
1.277 raeburn 17127: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 17128: $changes{'localonly'} = 1;
17129: }
17130: }
1.277 raeburn 17131: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 17132: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
17133: $changes{'lclocalonly'} = 1;
17134: }
1.277 raeburn 17135: } else {
17136: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
17137: $changes{'lclocalonly'} = 1;
17138: }
17139: }
1.23 raeburn 17140: if (keys(%changes) > 0) {
17141: $resulttext = &mt('Changes made:').'<ul>';
17142: if ($changes{'available'}) {
17143: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
17144: }
1.277 raeburn 17145: if ($changes{'lcavailable'}) {
17146: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
17147: }
1.24 raeburn 17148: if ($changes{'localonly'}) {
1.277 raeburn 17149: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 17150: }
1.277 raeburn 17151: if ($changes{'lclocalonly'}) {
17152: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 17153: }
1.23 raeburn 17154: if (ref($changes{'cansearch'}) eq 'ARRAY') {
17155: my $chgtext;
1.26 raeburn 17156: if (ref($usertypes) eq 'HASH') {
17157: if (keys(%{$usertypes}) > 0) {
17158: foreach my $type (@{$types}) {
17159: if (grep(/^\Q$type\E$/,@cansearch)) {
17160: $chgtext .= $usertypes->{$type}.'; ';
17161: }
17162: }
17163: if (grep(/^default$/,@cansearch)) {
17164: $chgtext .= $othertitle;
17165: } else {
17166: $chgtext =~ s/\; $//;
17167: }
1.210 raeburn 17168: $resulttext .=
1.178 raeburn 17169: '<li>'.
17170: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
17171: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
17172: '</li>';
1.23 raeburn 17173: }
17174: }
17175: }
17176: if (ref($changes{'searchby'}) eq 'ARRAY') {
17177: my ($searchtitles,$titleorder) = &sorted_searchtitles();
17178: my $chgtext;
17179: foreach my $type (@{$titleorder}) {
17180: if (grep(/^\Q$type\E$/,@searchby)) {
17181: if (defined($searchtitles->{$type})) {
17182: $chgtext .= $searchtitles->{$type}.'; ';
17183: }
17184: }
17185: }
17186: $chgtext =~ s/\; $//;
17187: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
17188: }
1.25 raeburn 17189: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
17190: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
17191: my $chgtext;
17192: foreach my $type (@{$srchtypeorder}) {
17193: if (grep(/^\Q$type\E$/,@searchtypes)) {
17194: if (defined($srchtypes_desc->{$type})) {
17195: $chgtext .= $srchtypes_desc->{$type}.'; ';
17196: }
17197: }
17198: }
17199: $chgtext =~ s/\; $//;
1.178 raeburn 17200: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 17201: }
17202: $resulttext .= '</ul>';
1.295 raeburn 17203: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
17204: if (ref($lastactref) eq 'HASH') {
17205: $lastactref->{'directorysrch'} = 1;
17206: }
1.23 raeburn 17207: } else {
1.277 raeburn 17208: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 17209: }
17210: } else {
17211: $resulttext = '<span class="LC_error">'.
1.27 raeburn 17212: &mt('An error occurred: [_1]',$putresult).'</span>';
17213: }
17214: return $resulttext;
17215: }
17216:
1.28 raeburn 17217: sub modify_contacts {
1.205 raeburn 17218: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 17219: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
17220: if (ref($domconfig{'contacts'}) eq 'HASH') {
17221: foreach my $key (keys(%{$domconfig{'contacts'}})) {
17222: $currsetting{$key} = $domconfig{'contacts'}{$key};
17223: }
17224: }
1.286 raeburn 17225: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 17226: my @contacts = ('supportemail','adminemail');
1.286 raeburn 17227: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350 raeburn 17228: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340 raeburn 17229: my @toggles = ('reporterrors','reportupdates','reportstatus');
17230: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 17231: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 17232: foreach my $type (@mailings) {
17233: @{$newsetting{$type}} =
17234: &Apache::loncommon::get_env_multiple('form.'.$type);
17235: foreach my $item (@contacts) {
17236: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
17237: $contacts_hash{contacts}{$type}{$item} = 1;
17238: } else {
17239: $contacts_hash{contacts}{$type}{$item} = 0;
17240: }
1.289 raeburn 17241: }
1.28 raeburn 17242: $others{$type} = $env{'form.'.$type.'_others'};
17243: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 17244: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17245: $bcc{$type} = $env{'form.'.$type.'_bcc'};
17246: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 17247: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
17248: $includestr{$type} = $env{'form.'.$type.'_includestr'};
17249: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
17250: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17251: }
1.134 raeburn 17252: }
1.28 raeburn 17253: }
17254: foreach my $item (@contacts) {
17255: $to{$item} = $env{'form.'.$item};
17256: $contacts_hash{'contacts'}{$item} = $to{$item};
17257: }
1.203 raeburn 17258: foreach my $item (@toggles) {
17259: if ($env{'form.'.$item} =~ /^(0|1)$/) {
17260: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
17261: }
17262: }
1.340 raeburn 17263: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
17264: foreach my $item (@lonstatus) {
17265: if ($item eq 'excluded') {
17266: my (%serverhomes,@excluded);
17267: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
17268: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
17269: if (@possexcluded) {
17270: foreach my $id (sort(@possexcluded)) {
17271: if ($serverhomes{$id}) {
17272: push(@excluded,$id);
17273: }
17274: }
17275: }
17276: if (@excluded) {
17277: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
17278: }
17279: } elsif ($item eq 'weights') {
1.377 raeburn 17280: foreach my $type ('E','W','N','U') {
1.340 raeburn 17281: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
17282: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
17283: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
17284: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
17285: $env{'form.error'.$item.'_'.$type};
17286: }
17287: }
17288: }
17289: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
17290: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
17291: if ($env{'form.error'.$item} =~ /^\d+$/) {
17292: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
17293: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
17294: }
17295: }
17296: }
17297: }
1.286 raeburn 17298: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
17299: foreach my $field (@{$fields}) {
17300: if (ref($possoptions->{$field}) eq 'ARRAY') {
17301: my $value = $env{'form.helpform_'.$field};
17302: $value =~ s/^\s+|\s+$//g;
17303: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 17304: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 17305: if ($field eq 'screenshot') {
17306: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
17307: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 17308: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 17309: }
17310: }
17311: }
17312: }
17313: }
17314: }
1.315 raeburn 17315: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17316: my (@statuses,%usertypeshash,@overrides);
17317: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
17318: @statuses = @{$types};
17319: if (ref($usertypes) eq 'HASH') {
17320: %usertypeshash = %{$usertypes};
17321: }
17322: }
17323: if (@statuses) {
17324: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
17325: foreach my $type (@possoverrides) {
17326: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
17327: push(@overrides,$type);
17328: }
17329: }
17330: if (@overrides) {
17331: foreach my $type (@overrides) {
17332: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
17333: foreach my $item (@contacts) {
17334: if (grep(/^\Q$item\E$/,@standard)) {
17335: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
17336: $newsetting{'override_'.$type}{$item} = 1;
17337: } else {
17338: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
17339: $newsetting{'override_'.$type}{$item} = 0;
17340: }
17341: }
17342: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
17343: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17344: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
17345: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17346: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
17347: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
17348: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
17349: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17350: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
17351: }
1.425 raeburn 17352: }
1.315 raeburn 17353: }
17354: }
1.28 raeburn 17355: if (keys(%currsetting) > 0) {
17356: foreach my $item (@contacts) {
17357: if ($to{$item} ne $currsetting{$item}) {
17358: $changes{$item} = 1;
17359: }
17360: }
17361: foreach my $type (@mailings) {
17362: foreach my $item (@contacts) {
17363: if (ref($currsetting{$type}) eq 'HASH') {
17364: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
17365: push(@{$changes{$type}},$item);
17366: }
17367: } else {
17368: push(@{$changes{$type}},@{$newsetting{$type}});
17369: }
17370: }
17371: if ($others{$type} ne $currsetting{$type}{'others'}) {
17372: push(@{$changes{$type}},'others');
17373: }
1.289 raeburn 17374: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17375: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
17376: push(@{$changes{$type}},'bcc');
17377: }
1.286 raeburn 17378: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
17379: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
17380: push(@{$changes{$type}},'include');
17381: }
17382: }
17383: }
17384: if (ref($fields) eq 'ARRAY') {
17385: if (ref($currsetting{'helpform'}) eq 'HASH') {
17386: foreach my $field (@{$fields}) {
17387: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
17388: push(@{$changes{'helpform'}},$field);
17389: }
17390: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17391: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
17392: push(@{$changes{'helpform'}},'maxsize');
17393: }
17394: }
17395: }
17396: } else {
17397: foreach my $field (@{$fields}) {
17398: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17399: push(@{$changes{'helpform'}},$field);
17400: }
17401: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17402: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17403: push(@{$changes{'helpform'}},'maxsize');
17404: }
17405: }
17406: }
1.134 raeburn 17407: }
1.28 raeburn 17408: }
1.315 raeburn 17409: if (@statuses) {
1.425 raeburn 17410: if (ref($currsetting{'overrides'}) eq 'HASH') {
1.315 raeburn 17411: foreach my $key (keys(%{$currsetting{'overrides'}})) {
17412: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
17413: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
17414: foreach my $item (@contacts,'bcc','others','include') {
1.425 raeburn 17415: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
1.315 raeburn 17416: push(@{$changes{'overrides'}},$key);
17417: last;
17418: }
17419: }
17420: } else {
17421: push(@{$changes{'overrides'}},$key);
17422: }
17423: }
17424: }
17425: foreach my $key (@overrides) {
17426: unless (exists($currsetting{'overrides'}{$key})) {
17427: push(@{$changes{'overrides'}},$key);
17428: }
17429: }
17430: } else {
17431: foreach my $key (@overrides) {
1.425 raeburn 17432: push(@{$changes{'overrides'}},$key);
1.315 raeburn 17433: }
17434: }
17435: }
1.340 raeburn 17436: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
17437: foreach my $key ('excluded','weights','threshold','sysmail') {
17438: if ($key eq 'excluded') {
17439: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17440: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
17441: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17442: (@{$currsetting{'lonstatus'}{$key}})) {
17443: my @diffs =
17444: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
17445: $currsetting{'lonstatus'}{$key});
17446: if (@diffs) {
17447: push(@{$changes{'lonstatus'}},$key);
17448: }
17449: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
17450: push(@{$changes{'lonstatus'}},$key);
17451: }
17452: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17453: (@{$currsetting{'lonstatus'}{$key}})) {
17454: push(@{$changes{'lonstatus'}},$key);
17455: }
17456: } elsif ($key eq 'weights') {
17457: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17458: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
17459: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17460: foreach my $type ('E','W','N','U') {
1.340 raeburn 17461: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
17462: $currsetting{'lonstatus'}{$key}{$type}) {
17463: push(@{$changes{'lonstatus'}},$key);
17464: last;
17465: }
17466: }
17467: } else {
1.341 raeburn 17468: foreach my $type ('E','W','N','U') {
1.340 raeburn 17469: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
17470: push(@{$changes{'lonstatus'}},$key);
17471: last;
17472: }
17473: }
17474: }
17475: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17476: foreach my $type ('E','W','N','U') {
1.340 raeburn 17477: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
17478: push(@{$changes{'lonstatus'}},$key);
17479: last;
17480: }
17481: }
17482: }
17483: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
17484: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17485: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17486: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
17487: push(@{$changes{'lonstatus'}},$key);
17488: }
17489: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
17490: push(@{$changes{'lonstatus'}},$key);
17491: }
17492: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17493: push(@{$changes{'lonstatus'}},$key);
17494: }
17495: }
17496: }
17497: } else {
17498: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17499: foreach my $key ('excluded','weights','threshold','sysmail') {
17500: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17501: push(@{$changes{'lonstatus'}},$key);
17502: }
17503: }
17504: }
17505: }
1.28 raeburn 17506: } else {
17507: my %default;
17508: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
17509: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
17510: $default{'errormail'} = 'adminemail';
17511: $default{'packagesmail'} = 'adminemail';
17512: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 17513: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 17514: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 17515: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 17516: $default{'updatesmail'} = 'adminemail';
1.350 raeburn 17517: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 17518: foreach my $item (@contacts) {
17519: if ($to{$item} ne $default{$item}) {
1.286 raeburn 17520: $changes{$item} = 1;
1.203 raeburn 17521: }
1.28 raeburn 17522: }
17523: foreach my $type (@mailings) {
17524: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
17525: push(@{$changes{$type}},@{$newsetting{$type}});
17526: }
17527: if ($others{$type} ne '') {
17528: push(@{$changes{$type}},'others');
1.134 raeburn 17529: }
1.286 raeburn 17530: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17531: if ($bcc{$type} ne '') {
17532: push(@{$changes{$type}},'bcc');
17533: }
1.286 raeburn 17534: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
17535: push(@{$changes{$type}},'include');
17536: }
1.134 raeburn 17537: }
1.28 raeburn 17538: }
1.286 raeburn 17539: if (ref($fields) eq 'ARRAY') {
17540: foreach my $field (@{$fields}) {
17541: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17542: push(@{$changes{'helpform'}},$field);
17543: }
17544: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17545: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17546: push(@{$changes{'helpform'}},'maxsize');
17547: }
17548: }
17549: }
1.289 raeburn 17550: }
1.340 raeburn 17551: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17552: foreach my $key ('excluded','weights','threshold','sysmail') {
17553: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17554: push(@{$changes{'lonstatus'}},$key);
17555: }
17556: }
17557: }
1.28 raeburn 17558: }
1.203 raeburn 17559: foreach my $item (@toggles) {
17560: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
17561: $changes{$item} = 1;
17562: } elsif ((!$env{'form.'.$item}) &&
17563: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
17564: $changes{$item} = 1;
17565: }
17566: }
1.28 raeburn 17567: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
17568: $dom);
17569: if ($putresult eq 'ok') {
17570: if (keys(%changes) > 0) {
1.205 raeburn 17571: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 17572: if (ref($lastactref) eq 'HASH') {
17573: $lastactref->{'domainconfig'} = 1;
17574: }
1.28 raeburn 17575: my ($titles,$short_titles) = &contact_titles();
17576: $resulttext = &mt('Changes made:').'<ul>';
17577: foreach my $item (@contacts) {
17578: if ($changes{$item}) {
17579: $resulttext .= '<li>'.$titles->{$item}.
17580: &mt(' set to: ').
17581: '<span class="LC_cusr_emph">'.
17582: $to{$item}.'</span></li>';
17583: }
17584: }
17585: foreach my $type (@mailings) {
17586: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 17587: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 17588: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 17589: } else {
17590: $resulttext .= '<li>'.$titles->{$type}.': ';
17591: }
1.28 raeburn 17592: my @text;
17593: foreach my $item (@{$newsetting{$type}}) {
17594: push(@text,$short_titles->{$item});
17595: }
17596: if ($others{$type} ne '') {
17597: push(@text,$others{$type});
17598: }
1.286 raeburn 17599: if (@text) {
17600: $resulttext .= '<span class="LC_cusr_emph">'.
17601: join(', ',@text).'</span>';
17602: }
17603: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17604: if ($bcc{$type} ne '') {
1.286 raeburn 17605: my $bcctext;
17606: if (@text) {
1.289 raeburn 17607: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 17608: } else {
17609: $bcctext = '(Bcc)';
17610: }
17611: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
17612: } elsif (!@text) {
17613: $resulttext .= &mt('No one');
1.425 raeburn 17614: }
1.289 raeburn 17615: if ($includestr{$type} ne '') {
1.286 raeburn 17616: if ($includeloc{$type} eq 'b') {
17617: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
17618: } elsif ($includeloc{$type} eq 's') {
17619: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
17620: }
1.134 raeburn 17621: }
1.286 raeburn 17622: } elsif (!@text) {
17623: $resulttext .= &mt('No recipients');
1.134 raeburn 17624: }
17625: $resulttext .= '</li>';
1.28 raeburn 17626: }
17627: }
1.315 raeburn 17628: if (ref($changes{'overrides'}) eq 'ARRAY') {
17629: my @deletions;
17630: foreach my $type (@{$changes{'overrides'}}) {
17631: if ($usertypeshash{$type}) {
17632: if (grep(/^\Q$type\E/,@overrides)) {
17633: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
17634: $usertypeshash{$type}).'<ul><li>';
17635: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
17636: my @text;
17637: foreach my $item (@contacts) {
1.425 raeburn 17638: if ($newsetting{'override_'.$type}{$item}) {
1.315 raeburn 17639: push(@text,$short_titles->{$item});
17640: }
17641: }
17642: if ($newsetting{'override_'.$type}{'others'} ne '') {
17643: push(@text,$newsetting{'override_'.$type}{'others'});
17644: }
1.425 raeburn 17645:
1.315 raeburn 17646: if (@text) {
17647: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
17648: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
17649: }
17650: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
17651: my $bcctext;
17652: if (@text) {
17653: $bcctext = ' '.&mt('with Bcc to');
17654: } else {
17655: $bcctext = '(Bcc)';
17656: }
17657: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
17658: } elsif (!@text) {
17659: $resulttext .= &mt('Helpdesk e-mail sent to no one');
17660: }
17661: $resulttext .= '</li>';
17662: if ($newsetting{'override_'.$type}{'include'} ne '') {
17663: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
17664: if ($loc eq 'b') {
17665: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
17666: } elsif ($loc eq 's') {
17667: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
17668: }
17669: }
17670: }
17671: $resulttext .= '</li></ul></li>';
17672: } else {
17673: push(@deletions,$usertypeshash{$type});
17674: }
17675: }
17676: }
17677: if (@deletions) {
17678: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
17679: join(', ',@deletions)).'</li>';
17680: }
17681: }
1.203 raeburn 17682: my @offon = ('off','on');
1.340 raeburn 17683: my $corelink = &core_link_msu();
1.203 raeburn 17684: if ($changes{'reporterrors'}) {
17685: $resulttext .= '<li>'.
17686: &mt('E-mail error reports to [_1] set to "'.
17687: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 17688: $corelink).
1.203 raeburn 17689: '</li>';
17690: }
17691: if ($changes{'reportupdates'}) {
17692: $resulttext .= '<li>'.
17693: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
17694: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 17695: $corelink).
1.203 raeburn 17696: '</li>';
17697: }
1.340 raeburn 17698: if ($changes{'reportstatus'}) {
17699: $resulttext .= '<li>'.
17700: &mt('E-mail status if errors above threshold to [_1] set to "'.
17701: $offon[$env{'form.reportstatus'}].'".',
17702: $corelink).
17703: '</li>';
17704: }
17705: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
17706: $resulttext .= '<li>'.
17707: &mt('Nightly status check e-mail settings').':<ul>';
17708: my (%defval,%use_def,%shown);
17709: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
17710: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
17711: $defval{'weights'} =
1.341 raeburn 17712: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 17713: $defval{'excluded'} = &mt('None');
17714: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
17715: foreach my $item ('threshold','sysmail','weights','excluded') {
17716: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
17717: if (($item eq 'threshold') || ($item eq 'sysmail')) {
17718: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
17719: } elsif ($item eq 'weights') {
17720: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 17721: foreach my $type ('E','W','N','U') {
1.340 raeburn 17722: $shown{$item} .= $lonstatus_names->{$type}.'=';
17723: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
17724: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
17725: } else {
17726: $shown{$item} .= $lonstatus_defs->{$type};
17727: }
17728: $shown{$item} .= ', ';
17729: }
17730: $shown{$item} =~ s/, $//;
17731: } else {
17732: $shown{$item} = $defval{$item};
17733: }
17734: } elsif ($item eq 'excluded') {
17735: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
17736: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
17737: } else {
17738: $shown{$item} = $defval{$item};
17739: }
17740: }
17741: } else {
17742: $shown{$item} = $defval{$item};
17743: }
17744: }
17745: } else {
17746: foreach my $item ('threshold','weights','excluded','sysmail') {
17747: $shown{$item} = $defval{$item};
17748: }
17749: }
17750: foreach my $item ('threshold','weights','excluded','sysmail') {
17751: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
17752: $shown{$item}).'</li>';
17753: }
17754: $resulttext .= '</ul></li>';
17755: }
1.286 raeburn 17756: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
17757: my (@optional,@required,@unused,$maxsizechg);
17758: foreach my $field (@{$changes{'helpform'}}) {
17759: if ($field eq 'maxsize') {
17760: $maxsizechg = 1;
17761: next;
17762: }
17763: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 17764: push(@optional,$field);
1.286 raeburn 17765: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
17766: push(@unused,$field);
17767: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 17768: push(@required,$field);
1.286 raeburn 17769: }
17770: }
17771: if (@optional) {
17772: $resulttext .= '<li>'.
17773: &mt('Help form fields changed to "Optional": [_1].',
17774: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
17775: '</li>';
17776: }
17777: if (@required) {
17778: $resulttext .= '<li>'.
17779: &mt('Help form fields changed to "Required": [_1].',
17780: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
17781: '</li>';
17782: }
17783: if (@unused) {
17784: $resulttext .= '<li>'.
17785: &mt('Help form fields changed to "Not shown": [_1].',
17786: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
17787: '</li>';
17788: }
17789: if ($maxsizechg) {
17790: $resulttext .= '<li>'.
17791: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
17792: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
17793: '</li>';
17794: }
17795: }
1.28 raeburn 17796: $resulttext .= '</ul>';
17797: } else {
1.288 raeburn 17798: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 17799: }
17800: } else {
17801: $resulttext = '<span class="LC_error">'.
17802: &mt('An error occurred: [_1].',$putresult).'</span>';
17803: }
17804: return $resulttext;
17805: }
17806:
1.357 raeburn 17807: sub modify_privacy {
1.427 raeburn 17808: my ($dom,$lastactref,%domconfig) = @_;
1.357 raeburn 17809: my ($resulttext,%current,%changes);
17810: if (ref($domconfig{'privacy'}) eq 'HASH') {
17811: %current = %{$domconfig{'privacy'}};
17812: }
17813: my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
17814: my @items = ('domain','author','course','community');
17815: my %names = &Apache::lonlocal::texthash (
17816: domain => 'Assigned domain role(s)',
17817: author => 'Assigned co-author role(s)',
17818: course => 'Assigned course role(s)',
1.416 raeburn 17819: community => 'Assigned community role(s)',
1.357 raeburn 17820: );
17821: my %roles = &Apache::lonlocal::texthash (
17822: domain => 'Domain role',
17823: author => 'Co-author role',
17824: course => 'Course role',
17825: community => 'Community role',
17826: );
17827: my %titles = &Apache::lonlocal::texthash (
17828: approval => 'Approval for role in different domain',
17829: othdom => 'User information available in other domain',
17830: priv => 'Information viewable by privileged user in same domain',
17831: unpriv => 'Information viewable by unprivileged user in same domain',
17832: instdom => 'Other domain shares institution/provider',
17833: extdom => 'Other domain has different institution/provider',
17834: none => 'Not allowed',
17835: user => 'User authorizes',
17836: domain => 'Domain Coordinator authorizes',
17837: auto => 'Unrestricted',
1.418 raeburn 17838: notify => 'Notify when role needs authorization',
1.357 raeburn 17839: );
17840: my %fieldnames = &Apache::lonlocal::texthash (
17841: id => 'Student/Employee ID',
17842: permanentemail => 'E-mail address',
17843: lastname => 'Last Name',
17844: firstname => 'First Name',
17845: middlename => 'Middle Name',
17846: generation => 'Generation',
17847: );
17848: my ($othertitle,$usertypes,$types) =
17849: &Apache::loncommon::sorted_inst_types($dom);
17850: my (%by_ip,%by_location,@intdoms,@instdoms);
17851: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
17852:
17853: my %privacyhash = (
17854: 'approval' => {
17855: instdom => {},
17856: extdom => {},
17857: },
17858: 'othdom' => {},
17859: 'priv' => {},
17860: 'unpriv' => {},
17861: );
17862: foreach my $item (@items) {
17863: if (@instdoms > 1) {
1.416 raeburn 17864: if ($env{'form.privacy_approval_instdom_'.$item} =~ /^(none|user|domain|auto)$/) {
1.357 raeburn 17865: $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
17866: }
17867: if (ref($current{'approval'}) eq 'HASH') {
17868: if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
17869: unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
17870: $changes{'approval'} = 1;
17871: }
17872: }
17873: } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
17874: $changes{'approval'} = 1;
17875: }
17876: }
17877: if (keys(%by_location) > 0) {
17878: if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
17879: $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
17880: }
17881: if (ref($current{'approval'}) eq 'HASH') {
17882: if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
17883: unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
17884: $changes{'approval'} = 1;
17885: }
17886: }
17887: } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
17888: $changes{'approval'} = 1;
17889: }
17890: }
17891: foreach my $status ('priv','unpriv') {
17892: my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
17893: my @newvalues;
17894: foreach my $field (@possibles) {
17895: if (grep(/^\Q$field\E$/,@fields)) {
17896: $privacyhash{$status}{$item}{$field} = 1;
17897: push(@newvalues,$field);
17898: }
17899: }
17900: @newvalues = sort(@newvalues);
17901: if (ref($current{$status}) eq 'HASH') {
17902: if (ref($current{$status}{$item}) eq 'HASH') {
17903: my @currvalues = sort(keys(%{$current{$status}{$item}}));
17904: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
17905: if (@diffs > 0) {
17906: $changes{$status} = 1;
17907: }
17908: }
17909: } else {
17910: my @stdfields;
17911: foreach my $field (@fields) {
17912: if ($field eq 'id') {
17913: next if ($status eq 'unpriv');
17914: next if (($status eq 'priv') && ($item eq 'community'));
17915: }
17916: push(@stdfields,$field);
17917: }
17918: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
17919: if (@diffs > 0) {
17920: $changes{$status} = 1;
17921: }
17922: }
17923: }
17924: }
17925: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
17926: my @statuses;
17927: if (ref($types) eq 'ARRAY') {
17928: @statuses = @{$types};
17929: }
17930: foreach my $type (@statuses,'default') {
17931: my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
17932: my @newvalues;
17933: foreach my $field (sort(@possfields)) {
17934: if (grep(/^\Q$field\E$/,@fields)) {
17935: $privacyhash{'othdom'}{$type}{$field} = 1;
17936: push(@newvalues,$field);
17937: }
17938: }
17939: @newvalues = sort(@newvalues);
17940: if (ref($current{'othdom'}) eq 'HASH') {
17941: if (ref($current{'othdom'}{$type}) eq 'HASH') {
17942: my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
17943: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
17944: if (@diffs > 0) {
17945: $changes{'othdom'} = 1;
17946: }
17947: }
17948: } else {
17949: my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
17950: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
17951: if (@diffs > 0) {
17952: $changes{'othdom'} = 1;
17953: }
17954: }
17955: }
1.417 raeburn 17956: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
17957: my %notify;
17958: foreach my $possdc (&Apache::loncommon::get_env_multiple('form.privacy_notify')) {
17959: if (exists($domcoords{$possdc})) {
17960: $notify{$possdc} = 1;
17961: }
17962: }
17963: my $notify = join(',',sort(keys(%notify)));
17964: if ($current{'notify'} ne $notify) {
17965: $changes{'notify'} = 1;
17966: }
17967: $privacyhash{'notify'} = $notify;
1.357 raeburn 17968: }
17969: my %confighash = (
17970: privacy => \%privacyhash,
17971: );
17972: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
17973: if ($putresult eq 'ok') {
17974: if (keys(%changes) > 0) {
17975: $resulttext = &mt('Changes made: ').'<ul>';
1.417 raeburn 17976: foreach my $key ('approval','notify','othdom','priv','unpriv') {
1.357 raeburn 17977: if ($changes{$key}) {
17978: $resulttext .= '<li>'.$titles{$key}.':<ul>';
17979: if ($key eq 'approval') {
17980: if (keys(%{$privacyhash{$key}{instdom}})) {
17981: $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
17982: foreach my $item (@items) {
17983: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
17984: }
17985: $resulttext .= '</ul></li>';
17986: }
17987: if (keys(%{$privacyhash{$key}{extdom}})) {
17988: $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
17989: foreach my $item (@items) {
17990: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
17991: }
17992: $resulttext .= '</ul></li>';
17993: }
1.417 raeburn 17994: } elsif ($key eq 'notify') {
17995: if ($privacyhash{$key}) {
17996: foreach my $dc (split(/,/,$privacyhash{$key})) {
17997: my ($dcname,$dcdom) = split(/:/,$dc);
17998: $resulttext .= '<li>'.&Apache::loncommon::plainname($dcname,$dcdom).'</li>';
17999: }
18000: } else {
18001: $resulttext .= '<li>'.&mt('No DCs to notify').'</li>';
18002: }
1.357 raeburn 18003: } elsif ($key eq 'othdom') {
18004: my @statuses;
18005: if (ref($types) eq 'ARRAY') {
18006: @statuses = @{$types};
18007: }
18008: if (ref($privacyhash{$key}) eq 'HASH') {
18009: foreach my $status (@statuses,'default') {
18010: if ($status eq 'default') {
18011: $resulttext .= '<li>'.$othertitle.': ';
18012: } elsif (ref($usertypes) eq 'HASH') {
18013: $resulttext .= '<li>'.$usertypes->{$status}.': ';
18014: } else {
18015: next;
18016: }
18017: if (ref($privacyhash{$key}{$status}) eq 'HASH') {
18018: if (keys(%{$privacyhash{$key}{$status}})) {
18019: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
18020: } else {
18021: $resulttext .= &mt('none');
18022: }
18023: }
18024: $resulttext .= '</li>';
18025: }
18026: }
18027: } else {
18028: foreach my $item (@items) {
18029: if (ref($privacyhash{$key}{$item}) eq 'HASH') {
18030: $resulttext .= '<li>'.$names{$item}.': ';
18031: if (keys(%{$privacyhash{$key}{$item}})) {
18032: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
18033: } else {
18034: $resulttext .= &mt('none');
18035: }
18036: $resulttext .= '</li>';
18037: }
18038: }
18039: }
18040: $resulttext .= '</ul></li>';
18041: }
18042: }
1.421 raeburn 18043: $resulttext .= '</ul>';
1.427 raeburn 18044: if ($changes{'approval'}) {
18045: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
18046: delete($domdefaults{'userapprovals'});
18047: if (ref($privacyhash{'approval'}) eq 'HASH') {
18048: foreach my $domtype ('instdom','extdom') {
18049: if (ref($privacyhash{'approval'}{$domtype}) eq 'HASH') {
18050: foreach my $roletype ('domain','author','course','community') {
18051: if ($privacyhash{'approval'}{$domtype}{$roletype} eq 'user') {
18052: $domdefaults{'userapprovals'} = 1;
18053: last;
18054: }
18055: }
18056: }
18057: last if ($domdefaults{'userapprovals'});
18058: }
18059: }
18060: my $cachetime = 24*60*60;
18061: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18062: if (ref($lastactref) eq 'HASH') {
18063: $lastactref->{'domdefaults'} = 1;
18064: }
18065: }
1.357 raeburn 18066: } else {
18067: $resulttext = &mt('No changes made to user information settings');
18068: }
18069: } else {
18070: $resulttext = '<span class="LC_error">'.
18071: &mt('An error occurred: [_1]',$putresult).'</span>';
18072: }
18073: return $resulttext;
18074: }
18075:
1.354 raeburn 18076: sub modify_passwords {
18077: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 raeburn 18078: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
18079: $updatedefaults,$updateconf);
1.354 raeburn 18080: my $customfn = 'resetpw.html';
18081: if (ref($domconfig{'passwords'}) eq 'HASH') {
18082: %current = %{$domconfig{'passwords'}};
18083: }
18084: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
18085: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
18086: if (ref($types) eq 'ARRAY') {
18087: @oktypes = @{$types};
18088: }
18089: push(@oktypes,'default');
18090:
18091: my %titles = &Apache::lonlocal::texthash (
18092: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
18093: intauth_check => 'Check bcrypt cost if authenticated',
18094: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
18095: permanent => 'Permanent e-mail address',
18096: critical => 'Critical notification address',
18097: notify => 'Notification address',
18098: min => 'Minimum password length',
18099: max => 'Maximum password length',
18100: chars => 'Required characters',
18101: expire => 'Password expiration (days)',
1.356 raeburn 18102: numsaved => 'Number of previous passwords to save',
1.354 raeburn 18103: reset => 'Resetting Forgotten Password',
18104: intauth => 'Encryption of Stored Passwords (Internal Auth)',
18105: rules => 'Rules for LON-CAPA Passwords',
18106: crsownerchg => 'Course Owner Changing Student Passwords',
18107: username => 'Username',
18108: email => 'E-mail address',
18109: );
18110:
18111: #
18112: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
18113: #
18114: my (%curr_defaults,%save_defaults);
18115: if (ref($domconfig{'defaults'}) eq 'HASH') {
18116: foreach my $key (keys(%{$domconfig{'defaults'}})) {
18117: if ($key =~ /^intauth_(cost|check|switch)$/) {
18118: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
18119: } else {
18120: $save_defaults{$key} = $domconfig{'defaults'}{$key};
18121: }
18122: }
18123: }
18124: my %staticdefaults = (
18125: 'resetlink' => 2,
18126: 'resetcase' => \@oktypes,
18127: 'resetprelink' => 'both',
18128: 'resetemail' => ['critical','notify','permanent'],
18129: 'intauth_cost' => 10,
18130: 'intauth_check' => 0,
18131: 'intauth_switch' => 0,
18132: );
1.365 raeburn 18133: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354 raeburn 18134: foreach my $type (@oktypes) {
18135: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
18136: }
18137: my $linklife = $env{'form.passwords_link'};
18138: $linklife =~ s/^\s+|\s+$//g;
18139: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
18140: $newvalues{'resetlink'} = $linklife;
18141: if ($current{'resetlink'}) {
18142: if ($current{'resetlink'} ne $linklife) {
18143: $changes{'reset'} = 1;
18144: }
1.368 raeburn 18145: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18146: if ($staticdefaults{'resetlink'} ne $linklife) {
18147: $changes{'reset'} = 1;
18148: }
18149: }
18150: } elsif ($current{'resetlink'}) {
18151: $changes{'reset'} = 1;
18152: }
18153: my @casesens;
18154: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
18155: foreach my $case (sort(@posscase)) {
18156: if (grep(/^\Q$case\E$/,@oktypes)) {
18157: push(@casesens,$case);
18158: }
18159: }
18160: $newvalues{'resetcase'} = \@casesens;
18161: if (ref($current{'resetcase'}) eq 'ARRAY') {
18162: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
18163: if (@diffs > 0) {
18164: $changes{'reset'} = 1;
18165: }
1.368 raeburn 18166: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18167: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
18168: if (@diffs > 0) {
18169: $changes{'reset'} = 1;
18170: }
18171: }
18172: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
18173: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
18174: if (exists($current{'resetprelink'})) {
18175: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
18176: $changes{'reset'} = 1;
18177: }
1.368 raeburn 18178: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18179: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
18180: $changes{'reset'} = 1;
18181: }
18182: }
18183: } elsif ($current{'resetprelink'}) {
18184: $changes{'reset'} = 1;
18185: }
18186: foreach my $type (@oktypes) {
18187: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
18188: my @postlink;
18189: foreach my $item (sort(@possplink)) {
18190: if ($item =~ /^(email|username)$/) {
18191: push(@postlink,$item);
18192: }
18193: }
18194: $newvalues{'resetpostlink'}{$type} = \@postlink;
18195: unless ($changes{'reset'}) {
18196: if (ref($current{'resetpostlink'}) eq 'HASH') {
18197: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
18198: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
18199: if (@diffs > 0) {
18200: $changes{'reset'} = 1;
18201: }
18202: } else {
18203: $changes{'reset'} = 1;
18204: }
1.368 raeburn 18205: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18206: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
18207: if (@diffs > 0) {
18208: $changes{'reset'} = 1;
18209: }
18210: }
18211: }
18212: }
18213: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
18214: my @resetemail;
18215: foreach my $item (sort(@possemailsrc)) {
18216: if ($item =~ /^(permanent|critical|notify)$/) {
18217: push(@resetemail,$item);
18218: }
18219: }
18220: $newvalues{'resetemail'} = \@resetemail;
18221: unless ($changes{'reset'}) {
18222: if (ref($current{'resetemail'}) eq 'ARRAY') {
18223: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
18224: if (@diffs > 0) {
18225: $changes{'reset'} = 1;
18226: }
1.368 raeburn 18227: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18228: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
18229: if (@diffs > 0) {
18230: $changes{'reset'} = 1;
18231: }
18232: }
18233: }
18234: if ($env{'form.passwords_stdtext'} == 0) {
18235: $newvalues{'resetremove'} = 1;
18236: unless ($current{'resetremove'}) {
18237: $changes{'reset'} = 1;
18238: }
18239: } elsif ($current{'resetremove'}) {
18240: $changes{'reset'} = 1;
18241: }
18242: if ($env{'form.passwords_customfile.filename'} ne '') {
18243: my $servadm = $r->dir_config('lonAdmEMail');
18244: my ($configuserok,$author_ok,$switchserver) =
18245: &config_check($dom,$confname,$servadm);
18246: my $error;
18247: if ($configuserok eq 'ok') {
18248: if ($switchserver) {
18249: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
18250: } else {
18251: if ($author_ok eq 'ok') {
1.421 raeburn 18252: my $modified = [];
1.354 raeburn 18253: my ($result,$customurl) =
1.421 raeburn 18254: &Apache::lonconfigsettings::publishlogo($r,'upload','passwords_customfile',$dom,
18255: $confname,'customtext/resetpw','','',$customfn,
18256: $modified);
1.354 raeburn 18257: if ($result eq 'ok') {
18258: $newvalues{'resetcustom'} = $customurl;
18259: $changes{'reset'} = 1;
1.421 raeburn 18260: &update_modify_urls($r,$modified);
1.354 raeburn 18261: } else {
18262: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
18263: }
18264: } else {
18265: $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);
18266: }
18267: }
18268: } else {
18269: $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);
18270: }
18271: if ($error) {
18272: &Apache::lonnet::logthis($error);
18273: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
18274: }
18275: } elsif ($current{'resetcustom'}) {
18276: if ($env{'form.passwords_custom_del'}) {
18277: $changes{'reset'} = 1;
18278: } else {
18279: $newvalues{'resetcustom'} = $current{'resetcustom'};
18280: }
18281: }
18282: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
18283: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
18284: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
18285: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
18286: $changes{'intauth'} = 1;
18287: }
18288: } else {
18289: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
18290: }
18291: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
18292: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
18293: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
18294: $changes{'intauth'} = 1;
18295: }
18296: } else {
18297: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18298: }
18299: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
18300: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
18301: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
18302: $changes{'intauth'} = 1;
18303: }
18304: } else {
18305: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18306: }
18307: foreach my $item ('cost','check','switch') {
18308: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
18309: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
18310: $updatedefaults = 1;
18311: }
18312: }
1.405 raeburn 18313: &password_rule_changes('passwords',\%newvalues,\%current,\%changes);
1.359 raeburn 18314: my %crsownerchg = (
18315: by => [],
18316: for => [],
18317: );
18318: foreach my $item ('by','for') {
18319: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
18320: foreach my $type (sort(@posstypes)) {
18321: if (grep(/^\Q$type\E$/,@oktypes)) {
18322: push(@{$crsownerchg{$item}},$type);
18323: }
18324: }
18325: }
18326: $newvalues{'crsownerchg'} = \%crsownerchg;
18327: if (ref($current{'crsownerchg'}) eq 'HASH') {
18328: foreach my $item ('by','for') {
18329: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
18330: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
18331: if (@diffs > 0) {
18332: $changes{'crsownerchg'} = 1;
18333: last;
18334: }
18335: }
18336: }
1.368 raeburn 18337: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359 raeburn 18338: foreach my $item ('by','for') {
18339: if (@{$crsownerchg{$item}} > 0) {
18340: $changes{'crsownerchg'} = 1;
18341: last;
18342: }
1.354 raeburn 18343: }
18344: }
18345:
18346: my %confighash = (
18347: defaults => \%save_defaults,
18348: passwords => \%newvalues,
18349: );
18350: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
18351:
18352: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
18353: if ($putresult eq 'ok') {
18354: if (keys(%changes) > 0) {
18355: $resulttext = &mt('Changes made: ').'<ul>';
18356: foreach my $key ('reset','intauth','rules','crsownerchg') {
18357: if ($changes{$key}) {
1.355 raeburn 18358: unless ($key eq 'intauth') {
18359: $updateconf = 1;
18360: }
1.354 raeburn 18361: $resulttext .= '<li>'.$titles{$key}.':<ul>';
18362: if ($key eq 'reset') {
18363: if ($confighash{'passwords'}{'captcha'} eq 'original') {
18364: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
18365: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
18366: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369 raeburn 18367: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
18368: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
18369: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
18370: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
18371: }
1.354 raeburn 18372: } else {
18373: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
18374: }
18375: if ($confighash{'passwords'}{'resetlink'}) {
18376: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
18377: } else {
18378: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
18379: &mt('Will default to 2 hours').'</li>';
18380: }
18381: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
18382: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
18383: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
18384: } else {
18385: my $casesens;
18386: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
18387: if ($type eq 'default') {
18388: $casesens .= $othertitle.', ';
18389: } elsif ($usertypes->{$type} ne '') {
18390: $casesens .= $usertypes->{$type}.', ';
18391: }
18392: }
18393: $casesens =~ s/\Q, \E$//;
18394: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
18395: }
18396: } else {
18397: $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>';
18398: }
18399: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
18400: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
18401: } else {
18402: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
18403: }
18404: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
18405: my $output;
18406: if (ref($types) eq 'ARRAY') {
18407: foreach my $type (@{$types}) {
18408: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
18409: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
18410: $output .= $usertypes->{$type}.' -- '.&mt('none');
18411: } else {
18412: $output .= $usertypes->{$type}.' -- '.
18413: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
18414: }
18415: }
18416: }
18417: }
18418: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
18419: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
18420: $output .= $othertitle.' -- '.&mt('none');
18421: } else {
18422: $output .= $othertitle.' -- '.
18423: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
18424: }
18425: }
18426: if ($output) {
18427: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
18428: } else {
18429: $resulttext .= '<li>'.&mt('Information required for new password form not set.').' '.&mt('Will default to requiring both the username and an e-mail address').'</li>';
18430: }
18431: } else {
18432: $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>';
18433: }
18434: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
18435: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
18436: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
18437: } else {
18438: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
18439: }
18440: } else {
1.379 raeburn 18441: $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 18442: }
18443: if ($confighash{'passwords'}{'resetremove'}) {
18444: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
18445: } else {
18446: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
18447: }
18448: if ($confighash{'passwords'}{'resetcustom'}) {
18449: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369 raeburn 18450: &mt('custom text'),600,500,undef,undef,
18451: undef,undef,'background-color:#ffffff');
18452: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354 raeburn 18453: } else {
18454: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
18455: }
18456: } elsif ($key eq 'intauth') {
18457: foreach my $item ('cost','switch','check') {
18458: my $value = $save_defaults{$key.'_'.$item};
18459: if ($item eq 'switch') {
18460: my %optiondesc = &Apache::lonlocal::texthash (
18461: 0 => 'No',
18462: 1 => 'Yes',
18463: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
18464: );
18465: if ($value =~ /^(0|1|2)$/) {
18466: $value = $optiondesc{$value};
18467: } else {
18468: $value = &mt('none -- defaults to No');
18469: }
18470: } elsif ($item eq 'check') {
18471: my %optiondesc = &Apache::lonlocal::texthash (
18472: 0 => 'No',
18473: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
18474: 2 => 'Yes, disallow login if stored cost is less than domain default',
18475: );
18476: if ($value =~ /^(0|1|2)$/) {
18477: $value = $optiondesc{$value};
18478: } else {
18479: $value = &mt('none -- defaults to No');
18480: }
18481: }
18482: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
18483: }
18484: } elsif ($key eq 'rules') {
1.356 raeburn 18485: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 18486: if ($confighash{'passwords'}{$rule} eq '') {
18487: if ($rule eq 'min') {
1.356 raeburn 18488: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365 raeburn 18489: ' '.&mt('Default of [_1] will be used',
18490: $Apache::lonnet::passwdmin).'</li>';
1.356 raeburn 18491: } else {
18492: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354 raeburn 18493: }
18494: } else {
18495: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
18496: }
18497: }
1.370 raeburn 18498: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
18499: if (@{$confighash{'passwords'}{'chars'}} > 0) {
18500: my %rulenames = &Apache::lonlocal::texthash(
18501: uc => 'At least one upper case letter',
18502: lc => 'At least one lower case letter',
18503: num => 'At least one number',
18504: spec => 'At least one non-alphanumeric',
18505: );
18506: my $needed = '<ul><li>'.
18507: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
1.425 raeburn 18508: '</li></ul>';
1.370 raeburn 18509: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
18510: } else {
18511: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18512: }
18513: } else {
18514: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18515: }
1.354 raeburn 18516: } elsif ($key eq 'crsownerchg') {
1.359 raeburn 18517: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
18518: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
18519: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
18520: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
18521: } else {
18522: my %crsownerstr;
18523: foreach my $item ('by','for') {
18524: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
18525: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
18526: if ($type eq 'default') {
18527: $crsownerstr{$item} .= $othertitle.', ';
18528: } elsif ($usertypes->{$type} ne '') {
18529: $crsownerstr{$item} .= $usertypes->{$type}.', ';
18530: }
18531: }
18532: $crsownerstr{$item} =~ s/\Q, \E$//;
18533: }
18534: }
18535: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
18536: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
18537: }
1.354 raeburn 18538: } else {
1.359 raeburn 18539: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354 raeburn 18540: }
18541: }
18542: $resulttext .= '</ul></li>';
18543: }
18544: }
18545: $resulttext .= '</ul>';
18546: } else {
18547: $resulttext = &mt('No changes made to password settings');
18548: }
1.355 raeburn 18549: my $cachetime = 24*60*60;
1.354 raeburn 18550: if ($updatedefaults) {
18551: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18552: if (ref($lastactref) eq 'HASH') {
18553: $lastactref->{'domdefaults'} = 1;
18554: }
18555: }
1.355 raeburn 18556: if ($updateconf) {
18557: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
18558: if (ref($lastactref) eq 'HASH') {
18559: $lastactref->{'passwdconf'} = 1;
18560: }
18561: }
1.354 raeburn 18562: } else {
18563: $resulttext = '<span class="LC_error">'.
18564: &mt('An error occurred: [_1]',$putresult).'</span>';
18565: }
18566: if ($errors) {
18567: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
18568: $errors.'</ul></p>';
18569: }
18570: return $resulttext;
18571: }
18572:
1.405 raeburn 18573: sub password_rule_changes {
18574: my ($prefix,$newvalues,$current,$changes) = @_;
18575: return unless ((ref($newvalues) eq 'HASH') &&
18576: (ref($current) eq 'HASH') &&
18577: (ref($changes) eq 'HASH'));
18578: my (@rules,%staticdefaults);
18579: if ($prefix eq 'passwords') {
18580: @rules = ('min','max','expire','numsaved');
1.421 raeburn 18581: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 18582: @rules = ('min','max');
18583: }
18584: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
18585: foreach my $rule (@rules) {
18586: $env{'form.'.$prefix.'_'.$rule} =~ s/^\s+|\s+$//g;
18587: my $ruleok;
18588: if ($rule eq 'expire') {
18589: if (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+(|\.\d*)$/) &&
18590: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18591: $ruleok = 1;
18592: }
18593: } elsif ($rule eq 'min') {
18594: if ($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) {
18595: if ($env{'form.'.$prefix.'_'.$rule} >= $staticdefaults{$rule}) {
18596: $ruleok = 1;
18597: }
18598: }
18599: } elsif (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) &&
18600: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18601: $ruleok = 1;
18602: }
18603: if ($ruleok) {
18604: $newvalues->{$rule} = $env{'form.'.$prefix.'_'.$rule};
18605: if (exists($current->{$rule})) {
18606: if ($newvalues->{$rule} ne $current->{$rule}) {
18607: $changes->{'rules'} = 1;
18608: }
18609: } elsif ($rule eq 'min') {
18610: if ($staticdefaults{$rule} ne $newvalues->{$rule}) {
18611: $changes->{'rules'} = 1;
18612: }
18613: } else {
18614: $changes->{'rules'} = 1;
18615: }
18616: } elsif (exists($current->{$rule})) {
18617: $changes->{'rules'} = 1;
18618: }
18619: }
18620: my @posschars = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_chars');
18621: my @chars;
18622: foreach my $item (sort(@posschars)) {
18623: if ($item =~ /^(uc|lc|num|spec)$/) {
18624: push(@chars,$item);
18625: }
18626: }
18627: $newvalues->{'chars'} = \@chars;
18628: unless ($changes->{'rules'}) {
18629: if (ref($current->{'chars'}) eq 'ARRAY') {
18630: my @diffs = &Apache::loncommon::compare_arrays($current->{'chars'},\@chars);
18631: if (@diffs > 0) {
18632: $changes->{'rules'} = 1;
18633: }
18634: } else {
18635: if (@chars > 0) {
18636: $changes->{'rules'} = 1;
18637: }
18638: }
18639: }
18640: return;
18641: }
18642:
1.28 raeburn 18643: sub modify_usercreation {
1.27 raeburn 18644: my ($dom,%domconfig) = @_;
1.224 raeburn 18645: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 18646: my $warningmsg;
1.27 raeburn 18647: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18648: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 18649: if ($key eq 'cancreate') {
18650: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18651: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 18652: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
18653: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18654: } else {
1.224 raeburn 18655: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18656: }
18657: }
18658: }
18659: } elsif ($key eq 'email_rule') {
18660: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18661: } else {
18662: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18663: }
1.27 raeburn 18664: }
18665: }
18666: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 18667: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 18668: my @contexts = ('author','course','requestcrs');
1.34 raeburn 18669: foreach my $item(@contexts) {
1.224 raeburn 18670: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 18671: }
1.34 raeburn 18672: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
18673: foreach my $item (@contexts) {
1.224 raeburn 18674: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
18675: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 18676: }
1.27 raeburn 18677: }
1.34 raeburn 18678: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
18679: foreach my $item (@contexts) {
1.43 raeburn 18680: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 18681: if ($cancreate{$item} ne 'any') {
18682: push(@{$changes{'cancreate'}},$item);
18683: }
18684: } else {
18685: if ($cancreate{$item} ne 'none') {
18686: push(@{$changes{'cancreate'}},$item);
18687: }
1.27 raeburn 18688: }
18689: }
18690: } else {
1.43 raeburn 18691: foreach my $item (@contexts) {
1.34 raeburn 18692: push(@{$changes{'cancreate'}},$item);
18693: }
1.27 raeburn 18694: }
1.34 raeburn 18695:
1.27 raeburn 18696: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
18697: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
18698: if (!grep(/^\Q$type\E$/,@username_rule)) {
18699: push(@{$changes{'username_rule'}},$type);
18700: }
18701: }
18702: foreach my $type (@username_rule) {
18703: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
18704: push(@{$changes{'username_rule'}},$type);
18705: }
18706: }
18707: } else {
18708: push(@{$changes{'username_rule'}},@username_rule);
18709: }
18710:
1.32 raeburn 18711: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
18712: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
18713: if (!grep(/^\Q$type\E$/,@id_rule)) {
18714: push(@{$changes{'id_rule'}},$type);
18715: }
18716: }
18717: foreach my $type (@id_rule) {
18718: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
18719: push(@{$changes{'id_rule'}},$type);
18720: }
18721: }
18722: } else {
18723: push(@{$changes{'id_rule'}},@id_rule);
18724: }
18725:
1.43 raeburn 18726: my @authen_contexts = ('author','course','domain');
1.325 raeburn 18727: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 18728: my %authhash;
1.43 raeburn 18729: foreach my $item (@authen_contexts) {
1.28 raeburn 18730: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
18731: foreach my $auth (@authtypes) {
18732: if (grep(/^\Q$auth\E$/,@authallowed)) {
18733: $authhash{$item}{$auth} = 1;
18734: } else {
18735: $authhash{$item}{$auth} = 0;
18736: }
18737: }
18738: }
18739: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 18740: foreach my $item (@authen_contexts) {
1.28 raeburn 18741: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
18742: foreach my $auth (@authtypes) {
18743: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
18744: push(@{$changes{'authtypes'}},$item);
18745: last;
18746: }
18747: }
18748: }
18749: }
18750: } else {
1.43 raeburn 18751: foreach my $item (@authen_contexts) {
1.28 raeburn 18752: push(@{$changes{'authtypes'}},$item);
18753: }
18754: }
18755:
1.224 raeburn 18756: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
18757: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
18758: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
18759: $save_usercreate{'id_rule'} = \@id_rule;
18760: $save_usercreate{'username_rule'} = \@username_rule,
18761: $save_usercreate{'authtypes'} = \%authhash;
18762:
1.27 raeburn 18763: my %usercreation_hash = (
1.224 raeburn 18764: usercreation => \%save_usercreate,
18765: );
1.27 raeburn 18766:
18767: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
18768: $dom);
1.50 raeburn 18769:
1.224 raeburn 18770: if ($putresult eq 'ok') {
18771: if (keys(%changes) > 0) {
18772: $resulttext = &mt('Changes made:').'<ul>';
18773: if (ref($changes{'cancreate'}) eq 'ARRAY') {
18774: my %lt = &usercreation_types();
18775: foreach my $type (@{$changes{'cancreate'}}) {
18776: my $chgtext = $lt{$type}.', ';
18777: if ($cancreate{$type} eq 'none') {
18778: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
18779: } elsif ($cancreate{$type} eq 'any') {
18780: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
18781: } elsif ($cancreate{$type} eq 'official') {
18782: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
18783: } elsif ($cancreate{$type} eq 'unofficial') {
18784: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
18785: }
18786: $resulttext .= '<li>'.$chgtext.'</li>';
18787: }
18788: }
18789: if (ref($changes{'username_rule'}) eq 'ARRAY') {
18790: my ($rules,$ruleorder) =
18791: &Apache::lonnet::inst_userrules($dom,'username');
18792: my $chgtext = '<ul>';
18793: foreach my $type (@username_rule) {
18794: if (ref($rules->{$type}) eq 'HASH') {
18795: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
18796: }
18797: }
18798: $chgtext .= '</ul>';
18799: if (@username_rule > 0) {
18800: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18801: } else {
18802: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
18803: }
18804: }
18805: if (ref($changes{'id_rule'}) eq 'ARRAY') {
18806: my ($idrules,$idruleorder) =
18807: &Apache::lonnet::inst_userrules($dom,'id');
18808: my $chgtext = '<ul>';
18809: foreach my $type (@id_rule) {
18810: if (ref($idrules->{$type}) eq 'HASH') {
18811: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
18812: }
18813: }
18814: $chgtext .= '</ul>';
18815: if (@id_rule > 0) {
18816: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18817: } else {
18818: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
18819: }
18820: }
18821: my %authname = &authtype_names();
18822: my %context_title = &context_names();
18823: if (ref($changes{'authtypes'}) eq 'ARRAY') {
18824: my $chgtext = '<ul>';
18825: foreach my $type (@{$changes{'authtypes'}}) {
18826: my @allowed;
18827: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
18828: foreach my $auth (@authtypes) {
18829: if ($authhash{$type}{$auth}) {
18830: push(@allowed,$authname{$auth});
18831: }
18832: }
18833: if (@allowed > 0) {
18834: $chgtext .= join(', ',@allowed).'</li>';
18835: } else {
18836: $chgtext .= &mt('none').'</li>';
18837: }
18838: }
18839: $chgtext .= '</ul>';
18840: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
18841: $resulttext .= '</li>';
18842: }
18843: $resulttext .= '</ul>';
18844: } else {
18845: $resulttext = &mt('No changes made to user creation settings');
18846: }
18847: } else {
18848: $resulttext = '<span class="LC_error">'.
18849: &mt('An error occurred: [_1]',$putresult).'</span>';
18850: }
18851: if ($warningmsg ne '') {
18852: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
18853: }
18854: return $resulttext;
18855: }
18856:
18857: sub modify_selfcreation {
1.305 raeburn 18858: my ($dom,$lastactref,%domconfig) = @_;
18859: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
18860: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
18861: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 18862: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
18863: if (ref($typesref) eq 'ARRAY') {
18864: @types = @{$typesref};
18865: }
18866: if (ref($usertypesref) eq 'HASH') {
18867: %usertypes = %{$usertypesref};
1.228 raeburn 18868: }
1.303 raeburn 18869: $usertypes{'default'} = $othertitle;
1.224 raeburn 18870: #
18871: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
18872: #
18873: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18874: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
18875: if ($key eq 'cancreate') {
18876: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18877: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
18878: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 18879: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
18880: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
18881: ($item eq 'emailusername') || ($item eq 'shibenv') ||
18882: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 18883: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 18884: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18885: } else {
18886: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18887: }
18888: }
18889: }
18890: } elsif ($key eq 'email_rule') {
18891: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18892: } else {
18893: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18894: }
18895: }
18896: }
18897: #
18898: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
18899: #
18900: if (ref($domconfig{'usermodification'}) eq 'HASH') {
18901: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
18902: if ($key eq 'selfcreate') {
18903: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
18904: } else {
18905: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
18906: }
18907: }
18908: }
1.305 raeburn 18909: #
18910: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
18911: #
18912: if (ref($domconfig{'inststatus'}) eq 'HASH') {
18913: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
18914: if ($key eq 'inststatusguest') {
18915: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
18916: } else {
18917: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
18918: }
18919: }
18920: }
1.224 raeburn 18921:
18922: my @contexts = ('selfcreate');
18923: @{$cancreate{'selfcreate'}} = ();
18924: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 18925: if (@types) {
18926: @{$cancreate{'statustocreate'}} = ();
18927: }
1.236 raeburn 18928: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 18929: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 18930: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 18931: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 18932: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 18933: my %selfcreatetypes = (
18934: sso => 'users authenticated by institutional single sign on',
18935: login => 'users authenticated by institutional log-in',
1.303 raeburn 18936: email => 'users verified by e-mail',
1.50 raeburn 18937: );
1.224 raeburn 18938: #
18939: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
18940: # is permitted.
18941: #
1.305 raeburn 18942: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 18943:
1.305 raeburn 18944: my (@statuses,%email_rule);
1.228 raeburn 18945: foreach my $item ('login','sso','email') {
1.224 raeburn 18946: if ($item eq 'email') {
1.236 raeburn 18947: if ($env{'form.cancreate_email'}) {
1.305 raeburn 18948: if (@types) {
18949: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
18950: foreach my $status (@poss_statuses) {
18951: if (grep(/^\Q$status\E$/,(@types,'default'))) {
18952: push(@statuses,$status);
18953: }
18954: }
18955: $save_inststatus{'inststatusguest'} = \@statuses;
18956: } else {
18957: push(@statuses,'default');
18958: }
18959: if (@statuses) {
18960: my %curr_rule;
18961: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
18962: foreach my $type (@statuses) {
18963: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 18964: }
1.305 raeburn 18965: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
18966: foreach my $type (@statuses) {
18967: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
18968: }
18969: }
18970: push(@{$cancreate{'selfcreate'}},'email');
18971: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
18972: my %curremaildom;
18973: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
18974: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
18975: }
18976: foreach my $type (@statuses) {
18977: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
18978: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
18979: }
18980: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
18981: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
18982: }
18983: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
18984: #
18985: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
18986: #
18987: my $chosen = $1;
18988: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
18989: my $emaildom;
18990: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
1.425 raeburn 18991: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
1.305 raeburn 18992: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
18993: if (ref($curremaildom{$type}) eq 'HASH') {
18994: if (exists($curremaildom{$type}{$chosen})) {
18995: if ($curremaildom{$type}{$chosen} ne $emaildom) {
18996: push(@{$changes{'cancreate'}},'emaildomain');
18997: }
18998: } elsif ($emaildom ne '') {
18999: push(@{$changes{'cancreate'}},'emaildomain');
19000: }
19001: } elsif ($emaildom ne '') {
19002: push(@{$changes{'cancreate'}},'emaildomain');
1.425 raeburn 19003: }
1.305 raeburn 19004: }
19005: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
19006: } elsif ($chosen eq 'custom') {
19007: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
19008: $email_rule{$type} = [];
19009: if (ref($emailrules) eq 'HASH') {
19010: foreach my $rule (@possemail_rules) {
19011: if (exists($emailrules->{$rule})) {
19012: push(@{$email_rule{$type}},$rule);
19013: }
19014: }
19015: }
19016: if (@{$email_rule{$type}}) {
19017: $cancreate{'emailoptions'}{$type} = 'custom';
19018: if (ref($curr_rule{$type}) eq 'ARRAY') {
19019: if (@{$curr_rule{$type}} > 0) {
19020: foreach my $rule (@{$curr_rule{$type}}) {
19021: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
19022: push(@{$changes{'email_rule'}},$type);
19023: }
19024: }
19025: }
19026: foreach my $type (@{$email_rule{$type}}) {
19027: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
19028: push(@{$changes{'email_rule'}},$type);
19029: }
19030: }
19031: } else {
19032: push(@{$changes{'email_rule'}},$type);
19033: }
19034: }
19035: } else {
19036: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
19037: }
19038: }
19039: }
19040: if (@types) {
19041: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19042: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
19043: if (@changed) {
19044: push(@{$changes{'inststatus'}},'inststatusguest');
19045: }
19046: } else {
19047: push(@{$changes{'inststatus'}},'inststatusguest');
19048: }
19049: }
19050: } else {
19051: delete($env{'form.cancreate_email'});
19052: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19053: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
19054: push(@{$changes{'inststatus'}},'inststatusguest');
19055: }
19056: }
19057: }
19058: } else {
19059: $save_inststatus{'inststatusguest'} = [];
19060: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19061: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
19062: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 19063: }
19064: }
1.224 raeburn 19065: }
19066: } else {
19067: if ($env{'form.cancreate_'.$item}) {
19068: push(@{$cancreate{'selfcreate'}},$item);
19069: }
19070: }
19071: }
1.305 raeburn 19072: my (%userinfo,%savecaptcha);
1.224 raeburn 19073: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
19074: #
1.228 raeburn 19075: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
19076: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 19077: #
1.236 raeburn 19078:
1.244 raeburn 19079: if ($env{'form.cancreate_email'}) {
1.228 raeburn 19080: push(@contexts,'emailusername');
1.305 raeburn 19081: if (@statuses) {
19082: foreach my $type (@statuses) {
1.228 raeburn 19083: if (ref($infofields) eq 'ARRAY') {
19084: foreach my $field (@{$infofields}) {
19085: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
19086: $cancreate{'emailusername'}{$type}{$field} = $1;
19087: }
19088: }
1.224 raeburn 19089: }
19090: }
19091: }
19092: #
19093: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 19094: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 19095: #
19096:
19097: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
19098: @approvalnotify = sort(@approvalnotify);
19099: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
19100: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
19101: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
19102: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
19103: push(@{$changes{'cancreate'}},'notify');
19104: }
19105: } else {
19106: if ($cancreate{'notify'}{'approval'}) {
19107: push(@{$changes{'cancreate'}},'notify');
19108: }
19109: }
19110: } elsif ($cancreate{'notify'}{'approval'}) {
19111: push(@{$changes{'cancreate'}},'notify');
19112: }
19113:
19114: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
19115: }
19116: #
1.236 raeburn 19117: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 19118: # institutional log-in.
19119: #
19120: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
19121: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
19122: ($domdefaults{'auth_def'} eq 'localauth'))) {
19123: $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.').' '.
19124: &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.');
19125: }
19126: }
19127: my @fields = ('lastname','firstname','middlename','generation',
19128: 'permanentemail','id');
1.240 raeburn 19129: my @shibfields = (@fields,'inststatus');
1.224 raeburn 19130: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19131: #
19132: # Where usernames may created for institutional log-in and/or institutional single sign on:
19133: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
19134: # may self-create accounts
19135: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
19136: # which the user may supply, if institutional data is unavailable.
19137: #
19138: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 19139: if (@types) {
1.305 raeburn 19140: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
19141: push(@contexts,'statustocreate');
1.303 raeburn 19142: foreach my $type (@types) {
1.224 raeburn 19143: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
19144: foreach my $field (@fields) {
19145: if (grep(/^\Q$field\E$/,@modifiable)) {
19146: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
19147: } else {
19148: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
19149: }
19150: }
19151: }
19152: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 19153: foreach my $type (@types) {
1.224 raeburn 19154: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
19155: foreach my $field (@fields) {
19156: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
19157: $curr_usermodify{'selfcreate'}{$type}{$field}) {
19158: push(@{$changes{'selfcreate'}},$type);
19159: last;
19160: }
19161: }
19162: }
19163: }
19164: } else {
1.303 raeburn 19165: foreach my $type (@types) {
1.224 raeburn 19166: push(@{$changes{'selfcreate'}},$type);
19167: }
19168: }
19169: }
1.240 raeburn 19170: foreach my $field (@shibfields) {
19171: if ($env{'form.shibenv_'.$field} ne '') {
19172: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
19173: }
19174: }
19175: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
19176: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
19177: foreach my $field (@shibfields) {
19178: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
19179: push(@{$changes{'cancreate'}},'shibenv');
19180: }
19181: }
19182: } else {
19183: foreach my $field (@shibfields) {
19184: if ($env{'form.shibenv_'.$field}) {
19185: push(@{$changes{'cancreate'}},'shibenv');
19186: last;
19187: }
19188: }
19189: }
19190: }
1.224 raeburn 19191: }
19192: foreach my $item (@contexts) {
19193: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
19194: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
19195: if (ref($cancreate{$item}) eq 'ARRAY') {
19196: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
19197: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19198: push(@{$changes{'cancreate'}},$item);
19199: }
19200: }
19201: }
19202: }
19203: if (ref($cancreate{$item}) eq 'ARRAY') {
19204: foreach my $type (@{$cancreate{$item}}) {
19205: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
19206: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19207: push(@{$changes{'cancreate'}},$item);
19208: }
19209: }
19210: }
19211: }
19212: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
19213: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 19214: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
19215: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19216: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
19217: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19218: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19219: push(@{$changes{'cancreate'}},$item);
19220: }
19221: }
19222: }
1.305 raeburn 19223: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19224: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19225: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19226: push(@{$changes{'cancreate'}},$item);
19227: }
1.224 raeburn 19228: }
19229: }
19230: }
1.305 raeburn 19231: foreach my $type (keys(%{$cancreate{$item}})) {
19232: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19233: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19234: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19235: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19236: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19237: push(@{$changes{'cancreate'}},$item);
19238: }
19239: }
19240: } else {
19241: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19242: push(@{$changes{'cancreate'}},$item);
19243: }
19244: }
19245: }
1.305 raeburn 19246: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19247: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19248: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19249: push(@{$changes{'cancreate'}},$item);
19250: }
1.224 raeburn 19251: }
19252: }
19253: }
19254: }
19255: } elsif ($curr_usercreation{'cancreate'}{$item}) {
19256: if (ref($cancreate{$item}) eq 'ARRAY') {
19257: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
19258: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19259: push(@{$changes{'cancreate'}},$item);
19260: }
19261: }
1.305 raeburn 19262: }
19263: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19264: if (ref($cancreate{$item}) eq 'HASH') {
19265: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19266: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 19267: }
19268: }
19269: } elsif ($item eq 'emailusername') {
1.228 raeburn 19270: if (ref($cancreate{$item}) eq 'HASH') {
19271: foreach my $type (keys(%{$cancreate{$item}})) {
19272: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19273: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19274: if ($cancreate{$item}{$type}{$field}) {
19275: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19276: push(@{$changes{'cancreate'}},$item);
19277: }
19278: last;
19279: }
19280: }
19281: }
19282: }
1.224 raeburn 19283: }
19284: }
19285: }
19286: #
19287: # Populate %save_usercreate hash with updates to self-creation configuration.
19288: #
19289: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
19290: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 19291: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 19292: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
19293: if (ref($cancreate{'notify'}) eq 'HASH') {
19294: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
19295: }
1.236 raeburn 19296: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
19297: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
19298: }
1.303 raeburn 19299: if (ref($cancreate{'emailverified'}) eq 'HASH') {
19300: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
19301: }
1.305 raeburn 19302: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
19303: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
19304: }
1.303 raeburn 19305: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
19306: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
19307: }
1.224 raeburn 19308: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19309: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
19310: }
1.240 raeburn 19311: if (ref($cancreate{'shibenv'}) eq 'HASH') {
19312: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
19313: }
1.224 raeburn 19314: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 19315: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 19316:
19317: my %userconfig_hash = (
19318: usercreation => \%save_usercreate,
19319: usermodification => \%save_usermodify,
1.305 raeburn 19320: inststatus => \%save_inststatus,
1.224 raeburn 19321: );
1.305 raeburn 19322:
1.224 raeburn 19323: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
19324: $dom);
19325: #
1.305 raeburn 19326: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 19327: #
1.27 raeburn 19328: if ($putresult eq 'ok') {
19329: if (keys(%changes) > 0) {
19330: $resulttext = &mt('Changes made:').'<ul>';
19331: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 19332: my %lt = &selfcreation_types();
1.34 raeburn 19333: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 19334: my $chgtext = '';
1.45 raeburn 19335: if ($type eq 'selfcreate') {
1.50 raeburn 19336: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 19337: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 19338: } else {
1.224 raeburn 19339: $chgtext .= &mt('Self-creation of a new account is permitted for:').
19340: '<ul>';
1.50 raeburn 19341: foreach my $case (@{$cancreate{$type}}) {
19342: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
19343: }
19344: $chgtext .= '</ul>';
1.100 raeburn 19345: if (ref($cancreate{$type}) eq 'ARRAY') {
19346: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
19347: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19348: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 19349: $chgtext .= '<span class="LC_warning">'.
19350: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
19351: '</span><br />';
19352: }
19353: }
19354: }
19355: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 19356: if (!@statuses) {
19357: $chgtext .= '<span class="LC_warning">'.
19358: &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.").
19359: '</span><br />';
1.303 raeburn 19360:
1.100 raeburn 19361: }
19362: }
19363: }
1.43 raeburn 19364: }
1.240 raeburn 19365: } elsif ($type eq 'shibenv') {
19366: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 19367: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 19368: } else {
19369: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
19370: '<ul>';
19371: foreach my $field (@shibfields) {
19372: next if ($cancreate{$type}{$field} eq '');
19373: if ($field eq 'inststatus') {
19374: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
19375: } else {
19376: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
19377: }
19378: }
19379: $chgtext .= '</ul>';
1.303 raeburn 19380: }
1.93 raeburn 19381: } elsif ($type eq 'statustocreate') {
1.96 raeburn 19382: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
19383: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
19384: if (@{$cancreate{'selfcreate'}} > 0) {
19385: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 19386: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 19387: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 19388: $chgtext .= '<br />'.
19389: '<span class="LC_warning">'.
19390: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
19391: '</span>';
19392: }
1.303 raeburn 19393: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 19394: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 19395: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
19396: } else {
19397: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
19398: }
19399: $chgtext .= '<ul>';
19400: foreach my $case (@{$cancreate{$type}}) {
19401: if ($case eq 'default') {
19402: $chgtext .= '<li>'.$othertitle.'</li>';
19403: } else {
1.303 raeburn 19404: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 19405: }
19406: }
1.100 raeburn 19407: $chgtext .= '</ul>';
19408: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 19409: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 19410: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
19411: '</span>';
1.100 raeburn 19412: }
19413: }
19414: } else {
19415: if (@{$cancreate{$type}} == 0) {
19416: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
19417: } else {
19418: $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 19419: }
19420: }
1.303 raeburn 19421: $chgtext .= '<br />';
1.93 raeburn 19422: }
1.236 raeburn 19423: } elsif ($type eq 'selfcreateprocessing') {
19424: my %choices = &Apache::lonlocal::texthash (
19425: automatic => 'Automatic approval',
19426: approval => 'Queued for approval',
19427: );
1.305 raeburn 19428: if (@types) {
19429: if (@statuses) {
1.425 raeburn 19430: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 19431: '<ul>';
1.305 raeburn 19432: foreach my $status (@statuses) {
19433: if ($status eq 'default') {
19434: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19435: } else {
1.305 raeburn 19436: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19437: }
19438: }
19439: $chgtext .= '</ul>';
19440: }
19441: } else {
19442: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
19443: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
19444: }
19445: } elsif ($type eq 'emailverified') {
19446: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 19447: all => 'Same as e-mail',
19448: first => 'Omit @domain',
19449: free => 'Free to choose',
1.303 raeburn 19450: );
1.305 raeburn 19451: if (@types) {
19452: if (@statuses) {
1.303 raeburn 19453: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
19454: '<ul>';
1.305 raeburn 19455: foreach my $status (@statuses) {
1.362 raeburn 19456: if ($status eq 'default') {
1.305 raeburn 19457: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19458: } else {
1.305 raeburn 19459: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19460: }
19461: }
19462: $chgtext .= '</ul>';
19463: }
19464: } else {
1.305 raeburn 19465: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 19466: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 19467: }
1.305 raeburn 19468: } elsif ($type eq 'emailoptions') {
19469: my %options = &Apache::lonlocal::texthash (
19470: any => 'Any e-mail',
19471: inst => 'Institutional only',
19472: noninst => 'Non-institutional only',
19473: custom => 'Custom restrictions',
19474: );
19475: if (@types) {
19476: if (@statuses) {
19477: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
19478: '<ul>';
19479: foreach my $status (@statuses) {
19480: if ($type eq 'default') {
19481: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
19482: } else {
19483: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 19484: }
19485: }
1.305 raeburn 19486: $chgtext .= '</ul>';
19487: }
19488: } else {
19489: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
19490: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
19491: } else {
19492: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
19493: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 19494: }
1.305 raeburn 19495: }
19496: } elsif ($type eq 'emaildomain') {
19497: my $output;
19498: if (@statuses) {
19499: foreach my $type (@statuses) {
19500: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
19501: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
19502: if ($type eq 'default') {
19503: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19504: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19505: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19506: } else {
19507: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
19508: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
19509: }
1.303 raeburn 19510: } else {
1.305 raeburn 19511: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19512: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19513: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19514: } else {
19515: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
1.421 raeburn 19516: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
1.305 raeburn 19517: }
1.303 raeburn 19518: }
1.305 raeburn 19519: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
19520: if ($type eq 'default') {
19521: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19522: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19523: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19524: } else {
19525: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
19526: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
19527: }
1.303 raeburn 19528: } else {
1.305 raeburn 19529: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19530: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19531: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19532: } else {
19533: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
1.421 raeburn 19534: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
1.305 raeburn 19535: }
1.303 raeburn 19536: }
19537: }
19538: }
19539: }
1.305 raeburn 19540: }
19541: if ($output ne '') {
19542: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
19543: '<ul>'.$output.'</ul>';
1.236 raeburn 19544: }
1.165 raeburn 19545: } elsif ($type eq 'captcha') {
1.224 raeburn 19546: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 19547: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
19548: } else {
19549: my %captchas = &captcha_phrases();
1.224 raeburn 19550: if ($captchas{$savecaptcha{$type}}) {
19551: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 19552: } else {
1.210 raeburn 19553: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 19554: }
19555: }
19556: } elsif ($type eq 'recaptchakeys') {
19557: my ($privkey,$pubkey);
1.224 raeburn 19558: if (ref($savecaptcha{$type}) eq 'HASH') {
19559: $pubkey = $savecaptcha{$type}{'public'};
19560: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 19561: }
19562: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
19563: if (!$pubkey) {
19564: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
19565: } else {
19566: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
19567: }
19568: if (!$privkey) {
19569: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
19570: } else {
19571: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
19572: }
19573: $chgtext .= '</ul>';
1.269 raeburn 19574: } elsif ($type eq 'recaptchaversion') {
19575: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 19576: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 19577: }
1.224 raeburn 19578: } elsif ($type eq 'emailusername') {
19579: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 19580: if (@statuses) {
19581: foreach my $type (@statuses) {
1.228 raeburn 19582: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
19583: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 19584: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 19585: '<ul>';
19586: foreach my $field (@{$infofields}) {
19587: if ($cancreate{'emailusername'}{$type}{$field}) {
19588: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
19589: }
19590: }
1.245 raeburn 19591: $chgtext .= '</ul>';
19592: } else {
1.303 raeburn 19593: $chgtext .= &mt('When self creating account with e-mail verification, no information besides e-mail address will be provided by [_1].',"'$usertypes{$type}'").'<br />';
1.228 raeburn 19594: }
19595: } else {
1.303 raeburn 19596: $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 19597: }
19598: }
19599: }
19600: }
19601: } elsif ($type eq 'notify') {
1.303 raeburn 19602: my $numapprove = 0;
1.224 raeburn 19603: if (ref($changes{'cancreate'}) eq 'ARRAY') {
19604: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
19605: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 19606: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
19607: $numapprove ++;
1.224 raeburn 19608: }
19609: }
1.43 raeburn 19610: }
1.303 raeburn 19611: unless ($numapprove) {
19612: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
19613: }
1.34 raeburn 19614: }
1.224 raeburn 19615: if ($chgtext) {
19616: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 19617: }
19618: }
19619: }
1.305 raeburn 19620: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 19621: my ($emailrules,$emailruleorder) =
19622: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 19623: foreach my $type (@{$changes{'email_rule'}}) {
19624: if (ref($email_rule{$type}) eq 'ARRAY') {
19625: my $chgtext = '<ul>';
19626: foreach my $rule (@{$email_rule{$type}}) {
19627: if (ref($emailrules->{$rule}) eq 'HASH') {
19628: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
19629: }
19630: }
19631: $chgtext .= '</ul>';
1.310 raeburn 19632: my $typename;
1.305 raeburn 19633: if (@types) {
19634: if ($type eq 'default') {
19635: $typename = $othertitle;
19636: } else {
19637: $typename = $usertypes{$type};
1.425 raeburn 19638: }
1.305 raeburn 19639: $chgtext .= &mt('(Affiliation: [_1])',$typename);
19640: }
19641: if (@{$email_rule{$type}} > 0) {
19642: $resulttext .= '<li>'.
19643: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
19644: $usertypes{$type}).
19645: $chgtext.
19646: '</li>';
19647: } else {
19648: $resulttext .= '<li>'.
1.310 raeburn 19649: &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 19650: '</li>'.
1.310 raeburn 19651: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 19652: }
1.43 raeburn 19653: }
19654: }
1.305 raeburn 19655: }
19656: if (ref($changes{'inststatus'}) eq 'ARRAY') {
19657: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
19658: if (@{$save_inststatus{'inststatusguest'}} > 0) {
19659: my $chgtext = '<ul>';
19660: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
19661: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
19662: }
19663: $chgtext .= '</ul>';
19664: $resulttext .= '<li>'.
19665: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
19666: $chgtext.
19667: '</li>';
19668: } else {
19669: $resulttext .= '<li>'.
19670: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
19671: '</li>';
19672: }
1.43 raeburn 19673: }
19674: }
1.224 raeburn 19675: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
19676: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
19677: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19678: foreach my $type (@{$changes{'selfcreate'}}) {
19679: my $typename = $type;
1.303 raeburn 19680: if (keys(%usertypes) > 0) {
19681: if ($usertypes{$type} ne '') {
19682: $typename = $usertypes{$type};
1.224 raeburn 19683: }
19684: }
19685: my @modifiable;
19686: $resulttext .= '<li>'.
19687: &mt('Self-creation of account by users with status: [_1]',
19688: '<span class="LC_cusr_emph">'.$typename.'</span>').
19689: ' - '.&mt('modifiable fields (if institutional data blank): ');
19690: foreach my $field (@fields) {
19691: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
19692: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 19693: }
19694: }
1.224 raeburn 19695: if (@modifiable > 0) {
19696: $resulttext .= join(', ',@modifiable);
1.43 raeburn 19697: } else {
1.224 raeburn 19698: $resulttext .= &mt('none');
1.43 raeburn 19699: }
1.224 raeburn 19700: $resulttext .= '</li>';
1.28 raeburn 19701: }
1.224 raeburn 19702: $resulttext .= '</ul></li>';
1.28 raeburn 19703: }
1.27 raeburn 19704: $resulttext .= '</ul>';
1.305 raeburn 19705: my $cachetime = 24*60*60;
19706: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
19707: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19708: if (ref($lastactref) eq 'HASH') {
19709: $lastactref->{'domdefaults'} = 1;
19710: }
1.27 raeburn 19711: } else {
1.224 raeburn 19712: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 19713: }
19714: } else {
19715: $resulttext = '<span class="LC_error">'.
1.23 raeburn 19716: &mt('An error occurred: [_1]',$putresult).'</span>';
19717: }
1.43 raeburn 19718: if ($warningmsg ne '') {
19719: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
19720: }
1.23 raeburn 19721: return $resulttext;
19722: }
19723:
1.165 raeburn 19724: sub process_captcha {
1.369 raeburn 19725: my ($container,$changes,$newsettings,$currsettings) = @_;
19726: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165 raeburn 19727: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
19728: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
19729: $newsettings->{'captcha'} = 'original';
19730: }
1.369 raeburn 19731: my %current;
19732: if (ref($currsettings) eq 'HASH') {
19733: %current = %{$currsettings};
19734: }
19735: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 19736: if ($container eq 'cancreate') {
1.169 raeburn 19737: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19738: push(@{$changes->{'cancreate'}},'captcha');
19739: } elsif (!defined($changes->{'cancreate'})) {
19740: $changes->{'cancreate'} = ['captcha'];
19741: }
1.368 raeburn 19742: } elsif ($container eq 'passwords') {
19743: $changes->{'reset'} = 1;
1.169 raeburn 19744: } else {
19745: $changes->{'captcha'} = 1;
1.165 raeburn 19746: }
19747: }
1.269 raeburn 19748: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 19749: if ($newsettings->{'captcha'} eq 'recaptcha') {
19750: $newpub = $env{'form.'.$container.'_recaptchapub'};
19751: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 19752: $newpub =~ s/[^\w\-]//g;
19753: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 19754: $newsettings->{'recaptchakeys'} = {
19755: public => $newpub,
19756: private => $newpriv,
19757: };
1.269 raeburn 19758: $newversion = $env{'form.'.$container.'_recaptchaversion'};
19759: $newversion =~ s/\D//g;
19760: if ($newversion ne '2') {
19761: $newversion = 1;
19762: }
19763: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 19764: }
1.369 raeburn 19765: if (ref($current{'recaptchakeys'}) eq 'HASH') {
19766: $currpub = $current{'recaptchakeys'}{'public'};
19767: $currpriv = $current{'recaptchakeys'}{'private'};
1.179 raeburn 19768: unless ($newsettings->{'captcha'} eq 'recaptcha') {
19769: $newsettings->{'recaptchakeys'} = {
19770: public => '',
19771: private => '',
19772: }
19773: }
1.165 raeburn 19774: }
1.369 raeburn 19775: if ($current{'captcha'} eq 'recaptcha') {
19776: $currversion = $current{'recaptchaversion'};
1.269 raeburn 19777: if ($currversion ne '2') {
19778: $currversion = 1;
19779: }
19780: }
19781: if ($currversion ne $newversion) {
19782: if ($container eq 'cancreate') {
19783: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19784: push(@{$changes->{'cancreate'}},'recaptchaversion');
19785: } elsif (!defined($changes->{'cancreate'})) {
19786: $changes->{'cancreate'} = ['recaptchaversion'];
19787: }
1.368 raeburn 19788: } elsif ($container eq 'passwords') {
19789: $changes->{'reset'} = 1;
1.269 raeburn 19790: } else {
19791: $changes->{'recaptchaversion'} = 1;
19792: }
19793: }
1.165 raeburn 19794: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 19795: if ($container eq 'cancreate') {
19796: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19797: push(@{$changes->{'cancreate'}},'recaptchakeys');
19798: } elsif (!defined($changes->{'cancreate'})) {
19799: $changes->{'cancreate'} = ['recaptchakeys'];
19800: }
1.368 raeburn 19801: } elsif ($container eq 'passwords') {
19802: $changes->{'reset'} = 1;
1.169 raeburn 19803: } else {
1.210 raeburn 19804: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 19805: }
19806: }
19807: return;
19808: }
19809:
1.33 raeburn 19810: sub modify_usermodification {
19811: my ($dom,%domconfig) = @_;
1.224 raeburn 19812: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 19813: if (ref($domconfig{'usermodification'}) eq 'HASH') {
19814: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 19815: if ($key eq 'selfcreate') {
19816: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
19817: } else {
19818: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
19819: }
1.33 raeburn 19820: }
19821: }
1.224 raeburn 19822: my @contexts = ('author','course');
1.33 raeburn 19823: my %context_title = (
19824: author => 'In author context',
19825: course => 'In course context',
19826: );
19827: my @fields = ('lastname','firstname','middlename','generation',
19828: 'permanentemail','id');
19829: my %roles = (
19830: author => ['ca','aa'],
19831: course => ['st','ep','ta','in','cr'],
19832: );
19833: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19834: foreach my $context (@contexts) {
19835: foreach my $role (@{$roles{$context}}) {
19836: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
19837: foreach my $item (@fields) {
19838: if (grep(/^\Q$item\E$/,@modifiable)) {
19839: $modifyhash{$context}{$role}{$item} = 1;
19840: } else {
19841: $modifyhash{$context}{$role}{$item} = 0;
19842: }
19843: }
19844: }
19845: if (ref($curr_usermodification{$context}) eq 'HASH') {
19846: foreach my $role (@{$roles{$context}}) {
19847: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
19848: foreach my $field (@fields) {
19849: if ($modifyhash{$context}{$role}{$field} ne
19850: $curr_usermodification{$context}{$role}{$field}) {
19851: push(@{$changes{$context}},$role);
19852: last;
19853: }
19854: }
19855: }
19856: }
19857: } else {
19858: foreach my $context (@contexts) {
19859: foreach my $role (@{$roles{$context}}) {
19860: push(@{$changes{$context}},$role);
19861: }
19862: }
19863: }
19864: }
19865: my %usermodification_hash = (
19866: usermodification => \%modifyhash,
19867: );
19868: my $putresult = &Apache::lonnet::put_dom('configuration',
19869: \%usermodification_hash,$dom);
19870: if ($putresult eq 'ok') {
19871: if (keys(%changes) > 0) {
19872: $resulttext = &mt('Changes made: ').'<ul>';
19873: foreach my $context (@contexts) {
19874: if (ref($changes{$context}) eq 'ARRAY') {
19875: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
19876: if (ref($changes{$context}) eq 'ARRAY') {
19877: foreach my $role (@{$changes{$context}}) {
19878: my $rolename;
1.224 raeburn 19879: if ($role eq 'cr') {
19880: $rolename = &mt('Custom');
1.33 raeburn 19881: } else {
1.224 raeburn 19882: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 19883: }
19884: my @modifiable;
1.224 raeburn 19885: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 19886: foreach my $field (@fields) {
19887: if ($modifyhash{$context}{$role}{$field}) {
19888: push(@modifiable,$fieldtitles{$field});
19889: }
19890: }
19891: if (@modifiable > 0) {
19892: $resulttext .= join(', ',@modifiable);
19893: } else {
19894: $resulttext .= &mt('none');
19895: }
19896: $resulttext .= '</li>';
19897: }
19898: $resulttext .= '</ul></li>';
19899: }
19900: }
19901: }
19902: $resulttext .= '</ul>';
19903: } else {
19904: $resulttext = &mt('No changes made to user modification settings');
19905: }
19906: } else {
19907: $resulttext = '<span class="LC_error">'.
19908: &mt('An error occurred: [_1]',$putresult).'</span>';
19909: }
19910: return $resulttext;
19911: }
19912:
1.43 raeburn 19913: sub modify_defaults {
1.212 raeburn 19914: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 19915: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 19916: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 19917: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 19918: 'portal_def');
1.325 raeburn 19919: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 19920: foreach my $item (@items) {
19921: $newvalues{$item} = $env{'form.'.$item};
19922: if ($item eq 'auth_def') {
19923: if ($newvalues{$item} ne '') {
19924: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
19925: push(@errors,$item);
19926: }
19927: }
19928: } elsif ($item eq 'lang_def') {
19929: if ($newvalues{$item} ne '') {
19930: if ($newvalues{$item} =~ /^(\w+)/) {
19931: my $langcode = $1;
1.103 raeburn 19932: if ($langcode ne 'x_chef') {
19933: if (code2language($langcode) eq '') {
19934: push(@errors,$item);
19935: }
1.43 raeburn 19936: }
19937: } else {
19938: push(@errors,$item);
19939: }
19940: }
1.54 raeburn 19941: } elsif ($item eq 'timezone_def') {
19942: if ($newvalues{$item} ne '') {
1.62 raeburn 19943: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 19944: push(@errors,$item);
19945: }
19946: }
1.68 raeburn 19947: } elsif ($item eq 'datelocale_def') {
19948: if ($newvalues{$item} ne '') {
19949: my @datelocale_ids = DateTime::Locale->ids();
19950: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
19951: push(@errors,$item);
19952: }
19953: }
1.141 raeburn 19954: } elsif ($item eq 'portal_def') {
19955: if ($newvalues{$item} ne '') {
1.414 raeburn 19956: 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])\/?$/) {
19957: foreach my $field ('email','web') {
19958: if ($env{'form.'.$item.'_'.$field}) {
19959: $newvalues{$item.'_'.$field} = $env{'form.'.$item.'_'.$field};
19960: }
19961: }
19962: } else {
1.141 raeburn 19963: push(@errors,$item);
19964: }
19965: }
1.43 raeburn 19966: }
19967: if (grep(/^\Q$item\E$/,@errors)) {
19968: $newvalues{$item} = $domdefaults{$item};
1.414 raeburn 19969: if ($item eq 'portal_def') {
19970: if ($domdefaults{$item}) {
19971: foreach my $field ('email','web') {
19972: if (exists($domdefaults{$item.'_'.$field})) {
19973: $newvalues{$item.'_'.$field} = $domdefaults{$item.'_'.$field};
19974: }
19975: }
19976: }
19977: }
1.43 raeburn 19978: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
19979: $changes{$item} = 1;
19980: }
1.414 raeburn 19981: if ($item eq 'portal_def') {
19982: unless (grep(/^\Q$item\E$/,@errors)) {
1.425 raeburn 19983: if ($newvalues{$item} eq '') {
1.414 raeburn 19984: foreach my $field ('email','web') {
19985: if (exists($domdefaults{$item.'_'.$field})) {
19986: delete($domdefaults{$item.'_'.$field});
19987: }
19988: }
19989: } else {
19990: unless ($changes{$item}) {
19991: foreach my $field ('email','web') {
19992: if ($domdefaults{$item.'_'.$field} ne $newvalues{$item.'_'.$field}) {
19993: $changes{$item} = 1;
19994: last;
19995: }
19996: }
19997: }
19998: foreach my $field ('email','web') {
19999: if ($newvalues{$item.'_'.$field}) {
20000: $domdefaults{$item.'_'.$field} = $newvalues{$item.'_'.$field};
20001: } elsif (exists($domdefaults{$item.'_'.$field})) {
20002: delete($domdefaults{$item.'_'.$field});
20003: }
20004: }
20005: }
20006: }
20007: }
1.72 raeburn 20008: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 20009: }
1.354 raeburn 20010: my %staticdefaults = (
20011: 'intauth_cost' => 10,
20012: 'intauth_check' => 0,
20013: 'intauth_switch' => 0,
20014: );
20015: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
20016: if (exists($domdefaults{$item})) {
20017: $newvalues{$item} = $domdefaults{$item};
20018: } else {
20019: $newvalues{$item} = $staticdefaults{$item};
20020: }
20021: }
1.409 raeburn 20022: my ($unamemaprules,$ruleorder);
20023: my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
20024: if (@possunamemaprules) {
20025: ($unamemaprules,$ruleorder) =
20026: &Apache::lonnet::inst_userrules($dom,'unamemap');
20027: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
20028: if (@{$ruleorder} > 0) {
20029: my %possrules;
20030: map { $possrules{$_} = 1; } @possunamemaprules;
20031: foreach my $rule (@{$ruleorder}) {
20032: if ($possrules{$rule}) {
20033: push(@{$newvalues{'unamemap_rule'}},$rule);
20034: }
20035: }
20036: }
20037: }
20038: }
20039: if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
20040: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20041: my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
20042: $newvalues{'unamemap_rule'});
20043: if (@rulediffs) {
20044: $changes{'unamemap_rule'} = 1;
20045: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
20046: }
20047: } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
20048: $changes{'unamemap_rule'} = 1;
20049: delete($domdefaults{'unamemap_rule'});
20050: }
20051: } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20052: if (@{$newvalues{'unamemap_rule'}} > 0) {
20053: $changes{'unamemap_rule'} = 1;
20054: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
20055: }
20056: }
1.43 raeburn 20057: my %defaults_hash = (
1.72 raeburn 20058: defaults => \%newvalues,
20059: );
1.43 raeburn 20060: my $title = &defaults_titles();
1.236 raeburn 20061:
20062: my $currinststatus;
20063: if (ref($domconfig{'inststatus'}) eq 'HASH') {
20064: $currinststatus = $domconfig{'inststatus'};
20065: } else {
20066: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
20067: $currinststatus = {
20068: inststatustypes => $usertypes,
20069: inststatusorder => $types,
20070: inststatusguest => [],
20071: };
20072: }
20073: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
20074: my @allpos;
20075: my %alltypes;
1.305 raeburn 20076: my @inststatusguest;
20077: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
20078: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
20079: unless (grep(/^\Q$type\E$/,@todelete)) {
20080: push(@inststatusguest,$type);
20081: }
20082: }
20083: }
20084: my ($currtitles,$currorder);
1.236 raeburn 20085: if (ref($currinststatus) eq 'HASH') {
20086: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
20087: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
20088: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
20089: if ($currinststatus->{inststatustypes}->{$type} ne '') {
20090: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
20091: }
20092: }
20093: unless (grep(/^\Q$type\E$/,@todelete)) {
20094: my $position = $env{'form.inststatus_pos_'.$type};
20095: $position =~ s/\D+//g;
20096: $allpos[$position] = $type;
20097: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
20098: $alltypes{$type} =~ s/`//g;
20099: }
20100: }
20101: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
20102: $currtitles =~ s/,$//;
20103: }
20104: }
20105: if ($env{'form.addinststatus'}) {
20106: my $newtype = $env{'form.addinststatus'};
20107: $newtype =~ s/\W//g;
20108: unless (exists($alltypes{$newtype})) {
20109: $alltypes{$newtype} = $env{'form.addinststatus_title'};
20110: $alltypes{$newtype} =~ s/`//g;
20111: my $position = $env{'form.addinststatus_pos'};
20112: $position =~ s/\D+//g;
20113: if ($position ne '') {
20114: $allpos[$position] = $newtype;
20115: }
20116: }
20117: }
1.305 raeburn 20118: my @orderedstatus;
1.236 raeburn 20119: foreach my $type (@allpos) {
20120: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
20121: push(@orderedstatus,$type);
20122: }
20123: }
20124: foreach my $type (keys(%alltypes)) {
20125: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
20126: delete($alltypes{$type});
20127: }
20128: }
20129: $defaults_hash{'inststatus'} = {
20130: inststatustypes => \%alltypes,
20131: inststatusorder => \@orderedstatus,
1.305 raeburn 20132: inststatusguest => \@inststatusguest,
1.236 raeburn 20133: };
20134: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
20135: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
20136: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
20137: }
20138: }
20139: if ($currorder ne join(',',@orderedstatus)) {
20140: $changes{'inststatus'}{'inststatusorder'} = 1;
20141: }
20142: my $newtitles;
20143: foreach my $item (@orderedstatus) {
20144: $newtitles .= $alltypes{$item}.',';
20145: }
20146: $newtitles =~ s/,$//;
20147: if ($currtitles ne $newtitles) {
20148: $changes{'inststatus'}{'inststatustypes'} = 1;
20149: }
1.43 raeburn 20150: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
20151: $dom);
20152: if ($putresult eq 'ok') {
20153: if (keys(%changes) > 0) {
20154: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 20155: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 20156: 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";
20157: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 20158: if ($item eq 'inststatus') {
20159: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 20160: if (@orderedstatus) {
1.236 raeburn 20161: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
20162: foreach my $type (@orderedstatus) {
20163: $resulttext .= $alltypes{$type}.', ';
20164: }
20165: $resulttext =~ s/, $//;
20166: $resulttext .= '</li>';
1.305 raeburn 20167: } else {
1.425 raeburn 20168: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 20169: }
20170: }
1.409 raeburn 20171: } elsif ($item eq 'unamemap_rule') {
20172: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20173: my @rulenames;
20174: if (ref($unamemaprules) eq 'HASH') {
20175: foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
20176: if (ref($unamemaprules->{$rule}) eq 'HASH') {
20177: push(@rulenames,$unamemaprules->{$rule}->{'name'});
20178: }
20179: }
20180: }
20181: if (@rulenames) {
20182: $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
20183: '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
20184: '</li>';
20185: } else {
20186: $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
20187: }
20188: } else {
20189: $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
20190: }
1.236 raeburn 20191: } else {
20192: my $value = $env{'form.'.$item};
20193: if ($value eq '') {
20194: $value = &mt('none');
20195: } elsif ($item eq 'auth_def') {
20196: my %authnames = &authtype_names();
20197: my %shortauth = (
20198: internal => 'int',
20199: krb4 => 'krb4',
20200: krb5 => 'krb5',
20201: localauth => 'loc',
1.325 raeburn 20202: lti => 'lti',
1.236 raeburn 20203: );
20204: $value = $authnames{$shortauth{$value}};
20205: }
20206: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
1.414 raeburn 20207: $mailmsgtext .= "$title->{$item} set to $value\n";
20208: if ($item eq 'portal_def') {
20209: if ($env{'form.'.$item} ne '') {
20210: foreach my $field ('email','web') {
20211: $value = $env{'form.'.$item.'_'.$field};
20212: if ($value) {
20213: $value = &mt('Yes');
20214: } else {
20215: $value = &mt('No');
20216: }
20217: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$field},$value).'</li>';
20218: }
20219: }
20220: }
1.43 raeburn 20221: }
20222: }
20223: $resulttext .= '</ul>';
20224: $mailmsgtext .= "\n";
20225: my $cachetime = 24*60*60;
1.72 raeburn 20226: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 20227: if (ref($lastactref) eq 'HASH') {
20228: $lastactref->{'domdefaults'} = 1;
20229: }
1.68 raeburn 20230: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 20231: my $notify = 1;
20232: if (ref($domconfig{'contacts'}) eq 'HASH') {
20233: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
20234: $notify = 0;
20235: }
20236: }
20237: if ($notify) {
20238: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
20239: "LON-CAPA Domain Settings Change - $dom",
20240: $mailmsgtext);
20241: }
1.54 raeburn 20242: }
1.43 raeburn 20243: } else {
1.54 raeburn 20244: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 20245: }
20246: } else {
20247: $resulttext = '<span class="LC_error">'.
20248: &mt('An error occurred: [_1]',$putresult).'</span>';
20249: }
20250: if (@errors > 0) {
20251: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
20252: foreach my $item (@errors) {
20253: $resulttext .= ' "'.$title->{$item}.'",';
20254: }
20255: $resulttext =~ s/,$//;
20256: }
20257: return $resulttext;
20258: }
20259:
1.46 raeburn 20260: sub modify_scantron {
1.205 raeburn 20261: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 20262: my ($resulttext,%confhash,%changes,$errors);
20263: my $custom = 'custom.tab';
20264: my $default = 'default.tab';
20265: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 20266: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 20267: &config_check($dom,$confname,$servadm);
20268: if ($env{'form.scantronformat.filename'} ne '') {
20269: my $error;
20270: if ($configuserok eq 'ok') {
20271: if ($switchserver) {
1.130 raeburn 20272: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 20273: } else {
20274: if ($author_ok eq 'ok') {
1.421 raeburn 20275: my $modified = [];
1.46 raeburn 20276: my ($result,$scantronurl) =
1.421 raeburn 20277: &Apache::lonconfigsettings::publishlogo($r,'upload','scantronformat',$dom,
20278: $confname,'scantron','','',$custom,
20279: $modified);
1.46 raeburn 20280: if ($result eq 'ok') {
20281: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 20282: $changes{'scantronformat'} = 1;
1.421 raeburn 20283: &update_modify_urls($r,$modified);
1.46 raeburn 20284: } else {
20285: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
20286: }
20287: } else {
20288: $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);
20289: }
20290: }
20291: } else {
20292: $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);
20293: }
20294: if ($error) {
20295: &Apache::lonnet::logthis($error);
20296: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
20297: }
20298: }
1.48 raeburn 20299: if (ref($domconfig{'scantron'}) eq 'HASH') {
20300: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
20301: if ($env{'form.scantronformat_del'}) {
20302: $confhash{'scantron'}{'scantronformat'} = '';
20303: $changes{'scantronformat'} = 1;
1.347 raeburn 20304: } else {
20305: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 20306: }
20307: }
20308: }
1.347 raeburn 20309: my @options = ('hdr','pad','rem');
1.346 raeburn 20310: my @fields = &scantroncsv_fields();
20311: my %titles = &scantronconfig_titles();
1.347 raeburn 20312: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 20313: my ($newdat,$currdat,%newcol,%currcol);
20314: if (grep(/^dat$/,@formats)) {
20315: $confhash{'scantron'}{config}{dat} = 1;
20316: $newdat = 1;
20317: } else {
20318: $newdat = 0;
20319: }
20320: if (grep(/^csv$/,@formats)) {
20321: my %bynum;
20322: foreach my $field (@fields) {
20323: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
20324: my $posscol = $1;
20325: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 20326: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 20327: $bynum{$posscol} = $field;
20328: $newcol{$field} = $posscol;
20329: }
20330: }
20331: }
1.347 raeburn 20332: if (keys(%newcol)) {
20333: foreach my $option (@options) {
20334: if ($env{'form.scantroncsv_'.$option}) {
20335: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
20336: }
20337: }
20338: }
1.346 raeburn 20339: }
20340: $currdat = 1;
20341: if (ref($domconfig{'scantron'}) eq 'HASH') {
20342: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 20343: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 20344: $currdat = 0;
20345: }
20346: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20347: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20348: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
20349: }
1.346 raeburn 20350: }
20351: }
20352: }
20353: if ($currdat != $newdat) {
20354: $changes{'config'} = 1;
20355: } else {
20356: foreach my $field (@fields) {
20357: if ($currcol{$field} ne '') {
20358: if ($currcol{$field} ne $newcol{$field}) {
20359: $changes{'config'} = 1;
20360: last;
1.347 raeburn 20361: }
1.346 raeburn 20362: } elsif ($newcol{$field} ne '') {
20363: $changes{'config'} = 1;
20364: last;
20365: }
20366: }
20367: }
1.46 raeburn 20368: if (keys(%confhash) > 0) {
20369: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
20370: $dom);
20371: if ($putresult eq 'ok') {
20372: if (keys(%changes) > 0) {
1.48 raeburn 20373: if (ref($confhash{'scantron'}) eq 'HASH') {
20374: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 20375: if ($changes{'scantronformat'}) {
20376: if ($confhash{'scantron'}{'scantronformat'} eq '') {
20377: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
20378: } else {
20379: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
20380: }
20381: }
1.347 raeburn 20382: if ($changes{'config'}) {
1.346 raeburn 20383: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
20384: if ($confhash{'scantron'}{'config'}{'dat'}) {
20385: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
20386: }
20387: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20388: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20389: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
20390: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
20391: foreach my $field (@fields) {
20392: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
20393: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
20394: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
20395: }
20396: }
20397: $resulttext .= '</ul></li>';
20398: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
20399: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
20400: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
20401: foreach my $option (@options) {
20402: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
20403: $resulttext .= '<li>'.$titles{$option}.'</li>';
20404: }
20405: }
20406: $resulttext .= '</ul></li>';
20407: }
1.346 raeburn 20408: }
20409: }
20410: }
20411: }
20412: } else {
20413: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
20414: }
1.46 raeburn 20415: }
1.48 raeburn 20416: $resulttext .= '</ul>';
20417: } else {
1.130 raeburn 20418: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 20419: }
20420: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 20421: if (ref($lastactref) eq 'HASH') {
20422: $lastactref->{'domainconfig'} = 1;
20423: }
1.46 raeburn 20424: } else {
1.346 raeburn 20425: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 20426: }
20427: } else {
20428: $resulttext = '<span class="LC_error">'.
20429: &mt('An error occurred: [_1]',$putresult).'</span>';
20430: }
20431: } else {
1.130 raeburn 20432: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 20433: }
20434: if ($errors) {
1.353 raeburn 20435: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
20436: $errors.'</ul></p>';
1.46 raeburn 20437: }
20438: return $resulttext;
20439: }
20440:
1.48 raeburn 20441: sub modify_coursecategories {
1.239 raeburn 20442: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 20443: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
20444: $cathash);
1.48 raeburn 20445: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 20446: my @catitems = ('unauth','auth');
20447: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 20448: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 20449: $cathash = $domconfig{'coursecategories'}{'cats'};
20450: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
20451: $changes{'togglecats'} = 1;
20452: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
20453: }
20454: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
20455: $changes{'categorize'} = 1;
20456: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
20457: }
1.120 raeburn 20458: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
20459: $changes{'togglecatscomm'} = 1;
20460: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
20461: }
20462: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
20463: $changes{'categorizecomm'} = 1;
20464: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 20465:
20466: }
20467: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
20468: $changes{'togglecatsplace'} = 1;
20469: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
20470: }
20471: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
20472: $changes{'categorizeplace'} = 1;
20473: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 20474: }
1.238 raeburn 20475: foreach my $item (@catitems) {
20476: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20477: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
20478: $changes{$item} = 1;
20479: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20480: }
20481: }
20482: }
1.57 raeburn 20483: } else {
20484: $changes{'togglecats'} = 1;
20485: $changes{'categorize'} = 1;
1.124 raeburn 20486: $changes{'togglecatscomm'} = 1;
20487: $changes{'categorizecomm'} = 1;
1.272 raeburn 20488: $changes{'togglecatsplace'} = 1;
20489: $changes{'categorizeplace'} = 1;
1.87 raeburn 20490: $domconfig{'coursecategories'} = {
20491: togglecats => $env{'form.togglecats'},
20492: categorize => $env{'form.categorize'},
1.124 raeburn 20493: togglecatscomm => $env{'form.togglecatscomm'},
20494: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 20495: togglecatsplace => $env{'form.togglecatsplace'},
20496: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 20497: };
1.238 raeburn 20498: foreach my $item (@catitems) {
20499: if ($env{'form.coursecat_'.$item} ne 'std') {
20500: $changes{$item} = 1;
20501: }
20502: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20503: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20504: }
20505: }
1.57 raeburn 20506: }
20507: if (ref($cathash) eq 'HASH') {
20508: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 20509: push (@deletecategory,'instcode::0');
20510: }
1.120 raeburn 20511: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
20512: push(@deletecategory,'communities::0');
20513: }
1.272 raeburn 20514: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
20515: push(@deletecategory,'placement::0');
20516: }
1.48 raeburn 20517: }
1.57 raeburn 20518: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
20519: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20520: if (@deletecategory > 0) {
20521: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 20522: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 20523: foreach my $item (@deletecategory) {
1.57 raeburn 20524: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
20525: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 20526: $deletions{$item} = 1;
1.57 raeburn 20527: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 20528: }
20529: }
20530: }
1.57 raeburn 20531: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 20532: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 20533: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 20534: $reorderings{$item} = 1;
1.57 raeburn 20535: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 20536: }
20537: if ($env{'form.addcategory_name_'.$item} ne '') {
20538: my $newcat = $env{'form.addcategory_name_'.$item};
20539: my $newdepth = $depth+1;
20540: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20541: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 20542: $adds{$newitem} = 1;
20543: }
20544: if ($env{'form.subcat_'.$item} ne '') {
20545: my $newcat = $env{'form.subcat_'.$item};
20546: my $newdepth = $depth+1;
20547: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20548: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 20549: $adds{$newitem} = 1;
20550: }
20551: }
20552: }
20553: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 20554: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20555: my $newitem = 'instcode::0';
1.57 raeburn 20556: if ($cathash->{$newitem} eq '') {
20557: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20558: $adds{$newitem} = 1;
20559: }
20560: } else {
20561: my $newitem = 'instcode::0';
1.57 raeburn 20562: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20563: $adds{$newitem} = 1;
20564: }
20565: }
1.120 raeburn 20566: if ($env{'form.communities'} eq '1') {
20567: if (ref($cathash) eq 'HASH') {
20568: my $newitem = 'communities::0';
20569: if ($cathash->{$newitem} eq '') {
20570: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20571: $adds{$newitem} = 1;
20572: }
20573: } else {
20574: my $newitem = 'communities::0';
20575: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20576: $adds{$newitem} = 1;
20577: }
20578: }
1.272 raeburn 20579: if ($env{'form.placement'} eq '1') {
20580: if (ref($cathash) eq 'HASH') {
20581: my $newitem = 'placement::0';
20582: if ($cathash->{$newitem} eq '') {
20583: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20584: $adds{$newitem} = 1;
20585: }
20586: } else {
20587: my $newitem = 'placement::0';
20588: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20589: $adds{$newitem} = 1;
20590: }
20591: }
1.48 raeburn 20592: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 20593: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 20594: ($env{'form.addcategory_name'} ne 'communities') &&
20595: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 20596: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
20597: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
20598: $adds{$newitem} = 1;
20599: }
1.48 raeburn 20600: }
1.57 raeburn 20601: my $putresult;
1.48 raeburn 20602: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20603: if (keys(%deletions) > 0) {
20604: foreach my $key (keys(%deletions)) {
20605: if ($predelallitems{$key} ne '') {
20606: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
20607: }
20608: }
20609: }
20610: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 20611: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 20612: if (ref($chkcats[0]) eq 'ARRAY') {
20613: my $depth = 0;
20614: my $chg = 0;
20615: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
20616: my $name = $chkcats[0][$i];
20617: my $item;
20618: if ($name eq '') {
20619: $chg ++;
20620: } else {
20621: $item = &escape($name).'::0';
20622: if ($chg) {
1.57 raeburn 20623: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 20624: }
20625: $depth ++;
1.57 raeburn 20626: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 20627: $depth --;
20628: }
20629: }
20630: }
1.57 raeburn 20631: }
20632: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20633: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 20634: if ($putresult eq 'ok') {
1.57 raeburn 20635: my %title = (
1.120 raeburn 20636: togglecats => 'Show/Hide a course in catalog',
20637: categorize => 'Assign a category to a course',
20638: togglecatscomm => 'Show/Hide a community in catalog',
20639: categorizecomm => 'Assign a category to a community',
1.57 raeburn 20640: );
20641: my %level = (
1.120 raeburn 20642: dom => 'set in Domain ("Modify Course/Community")',
20643: crs => 'set in Course ("Course Configuration")',
20644: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 20645: none => 'No catalog',
20646: std => 'Standard catalog',
20647: domonly => 'Domain-only catalog',
20648: codesrch => 'Code search form',
1.57 raeburn 20649: );
1.48 raeburn 20650: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 20651: if ($changes{'togglecats'}) {
20652: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
20653: }
20654: if ($changes{'categorize'}) {
20655: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 20656: }
1.120 raeburn 20657: if ($changes{'togglecatscomm'}) {
20658: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
20659: }
20660: if ($changes{'categorizecomm'}) {
20661: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
20662: }
1.238 raeburn 20663: if ($changes{'unauth'}) {
20664: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
20665: }
20666: if ($changes{'auth'}) {
20667: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
20668: }
1.57 raeburn 20669: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20670: my $cathash;
20671: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
20672: $cathash = $domconfig{'coursecategories'}{'cats'};
20673: } else {
20674: $cathash = {};
20675: }
20676: my (@cats,@trails,%allitems);
20677: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
20678: if (keys(%deletions) > 0) {
20679: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
20680: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
20681: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
20682: }
20683: $resulttext .= '</ul></li>';
20684: }
20685: if (keys(%reorderings) > 0) {
20686: my %sort_by_trail;
20687: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
20688: foreach my $key (keys(%reorderings)) {
20689: if ($allitems{$key} ne '') {
20690: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20691: }
1.48 raeburn 20692: }
1.57 raeburn 20693: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20694: $resulttext .= '<li>'.$trails[$trail].'</li>';
20695: }
20696: $resulttext .= '</ul></li>';
1.48 raeburn 20697: }
1.57 raeburn 20698: if (keys(%adds) > 0) {
20699: my %sort_by_trail;
20700: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
20701: foreach my $key (keys(%adds)) {
20702: if ($allitems{$key} ne '') {
20703: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20704: }
20705: }
20706: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20707: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 20708: }
1.57 raeburn 20709: $resulttext .= '</ul></li>';
1.48 raeburn 20710: }
1.364 raeburn 20711: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
20712: if (ref($lastactref) eq 'HASH') {
20713: $lastactref->{'cats'} = 1;
20714: }
1.48 raeburn 20715: }
20716: $resulttext .= '</ul>';
1.239 raeburn 20717: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 20718: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
20719: if ($changes{'auth'}) {
20720: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
20721: }
20722: if ($changes{'unauth'}) {
20723: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
20724: }
20725: my $cachetime = 24*60*60;
20726: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 20727: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 20728: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 20729: }
20730: }
1.48 raeburn 20731: } else {
20732: $resulttext = '<span class="LC_error">'.
1.57 raeburn 20733: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 20734: }
20735: } else {
1.120 raeburn 20736: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 20737: }
20738: return $resulttext;
20739: }
20740:
1.69 raeburn 20741: sub modify_serverstatuses {
20742: my ($dom,%domconfig) = @_;
20743: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
20744: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
20745: %currserverstatus = %{$domconfig{'serverstatuses'}};
20746: }
20747: my @pages = &serverstatus_pages();
20748: foreach my $type (@pages) {
20749: $newserverstatus{$type}{'namedusers'} = '';
20750: $newserverstatus{$type}{'machines'} = '';
20751: if (defined($env{'form.'.$type.'_namedusers'})) {
20752: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
20753: my @okusers;
20754: foreach my $user (@users) {
20755: my ($uname,$udom) = split(/:/,$user);
20756: if (($udom =~ /^$match_domain$/) &&
20757: (&Apache::lonnet::domain($udom)) &&
20758: ($uname =~ /^$match_username$/)) {
20759: if (!grep(/^\Q$user\E/,@okusers)) {
20760: push(@okusers,$user);
20761: }
20762: }
20763: }
20764: if (@okusers > 0) {
20765: @okusers = sort(@okusers);
20766: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
20767: }
20768: }
20769: if (defined($env{'form.'.$type.'_machines'})) {
20770: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
20771: my @okmachines;
20772: foreach my $ip (@machines) {
20773: my @parts = split(/\./,$ip);
20774: next if (@parts < 4);
20775: my $badip = 0;
20776: for (my $i=0; $i<4; $i++) {
20777: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
20778: $badip = 1;
20779: last;
20780: }
20781: }
20782: if (!$badip) {
20783: push(@okmachines,$ip);
20784: }
20785: }
20786: @okmachines = sort(@okmachines);
20787: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
20788: }
20789: }
20790: my %serverstatushash = (
20791: serverstatuses => \%newserverstatus,
20792: );
20793: foreach my $type (@pages) {
1.83 raeburn 20794: foreach my $setting ('namedusers','machines') {
1.84 raeburn 20795: my (@current,@new);
1.83 raeburn 20796: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 20797: if ($currserverstatus{$type}{$setting} ne '') {
20798: @current = split(/,/,$currserverstatus{$type}{$setting});
20799: }
20800: }
20801: if ($newserverstatus{$type}{$setting} ne '') {
20802: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 20803: }
20804: if (@current > 0) {
20805: if (@new > 0) {
20806: foreach my $item (@current) {
20807: if (!grep(/^\Q$item\E$/,@new)) {
20808: $changes{$type}{$setting} = 1;
1.82 raeburn 20809: last;
20810: }
20811: }
1.84 raeburn 20812: foreach my $item (@new) {
20813: if (!grep(/^\Q$item\E$/,@current)) {
20814: $changes{$type}{$setting} = 1;
20815: last;
1.82 raeburn 20816: }
20817: }
20818: } else {
1.83 raeburn 20819: $changes{$type}{$setting} = 1;
1.69 raeburn 20820: }
1.83 raeburn 20821: } elsif (@new > 0) {
20822: $changes{$type}{$setting} = 1;
1.69 raeburn 20823: }
20824: }
20825: }
20826: if (keys(%changes) > 0) {
1.81 raeburn 20827: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 20828: my $putresult = &Apache::lonnet::put_dom('configuration',
20829: \%serverstatushash,$dom);
20830: if ($putresult eq 'ok') {
20831: $resulttext .= &mt('Changes made:').'<ul>';
20832: foreach my $type (@pages) {
1.84 raeburn 20833: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 20834: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 20835: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 20836: if ($newserverstatus{$type}{'namedusers'} eq '') {
20837: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
20838: } else {
20839: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
20840: }
1.84 raeburn 20841: }
20842: if ($changes{$type}{'machines'}) {
1.69 raeburn 20843: if ($newserverstatus{$type}{'machines'} eq '') {
20844: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
20845: } else {
20846: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
20847: }
20848:
20849: }
20850: $resulttext .= '</ul></li>';
20851: }
20852: }
20853: $resulttext .= '</ul>';
20854: } else {
20855: $resulttext = '<span class="LC_error">'.
20856: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
20857:
20858: }
20859: } else {
20860: $resulttext = &mt('No changes made to access to server status pages');
20861: }
20862: return $resulttext;
20863: }
20864:
1.118 jms 20865: sub modify_helpsettings {
1.285 raeburn 20866: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 20867: my ($resulttext,$errors,%changes,%helphash);
20868: my %defaultchecked = ('submitbugs' => 'on');
20869: my @offon = ('off','on');
1.118 jms 20870: my @toggles = ('submitbugs');
1.285 raeburn 20871: my %current = ('submitbugs' => '',
20872: 'adhoc' => {},
20873: );
1.118 jms 20874: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 20875: %current = %{$domconfig{'helpsettings'}};
20876: }
1.285 raeburn 20877: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 20878: foreach my $item (@toggles) {
20879: if ($defaultchecked{$item} eq 'on') {
20880: if ($current{$item} eq '') {
20881: if ($env{'form.'.$item} eq '0') {
20882: $changes{$item} = 1;
20883: }
20884: } elsif ($current{$item} ne $env{'form.'.$item}) {
20885: $changes{$item} = 1;
20886: }
20887: } elsif ($defaultchecked{$item} eq 'off') {
20888: if ($current{$item} eq '') {
20889: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 20890: $changes{$item} = 1;
20891: }
1.282 raeburn 20892: } elsif ($current{$item} ne $env{'form.'.$item}) {
20893: $changes{$item} = 1;
20894: }
20895: }
20896: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
20897: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
20898: }
20899: }
1.285 raeburn 20900: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 20901: my $confname = $dom.'-domainconfig';
20902: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 20903: my (@allpos,%newsettings,%changedprivs,$newrole);
20904: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 20905: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 20906: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 20907: my %lt = &Apache::lonlocal::texthash(
20908: s => 'system',
20909: d => 'domain',
20910: order => 'Display order',
20911: access => 'Role usage',
1.291 raeburn 20912: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 20913: dh => 'All with domain helpdesk role',
20914: da => 'All with domain helpdesk assistant role',
1.285 raeburn 20915: none => 'None',
20916: status => 'Determined based on institutional status',
20917: inc => 'Include all, but exclude specific personnel',
20918: exc => 'Exclude all, but include specific personnel',
20919: );
20920: for (my $num=0; $num<=$maxnum; $num++) {
20921: my ($prefix,$identifier,$rolename,%curr);
20922: if ($num == $maxnum) {
20923: next unless ($env{'form.newcusthelp'} == $maxnum);
20924: $identifier = 'custhelp'.$num;
20925: $prefix = 'helproles_'.$num;
20926: $rolename = $env{'form.custhelpname'.$num};
20927: $rolename=~s/[^A-Za-z0-9]//gs;
20928: next if ($rolename eq '');
20929: next if (exists($existing{'rolesdef_'.$rolename}));
20930: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
20931: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
20932: $newprivs{'c'},$confname,$dom);
20933: if ($result ne 'ok') {
20934: $errors .= '<li><span class="LC_error">'.
20935: &mt('An error occurred storing the new custom role: [_1]',
20936: $result).'</span></li>';
20937: next;
20938: } else {
20939: $changedprivs{$rolename} = \%newprivs;
20940: $newrole = $rolename;
20941: }
20942: } else {
20943: $prefix = 'helproles_'.$num;
20944: $rolename = $env{'form.'.$prefix};
20945: next if ($rolename eq '');
20946: next unless (exists($existing{'rolesdef_'.$rolename}));
20947: $identifier = 'custhelp'.$num;
20948: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
20949: my %currprivs;
1.289 raeburn 20950: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 20951: split(/\_/,$existing{'rolesdef_'.$rolename});
20952: foreach my $level ('c','d','s') {
20953: if ($newprivs{$level} ne $currprivs{$level}) {
20954: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
20955: $newprivs{'c'},$confname,$dom);
20956: if ($result ne 'ok') {
20957: $errors .= '<li><span class="LC_error">'.
20958: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
20959: $rolename,$result).'</span></li>';
20960: } else {
20961: $changedprivs{$rolename} = \%newprivs;
20962: }
20963: last;
20964: }
20965: }
20966: if (ref($current{'adhoc'}) eq 'HASH') {
20967: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
20968: %curr = %{$current{'adhoc'}{$rolename}};
20969: }
20970: }
20971: }
20972: my $newpos = $env{'form.'.$prefix.'_pos'};
20973: $newpos =~ s/\D+//g;
20974: $allpos[$newpos] = $rolename;
20975: my $newdesc = $env{'form.'.$prefix.'_desc'};
20976: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
20977: if ($curr{'desc'}) {
20978: if ($curr{'desc'} ne $newdesc) {
20979: $changes{'customrole'}{$rolename}{'desc'} = 1;
20980: $newsettings{$rolename}{'desc'} = $newdesc;
20981: }
20982: } elsif ($newdesc ne '') {
20983: $changes{'customrole'}{$rolename}{'desc'} = 1;
20984: $newsettings{$rolename}{'desc'} = $newdesc;
20985: }
20986: my $access = $env{'form.'.$prefix.'_access'};
20987: if (grep(/^\Q$access\E$/,@accesstypes)) {
20988: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
20989: if ($access eq 'status') {
20990: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
20991: if (scalar(@statuses) == 0) {
1.289 raeburn 20992: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 20993: } else {
20994: my (@shownstatus,$numtypes);
20995: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
20996: if (ref($types) eq 'ARRAY') {
20997: $numtypes = scalar(@{$types});
20998: foreach my $type (sort(@statuses)) {
20999: if ($type eq 'default') {
21000: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
21001: } elsif (grep(/^\Q$type\E$/,@{$types})) {
21002: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
21003: push(@shownstatus,$usertypes->{$type});
21004: }
21005: }
21006: }
21007: if (grep(/^default$/,@statuses)) {
21008: push(@shownstatus,$othertitle);
21009: }
21010: if (scalar(@shownstatus) == 1+$numtypes) {
21011: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
21012: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
21013: } else {
21014: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
21015: if (ref($curr{'status'}) eq 'ARRAY') {
21016: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
21017: if (@diffs) {
21018: $changes{'customrole'}{$rolename}{$access} = 1;
21019: }
21020: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21021: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 21022: }
1.166 raeburn 21023: }
21024: }
1.285 raeburn 21025: } elsif (($access eq 'inc') || ($access eq 'exc')) {
21026: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
21027: my @newspecstaff;
21028: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
21029: foreach my $person (sort(@personnel)) {
21030: if ($domhelpdesk{$person}) {
21031: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
21032: }
21033: }
21034: if (ref($curr{$access}) eq 'ARRAY') {
21035: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
21036: if (@diffs) {
21037: $changes{'customrole'}{$rolename}{$access} = 1;
21038: }
21039: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21040: $changes{'customrole'}{$rolename}{$access} = 1;
21041: }
21042: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21043: my ($uname,$udom) = split(/:/,$person);
21044: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
21045: }
21046: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 21047: }
1.285 raeburn 21048: } else {
21049: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
21050: }
21051: unless ($curr{'access'} eq $access) {
21052: $changes{'customrole'}{$rolename}{'access'} = 1;
21053: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 21054: }
21055: }
1.285 raeburn 21056: if (@allpos > 0) {
21057: my $idx = 0;
21058: foreach my $rolename (@allpos) {
21059: if ($rolename ne '') {
21060: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
21061: if (ref($current{'adhoc'}) eq 'HASH') {
21062: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
21063: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
21064: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 21065: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 21066: }
21067: }
1.282 raeburn 21068: }
1.285 raeburn 21069: $idx ++;
1.166 raeburn 21070: }
21071: }
1.118 jms 21072: }
1.123 jms 21073: my $putresult;
21074: if (keys(%changes) > 0) {
1.166 raeburn 21075: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 21076: if ($putresult eq 'ok') {
1.285 raeburn 21077: if (ref($helphash{'helpsettings'}) eq 'HASH') {
21078: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
21079: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
21080: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
21081: }
21082: }
21083: my $cachetime = 24*60*60;
21084: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21085: if (ref($lastactref) eq 'HASH') {
21086: $lastactref->{'domdefaults'} = 1;
21087: }
21088: } else {
21089: $errors .= '<li><span class="LC_error">'.
21090: &mt('An error occurred storing the settings: [_1]',
21091: $putresult).'</span></li>';
21092: }
21093: }
21094: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
21095: $resulttext = &mt('Changes made:').'<ul>';
21096: my (%shownprivs,@levelorder);
21097: @levelorder = ('c','d','s');
21098: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 21099: foreach my $item (sort(keys(%changes))) {
21100: if ($item eq 'submitbugs') {
21101: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
21102: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
21103: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 21104: } elsif ($item eq 'customrole') {
21105: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 21106: my @keyorder = ('order','desc','access','status','exc','inc');
21107: my %keytext = &Apache::lonlocal::texthash(
21108: order => 'Order',
21109: desc => 'Role description',
21110: access => 'Role usage',
1.300 droeschl 21111: status => 'Allowed institutional types',
1.285 raeburn 21112: exc => 'Allowed personnel',
21113: inc => 'Disallowed personnel',
21114: );
1.282 raeburn 21115: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 21116: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
21117: if ($role eq $newrole) {
21118: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
21119: $role).'<ul>';
21120: } else {
21121: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
21122: $role).'<ul>';
21123: }
21124: foreach my $key (@keyorder) {
21125: if ($changes{'customrole'}{$role}{$key}) {
21126: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
21127: $keytext{$key},$newsettings{$role}{$key}).
21128: '</li>';
21129: }
21130: }
21131: if (ref($changedprivs{$role}) eq 'HASH') {
21132: $shownprivs{$role} = 1;
21133: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
21134: foreach my $level (@levelorder) {
21135: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
21136: next if ($item eq '');
21137: my ($priv) = split(/\&/,$item,2);
21138: if (&Apache::lonnet::plaintext($priv)) {
21139: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
21140: unless ($level eq 'c') {
21141: $resulttext .= ' ('.$lt{$level}.')';
21142: }
21143: $resulttext .= '</li>';
21144: }
21145: }
21146: }
21147: $resulttext .= '</ul>';
21148: }
21149: $resulttext .= '</ul></li>';
21150: }
21151: }
21152: }
21153: }
21154: }
21155: }
21156: if (keys(%changedprivs)) {
21157: foreach my $role (sort(keys(%changedprivs))) {
21158: unless ($shownprivs{$role}) {
21159: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
21160: $role).'<ul>'.
21161: '<li>'.&mt('Privileges set to :').'<ul>';
21162: foreach my $level (@levelorder) {
21163: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
21164: next if ($item eq '');
21165: my ($priv) = split(/\&/,$item,2);
21166: if (&Apache::lonnet::plaintext($priv)) {
21167: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
21168: unless ($level eq 'c') {
21169: $resulttext .= ' ('.$lt{$level}.')';
21170: }
21171: $resulttext .= '</li>';
21172: }
1.282 raeburn 21173: }
21174: }
1.285 raeburn 21175: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 21176: }
21177: }
21178: }
1.285 raeburn 21179: $resulttext .= '</ul>';
21180: } else {
21181: $resulttext = &mt('No changes made to help settings');
1.118 jms 21182: }
21183: if ($errors) {
1.168 raeburn 21184: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 21185: $errors.'</ul>';
1.118 jms 21186: }
21187: return $resulttext;
21188: }
21189:
1.121 raeburn 21190: sub modify_coursedefaults {
1.212 raeburn 21191: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 21192: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 21193: my %defaultchecked = (
21194: 'canuse_pdfforms' => 'off',
21195: 'uselcmath' => 'on',
1.398 raeburn 21196: 'usejsme' => 'on',
21197: 'inline_chem' => 'on',
1.404 raeburn 21198: 'ltiauth' => 'off',
1.257 raeburn 21199: );
1.404 raeburn 21200: my @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem','ltiauth');
1.198 raeburn 21201: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 21202: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
1.428 raeburn 21203: 'coursequota_official','coursequota_unofficial','coursequota_community',
21204: 'coursequota_textbook','coursequota_placement','mysqltables_official',
21205: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook',
21206: 'mysqltables_placement');
1.271 raeburn 21207: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 21208: my %staticdefaults = (
21209: anonsurvey_threshold => 10,
21210: uploadquota => 500,
1.428 raeburn 21211: coursequota => 20,
1.257 raeburn 21212: postsubmit => 60,
1.276 raeburn 21213: mysqltables => 172800,
1.422 raeburn 21214: domexttool => 1,
1.432 raeburn 21215: crsauthor => 1,
1.198 raeburn 21216: );
1.314 raeburn 21217: my %texoptions = (
21218: MathJax => 'MathJax',
21219: mimetex => &mt('Convert to Images'),
21220: tth => &mt('TeX to HTML'),
21221: );
1.121 raeburn 21222: $defaultshash{'coursedefaults'} = {};
21223:
21224: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
21225: if ($domconfig{'coursedefaults'} eq '') {
21226: $domconfig{'coursedefaults'} = {};
21227: }
21228: }
21229:
21230: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
21231: foreach my $item (@toggles) {
21232: if ($defaultchecked{$item} eq 'on') {
21233: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21234: ($env{'form.'.$item} eq '0')) {
21235: $changes{$item} = 1;
1.192 raeburn 21236: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 21237: $changes{$item} = 1;
21238: }
21239: } elsif ($defaultchecked{$item} eq 'off') {
21240: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21241: ($env{'form.'.$item} eq '1')) {
21242: $changes{$item} = 1;
21243: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
21244: $changes{$item} = 1;
21245: }
21246: }
21247: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
21248: }
1.198 raeburn 21249: foreach my $item (@numbers) {
21250: my ($currdef,$newdef);
1.208 raeburn 21251: $newdef = $env{'form.'.$item};
1.198 raeburn 21252: if ($item eq 'anonsurvey_threshold') {
21253: $currdef = $domconfig{'coursedefaults'}{$item};
21254: $newdef =~ s/\D//g;
21255: if ($newdef eq '' || $newdef < 1) {
21256: $newdef = 1;
21257: }
21258: $defaultshash{'coursedefaults'}{$item} = $newdef;
21259: } else {
1.428 raeburn 21260: my ($setting,$type) = ($item =~ /^(uploadquota|coursequota|mysqltables)_(\w+)$/);
1.276 raeburn 21261: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
21262: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 21263: }
21264: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 21265: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 21266: }
21267: if ($currdef ne $newdef) {
21268: if ($item eq 'anonsurvey_threshold') {
21269: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
21270: $changes{$item} = 1;
21271: }
1.428 raeburn 21272: } elsif ($item =~ /^(uploadquota|coursequota|mysqltables)_/) {
1.289 raeburn 21273: my $setting = $1;
1.276 raeburn 21274: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
21275: $changes{$setting} = 1;
1.198 raeburn 21276: }
21277: }
1.139 raeburn 21278: }
21279: }
1.314 raeburn 21280: my $texengine;
21281: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
21282: $texengine = $env{'form.texengine'};
1.349 raeburn 21283: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
21284: if ($currdef eq '') {
21285: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 21286: $changes{'texengine'} = 1;
21287: }
1.349 raeburn 21288: } elsif ($currdef ne $texengine) {
1.314 raeburn 21289: $changes{'texengine'} = 1;
21290: }
21291: }
21292: if ($texengine ne '') {
21293: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
21294: }
1.264 raeburn 21295: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
21296: my @currclonecode;
21297: if (ref($currclone) eq 'HASH') {
21298: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
21299: @currclonecode = @{$currclone->{'instcode'}};
21300: }
21301: }
21302: my $newclone;
1.289 raeburn 21303: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 21304: $newclone = $env{'form.canclone'};
21305: }
21306: if ($newclone eq 'instcode') {
21307: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
21308: my (%codedefaults,@code_order,@clonecode);
21309: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
21310: \@code_order);
21311: foreach my $item (@code_order) {
21312: if (grep(/^\Q$item\E$/,@newcodes)) {
21313: push(@clonecode,$item);
21314: }
21315: }
21316: if (@clonecode) {
21317: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
21318: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
21319: if (@diffs) {
21320: $changes{'canclone'} = 1;
21321: }
21322: } else {
21323: $newclone eq '';
21324: }
21325: } elsif ($newclone ne '') {
1.289 raeburn 21326: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
21327: }
1.264 raeburn 21328: if ($newclone ne $currclone) {
21329: $changes{'canclone'} = 1;
21330: }
1.257 raeburn 21331: my %credits;
21332: foreach my $type (@types) {
21333: unless ($type eq 'community') {
21334: $credits{$type} = $env{'form.'.$type.'_credits'};
21335: $credits{$type} =~ s/[^\d.]+//g;
21336: }
21337: }
21338: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
21339: ($env{'form.coursecredits'} eq '1')) {
21340: $changes{'coursecredits'} = 1;
21341: foreach my $type (keys(%credits)) {
21342: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21343: }
21344: } else {
1.289 raeburn 21345: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 21346: foreach my $type (@types) {
21347: unless ($type eq 'community') {
1.289 raeburn 21348: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 21349: $changes{'coursecredits'} = 1;
21350: }
21351: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21352: }
21353: }
21354: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21355: foreach my $type (@types) {
21356: unless ($type eq 'community') {
21357: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
21358: $changes{'coursecredits'} = 1;
21359: last;
21360: }
21361: }
21362: }
21363: }
21364: }
21365: if ($env{'form.postsubmit'} eq '1') {
21366: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
21367: my %currtimeout;
21368: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21369: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
21370: $changes{'postsubmit'} = 1;
21371: }
21372: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21373: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
21374: }
21375: } else {
21376: $changes{'postsubmit'} = 1;
21377: }
21378: foreach my $type (@types) {
21379: my $timeout = $env{'form.'.$type.'_timeout'};
21380: $timeout =~ s/\D//g;
21381: if ($timeout == $staticdefaults{'postsubmit'}) {
21382: $timeout = '';
21383: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
21384: $timeout = '0';
21385: }
21386: unless ($timeout eq '') {
21387: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
21388: }
21389: if (exists($currtimeout{$type})) {
21390: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 21391: $changes{'postsubmit'} = 1;
1.257 raeburn 21392: }
21393: } elsif ($timeout ne '') {
21394: $changes{'postsubmit'} = 1;
21395: }
21396: }
21397: } else {
21398: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
21399: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21400: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
21401: $changes{'postsubmit'} = 1;
21402: }
21403: } else {
21404: $changes{'postsubmit'} = 1;
21405: }
1.192 raeburn 21406: }
1.432 raeburn 21407: my (%newdomexttool,%newexttool,%newcrsauthor,%olddomexttool,%oldexttool,%oldcrsauthor);
1.422 raeburn 21408: map { $newdomexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.domexttool');
1.425 raeburn 21409: map { $newexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.exttool');
1.432 raeburn 21410: map { $newcrsauthor{$_} = 1; } &Apache::loncommon::get_env_multiple('form.crsauthor');
1.422 raeburn 21411: if (ref($domconfig{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21412: %olddomexttool = %{$domconfig{'coursedefaults'}{'domexttool'}};
21413: } else {
21414: foreach my $type (@types) {
21415: if ($staticdefaults{'domexttool'}) {
21416: $olddomexttool{$type} = 1;
21417: } else {
21418: $olddomexttool{$type} = 0;
21419: }
21420: }
21421: }
21422: if (ref($domconfig{'coursedefaults'}{'exttool'}) eq 'HASH') {
1.425 raeburn 21423: %oldexttool = %{$domconfig{'coursedefaults'}{'exttool'}};
1.422 raeburn 21424: } else {
21425: foreach my $type (@types) {
21426: if ($staticdefaults{'exttool'}) {
21427: $oldexttool{$type} = 1;
21428: } else {
21429: $oldexttool{$type} = 0;
21430: }
21431: }
21432: }
1.432 raeburn 21433: if (ref($domconfig{'coursedefaults'}{'crsauthor'}) eq 'HASH') {
21434: %oldcrsauthor = %{$domconfig{'coursedefaults'}{'crsauthor'}};
21435: } else {
21436: foreach my $type (@types) {
21437: if ($staticdefaults{'crsauthor'}) {
21438: $oldcrsauthor{$type} = 1;
21439: } else {
21440: $oldcrsauthor{$type} = 0;
21441: }
21442: }
21443: }
1.422 raeburn 21444: foreach my $type (@types) {
21445: unless ($newdomexttool{$type}) {
21446: $newdomexttool{$type} = 0;
21447: }
21448: unless ($newexttool{$type}) {
21449: $newexttool{$type} = 0;
21450: }
1.432 raeburn 21451: unless ($newcrsauthor{$type}) {
21452: $newcrsauthor{$type} = 0;
21453: }
1.422 raeburn 21454: if ($newdomexttool{$type} != $olddomexttool{$type}) {
21455: $changes{'domexttool'} = 1;
21456: }
21457: if ($newexttool{$type} != $oldexttool{$type}) {
21458: $changes{'exttool'} = 1;
21459: }
1.432 raeburn 21460: if ($newcrsauthor{$type} != $oldcrsauthor{$type}) {
21461: $changes{'crsauthor'} = 1;
21462: }
1.422 raeburn 21463: }
21464: $defaultshash{'coursedefaults'}{'domexttool'} = \%newdomexttool;
21465: $defaultshash{'coursedefaults'}{'exttool'} = \%newexttool;
1.432 raeburn 21466: $defaultshash{'coursedefaults'}{'crsauthor'} = \%newcrsauthor;
1.121 raeburn 21467: }
21468: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21469: $dom);
21470: if ($putresult eq 'ok') {
21471: if (keys(%changes) > 0) {
1.213 raeburn 21472: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 21473: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 21474: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.398 raeburn 21475: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
1.422 raeburn 21476: ($changes{'inline_chem'}) || ($changes{'ltiauth'}) || ($changes{'domexttool'}) ||
1.432 raeburn 21477: ($changes{'exttool'}) || ($changes{'coursequota'}) || ($changes{'crsauthor'})) {
1.422 raeburn 21478: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','inline_chem','texengine',
21479: 'ltiauth') {
1.257 raeburn 21480: if ($changes{$item}) {
21481: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
21482: }
1.289 raeburn 21483: }
1.192 raeburn 21484: if ($changes{'coursecredits'}) {
21485: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 21486: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
21487: $domdefaults{$type.'credits'} =
21488: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
21489: }
21490: }
21491: }
21492: if ($changes{'postsubmit'}) {
21493: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21494: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
21495: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21496: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
21497: $domdefaults{$type.'postsubtimeout'} =
21498: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21499: }
21500: }
1.192 raeburn 21501: }
21502: }
1.198 raeburn 21503: if ($changes{'uploadquota'}) {
21504: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21505: foreach my $type (@types) {
21506: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
21507: }
21508: }
21509: }
1.428 raeburn 21510: if ($changes{'coursequota'}) {
21511: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
21512: foreach my $type (@types) {
21513: $domdefaults{$type.'coursequota'}=$defaultshash{'coursedefaults'}{'coursequota'}{$type};
21514: }
21515: }
21516: }
1.264 raeburn 21517: if ($changes{'canclone'}) {
21518: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21519: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21520: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
21521: if (@clonecodes) {
21522: $domdefaults{'canclone'} = join('+',@clonecodes);
21523: }
21524: }
21525: } else {
21526: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
21527: }
21528: }
1.422 raeburn 21529: if ($changes{'domexttool'}) {
21530: if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21531: foreach my $type (@types) {
21532: $domdefaults{$type.'domexttool'}=$defaultshash{'coursedefaults'}{'domexttool'}{$type};
21533: }
21534: }
21535: }
21536: if ($changes{'exttool'}) {
21537: if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
21538: foreach my $type (@types) {
21539: $domdefaults{$type.'exttool'}=$defaultshash{'coursedefaults'}{'exttool'}{$type};
21540: }
21541: }
21542: }
1.432 raeburn 21543: if ($changes{'crsauthor'}) {
21544: if (ref($defaultshash{'coursedefaults'}{'crsauthor'}) eq 'HASH') {
21545: foreach my $type (@types) {
21546: $domdefaults{$type.'crsauthor'}=$defaultshash{'coursedefaults'}{'crsauthor'}{$type};
21547: }
21548: }
21549: }
1.121 raeburn 21550: my $cachetime = 24*60*60;
21551: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 21552: if (ref($lastactref) eq 'HASH') {
21553: $lastactref->{'domdefaults'} = 1;
21554: }
1.121 raeburn 21555: }
21556: $resulttext = &mt('Changes made:').'<ul>';
21557: foreach my $item (sort(keys(%changes))) {
21558: if ($item eq 'canuse_pdfforms') {
21559: if ($env{'form.'.$item} eq '1') {
21560: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
21561: } else {
21562: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
21563: }
1.257 raeburn 21564: } elsif ($item eq 'uselcmath') {
21565: if ($env{'form.'.$item} eq '1') {
21566: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
21567: } else {
21568: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
21569: }
21570: } elsif ($item eq 'usejsme') {
21571: if ($env{'form.'.$item} eq '1') {
21572: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
21573: } else {
1.289 raeburn 21574: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 21575: }
1.398 raeburn 21576: } elsif ($item eq 'inline_chem') {
21577: if ($env{'form.'.$item} eq '1') {
21578: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
21579: } else {
21580: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
21581: }
1.314 raeburn 21582: } elsif ($item eq 'texengine') {
21583: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
21584: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
21585: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
21586: }
1.139 raeburn 21587: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 21588: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 21589: } elsif ($item eq 'uploadquota') {
21590: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21591: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
21592: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
21593: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 21594: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 21595: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 21596: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
21597: '</ul>'.
21598: '</li>';
21599: } else {
21600: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
21601: }
1.428 raeburn 21602: } elsif ($item eq 'coursequota') {
21603: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
21604: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course set as follows:').'<ul>'.
21605: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'official'}.'</b>').'</li>'.
21606: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'unofficial'}.'</b>').'</li>'.
21607: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'textbook'}.'</b>').'</li>'.
21608: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'placement'}.'</b>').'</li>'.
21609: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'community'}.'</b>').'</li>'.
21610: '</ul>'.
21611: '</li>';
21612: } else {
21613: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course remains default: [_1] MB',$staticdefaults{'coursequota'}).'</li>';
21614: }
1.276 raeburn 21615: } elsif ($item eq 'mysqltables') {
21616: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
21617: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
21618: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
21619: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
21620: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
21621: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
21622: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
21623: '</ul>'.
21624: '</li>';
21625: } else {
21626: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
21627: }
1.257 raeburn 21628: } elsif ($item eq 'postsubmit') {
21629: if ($domdefaults{'postsubmit'} eq 'off') {
21630: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
21631: } else {
21632: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 21633: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 21634: $resulttext .= &mt('durations:').'<ul>';
21635: foreach my $type (@types) {
21636: $resulttext .= '<li>';
21637: my $timeout;
21638: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21639: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21640: }
21641: my $display;
21642: if ($timeout eq '0') {
21643: $display = &mt('unlimited');
21644: } elsif ($timeout eq '') {
21645: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
21646: } else {
21647: $display = &mt('[quant,_1,second]',$timeout);
21648: }
21649: if ($type eq 'community') {
21650: $resulttext .= &mt('Communities');
21651: } elsif ($type eq 'official') {
21652: $resulttext .= &mt('Official courses');
21653: } elsif ($type eq 'unofficial') {
21654: $resulttext .= &mt('Unofficial courses');
21655: } elsif ($type eq 'textbook') {
21656: $resulttext .= &mt('Textbook courses');
1.271 raeburn 21657: } elsif ($type eq 'placement') {
21658: $resulttext .= &mt('Placement tests');
1.257 raeburn 21659: }
21660: $resulttext .= ' -- '.$display.'</li>';
21661: }
21662: $resulttext .= '</ul>';
21663: }
1.289 raeburn 21664: $resulttext .= '</li>';
1.257 raeburn 21665: }
1.192 raeburn 21666: } elsif ($item eq 'coursecredits') {
21667: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21668: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 21669: ($domdefaults{'unofficialcredits'} eq '') &&
21670: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 21671: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21672: } else {
21673: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
21674: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
21675: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 21676: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 21677: '</ul>'.
21678: '</li>';
21679: }
21680: } else {
21681: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21682: }
1.264 raeburn 21683: } elsif ($item eq 'canclone') {
21684: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21685: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21686: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
21687: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
21688: }
21689: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
21690: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
21691: } else {
1.289 raeburn 21692: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 21693: }
1.404 raeburn 21694: } elsif ($item eq 'ltiauth') {
21695: if ($env{'form.'.$item} eq '1') {
21696: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
21697: } else {
21698: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
21699: }
1.432 raeburn 21700: } elsif (($item eq 'domexttool') || ($item eq 'exttool') || ($item eq 'crsauthor')) {
1.422 raeburn 21701: my @noyes = (&mt('no'),&mt('yes'));
1.432 raeburn 21702: my %status = (
21703: domexttool => {
21704: ishash => &mt('External Tools defined in the domain may be used as follows:'),
21705: default => &mt('External Tools defined in the domain may be used in all course types, by default'),
21706: },
21707: exttool => {
21708: ishash => &mt('External Tools can be defined and configured in course containers as follows:'),
21709: default => &mt('External Tools can not be defined in any course types, by default'),
21710: },
21711: crsauthor => {
21712: ishash => &mt('Standard Problems can be created within course containers as follows:'),
21713: default => &mt('Standard Problems can be created within any course type, by default'),
21714: },
21715: );
21716:
21717: if (ref($defaultshash{'coursedefaults'}{$item}) eq 'HASH') {
21718: $resulttext .= '<li>'.$status{$item}{'ishash'}.'<ul>'.
21719: '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'official'}].'</b>').'</li>'.
21720: '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'unofficial'}].'</b>').'</li>'.
21721: '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'textbook'}].'</b>').'</li>'.
21722: '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'placement'}].'</b>').'</li>'.
21723: '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'community'}].'</b>').'</li>'.
1.422 raeburn 21724: '</ul>'.
21725: '</li>';
21726: } else {
1.432 raeburn 21727: $resulttext .= '<li>'.$status{$item}{'default'}.'</li>';
1.422 raeburn 21728: }
1.140 raeburn 21729: }
1.121 raeburn 21730: }
21731: $resulttext .= '</ul>';
21732: } else {
21733: $resulttext = &mt('No changes made to course defaults');
21734: }
21735: } else {
21736: $resulttext = '<span class="LC_error">'.
21737: &mt('An error occurred: [_1]',$putresult).'</span>';
21738: }
21739: return $resulttext;
21740: }
21741:
1.231 raeburn 21742: sub modify_selfenrollment {
21743: my ($dom,$lastactref,%domconfig) = @_;
21744: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 21745: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 21746: my %titles = &tool_titles();
1.232 raeburn 21747: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
21748: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 21749: $ordered{'default'} = ['types','registered','approval','limit'];
21750:
21751: my (%roles,%shown,%toplevel);
21752: $roles{'0'} = &Apache::lonnet::plaintext('dc');
21753:
21754: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
21755: if ($domconfig{'selfenrollment'} eq '') {
21756: $domconfig{'selfenrollment'} = {};
21757: }
21758: }
21759: %toplevel = (
21760: admin => 'Configuration Rights',
21761: default => 'Default settings',
21762: validation => 'Validation of self-enrollment requests',
21763: );
1.233 raeburn 21764: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 21765:
21766: if (ref($ordered{'admin'}) eq 'ARRAY') {
21767: foreach my $item (@{$ordered{'admin'}}) {
21768: foreach my $type (@types) {
21769: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
21770: $selfenrollhash{'admin'}{$type}{$item} = 1;
21771: } else {
21772: $selfenrollhash{'admin'}{$type}{$item} = 0;
21773: }
21774: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
21775: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
21776: if ($selfenrollhash{'admin'}{$type}{$item} ne
21777: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
21778: push(@{$changes{'admin'}{$type}},$item);
21779: }
21780: } else {
21781: if (!$selfenrollhash{'admin'}{$type}{$item}) {
21782: push(@{$changes{'admin'}{$type}},$item);
21783: }
21784: }
21785: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
21786: push(@{$changes{'admin'}{$type}},$item);
21787: }
21788: }
21789: }
21790: }
21791:
21792: foreach my $item (@{$ordered{'default'}}) {
21793: foreach my $type (@types) {
21794: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
21795: if ($item eq 'types') {
21796: unless (($value eq 'all') || ($value eq 'dom')) {
21797: $value = '';
21798: }
21799: } elsif ($item eq 'registered') {
21800: unless ($value eq '1') {
21801: $value = 0;
21802: }
21803: } elsif ($item eq 'approval') {
21804: unless ($value =~ /^[012]$/) {
21805: $value = 0;
21806: }
21807: } else {
21808: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21809: $value = 'none';
21810: }
21811: }
21812: $selfenrollhash{'default'}{$type}{$item} = $value;
21813: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
21814: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21815: if ($selfenrollhash{'default'}{$type}{$item} ne
21816: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
21817: push(@{$changes{'default'}{$type}},$item);
21818: }
21819: } else {
21820: push(@{$changes{'default'}{$type}},$item);
21821: }
21822: } else {
21823: push(@{$changes{'default'}{$type}},$item);
21824: }
21825: if ($item eq 'limit') {
21826: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21827: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
21828: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
21829: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
21830: }
21831: } else {
21832: $selfenrollhash{'default'}{$type}{'cap'} = '';
21833: }
21834: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21835: if ($selfenrollhash{'default'}{$type}{'cap'} ne
21836: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
21837: push(@{$changes{'default'}{$type}},'cap');
21838: }
21839: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
21840: push(@{$changes{'default'}{$type}},'cap');
21841: }
21842: }
21843: }
21844: }
21845:
21846: foreach my $item (@{$itemsref}) {
21847: if ($item eq 'fields') {
21848: my @changed;
21849: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
21850: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
21851: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
21852: }
21853: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21854: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
21855: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
21856: $domconfig{'selfenrollment'}{'validation'}{$item});
21857: } else {
21858: @changed = @{$selfenrollhash{'validation'}{$item}};
21859: }
21860: } else {
21861: @changed = @{$selfenrollhash{'validation'}{$item}};
21862: }
21863: if (@changed) {
21864: if ($selfenrollhash{'validation'}{$item}) {
21865: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
21866: } else {
21867: $changes{'validation'}{$item} = &mt('None');
21868: }
21869: }
21870: } else {
21871: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
21872: if ($item eq 'markup') {
21873: if ($env{'form.selfenroll_validation_'.$item}) {
21874: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
21875: }
21876: }
21877: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21878: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
21879: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
21880: }
21881: }
21882: }
21883: }
21884:
21885: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
21886: $dom);
21887: if ($putresult eq 'ok') {
21888: if (keys(%changes) > 0) {
21889: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
21890: $resulttext = &mt('Changes made:').'<ul>';
21891: foreach my $key ('admin','default','validation') {
21892: if (ref($changes{$key}) eq 'HASH') {
21893: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
21894: if ($key eq 'validation') {
21895: foreach my $item (@{$itemsref}) {
21896: if (exists($changes{$key}{$item})) {
21897: if ($item eq 'markup') {
21898: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
21899: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
21900: } else {
21901: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
21902: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
21903: }
21904: }
21905: }
21906: } else {
21907: foreach my $type (@types) {
21908: if ($type eq 'community') {
21909: $roles{'1'} = &mt('Community personnel');
21910: } else {
21911: $roles{'1'} = &mt('Course personnel');
21912: }
21913: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 21914: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
21915: if ($key eq 'admin') {
21916: my @mgrdc = ();
21917: if (ref($ordered{$key}) eq 'ARRAY') {
21918: foreach my $item (@{$ordered{'admin'}}) {
21919: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
21920: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
21921: push(@mgrdc,$item);
21922: }
21923: }
21924: }
21925: if (@mgrdc) {
21926: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
21927: } else {
21928: delete($domdefaults{$type.'selfenrolladmdc'});
21929: }
21930: }
21931: } else {
21932: if (ref($ordered{$key}) eq 'ARRAY') {
21933: foreach my $item (@{$ordered{$key}}) {
21934: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
21935: $domdefaults{$type.'selfenroll'.$item} =
21936: $selfenrollhash{$key}{$type}{$item};
21937: }
21938: }
21939: }
21940: }
21941: }
1.231 raeburn 21942: $resulttext .= '<li>'.$titles{$type}.'<ul>';
21943: foreach my $item (@{$ordered{$key}}) {
21944: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
21945: $resulttext .= '<li>';
21946: if ($key eq 'admin') {
21947: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
21948: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
21949: } else {
21950: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
21951: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
21952: }
21953: $resulttext .= '</li>';
21954: }
21955: }
21956: $resulttext .= '</ul></li>';
21957: }
21958: }
21959: $resulttext .= '</ul></li>';
21960: }
21961: }
1.305 raeburn 21962: }
21963: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
21964: my $cachetime = 24*60*60;
21965: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21966: if (ref($lastactref) eq 'HASH') {
21967: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 21968: }
1.231 raeburn 21969: }
21970: $resulttext .= '</ul>';
21971: } else {
21972: $resulttext = &mt('No changes made to self-enrollment settings');
21973: }
21974: } else {
21975: $resulttext = '<span class="LC_error">'.
21976: &mt('An error occurred: [_1]',$putresult).'</span>';
21977: }
21978: return $resulttext;
21979: }
21980:
1.373 raeburn 21981: sub modify_wafproxy {
21982: my ($dom,$action,$lastactref,%domconfig) = @_;
21983: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 21984: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
21985: %wafproxy,%changes,%expirecache,%expiresaml);
1.373 raeburn 21986: foreach my $server (sort(keys(%servers))) {
21987: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
21988: if ($serverhome eq $server) {
21989: my $serverdom = &Apache::lonnet::host_domain($server);
21990: if ($serverdom eq $dom) {
21991: $canset{$server} = 1;
21992: }
21993: }
21994: }
1.381 raeburn 21995: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
21996: %{$values{$dom}} = ();
21997: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
21998: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
21999: }
1.388 raeburn 22000: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
22001: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
22002: }
1.382 raeburn 22003: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.381 raeburn 22004: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
22005: }
22006: }
1.373 raeburn 22007: my $output;
22008: if (keys(%canset)) {
22009: %{$wafproxy{'alias'}} = ();
1.388 raeburn 22010: %{$wafproxy{'saml'}} = ();
1.373 raeburn 22011: foreach my $key (sort(keys(%canset))) {
1.381 raeburn 22012: if ($env{'form.wafproxy_'.$dom}) {
22013: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
22014: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
22015: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
22016: $changes{'alias'} = 1;
22017: }
1.388 raeburn 22018: if ($env{'form.wafproxy_alias_saml_'.$key}) {
22019: $wafproxy{'saml'}{$key} = 1;
22020: }
22021: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
22022: $changes{'saml'} = 1;
22023: }
1.381 raeburn 22024: } else {
22025: $wafproxy{'alias'}{$key} = '';
1.388 raeburn 22026: $wafproxy{'saml'}{$key} = '';
1.381 raeburn 22027: if ($curralias{$key}) {
22028: $changes{'alias'} = 1;
22029: }
1.388 raeburn 22030: if ($currsaml{$key}) {
22031: $changes{'saml'} = 1;
22032: }
1.373 raeburn 22033: }
22034: if ($wafproxy{'alias'}{$key} eq '') {
22035: if ($curralias{$key}) {
22036: $expirecache{$key} = 1;
22037: }
22038: delete($wafproxy{'alias'}{$key});
22039: }
1.388 raeburn 22040: if ($wafproxy{'saml'}{$key} eq '') {
22041: if ($currsaml{$key}) {
22042: $expiresaml{$key} = 1;
22043: }
22044: delete($wafproxy{'saml'}{$key});
22045: }
1.373 raeburn 22046: }
22047: unless (keys(%{$wafproxy{'alias'}})) {
22048: delete($wafproxy{'alias'});
22049: }
1.388 raeburn 22050: unless (keys(%{$wafproxy{'saml'}})) {
22051: delete($wafproxy{'saml'});
22052: }
22053: # Localization for values in %warn occurs in &mt() calls separately.
1.373 raeburn 22054: my %warn = (
22055: trusted => 'trusted IP range(s)',
1.381 raeburn 22056: vpnint => 'internal IP range(s) for VPN sessions(s)',
22057: vpnext => 'IP range(s) for backend WAF connections',
1.373 raeburn 22058: );
1.382 raeburn 22059: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22060: my $possible = $env{'form.wafproxy_'.$item};
22061: $possible =~ s/^\s+|\s+$//g;
22062: if ($possible ne '') {
1.381 raeburn 22063: if ($item eq 'remoteip') {
22064: if ($possible =~ /^[mhn]$/) {
22065: $wafproxy{$item} = $possible;
22066: }
22067: } elsif ($item eq 'ipheader') {
22068: if ($wafproxy{'remoteip'} eq 'h') {
22069: $wafproxy{$item} = $possible;
22070: }
1.382 raeburn 22071: } elsif ($item eq 'sslopt') {
22072: if ($possible =~ /^0|1$/) {
22073: $wafproxy{$item} = $possible;
22074: }
1.373 raeburn 22075: } else {
22076: my (@ok,$count);
1.381 raeburn 22077: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
22078: unless ($env{'form.wafproxy_vpnaccess'}) {
22079: $possible = '';
22080: }
22081: } elsif ($item eq 'trusted') {
22082: unless ($wafproxy{'remoteip'} eq 'h') {
22083: $possible = '';
22084: }
22085: }
22086: unless ($possible eq '') {
22087: $possible =~ s/[\r\n]+/\s/g;
22088: $possible =~ s/\s*-\s*/-/g;
22089: $possible =~ s/\s+/,/g;
1.393 raeburn 22090: $possible =~ s/,+/,/g;
1.381 raeburn 22091: }
1.373 raeburn 22092: $count = 0;
1.381 raeburn 22093: if ($possible ne '') {
1.373 raeburn 22094: foreach my $poss (split(/\,/,$possible)) {
22095: $count ++;
1.393 raeburn 22096: $poss = &validate_ip_pattern($poss);
22097: if ($poss ne '') {
1.373 raeburn 22098: push(@ok,$poss);
22099: }
22100: }
22101: my $diff = $count - scalar(@ok);
22102: if ($diff) {
22103: push(@warnings,'<li>'.
22104: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
22105: $diff,$warn{$item}).
22106: '</li>');
22107: }
1.393 raeburn 22108: if (@ok) {
22109: my @cidr_list;
22110: foreach my $item (@ok) {
22111: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
22112: }
22113: $wafproxy{$item} = join(',',@cidr_list);
22114: }
1.373 raeburn 22115: }
22116: }
1.381 raeburn 22117: if ($wafproxy{$item} ne $currvalue{$item}) {
1.373 raeburn 22118: $changes{$item} = 1;
22119: }
1.381 raeburn 22120: } elsif ($currvalue{$item}) {
22121: $changes{$item} = 1;
1.425 raeburn 22122: }
1.381 raeburn 22123: }
22124: } else {
22125: if (keys(%curralias)) {
22126: $changes{'alias'} = 1;
1.388 raeburn 22127: }
22128: if (keys(%currsaml)) {
22129: $changes{'saml'} = 1;
1.425 raeburn 22130: }
1.381 raeburn 22131: if (keys(%currvalue)) {
22132: foreach my $key (keys(%currvalue)) {
22133: $changes{$key} = 1;
1.373 raeburn 22134: }
22135: }
22136: }
22137: if (keys(%changes)) {
22138: my %defaultshash = (
22139: wafproxy => \%wafproxy,
1.425 raeburn 22140: );
1.373 raeburn 22141: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22142: $dom);
22143: if ($putresult eq 'ok') {
22144: my $cachetime = 24*60*60;
22145: my (%domdefaults,$updatedomdefs);
1.382 raeburn 22146: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22147: if ($changes{$item}) {
22148: unless ($updatedomdefs) {
22149: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
22150: $updatedomdefs = 1;
22151: }
22152: if ($wafproxy{$item}) {
22153: $domdefaults{'waf_'.$item} = $wafproxy{$item};
22154: } elsif (exists($domdefaults{'waf_'.$item})) {
22155: delete($domdefaults{'waf_'.$item});
1.425 raeburn 22156: }
1.373 raeburn 22157: }
22158: }
22159: if ($updatedomdefs) {
22160: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22161: if (ref($lastactref) eq 'HASH') {
22162: $lastactref->{'domdefaults'} = 1;
22163: }
22164: }
22165: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
22166: my %updates = %expirecache;
22167: foreach my $key (keys(%expirecache)) {
22168: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
22169: }
22170: if (ref($wafproxy{'alias'}) eq 'HASH') {
22171: my $cachetime = 24*60*60;
22172: foreach my $key (keys(%{$wafproxy{'alias'}})) {
22173: $updates{$key} = 1;
22174: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
22175: $cachetime);
22176: }
22177: }
22178: if (ref($lastactref) eq 'HASH') {
22179: $lastactref->{'proxyalias'} = \%updates;
22180: }
22181: }
1.388 raeburn 22182: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
22183: my %samlupdates = %expiresaml;
22184: foreach my $key (keys(%expiresaml)) {
22185: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
22186: }
22187: if (ref($wafproxy{'saml'}) eq 'HASH') {
22188: my $cachetime = 24*60*60;
22189: foreach my $key (keys(%{$wafproxy{'saml'}})) {
22190: $samlupdates{$key} = 1;
22191: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
22192: $cachetime);
22193: }
22194: }
22195: if (ref($lastactref) eq 'HASH') {
22196: $lastactref->{'proxysaml'} = \%samlupdates;
22197: }
22198: }
1.373 raeburn 22199: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.401 raeburn 22200: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22201: if ($changes{$item}) {
22202: if ($item eq 'alias') {
22203: my $numaliased = 0;
22204: if (ref($wafproxy{'alias'}) eq 'HASH') {
22205: my $shown;
22206: if (keys(%{$wafproxy{'alias'}})) {
22207: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
22208: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
22209: &Apache::lonnet::hostname($server),
22210: $wafproxy{'alias'}{$server}).'</li>';
22211: $numaliased ++;
22212: }
22213: if ($numaliased) {
22214: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
22215: '<ul>'.$shown.'</ul>').'</li>';
22216: }
22217: }
22218: }
22219: unless ($numaliased) {
22220: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
22221: }
1.388 raeburn 22222: } elsif ($item eq 'saml') {
1.425 raeburn 22223: my $shown;
1.388 raeburn 22224: if (ref($wafproxy{'saml'}) eq 'HASH') {
22225: if (keys(%{$wafproxy{'saml'}})) {
22226: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
22227: }
22228: }
22229: if ($shown) {
1.396 raeburn 22230: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
1.388 raeburn 22231: $shown).'</li>';
22232: } else {
1.396 raeburn 22233: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
1.388 raeburn 22234: }
1.373 raeburn 22235: } else {
1.381 raeburn 22236: if ($item eq 'remoteip') {
22237: my %ip_methods = &remoteip_methods();
22238: if ($wafproxy{$item} =~ /^[mh]$/) {
22239: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
22240: $ip_methods{$wafproxy{$item}}).'</li>';
22241: } else {
22242: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
22243: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
22244: '</li>';
22245: } else {
22246: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
22247: }
22248: }
22249: } elsif ($item eq 'ipheader') {
1.373 raeburn 22250: if ($wafproxy{$item}) {
1.381 raeburn 22251: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
1.373 raeburn 22252: $wafproxy{$item}).'</li>';
22253: } else {
1.381 raeburn 22254: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
1.373 raeburn 22255: }
22256: } elsif ($item eq 'trusted') {
22257: if ($wafproxy{$item}) {
1.381 raeburn 22258: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
1.373 raeburn 22259: $wafproxy{$item}).'</li>';
22260: } else {
22261: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
22262: }
1.381 raeburn 22263: } elsif ($item eq 'vpnint') {
22264: if ($wafproxy{$item}) {
22265: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
22266: $wafproxy{$item}).'</li>';
22267: } else {
22268: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
22269: }
22270: } elsif ($item eq 'vpnext') {
1.373 raeburn 22271: if ($wafproxy{$item}) {
1.381 raeburn 22272: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
1.373 raeburn 22273: $wafproxy{$item}).'</li>';
22274: } else {
1.381 raeburn 22275: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
1.373 raeburn 22276: }
1.382 raeburn 22277: } elsif ($item eq 'sslopt') {
22278: if ($wafproxy{$item}) {
22279: $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>';
22280: } else {
22281: $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>';
22282: }
1.373 raeburn 22283: }
22284: }
22285: }
22286: }
1.420 raeburn 22287: $output .= '</ul>';
1.373 raeburn 22288: } else {
22289: $output = '<span class="LC_error">'.
22290: &mt('An error occurred: [_1]',$putresult).'</span>';
22291: }
22292: } elsif (keys(%canset)) {
22293: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
22294: }
22295: if (@warnings) {
22296: $output .= '<br />'.&mt('Warnings:').'<ul>'.
22297: join("\n",@warnings).'</ul>';
22298: }
22299: return $output;
22300: }
22301:
22302: sub validate_ip_pattern {
22303: my ($pattern) = @_;
22304: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
22305: my ($start,$end) = ($1,$2);
22306: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
1.393 raeburn 22307: if (($start !~ m{/}) && ($end !~ m{/})) {
22308: return $start.'-'.$end;
22309: }
22310: }
22311: } elsif ($pattern ne '') {
22312: $pattern = &Net::CIDR::cidrvalidate($pattern);
22313: if ($pattern ne '') {
22314: return $pattern;
1.373 raeburn 22315: }
22316: }
1.393 raeburn 22317: return;
1.373 raeburn 22318: }
22319:
1.137 raeburn 22320: sub modify_usersessions {
1.212 raeburn 22321: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 22322: my @hostingtypes = ('version','excludedomain','includedomain');
22323: my @offloadtypes = ('primary','default');
22324: my %types = (
22325: remote => \@hostingtypes,
22326: hosted => \@hostingtypes,
22327: spares => \@offloadtypes,
22328: );
22329: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 22330: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 22331: my (%by_ip,%by_location,@intdoms,@instdoms);
22332: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 22333: my @locations = sort(keys(%by_location));
1.137 raeburn 22334: my (%defaultshash,%changes);
22335: foreach my $prefix (@prefixes) {
22336: $defaultshash{'usersessions'}{$prefix} = {};
22337: }
1.212 raeburn 22338: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 22339: my $resulttext;
1.138 raeburn 22340: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 22341: foreach my $prefix (@prefixes) {
1.145 raeburn 22342: next if ($prefix eq 'spares');
22343: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 22344: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22345: if ($type eq 'version') {
22346: my $value = $env{'form.'.$prefix.'_'.$type};
22347: my $okvalue;
22348: if ($value ne '') {
22349: if (grep(/^\Q$value\E$/,@lcversions)) {
22350: $okvalue = $value;
22351: }
22352: }
22353: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22354: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22355: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
22356: if ($inuse == 0) {
22357: $changes{$prefix}{$type} = 1;
22358: } else {
22359: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
22360: $changes{$prefix}{$type} = 1;
22361: }
22362: if ($okvalue ne '') {
22363: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22364: }
22365: }
22366: } else {
22367: if (($inuse == 1) && ($okvalue ne '')) {
22368: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22369: $changes{$prefix}{$type} = 1;
22370: }
22371: }
22372: } else {
22373: if (($inuse == 1) && ($okvalue ne '')) {
22374: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22375: $changes{$prefix}{$type} = 1;
22376: }
22377: }
22378: } else {
22379: if (($inuse == 1) && ($okvalue ne '')) {
22380: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22381: $changes{$prefix}{$type} = 1;
22382: }
22383: }
22384: } else {
22385: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22386: my @okvals;
22387: foreach my $val (@vals) {
1.138 raeburn 22388: if ($val =~ /:/) {
22389: my @items = split(/:/,$val);
22390: foreach my $item (@items) {
22391: if (ref($by_location{$item}) eq 'ARRAY') {
22392: push(@okvals,$item);
22393: }
22394: }
22395: } else {
22396: if (ref($by_location{$val}) eq 'ARRAY') {
22397: push(@okvals,$val);
22398: }
1.137 raeburn 22399: }
22400: }
22401: @okvals = sort(@okvals);
22402: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22403: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22404: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22405: if ($inuse == 0) {
22406: $changes{$prefix}{$type} = 1;
22407: } else {
22408: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22409: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
22410: if (@changed > 0) {
22411: $changes{$prefix}{$type} = 1;
22412: }
22413: }
22414: } else {
22415: if ($inuse == 1) {
22416: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22417: $changes{$prefix}{$type} = 1;
22418: }
22419: }
22420: } else {
22421: if ($inuse == 1) {
22422: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22423: $changes{$prefix}{$type} = 1;
22424: }
22425: }
22426: } else {
22427: if ($inuse == 1) {
22428: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22429: $changes{$prefix}{$type} = 1;
22430: }
22431: }
22432: }
22433: }
22434: }
1.145 raeburn 22435:
22436: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 22437: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 22438: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
22439: my $savespares;
22440:
22441: foreach my $lonhost (sort(keys(%servers))) {
22442: my $serverhomeID =
22443: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 22444: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 22445: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
22446: my %spareschg;
22447: foreach my $type (@{$types{'spares'}}) {
22448: my @okspares;
22449: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
22450: foreach my $server (@checked) {
1.152 raeburn 22451: if (&Apache::lonnet::hostname($server) ne '') {
22452: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
22453: unless (grep(/^\Q$server\E$/,@okspares)) {
22454: push(@okspares,$server);
22455: }
1.145 raeburn 22456: }
22457: }
22458: }
22459: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
22460: my $newspare;
1.152 raeburn 22461: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
22462: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 22463: $newspare = $new;
22464: }
22465: }
1.152 raeburn 22466: my @spares;
22467: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
22468: @spares = sort(@okspares,$newspare);
22469: } else {
22470: @spares = sort(@okspares);
22471: }
22472: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 22473: if (ref($spareid{$lonhost}) eq 'HASH') {
22474: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 22475: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 22476: if (@diffs > 0) {
22477: $spareschg{$type} = 1;
22478: }
22479: }
22480: }
22481: }
22482: if (keys(%spareschg) > 0) {
22483: $changes{'spares'}{$lonhost} = \%spareschg;
22484: }
22485: }
1.261 raeburn 22486: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371 raeburn 22487: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261 raeburn 22488: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
22489: my @okoffload;
22490: if (@offloadnow) {
22491: foreach my $server (@offloadnow) {
22492: if (&Apache::lonnet::hostname($server) ne '') {
22493: unless (grep(/^\Q$server\E$/,@okoffload)) {
22494: push(@okoffload,$server);
22495: }
22496: }
22497: }
22498: if (@okoffload) {
22499: foreach my $lonhost (@okoffload) {
22500: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
22501: }
22502: }
22503: }
1.371 raeburn 22504: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
22505: my @okoffloadoth;
22506: if (@offloadoth) {
22507: foreach my $server (@offloadoth) {
22508: if (&Apache::lonnet::hostname($server) ne '') {
22509: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
22510: push(@okoffloadoth,$server);
22511: }
22512: }
22513: }
22514: if (@okoffloadoth) {
22515: foreach my $lonhost (@okoffloadoth) {
22516: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
22517: }
22518: }
22519: }
1.145 raeburn 22520: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22521: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
22522: if (ref($changes{'spares'}) eq 'HASH') {
22523: if (keys(%{$changes{'spares'}}) > 0) {
22524: $savespares = 1;
22525: }
22526: }
22527: } else {
22528: $savespares = 1;
22529: }
1.371 raeburn 22530: foreach my $offload ('offloadnow','offloadoth') {
22531: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
22532: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
22533: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
22534: $changes{$offload} = 1;
22535: last;
22536: }
1.261 raeburn 22537: }
1.371 raeburn 22538: unless ($changes{$offload}) {
22539: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
22540: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
22541: $changes{$offload} = 1;
22542: last;
22543: }
1.261 raeburn 22544: }
22545: }
1.371 raeburn 22546: } else {
22547: if (($offload eq 'offloadnow') && (@okoffload)) {
22548: $changes{'offloadnow'} = 1;
22549: }
22550: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
22551: $changes{'offloadoth'} = 1;
22552: }
1.425 raeburn 22553: }
1.371 raeburn 22554: }
22555: } else {
22556: if (@okoffload) {
1.261 raeburn 22557: $changes{'offloadnow'} = 1;
22558: }
1.371 raeburn 22559: if (@okoffloadoth) {
22560: $changes{'offloadoth'} = 1;
22561: }
1.145 raeburn 22562: }
1.147 raeburn 22563: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
22564: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 22565: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22566: $dom);
22567: if ($putresult eq 'ok') {
22568: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22569: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
22570: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
22571: }
22572: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
22573: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
22574: }
1.261 raeburn 22575: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22576: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
22577: }
1.371 raeburn 22578: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22579: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
22580: }
1.137 raeburn 22581: }
22582: my $cachetime = 24*60*60;
22583: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 22584: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 22585: if (ref($lastactref) eq 'HASH') {
22586: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 22587: $lastactref->{'usersessions'} = 1;
1.212 raeburn 22588: }
1.147 raeburn 22589: if (keys(%changes) > 0) {
22590: my %lt = &usersession_titles();
22591: $resulttext = &mt('Changes made:').'<ul>';
22592: foreach my $prefix (@prefixes) {
22593: if (ref($changes{$prefix}) eq 'HASH') {
22594: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
22595: if ($prefix eq 'spares') {
22596: if (ref($changes{$prefix}) eq 'HASH') {
22597: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
22598: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 22599: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 22600: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
22601: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 22602: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
22603: foreach my $type (@{$types{$prefix}}) {
22604: if ($changes{$prefix}{$lonhost}{$type}) {
22605: my $offloadto = &mt('None');
22606: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
22607: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
22608: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
22609: }
1.145 raeburn 22610: }
1.147 raeburn 22611: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 22612: }
1.137 raeburn 22613: }
22614: }
1.147 raeburn 22615: $resulttext .= '</li>';
1.137 raeburn 22616: }
22617: }
1.147 raeburn 22618: } else {
22619: foreach my $type (@{$types{$prefix}}) {
22620: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22621: my ($newvalue,$notinuse);
1.147 raeburn 22622: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22623: if (ref($defaultshash{'usersessions'}{$prefix})) {
22624: if ($type eq 'version') {
22625: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 22626: } else {
22627: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22628: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
22629: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
22630: }
22631: } else {
22632: $notinuse = 1;
1.147 raeburn 22633: }
1.145 raeburn 22634: }
22635: }
22636: }
1.147 raeburn 22637: if ($newvalue eq '') {
22638: if ($type eq 'version') {
22639: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 22640: } elsif ($notinuse) {
22641: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 22642: } else {
22643: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
22644: }
1.145 raeburn 22645: } else {
1.147 raeburn 22646: if ($type eq 'version') {
1.344 raeburn 22647: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 22648: }
22649: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 22650: }
1.137 raeburn 22651: }
22652: }
22653: }
1.147 raeburn 22654: $resulttext .= '</ul>';
1.137 raeburn 22655: }
22656: }
1.261 raeburn 22657: if ($changes{'offloadnow'}) {
22658: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22659: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371 raeburn 22660: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261 raeburn 22661: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
22662: $resulttext .= '<li>'.$lonhost.'</li>';
22663: }
22664: $resulttext .= '</ul>';
22665: } else {
1.371 raeburn 22666: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
22667: }
22668: } else {
22669: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
22670: }
22671: }
22672: if ($changes{'offloadoth'}) {
22673: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22674: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
22675: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
22676: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
22677: $resulttext .= '<li>'.$lonhost.'</li>';
22678: }
22679: $resulttext .= '</ul>';
22680: } else {
22681: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261 raeburn 22682: }
22683: } else {
1.371 raeburn 22684: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261 raeburn 22685: }
22686: }
1.147 raeburn 22687: $resulttext .= '</ul>';
22688: } else {
22689: $resulttext = $nochgmsg;
1.137 raeburn 22690: }
22691: } else {
22692: $resulttext = '<span class="LC_error">'.
22693: &mt('An error occurred: [_1]',$putresult).'</span>';
22694: }
22695: } else {
1.147 raeburn 22696: $resulttext = $nochgmsg;
1.137 raeburn 22697: }
22698: return $resulttext;
22699: }
22700:
1.275 raeburn 22701: sub modify_ssl {
22702: my ($dom,$lastactref,%domconfig) = @_;
22703: my (%by_ip,%by_location,@intdoms,@instdoms);
22704: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
22705: my @locations = sort(keys(%by_location));
22706: my %servers = &Apache::lonnet::internet_dom_servers($dom);
22707: my (%defaultshash,%changes);
22708: my $action = 'ssl';
1.293 raeburn 22709: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 22710: foreach my $prefix (@prefixes) {
22711: $defaultshash{$action}{$prefix} = {};
22712: }
22713: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22714: my $resulttext;
22715: my %iphost = &Apache::lonnet::get_iphost();
22716: my @reptypes = ('certreq','nocertreq');
22717: my @connecttypes = ('dom','intdom','other');
22718: my %types = (
1.293 raeburn 22719: connto => \@connecttypes,
22720: connfrom => \@connecttypes,
22721: replication => \@reptypes,
1.275 raeburn 22722: );
22723: foreach my $prefix (sort(keys(%types))) {
22724: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 22725: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22726: my $value = 'yes';
22727: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
22728: $value = $env{'form.'.$prefix.'_'.$type};
22729: }
1.335 raeburn 22730: if (ref($domconfig{$action}) eq 'HASH') {
22731: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22732: if ($domconfig{$action}{$prefix}{$type} ne '') {
22733: if ($value ne $domconfig{$action}{$prefix}{$type}) {
22734: $changes{$prefix}{$type} = 1;
22735: }
22736: $defaultshash{$action}{$prefix}{$type} = $value;
22737: } else {
22738: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 22739: $changes{$prefix}{$type} = 1;
22740: }
22741: } else {
22742: $defaultshash{$action}{$prefix}{$type} = $value;
22743: $changes{$prefix}{$type} = 1;
22744: }
22745: } else {
22746: $defaultshash{$action}{$prefix}{$type} = $value;
22747: $changes{$prefix}{$type} = 1;
22748: }
22749: if (($type eq 'dom') && (keys(%servers) == 1)) {
22750: delete($changes{$prefix}{$type});
22751: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
22752: delete($changes{$prefix}{$type});
22753: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
22754: delete($changes{$prefix}{$type});
22755: }
22756: } elsif ($prefix eq 'replication') {
22757: if (@locations > 0) {
22758: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22759: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22760: my @okvals;
22761: foreach my $val (@vals) {
22762: if ($val =~ /:/) {
22763: my @items = split(/:/,$val);
22764: foreach my $item (@items) {
22765: if (ref($by_location{$item}) eq 'ARRAY') {
22766: push(@okvals,$item);
22767: }
22768: }
22769: } else {
22770: if (ref($by_location{$val}) eq 'ARRAY') {
22771: push(@okvals,$val);
22772: }
22773: }
22774: }
22775: @okvals = sort(@okvals);
22776: if (ref($domconfig{$action}) eq 'HASH') {
22777: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22778: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
22779: if ($inuse == 0) {
22780: $changes{$prefix}{$type} = 1;
22781: } else {
22782: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22783: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
22784: if (@changed > 0) {
22785: $changes{$prefix}{$type} = 1;
22786: }
22787: }
22788: } else {
22789: if ($inuse == 1) {
22790: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22791: $changes{$prefix}{$type} = 1;
22792: }
22793: }
22794: } else {
22795: if ($inuse == 1) {
22796: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22797: $changes{$prefix}{$type} = 1;
22798: }
22799: }
22800: } else {
22801: if ($inuse == 1) {
22802: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22803: $changes{$prefix}{$type} = 1;
22804: }
22805: }
22806: }
22807: }
22808: }
22809: }
1.336 raeburn 22810: if (keys(%changes)) {
22811: foreach my $prefix (keys(%changes)) {
22812: if (ref($changes{$prefix}) eq 'HASH') {
22813: if (scalar(keys(%{$changes{$prefix}})) == 0) {
22814: delete($changes{$prefix});
22815: }
22816: } else {
22817: delete($changes{$prefix});
22818: }
22819: }
22820: }
1.275 raeburn 22821: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
22822: if (keys(%changes) > 0) {
22823: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22824: $dom);
22825: if ($putresult eq 'ok') {
22826: if (ref($defaultshash{$action}) eq 'HASH') {
22827: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
22828: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
22829: }
1.293 raeburn 22830: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 22831: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 22832: }
22833: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 22834: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 22835: }
22836: }
22837: my $cachetime = 24*60*60;
22838: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22839: if (ref($lastactref) eq 'HASH') {
22840: $lastactref->{'domdefaults'} = 1;
22841: }
22842: if (keys(%changes) > 0) {
22843: my %titles = &ssl_titles();
22844: $resulttext = &mt('Changes made:').'<ul>';
22845: foreach my $prefix (@prefixes) {
22846: if (ref($changes{$prefix}) eq 'HASH') {
22847: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
22848: foreach my $type (@{$types{$prefix}}) {
22849: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22850: my ($newvalue,$notinuse);
1.275 raeburn 22851: if (ref($defaultshash{$action}) eq 'HASH') {
22852: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 22853: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22854: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 22855: } else {
22856: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
22857: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
22858: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
22859: }
22860: } else {
22861: $notinuse = 1;
1.275 raeburn 22862: }
22863: }
22864: }
1.344 raeburn 22865: if ($notinuse) {
22866: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
22867: } elsif ($newvalue eq '') {
1.275 raeburn 22868: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
22869: } else {
22870: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
22871: }
22872: }
22873: }
22874: }
22875: $resulttext .= '</ul>';
22876: }
22877: }
22878: } else {
22879: $resulttext = $nochgmsg;
22880: }
22881: } else {
22882: $resulttext = '<span class="LC_error">'.
22883: &mt('An error occurred: [_1]',$putresult).'</span>';
22884: }
22885: } else {
22886: $resulttext = $nochgmsg;
22887: }
22888: return $resulttext;
22889: }
22890:
1.279 raeburn 22891: sub modify_trust {
22892: my ($dom,$lastactref,%domconfig) = @_;
22893: my (%by_ip,%by_location,@intdoms,@instdoms);
22894: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
22895: my @locations = sort(keys(%by_location));
22896: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
22897: my @types = ('exc','inc');
22898: my (%defaultshash,%changes);
22899: foreach my $prefix (@prefixes) {
22900: $defaultshash{'trust'}{$prefix} = {};
22901: }
22902: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22903: my $resulttext;
22904: foreach my $prefix (@prefixes) {
22905: foreach my $type (@types) {
22906: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22907: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22908: my @okvals;
22909: foreach my $val (@vals) {
22910: if ($val =~ /:/) {
22911: my @items = split(/:/,$val);
22912: foreach my $item (@items) {
22913: if (ref($by_location{$item}) eq 'ARRAY') {
22914: push(@okvals,$item);
22915: }
22916: }
22917: } else {
22918: if (ref($by_location{$val}) eq 'ARRAY') {
22919: push(@okvals,$val);
22920: }
22921: }
22922: }
22923: @okvals = sort(@okvals);
22924: if (ref($domconfig{'trust'}) eq 'HASH') {
22925: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
22926: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
22927: if ($inuse == 0) {
22928: $changes{$prefix}{$type} = 1;
22929: } else {
22930: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22931: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
22932: if (@changed > 0) {
22933: $changes{$prefix}{$type} = 1;
22934: }
22935: }
22936: } else {
22937: if ($inuse == 1) {
22938: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22939: $changes{$prefix}{$type} = 1;
22940: }
22941: }
22942: } else {
22943: if ($inuse == 1) {
22944: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22945: $changes{$prefix}{$type} = 1;
22946: }
22947: }
22948: } else {
22949: if ($inuse == 1) {
22950: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22951: $changes{$prefix}{$type} = 1;
22952: }
22953: }
22954: }
22955: }
22956: my $nochgmsg = &mt('No changes made to trust settings.');
22957: if (keys(%changes) > 0) {
22958: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22959: $dom);
22960: if ($putresult eq 'ok') {
22961: if (ref($defaultshash{'trust'}) eq 'HASH') {
22962: foreach my $prefix (@prefixes) {
22963: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
22964: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
22965: }
22966: }
22967: }
22968: my $cachetime = 24*60*60;
22969: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.410 raeburn 22970: &Apache::lonnet::do_cache_new('trust',$dom,$defaultshash{'trust'},3600);
1.279 raeburn 22971: if (ref($lastactref) eq 'HASH') {
22972: $lastactref->{'domdefaults'} = 1;
1.410 raeburn 22973: $lastactref->{'trust'} = 1;
1.279 raeburn 22974: }
22975: if (keys(%changes) > 0) {
22976: my %lt = &trust_titles();
22977: $resulttext = &mt('Changes made:').'<ul>';
22978: foreach my $prefix (@prefixes) {
22979: if (ref($changes{$prefix}) eq 'HASH') {
22980: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
22981: foreach my $type (@types) {
22982: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22983: my ($newvalue,$notinuse);
1.279 raeburn 22984: if (ref($defaultshash{'trust'}) eq 'HASH') {
22985: if (ref($defaultshash{'trust'}{$prefix})) {
22986: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
22987: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
22988: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
22989: }
1.344 raeburn 22990: } else {
22991: $notinuse = 1;
1.279 raeburn 22992: }
22993: }
22994: }
1.344 raeburn 22995: if ($notinuse) {
22996: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
22997: } elsif ($newvalue eq '') {
1.279 raeburn 22998: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
22999: } else {
23000: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
23001: }
23002: }
23003: }
23004: $resulttext .= '</ul>';
23005: }
23006: }
23007: $resulttext .= '</ul>';
23008: } else {
23009: $resulttext = $nochgmsg;
23010: }
23011: } else {
23012: $resulttext = '<span class="LC_error">'.
23013: &mt('An error occurred: [_1]',$putresult).'</span>';
23014: }
23015: } else {
23016: $resulttext = $nochgmsg;
23017: }
23018: return $resulttext;
23019: }
23020:
1.150 raeburn 23021: sub modify_loadbalancing {
23022: my ($dom,%domconfig) = @_;
23023: my $primary_id = &Apache::lonnet::domain($dom,'primary');
23024: my $intdom = &Apache::lonnet::internet_dom($primary_id);
23025: my ($othertitle,$usertypes,$types) =
23026: &Apache::loncommon::sorted_inst_types($dom);
23027: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 23028: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 23029: my @sparestypes = ('primary','default');
23030: my %typetitles = &sparestype_titles();
23031: my $resulttext;
1.342 raeburn 23032: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 23033: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
23034: %existing = %{$domconfig{'loadbalancing'}};
23035: }
23036: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 23037: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 23038: my ($saveloadbalancing,%defaultshash,%changes);
23039: my ($alltypes,$othertypes,$titles) =
23040: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
23041: my %ruletitles = &offloadtype_text();
23042: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
23043: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
23044: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
23045: if ($balancer eq '') {
23046: next;
23047: }
1.210 raeburn 23048: if (!exists($servers{$balancer})) {
1.171 raeburn 23049: if (exists($currbalancer{$balancer})) {
23050: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 23051: }
1.171 raeburn 23052: next;
23053: }
23054: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
23055: push(@{$changes{'delete'}},$balancer);
23056: next;
23057: }
23058: if (!exists($currbalancer{$balancer})) {
23059: push(@{$changes{'add'}},$balancer);
23060: }
23061: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
23062: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
23063: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
23064: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
23065: $saveloadbalancing = 1;
23066: }
23067: foreach my $sparetype (@sparestypes) {
23068: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
23069: my @offloadto;
23070: foreach my $target (@targets) {
23071: if (($servers{$target}) && ($target ne $balancer)) {
23072: if ($sparetype eq 'default') {
23073: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
23074: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 23075: }
23076: }
1.171 raeburn 23077: unless(grep(/^\Q$target\E$/,@offloadto)) {
23078: push(@offloadto,$target);
23079: }
1.150 raeburn 23080: }
23081: }
1.284 raeburn 23082: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
23083: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
23084: push(@offloadto,$balancer);
23085: }
23086: }
23087: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 23088: }
1.342 raeburn 23089: if ($env{'form.loadbalancing_cookie_'.$i}) {
23090: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
1.425 raeburn 23091: if (exists($currbalancer{$balancer})) {
1.342 raeburn 23092: unless ($currcookies{$balancer}) {
23093: $changes{'curr'}{$balancer}{'cookie'} = 1;
23094: }
23095: }
23096: } elsif (exists($currbalancer{$balancer})) {
23097: if ($currcookies{$balancer}) {
23098: $changes{'curr'}{$balancer}{'cookie'} = 1;
23099: }
23100: }
1.171 raeburn 23101: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 23102: foreach my $sparetype (@sparestypes) {
1.171 raeburn 23103: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
23104: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 23105: if (@targetdiffs > 0) {
1.171 raeburn 23106: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 23107: }
1.171 raeburn 23108: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23109: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23110: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 23111: }
23112: }
23113: }
23114: } else {
1.171 raeburn 23115: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 23116: foreach my $sparetype (@sparestypes) {
1.171 raeburn 23117: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23118: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23119: $changes{'curr'}{$balancer}{'targets'} = 1;
23120: }
1.150 raeburn 23121: }
23122: }
1.210 raeburn 23123: }
1.150 raeburn 23124: }
23125: my $ishomedom;
1.171 raeburn 23126: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
23127: $ishomedom = 1;
1.150 raeburn 23128: }
23129: if (ref($alltypes) eq 'ARRAY') {
23130: foreach my $type (@{$alltypes}) {
23131: my $rule;
1.210 raeburn 23132: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 23133: (!$ishomedom)) {
1.171 raeburn 23134: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
23135: }
23136: if ($rule eq 'specific') {
1.255 raeburn 23137: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 23138: if (exists($servers{$specifiedhost})) {
1.255 raeburn 23139: $rule = $specifiedhost;
23140: }
1.150 raeburn 23141: }
1.171 raeburn 23142: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
23143: if (ref($currrules{$balancer}) eq 'HASH') {
23144: if ($rule ne $currrules{$balancer}{$type}) {
23145: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 23146: }
23147: } elsif ($rule ne '') {
1.171 raeburn 23148: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 23149: }
23150: }
23151: }
1.171 raeburn 23152: }
23153: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
23154: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
23155: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
23156: $defaultshash{'loadbalancing'} = {};
23157: }
23158: my $putresult = &Apache::lonnet::put_dom('configuration',
23159: \%defaultshash,$dom);
23160: if ($putresult eq 'ok') {
23161: if (keys(%changes) > 0) {
1.252 raeburn 23162: my %toupdate;
1.171 raeburn 23163: if (ref($changes{'delete'}) eq 'ARRAY') {
23164: foreach my $balancer (sort(@{$changes{'delete'}})) {
23165: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 23166: $toupdate{$balancer} = 1;
1.150 raeburn 23167: }
1.171 raeburn 23168: }
23169: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 23170: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 23171: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 23172: $toupdate{$balancer} = 1;
1.171 raeburn 23173: }
23174: }
23175: if (ref($changes{'curr'}) eq 'HASH') {
23176: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 23177: $toupdate{$balancer} = 1;
1.171 raeburn 23178: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
23179: if ($changes{'curr'}{$balancer}{'targets'}) {
23180: my %offloadstr;
23181: foreach my $sparetype (@sparestypes) {
23182: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23183: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23184: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
23185: }
23186: }
1.150 raeburn 23187: }
1.171 raeburn 23188: if (keys(%offloadstr) == 0) {
23189: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 23190: } else {
1.171 raeburn 23191: my $showoffload;
23192: foreach my $sparetype (@sparestypes) {
23193: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
23194: if (defined($offloadstr{$sparetype})) {
23195: $showoffload .= $offloadstr{$sparetype};
23196: } else {
23197: $showoffload .= &mt('None');
23198: }
23199: $showoffload .= (' 'x3);
23200: }
23201: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 23202: }
23203: }
23204: }
1.171 raeburn 23205: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
23206: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
23207: foreach my $type (@{$alltypes}) {
23208: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
23209: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23210: my $balancetext;
23211: if ($rule eq '') {
23212: $balancetext = $ruletitles{'default'};
1.209 raeburn 23213: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 23214: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 23215: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 23216: foreach my $sparetype (@sparestypes) {
23217: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23218: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
23219: }
23220: }
1.253 raeburn 23221: foreach my $item (@{$alltypes}) {
23222: next if ($item =~ /^_LC_ipchange/);
23223: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
23224: if ($hasrule eq 'homeserver') {
23225: map { $toupdate{$_} = 1; } (keys(%libraryservers));
23226: } else {
23227: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
23228: if ($servers{$hasrule}) {
23229: $toupdate{$hasrule} = 1;
23230: }
23231: }
23232: }
23233: }
1.254 raeburn 23234: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
23235: $balancetext = $ruletitles{$rule};
23236: } else {
23237: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23238: $balancetext = $ruletitles{'particular'}.' '.$receiver;
23239: if ($receiver) {
23240: $toupdate{$receiver};
23241: }
23242: }
23243: } else {
23244: $balancetext = $ruletitles{$rule};
1.252 raeburn 23245: }
1.171 raeburn 23246: } else {
23247: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
23248: }
1.210 raeburn 23249: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 23250: }
23251: }
23252: }
23253: }
1.342 raeburn 23254: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.389 raeburn 23255: if ($currcookies{$balancer}) {
23256: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
23257: $balancer).'</li>';
23258: } else {
23259: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
23260: $balancer).'</li>';
23261: }
1.342 raeburn 23262: }
1.375 raeburn 23263: }
23264: }
23265: if (keys(%toupdate)) {
23266: my %thismachine;
23267: my $updatedhere;
23268: my $cachetime = 60*60*24;
23269: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
23270: foreach my $lonhost (keys(%toupdate)) {
23271: if ($thismachine{$lonhost}) {
23272: unless ($updatedhere) {
23273: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
23274: $defaultshash{'loadbalancing'},
23275: $cachetime);
23276: $updatedhere = 1;
1.252 raeburn 23277: }
1.375 raeburn 23278: } else {
23279: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
23280: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.252 raeburn 23281: }
1.150 raeburn 23282: }
1.171 raeburn 23283: }
23284: if ($resulttext ne '') {
23285: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 23286: } else {
23287: $resulttext = $nochgmsg;
23288: }
23289: } else {
1.171 raeburn 23290: $resulttext = $nochgmsg;
1.150 raeburn 23291: }
23292: } else {
1.171 raeburn 23293: $resulttext = '<span class="LC_error">'.
23294: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 23295: }
23296: } else {
1.171 raeburn 23297: $resulttext = $nochgmsg;
1.150 raeburn 23298: }
23299: return $resulttext;
23300: }
23301:
1.48 raeburn 23302: sub recurse_check {
23303: my ($chkcats,$categories,$depth,$name) = @_;
23304: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
23305: my $chg = 0;
23306: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
23307: my $category = $chkcats->[$depth]{$name}[$j];
23308: my $item;
23309: if ($category eq '') {
23310: $chg ++;
23311: } else {
23312: my $deeper = $depth + 1;
23313: $item = &escape($category).':'.&escape($name).':'.$depth;
23314: if ($chg) {
23315: $categories->{$item} -= $chg;
23316: }
23317: &recurse_check($chkcats,$categories,$deeper,$category);
23318: $deeper --;
23319: }
23320: }
23321: }
23322: return;
23323: }
23324:
23325: sub recurse_cat_deletes {
23326: my ($item,$coursecategories,$deletions) = @_;
23327: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
23328: my $subdepth = $depth + 1;
23329: if (ref($coursecategories) eq 'HASH') {
23330: foreach my $subitem (keys(%{$coursecategories})) {
23331: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
23332: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
23333: delete($coursecategories->{$subitem});
23334: $deletions->{$subitem} = 1;
23335: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 23336: }
1.48 raeburn 23337: }
23338: }
23339: return;
23340: }
23341:
1.125 raeburn 23342: sub active_dc_picker {
1.191 raeburn 23343: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 23344: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 23345: my @domcoord = keys(%domcoords);
23346: if (keys(%currhash)) {
23347: foreach my $dc (keys(%currhash)) {
23348: unless (exists($domcoords{$dc})) {
23349: push(@domcoord,$dc);
23350: }
23351: }
23352: }
23353: @domcoord = sort(@domcoord);
1.210 raeburn 23354: my $numdcs = scalar(@domcoord);
1.191 raeburn 23355: my $rows = 0;
23356: my $table;
1.125 raeburn 23357: if ($numdcs > 1) {
1.191 raeburn 23358: $table = '<table>';
23359: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 23360: my $rem = $i%($numinrow);
23361: if ($rem == 0) {
23362: if ($i > 0) {
1.191 raeburn 23363: $table .= '</tr>';
1.125 raeburn 23364: }
1.191 raeburn 23365: $table .= '<tr>';
23366: $rows ++;
1.125 raeburn 23367: }
1.191 raeburn 23368: my $check = '';
23369: if ($inputtype eq 'radio') {
23370: if (keys(%currhash) == 0) {
23371: if (!$i) {
23372: $check = ' checked="checked"';
23373: }
23374: } elsif (exists($currhash{$domcoord[$i]})) {
23375: $check = ' checked="checked"';
23376: }
23377: } else {
23378: if (exists($currhash{$domcoord[$i]})) {
23379: $check = ' checked="checked"';
1.125 raeburn 23380: }
23381: }
1.191 raeburn 23382: if ($i == @domcoord - 1) {
1.125 raeburn 23383: my $colsleft = $numinrow - $rem;
23384: if ($colsleft > 1) {
1.191 raeburn 23385: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 23386: } else {
1.191 raeburn 23387: $table .= '<td class="LC_left_item">';
1.125 raeburn 23388: }
23389: } else {
1.191 raeburn 23390: $table .= '<td class="LC_left_item">';
23391: }
23392: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
23393: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
23394: $table .= '<span class="LC_nobreak"><label>'.
23395: '<input type="'.$inputtype.'" name="'.$name.'"'.
23396: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
23397: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 23398: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 23399: }
1.219 raeburn 23400: $table .= '</label></span></td>';
1.191 raeburn 23401: }
23402: $table .= '</tr></table>';
23403: } elsif ($numdcs == 1) {
1.219 raeburn 23404: my ($dcname,$dcdom) = split(':',$domcoord[0]);
23405: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 23406: if ($inputtype eq 'radio') {
1.247 raeburn 23407: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 23408: if ($user ne $dcname.':'.$dcdom) {
23409: $table .= ' ('.$dcname.':'.$dcdom.')';
23410: }
1.191 raeburn 23411: } else {
23412: my $check;
23413: if (exists($currhash{$domcoord[0]})) {
23414: $check = ' checked="checked"';
1.125 raeburn 23415: }
1.247 raeburn 23416: $table = '<span class="LC_nobreak"><label>'.
23417: '<input type="checkbox" name="'.$name.'" '.
23418: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 23419: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 23420: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 23421: }
1.220 raeburn 23422: $table .= '</label></span>';
1.191 raeburn 23423: $rows ++;
1.125 raeburn 23424: }
23425: }
1.191 raeburn 23426: return ($numdcs,$table,$rows);
1.125 raeburn 23427: }
23428:
1.137 raeburn 23429: sub usersession_titles {
23430: return &Apache::lonlocal::texthash(
23431: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
23432: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 23433: spares => 'Servers offloaded to, when busy',
1.137 raeburn 23434: version => 'LON-CAPA version requirement',
1.138 raeburn 23435: excludedomain => 'Allow all, but exclude specific domains',
23436: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 23437: primary => 'Primary (checked first)',
1.154 raeburn 23438: default => 'Default',
1.137 raeburn 23439: );
23440: }
23441:
1.152 raeburn 23442: sub id_for_thisdom {
23443: my (%servers) = @_;
23444: my %altids;
23445: foreach my $server (keys(%servers)) {
23446: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
23447: if ($serverhome ne $server) {
23448: $altids{$serverhome} = $server;
23449: }
23450: }
23451: return %altids;
23452: }
23453:
1.150 raeburn 23454: sub count_servers {
23455: my ($currbalancer,%servers) = @_;
23456: my (@spares,$numspares);
23457: foreach my $lonhost (sort(keys(%servers))) {
23458: next if ($currbalancer eq $lonhost);
23459: push(@spares,$lonhost);
23460: }
23461: if ($currbalancer) {
23462: $numspares = scalar(@spares);
23463: } else {
23464: $numspares = scalar(@spares) - 1;
23465: }
23466: return ($numspares,@spares);
23467: }
23468:
23469: sub lonbalance_targets_js {
1.171 raeburn 23470: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 23471: my $select = &mt('Select');
23472: my ($alltargets,$allishome,$allinsttypes,@alltypes);
23473: if (ref($servers) eq 'HASH') {
23474: $alltargets = join("','",sort(keys(%{$servers})));
23475: my @homedoms;
23476: foreach my $server (sort(keys(%{$servers}))) {
23477: if (&Apache::lonnet::host_domain($server) eq $dom) {
23478: push(@homedoms,'1');
23479: } else {
23480: push(@homedoms,'0');
23481: }
23482: }
23483: $allishome = join("','",@homedoms);
23484: }
23485: if (ref($types) eq 'ARRAY') {
23486: if (@{$types} > 0) {
23487: @alltypes = @{$types};
23488: }
23489: }
23490: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
23491: $allinsttypes = join("','",@alltypes);
1.342 raeburn 23492: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 23493: if (ref($settings) eq 'HASH') {
23494: %existing = %{$settings};
23495: }
23496: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 23497: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 23498: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 23499: return <<"END";
23500:
23501: <script type="text/javascript">
23502: // <![CDATA[
23503:
1.171 raeburn 23504: currBalancers = new Array('$balancers');
23505:
23506: function toggleTargets(balnum) {
23507: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23508: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
23509: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
23510: var prevbalancer = prevhostitem.value;
23511: var baltotal = document.getElementById('loadbalancing_total').value;
23512: prevhostitem.value = balancer;
23513: if (prevbalancer != '') {
23514: var prevIdx = currBalancers.indexOf(prevbalancer);
23515: if (prevIdx != -1) {
23516: currBalancers.splice(prevIdx,1);
23517: }
23518: }
1.150 raeburn 23519: if (balancer == '') {
1.171 raeburn 23520: hideSpares(balnum);
1.150 raeburn 23521: } else {
1.171 raeburn 23522: var currIdx = currBalancers.indexOf(balancer);
23523: if (currIdx == -1) {
23524: currBalancers.push(balancer);
23525: }
1.150 raeburn 23526: var homedoms = new Array('$allishome');
1.171 raeburn 23527: var ishomedom = homedoms[lonhostitem.selectedIndex];
23528: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 23529: }
1.171 raeburn 23530: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 23531: return;
23532: }
23533:
1.171 raeburn 23534: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 23535: var alltargets = new Array('$alltargets');
23536: var insttypes = new Array('$allinsttypes');
1.151 raeburn 23537: var offloadtypes = new Array('primary','default');
23538:
1.171 raeburn 23539: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
23540: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 23541:
1.151 raeburn 23542: for (var i=0; i<offloadtypes.length; i++) {
23543: var count = 0;
23544: for (var j=0; j<alltargets.length; j++) {
23545: if (alltargets[j] != balancer) {
1.171 raeburn 23546: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
23547: item.value = alltargets[j];
23548: item.style.textAlign='left';
23549: item.style.textFace='normal';
23550: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
23551: if (currBalancers.indexOf(alltargets[j]) == -1) {
23552: item.disabled = '';
23553: } else {
23554: item.disabled = 'disabled';
23555: item.checked = false;
23556: }
1.151 raeburn 23557: count ++;
23558: }
1.150 raeburn 23559: }
23560: }
1.151 raeburn 23561: for (var k=0; k<insttypes.length; k++) {
23562: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 23563: if (ishomedom == 1) {
1.171 raeburn 23564: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23565: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23566: } else {
1.171 raeburn 23567: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23568: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 23569: }
23570: } else {
1.171 raeburn 23571: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23572: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23573: }
1.151 raeburn 23574: if ((insttypes[k] != '_LC_external') &&
23575: ((insttypes[k] != '_LC_internetdom') ||
23576: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 23577: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
23578: item.options.length = 0;
23579: item.options[0] = new Option("","",true,true);
1.210 raeburn 23580: var idx = 0;
1.151 raeburn 23581: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 23582: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
23583: idx ++;
23584: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 23585: }
23586: }
23587: }
23588: }
23589: return;
23590: }
23591:
1.171 raeburn 23592: function hideSpares(balnum) {
1.150 raeburn 23593: var alltargets = new Array('$alltargets');
23594: var insttypes = new Array('$allinsttypes');
23595: var offloadtypes = new Array('primary','default');
23596:
1.171 raeburn 23597: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
23598: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 23599:
23600: var total = alltargets.length - 1;
23601: for (var i=0; i<offloadtypes; i++) {
23602: for (var j=0; j<total; j++) {
1.171 raeburn 23603: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
23604: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
23605: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 23606: }
1.150 raeburn 23607: }
23608: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 23609: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23610: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 23611: if (insttypes[k] != '_LC_external') {
1.171 raeburn 23612: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
23613: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 23614: }
23615: }
23616: return;
23617: }
23618:
1.171 raeburn 23619: function checkOffloads(item,balnum,type) {
1.150 raeburn 23620: var alltargets = new Array('$alltargets');
23621: var offloadtypes = new Array('primary','default');
23622: if (item.checked) {
23623: var total = alltargets.length - 1;
23624: var other;
23625: if (type == offloadtypes[0]) {
1.151 raeburn 23626: other = offloadtypes[1];
1.150 raeburn 23627: } else {
1.151 raeburn 23628: other = offloadtypes[0];
1.150 raeburn 23629: }
23630: for (var i=0; i<total; i++) {
1.171 raeburn 23631: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 23632: if (server == item.value) {
1.171 raeburn 23633: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
23634: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 23635: }
23636: }
23637: }
23638: }
23639: return;
23640: }
23641:
1.171 raeburn 23642: function singleServerToggle(balnum,type) {
23643: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 23644: if (offloadtoSelIdx == 0) {
1.171 raeburn 23645: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
23646: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23647:
23648: } else {
1.171 raeburn 23649: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
23650: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 23651: }
23652: return;
23653: }
23654:
1.171 raeburn 23655: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 23656: if (type == '_LC_external') {
1.171 raeburn 23657: return;
1.150 raeburn 23658: }
1.171 raeburn 23659: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 23660: for (var i=0; i<typesRules.length; i++) {
23661: if (formname.elements[typesRules[i]].checked) {
23662: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 23663: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
23664: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23665: } else {
1.171 raeburn 23666: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
23667: }
23668: }
23669: }
23670: return;
23671: }
23672:
23673: function balancerDeleteChange(balnum) {
23674: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23675: var baltotal = document.getElementById('loadbalancing_total').value;
23676: var addtarget;
23677: var removetarget;
23678: var action = 'delete';
23679: if (document.getElementById('loadbalancing_delete_'+balnum)) {
23680: var lonhost = hostitem.value;
23681: var currIdx = currBalancers.indexOf(lonhost);
23682: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
23683: if (currIdx != -1) {
23684: currBalancers.splice(currIdx,1);
23685: }
23686: addtarget = lonhost;
23687: } else {
23688: if (currIdx == -1) {
23689: currBalancers.push(lonhost);
23690: }
23691: removetarget = lonhost;
23692: action = 'undelete';
23693: }
23694: balancerChange(balnum,baltotal,action,addtarget,removetarget);
23695: }
23696: return;
23697: }
23698:
23699: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
23700: if (baltotal > 1) {
23701: var offloadtypes = new Array('primary','default');
23702: var alltargets = new Array('$alltargets');
23703: var insttypes = new Array('$allinsttypes');
23704: for (var i=0; i<baltotal; i++) {
23705: if (i != balnum) {
23706: for (var j=0; j<offloadtypes.length; j++) {
23707: var total = alltargets.length - 1;
23708: for (var k=0; k<total; k++) {
23709: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
23710: var server = serveritem.value;
23711: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23712: if (server == addtarget) {
23713: serveritem.disabled = '';
23714: }
23715: }
23716: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23717: if (server == removetarget) {
23718: serveritem.disabled = 'disabled';
23719: serveritem.checked = false;
23720: }
23721: }
23722: }
23723: }
23724: for (var j=0; j<insttypes.length; j++) {
23725: if (insttypes[j] != '_LC_external') {
23726: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
23727: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
23728: var currSel = singleserver.selectedIndex;
23729: var currVal = singleserver.options[currSel].value;
23730: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23731: var numoptions = singleserver.options.length;
23732: var needsnew = 1;
23733: for (var k=0; k<numoptions; k++) {
23734: if (singleserver.options[k] == addtarget) {
23735: needsnew = 0;
23736: break;
23737: }
23738: }
23739: if (needsnew == 1) {
23740: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
23741: }
23742: }
23743: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23744: singleserver.options.length = 0;
23745: if ((currVal) && (currVal != removetarget)) {
23746: singleserver.options[0] = new Option("","",false,false);
23747: } else {
23748: singleserver.options[0] = new Option("","",true,true);
23749: }
23750: var idx = 0;
23751: for (var m=0; m<alltargets.length; m++) {
23752: if (currBalancers.indexOf(alltargets[m]) == -1) {
23753: idx ++;
23754: if (currVal == alltargets[m]) {
23755: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
23756: } else {
23757: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
23758: }
23759: }
23760: }
23761: }
23762: }
23763: }
23764: }
1.150 raeburn 23765: }
23766: }
23767: }
23768: return;
23769: }
23770:
1.152 raeburn 23771: // ]]>
23772: </script>
23773:
23774: END
23775: }
23776:
23777: sub new_spares_js {
23778: my @sparestypes = ('primary','default');
23779: my $types = join("','",@sparestypes);
23780: my $select = &mt('Select');
23781: return <<"END";
23782:
23783: <script type="text/javascript">
23784: // <![CDATA[
23785:
23786: function updateNewSpares(formname,lonhost) {
23787: var types = new Array('$types');
23788: var include = new Array();
23789: var exclude = new Array();
23790: for (var i=0; i<types.length; i++) {
23791: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
23792: for (var j=0; j<spareboxes.length; j++) {
23793: if (formname.elements[spareboxes[j]].checked) {
23794: exclude.push(formname.elements[spareboxes[j]].value);
23795: } else {
23796: include.push(formname.elements[spareboxes[j]].value);
23797: }
23798: }
23799: }
23800: for (var i=0; i<types.length; i++) {
23801: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
23802: var selIdx = newSpare.selectedIndex;
23803: var currnew = newSpare.options[selIdx].value;
23804: var okSpares = new Array();
23805: for (var j=0; j<newSpare.options.length; j++) {
23806: var possible = newSpare.options[j].value;
23807: if (possible != '') {
23808: if (exclude.indexOf(possible) == -1) {
23809: okSpares.push(possible);
23810: } else {
23811: if (currnew == possible) {
23812: selIdx = 0;
23813: }
23814: }
23815: }
23816: }
23817: for (var k=0; k<include.length; k++) {
23818: if (okSpares.indexOf(include[k]) == -1) {
23819: okSpares.push(include[k]);
23820: }
23821: }
23822: okSpares.sort();
23823: newSpare.options.length = 0;
23824: if (selIdx == 0) {
23825: newSpare.options[0] = new Option("$select","",true,true);
23826: } else {
23827: newSpare.options[0] = new Option("$select","",false,false);
23828: }
23829: for (var m=0; m<okSpares.length; m++) {
23830: var idx = m+1;
23831: var selThis = 0;
23832: if (selIdx != 0) {
23833: if (okSpares[m] == currnew) {
23834: selThis = 1;
23835: }
23836: }
23837: if (selThis == 1) {
23838: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
23839: } else {
23840: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
23841: }
23842: }
23843: }
23844: return;
23845: }
23846:
23847: function checkNewSpares(lonhost,type) {
23848: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
23849: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.372 raeburn 23850: if (chosen != '') {
1.152 raeburn 23851: var othertype;
23852: var othernewSpare;
23853: if (type == 'primary') {
23854: othernewSpare = document.getElementById('newspare_default_'+lonhost);
23855: }
23856: if (type == 'default') {
23857: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
23858: }
23859: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
23860: othernewSpare.selectedIndex = 0;
23861: }
23862: }
23863: return;
23864: }
23865:
23866: // ]]>
23867: </script>
23868:
23869: END
23870:
23871: }
23872:
23873: sub common_domprefs_js {
23874: return <<"END";
23875:
23876: <script type="text/javascript">
23877: // <![CDATA[
23878:
1.150 raeburn 23879: function getIndicesByName(formname,item) {
1.152 raeburn 23880: var group = new Array();
1.150 raeburn 23881: for (var i=0;i<formname.elements.length;i++) {
23882: if (formname.elements[i].name == item) {
1.152 raeburn 23883: group.push(formname.elements[i].id);
1.150 raeburn 23884: }
23885: }
1.152 raeburn 23886: return group;
1.150 raeburn 23887: }
23888:
23889: // ]]>
23890: </script>
23891:
23892: END
1.152 raeburn 23893:
1.150 raeburn 23894: }
23895:
1.165 raeburn 23896: sub recaptcha_js {
23897: my %lt = &captcha_phrases();
23898: return <<"END";
23899:
23900: <script type="text/javascript">
23901: // <![CDATA[
23902:
23903: function updateCaptcha(caller,context) {
23904: var privitem;
23905: var pubitem;
23906: var privtext;
23907: var pubtext;
1.269 raeburn 23908: var versionitem;
23909: var versiontext;
1.165 raeburn 23910: if (document.getElementById(context+'_recaptchapub')) {
23911: pubitem = document.getElementById(context+'_recaptchapub');
23912: } else {
23913: return;
23914: }
23915: if (document.getElementById(context+'_recaptchapriv')) {
23916: privitem = document.getElementById(context+'_recaptchapriv');
23917: } else {
23918: return;
23919: }
23920: if (document.getElementById(context+'_recaptchapubtxt')) {
23921: pubtext = document.getElementById(context+'_recaptchapubtxt');
23922: } else {
23923: return;
23924: }
23925: if (document.getElementById(context+'_recaptchaprivtxt')) {
23926: privtext = document.getElementById(context+'_recaptchaprivtxt');
23927: } else {
23928: return;
23929: }
1.269 raeburn 23930: if (document.getElementById(context+'_recaptchaversion')) {
23931: versionitem = document.getElementById(context+'_recaptchaversion');
23932: } else {
23933: return;
23934: }
23935: if (document.getElementById(context+'_recaptchavertxt')) {
23936: versiontext = document.getElementById(context+'_recaptchavertxt');
23937: } else {
23938: return;
23939: }
1.165 raeburn 23940: if (caller.checked) {
23941: if (caller.value == 'recaptcha') {
23942: pubitem.type = 'text';
23943: privitem.type = 'text';
23944: pubitem.size = '40';
23945: privitem.size = '40';
23946: pubtext.innerHTML = "$lt{'pub'}";
23947: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 23948: versionitem.type = 'text';
23949: versionitem.size = '3';
1.289 raeburn 23950: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 23951: } else {
23952: pubitem.type = 'hidden';
23953: privitem.type = 'hidden';
1.269 raeburn 23954: versionitem.type = 'hidden';
1.165 raeburn 23955: pubtext.innerHTML = '';
23956: privtext.innerHTML = '';
1.269 raeburn 23957: versiontext.innerHTML = '';
1.165 raeburn 23958: }
23959: }
23960: return;
23961: }
23962:
23963: // ]]>
23964: </script>
23965:
23966: END
23967:
23968: }
23969:
1.236 raeburn 23970: sub toggle_display_js {
1.192 raeburn 23971: return <<"END";
23972:
23973: <script type="text/javascript">
23974: // <![CDATA[
23975:
1.236 raeburn 23976: function toggleDisplay(domForm,caller) {
23977: if (document.getElementById(caller)) {
23978: var divitem = document.getElementById(caller);
23979: var optionsElement = domForm.coursecredits;
1.264 raeburn 23980: var checkval = 1;
23981: var dispval = 'block';
1.303 raeburn 23982: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 23983: if (caller == 'emailoptions') {
1.372 raeburn 23984: optionsElement = domForm.cancreate_email;
1.236 raeburn 23985: }
1.257 raeburn 23986: if (caller == 'studentsubmission') {
23987: optionsElement = domForm.postsubmit;
23988: }
1.264 raeburn 23989: if (caller == 'cloneinstcode') {
23990: optionsElement = domForm.canclone;
23991: checkval = 'instcode';
23992: }
1.303 raeburn 23993: if (selfcreateRegExp.test(caller)) {
23994: optionsElement = domForm.elements[caller];
23995: checkval = 'other';
23996: dispval = 'inline'
23997: }
1.236 raeburn 23998: if (optionsElement.length) {
1.192 raeburn 23999: var currval;
1.236 raeburn 24000: for (var i=0; i<optionsElement.length; i++) {
24001: if (optionsElement[i].checked) {
24002: currval = optionsElement[i].value;
1.192 raeburn 24003: }
24004: }
1.264 raeburn 24005: if (currval == checkval) {
24006: divitem.style.display = dispval;
1.192 raeburn 24007: } else {
1.236 raeburn 24008: divitem.style.display = 'none';
1.192 raeburn 24009: }
24010: }
24011: }
24012: return;
24013: }
24014:
24015: // ]]>
24016: </script>
24017:
24018: END
24019:
24020: }
24021:
1.165 raeburn 24022: sub captcha_phrases {
24023: return &Apache::lonlocal::texthash (
24024: priv => 'Private key',
24025: pub => 'Public key',
24026: original => 'original (CAPTCHA)',
24027: recaptcha => 'successor (ReCAPTCHA)',
24028: notused => 'unused',
1.289 raeburn 24029: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 24030: );
24031: }
24032:
1.205 raeburn 24033: sub devalidate_remote_domconfs {
1.212 raeburn 24034: my ($dom,$cachekeys) = @_;
24035: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 24036: my %servers = &Apache::lonnet::internet_dom_servers($dom);
24037: my %thismachine;
24038: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 raeburn 24039: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.394 raeburn 24040: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
1.410 raeburn 24041: 'ipaccess','trust');
1.386 raeburn 24042: my %cache_by_lonhost;
24043: if (exists($cachekeys->{'samllanding'})) {
24044: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
24045: my %landing = %{$cachekeys->{'samllanding'}};
24046: my %domservers = &Apache::lonnet::get_servers($dom);
24047: if (keys(%domservers)) {
24048: foreach my $server (keys(%domservers)) {
24049: my @cached;
24050: next if ($thismachine{$server});
24051: if ($landing{$server}) {
24052: push(@cached,&escape('samllanding').':'.&escape($server));
24053: }
24054: if (@cached) {
24055: $cache_by_lonhost{$server} = \@cached;
24056: }
24057: }
24058: }
24059: }
24060: }
1.260 raeburn 24061: if (keys(%servers)) {
1.205 raeburn 24062: foreach my $server (keys(%servers)) {
24063: next if ($thismachine{$server});
1.212 raeburn 24064: my @cached;
24065: foreach my $name (@posscached) {
24066: if ($cachekeys->{$name}) {
1.388 raeburn 24067: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
1.386 raeburn 24068: if (ref($cachekeys->{$name}) eq 'HASH') {
1.373 raeburn 24069: foreach my $key (keys(%{$cachekeys->{$name}})) {
24070: push(@cached,&escape($name).':'.&escape($key));
24071: }
24072: }
24073: } else {
24074: push(@cached,&escape($name).':'.&escape($dom));
24075: }
1.212 raeburn 24076: }
24077: }
1.386 raeburn 24078: if ((exists($cache_by_lonhost{$server})) &&
24079: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
24080: push(@cached,@{$cache_by_lonhost{$server}});
24081: }
1.212 raeburn 24082: if (@cached) {
24083: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
24084: }
1.205 raeburn 24085: }
24086: }
24087: return;
24088: }
24089:
1.3 raeburn 24090: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>