Annotation of loncom/interface/domainprefs.pm, revision 1.442
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.442 ! raeburn 4: # $Id: domainprefs.pm,v 1.441 2024/05/21 02:57:15 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.438 raeburn 6920: crseditors => 'Available editors for web pages and/or problems created in a course/community',
1.192 raeburn 6921: );
1.198 raeburn 6922: my %staticdefaults = (
6923: anonsurvey_threshold => 10,
6924: uploadquota => 500,
1.428 raeburn 6925: coursequota => 20,
1.257 raeburn 6926: postsubmit => 60,
1.276 raeburn 6927: mysqltables => 172800,
1.422 raeburn 6928: domexttool => 1,
6929: exttool => 0,
1.432 raeburn 6930: crsauthor => 1,
1.438 raeburn 6931: crseditors => ['edit','xml'],
1.198 raeburn 6932: );
1.139 raeburn 6933: if ($position eq 'top') {
1.257 raeburn 6934: %defaultchecked = (
6935: 'canuse_pdfforms' => 'off',
6936: 'uselcmath' => 'on',
6937: 'usejsme' => 'on',
1.398 raeburn 6938: 'inline_chem' => 'on',
1.289 raeburn 6939: 'canclone' => 'none',
1.257 raeburn 6940: );
1.398 raeburn 6941: @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem');
1.349 raeburn 6942: my $deftex = $Apache::lonnet::deftex;
1.314 raeburn 6943: if (ref($settings) eq 'HASH') {
6944: if ($settings->{'texengine'}) {
6945: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
6946: $deftex = $settings->{'texengine'};
6947: }
6948: }
6949: }
6950: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6951: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
6952: '<span class="LC_nobreak">'.$choices{'texengine'}.
6953: '</span></td><td class="LC_right_item">'.
6954: '<select name="texengine">'."\n";
6955: my %texoptions = (
6956: MathJax => 'MathJax',
6957: mimetex => &mt('Convert to Images'),
6958: tth => &mt('TeX to HTML'),
6959: );
6960: foreach my $renderer ('MathJax','mimetex','tth') {
6961: my $selected = '';
6962: if ($renderer eq $deftex) {
6963: $selected = ' selected="selected"';
6964: }
6965: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
6966: }
6967: $mathdisp .= '</select></td></tr>'."\n";
6968: $itemcount ++;
1.139 raeburn 6969: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 6970: \%choices,$itemcount);
1.314 raeburn 6971: $datatable = $mathdisp.$datatable;
1.264 raeburn 6972: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6973: $datatable .=
1.306 raeburn 6974: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 6975: '<span class="LC_nobreak">'.$choices{'canclone'}.
6976: '</span></td><td class="LC_left_item">';
6977: my $currcanclone = 'none';
6978: my $onclick;
6979: my @cloneoptions = ('none','domain');
1.380 raeburn 6980: my %clonetitles = &Apache::lonlocal::texthash (
1.264 raeburn 6981: none => 'No additional course requesters',
6982: domain => "Any course requester in course's domain",
6983: instcode => 'Course requests for official courses ...',
6984: );
6985: my (%codedefaults,@code_order,@posscodes);
6986: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
6987: \@code_order) eq 'ok') {
6988: if (@code_order > 0) {
6989: push(@cloneoptions,'instcode');
6990: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
6991: }
6992: }
6993: if (ref($settings) eq 'HASH') {
6994: if ($settings->{'canclone'}) {
6995: if (ref($settings->{'canclone'}) eq 'HASH') {
6996: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
6997: if (@code_order > 0) {
6998: $currcanclone = 'instcode';
6999: @posscodes = @{$settings->{'canclone'}{'instcode'}};
7000: }
7001: }
7002: } elsif ($settings->{'canclone'} eq 'domain') {
7003: $currcanclone = $settings->{'canclone'};
7004: }
7005: }
1.289 raeburn 7006: }
1.264 raeburn 7007: foreach my $option (@cloneoptions) {
7008: my ($checked,$additional);
7009: if ($currcanclone eq $option) {
7010: $checked = ' checked="checked"';
7011: }
7012: if ($option eq 'instcode') {
7013: if (@code_order) {
7014: my $show = 'none';
7015: if ($checked) {
7016: $show = 'block';
7017: }
1.317 raeburn 7018: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 7019: &mt('Institutional codes for new and cloned course have identical:').
7020: '<br />';
7021: foreach my $item (@code_order) {
7022: my $codechk;
7023: if ($checked) {
7024: if (grep(/^\Q$item\E$/,@posscodes)) {
7025: $codechk = ' checked="checked"';
7026: }
7027: }
7028: $additional .= '<label>'.
7029: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
7030: $item.'</label>';
7031: }
7032: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
7033: }
7034: }
7035: $datatable .=
7036: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
7037: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
7038: '</label> '.$additional.'</span><br />';
7039: }
7040: $datatable .= '</td>'.
7041: '</tr>';
7042: $itemcount ++;
1.139 raeburn 7043: } else {
7044: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.428 raeburn 7045: my ($currdefresponder,%defcredits,%curruploadquota,%currcoursequota,
7046: %deftimeout,%currmysql);
1.192 raeburn 7047: my $currusecredits = 0;
1.257 raeburn 7048: my $postsubmitclient = 1;
1.405 raeburn 7049: my $ltiauth = 0;
1.422 raeburn 7050: my %domexttool;
7051: my %exttool;
1.432 raeburn 7052: my %crsauthor;
1.438 raeburn 7053: my %crseditors;
1.271 raeburn 7054: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 7055: if (ref($settings) eq 'HASH') {
1.404 raeburn 7056: if ($settings->{'ltiauth'}) {
7057: $ltiauth = 1;
1.405 raeburn 7058: }
1.422 raeburn 7059: if (ref($settings->{'domexttool'}) eq 'HASH') {
7060: foreach my $type (@types) {
7061: if ($settings->{'domexttool'}->{$type}) {
7062: $domexttool{$type} = ' checked="checked"';
7063: }
7064: }
7065: } else {
7066: foreach my $type (@types) {
7067: if ($staticdefaults{'domexttool'}) {
7068: $domexttool{$type} = ' checked="checked"';
7069: }
7070: }
7071: }
7072: if (ref($settings->{'exttool'}) eq 'HASH') {
7073: foreach my $type (@types) {
7074: if ($settings->{'exttool'}->{$type}) {
7075: $exttool{$type} = ' checked="checked"';
7076: }
7077: }
7078: }
1.432 raeburn 7079: if (ref($settings->{'crsauthor'}) eq 'HASH') {
7080: foreach my $type (@types) {
7081: if ($settings->{'crsauthor'}->{$type}) {
7082: $crsauthor{$type} = ' checked="checked"';
7083: }
7084: }
7085: } else {
7086: foreach my $type (@types) {
7087: if ($staticdefaults{'crsauthor'}) {
7088: $crsauthor{$type} = ' checked="checked"';
7089: }
7090: }
7091: }
1.438 raeburn 7092: if (ref($settings->{'crseditors'}) eq 'ARRAY') {
7093: foreach my $editor (@{$settings->{'crseditors'}}) {
7094: $crseditors{$editor} = ' checked="checked"';
7095: }
7096: } else {
7097: foreach my $editor (@{$staticdefaults{'crseditors'}}) {
7098: $crseditors{$editor} = ' checked="checked"';
7099: }
7100: }
1.139 raeburn 7101: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 7102: if (ref($settings->{'uploadquota'}) eq 'HASH') {
7103: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
7104: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
7105: }
7106: }
1.428 raeburn 7107: if (ref($settings->{'coursequota'}) eq 'HASH') {
7108: foreach my $type (keys(%{$settings->{'coursequota'}})) {
7109: $currcoursequota{$type} = $settings->{'coursequota'}{$type};
7110: }
7111: }
1.192 raeburn 7112: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 7113: foreach my $type (@types) {
7114: next if ($type eq 'community');
7115: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
7116: if ($defcredits{$type} ne '') {
7117: $currusecredits = 1;
7118: }
7119: }
7120: }
7121: if (ref($settings->{'postsubmit'}) eq 'HASH') {
7122: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
7123: $postsubmitclient = 0;
7124: foreach my $type (@types) {
7125: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7126: }
7127: } else {
7128: foreach my $type (@types) {
7129: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
7130: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 7131: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 7132: } else {
7133: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7134: }
7135: } else {
7136: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7137: }
7138: }
7139: }
7140: } else {
7141: foreach my $type (@types) {
7142: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 7143: }
7144: }
1.276 raeburn 7145: if (ref($settings->{'mysqltables'}) eq 'HASH') {
7146: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
7147: $currmysql{$type} = $settings->{'mysqltables'}{$type};
7148: }
7149: } else {
7150: foreach my $type (@types) {
7151: $currmysql{$type} = $staticdefaults{'mysqltables'};
7152: }
7153: }
1.258 raeburn 7154: } else {
7155: foreach my $type (@types) {
7156: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.422 raeburn 7157: if ($staticdefaults{'domexttool'}) {
7158: $domexttool{$type} = ' checked="checked"';
7159: }
1.432 raeburn 7160: if ($staticdefaults{'crsauthor'}) {
7161: $crsauthor{$type} = ' checked="checked"';
7162: }
1.258 raeburn 7163: }
1.438 raeburn 7164: foreach my $editor (@{$staticdefaults{'crseditors'}}) {
7165: $crseditors{$editor} = ' checked="checked"';
7166: }
1.139 raeburn 7167: }
7168: if (!$currdefresponder) {
1.198 raeburn 7169: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 7170: } elsif ($currdefresponder < 1) {
7171: $currdefresponder = 1;
7172: }
1.198 raeburn 7173: foreach my $type (@types) {
7174: if ($curruploadquota{$type} eq '') {
7175: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
7176: }
1.428 raeburn 7177: if ($currcoursequota{$type} eq '') {
7178: $currcoursequota{$type} = $staticdefaults{'coursequota'};
7179: }
1.198 raeburn 7180: }
1.139 raeburn 7181: $datatable .=
1.192 raeburn 7182: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7183: $choices{'anonsurvey_threshold'}.
1.139 raeburn 7184: '</span></td>'.
7185: '<td class="LC_right_item"><span class="LC_nobreak">'.
7186: '<input type="text" name="anonsurvey_threshold"'.
7187: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 7188: '</td></tr>'."\n";
7189: $itemcount ++;
7190: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7191: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7192: $choices{'uploadquota'}.
7193: '</span></td>'.
1.306 raeburn 7194: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 7195: '<table><tr>';
1.198 raeburn 7196: foreach my $type (@types) {
1.306 raeburn 7197: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 7198: '<input type="text" name="uploadquota_'.$type.'"'.
7199: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
7200: }
7201: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 7202: $itemcount ++;
1.428 raeburn 7203: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7204: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7205: $choices{'coursequota'}.
7206: '</span></td>'.
7207: '<td style="text-align: right" class="LC_right_item">'.
7208: '<table><tr>';
7209: foreach my $type (@types) {
7210: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
7211: '<input type="text" name="coursequota_'.$type.'"'.
7212: ' value="'.$currcoursequota{$type}.'" size="5" /></td>';
7213: }
7214: $datatable .= '</tr></table></td></tr>'."\n";
7215: $itemcount ++;
1.236 raeburn 7216: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 7217: my $display = 'none';
1.192 raeburn 7218: if ($currusecredits) {
7219: $display = 'block';
7220: }
7221: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 7222: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
7223: foreach my $type (@types) {
7224: next if ($type eq 'community');
1.306 raeburn 7225: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7226: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 7227: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 7228: }
7229: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 7230: %defaultchecked = ('coursecredits' => 'off');
7231: @toggles = ('coursecredits');
7232: my $current = {
7233: 'coursecredits' => $currusecredits,
7234: };
7235: (my $table,$itemcount) =
7236: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 7237: \%choices,$itemcount,$onclick,$additional,'left');
7238: $datatable .= $table;
7239: $onclick = "toggleDisplay(this.form,'studentsubmission');";
7240: my $display = 'none';
7241: if ($postsubmitclient) {
7242: $display = 'block';
7243: }
7244: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 7245: &mt('Number of seconds submit is disabled').'<br />'.
7246: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
7247: '<table><tr>';
1.257 raeburn 7248: foreach my $type (@types) {
1.306 raeburn 7249: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7250: '<input type="text" name="'.$type.'_timeout" value="'.
7251: $deftimeout{$type}.'" size="5" /></td>';
7252: }
7253: $additional .= '</tr></table></div>'."\n";
7254: %defaultchecked = ('postsubmit' => 'on');
7255: @toggles = ('postsubmit');
1.280 raeburn 7256: $current = {
7257: 'postsubmit' => $postsubmitclient,
7258: };
1.257 raeburn 7259: ($table,$itemcount) =
7260: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7261: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 7262: $datatable .= $table;
1.276 raeburn 7263: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7264: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7265: $choices{'mysqltables'}.
7266: '</span></td>'.
1.306 raeburn 7267: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 7268: '<table><tr>';
7269: foreach my $type (@types) {
1.306 raeburn 7270: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 7271: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 7272: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 7273: }
7274: $datatable .= '</tr></table></td></tr>'."\n";
7275: $itemcount ++;
1.404 raeburn 7276: %defaultchecked = ('ltiauth' => 'off');
7277: @toggles = ('ltiauth');
7278: $current = {
7279: 'ltiauth' => $ltiauth,
7280: };
7281: ($table,$itemcount) =
7282: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7283: \%choices,$itemcount,undef,undef,'left');
7284: $datatable .= $table;
1.422 raeburn 7285: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7286: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7287: $choices{'domexttool'}.
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">'.
1.438 raeburn 7294: '<label><input type="checkbox" name="domexttool"'.
1.422 raeburn 7295: ' value="'.$type.'"'.$domexttool{$type}.' />'.
1.438 raeburn 7296: &mt($type).'</label></span></td>'."\n";
1.422 raeburn 7297: }
7298: $datatable .= '</tr></table></td></tr>'."\n";
1.404 raeburn 7299: $itemcount ++;
1.422 raeburn 7300: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7301: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7302: $choices{'exttool'}.
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">'.
1.438 raeburn 7309: '<label><input type="checkbox" name="exttool"'.
1.422 raeburn 7310: ' value="'.$type.'"'.$exttool{$type}.' />'.
1.438 raeburn 7311: &mt($type).'</label></span></td>'."\n";
1.422 raeburn 7312: }
7313: $datatable .= '</tr></table></td></tr>'."\n";
1.432 raeburn 7314: $itemcount ++;
7315: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7316: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7317: $choices{'crsauthor'}.
7318: '</span></td>'.
7319: '<td style="text-align: right" class="LC_right_item">'.
7320: '<table><tr>';
7321: foreach my $type (@types) {
7322: $datatable .= '<td style="text-align: left">'.
7323: '<span class="LC_nobreak">'.
1.438 raeburn 7324: '<label><input type="checkbox" name="crsauthor"'.
1.432 raeburn 7325: ' value="'.$type.'"'.$crsauthor{$type}.' />'.
1.438 raeburn 7326: &mt($type).'</label></span></td>'."\n";
7327: }
7328: $datatable .= '</tr></table></td></tr>'."\n";
7329: $itemcount ++;
7330: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7331: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7332: $choices{'crseditors'}.
7333: '</span></td>'.
7334: '<td style="text-align: right" class="LC_right_item">'.
7335: '<table><tr>';
7336: my @editors = ('edit','xml','daxe');
7337: my %editornames = &crseditor_titles();
7338: foreach my $editor (@editors) {
7339: $datatable .= '<td style="text-align: left">'.
7340: '<span class="LC_nobreak">'.
7341: '<label><input type="checkbox" name="crseditors"'.
7342: ' value="'.$editor.'"'.$crseditors{$editor}.' />'.
7343: $editornames{$editor}.'</label></span></td>'."\n";
1.432 raeburn 7344: }
7345: $datatable .= '</tr></table></td></tr>'."\n";
1.139 raeburn 7346: }
1.192 raeburn 7347: $$rowtotal += $itemcount;
1.121 raeburn 7348: return $datatable;
1.118 jms 7349: }
7350:
1.438 raeburn 7351: sub crseditor_titles {
7352: return &Apache::lonlocal::texthash(
7353: edit => 'Standard editor (Edit)',
7354: xml => 'Text editor (EditXML)',
7355: daxe => 'Daxe editor (Daxe)',
7356: );
7357: }
7358:
1.429 raeburn 7359: sub print_authordefaults {
7360: my ($position,$dom,$settings,$rowtotal) = @_;
7361: my ($css_class,$datatable,%checkedon,%checkedoff);
7362: my $itemcount = 1;
7363: my %titles = &authordefaults_titles();
7364: if ($position eq 'top') {
7365: my %defaultchecked = (
7366: 'nocodemirror' => 'off',
1.437 raeburn 7367: 'daxecollapse' => 'off',
1.429 raeburn 7368: 'domcoordacc' => 'on',
7369: );
1.437 raeburn 7370: my @toggles = ('nocodemirror','daxecollapse','domcoordacc');
1.429 raeburn 7371: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
7372: \%titles,$itemcount);
7373: my %staticdefaults = (
7374: 'copyright' => 'default',
7375: 'sourceavail' => 'closed',
7376: );
7377: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7378: my %currrights;
7379: foreach my $item ('copyright','sourceavail') {
7380: $currrights{$item} = $staticdefaults{$item};
7381: if (ref($settings) eq 'HASH') {
7382: if (exists($settings->{$item})) {
7383: $currrights{$item} = $settings->{$item};
7384: }
7385: }
7386: }
7387: $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
7388: '<span class="LC_nobreak">'.$titles{'copyright'}.
7389: '</span></td><td class="LC_right_item">'.
7390: &selectbox('copyright',$currrights{'copyright'},'',
7391: \&Apache::loncommon::copyrightdescription,
7392: (grep !/^priv|custom$/,(&Apache::loncommon::copyrightids))).
7393: '</td></tr>'."\n";
7394: $itemcount ++;
7395: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7396: $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
7397: '<span class="LC_nobreak">'.$titles{'sourceavail'}.
7398: '</span></td><td class="LC_right_item">'.
7399: &selectbox('sourceavail',$currrights{'sourceavail'},'',
7400: \&Apache::loncommon::source_copyrightdescription,
7401: (&Apache::loncommon::source_copyrightids)).
7402: '</td></tr>'."\n";
7403: } else {
7404: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7405: my $curreditors;
7406: my %staticdefaults = (
7407: editors => ['edit','xml'],
7408: authorquota => 500,
7409: webdav => 0,
7410: );
7411: my $curreditors = $staticdefaults{'editors'};
7412: if ((ref($settings) eq 'HASH') &&
7413: (ref($settings->{'editors'}) eq 'ARRAY')) {
7414: $curreditors = $settings->{'editors'};
7415: } else {
7416: $curreditors = $staticdefaults{'editors'};
7417: }
7418: my @editors = ('edit','xml','daxe');
7419: $datatable = '<tr'.$css_class.'>'."\n".
7420: '<td>'.$titles{'editors'}.'</td>'."\n".
7421: '<td class="LC_left_item">'."\n".
7422: '<span class="LC_nobreak">';
7423: foreach my $editor (@editors) {
7424: my $checked;
7425: if (grep(/^\Q$editor\E$/,@{$curreditors})) {
7426: $checked = ' checked="checked"';
7427: }
7428: $datatable .= '<label>'.
7429: '<input type="checkbox" name="author_editors" '.
7430: $checked.' value="'.$editor.'" '.
7431: 'onclick="javascript:checkEditors(this.form,'."'author_editors'".',this);" />'.
7432: $titles{$editor}.'</label> ';
7433: }
7434: $datatable .= '</span>'."\n".'</td>'."\n".'</tr>'."\n";
7435: $itemcount ++;
7436: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7437: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7438: my @insttypes;
7439: if (ref($types) eq 'ARRAY') {
7440: @insttypes = @{$types};
7441: }
7442: my $typecount = 0;
7443: my %domconf = &Apache::lonnet::get_dom('configuration',['quotas'],$dom);
7444: my @items = ('webdav','authorquota');
7445: my %quotas;
7446: if (ref($domconf{'quotas'}) eq 'HASH') {
7447: %quotas = %{$domconf{'quotas'}};
7448: foreach my $item (@items) {
7449: if (ref($quotas{$item}) eq 'HASH') {
7450: foreach my $type (@insttypes,'default') {
7451: if ($item eq 'authorquota') {
7452: if ($quotas{$item}{$type} !~ /^\d+$/) {
7453: $quotas{$item}{$type} = $staticdefaults{$item};
7454: }
7455: } elsif ($item eq 'webdav') {
7456: if ($quotas{$item}{$type} !~ /^(0|1)$/) {
7457: $quotas{$item}{$type} = $staticdefaults{$item};
7458: }
7459: }
7460: }
7461: } else {
7462: foreach my $type (@insttypes,'default') {
7463: $quotas{$item}{$type} = $staticdefaults{$item};
7464: }
7465: }
7466: }
7467: } else {
7468: foreach my $item (@items) {
7469: foreach my $type (@insttypes,'default') {
7470: $quotas{$item}{$type} = $staticdefaults{$item};
7471: }
7472: }
7473: }
7474: if (ref($usertypes) eq 'HASH') {
7475: my $numinrow = 4;
7476: my $onclick = '';
7477: $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
7478: $numinrow,$othertitle,'authorquota',
7479: \$itemcount,$onclick);
7480: $itemcount ++;
7481: $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
7482: $numinrow,$othertitle,'webdav',
7483: \$itemcount);
7484: $itemcount ++;
7485: }
7486: my $checkedno = ' checked="checked"';
7487: my ($checkedon,$checkedoff);
7488: if (ref($quotas{'webdav'}) eq 'HASH') {
1.436 raeburn 7489: if ($quotas{'webdav'}{'_LC_adv'} =~ /^0|1$/) {
1.429 raeburn 7490: if ($quotas{'webdav'}{'_LC_adv'}) {
7491: $checkedon = $checkedno;
7492: } else {
7493: $checkedoff = $checkedno;
7494: }
7495: undef($checkedno);
7496: }
7497: }
7498: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7499: $datatable .= '<tr'.$css_class.'>'.
7500: '<td>'.$titles{'webdav_LC_adv'}.'<br />'.
7501: $titles{'webdav_LC_adv_over'}.
7502: '</td>'.
7503: '<td class="LC_left_item">';
7504: foreach my $option ('none','off','on') {
7505: my ($text,$val,$checked);
7506: if ($option eq 'none') {
7507: $text = $titles{'none'};
7508: $val = '';
7509: $checked = $checkedno;
7510: } elsif ($option eq 'off') {
7511: $text = $titles{'overoff'};
7512: $val = 0;
7513: $checked = $checkedoff;
7514: } elsif ($option eq 'on') {
7515: $text = $titles{'overon'};
7516: $val = 1;
7517: $checked = $checkedon;
1.436 raeburn 7518: }
1.429 raeburn 7519: $datatable .= '<span class="LC_nobreak"><label>'.
7520: '<input type="radio" name="webdav_LC_adv"'.
7521: ' value="'.$val.'"'.$checked.' />'.
7522: $text.'</label></span> ';
7523: }
7524: $datatable .= '</td></tr>';
7525: $itemcount ++;
1.440 raeburn 7526: my %defchecked = (
7527: 'archive' => 'off',
7528: );
7529: my @toggles = ('archive');
7530: (my $archive,$itemcount) = &radiobutton_prefs($settings,['archive'],
7531: {'archive' => 'off'},
7532: \%titles,$itemcount);
7533: $datatable .= $archive."\n";
7534: $itemcount ++;
1.429 raeburn 7535: }
7536: $$rowtotal += $itemcount;
7537: return $datatable;
7538: }
7539:
7540: sub authordefaults_titles {
7541: return &Apache::lonlocal::texthash(
7542: copyright => 'Copyright/Distribution',
7543: sourceavail => ' Source Available',
7544: editors => 'Available Editors',
7545: webdav => 'WebDAV',
7546: authorquota => 'Authoring Space quotas (MB)',
7547: nocodemirror => 'Deactivate CodeMirror for EditXML editor',
1.437 raeburn 7548: daxecollapse => 'Daxe editor: LON-CAPA standard menus start collapsed',
1.429 raeburn 7549: domcoordacc => 'Dom. Coords. can enter Authoring Spaces in domain',
7550: edit => 'Standard editor (Edit)',
7551: xml => 'Text editor (EditXML)',
7552: daxe => 'Daxe editor (Daxe)',
7553: webdav_LC_adv => 'WebDAV access for LON-CAPA "advanced" users',
7554: webdav_LC_adv_over => '(overrides access based on affiliation, if set)',
7555: none => 'No override set',
7556: overon => 'Override -- webDAV on',
1.436 raeburn 7557: overoff => 'Override -- webDAV off',
1.440 raeburn 7558: archive => 'Authors can download tar.gz file of Authoring Space',
1.429 raeburn 7559: );
7560: }
7561:
7562: sub selectbox {
7563: my ($name,$value,$readonly,$functionref,@idlist)=@_;
7564: my $selout = '<select name="'.$name.'">';
7565: foreach my $id (@idlist) {
7566: $selout.='<option value="'.$id.'"';
7567: if ($id eq $value) {
7568: $selout.=' selected="selected"';
7569: }
7570: if ($readonly) {
7571: $selout .= ' disabled="disabled"';
7572: }
7573: $selout.='>'.&{$functionref}($id).'</option>';
7574: }
7575: $selout.='</select>';
7576: return $selout;
7577: }
7578:
1.231 raeburn 7579: sub print_selfenrollment {
7580: my ($position,$dom,$settings,$rowtotal) = @_;
7581: my ($css_class,$datatable);
7582: my $itemcount = 1;
1.271 raeburn 7583: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 7584: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 7585: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
7586: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 7587: my @rows;
7588: my $key;
7589: if ($position eq 'top') {
7590: $key = 'admin';
7591: if (ref($rowsref) eq 'ARRAY') {
7592: @rows = @{$rowsref};
7593: }
7594: } elsif ($position eq 'middle') {
7595: $key = 'default';
7596: @rows = ('types','registered','approval','limit');
7597: }
7598: foreach my $row (@rows) {
7599: if (defined($titlesref->{$row})) {
7600: $itemcount ++;
7601: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7602: $datatable .= '<tr'.$css_class.'>'.
7603: '<td>'.$titlesref->{$row}.'</td>'.
7604: '<td class="LC_left_item">'.
7605: '<table><tr>';
7606: my (%current,%currentcap);
7607: if (ref($settings) eq 'HASH') {
7608: if (ref($settings->{$key}) eq 'HASH') {
7609: foreach my $type (@types) {
7610: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7611: $current{$type} = $settings->{$key}->{$type}->{$row};
7612: }
7613: if (($row eq 'limit') && ($key eq 'default')) {
7614: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7615: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
7616: }
7617: }
7618: }
7619: }
7620: }
7621: my %roles = (
7622: '0' => &Apache::lonnet::plaintext('dc'),
7623: );
7624:
7625: foreach my $type (@types) {
7626: unless (($row eq 'registered') && ($key eq 'default')) {
7627: $datatable .= '<th>'.&mt($type).'</th>';
7628: }
7629: }
7630: unless (($row eq 'registered') && ($key eq 'default')) {
7631: $datatable .= '</tr><tr>';
7632: }
7633: foreach my $type (@types) {
7634: if ($type eq 'community') {
7635: $roles{'1'} = &mt('Community personnel');
7636: } else {
7637: $roles{'1'} = &mt('Course personnel');
7638: }
7639: $datatable .= '<td style="vertical-align: top">';
7640: if ($position eq 'top') {
7641: my %checked;
7642: if ($current{$type} eq '0') {
7643: $checked{'0'} = ' checked="checked"';
7644: } else {
7645: $checked{'1'} = ' checked="checked"';
7646: }
7647: foreach my $role ('1','0') {
7648: $datatable .= '<span class="LC_nobreak"><label>'.
7649: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
7650: 'value="'.$role.'"'.$checked{$role}.' />'.
7651: $roles{$role}.'</label></span> ';
7652: }
7653: } else {
7654: if ($row eq 'types') {
7655: my %checked;
7656: if ($current{$type} =~ /^(all|dom)$/) {
7657: $checked{$1} = ' checked="checked"';
7658: } else {
7659: $checked{''} = ' checked="checked"';
7660: }
7661: foreach my $val ('','dom','all') {
7662: $datatable .= '<span class="LC_nobreak"><label>'.
7663: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7664: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7665: }
7666: } elsif ($row eq 'registered') {
7667: my %checked;
7668: if ($current{$type} eq '1') {
7669: $checked{'1'} = ' checked="checked"';
7670: } else {
7671: $checked{'0'} = ' checked="checked"';
7672: }
7673: foreach my $val ('0','1') {
7674: $datatable .= '<span class="LC_nobreak"><label>'.
7675: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7676: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7677: }
7678: } elsif ($row eq 'approval') {
7679: my %checked;
7680: if ($current{$type} =~ /^([12])$/) {
7681: $checked{$1} = ' checked="checked"';
7682: } else {
7683: $checked{'0'} = ' checked="checked"';
7684: }
7685: for my $val (0..2) {
7686: $datatable .= '<span class="LC_nobreak"><label>'.
7687: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7688: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7689: }
7690: } elsif ($row eq 'limit') {
7691: my %checked;
7692: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
7693: $checked{$1} = ' checked="checked"';
7694: } else {
7695: $checked{'none'} = ' checked="checked"';
7696: }
7697: my $cap;
7698: if ($currentcap{$type} =~ /^\d+$/) {
7699: $cap = $currentcap{$type};
7700: }
7701: foreach my $val ('none','allstudents','selfenrolled') {
7702: $datatable .= '<span class="LC_nobreak"><label>'.
7703: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7704: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7705: }
7706: $datatable .= '<br />'.
7707: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
7708: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
7709: '</span>';
7710: }
7711: }
7712: $datatable .= '</td>';
7713: }
7714: $datatable .= '</tr>';
7715: }
7716: $datatable .= '</table></td></tr>';
7717: }
7718: } elsif ($position eq 'bottom') {
1.235 raeburn 7719: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
7720: }
7721: $$rowtotal += $itemcount;
7722: return $datatable;
7723: }
7724:
7725: sub print_validation_rows {
7726: my ($caller,$dom,$settings,$rowtotal) = @_;
7727: my ($itemsref,$namesref,$fieldsref);
7728: if ($caller eq 'selfenroll') {
7729: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
7730: } elsif ($caller eq 'requestcourses') {
7731: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
7732: }
7733: my %currvalidation;
7734: if (ref($settings) eq 'HASH') {
7735: if (ref($settings->{'validation'}) eq 'HASH') {
7736: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 7737: }
1.235 raeburn 7738: }
7739: my $datatable;
7740: my $itemcount = 0;
7741: foreach my $item (@{$itemsref}) {
7742: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7743: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7744: $namesref->{$item}.
7745: '</span></td>'.
7746: '<td class="LC_left_item">';
7747: if (($item eq 'url') || ($item eq 'button')) {
7748: $datatable .= '<span class="LC_nobreak">'.
7749: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
7750: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
7751: } elsif ($item eq 'fields') {
7752: my @currfields;
7753: if (ref($currvalidation{$item}) eq 'ARRAY') {
7754: @currfields = @{$currvalidation{$item}};
7755: }
7756: foreach my $field (@{$fieldsref}) {
7757: my $check = '';
7758: if (grep(/^\Q$field\E$/,@currfields)) {
7759: $check = ' checked="checked"';
7760: }
7761: $datatable .= '<span class="LC_nobreak"><label>'.
7762: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
7763: ' value="'.$field.'"'.$check.' />'.$field.
7764: '</label></span> ';
7765: }
7766: } elsif ($item eq 'markup') {
1.334 raeburn 7767: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 7768: $currvalidation{$item}.
1.231 raeburn 7769: '</textarea>';
1.235 raeburn 7770: }
7771: $datatable .= '</td></tr>'."\n";
7772: if (ref($rowtotal)) {
1.231 raeburn 7773: $itemcount ++;
7774: }
7775: }
1.235 raeburn 7776: if ($caller eq 'requestcourses') {
7777: my %currhash;
1.248 raeburn 7778: if (ref($settings) eq 'HASH') {
7779: if (ref($settings->{'validation'}) eq 'HASH') {
7780: if ($settings->{'validation'}{'dc'} ne '') {
7781: $currhash{$settings->{'validation'}{'dc'}} = 1;
7782: }
1.235 raeburn 7783: }
7784: }
7785: my $numinrow = 2;
7786: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
7787: 'validationdc',%currhash);
1.247 raeburn 7788: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 7789: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 7790: if ($numdc > 1) {
1.247 raeburn 7791: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 7792: } else {
1.247 raeburn 7793: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 7794: }
1.247 raeburn 7795: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 7796: $itemcount ++;
7797: }
7798: if (ref($rowtotal)) {
7799: $$rowtotal += $itemcount;
7800: }
1.231 raeburn 7801: return $datatable;
7802: }
7803:
1.357 raeburn 7804: sub print_privacy {
7805: my ($position,$dom,$settings,$rowtotal) = @_;
7806: my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
7807: my $itemcount = 0;
1.417 raeburn 7808: if ($position eq 'top') {
7809: $numinrow = 2;
7810: } else {
1.357 raeburn 7811: @items = ('domain','author','course','community');
7812: %names = &Apache::lonlocal::texthash (
7813: domain => 'Assigned domain role(s)',
7814: author => 'Assigned co-author role(s)',
7815: course => 'Assigned course role(s)',
1.416 raeburn 7816: community => 'Assigned community role(s)',
1.357 raeburn 7817: );
7818: $numinrow = 4;
7819: ($othertitle,$usertypes,$types) =
7820: &Apache::loncommon::sorted_inst_types($dom);
7821: }
7822: if (($position eq 'top') || ($position eq 'middle')) {
7823: my (%by_ip,%by_location,@intdoms,@instdoms);
7824: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
7825: if ($position eq 'top') {
7826: my %curr;
7827: my @options = ('none','user','domain','auto');
7828: my %titles = &Apache::lonlocal::texthash (
7829: none => 'Not allowed',
7830: user => 'User authorizes',
7831: domain => 'DC authorizes',
7832: auto => 'Unrestricted',
7833: instdom => 'Other domain shares institution/provider',
7834: extdom => 'Other domain has different institution/provider',
1.418 raeburn 7835: notify => 'Notify when role needs authorization',
1.357 raeburn 7836: );
7837: my %names = &Apache::lonlocal::texthash (
7838: domain => 'Domain role',
7839: author => 'Co-author role',
7840: course => 'Course role',
7841: community => 'Community role',
7842: );
7843: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7844: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7845: foreach my $domtype ('instdom','extdom') {
7846: my (%checked,$skip);
7847: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7848: $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
7849: '<td class="LC_left_item">';
7850: if ($domtype eq 'instdom') {
7851: unless (@instdoms > 1) {
7852: $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
7853: $skip = 1;
7854: }
7855: } elsif ($domtype eq 'extdom') {
7856: if (keys(%by_location) == 0) {
7857: $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
7858: $skip = 1;
7859: }
7860: }
7861: unless ($skip) {
7862: foreach my $roletype ('domain','author','course','community') {
7863: $checked{'auto'} = ' checked="checked"';
7864: if (ref($settings) eq 'HASH') {
7865: if (ref($settings->{approval}) eq 'HASH') {
7866: if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
7867: if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
7868: $checked{$1} = ' checked="checked"';
7869: $checked{'auto'} = '';
7870: }
7871: }
7872: }
7873: }
7874: $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
7875: foreach my $option (@options) {
7876: $datatable .= '<span class="LC_nobreak"><label>'.
7877: '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
7878: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
7879: '</label></span> ';
7880: }
7881: $datatable .= '</fieldset>';
7882: }
7883: }
7884: $datatable .= '</td></tr>';
7885: $itemcount ++;
7886: }
1.417 raeburn 7887: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7888: $datatable .= '<tr'.$css_class.'><td>'.$titles{'notify'}.'</td>'.
7889: '<td class="LC_left_item">';
7890: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7891: my %curr;
7892: if (ref($settings) eq 'HASH') {
7893: if ($settings->{'notify'} ne '') {
7894: map {$curr{$_}=1;} split(/,/,$settings->{'notify'});
7895: }
7896: }
7897: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7898: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
7899: 'privacy_notify',%curr);
7900: if ($numdc > 0) {
7901: $datatable .= $table;
7902: } else {
7903: $datatable .= &mt('There are no active Domain Coordinators');
7904: }
7905: } else {
7906: $datatable .= &mt('Nothing to set here, as there are no other domains');
7907: }
7908: $datatable .='</td></tr>';
1.357 raeburn 7909: } elsif ($position eq 'middle') {
7910: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7911: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7912: foreach my $item (@{$types}) {
7913: $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
7914: $numinrow,$itemcount,'','','','','',
7915: '',$usertypes->{$item});
7916: $itemcount ++;
7917: }
7918: }
7919: $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
7920: $numinrow,$itemcount,'','','','','',
7921: '',$othertitle);
7922: $itemcount ++;
7923: } else {
1.360 raeburn 7924: my (@insttypes,%insttitles);
7925: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7926: @insttypes = @{$types};
7927: %insttitles = %{$usertypes};
7928: }
7929: foreach my $item (@insttypes,'default') {
7930: my $title;
7931: if ($item eq 'default') {
7932: $title = $othertitle;
7933: } else {
7934: $title = $insttitles{$item};
7935: }
7936: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7937: $datatable .= '<tr'.$css_class.'>'.
7938: '<td class="LC_left_item">'.$title.'</td>'.
7939: '<td class="LC_left_item">'.
7940: &mt('Nothing to set here, as there are no other domains').
7941: '</td></tr>';
7942: $itemcount ++;
7943: }
1.357 raeburn 7944: }
7945: }
7946: } else {
7947: my $prefix;
7948: if ($position eq 'lower') {
7949: $prefix = 'priv';
7950: } else {
7951: $prefix = 'unpriv';
7952: }
7953: foreach my $item (@items) {
7954: $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
7955: $numinrow,$itemcount,'','','','','',
7956: '',$names{$item});
7957: $itemcount ++;
7958: }
7959: }
7960: if (ref($rowtotal)) {
7961: $$rowtotal += $itemcount;
7962: }
7963: return $datatable;
7964: }
7965:
1.354 raeburn 7966: sub print_passwords {
7967: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
7968: my ($datatable,$css_class);
7969: my $itemcount = 0;
7970: my %titles = &Apache::lonlocal::texthash (
7971: captcha => '"Forgot Password" CAPTCHA validation',
7972: link => 'Reset link expiration (hours)',
7973: case => 'Case-sensitive usernames/e-mail',
7974: prelink => 'Information required (form 1)',
7975: postlink => 'Information required (form 2)',
7976: emailsrc => 'LON-CAPA e-mail address type(s)',
7977: customtext => 'Domain specific text (HTML)',
7978: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
7979: intauth_check => 'Check bcrypt cost if authenticated',
7980: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
7981: permanent => 'Permanent e-mail address',
7982: critical => 'Critical notification address',
7983: notify => 'Notification address',
7984: min => 'Minimum password length',
7985: max => 'Maximum password length',
7986: chars => 'Required characters',
7987: expire => 'Password expiration (days)',
1.356 raeburn 7988: numsaved => 'Number of previous passwords to save and disallow reuse',
1.354 raeburn 7989: );
7990: if ($position eq 'top') {
7991: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7992: my $shownlinklife = 2;
7993: my $prelink = 'both';
7994: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
7995: if (ref($settings) eq 'HASH') {
7996: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
7997: $shownlinklife = $settings->{resetlink};
7998: }
7999: if (ref($settings->{resetcase}) eq 'ARRAY') {
8000: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
8001: }
8002: if ($settings->{resetprelink} =~ /^(both|either)$/) {
8003: $prelink = $settings->{resetprelink};
8004: }
8005: if (ref($settings->{resetpostlink}) eq 'HASH') {
8006: %postlink = %{$settings->{resetpostlink}};
8007: }
8008: if (ref($settings->{resetemail}) eq 'ARRAY') {
8009: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
8010: }
8011: if ($settings->{resetremove}) {
8012: $nostdtext = 1;
8013: }
8014: if ($settings->{resetcustom}) {
8015: $customurl = $settings->{resetcustom};
8016: }
8017: } else {
8018: if (ref($types) eq 'ARRAY') {
8019: foreach my $item (@{$types}) {
8020: $casesens{$item} = 1;
8021: $postlink{$item} = ['username','email'];
8022: }
8023: }
8024: $casesens{'default'} = 1;
8025: $postlink{'default'} = ['username','email'];
8026: $prelink = 'both';
8027: %emailsrc = (
8028: permanent => 1,
8029: critical => 1,
8030: notify => 1,
8031: );
8032: }
8033: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
8034: $itemcount ++;
8035: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8036: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
8037: '<td class="LC_left_item">'.
8038: '<input type="textbox" value="'.$shownlinklife.'" '.
8039: 'name="passwords_link" size="3" /></td></tr>';
8040: $itemcount ++;
8041: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8042: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
8043: '<td class="LC_left_item">';
8044: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8045: foreach my $item (@{$types}) {
8046: my $checkedcase;
8047: if ($casesens{$item}) {
8048: $checkedcase = ' checked="checked"';
8049: }
8050: $datatable .= '<span class="LC_nobreak"><label>'.
8051: '<input type="checkbox" name="passwords_case_sensitive" value="'.
8052: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369 raeburn 8053: '</span> ';
1.354 raeburn 8054: }
8055: }
8056: my $checkedcase;
8057: if ($casesens{'default'}) {
8058: $checkedcase = ' checked="checked"';
8059: }
8060: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
8061: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
8062: $othertitle.'</label></span></td>';
8063: $itemcount ++;
8064: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8065: my %checkedpre = (
8066: both => ' checked="checked"',
8067: either => '',
8068: );
8069: if ($prelink eq 'either') {
8070: $checkedpre{either} = ' checked="checked"';
8071: $checkedpre{both} = '';
8072: }
8073: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
8074: '<td class="LC_left_item"><span class="LC_nobreak">'.
8075: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
8076: &mt('Both username and e-mail address').'</label></span> '.
8077: '<span class="LC_nobreak"><label>'.
8078: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
8079: &mt('Either username or e-mail address').'</label></span></td></tr>';
8080: $itemcount ++;
8081: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8082: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
8083: '<td class="LC_left_item">';
8084: my %postlinked;
8085: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8086: foreach my $item (@{$types}) {
8087: undef(%postlinked);
8088: $datatable .= '<fieldset style="display: inline-block;">'.
8089: '<legend>'.$usertypes->{$item}.'</legend>';
8090: if (ref($postlink{$item}) eq 'ARRAY') {
8091: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
8092: }
8093: foreach my $field ('email','username') {
8094: my $checked;
8095: if ($postlinked{$field}) {
8096: $checked = ' checked="checked"';
8097: }
8098: $datatable .= '<span class="LC_nobreak"><label>'.
8099: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
8100: $field.'"'.$checked.' />'.$field.'</label>'.
8101: '<span> ';
8102: }
8103: $datatable .= '</fieldset>';
8104: }
8105: }
8106: if (ref($postlink{'default'}) eq 'ARRAY') {
8107: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
8108: }
8109: $datatable .= '<fieldset style="display: inline-block;">'.
8110: '<legend>'.$othertitle.'</legend>';
8111: foreach my $field ('email','username') {
8112: my $checked;
8113: if ($postlinked{$field}) {
8114: $checked = ' checked="checked"';
8115: }
8116: $datatable .= '<span class="LC_nobreak"><label>'.
8117: '<input type="checkbox" name="passwords_postlink_default" value="'.
8118: $field.'"'.$checked.' />'.$field.'</label>'.
8119: '<span> ';
8120: }
8121: $datatable .= '</fieldset></td></tr>';
8122: $itemcount ++;
8123: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8124: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
8125: '<td class="LC_left_item">';
8126: foreach my $type ('permanent','critical','notify') {
8127: my $checkedemail;
8128: if ($emailsrc{$type}) {
8129: $checkedemail = ' checked="checked"';
8130: }
8131: $datatable .= '<span class="LC_nobreak"><label>'.
8132: '<input type="checkbox" name="passwords_emailsrc" value="'.
8133: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
8134: '<span> ';
8135: }
8136: $datatable .= '</td></tr>';
8137: $itemcount ++;
8138: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8139: my $switchserver = &check_switchserver($dom,$confname);
8140: my ($showstd,$noshowstd);
8141: if ($nostdtext) {
8142: $noshowstd = ' checked="checked"';
8143: } else {
8144: $showstd = ' checked="checked"';
8145: }
8146: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
8147: '<td class="LC_left_item"><span class="LC_nobreak">'.
8148: &mt('Retain standard text:').
8149: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
8150: &mt('Yes').'</label>'.' '.
8151: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
8152: &mt('No').'</label></span><br />'.
8153: '<span class="LC_fontsize_small">'.
8154: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
8155: &mt('Include custom text:');
8156: if ($customurl) {
1.369 raeburn 8157: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354 raeburn 8158: undef,undef,undef,undef,'background-color:#ffffff');
8159: $datatable .= '<span class="LC_nobreak"> '.$link.
8160: '<label><input type="checkbox" name="passwords_custom_del"'.
8161: ' value="1" />'.&mt('Delete?').'</label></span>'.
8162: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
8163: }
8164: if ($switchserver) {
8165: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
8166: } else {
8167: $datatable .='<span class="LC_nobreak"> '.
8168: '<input type="file" name="passwords_customfile" /></span>';
8169: }
8170: $datatable .= '</td></tr>';
8171: } elsif ($position eq 'middle') {
8172: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
8173: my @items = ('intauth_cost','intauth_check','intauth_switch');
8174: my %defaults;
8175: if (ref($domconf{'defaults'}) eq 'HASH') {
8176: %defaults = %{$domconf{'defaults'}};
8177: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
8178: $defaults{'intauth_cost'} = 10;
8179: }
8180: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
8181: $defaults{'intauth_check'} = 0;
8182: }
8183: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
8184: $defaults{'intauth_switch'} = 0;
8185: }
8186: } else {
8187: %defaults = (
8188: 'intauth_cost' => 10,
8189: 'intauth_check' => 0,
8190: 'intauth_switch' => 0,
8191: );
8192: }
8193: foreach my $item (@items) {
8194: if ($itemcount%2) {
8195: $css_class = '';
8196: } else {
8197: $css_class = ' class="LC_odd_row" ';
8198: }
8199: $datatable .= '<tr'.$css_class.'>'.
8200: '<td><span class="LC_nobreak">'.$titles{$item}.
8201: '</span></td><td class="LC_left_item" colspan="3">';
8202: if ($item eq 'intauth_switch') {
8203: my @options = (0,1,2);
8204: my %optiondesc = &Apache::lonlocal::texthash (
8205: 0 => 'No',
8206: 1 => 'Yes',
8207: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
8208: );
8209: $datatable .= '<table width="100%">';
8210: foreach my $option (@options) {
8211: my $checked = ' ';
8212: if ($defaults{$item} eq $option) {
8213: $checked = ' checked="checked"';
8214: }
8215: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8216: '<label><input type="radio" name="'.$item.
8217: '" value="'.$option.'"'.$checked.' />'.
8218: $optiondesc{$option}.'</label></span></td></tr>';
8219: }
8220: $datatable .= '</table>';
8221: } elsif ($item eq 'intauth_check') {
8222: my @options = (0,1,2);
8223: my %optiondesc = &Apache::lonlocal::texthash (
8224: 0 => 'No',
8225: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
8226: 2 => 'Yes, disallow login if stored cost is less than domain default',
8227: );
8228: $datatable .= '<table width="100%">';
8229: foreach my $option (@options) {
8230: my $checked = ' ';
8231: my $onclick;
8232: if ($defaults{$item} eq $option) {
8233: $checked = ' checked="checked"';
8234: }
8235: if ($option == 2) {
8236: $onclick = ' onclick="javascript:warnIntAuth(this);"';
8237: }
8238: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8239: '<label><input type="radio" name="'.$item.
8240: '" value="'.$option.'"'.$checked.$onclick.' />'.
8241: $optiondesc{$option}.'</label></span></td></tr>';
8242: }
8243: $datatable .= '</table>';
8244: } else {
8245: $datatable .= '<input type="text" name="'.$item.'" value="'.
8246: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
8247: }
8248: $datatable .= '</td></tr>';
8249: $itemcount ++;
8250: }
8251: } elsif ($position eq 'lower') {
1.405 raeburn 8252: $datatable .= &password_rules('passwords',\$itemcount,$settings);
1.354 raeburn 8253: } else {
1.359 raeburn 8254: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8255: my %ownerchg = (
8256: by => {},
8257: for => {},
8258: );
8259: my %ownertitles = &Apache::lonlocal::texthash (
8260: by => 'Course owner status(es) allowed',
8261: for => 'Student status(es) allowed',
8262: );
1.354 raeburn 8263: if (ref($settings) eq 'HASH') {
1.359 raeburn 8264: if (ref($settings->{crsownerchg}) eq 'HASH') {
8265: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
8266: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
8267: }
8268: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
8269: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
8270: }
1.354 raeburn 8271: }
8272: }
8273: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8274: $datatable .= '<tr '.$css_class.'>'.
8275: '<td>'.
8276: &mt('Requirements').'<ul>'.
1.359 raeburn 8277: '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354 raeburn 8278: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
8279: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359 raeburn 8280: '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354 raeburn 8281: '</ul>'.
8282: '</td>'.
1.359 raeburn 8283: '<td class="LC_left_item">';
8284: foreach my $item ('by','for') {
8285: $datatable .= '<fieldset style="display: inline-block;">'.
8286: '<legend>'.$ownertitles{$item}.'</legend>';
8287: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8288: foreach my $type (@{$types}) {
8289: my $checked;
8290: if ($ownerchg{$item}{$type}) {
8291: $checked = ' checked="checked"';
8292: }
8293: $datatable .= '<span class="LC_nobreak"><label>'.
8294: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
8295: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369 raeburn 8296: '</span> ';
1.359 raeburn 8297: }
8298: }
8299: my $checked;
8300: if ($ownerchg{$item}{'default'}) {
8301: $checked = ' checked="checked"';
8302: }
8303: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
8304: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
8305: $othertitle.'</label></span></fieldset>';
8306: }
8307: $datatable .= '</td></tr>';
1.354 raeburn 8308: }
8309: return $datatable;
8310: }
8311:
1.405 raeburn 8312: sub password_rules {
8313: my ($prefix,$itemcountref,$settings) = @_;
8314: my ($min,$max,%chars,$expire,$numsaved,$numinrow);
8315: my %titles;
8316: if ($prefix eq 'passwords') {
8317: %titles = &Apache::lonlocal::texthash (
8318: min => 'Minimum password length',
8319: max => 'Maximum password length',
8320: chars => 'Required characters',
8321: );
1.421 raeburn 8322: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 8323: %titles = &Apache::lonlocal::texthash (
8324: min => 'Minimum secret length',
8325: max => 'Maximum secret length',
8326: chars => 'Required characters',
8327: );
8328: }
8329: $min = $Apache::lonnet::passwdmin;
8330: my $datatable;
8331: my $itemcount;
8332: if (ref($itemcountref)) {
8333: $itemcount = $$itemcountref;
8334: }
8335: if (ref($settings) eq 'HASH') {
8336: if ($settings->{min}) {
8337: $min = $settings->{min};
8338: }
8339: if ($settings->{max}) {
8340: $max = $settings->{max};
8341: }
8342: if (ref($settings->{chars}) eq 'ARRAY') {
8343: map { $chars{$_} = 1; } (@{$settings->{chars}});
8344: }
1.425 raeburn 8345: if ($prefix eq 'passwords') {
1.405 raeburn 8346: if ($settings->{expire}) {
8347: $expire = $settings->{expire};
8348: }
8349: if ($settings->{numsaved}) {
8350: $numsaved = $settings->{numsaved};
8351: }
8352: }
8353: }
8354: my %rulenames = &Apache::lonlocal::texthash(
8355: uc => 'At least one upper case letter',
8356: lc => 'At least one lower case letter',
8357: num => 'At least one number',
8358: spec => 'At least one non-alphanumeric',
8359: );
8360: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
8361: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
8362: '<td class="LC_left_item"><span class="LC_nobreak">'.
8363: '<input type="text" name="'.$prefix.'_min" value="'.$min.'" size="3" '.
8364: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8365: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
8366: '</span></td></tr>';
8367: $itemcount ++;
8368: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8369: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
8370: '<td class="LC_left_item"><span class="LC_nobreak">'.
8371: '<input type="text" name="'.$prefix.'_max" value="'.$max.'" size="3" '.
8372: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8373: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
8374: '</span></td></tr>';
8375: $itemcount ++;
8376: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8377: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
8378: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
8379: '</span></td>';
8380: my $numinrow = 2;
8381: my @possrules = ('uc','lc','num','spec');
8382: $datatable .= '<td class="LC_left_item"><table>';
8383: for (my $i=0; $i<@possrules; $i++) {
8384: my ($rem,$checked);
8385: if ($chars{$possrules[$i]}) {
8386: $checked = ' checked="checked"';
8387: }
8388: $rem = $i%($numinrow);
8389: if ($rem == 0) {
8390: if ($i > 0) {
8391: $datatable .= '</tr>';
8392: }
8393: $datatable .= '<tr>';
8394: }
8395: $datatable .= '<td><span class="LC_nobreak"><label>'.
8396: '<input type="checkbox" name="'.$prefix.'_chars" value="'.$possrules[$i].'"'.$checked.' />'.
8397: $rulenames{$possrules[$i]}.'</label></span></td>';
8398: }
8399: my $rem = @possrules%($numinrow);
8400: my $colsleft = $numinrow - $rem;
8401: if ($colsleft > 1 ) {
8402: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8403: ' </td>';
8404: } elsif ($colsleft == 1) {
8405: $datatable .= '<td class="LC_left_item"> </td>';
8406: }
8407: $datatable .='</table></td></tr>';
8408: $itemcount ++;
8409: if ($prefix eq 'passwords') {
8410: $titles{'expire'} = &mt('Password expiration (days)');
8411: $titles{'numsaved'} = &mt('Number of previous passwords to save and disallow reuse');
8412: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8413: $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
8414: '<td class="LC_left_item"><span class="LC_nobreak">'.
8415: '<input type="text" name="'.$prefix.'_expire" value="'.$expire.'" size="4" '.
8416: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8417: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
8418: '</span></td></tr>';
8419: $itemcount ++;
8420: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8421: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
8422: '<td class="LC_left_item"><span class="LC_nobreak">'.
8423: '<input type="text" name="'.$prefix.'_numsaved" value="'.$numsaved.'" size="3" '.
8424: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8425: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
8426: '</span></td></tr>';
8427: $itemcount ++;
8428: }
8429: if (ref($itemcountref)) {
8430: $$itemcountref += $itemcount;
8431: }
8432: return $datatable;
8433: }
8434:
1.373 raeburn 8435: sub print_wafproxy {
8436: my ($position,$dom,$settings,$rowtotal) = @_;
8437: my $css_class;
8438: my $itemcount = 0;
8439: my $datatable;
8440: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 8441: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
1.374 raeburn 8442: my %lt = &wafproxy_titles();
1.373 raeburn 8443: foreach my $server (sort(keys(%servers))) {
8444: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
1.381 raeburn 8445: next if ($serverhome eq '');
1.373 raeburn 8446: my $serverdom;
8447: if ($serverhome ne $server) {
8448: $serverdom = &Apache::lonnet::host_domain($serverhome);
1.381 raeburn 8449: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
8450: $othercontrol{$server} = $serverdom;
8451: }
1.373 raeburn 8452: } else {
8453: $serverdom = &Apache::lonnet::host_domain($server);
1.381 raeburn 8454: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
1.373 raeburn 8455: if ($serverdom ne $dom) {
8456: $othercontrol{$server} = $serverdom;
8457: } else {
8458: $setdom = 1;
8459: if (ref($settings) eq 'HASH') {
8460: if (ref($settings->{'alias'}) eq 'HASH') {
8461: $aliases{$dom} = $settings->{'alias'};
1.381 raeburn 8462: if ($aliases{$dom} ne '') {
8463: $showdom = 1;
8464: }
1.373 raeburn 8465: }
1.388 raeburn 8466: if (ref($settings->{'saml'}) eq 'HASH') {
8467: $saml{$dom} = $settings->{'saml'};
8468: }
1.373 raeburn 8469: }
8470: }
8471: }
8472: }
1.381 raeburn 8473: if ($setdom) {
8474: %{$values{$dom}} = ();
8475: if (ref($settings) eq 'HASH') {
8476: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8477: $values{$dom}{$item} = $settings->{$item};
8478: }
8479: }
8480: }
1.373 raeburn 8481: if (keys(%othercontrol)) {
8482: %otherdoms = reverse(%othercontrol);
8483: foreach my $domain (keys(%otherdoms)) {
8484: %{$values{$domain}} = ();
8485: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
1.383 raeburn 8486: if (ref($config{'wafproxy'}) eq 'HASH') {
8487: $aliases{$domain} = $config{'wafproxy'}{'alias'};
1.425 raeburn 8488: if (exists($config{'wafproxy'}{'saml'})) {
1.388 raeburn 8489: $saml{$domain} = $config{'wafproxy'}{'saml'};
8490: }
1.383 raeburn 8491: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8492: $values{$domain}{$item} = $config{'wafproxy'}{$item};
1.373 raeburn 8493: }
8494: }
8495: }
8496: }
8497: if ($position eq 'top') {
8498: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.381 raeburn 8499: my %aliasinfo;
1.373 raeburn 8500: foreach my $server (sort(keys(%servers))) {
1.381 raeburn 8501: $itemcount ++;
8502: my $dom_in_effect;
8503: my $aliasrows = '<tr>'.
1.383 raeburn 8504: '<td class="LC_left_item" style="vertical-align: baseline;">'.
1.433 raeburn 8505: &mt('Hostname').': '.
8506: '<span class="LC_nobreak LC_cusr_emph">'.
8507: &Apache::lonnet::hostname($server).
8508: '</span></td><td> </td>';
1.373 raeburn 8509: if ($othercontrol{$server}) {
1.381 raeburn 8510: $dom_in_effect = $othercontrol{$server};
1.388 raeburn 8511: my ($current,$forsaml);
1.383 raeburn 8512: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
8513: $current = $aliases{$dom_in_effect}{$server};
1.373 raeburn 8514: }
1.388 raeburn 8515: if (ref($saml{$dom_in_effect}) eq 'HASH') {
8516: if ($saml{$dom_in_effect}{$server}) {
8517: $forsaml = 1;
8518: }
8519: }
1.383 raeburn 8520: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8521: &mt('Alias').': ';
1.373 raeburn 8522: if ($current) {
1.381 raeburn 8523: $aliasrows .= $current;
1.388 raeburn 8524: if ($forsaml) {
1.396 raeburn 8525: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
1.388 raeburn 8526: }
1.373 raeburn 8527: } else {
1.383 raeburn 8528: $aliasrows .= &mt('None');
1.373 raeburn 8529: }
1.383 raeburn 8530: $aliasrows .= ' <span class="LC_small">('.
8531: &mt('controlled by domain: [_1]',
8532: '<b>'.$dom_in_effect.'</b>').')</span></td>';
1.373 raeburn 8533: } else {
1.381 raeburn 8534: $dom_in_effect = $dom;
1.388 raeburn 8535: my ($current,$samlon,$samloff);
8536: $samloff = ' checked="checked"';
1.373 raeburn 8537: if (ref($aliases{$dom}) eq 'HASH') {
8538: if ($aliases{$dom}{$server}) {
8539: $current = $aliases{$dom}{$server};
8540: }
8541: }
1.388 raeburn 8542: if (ref($saml{$dom}) eq 'HASH') {
8543: if ($saml{$dom}{$server}) {
8544: $samlon = $samloff;
8545: undef($samloff);
8546: }
8547: }
1.383 raeburn 8548: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8549: &mt('Alias').': '.
1.381 raeburn 8550: '<input type="text" name="wafproxy_alias_'.$server.'" '.
1.388 raeburn 8551: 'value="'.$current.'" size="30" />'.
8552: (' 'x2).'<span class="LC_nobreak">'.
1.396 raeburn 8553: &mt('Alias used for SSO Auth').': <label>'.
1.388 raeburn 8554: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
1.425 raeburn 8555: &mt('No').'</label> <label>'.
1.388 raeburn 8556: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
8557: &mt('Yes').'</label></span>'.
1.425 raeburn 8558: '</td>';
1.381 raeburn 8559: }
8560: $aliasrows .= '</tr>';
8561: $aliasinfo{$dom_in_effect} .= $aliasrows;
8562: }
8563: if ($aliasinfo{$dom}) {
8564: my ($onclick,$wafon,$wafoff,$showtable);
8565: $onclick = ' onclick="javascript:toggleWAF();"';
8566: $wafoff = ' checked="checked"';
8567: $showtable = ' style="display:none";';
8568: if ($showdom) {
8569: $wafon = $wafoff;
8570: $wafoff = '';
8571: $showtable = ' style="display:inline;"';
8572: }
8573: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8574: $datatable = '<tr'.$css_class.'>'.
8575: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
8576: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
8577: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
8578: &mt('Yes').'</label>'.(' 'x2).'<label>'.
8579: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
8580: &mt('No').'</label></span></td>'.
8581: '<td class="LC_left_item">'.
8582: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
8583: '</table></td></tr>';
8584: $itemcount++;
8585: }
1.383 raeburn 8586: if (keys(%otherdoms)) {
8587: foreach my $key (sort(keys(%otherdoms))) {
1.381 raeburn 8588: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.383 raeburn 8589: $datatable .= '<tr'.$css_class.'>'.
8590: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
8591: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
8592: '</table></td></tr>';
1.381 raeburn 8593: $itemcount++;
1.373 raeburn 8594: }
8595: }
8596: } else {
1.383 raeburn 8597: my %ip_methods = &remoteip_methods();
1.373 raeburn 8598: if ($setdom) {
8599: $itemcount ++;
8600: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.381 raeburn 8601: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
1.382 raeburn 8602: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
1.381 raeburn 8603: $wafstyle = ' style="display:none;"';
8604: $nowafstyle = ' style="display:table-row;"';
8605: $currwafdisplay = ' style="display: none"';
8606: $wafrangestyle = ' style="display: none"';
8607: $curr_remotip = 'n';
1.382 raeburn 8608: $ssltossl = ' checked="checked"';
1.381 raeburn 8609: if ($showdom) {
8610: $wafstyle = ' style="display:table-row;"';
8611: $nowafstyle = ' style="display:none;"';
8612: if (keys(%{$values{$dom}})) {
8613: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
8614: $curr_remotip = $values{$dom}{remoteip};
8615: }
8616: if ($curr_remotip eq 'h') {
8617: $currwafdisplay = ' style="display:table-row"';
8618: $wafrangestyle = ' style="display:inline-block;"';
8619: }
1.382 raeburn 8620: if ($values{$dom}{'sslopt'}) {
8621: $alltossl = ' checked="checked"';
8622: $ssltossl = '';
8623: }
1.381 raeburn 8624: }
8625: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
8626: $vpndircheck = ' checked="checked"';
8627: $currwafvpn = ' style="display:table-row;"';
8628: $wafrangestyle = ' style="display:inline-block;"';
8629: } else {
8630: $vpnaliascheck = ' checked="checked"';
8631: $currwafvpn = ' style="display:none;"';
8632: }
8633: }
8634: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
8635: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
8636: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
8637: '</tr>'.
8638: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
1.374 raeburn 8639: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
1.381 raeburn 8640: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
1.393 raeburn 8641: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
8642: &mt('Range(s) stored in CIDR notation').'</div></td>'.
1.381 raeburn 8643: '<td class="LC_left_item"><table>'.
8644: '<tr>'.
8645: '<td valign="top">'.$lt{'remoteip'}.': '.
8646: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
8647: foreach my $option ('m','h','n') {
8648: my $sel;
8649: if ($option eq $curr_remotip) {
8650: $sel = ' selected="selected"';
8651: }
8652: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
8653: $ip_methods{$option}.'</option>';
8654: }
8655: $datatable .= '</select></td></tr>'."\n".
8656: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
8657: $lt{'ipheader'}.': '.
8658: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
8659: 'name="wafproxy_ipheader" />'.
8660: '</td></tr>'."\n".
8661: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
1.382 raeburn 8662: $lt{'trusted'}.':<br />'.
1.381 raeburn 8663: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
8664: $values{$dom}{'trusted'}.'</textarea>'.
8665: '</td></tr>'."\n".
8666: '<tr><td><hr /></td></tr>'."\n".
8667: '<tr>'.
8668: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
8669: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
8670: $lt{'vpndirect'}.'</label>'.(' 'x2).
8671: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
8672: $lt{'vpnaliased'}.'</label></span></td></tr>';
8673: foreach my $item ('vpnint','vpnext') {
8674: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
1.382 raeburn 8675: '<td valign="top">'.$lt{$item}.':<br />'.
1.381 raeburn 8676: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
8677: $values{$dom}{$item}.'</textarea>'.
8678: '</td></tr>'."\n";
1.373 raeburn 8679: }
1.382 raeburn 8680: $datatable .= '<tr><td><hr /></td></tr>'."\n".
8681: '<tr>'.
8682: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
8683: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
8684: $lt{'alltossl'}.'</label>'.(' 'x2).
8685: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
8686: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
8687: '</table></td></tr>';
1.373 raeburn 8688: }
8689: if (keys(%otherdoms)) {
8690: foreach my $domain (sort(keys(%otherdoms))) {
8691: $itemcount ++;
8692: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8693: $datatable .= '<tr'.$css_class.'>'.
1.383 raeburn 8694: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
1.374 raeburn 8695: '<td class="LC_left_item"><table>';
1.382 raeburn 8696: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 8697: my $showval = &mt('None');
1.382 raeburn 8698: if ($item eq 'ssl') {
8699: $showval = $lt{'ssltossl'};
8700: }
1.373 raeburn 8701: if ($values{$domain}{$item}) {
1.381 raeburn 8702: $showval = $values{$domain}{$item};
1.382 raeburn 8703: if ($item eq 'ssl') {
8704: $showval = $lt{'alltossl'};
1.383 raeburn 8705: } elsif ($item eq 'remoteip') {
8706: $showval = $ip_methods{$values{$domain}{$item}};
1.382 raeburn 8707: }
1.373 raeburn 8708: }
8709: $datatable .= '<tr>'.
8710: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
8711: }
1.381 raeburn 8712: $datatable .= '</table></td></tr>';
1.373 raeburn 8713: }
8714: }
8715: }
8716: $$rowtotal += $itemcount;
8717: return $datatable;
8718: }
8719:
8720: sub wafproxy_titles {
8721: return &Apache::lonlocal::texthash(
1.381 raeburn 8722: remoteip => "Method for determining user's IP",
8723: ipheader => 'Request header containing remote IP',
8724: trusted => 'Trusted IP range(s)',
8725: vpnaccess => 'Access from institutional VPN',
8726: vpndirect => 'via regular hostname (no WAF)',
8727: vpnaliased => 'via aliased hostname (WAF)',
8728: vpnint => 'Internal IP Range(s) for VPN sessions',
8729: vpnext => 'IP Range(s) for backend WAF connections',
1.382 raeburn 8730: sslopt => 'Forwarding http/https',
1.381 raeburn 8731: alltossl => 'WAF forwards both http and https requests to https',
8732: ssltossl => 'WAF forwards http requests to http and https to https',
8733: );
8734: }
8735:
8736: sub remoteip_methods {
8737: return &Apache::lonlocal::texthash(
8738: m => 'Use Apache mod_remoteip',
8739: h => 'Use headers parsed by LON-CAPA',
8740: n => 'Not in use',
1.373 raeburn 8741: );
8742: }
8743:
1.137 raeburn 8744: sub print_usersessions {
8745: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 8746: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 8747: my (%by_ip,%by_location,@intdoms,@instdoms);
8748: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 8749:
8750: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 8751: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 8752: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 8753: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 8754: if ($position eq 'top') {
1.152 raeburn 8755: if (keys(%serverhomes) > 1) {
1.145 raeburn 8756: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.371 raeburn 8757: my ($curroffloadnow,$curroffloadoth);
1.261 raeburn 8758: if (ref($settings) eq 'HASH') {
8759: if (ref($settings->{'offloadnow'}) eq 'HASH') {
8760: $curroffloadnow = $settings->{'offloadnow'};
8761: }
1.371 raeburn 8762: if (ref($settings->{'offloadoth'}) eq 'HASH') {
8763: $curroffloadoth = $settings->{'offloadoth'};
8764: }
1.261 raeburn 8765: }
1.371 raeburn 8766: my $other_insts = scalar(keys(%by_location));
8767: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
8768: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 8769: } else {
1.140 raeburn 8770: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 8771: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
8772: '</td></tr>';
1.140 raeburn 8773: }
1.137 raeburn 8774: } else {
1.279 raeburn 8775: my %titles = &usersession_titles();
8776: my ($prefix,@types);
8777: if ($position eq 'bottom') {
8778: $prefix = 'remote';
8779: @types = ('version','excludedomain','includedomain');
1.145 raeburn 8780: } else {
1.279 raeburn 8781: $prefix = 'hosted';
8782: @types = ('excludedomain','includedomain');
8783: }
8784: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8785: }
8786: $$rowtotal += $itemcount;
8787: return $datatable;
8788: }
8789:
8790: sub rules_by_location {
8791: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
8792: my ($datatable,$itemcount,$css_class);
8793: if (keys(%{$by_location}) == 0) {
8794: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8795: $datatable = '<tr'.$css_class.'><td colspan="2">'.
8796: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
8797: '</td></tr>';
8798: $itemcount = 1;
8799: } else {
8800: $itemcount = 0;
8801: my $numinrow = 5;
8802: my (%current,%checkedon,%checkedoff);
8803: my @locations = sort(keys(%{$by_location}));
8804: foreach my $type (@{$types}) {
8805: $checkedon{$type} = '';
8806: $checkedoff{$type} = ' checked="checked"';
8807: }
8808: if (ref($settings) eq 'HASH') {
8809: if (ref($settings->{$prefix}) eq 'HASH') {
8810: foreach my $key (keys(%{$settings->{$prefix}})) {
8811: $current{$key} = $settings->{$prefix}{$key};
8812: if ($key eq 'version') {
8813: if ($current{$key} ne '') {
1.145 raeburn 8814: $checkedon{$key} = ' checked="checked"';
8815: $checkedoff{$key} = '';
8816: }
1.279 raeburn 8817: } elsif (ref($current{$key}) eq 'ARRAY') {
8818: $checkedon{$key} = ' checked="checked"';
8819: $checkedoff{$key} = '';
1.137 raeburn 8820: }
8821: }
8822: }
1.279 raeburn 8823: }
8824: foreach my $type (@{$types}) {
8825: next if ($type ne 'version' && !@locations);
8826: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8827: $datatable .= '<tr'.$css_class.'>
8828: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
8829: <span class="LC_nobreak">
8830: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
8831: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
8832: if ($type eq 'version') {
8833: my @lcversions = &Apache::lonnet::all_loncaparevs();
8834: my $selector = '<select name="'.$prefix.'_version">';
8835: foreach my $version (@lcversions) {
8836: my $selected = '';
8837: if ($current{'version'} eq $version) {
8838: $selected = ' selected="selected"';
1.145 raeburn 8839: }
1.279 raeburn 8840: $selector .= ' <option value="'.$version.'"'.
8841: $selected.'>'.$version.'</option>';
8842: }
8843: $selector .= '</select> ';
8844: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
8845: } else {
8846: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
8847: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
8848: ' />'.(' 'x2).
8849: '<input type="button" value="'.&mt('uncheck all').'" '.
8850: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
8851: "\n".
8852: '</div><div><table>';
8853: my $rem;
8854: for (my $i=0; $i<@locations; $i++) {
8855: my ($showloc,$value,$checkedtype);
8856: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
8857: my $ip = $by_location->{$locations[$i]}->[0];
8858: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8859: $value = join(':',@{$by_ip->{$ip}});
8860: $showloc = join(', ',@{$by_ip->{$ip}});
8861: if (ref($current{$type}) eq 'ARRAY') {
8862: foreach my $loc (@{$by_ip->{$ip}}) {
8863: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
8864: $checkedtype = ' checked="checked"';
8865: last;
1.145 raeburn 8866: }
1.138 raeburn 8867: }
8868: }
8869: }
1.137 raeburn 8870: }
1.279 raeburn 8871: $rem = $i%($numinrow);
8872: if ($rem == 0) {
8873: if ($i > 0) {
8874: $datatable .= '</tr>';
8875: }
8876: $datatable .= '<tr>';
8877: }
8878: $datatable .= '<td class="LC_left_item">'.
8879: '<span class="LC_nobreak"><label>'.
8880: '<input type="checkbox" name="'.$prefix.'_'.$type.
8881: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
8882: '</label></span></td>';
8883: }
8884: $rem = @locations%($numinrow);
8885: my $colsleft = $numinrow - $rem;
8886: if ($colsleft > 1 ) {
8887: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8888: ' </td>';
8889: } elsif ($colsleft == 1) {
8890: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 8891: }
1.279 raeburn 8892: $datatable .= '</tr></table>';
1.137 raeburn 8893: }
1.279 raeburn 8894: $datatable .= '</td></tr>';
8895: $itemcount ++;
1.137 raeburn 8896: }
8897: }
1.279 raeburn 8898: return ($datatable,$itemcount);
1.137 raeburn 8899: }
8900:
1.275 raeburn 8901: sub print_ssl {
8902: my ($position,$dom,$settings,$rowtotal) = @_;
8903: my ($css_class,$datatable);
8904: my $itemcount = 1;
8905: if ($position eq 'top') {
1.281 raeburn 8906: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8907: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8908: my $same_institution;
8909: if ($intdom ne '') {
8910: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
8911: if (ref($internet_names) eq 'ARRAY') {
8912: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
8913: $same_institution = 1;
8914: }
8915: }
8916: }
1.275 raeburn 8917: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 8918: $datatable = '<tr'.$css_class.'><td colspan="2">';
8919: if ($same_institution) {
8920: my %domservers = &Apache::lonnet::get_servers($dom);
8921: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
8922: } else {
8923: $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.");
8924: }
8925: $datatable .= '</td></tr>';
1.275 raeburn 8926: $itemcount ++;
8927: } else {
8928: my %titles = &ssl_titles();
8929: my (%by_ip,%by_location,@intdoms,@instdoms);
8930: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8931: my @alldoms = &Apache::lonnet::all_domains();
8932: my %serverhomes = %Apache::lonnet::serverhomeIDs;
8933: my @domservers = &Apache::lonnet::get_servers($dom);
8934: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8935: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 8936: if (($position eq 'connto') || ($position eq 'connfrom')) {
8937: my $legacy;
8938: unless (ref($settings) eq 'HASH') {
8939: my $name;
8940: if ($position eq 'connto') {
8941: $name = 'loncAllowInsecure';
8942: } else {
8943: $name = 'londAllowInsecure';
8944: }
8945: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
8946: my @ids=&Apache::lonnet::current_machine_ids();
8947: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
8948: my %what = (
8949: $name => 1,
8950: );
8951: my ($result,$returnhash) =
8952: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
8953: if ($result eq 'ok') {
8954: if (ref($returnhash) eq 'HASH') {
8955: $legacy = $returnhash->{$name};
8956: }
8957: }
8958: } else {
8959: $legacy = $Apache::lonnet::perlvar{$name};
8960: }
8961: }
1.275 raeburn 8962: foreach my $type ('dom','intdom','other') {
8963: my %checked;
8964: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8965: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
8966: '<td class="LC_right_item">';
8967: my $skip;
8968: if ($type eq 'dom') {
8969: unless (keys(%servers) > 1) {
8970: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
8971: $skip = 1;
8972: }
8973: }
8974: if ($type eq 'intdom') {
8975: unless (@instdoms > 1) {
8976: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
8977: $skip = 1;
8978: }
8979: } elsif ($type eq 'other') {
8980: if (keys(%by_location) == 0) {
8981: $datatable .= &mt('Nothing to set here, as there are no other institutions');
8982: $skip = 1;
8983: }
8984: }
8985: unless ($skip) {
8986: $checked{'yes'} = ' checked="checked"';
8987: if (ref($settings) eq 'HASH') {
1.293 raeburn 8988: if (ref($settings->{$position}) eq 'HASH') {
8989: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 8990: $checked{$1} = $checked{'yes'};
8991: delete($checked{'yes'});
8992: }
8993: }
1.293 raeburn 8994: } else {
8995: if ($legacy == 0) {
8996: $checked{'req'} = $checked{'yes'};
8997: delete($checked{'yes'});
8998: }
1.275 raeburn 8999: }
9000: foreach my $option ('no','yes','req') {
9001: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 9002: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 9003: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
9004: '</label></span>'.(' 'x2);
9005: }
9006: }
9007: $datatable .= '</td></tr>';
9008: $itemcount ++;
9009: }
9010: } else {
9011: my $prefix = 'replication';
9012: my @types = ('certreq','nocertreq');
1.279 raeburn 9013: if (keys(%by_location) == 0) {
9014: $datatable .= '<tr'.$css_class.'><td>'.
9015: &mt('Nothing to set here, as there are no other institutions').
9016: '</td></tr>';
9017: $itemcount ++;
1.275 raeburn 9018: } else {
1.279 raeburn 9019: ($datatable,$itemcount) =
9020: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 9021: }
9022: }
9023: }
9024: $$rowtotal += $itemcount;
9025: return $datatable;
9026: }
9027:
9028: sub ssl_titles {
9029: return &Apache::lonlocal::texthash (
9030: dom => 'LON-CAPA servers/VMs from same domain',
9031: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
9032: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 9033: connto => 'Connections to other servers',
9034: connfrom => 'Connections from other servers',
1.275 raeburn 9035: replication => 'Replicating content to other institutions',
9036: certreq => 'Client certificate required, but specific domains exempt',
9037: nocertreq => 'No client certificate required, except for specific domains',
9038: no => 'SSL not used',
9039: yes => 'SSL Optional (used if available)',
9040: req => 'SSL Required',
9041: );
1.279 raeburn 9042: }
9043:
9044: sub print_trust {
9045: my ($prefix,$dom,$settings,$rowtotal) = @_;
9046: my ($css_class,$datatable,%checked,%choices);
9047: my (%by_ip,%by_location,@intdoms,@instdoms);
9048: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
9049: my $itemcount = 1;
9050: my %titles = &trust_titles();
9051: my @types = ('exc','inc');
9052: if ($prefix eq 'top') {
9053: $prefix = 'content';
9054: } elsif ($prefix eq 'bottom') {
9055: $prefix = 'msg';
9056: }
9057: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
9058: $$rowtotal += $itemcount;
9059: return $datatable;
9060: }
9061:
9062: sub trust_titles {
9063: return &Apache::lonlocal::texthash(
9064: content => "Access to this domain's content by others",
9065: shared => "Access to other domain's content by this domain",
9066: enroll => "Enrollment in this domain's courses by others",
9067: othcoau => "Co-author roles in this domain for others",
9068: coaurem => "Co-author roles for this domain's users elsewhere",
9069: domroles => "Domain roles in this domain assignable to others",
9070: catalog => "Course Catalog for this domain displayed elsewhere",
9071: reqcrs => "Requests for creation of courses in this domain by others",
9072: msg => "Users in other domains can send messages to this domain",
9073: exc => "Allow all, but exclude specific domains",
9074: inc => "Deny all, but include specific domains",
9075: );
1.275 raeburn 9076: }
9077:
1.138 raeburn 9078: sub build_location_hashes {
1.275 raeburn 9079: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 9080: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 9081: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 9082: my %iphost = &Apache::lonnet::get_iphost();
9083: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
9084: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
9085: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
9086: foreach my $id (@{$iphost{$primary_ip}}) {
9087: my $intdom = &Apache::lonnet::internet_dom($id);
9088: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
9089: push(@{$intdoms},$intdom);
9090: }
9091: }
9092: }
9093: foreach my $ip (keys(%iphost)) {
9094: if (ref($iphost{$ip}) eq 'ARRAY') {
9095: foreach my $id (@{$iphost{$ip}}) {
9096: my $location = &Apache::lonnet::internet_dom($id);
9097: if ($location) {
1.275 raeburn 9098: if (grep(/^\Q$location\E$/,@{$intdoms})) {
9099: my $dom = &Apache::lonnet::host_domain($id);
9100: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
9101: push(@{$instdoms},$dom);
9102: }
9103: next;
9104: }
1.138 raeburn 9105: if (ref($by_ip->{$ip}) eq 'ARRAY') {
9106: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
9107: push(@{$by_ip->{$ip}},$location);
9108: }
9109: } else {
9110: $by_ip->{$ip} = [$location];
9111: }
9112: }
9113: }
9114: }
9115: }
9116: foreach my $ip (sort(keys(%{$by_ip}))) {
9117: if (ref($by_ip->{$ip}) eq 'ARRAY') {
9118: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
9119: my $first = $by_ip->{$ip}->[0];
9120: if (ref($by_location->{$first}) eq 'ARRAY') {
9121: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
9122: push(@{$by_location->{$first}},$ip);
9123: }
9124: } else {
9125: $by_location->{$first} = [$ip];
9126: }
9127: }
9128: }
9129: return;
9130: }
9131:
1.145 raeburn 9132: sub current_offloads_to {
9133: my ($dom,$settings,$servers) = @_;
9134: my (%spareid,%otherdomconfigs);
1.152 raeburn 9135: if (ref($servers) eq 'HASH') {
1.145 raeburn 9136: foreach my $lonhost (sort(keys(%{$servers}))) {
9137: my $gotspares;
1.152 raeburn 9138: if (ref($settings) eq 'HASH') {
9139: if (ref($settings->{'spares'}) eq 'HASH') {
9140: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
9141: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
9142: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
9143: $gotspares = 1;
9144: }
1.145 raeburn 9145: }
9146: }
9147: unless ($gotspares) {
9148: my $gotspares;
9149: my $serverhomeID =
9150: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
9151: my $serverhomedom =
9152: &Apache::lonnet::host_domain($serverhomeID);
9153: if ($serverhomedom ne $dom) {
9154: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
9155: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
9156: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
9157: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
9158: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
9159: $gotspares = 1;
9160: }
9161: }
9162: } else {
9163: $otherdomconfigs{$serverhomedom} =
9164: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
9165: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
9166: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
9167: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
9168: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
9169: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
9170: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
9171: $gotspares = 1;
9172: }
9173: }
9174: }
9175: }
9176: }
9177: }
9178: }
9179: unless ($gotspares) {
9180: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
9181: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9182: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9183: } else {
9184: my $server_hostname = &Apache::lonnet::hostname($lonhost);
9185: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
9186: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
9187: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9188: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9189: } else {
1.150 raeburn 9190: my %what = (
9191: spareid => 1,
9192: );
9193: my ($result,$returnhash) =
9194: &Apache::lonnet::get_remote_globals($lonhost,\%what);
9195: if ($result eq 'ok') {
9196: if (ref($returnhash) eq 'HASH') {
9197: if (ref($returnhash->{'spareid'}) eq 'HASH') {
9198: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
9199: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
9200: }
9201: }
1.145 raeburn 9202: }
9203: }
9204: }
9205: }
9206: }
9207: }
9208: return %spareid;
9209: }
9210:
9211: sub spares_row {
1.371 raeburn 9212: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
9213: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 9214: my $css_class;
9215: my $numinrow = 4;
9216: my $itemcount = 1;
9217: my $datatable;
1.152 raeburn 9218: my %typetitles = &sparestype_titles();
9219: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 9220: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 9221: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
9222: my ($othercontrol,$serverdom);
9223: if ($serverhome ne $server) {
9224: $serverdom = &Apache::lonnet::host_domain($serverhome);
9225: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9226: } else {
9227: $serverdom = &Apache::lonnet::host_domain($server);
9228: if ($serverdom ne $dom) {
9229: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9230: }
9231: }
9232: next unless (ref($spareid->{$server}) eq 'HASH');
1.371 raeburn 9233: my ($checkednow,$checkedoth);
1.261 raeburn 9234: if (ref($curroffloadnow) eq 'HASH') {
9235: if ($curroffloadnow->{$server}) {
9236: $checkednow = ' checked="checked"';
9237: }
9238: }
1.371 raeburn 9239: if (ref($curroffloadoth) eq 'HASH') {
9240: if ($curroffloadoth->{$server}) {
9241: $checkedoth = ' checked="checked"';
9242: }
9243: }
1.145 raeburn 9244: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
9245: $datatable .= '<tr'.$css_class.'>
9246: <td rowspan="2">
1.183 bisitz 9247: <span class="LC_nobreak">'.
9248: &mt('[_1] when busy, offloads to:'
1.261 raeburn 9249: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 9250: '<span class="LC_nobreak">'."\n".
1.261 raeburn 9251: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.371 raeburn 9252: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.183 bisitz 9253: "\n";
1.371 raeburn 9254: if ($other_insts) {
9255: $datatable .= '<br />'.
9256: '<span class="LC_nobreak">'."\n".
9257: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
9258: ' '.&mt('Switch other institutions on next access').'</label></span>'.
9259: "\n";
9260: }
1.145 raeburn 9261: my (%current,%canselect);
1.152 raeburn 9262: my @choices =
9263: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
9264: foreach my $type ('primary','default') {
9265: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 9266: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
9267: my @spares = @{$spareid->{$server}{$type}};
9268: if (@spares > 0) {
1.152 raeburn 9269: if ($othercontrol) {
9270: $current{$type} = join(', ',@spares);
9271: } else {
9272: $current{$type} .= '<table>';
9273: my $numspares = scalar(@spares);
9274: for (my $i=0; $i<@spares; $i++) {
9275: my $rem = $i%($numinrow);
9276: if ($rem == 0) {
9277: if ($i > 0) {
9278: $current{$type} .= '</tr>';
9279: }
9280: $current{$type} .= '<tr>';
1.145 raeburn 9281: }
1.152 raeburn 9282: $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'".');" /> '.
9283: $spareid->{$server}{$type}[$i].
9284: '</label></td>'."\n";
9285: }
9286: my $rem = @spares%($numinrow);
9287: my $colsleft = $numinrow - $rem;
9288: if ($colsleft > 1 ) {
9289: $current{$type} .= '<td colspan="'.$colsleft.
9290: '" class="LC_left_item">'.
9291: ' </td>';
9292: } elsif ($colsleft == 1) {
9293: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 9294: }
1.152 raeburn 9295: $current{$type} .= '</tr></table>';
1.150 raeburn 9296: }
1.145 raeburn 9297: }
9298: }
9299: if ($current{$type} eq '') {
9300: $current{$type} = &mt('None specified');
9301: }
1.152 raeburn 9302: if ($othercontrol) {
9303: if ($type eq 'primary') {
9304: $canselect{$type} = $othercontrol;
9305: }
9306: } else {
9307: $canselect{$type} =
9308: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
9309: '<select name="newspare_'.$type.'_'.$server.'" '.
9310: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
9311: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
9312: if (@choices > 0) {
9313: foreach my $lonhost (@choices) {
9314: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
9315: }
9316: }
9317: $canselect{$type} .= '</select>'."\n";
9318: }
9319: } else {
9320: $current{$type} = &mt('Could not be determined');
9321: if ($type eq 'primary') {
9322: $canselect{$type} = $othercontrol;
9323: }
1.145 raeburn 9324: }
1.152 raeburn 9325: if ($type eq 'default') {
9326: $datatable .= '<tr'.$css_class.'>';
9327: }
9328: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
9329: '<td>'.$current{$type}.'</td>'."\n".
9330: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 9331: }
9332: $itemcount ++;
9333: }
9334: }
9335: $$rowtotal += $itemcount;
9336: return $datatable;
9337: }
9338:
1.152 raeburn 9339: sub possible_newspares {
9340: my ($server,$currspares,$serverhomes,$altids) = @_;
9341: my $serverhostname = &Apache::lonnet::hostname($server);
9342: my %excluded;
9343: if ($serverhostname ne '') {
9344: %excluded = (
9345: $serverhostname => 1,
9346: );
9347: }
9348: if (ref($currspares) eq 'HASH') {
9349: foreach my $type (keys(%{$currspares})) {
9350: if (ref($currspares->{$type}) eq 'ARRAY') {
9351: if (@{$currspares->{$type}} > 0) {
9352: foreach my $curr (@{$currspares->{$type}}) {
9353: my $hostname = &Apache::lonnet::hostname($curr);
9354: $excluded{$hostname} = 1;
9355: }
9356: }
9357: }
9358: }
9359: }
9360: my @choices;
9361: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
9362: if (keys(%{$serverhomes}) > 1) {
9363: foreach my $name (sort(keys(%{$serverhomes}))) {
9364: unless ($excluded{$name}) {
9365: if (exists($altids->{$serverhomes->{$name}})) {
9366: push(@choices,$altids->{$serverhomes->{$name}});
9367: } else {
9368: push(@choices,$serverhomes->{$name});
1.145 raeburn 9369: }
9370: }
9371: }
9372: }
9373: }
1.152 raeburn 9374: return sort(@choices);
1.145 raeburn 9375: }
9376:
1.150 raeburn 9377: sub print_loadbalancing {
9378: my ($dom,$settings,$rowtotal) = @_;
9379: my $primary_id = &Apache::lonnet::domain($dom,'primary');
9380: my $intdom = &Apache::lonnet::internet_dom($primary_id);
9381: my $numinrow = 1;
9382: my $datatable;
9383: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 9384: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 9385: if (ref($settings) eq 'HASH') {
9386: %existing = %{$settings};
9387: }
9388: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
9389: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 9390: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 9391: } else {
9392: return;
9393: }
9394: my ($othertitle,$usertypes,$types) =
9395: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 9396: my $rownum = 8;
1.150 raeburn 9397: if (ref($types) eq 'ARRAY') {
9398: $rownum += scalar(@{$types});
9399: }
1.171 raeburn 9400: my @css_class = ('LC_odd_row','LC_even_row');
9401: my $balnum = 0;
9402: my $islast;
9403: my (@toshow,$disabledtext);
9404: if (keys(%currbalancer) > 0) {
9405: @toshow = sort(keys(%currbalancer));
9406: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
9407: push(@toshow,'');
9408: }
9409: } else {
9410: @toshow = ('');
9411: $disabledtext = &mt('No existing load balancer');
9412: }
9413: foreach my $lonhost (@toshow) {
9414: if ($balnum == scalar(@toshow)-1) {
9415: $islast = 1;
9416: } else {
9417: $islast = 0;
9418: }
9419: my $cssidx = $balnum%2;
9420: my $targets_div_style = 'display: none';
9421: my $disabled_div_style = 'display: block';
9422: my $homedom_div_style = 'display: none';
9423: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 9424: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9425: '<p>';
9426: if ($lonhost eq '') {
1.210 raeburn 9427: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 9428: if (keys(%currbalancer) > 0) {
9429: $datatable .= &mt('Add balancer:');
9430: } else {
9431: $datatable .= &mt('Enable balancer:');
9432: }
9433: $datatable .= ' '.
9434: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
9435: ' id="loadbalancing_lonhost_'.$balnum.'"'.
9436: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
9437: '<option value="" selected="selected">'.&mt('None').
9438: '</option>'."\n";
9439: foreach my $server (sort(keys(%servers))) {
9440: next if ($currbalancer{$server});
9441: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
9442: }
1.210 raeburn 9443: $datatable .=
1.171 raeburn 9444: '</select>'."\n".
9445: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
9446: } else {
9447: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
9448: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
9449: &mt('Stop balancing').'</label>'.
9450: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
9451: $targets_div_style = 'display: block';
9452: $disabled_div_style = 'display: none';
9453: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
9454: $homedom_div_style = 'display: block';
9455: }
9456: }
1.306 raeburn 9457: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9458: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
9459: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
9460: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
9461: my ($numspares,@spares) = &count_servers($lonhost,%servers);
9462: my @sparestypes = ('primary','default');
9463: my %typetitles = &sparestype_titles();
1.284 raeburn 9464: my %hostherechecked = (
9465: no => ' checked="checked"',
9466: );
1.342 raeburn 9467: my %balcookiechecked = (
1.425 raeburn 9468: no => ' checked="checked"',
1.342 raeburn 9469: );
1.171 raeburn 9470: foreach my $sparetype (@sparestypes) {
9471: my $targettable;
9472: for (my $i=0; $i<$numspares; $i++) {
9473: my $checked;
9474: if (ref($currtargets{$lonhost}) eq 'HASH') {
9475: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9476: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9477: $checked = ' checked="checked"';
9478: }
9479: }
9480: }
9481: my ($chkboxval,$disabled);
9482: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
9483: $chkboxval = $spares[$i];
9484: }
9485: if (exists($currbalancer{$spares[$i]})) {
9486: $disabled = ' disabled="disabled"';
9487: }
1.210 raeburn 9488: $targettable .=
1.253 raeburn 9489: '<td><span class="LC_nobreak"><label>'.
9490: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 9491: $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 9492: '</span></label></span></td>';
1.171 raeburn 9493: my $rem = $i%($numinrow);
9494: if ($rem == 0) {
9495: if (($i > 0) && ($i < $numspares-1)) {
9496: $targettable .= '</tr>';
9497: }
9498: if ($i < $numspares-1) {
9499: $targettable .= '<tr>';
1.150 raeburn 9500: }
9501: }
9502: }
1.171 raeburn 9503: if ($targettable ne '') {
9504: my $rem = $numspares%($numinrow);
9505: my $colsleft = $numinrow - $rem;
9506: if ($colsleft > 1 ) {
9507: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9508: ' </td>';
9509: } elsif ($colsleft == 1) {
9510: $targettable .= '<td class="LC_left_item"> </td>';
9511: }
9512: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
9513: '<table><tr>'.$targettable.'</tr></table><br />';
9514: }
1.284 raeburn 9515: $hostherechecked{$sparetype} = '';
9516: if (ref($currtargets{$lonhost}) eq 'HASH') {
9517: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9518: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9519: $hostherechecked{$sparetype} = ' checked="checked"';
9520: $hostherechecked{'no'} = '';
9521: }
9522: }
9523: }
9524: }
1.342 raeburn 9525: if ($currcookies{$lonhost}) {
9526: %balcookiechecked = (
9527: yes => ' checked="checked"',
9528: );
9529: }
1.284 raeburn 9530: $datatable .= &mt('Hosting on balancer itself').'<br />'.
9531: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
9532: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
9533: foreach my $sparetype (@sparestypes) {
9534: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
9535: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
9536: '</i></label><br />';
1.171 raeburn 9537: }
1.342 raeburn 9538: $datatable .= &mt('Use balancer cookie').'<br />'.
9539: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
9540: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
9541: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
9542: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
9543: '</div></td></tr>'.
1.171 raeburn 9544: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
9545: $othertitle,$usertypes,$types,\%servers,
9546: \%currbalancer,$lonhost,
9547: $targets_div_style,$homedom_div_style,
9548: $css_class[$cssidx],$balnum,$islast);
9549: $$rowtotal += $rownum;
9550: $balnum ++;
9551: }
9552: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
9553: return $datatable;
9554: }
9555:
9556: sub get_loadbalancers_config {
1.342 raeburn 9557: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 9558: return unless ((ref($servers) eq 'HASH') &&
9559: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 9560: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
9561: (ref($currcookies) eq 'HASH'));
1.171 raeburn 9562: if (keys(%{$existing}) > 0) {
9563: my $oldlonhost;
9564: foreach my $key (sort(keys(%{$existing}))) {
9565: if ($key eq 'lonhost') {
9566: $oldlonhost = $existing->{'lonhost'};
9567: $currbalancer->{$oldlonhost} = 1;
9568: } elsif ($key eq 'targets') {
9569: if ($oldlonhost) {
9570: $currtargets->{$oldlonhost} = $existing->{'targets'};
9571: }
9572: } elsif ($key eq 'rules') {
9573: if ($oldlonhost) {
9574: $currrules->{$oldlonhost} = $existing->{'rules'};
9575: }
9576: } elsif (ref($existing->{$key}) eq 'HASH') {
9577: $currbalancer->{$key} = 1;
9578: $currtargets->{$key} = $existing->{$key}{'targets'};
9579: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 9580: if ($existing->{$key}{'cookie'}) {
9581: $currcookies->{$key} = 1;
9582: }
1.150 raeburn 9583: }
9584: }
1.171 raeburn 9585: } else {
9586: my ($balancerref,$targetsref) =
9587: &Apache::lonnet::get_lonbalancer_config($servers);
9588: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
9589: foreach my $server (sort(keys(%{$balancerref}))) {
9590: $currbalancer->{$server} = 1;
9591: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 9592: }
9593: }
9594: }
1.171 raeburn 9595: return;
1.150 raeburn 9596: }
9597:
9598: sub loadbalancing_rules {
9599: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 9600: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
9601: $css_class,$balnum,$islast) = @_;
1.150 raeburn 9602: my $output;
1.171 raeburn 9603: my $num = 0;
1.210 raeburn 9604: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 9605: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
9606: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
9607: foreach my $type (@{$alltypes}) {
1.171 raeburn 9608: $num ++;
1.150 raeburn 9609: my $current;
9610: if (ref($currrules) eq 'HASH') {
9611: $current = $currrules->{$type};
9612: }
1.253 raeburn 9613: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 9614: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 9615: $current = '';
9616: }
9617: }
9618: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 9619: $servers,$currbalancer,$lonhost,$dom,
9620: $targets_div_style,$homedom_div_style,
9621: $css_class,$balnum,$num,$islast);
1.150 raeburn 9622: }
9623: }
9624: return $output;
9625: }
9626:
9627: sub loadbalancing_titles {
9628: my ($dom,$intdom,$usertypes,$types) = @_;
9629: my %othertypes = (
9630: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
9631: '_LC_author' => &mt('Users from [_1] with author role',$dom),
9632: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
9633: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 9634: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
9635: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 9636: );
1.209 raeburn 9637: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 9638: my @available;
1.150 raeburn 9639: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9640: @available = @{$types};
1.150 raeburn 9641: }
1.302 raeburn 9642: unless (grep(/^default$/,@available)) {
9643: push(@available,'default');
9644: }
9645: unshift(@alltypes,@available);
1.150 raeburn 9646: my %titles;
9647: foreach my $type (@alltypes) {
9648: if ($type =~ /^_LC_/) {
9649: $titles{$type} = $othertypes{$type};
9650: } elsif ($type eq 'default') {
9651: $titles{$type} = &mt('All users from [_1]',$dom);
9652: if (ref($types) eq 'ARRAY') {
9653: if (@{$types} > 0) {
9654: $titles{$type} = &mt('Other users from [_1]',$dom);
9655: }
9656: }
9657: } elsif (ref($usertypes) eq 'HASH') {
9658: $titles{$type} = $usertypes->{$type};
9659: }
9660: }
9661: return (\@alltypes,\%othertypes,\%titles);
9662: }
9663:
9664: sub loadbalance_rule_row {
1.171 raeburn 9665: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
9666: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 9667: my @rulenames;
1.150 raeburn 9668: my %ruletitles = &offloadtype_text();
1.209 raeburn 9669: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 9670: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 9671: } else {
1.209 raeburn 9672: @rulenames = ('default','homeserver');
9673: if ($type eq '_LC_external') {
9674: push(@rulenames,'externalbalancer');
9675: } else {
9676: push(@rulenames,'specific');
9677: }
9678: push(@rulenames,'none');
1.150 raeburn 9679: }
9680: my $style = $targets_div_style;
1.253 raeburn 9681: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 9682: $style = $homedom_div_style;
9683: }
1.171 raeburn 9684: my $space;
9685: if ($islast && $num == 1) {
1.317 raeburn 9686: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 9687: }
1.210 raeburn 9688: my $output =
1.306 raeburn 9689: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 9690: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
9691: '<td valaign="top">'.$space.
9692: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 9693: for (my $i=0; $i<@rulenames; $i++) {
9694: my $rule = $rulenames[$i];
9695: my ($checked,$extra);
9696: if ($rulenames[$i] eq 'default') {
9697: $rule = '';
9698: }
9699: if ($rulenames[$i] eq 'specific') {
9700: if (ref($servers) eq 'HASH') {
9701: my $default;
9702: if (($current ne '') && (exists($servers->{$current}))) {
9703: $checked = ' checked="checked"';
9704: }
9705: unless ($checked) {
9706: $default = ' selected="selected"';
9707: }
1.210 raeburn 9708: $extra =
1.171 raeburn 9709: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
9710: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
9711: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
9712: '<option value=""'.$default.'></option>'."\n";
9713: foreach my $server (sort(keys(%{$servers}))) {
9714: if (ref($currbalancer) eq 'HASH') {
9715: next if (exists($currbalancer->{$server}));
9716: }
1.150 raeburn 9717: my $selected;
1.171 raeburn 9718: if ($server eq $current) {
1.150 raeburn 9719: $selected = ' selected="selected"';
9720: }
1.171 raeburn 9721: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 9722: }
9723: $extra .= '</select>';
9724: }
9725: } elsif ($rule eq $current) {
9726: $checked = ' checked="checked"';
9727: }
9728: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 9729: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
9730: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
9731: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 9732: ')"'.$checked.' /> ';
9733: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
9734: $output .= $ruletitles{'particular'};
9735: } else {
9736: $output .= $ruletitles{$rulenames[$i]};
9737: }
9738: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 9739: }
9740: $output .= '</div></td></tr>'."\n";
9741: return $output;
9742: }
9743:
9744: sub offloadtype_text {
9745: my %ruletitles = &Apache::lonlocal::texthash (
9746: 'default' => 'Offloads to default destinations',
9747: 'homeserver' => "Offloads to user's home server",
9748: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
9749: 'specific' => 'Offloads to specific server',
1.161 raeburn 9750: 'none' => 'No offload',
1.209 raeburn 9751: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
9752: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 9753: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 9754: );
9755: return %ruletitles;
9756: }
9757:
9758: sub sparestype_titles {
9759: my %typestitles = &Apache::lonlocal::texthash (
9760: 'primary' => 'primary',
9761: 'default' => 'default',
9762: );
9763: return %typestitles;
9764: }
9765:
1.28 raeburn 9766: sub contact_titles {
9767: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 9768: 'supportemail' => 'Support E-mail address',
9769: 'adminemail' => 'Default Server Admin E-mail address',
9770: 'errormail' => 'Error reports to be e-mailed to',
9771: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 9772: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
9773: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 9774: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
9775: 'requestsmail' => 'E-mail from course requests requiring approval',
9776: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 9777: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350 raeburn 9778: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.378 raeburn 9779: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
9780: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.340 raeburn 9781: 'errorweights' => 'Weights used to compute error count',
9782: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 9783: );
9784: my %short_titles = &Apache::lonlocal::texthash (
9785: adminemail => 'Admin E-mail address',
9786: supportemail => 'Support E-mail',
9787: );
9788: return (\%titles,\%short_titles);
9789: }
9790:
1.286 raeburn 9791: sub helpform_fields {
9792: my %titles = &Apache::lonlocal::texthash (
9793: 'username' => 'Name',
9794: 'user' => 'Username/domain',
9795: 'phone' => 'Phone',
9796: 'cc' => 'Cc e-mail',
9797: 'course' => 'Course Details',
9798: 'section' => 'Sections',
1.289 raeburn 9799: 'screenshot' => 'File upload',
1.286 raeburn 9800: );
9801: my @fields = ('username','phone','user','course','section','cc','screenshot');
9802: my %possoptions = (
9803: username => ['yes','no','req'],
1.289 raeburn 9804: phone => ['yes','no','req'],
1.286 raeburn 9805: user => ['yes','no'],
1.289 raeburn 9806: cc => ['yes','no'],
1.286 raeburn 9807: course => ['yes','no'],
9808: section => ['yes','no'],
9809: screenshot => ['yes','no'],
9810: );
9811: my %fieldoptions = &Apache::lonlocal::texthash (
9812: 'yes' => 'Optional',
9813: 'req' => 'Required',
9814: 'no' => "Not shown",
9815: );
9816: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
9817: }
9818:
1.72 raeburn 9819: sub tool_titles {
9820: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 9821: aboutme => 'Personal web page',
1.86 raeburn 9822: blog => 'Blog',
9823: portfolio => 'Portfolio',
1.430 raeburn 9824: portaccess => 'Share portfolio files',
1.413 raeburn 9825: timezone => 'Can set time zone',
1.88 bisitz 9826: official => 'Official courses (with institutional codes)',
9827: unofficial => 'Unofficial courses',
1.98 raeburn 9828: community => 'Communities',
1.216 raeburn 9829: textbook => 'Textbook courses',
1.271 raeburn 9830: placement => 'Placement tests',
1.86 raeburn 9831: );
1.72 raeburn 9832: return %titles;
9833: }
9834:
1.101 raeburn 9835: sub courserequest_titles {
9836: my %titles = &Apache::lonlocal::texthash (
9837: official => 'Official',
9838: unofficial => 'Unofficial',
9839: community => 'Communities',
1.216 raeburn 9840: textbook => 'Textbook',
1.271 raeburn 9841: placement => 'Placement tests',
1.325 raeburn 9842: lti => 'LTI Provider',
1.101 raeburn 9843: norequest => 'Not allowed',
1.325 raeburn 9844: approval => 'Approval by DC',
1.101 raeburn 9845: validate => 'With validation',
9846: autolimit => 'Numerical limit',
1.103 raeburn 9847: unlimited => '(blank for unlimited)',
1.101 raeburn 9848: );
9849: return %titles;
9850: }
9851:
1.163 raeburn 9852: sub authorrequest_titles {
9853: my %titles = &Apache::lonlocal::texthash (
9854: norequest => 'Not allowed',
9855: approval => 'Approval by Dom. Coord.',
9856: automatic => 'Automatic approval',
9857: );
9858: return %titles;
1.210 raeburn 9859: }
1.163 raeburn 9860:
1.101 raeburn 9861: sub courserequest_conditions {
9862: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 9863: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 9864: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 9865: );
9866: return %conditions;
9867: }
9868:
9869:
1.27 raeburn 9870: sub print_usercreation {
1.30 raeburn 9871: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 9872: my $numinrow = 4;
1.28 raeburn 9873: my $datatable;
9874: if ($position eq 'top') {
1.30 raeburn 9875: $$rowtotal ++;
1.34 raeburn 9876: my $rowcount = 0;
1.32 raeburn 9877: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 9878: if (ref($rules) eq 'HASH') {
9879: if (keys(%{$rules}) > 0) {
1.32 raeburn 9880: $datatable .= &user_formats_row('username',$settings,$rules,
9881: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 9882: $$rowtotal ++;
1.32 raeburn 9883: $rowcount ++;
9884: }
9885: }
9886: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
9887: if (ref($idrules) eq 'HASH') {
9888: if (keys(%{$idrules}) > 0) {
9889: $datatable .= &user_formats_row('id',$settings,$idrules,
9890: $idruleorder,$numinrow,$rowcount);
9891: $$rowtotal ++;
9892: $rowcount ++;
1.28 raeburn 9893: }
9894: }
1.39 raeburn 9895: if ($rowcount == 0) {
9896: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
9897: $$rowtotal ++;
9898: $rowcount ++;
9899: }
1.34 raeburn 9900: } elsif ($position eq 'middle') {
1.224 raeburn 9901: my @creators = ('author','course','requestcrs');
1.37 raeburn 9902: my ($rules,$ruleorder) =
9903: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 9904: my %lt = &usercreation_types();
9905: my %checked;
9906: if (ref($settings) eq 'HASH') {
9907: if (ref($settings->{'cancreate'}) eq 'HASH') {
9908: foreach my $item (@creators) {
9909: $checked{$item} = $settings->{'cancreate'}{$item};
9910: }
9911: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
9912: foreach my $item (@creators) {
9913: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
9914: $checked{$item} = 'none';
9915: }
9916: }
9917: }
9918: }
9919: my $rownum = 0;
9920: foreach my $item (@creators) {
9921: $rownum ++;
1.224 raeburn 9922: if ($checked{$item} eq '') {
9923: $checked{$item} = 'any';
1.34 raeburn 9924: }
9925: my $css_class;
9926: if ($rownum%2) {
9927: $css_class = '';
9928: } else {
9929: $css_class = ' class="LC_odd_row" ';
9930: }
9931: $datatable .= '<tr'.$css_class.'>'.
9932: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 9933: '</span></td><td style="text-align: right">';
1.224 raeburn 9934: my @options = ('any');
9935: if (ref($rules) eq 'HASH') {
9936: if (keys(%{$rules}) > 0) {
9937: push(@options,('official','unofficial'));
1.37 raeburn 9938: }
9939: }
1.224 raeburn 9940: push(@options,'none');
1.37 raeburn 9941: foreach my $option (@options) {
1.50 raeburn 9942: my $type = 'radio';
1.34 raeburn 9943: my $check = ' ';
1.224 raeburn 9944: if ($checked{$item} eq $option) {
9945: $check = ' checked="checked" ';
1.34 raeburn 9946: }
9947: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 9948: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 9949: $item.'" value="'.$option.'"'.$check.'/> '.
9950: $lt{$option}.'</label> </span>';
9951: }
9952: $datatable .= '</td></tr>';
9953: }
1.28 raeburn 9954: } else {
9955: my @contexts = ('author','course','domain');
1.325 raeburn 9956: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 9957: my %checked;
9958: if (ref($settings) eq 'HASH') {
9959: if (ref($settings->{'authtypes'}) eq 'HASH') {
9960: foreach my $item (@contexts) {
9961: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
9962: foreach my $auth (@authtypes) {
9963: if ($settings->{'authtypes'}{$item}{$auth}) {
9964: $checked{$item}{$auth} = ' checked="checked" ';
9965: }
9966: }
9967: }
9968: }
1.27 raeburn 9969: }
1.35 raeburn 9970: } else {
9971: foreach my $item (@contexts) {
1.36 raeburn 9972: foreach my $auth (@authtypes) {
1.35 raeburn 9973: $checked{$item}{$auth} = ' checked="checked" ';
9974: }
9975: }
1.27 raeburn 9976: }
1.28 raeburn 9977: my %title = &context_names();
9978: my %authname = &authtype_names();
9979: my $rownum = 0;
9980: my $css_class;
9981: foreach my $item (@contexts) {
9982: if ($rownum%2) {
9983: $css_class = '';
9984: } else {
9985: $css_class = ' class="LC_odd_row" ';
9986: }
1.30 raeburn 9987: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 9988: '<td>'.$title{$item}.
9989: '</td><td class="LC_left_item">'.
9990: '<span class="LC_nobreak">';
9991: foreach my $auth (@authtypes) {
9992: $datatable .= '<label>'.
9993: '<input type="checkbox" name="'.$item.'_auth" '.
9994: $checked{$item}{$auth}.' value="'.$auth.'" />'.
9995: $authname{$auth}.'</label> ';
9996: }
9997: $datatable .= '</span></td></tr>';
9998: $rownum ++;
1.27 raeburn 9999: }
1.30 raeburn 10000: $$rowtotal += $rownum;
1.27 raeburn 10001: }
10002: return $datatable;
10003: }
10004:
1.224 raeburn 10005: sub print_selfcreation {
10006: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 10007: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
10008: $emaildomain,$datatable);
1.224 raeburn 10009: if (ref($settings) eq 'HASH') {
10010: if (ref($settings->{'cancreate'}) eq 'HASH') {
10011: $createsettings = $settings->{'cancreate'};
1.236 raeburn 10012: if (ref($createsettings) eq 'HASH') {
10013: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
10014: @selfcreate = @{$createsettings->{'selfcreate'}};
10015: } elsif ($createsettings->{'selfcreate'} ne '') {
10016: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
10017: @selfcreate = ('email','login','sso');
10018: } elsif ($createsettings->{'selfcreate'} ne 'none') {
10019: @selfcreate = ($createsettings->{'selfcreate'});
10020: }
10021: }
10022: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
10023: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 10024: }
1.305 raeburn 10025: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
10026: $emailoptions = $createsettings->{'emailoptions'};
10027: }
1.303 raeburn 10028: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
10029: $emailverified = $createsettings->{'emailverified'};
10030: }
10031: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
10032: $emaildomain = $createsettings->{'emaildomain'};
10033: }
1.224 raeburn 10034: }
10035: }
10036: }
10037: my %radiohash;
10038: my $numinrow = 4;
10039: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 10040: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 10041: if ($position eq 'top') {
10042: my %choices = &Apache::lonlocal::texthash (
10043: cancreate_login => 'Institutional Login',
10044: cancreate_sso => 'Institutional Single Sign On',
10045: );
10046: my @toggles = sort(keys(%choices));
10047: my %defaultchecked = (
10048: 'cancreate_login' => 'off',
10049: 'cancreate_sso' => 'off',
10050: );
1.228 raeburn 10051: my ($onclick,$itemcount);
1.224 raeburn 10052: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
10053: \%choices,$itemcount,$onclick);
1.228 raeburn 10054: $$rowtotal += $itemcount;
1.425 raeburn 10055:
1.224 raeburn 10056: if (ref($usertypes) eq 'HASH') {
10057: if (keys(%{$usertypes}) > 0) {
10058: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
10059: $dom,$numinrow,$othertitle,
1.305 raeburn 10060: 'statustocreate',$rowtotal);
1.224 raeburn 10061: $$rowtotal ++;
10062: }
10063: }
1.240 raeburn 10064: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
10065: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10066: $fieldtitles{'inststatus'} = &mt('Institutional status');
10067: my $rem;
10068: my $numperrow = 2;
10069: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
10070: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 10071: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 10072: '<td class="LC_left_item">'."\n".
1.334 raeburn 10073: '<table>'."\n";
1.240 raeburn 10074: for (my $i=0; $i<@fields; $i++) {
10075: $rem = $i%($numperrow);
10076: if ($rem == 0) {
10077: if ($i > 0) {
10078: $datatable .= '</tr>';
10079: }
10080: $datatable .= '<tr>';
10081: }
10082: my $currval;
1.248 raeburn 10083: if (ref($createsettings) eq 'HASH') {
10084: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
10085: $currval = $createsettings->{'shibenv'}{$fields[$i]};
10086: }
1.240 raeburn 10087: }
10088: $datatable .= '<td class="LC_left_item">'.
10089: '<span class="LC_nobreak">'.
10090: '<input type="text" name="shibenv_'.$fields[$i].'" '.
10091: 'value="'.$currval.'" size="10" /> '.
10092: $fieldtitles{$fields[$i]}.'</span></td>';
10093: }
10094: my $colsleft = $numperrow - $rem;
10095: if ($colsleft > 1 ) {
10096: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10097: ' </td>';
10098: } elsif ($colsleft == 1) {
10099: $datatable .= '<td class="LC_left_item"> </td>';
10100: }
10101: $datatable .= '</tr></table></td></tr>';
10102: $$rowtotal ++;
1.224 raeburn 10103: } elsif ($position eq 'middle') {
10104: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 10105: my @posstypes;
1.224 raeburn 10106: if (ref($types) eq 'ARRAY') {
1.302 raeburn 10107: @posstypes = @{$types};
10108: }
10109: unless (grep(/^default$/,@posstypes)) {
10110: push(@posstypes,'default');
10111: }
10112: my %usertypeshash;
10113: if (ref($usertypes) eq 'HASH') {
10114: %usertypeshash = %{$usertypes};
10115: }
10116: $usertypeshash{'default'} = $othertitle;
10117: foreach my $status (@posstypes) {
10118: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
10119: $numinrow,$$rowtotal,\%usertypeshash);
10120: $$rowtotal ++;
1.224 raeburn 10121: }
10122: } else {
1.236 raeburn 10123: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 10124: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 10125: );
10126: my @toggles = sort(keys(%choices));
10127: my %defaultchecked = (
10128: 'cancreate_email' => 'off',
10129: );
1.305 raeburn 10130: my $customclass = 'LC_selfcreate_email';
10131: my $classprefix = 'LC_canmodify_emailusername_';
10132: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 10133: my $display = 'none';
1.305 raeburn 10134: my $rowstyle = 'display:none';
1.236 raeburn 10135: if (grep(/^\Qemail\E$/,@selfcreate)) {
10136: $display = 'block';
1.305 raeburn 10137: $rowstyle = 'display:table-row';
1.236 raeburn 10138: }
1.305 raeburn 10139: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
10140: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
10141: \%choices,$$rowtotal,$onclick);
10142: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
10143: $rowstyle);
10144: $$rowtotal ++;
10145: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
10146: $rowstyle);
10147: $$rowtotal ++;
10148: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 10149: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 10150: my ($emailrules,$emailruleorder) =
10151: &Apache::lonnet::inst_userrules($dom,'email');
10152: my $primary_id = &Apache::lonnet::domain($dom,'primary');
10153: my $intdom = &Apache::lonnet::internet_dom($primary_id);
10154: if (ref($types) eq 'ARRAY') {
10155: @posstypes = @{$types};
10156: }
10157: if (@posstypes) {
10158: unless (grep(/^default$/,@posstypes)) {
10159: push(@posstypes,'default');
1.302 raeburn 10160: }
10161: if (ref($usertypes) eq 'HASH') {
10162: %usertypeshash = %{$usertypes};
10163: }
1.305 raeburn 10164: my $currassign;
10165: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
10166: $currassign = {
10167: selfassign => $domdefaults{'inststatusguest'},
10168: };
10169: @ordered = @{$domdefaults{'inststatusguest'}};
10170: } else {
10171: $currassign = { selfassign => [] };
10172: }
10173: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
10174: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
10175: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
10176: $numinrow,$othertitle,'selfassign',
10177: $rowtotal,$onclicktypes,$customclass,
10178: $rowstyle);
10179: $$rowtotal ++;
1.302 raeburn 10180: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10181: foreach my $status (@posstypes) {
10182: my $css_class;
10183: if ($$rowtotal%2) {
10184: $css_class = 'LC_odd_row ';
10185: }
10186: $css_class .= $customclass;
10187: my $rowid = $optionsprefix.$status;
10188: my $hidden = 1;
10189: my $currstyle = 'display:none';
10190: if (grep(/^\Q$status\E$/,@ordered)) {
10191: $currstyle = $rowstyle;
1.425 raeburn 10192: $hidden = 0;
1.305 raeburn 10193: }
10194: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10195: $emailrules,$emailruleorder,$settings,$status,$rowid,
10196: $usertypeshash{$status},$css_class,$currstyle,$intdom);
10197: unless ($hidden) {
10198: $$rowtotal ++;
10199: }
1.224 raeburn 10200: }
1.302 raeburn 10201: } else {
1.305 raeburn 10202: my $css_class;
10203: if ($$rowtotal%2) {
10204: $css_class = 'LC_odd_row ';
10205: }
10206: $css_class .= $customclass;
1.302 raeburn 10207: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10208: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10209: $emailrules,$emailruleorder,$settings,'default','',
10210: $othertitle,$css_class,$rowstyle,$intdom);
10211: $$rowtotal ++;
1.224 raeburn 10212: }
10213: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 10214: $numinrow = 1;
1.305 raeburn 10215: if (@posstypes) {
10216: foreach my $status (@posstypes) {
10217: my $rowid = $classprefix.$status;
10218: my $datarowstyle = 'display:none';
1.425 raeburn 10219: if (grep(/^\Q$status\E$/,@ordered)) {
10220: $datarowstyle = $rowstyle;
1.305 raeburn 10221: }
10222: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
10223: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10224: $infotitles,$rowid,$customclass,$datarowstyle);
10225: unless ($datarowstyle eq 'display:none') {
10226: $$rowtotal ++;
10227: }
1.224 raeburn 10228: }
1.305 raeburn 10229: } else {
10230: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
10231: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10232: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 10233: }
10234: }
10235: return $datatable;
10236: }
10237:
1.305 raeburn 10238: sub selfcreate_javascript {
10239: return <<"ENDSCRIPT";
10240:
10241: <script type="text/javascript">
10242: // <![CDATA[
10243:
10244: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
10245: var x = document.getElementsByClassName(target);
10246: var insttypes = 0;
10247: var insttypeRegExp = new RegExp(prefix);
10248: if ((x.length != undefined) && (x.length > 0)) {
10249: if (form.elements[radio].length != undefined) {
10250: for (var i=0; i<form.elements[radio].length; i++) {
10251: if (form.elements[radio][i].checked) {
10252: if (form.elements[radio][i].value == 1) {
10253: for (var j=0; j<x.length; j++) {
10254: if (x[j].id == 'undefined') {
10255: x[j].style.display = 'table-row';
10256: } else if (insttypeRegExp.test(x[j].id)) {
10257: insttypes ++;
10258: } else {
10259: x[j].style.display = 'table-row';
10260: }
10261: }
10262: } else {
10263: for (var j=0; j<x.length; j++) {
10264: x[j].style.display = 'none';
10265: }
1.236 raeburn 10266: }
1.305 raeburn 10267: break;
10268: }
10269: }
10270: if (insttypes > 0) {
10271: toggleDataRow(form,checkbox,target,altprefix);
10272: toggleDataRow(form,checkbox,target,prefix,1);
10273: }
10274: }
10275: }
10276: return;
10277: }
10278:
10279: function toggleDataRow(form,checkbox,target,prefix,docount) {
10280: if (form.elements[checkbox].length != undefined) {
10281: var count = 0;
10282: if (docount) {
10283: for (var i=0; i<form.elements[checkbox].length; i++) {
10284: if (form.elements[checkbox][i].checked) {
10285: count ++;
1.236 raeburn 10286: }
1.305 raeburn 10287: }
10288: }
10289: for (var i=0; i<form.elements[checkbox].length; i++) {
10290: var type = form.elements[checkbox][i].value;
10291: if (document.getElementById(prefix+type)) {
10292: if (form.elements[checkbox][i].checked) {
10293: document.getElementById(prefix+type).style.display = 'table-row';
10294: if (count % 2 == 1) {
10295: document.getElementById(prefix+type).className = target+' LC_odd_row';
10296: } else {
10297: document.getElementById(prefix+type).className = target;
1.236 raeburn 10298: }
1.305 raeburn 10299: count ++;
1.236 raeburn 10300: } else {
1.305 raeburn 10301: document.getElementById(prefix+type).style.display = 'none';
10302: }
10303: }
10304: }
10305: }
10306: return;
10307: }
10308:
10309: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
10310: var caller = radio+'_'+status;
10311: if (form.elements[caller].length != undefined) {
10312: for (var i=0; i<form.elements[caller].length; i++) {
10313: if (form.elements[caller][i].checked) {
10314: if (document.getElementById(altprefix+'_inst_'+status)) {
10315: var curr = form.elements[caller][i].value;
10316: if (prefix) {
10317: document.getElementById(prefix+'_'+status).style.display = 'none';
10318: }
10319: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
10320: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
10321: if (curr == 'custom') {
1.425 raeburn 10322: if (prefix) {
1.305 raeburn 10323: document.getElementById(prefix+'_'+status).style.display = 'inline';
10324: }
10325: } else if (curr == 'inst') {
10326: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
10327: } else if (curr == 'noninst') {
10328: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 10329: }
1.305 raeburn 10330: break;
1.236 raeburn 10331: }
10332: }
10333: }
10334: }
10335: }
10336:
1.305 raeburn 10337: // ]]>
10338: </script>
10339:
10340: ENDSCRIPT
10341: }
10342:
10343: sub noninst_users {
10344: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
1.425 raeburn 10345: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
1.305 raeburn 10346: my $class = 'LC_left_item';
10347: if ($css_class) {
1.425 raeburn 10348: $css_class = ' class="'.$css_class.'"';
1.305 raeburn 10349: }
10350: if ($rowid) {
10351: $rowid = ' id="'.$rowid.'"';
10352: }
10353: if ($rowstyle) {
10354: $rowstyle = ' style="'.$rowstyle.'"';
10355: }
10356: my ($output,$description);
10357: if ($type eq 'default') {
10358: $description = &mt('Requests for: [_1]',$typetitle);
10359: } else {
10360: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
10361: }
10362: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
1.425 raeburn 10363: "<td>$description</td>\n".
1.305 raeburn 10364: '<td class="'.$class.'" colspan="2">'.
10365: '<table><tr>';
1.425 raeburn 10366: my %headers = &Apache::lonlocal::texthash(
1.305 raeburn 10367: approve => 'Processing',
10368: email => 'E-mail',
10369: username => 'Username',
10370: );
10371: foreach my $item ('approve','email','username') {
10372: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 10373: }
1.305 raeburn 10374: $output .= '</tr><tr>';
10375: foreach my $item ('approve','email','username') {
1.306 raeburn 10376: $output .= '<td style="vertical-align: top">';
1.305 raeburn 10377: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
10378: if ($item eq 'approve') {
10379: %choices = &Apache::lonlocal::texthash (
10380: automatic => 'Automatically approved',
10381: approval => 'Queued for approval',
10382: );
10383: @options = ('automatic','approval');
10384: $hashref = $processing;
10385: $defoption = 'automatic';
10386: $name = 'cancreate_emailprocess_'.$type;
10387: } elsif ($item eq 'email') {
10388: %choices = &Apache::lonlocal::texthash (
10389: any => 'Any e-mail',
10390: inst => 'Institutional only',
10391: noninst => 'Non-institutional only',
10392: custom => 'Custom restrictions',
10393: );
10394: @options = ('any','inst','noninst');
10395: my $showcustom;
10396: if (ref($emailrules) eq 'HASH') {
10397: if (keys(%{$emailrules}) > 0) {
10398: push(@options,'custom');
10399: $showcustom = 'cancreate_emailrule';
10400: if (ref($settings) eq 'HASH') {
10401: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
10402: foreach my $rule (@{$settings->{'email_rule'}}) {
10403: if (exists($emailrules->{$rule})) {
10404: $hascustom ++;
10405: }
10406: }
10407: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
10408: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
10409: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
10410: if (exists($emailrules->{$rule})) {
10411: $hascustom ++;
10412: }
10413: }
10414: }
10415: }
10416: }
10417: }
10418: }
10419: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
10420: "'cancreate_emaildomain','$type'".');"';
10421: $hashref = $emailoptions;
10422: $defoption = 'any';
10423: $name = 'cancreate_emailoptions_'.$type;
10424: } elsif ($item eq 'username') {
10425: %choices = &Apache::lonlocal::texthash (
10426: all => 'Same as e-mail',
10427: first => 'Omit @domain',
10428: free => 'Free to choose',
10429: );
10430: @options = ('all','first','free');
10431: $hashref = $emailverified;
10432: $defoption = 'all';
10433: $name = 'cancreate_usernameoptions_'.$type;
10434: }
10435: foreach my $option (@options) {
10436: my $checked;
10437: if (ref($hashref) eq 'HASH') {
10438: if ($type eq '') {
10439: if (!exists($hashref->{'default'})) {
10440: if ($option eq $defoption) {
10441: $checked = ' checked="checked"';
10442: }
10443: } else {
10444: if ($hashref->{'default'} eq $option) {
10445: $checked = ' checked="checked"';
10446: }
1.303 raeburn 10447: }
10448: } else {
1.305 raeburn 10449: if (!exists($hashref->{$type})) {
10450: if ($option eq $defoption) {
10451: $checked = ' checked="checked"';
10452: }
10453: } else {
10454: if ($hashref->{$type} eq $option) {
10455: $checked = ' checked="checked"';
10456: }
1.303 raeburn 10457: }
10458: }
1.305 raeburn 10459: } elsif (($item eq 'email') && ($hascustom)) {
10460: if ($option eq 'custom') {
10461: $checked = ' checked="checked"';
10462: }
10463: } elsif ($option eq $defoption) {
10464: $checked = ' checked="checked"';
10465: }
10466: $output .= '<span class="LC_nobreak"><label>'.
10467: '<input type="radio" name="'.$name.'"'.
10468: $checked.' value="'.$option.'"'.$onclick.' />'.
10469: $choices{$option}.'</label></span><br />';
10470: if ($item eq 'email') {
10471: if ($option eq 'custom') {
10472: my $id = 'cancreate_emailrule_'.$type;
10473: my $display = 'none';
10474: if ($checked) {
10475: $display = 'inline';
1.303 raeburn 10476: }
1.305 raeburn 10477: my $numinrow = 2;
10478: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
10479: '<legend>'.&mt('Disallow').'</legend><table>'.
10480: &user_formats_row('email',$settings,$emailrules,
10481: $emailruleorder,$numinrow,'',$type);
10482: '</table></fieldset>';
10483: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
10484: my %text = &Apache::lonlocal::texthash (
10485: inst => 'must end:',
10486: noninst => 'cannot end:',
10487: );
10488: my $value;
10489: if (ref($emaildomain) eq 'HASH') {
10490: if (ref($emaildomain->{$type}) eq 'HASH') {
1.425 raeburn 10491: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 10492: }
10493: }
1.305 raeburn 10494: if ($value eq '') {
10495: $value = '@'.$intdom;
10496: }
10497: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
10498: my $display = 'none';
10499: if ($checked) {
10500: $display = 'inline';
10501: }
10502: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
10503: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
10504: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
10505: '</div>';
1.303 raeburn 10506: }
10507: }
10508: }
1.305 raeburn 10509: $output .= '</td>'."\n";
1.303 raeburn 10510: }
1.305 raeburn 10511: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 10512: return $output;
10513: }
10514:
1.165 raeburn 10515: sub captcha_choice {
1.305 raeburn 10516: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 10517: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
10518: $vertext,$currver);
1.165 raeburn 10519: my %lt = &captcha_phrases();
10520: $keyentry = 'hidden';
1.354 raeburn 10521: my $colspan=2;
1.165 raeburn 10522: if ($context eq 'cancreate') {
1.224 raeburn 10523: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 10524: } elsif ($context eq 'login') {
10525: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.354 raeburn 10526: } elsif ($context eq 'passwords') {
10527: $rowname = &mt('"Forgot Password" CAPTCHA validation');
10528: $colspan=1;
1.165 raeburn 10529: }
10530: if (ref($settings) eq 'HASH') {
10531: if ($settings->{'captcha'}) {
10532: $checked{$settings->{'captcha'}} = ' checked="checked"';
10533: } else {
10534: $checked{'original'} = ' checked="checked"';
10535: }
10536: if ($settings->{'captcha'} eq 'recaptcha') {
10537: $pubtext = $lt{'pub'};
10538: $privtext = $lt{'priv'};
10539: $keyentry = 'text';
1.269 raeburn 10540: $vertext = $lt{'ver'};
10541: $currver = $settings->{'recaptchaversion'};
10542: if ($currver ne '2') {
10543: $currver = 1;
10544: }
1.165 raeburn 10545: }
10546: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
10547: $currpub = $settings->{'recaptchakeys'}{'public'};
10548: $currpriv = $settings->{'recaptchakeys'}{'private'};
10549: }
10550: } else {
10551: $checked{'original'} = ' checked="checked"';
10552: }
1.305 raeburn 10553: my $css_class;
10554: if ($itemcount%2) {
10555: $css_class = 'LC_odd_row';
10556: }
10557: if ($customcss) {
10558: $css_class .= " $customcss";
10559: }
10560: $css_class =~ s/^\s+//;
10561: if ($css_class) {
10562: $css_class = ' class="'.$css_class.'"';
10563: }
10564: if ($rowstyle) {
10565: $css_class .= ' style="'.$rowstyle.'"';
10566: }
1.169 raeburn 10567: my $output = '<tr'.$css_class.'>'.
1.354 raeburn 10568: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165 raeburn 10569: '<table><tr><td>'."\n";
10570: foreach my $option ('original','recaptcha','notused') {
10571: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
10572: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
10573: $lt{$option}.'</label></span>';
10574: unless ($option eq 'notused') {
10575: $output .= (' 'x2)."\n";
10576: }
10577: }
10578: #
10579: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
10580: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 10581: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 10582: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 10583: #
1.165 raeburn 10584: $output .= '</td></tr>'."\n".
1.305 raeburn 10585: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 10586: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
10587: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
10588: $currpub.'" size="40" /></span><br />'."\n".
10589: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
10590: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 10591: $currpriv.'" size="40" /></span><br />'.
10592: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
10593: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
10594: $currver.'" size="3" /></span><br />'.
10595: '</td></tr></table>'."\n".
1.165 raeburn 10596: '</td></tr>';
10597: return $output;
10598: }
10599:
1.32 raeburn 10600: sub user_formats_row {
1.305 raeburn 10601: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 10602: my $output;
10603: my %text = (
10604: 'username' => 'new usernames',
10605: 'id' => 'IDs',
10606: );
1.409 raeburn 10607: unless (($type eq 'email') || ($type eq 'unamemap')) {
1.305 raeburn 10608: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
10609: $output = '<tr '.$css_class.'>'.
10610: '<td><span class="LC_nobreak">'.
10611: &mt("Format rules to check for $text{$type}: ").
10612: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 10613: }
1.27 raeburn 10614: my $rem;
10615: if (ref($ruleorder) eq 'ARRAY') {
10616: for (my $i=0; $i<@{$ruleorder}; $i++) {
10617: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
10618: my $rem = $i%($numinrow);
10619: if ($rem == 0) {
10620: if ($i > 0) {
10621: $output .= '</tr>';
10622: }
10623: $output .= '<tr>';
10624: }
10625: my $check = ' ';
1.39 raeburn 10626: if (ref($settings) eq 'HASH') {
10627: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
10628: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
10629: $check = ' checked="checked" ';
10630: }
1.305 raeburn 10631: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
10632: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
10633: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
10634: $check = ' checked="checked" ';
10635: }
10636: }
1.27 raeburn 10637: }
10638: }
1.305 raeburn 10639: my $name = $type.'_rule';
10640: if ($type eq 'email') {
10641: $name .= '_'.$status;
10642: }
1.27 raeburn 10643: $output .= '<td class="LC_left_item">'.
10644: '<span class="LC_nobreak"><label>'.
1.311 raeburn 10645: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 10646: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
10647: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
10648: }
10649: }
10650: $rem = @{$ruleorder}%($numinrow);
10651: }
1.305 raeburn 10652: my $colsleft;
10653: if ($rem) {
10654: $colsleft = $numinrow - $rem;
10655: }
1.27 raeburn 10656: if ($colsleft > 1 ) {
10657: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10658: ' </td>';
10659: } elsif ($colsleft == 1) {
10660: $output .= '<td class="LC_left_item"> </td>';
10661: }
1.409 raeburn 10662: $output .= '</tr>';
10663: unless (($type eq 'email') || ($type eq 'unamemap')) {
10664: $output .= '</table></td></tr>';
1.305 raeburn 10665: }
1.27 raeburn 10666: return $output;
10667: }
10668:
1.34 raeburn 10669: sub usercreation_types {
10670: my %lt = &Apache::lonlocal::texthash (
10671: author => 'When adding a co-author',
10672: course => 'When adding a user to a course',
1.100 raeburn 10673: requestcrs => 'When requesting a course',
1.34 raeburn 10674: any => 'Any',
10675: official => 'Institutional only ',
10676: unofficial => 'Non-institutional only',
10677: none => 'None',
10678: );
10679: return %lt;
1.48 raeburn 10680: }
1.34 raeburn 10681:
1.224 raeburn 10682: sub selfcreation_types {
10683: my %lt = &Apache::lonlocal::texthash (
10684: selfcreate => 'User creates own account',
10685: any => 'Any',
10686: official => 'Institutional only ',
10687: unofficial => 'Non-institutional only',
10688: email => 'E-mail address',
10689: login => 'Institutional Login',
10690: sso => 'SSO',
10691: );
10692: }
10693:
1.28 raeburn 10694: sub authtype_names {
10695: my %lt = &Apache::lonlocal::texthash(
10696: int => 'Internal',
10697: krb4 => 'Kerberos 4',
10698: krb5 => 'Kerberos 5',
10699: loc => 'Local',
1.325 raeburn 10700: lti => 'LTI',
1.28 raeburn 10701: );
10702: return %lt;
10703: }
10704:
10705: sub context_names {
10706: my %context_title = &Apache::lonlocal::texthash(
10707: author => 'Creating users when an Author',
10708: course => 'Creating users when in a course',
10709: domain => 'Creating users when a Domain Coordinator',
10710: );
10711: return %context_title;
10712: }
10713:
1.33 raeburn 10714: sub print_usermodification {
10715: my ($position,$dom,$settings,$rowtotal) = @_;
10716: my $numinrow = 4;
10717: my ($context,$datatable,$rowcount);
10718: if ($position eq 'top') {
10719: $rowcount = 0;
10720: $context = 'author';
10721: foreach my $role ('ca','aa') {
10722: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10723: $numinrow,$rowcount);
10724: $$rowtotal ++;
10725: $rowcount ++;
10726: }
1.230 raeburn 10727: } elsif ($position eq 'bottom') {
1.33 raeburn 10728: $context = 'course';
10729: $rowcount = 0;
10730: foreach my $role ('st','ep','ta','in','cr') {
10731: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10732: $numinrow,$rowcount);
10733: $$rowtotal ++;
10734: $rowcount ++;
10735: }
10736: }
10737: return $datatable;
10738: }
10739:
1.43 raeburn 10740: sub print_defaults {
1.236 raeburn 10741: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 10742: my $rownum = 0;
1.294 raeburn 10743: my ($datatable,$css_class,$titles);
10744: unless ($position eq 'bottom') {
10745: $titles = &defaults_titles($dom);
10746: }
1.236 raeburn 10747: if ($position eq 'top') {
10748: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
10749: 'datelocale_def','portal_def');
10750: my %defaults;
10751: if (ref($settings) eq 'HASH') {
10752: %defaults = %{$settings};
1.43 raeburn 10753: } else {
1.236 raeburn 10754: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10755: foreach my $item (@items) {
10756: $defaults{$item} = $domdefaults{$item};
10757: }
1.43 raeburn 10758: }
1.236 raeburn 10759: foreach my $item (@items) {
10760: if ($rownum%2) {
10761: $css_class = '';
10762: } else {
10763: $css_class = ' class="LC_odd_row" ';
10764: }
10765: $datatable .= '<tr'.$css_class.'>'.
10766: '<td><span class="LC_nobreak">'.$titles->{$item}.
10767: '</span></td><td class="LC_right_item" colspan="3">';
10768: if ($item eq 'auth_def') {
1.325 raeburn 10769: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 10770: my %shortauth = (
10771: internal => 'int',
10772: krb4 => 'krb4',
10773: krb5 => 'krb5',
1.325 raeburn 10774: localauth => 'loc',
10775: lti => 'lti',
1.236 raeburn 10776: );
10777: my %authnames = &authtype_names();
10778: foreach my $auth (@authtypes) {
10779: my $checked = ' ';
10780: if ($defaults{$item} eq $auth) {
10781: $checked = ' checked="checked" ';
10782: }
10783: $datatable .= '<label><input type="radio" name="'.$item.
10784: '" value="'.$auth.'"'.$checked.'/>'.
10785: $authnames{$shortauth{$auth}}.'</label> ';
10786: }
10787: } elsif ($item eq 'timezone_def') {
10788: my $includeempty = 1;
10789: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
10790: } elsif ($item eq 'datelocale_def') {
10791: my $includeempty = 1;
10792: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
10793: } elsif ($item eq 'lang_def') {
1.263 raeburn 10794: my $includeempty = 1;
10795: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.414 raeburn 10796: } elsif ($item eq 'portal_def') {
10797: $datatable .= '<input type="text" name="'.$item.'" value="'.
10798: $defaults{$item}.'" size="25" onkeyup="portalExtras(this);" />';
10799: my $portalsty = 'none';
10800: if ($defaults{$item}) {
10801: $portalsty = 'block';
10802: }
10803: foreach my $field ('email','web') {
10804: my $checkedoff = ' checked="checked"';
10805: my $checkedon;
10806: if ($defaults{$item.'_'.$field}) {
10807: $checkedon = $checkedoff;
10808: $checkedoff = '';
1.425 raeburn 10809: }
1.414 raeburn 10810: $datatable .= '<div id="'.$item.'_'.$field.'_div" style="display:'.$portalsty.'">'.
10811: '<span class="LC_nobreak">'.$titles->{$field}.' '.
10812: '<label><input type="radio" name="'.$item.'_'.$field.'" value="1"'.$checkedon.'/>'.&mt('Yes').'</label>'.
10813: (' 'x2).
10814: '<label><input type="radio" name="'.$item.'_'.$field.'" value="0"'.$checkedoff.'/>'.&mt('No').'</label>'.
10815: '</div>';
10816: }
1.236 raeburn 10817: } else {
1.414 raeburn 10818: $datatable .= '<input type="text" name="'.$item.'" value="'.$defaults{$item}.'" />';
1.43 raeburn 10819: }
1.236 raeburn 10820: $datatable .= '</td></tr>';
10821: $rownum ++;
10822: }
1.409 raeburn 10823: } elsif ($position eq 'middle') {
1.294 raeburn 10824: my %defaults;
10825: if (ref($settings) eq 'HASH') {
1.354 raeburn 10826: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
10827: my $maxnum = @{$settings->{'inststatusorder'}};
10828: for (my $i=0; $i<$maxnum; $i++) {
10829: $css_class = $rownum%2?' class="LC_odd_row"':'';
10830: my $item = $settings->{'inststatusorder'}->[$i];
10831: my $title = $settings->{'inststatustypes'}->{$item};
10832: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
10833: $datatable .= '<tr'.$css_class.'>'.
10834: '<td><span class="LC_nobreak">'.
10835: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
10836: for (my $k=0; $k<=$maxnum; $k++) {
10837: my $vpos = $k+1;
10838: my $selstr;
10839: if ($k == $i) {
10840: $selstr = ' selected="selected" ';
10841: }
10842: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10843: }
10844: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
10845: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
10846: &mt('delete').'</span></td>'.
1.380 raeburn 10847: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.354 raeburn 10848: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
10849: '</span></td></tr>';
10850: }
10851: $css_class = $rownum%2?' class="LC_odd_row"':'';
10852: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
10853: $datatable .= '<tr '.$css_class.'>'.
10854: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
10855: for (my $k=0; $k<=$maxnum; $k++) {
10856: my $vpos = $k+1;
10857: my $selstr;
10858: if ($k == $maxnum) {
10859: $selstr = ' selected="selected" ';
10860: }
10861: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10862: }
10863: $datatable .= '</select> '.&mt('Internal ID:').
10864: '<input type="text" size="10" name="addinststatus" value="" />'.
10865: ' '.&mt('(new)').
10866: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.380 raeburn 10867: &mt('Name displayed').':'.
1.354 raeburn 10868: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
10869: '</tr>'."\n";
10870: $rownum ++;
1.294 raeburn 10871: }
1.354 raeburn 10872: }
1.409 raeburn 10873: } else {
10874: my ($unamemaprules,$ruleorder) =
10875: &Apache::lonnet::inst_userrules($dom,'unamemap');
10876: $css_class = $rownum%2?' class="LC_odd_row"':'';
10877: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10878: my $numinrow = 2;
10879: $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
10880: &user_formats_row('unamemap',$settings,$unamemaprules,
10881: $ruleorder,$numinrow).
10882: '</table></td></tr>';
10883: }
10884: if ($datatable eq '') {
10885: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
10886: &mt('No rules set for domain in customized localenroll.pm').
10887: '</td></tr>';
10888: }
1.354 raeburn 10889: }
10890: $$rowtotal += $rownum;
1.43 raeburn 10891: return $datatable;
10892: }
10893:
1.168 raeburn 10894: sub get_languages_hash {
10895: my %langchoices;
10896: foreach my $id (&Apache::loncommon::languageids()) {
10897: my $code = &Apache::loncommon::supportedlanguagecode($id);
10898: if ($code ne '') {
10899: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
10900: }
10901: }
10902: return %langchoices;
10903: }
10904:
1.43 raeburn 10905: sub defaults_titles {
1.141 raeburn 10906: my ($dom) = @_;
1.43 raeburn 10907: my %titles = &Apache::lonlocal::texthash (
10908: 'auth_def' => 'Default authentication type',
10909: 'auth_arg_def' => 'Default authentication argument',
10910: 'lang_def' => 'Default language',
1.54 raeburn 10911: 'timezone_def' => 'Default timezone',
1.68 raeburn 10912: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 10913: 'portal_def' => 'Portal/Default URL',
1.414 raeburn 10914: 'email' => 'Email links use portal URL',
10915: 'web' => 'Public web links use portal URL',
1.294 raeburn 10916: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
10917: 'intauth_check' => 'Check bcrypt cost if authenticated',
10918: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 10919: );
1.141 raeburn 10920: if ($dom) {
10921: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
10922: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
10923: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
10924: $protocol = 'http' if ($protocol ne 'https');
10925: if ($uint_dom) {
10926: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
10927: $uint_dom);
10928: }
10929: }
1.43 raeburn 10930: return (\%titles);
10931: }
10932:
1.346 raeburn 10933: sub print_scantron {
10934: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
10935: if ($position eq 'top') {
10936: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
10937: } else {
10938: return &print_scantronconfig($dom,$settings,\$rowtotal);
10939: }
10940: }
10941:
10942: sub scantron_javascript {
10943: return <<"ENDSCRIPT";
10944:
10945: <script type="text/javascript">
10946: // <![CDATA[
10947:
10948: function toggleScantron(form) {
1.347 raeburn 10949: var csvfieldset = new Array();
1.346 raeburn 10950: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 10951: csvfieldset.push(document.getElementById('scantroncsv_cols'));
10952: }
10953: if (document.getElementById('scantroncsv_options')) {
10954: csvfieldset.push(document.getElementById('scantroncsv_options'));
10955: }
10956: if (csvfieldset.length) {
1.346 raeburn 10957: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 10958: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 10959: if (scantroncsv.checked) {
1.347 raeburn 10960: for (var i=0; i<csvfieldset.length; i++) {
10961: csvfieldset[i].style.display = 'block';
10962: }
1.346 raeburn 10963: } else {
1.347 raeburn 10964: for (var i=0; i<csvfieldset.length; i++) {
10965: csvfieldset[i].style.display = 'none';
10966: }
1.346 raeburn 10967: var csvselects = document.getElementsByClassName('scantronconfig_csv');
10968: if (csvselects.length) {
10969: for (var j=0; j<csvselects.length; j++) {
10970: csvselects[j].selectedIndex = 0;
10971: }
10972: }
10973: }
10974: }
10975: }
10976: return;
10977: }
10978: // ]]>
10979: </script>
10980:
10981: ENDSCRIPT
10982:
10983: }
10984:
1.46 raeburn 10985: sub print_scantronformat {
10986: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
10987: my $itemcount = 1;
1.60 raeburn 10988: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
10989: %confhash);
1.46 raeburn 10990: my $switchserver = &check_switchserver($dom,$confname);
10991: my %lt = &Apache::lonlocal::texthash (
1.95 www 10992: default => 'Default bubblesheet format file error',
10993: custom => 'Custom bubblesheet format file error',
1.46 raeburn 10994: );
10995: my %scantronfiles = (
10996: default => 'default.tab',
10997: custom => 'custom.tab',
10998: );
10999: foreach my $key (keys(%scantronfiles)) {
11000: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
11001: .$scantronfiles{$key};
11002: }
11003: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
11004: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
11005: if (!$switchserver) {
11006: my $servadm = $r->dir_config('lonAdmEMail');
11007: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
11008: if ($configuserok eq 'ok') {
11009: if ($author_ok eq 'ok') {
11010: my %legacyfile = (
1.346 raeburn 11011: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
11012: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 11013: );
11014: my %md5chk;
11015: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 11016: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
11017: chomp($md5chk{$type});
1.46 raeburn 11018: }
11019: if ($md5chk{'default'} ne $md5chk{'custom'}) {
11020: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 11021: ($scantronurls{$type},my $error) =
1.46 raeburn 11022: &legacy_scantronformat($r,$dom,$confname,
11023: $type,$legacyfile{$type},
11024: $scantronurls{$type},
11025: $scantronfiles{$type});
1.60 raeburn 11026: if ($error ne '') {
11027: $error{$type} = $error;
11028: }
11029: }
11030: if (keys(%error) == 0) {
11031: $is_custom = 1;
1.346 raeburn 11032: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 11033: $scantronurls{'custom'};
1.346 raeburn 11034: my $putresult =
1.60 raeburn 11035: &Apache::lonnet::put_dom('configuration',
11036: \%confhash,$dom);
11037: if ($putresult ne 'ok') {
1.346 raeburn 11038: $error{'custom'} =
1.60 raeburn 11039: '<span class="LC_error">'.
11040: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
11041: }
1.46 raeburn 11042: }
11043: } else {
1.60 raeburn 11044: ($scantronurls{'default'},my $error) =
1.46 raeburn 11045: &legacy_scantronformat($r,$dom,$confname,
11046: 'default',$legacyfile{'default'},
11047: $scantronurls{'default'},
11048: $scantronfiles{'default'});
1.60 raeburn 11049: if ($error eq '') {
11050: $confhash{'scantron'}{'scantronformat'} = '';
11051: my $putresult =
11052: &Apache::lonnet::put_dom('configuration',
11053: \%confhash,$dom);
11054: if ($putresult ne 'ok') {
11055: $error{'default'} =
11056: '<span class="LC_error">'.
11057: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
11058: }
11059: } else {
11060: $error{'default'} = $error;
11061: }
1.46 raeburn 11062: }
11063: }
11064: }
11065: } else {
1.95 www 11066: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 11067: }
11068: }
11069: if (ref($settings) eq 'HASH') {
11070: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
11071: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
11072: if ((!@info) || ($info[0] eq 'no_such_dir')) {
11073: $scantronurl = '';
11074: } else {
11075: $scantronurl = $settings->{'scantronformat'};
11076: }
11077: $is_custom = 1;
11078: } else {
11079: $scantronurl = $scantronurls{'default'};
11080: }
11081: } else {
1.60 raeburn 11082: if ($is_custom) {
11083: $scantronurl = $scantronurls{'custom'};
11084: } else {
11085: $scantronurl = $scantronurls{'default'};
11086: }
1.46 raeburn 11087: }
11088: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11089: $datatable .= '<tr'.$css_class.'>';
11090: if (!$is_custom) {
1.65 raeburn 11091: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
11092: '<span class="LC_nobreak">';
1.46 raeburn 11093: if ($scantronurl) {
1.199 raeburn 11094: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
11095: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 11096: } else {
11097: $datatable = &mt('File unavailable for display');
11098: }
1.65 raeburn 11099: $datatable .= '</span></td>';
1.60 raeburn 11100: if (keys(%error) == 0) {
1.306 raeburn 11101: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 11102: if (!$switchserver) {
11103: $datatable .= &mt('Upload:').'<br />';
11104: }
11105: } else {
11106: my $errorstr;
11107: foreach my $key (sort(keys(%error))) {
11108: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
11109: }
11110: $datatable .= '<td>'.$errorstr;
11111: }
1.46 raeburn 11112: } else {
11113: if (keys(%error) > 0) {
11114: my $errorstr;
11115: foreach my $key (sort(keys(%error))) {
11116: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
11117: }
1.60 raeburn 11118: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 11119: } elsif ($scantronurl) {
1.199 raeburn 11120: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
11121: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 11122: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 11123: $link.
11124: '<label><input type="checkbox" name="scantronformat_del"'.
11125: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 11126: '<td><span class="LC_nobreak"> '.
11127: &mt('Replace:').'</span><br />';
1.46 raeburn 11128: }
11129: }
11130: if (keys(%error) == 0) {
11131: if ($switchserver) {
11132: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
11133: } else {
1.65 raeburn 11134: $datatable .='<span class="LC_nobreak"> '.
11135: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 11136: }
11137: }
11138: $datatable .= '</td></tr>';
11139: $$rowtotal ++;
11140: return $datatable;
11141: }
11142:
11143: sub legacy_scantronformat {
11144: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
11145: my ($url,$error);
11146: my @statinfo = &Apache::lonnet::stat_file($newurl);
11147: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
1.421 raeburn 11148: my $modified = [];
1.46 raeburn 11149: (my $result,$url) =
1.421 raeburn 11150: &Apache::lonconfigsettings::publishlogo($r,'copy',$legacyfile,$dom,$confname,
11151: 'scantron','','',$newfile,$modified);
11152: if ($result eq 'ok') {
11153: &update_modify_urls($r,$modified);
11154: } else {
1.130 raeburn 11155: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 11156: }
11157: }
11158: return ($url,$error);
11159: }
1.43 raeburn 11160:
1.346 raeburn 11161: sub print_scantronconfig {
11162: my ($dom,$settings,$rowtotal) = @_;
11163: my $itemcount = 2;
11164: my $is_checked = ' checked="checked"';
1.347 raeburn 11165: my %optionson = (
11166: hdr => ' checked="checked"',
11167: pad => ' checked="checked"',
11168: rem => ' checked="checked"',
11169: );
11170: my %optionsoff = (
11171: hdr => '',
11172: pad => '',
11173: rem => '',
11174: );
1.346 raeburn 11175: my $currcsvsty = 'none';
1.347 raeburn 11176: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 11177: my @fields = &scantroncsv_fields();
11178: my %titles = &scantronconfig_titles();
11179: if (ref($settings) eq 'HASH') {
11180: if (ref($settings->{config}) eq 'HASH') {
11181: if ($settings->{config}->{dat}) {
11182: $checked{'dat'} = $is_checked;
11183: }
11184: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 11185: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
11186: %csvfields = %{$settings->{config}->{csv}->{fields}};
11187: if (keys(%csvfields) > 0) {
11188: $checked{'csv'} = $is_checked;
11189: $currcsvsty = 'block';
11190: }
11191: }
11192: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
11193: %csvoptions = %{$settings->{config}->{csv}->{options}};
11194: foreach my $option (keys(%optionson)) {
11195: unless ($csvoptions{$option}) {
11196: $optionsoff{$option} = $optionson{$option};
11197: $optionson{$option} = '';
11198: }
11199: }
1.346 raeburn 11200: }
11201: }
11202: } else {
11203: $checked{'dat'} = $is_checked;
11204: }
11205: } else {
11206: $checked{'dat'} = $is_checked;
11207: }
11208: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
11209: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11210: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
11211: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
11212: foreach my $item ('dat','csv') {
11213: my $id;
11214: if ($item eq 'csv') {
11215: $id = 'id="scantronconfcsv" ';
1.347 raeburn 11216: }
1.346 raeburn 11217: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
11218: $titles{$item}.'</label>'.(' 'x3);
11219: if ($item eq 'csv') {
11220: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
11221: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
11222: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
11223: foreach my $col (@fields) {
11224: my $selnone;
11225: if ($csvfields{$col} eq '') {
11226: $selnone = ' selected="selected"';
11227: }
11228: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
11229: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
11230: '<option value=""'.$selnone.'></option>';
11231: for (my $i=0; $i<20; $i++) {
11232: my $shown = $i+1;
11233: my $sel;
11234: unless ($selnone) {
11235: if (exists($csvfields{$col})) {
11236: if ($csvfields{$col} == $i) {
11237: $sel = ' selected="selected"';
11238: }
11239: }
11240: }
11241: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
11242: }
11243: $datatable .= '</select></td></tr>';
11244: }
1.347 raeburn 11245: $datatable .= '</table></fieldset>'.
11246: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
11247: '<legend>'.&mt('CSV Options').'</legend>';
11248: foreach my $option ('hdr','pad','rem') {
11249: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
11250: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
11251: &mt('Yes').'</label>'.(' 'x2)."\n".
11252: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
11253: }
11254: $datatable .= '</fieldset>';
1.346 raeburn 11255: $itemcount ++;
11256: }
11257: }
11258: $datatable .= '</td></tr>';
11259: $$rowtotal ++;
11260: return $datatable;
11261: }
11262:
11263: sub scantronconfig_titles {
11264: return &Apache::lonlocal::texthash(
11265: dat => 'Standard format (.dat)',
11266: csv => 'Comma separated values (.csv)',
1.347 raeburn 11267: hdr => 'Remove first line in file (contains column titles)',
11268: pad => 'Prepend 0s to PaperID',
1.348 raeburn 11269: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 11270: CODE => 'CODE',
11271: ID => 'Student ID',
11272: PaperID => 'Paper ID',
11273: FirstName => 'First Name',
11274: LastName => 'Last Name',
11275: FirstQuestion => 'First Question Response',
11276: Section => 'Section',
11277: );
11278: }
11279:
11280: sub scantroncsv_fields {
11281: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
11282: }
11283:
1.49 raeburn 11284: sub print_coursecategories {
1.57 raeburn 11285: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
11286: my $datatable;
11287: if ($position eq 'top') {
1.238 raeburn 11288: my (%checked);
11289: my @catitems = ('unauth','auth');
11290: my @cattypes = ('std','domonly','codesrch','none');
11291: $checked{'unauth'} = 'std';
11292: $checked{'auth'} = 'std';
11293: if (ref($settings) eq 'HASH') {
11294: foreach my $type (@cattypes) {
11295: if ($type eq $settings->{'unauth'}) {
11296: $checked{'unauth'} = $type;
11297: }
11298: if ($type eq $settings->{'auth'}) {
11299: $checked{'auth'} = $type;
11300: }
11301: }
11302: }
11303: my %lt = &Apache::lonlocal::texthash (
11304: unauth => 'Catalog type for unauthenticated users',
11305: auth => 'Catalog type for authenticated users',
11306: none => 'No catalog',
11307: std => 'Standard catalog',
11308: domonly => 'Domain-only catalog',
11309: codesrch => "Code search form",
11310: );
11311: my $itemcount = 0;
11312: foreach my $item (@catitems) {
11313: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11314: $datatable .= '<tr '.$css_class.'>'.
11315: '<td>'.$lt{$item}.'</td>'.
11316: '<td class="LC_right_item"><span class="LC_nobreak">';
11317: foreach my $type (@cattypes) {
11318: my $ischecked;
11319: if ($checked{$item} eq $type) {
11320: $ischecked=' checked="checked"';
11321: }
11322: $datatable .= '<label>'.
11323: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
11324: ' />'.$lt{$type}.'</label> ';
11325: }
1.327 raeburn 11326: $datatable .= '</span></td></tr>';
1.238 raeburn 11327: $itemcount ++;
11328: }
11329: $$rowtotal += $itemcount;
11330: } elsif ($position eq 'middle') {
1.57 raeburn 11331: my $toggle_cats_crs = ' ';
11332: my $toggle_cats_dom = ' checked="checked" ';
11333: my $can_cat_crs = ' ';
11334: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 11335: my $toggle_catscomm_comm = ' ';
11336: my $toggle_catscomm_dom = ' checked="checked" ';
11337: my $can_catcomm_comm = ' ';
11338: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 11339: my $toggle_catsplace_place = ' ';
11340: my $toggle_catsplace_dom = ' checked="checked" ';
11341: my $can_catplace_place = ' ';
11342: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 11343:
1.57 raeburn 11344: if (ref($settings) eq 'HASH') {
11345: if ($settings->{'togglecats'} eq 'crs') {
11346: $toggle_cats_crs = $toggle_cats_dom;
11347: $toggle_cats_dom = ' ';
11348: }
11349: if ($settings->{'categorize'} eq 'crs') {
11350: $can_cat_crs = $can_cat_dom;
11351: $can_cat_dom = ' ';
11352: }
1.120 raeburn 11353: if ($settings->{'togglecatscomm'} eq 'comm') {
11354: $toggle_catscomm_comm = $toggle_catscomm_dom;
11355: $toggle_catscomm_dom = ' ';
11356: }
11357: if ($settings->{'categorizecomm'} eq 'comm') {
11358: $can_catcomm_comm = $can_catcomm_dom;
11359: $can_catcomm_dom = ' ';
11360: }
1.272 raeburn 11361: if ($settings->{'togglecatsplace'} eq 'place') {
11362: $toggle_catsplace_place = $toggle_catsplace_dom;
11363: $toggle_catsplace_dom = ' ';
11364: }
11365: if ($settings->{'categorizeplace'} eq 'place') {
11366: $can_catplace_place = $can_catplace_dom;
11367: $can_catplace_dom = ' ';
11368: }
1.57 raeburn 11369: }
11370: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 11371: togglecats => 'Show/Hide a course in catalog',
11372: togglecatscomm => 'Show/Hide a community in catalog',
11373: togglecatsplace => 'Show/Hide a placement test in catalog',
11374: categorize => 'Assign a category to a course',
11375: categorizecomm => 'Assign a category to a community',
11376: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 11377: );
11378: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 11379: dom => 'Set in Domain',
11380: crs => 'Set in Course',
11381: comm => 'Set in Community',
11382: place => 'Set in Placement Test',
1.57 raeburn 11383: );
11384: $datatable = '<tr class="LC_odd_row">'.
11385: '<td>'.$title{'togglecats'}.'</td>'.
11386: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11387: '<input type="radio" name="togglecats"'.
11388: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11389: '<label><input type="radio" name="togglecats"'.
11390: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
11391: '</tr><tr>'.
11392: '<td>'.$title{'categorize'}.'</td>'.
11393: '<td class="LC_right_item"><span class="LC_nobreak">'.
11394: '<label><input type="radio" name="categorize"'.
11395: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11396: '<label><input type="radio" name="categorize"'.
11397: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 11398: '</tr><tr class="LC_odd_row">'.
11399: '<td>'.$title{'togglecatscomm'}.'</td>'.
11400: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11401: '<input type="radio" name="togglecatscomm"'.
11402: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11403: '<label><input type="radio" name="togglecatscomm"'.
11404: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
11405: '</tr><tr>'.
11406: '<td>'.$title{'categorizecomm'}.'</td>'.
11407: '<td class="LC_right_item"><span class="LC_nobreak">'.
11408: '<label><input type="radio" name="categorizecomm"'.
11409: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11410: '<label><input type="radio" name="categorizecomm"'.
11411: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 11412: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 11413: '<td>'.$title{'togglecatsplace'}.'</td>'.
11414: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11415: '<input type="radio" name="togglecatsplace"'.
11416: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11417: '<label><input type="radio" name="togglecatscomm"'.
11418: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
11419: '</tr><tr>'.
11420: '<td>'.$title{'categorizeplace'}.'</td>'.
11421: '<td class="LC_right_item"><span class="LC_nobreak">'.
11422: '<label><input type="radio" name="categorizeplace"'.
11423: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11424: '<label><input type="radio" name="categorizeplace"'.
11425: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 11426: '</tr>';
1.272 raeburn 11427: $$rowtotal += 6;
1.57 raeburn 11428: } else {
11429: my $css_class;
11430: my $itemcount = 1;
11431: my $cathash;
11432: if (ref($settings) eq 'HASH') {
11433: $cathash = $settings->{'cats'};
11434: }
11435: if (ref($cathash) eq 'HASH') {
11436: my (@cats,@trails,%allitems,%idx,@jsarray);
11437: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
11438: \%allitems,\%idx,\@jsarray);
11439: my $maxdepth = scalar(@cats);
11440: my $colattrib = '';
11441: if ($maxdepth > 2) {
11442: $colattrib = ' colspan="2" ';
11443: }
11444: my @path;
11445: if (@cats > 0) {
11446: if (ref($cats[0]) eq 'ARRAY') {
11447: my $numtop = @{$cats[0]};
11448: my $maxnum = $numtop;
1.120 raeburn 11449: my %default_names = (
11450: instcode => &mt('Official courses'),
11451: communities => &mt('Communities'),
1.272 raeburn 11452: placement => &mt('Placement Tests'),
1.120 raeburn 11453: );
11454:
11455: if ((!grep(/^instcode$/,@{$cats[0]})) ||
11456: ($cathash->{'instcode::0'} eq '') ||
11457: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 11458: ($cathash->{'communities::0'} eq '') ||
11459: (!grep(/^placement$/,@{$cats[0]})) ||
11460: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 11461: $maxnum ++;
11462: }
11463: my $lastidx;
11464: for (my $i=0; $i<$numtop; $i++) {
11465: my $parent = $cats[0][$i];
11466: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11467: my $item = &escape($parent).'::0';
11468: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
11469: $lastidx = $idx{$item};
11470: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
11471: .'<select name="'.$item.'"'.$chgstr.'>';
11472: for (my $k=0; $k<=$maxnum; $k++) {
11473: my $vpos = $k+1;
11474: my $selstr;
11475: if ($k == $i) {
11476: $selstr = ' selected="selected" ';
11477: }
11478: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11479: }
1.214 raeburn 11480: $datatable .= '</select></span></td><td>';
1.272 raeburn 11481: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 11482: $datatable .= '<span class="LC_nobreak">'
11483: .$default_names{$parent}.'</span>';
11484: if ($parent eq 'instcode') {
11485: $datatable .= '<br /><span class="LC_nobreak">('
11486: .&mt('with institutional codes')
11487: .')</span></td><td'.$colattrib.'>';
11488: } else {
11489: $datatable .= '<table><tr><td>';
11490: }
11491: $datatable .= '<span class="LC_nobreak">'
11492: .'<label><input type="radio" name="'
11493: .$parent.'" value="1" checked="checked" />'
11494: .&mt('Display').'</label>';
11495: if ($parent eq 'instcode') {
11496: $datatable .= ' ';
11497: } else {
11498: $datatable .= '</span></td></tr><tr><td>'
11499: .'<span class="LC_nobreak">';
11500: }
11501: $datatable .= '<label><input type="radio" name="'
11502: .$parent.'" value="0" />'
11503: .&mt('Do not display').'</label></span>';
1.272 raeburn 11504: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 11505: $datatable .= '</td></tr></table>';
11506: }
11507: $datatable .= '</td>';
1.57 raeburn 11508: } else {
11509: $datatable .= $parent
1.214 raeburn 11510: .' <span class="LC_nobreak"><label>'
11511: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 11512: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
11513: }
11514: my $depth = 1;
11515: push(@path,$parent);
11516: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
11517: pop(@path);
11518: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
11519: $itemcount ++;
11520: }
1.48 raeburn 11521: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 11522: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
11523: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 11524: for (my $k=0; $k<=$maxnum; $k++) {
11525: my $vpos = $k+1;
11526: my $selstr;
1.57 raeburn 11527: if ($k == $numtop) {
1.48 raeburn 11528: $selstr = ' selected="selected" ';
11529: }
11530: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11531: }
1.59 bisitz 11532: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 11533: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
11534: .'</tr>'."\n";
1.48 raeburn 11535: $itemcount ++;
1.272 raeburn 11536: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11537: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
11538: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11539: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
11540: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
11541: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
11542: for (my $k=0; $k<=$maxnum; $k++) {
11543: my $vpos = $k+1;
11544: my $selstr;
11545: if ($k == $maxnum) {
11546: $selstr = ' selected="selected" ';
11547: }
11548: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 11549: }
1.120 raeburn 11550: $datatable .= '</select></span></td>'.
11551: '<td><span class="LC_nobreak">'.
11552: $default_names{$default}.'</span>';
11553: if ($default eq 'instcode') {
11554: $datatable .= '<br /><span class="LC_nobreak">('
11555: .&mt('with institutional codes').')</span>';
11556: }
11557: $datatable .= '</td>'
11558: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
11559: .&mt('Display').'</label> '
11560: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
11561: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 11562: }
11563: }
11564: }
1.57 raeburn 11565: } else {
11566: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 11567: }
11568: } else {
1.327 raeburn 11569: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 11570: .&initialize_categories($itemcount);
1.48 raeburn 11571: }
1.57 raeburn 11572: $$rowtotal += $itemcount;
1.48 raeburn 11573: }
11574: return $datatable;
11575: }
11576:
1.69 raeburn 11577: sub print_serverstatuses {
11578: my ($dom,$settings,$rowtotal) = @_;
11579: my $datatable;
11580: my @pages = &serverstatus_pages();
11581: my (%namedaccess,%machineaccess);
11582: foreach my $type (@pages) {
11583: $namedaccess{$type} = '';
11584: $machineaccess{$type}= '';
11585: }
11586: if (ref($settings) eq 'HASH') {
11587: foreach my $type (@pages) {
11588: if (exists($settings->{$type})) {
11589: if (ref($settings->{$type}) eq 'HASH') {
11590: foreach my $key (keys(%{$settings->{$type}})) {
11591: if ($key eq 'namedusers') {
11592: $namedaccess{$type} = $settings->{$type}->{$key};
11593: } elsif ($key eq 'machines') {
11594: $machineaccess{$type} = $settings->{$type}->{$key};
11595: }
11596: }
11597: }
11598: }
11599: }
11600: }
1.81 raeburn 11601: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11602: my $rownum = 0;
11603: my $css_class;
11604: foreach my $type (@pages) {
11605: $rownum ++;
11606: $css_class = $rownum%2?' class="LC_odd_row"':'';
11607: $datatable .= '<tr'.$css_class.'>'.
11608: '<td><span class="LC_nobreak">'.
11609: $titles->{$type}.'</span></td>'.
11610: '<td class="LC_left_item">'.
11611: '<input type="text" name="'.$type.'_namedusers" '.
11612: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
11613: '<td class="LC_right_item">'.
11614: '<span class="LC_nobreak">'.
11615: '<input type="text" name="'.$type.'_machines" '.
11616: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 11617: '</span></td></tr>'."\n";
1.69 raeburn 11618: }
11619: $$rowtotal += $rownum;
11620: return $datatable;
11621: }
11622:
11623: sub serverstatus_pages {
11624: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 11625: 'checksums','clusterstatus','certstatus','metadata_keywords',
11626: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
11627: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 11628: }
11629:
1.236 raeburn 11630: sub defaults_javascript {
11631: my ($settings) = @_;
1.354 raeburn 11632: return unless (ref($settings) eq 'HASH');
1.414 raeburn 11633: my $portal_js = <<"ENDPORTAL";
11634:
11635: function portalExtras(caller) {
11636: var x = caller.value;
11637: var y = new Array('email','web');
1.425 raeburn 11638: for (var i=0; i<y.length; i++) {
1.414 raeburn 11639: if (document.getElementById('portal_def_'+y[i]+'_div')) {
11640: var z = document.getElementById('portal_def_'+y[i]+'_div');
11641: if (x.length > 0) {
11642: z.style.display = 'block';
11643: } else {
11644: z.style.display = 'none';
11645: }
11646: }
11647: }
11648: }
11649: ENDPORTAL
1.236 raeburn 11650: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
11651: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
11652: if ($maxnum eq '') {
11653: $maxnum = 0;
11654: }
11655: $maxnum ++;
1.249 raeburn 11656: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 11657: return <<"ENDSCRIPT";
11658: <script type="text/javascript">
11659: // <![CDATA[
11660: function reorderTypes(form,caller) {
11661: var changedVal;
11662: $jstext
11663: var newpos = 'addinststatus_pos';
11664: var current = new Array;
11665: var maxh = $maxnum;
11666: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11667: var oldVal;
11668: if (caller == newpos) {
11669: changedVal = newitemVal;
11670: } else {
11671: var curritem = 'inststatus_pos_'+caller;
11672: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
11673: current[newitemVal] = newpos;
11674: }
11675: for (var i=0; i<inststatuses.length; i++) {
11676: if (inststatuses[i] != caller) {
11677: var elementName = 'inststatus_pos_'+inststatuses[i];
11678: if (form.elements[elementName]) {
11679: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11680: current[currVal] = elementName;
11681: }
11682: }
11683: }
11684: for (var j=0; j<maxh; j++) {
11685: if (current[j] == undefined) {
11686: oldVal = j;
11687: }
11688: }
11689: if (oldVal < changedVal) {
11690: for (var k=oldVal+1; k<=changedVal ; k++) {
11691: var elementName = current[k];
11692: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11693: }
11694: } else {
11695: for (var k=changedVal; k<oldVal; k++) {
11696: var elementName = current[k];
11697: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11698: }
11699: }
11700: return;
11701: }
11702:
1.414 raeburn 11703: $portal_js
11704:
11705: // ]]>
11706: </script>
11707:
11708: ENDSCRIPT
11709: } else {
11710: return <<"ENDSCRIPT";
11711: <script type="text/javascript">
11712: // <![CDATA[
11713: $portal_js
1.236 raeburn 11714: // ]]>
11715: </script>
11716:
11717: ENDSCRIPT
11718: }
1.354 raeburn 11719: return;
11720: }
11721:
11722: sub passwords_javascript {
1.405 raeburn 11723: my ($prefix) = @_;
11724: my %intalert;
11725: if ($prefix eq 'passwords') {
11726: %intalert = &Apache::lonlocal::texthash (
11727: 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.',
11728: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
11729: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
11730: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
11731: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
11732: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
11733: );
1.421 raeburn 11734: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 11735: %intalert = &Apache::lonlocal::texthash (
11736: passmin => 'Warning: minimum secret length must be a positive integer greater than 6.',
11737: passmax => 'Warning: maximum secret length must be a positive integer (or blank).',
11738: );
11739: }
1.365 raeburn 11740: &js_escape(\%intalert);
11741: my $defmin = $Apache::lonnet::passwdmin;
1.425 raeburn 11742: my $intauthjs;
1.405 raeburn 11743: if ($prefix eq 'passwords') { $intauthjs = <<"ENDSCRIPT";
1.354 raeburn 11744:
11745: function warnIntAuth(field) {
11746: if (field.name == 'intauth_check') {
11747: if (field.value == '2') {
1.365 raeburn 11748: alert('$intalert{authcheck}');
1.354 raeburn 11749: }
11750: }
11751: if (field.name == 'intauth_cost') {
11752: field.value.replace(/\s/g,'');
11753: if (field.value != '') {
11754: var regexdigit=/^\\d+\$/;
11755: if (!regexdigit.test(field.value)) {
1.365 raeburn 11756: alert('$intalert{authcost}');
11757: }
11758: }
11759: }
11760: return;
11761: }
11762:
1.405 raeburn 11763: ENDSCRIPT
11764:
11765: }
11766:
11767: $intauthjs .= <<"ENDSCRIPT";
11768:
11769: function warnInt$prefix(field) {
1.365 raeburn 11770: field.value.replace(/^\s+/,'');
11771: field.value.replace(/\s+\$/,'');
11772: var regexdigit=/^\\d+\$/;
1.408 raeburn 11773: if (field.name == '${prefix}_min') {
1.365 raeburn 11774: if (field.value == '') {
11775: alert('$intalert{passmin}');
11776: field.value = '$defmin';
11777: } else {
11778: if (!regexdigit.test(field.value)) {
11779: alert('$intalert{passmin}');
11780: field.value = '$defmin';
11781: }
1.366 raeburn 11782: var minval = parseInt(field.value,10);
1.365 raeburn 11783: if (minval < $defmin) {
11784: alert('$intalert{passmin}');
11785: field.value = '$defmin';
11786: }
11787: }
11788: } else {
11789: if (field.value == '0') {
11790: field.value = '';
11791: }
11792: if (field.value != '') {
1.408 raeburn 11793: if (field.name == '${prefix}_expire') {
1.365 raeburn 11794: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
11795: if (!regexpposnum.test(field.value)) {
11796: alert('$intalert{passexp}');
11797: field.value = '';
11798: } else {
11799: var expval = parseFloat(field.value);
11800: if (expval == 0) {
11801: alert('$intalert{passexp}');
11802: field.value = '';
11803: }
11804: }
11805: } else {
11806: if (!regexdigit.test(field.value)) {
1.408 raeburn 11807: if (field.name == '${prefix}_max') {
1.365 raeburn 11808: alert('$intalert{passmax}');
11809: } else {
1.408 raeburn 11810: if (field.name == '${prefix}_numsaved') {
1.365 raeburn 11811: alert('$intalert{passnum}');
11812: }
11813: }
1.370 raeburn 11814: field.value = '';
1.365 raeburn 11815: }
1.354 raeburn 11816: }
11817: }
11818: }
11819: return;
11820: }
11821:
11822: ENDSCRIPT
11823: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 11824: }
11825:
1.49 raeburn 11826: sub coursecategories_javascript {
11827: my ($settings) = @_;
1.57 raeburn 11828: my ($output,$jstext,$cathash);
1.49 raeburn 11829: if (ref($settings) eq 'HASH') {
1.57 raeburn 11830: $cathash = $settings->{'cats'};
11831: }
11832: if (ref($cathash) eq 'HASH') {
1.49 raeburn 11833: my (@cats,@jsarray,%idx);
1.57 raeburn 11834: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 11835: if (@jsarray > 0) {
11836: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
11837: for (my $i=0; $i<@jsarray; $i++) {
11838: if (ref($jsarray[$i]) eq 'ARRAY') {
11839: my $catstr = join('","',@{$jsarray[$i]});
11840: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
11841: }
11842: }
11843: }
11844: } else {
11845: $jstext = ' var categories = Array(1);'."\n".
11846: ' categories[0] = Array("instcode_pos");'."\n";
11847: }
1.237 bisitz 11848: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
11849: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 11850: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 11851: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
11852: &js_escape(\$instcode_reserved);
11853: &js_escape(\$communities_reserved);
1.272 raeburn 11854: &js_escape(\$placement_reserved);
1.265 damieng 11855: &js_escape(\$choose_again);
1.49 raeburn 11856: $output = <<"ENDSCRIPT";
11857: <script type="text/javascript">
1.109 raeburn 11858: // <![CDATA[
1.49 raeburn 11859: function reorderCats(form,parent,item,idx) {
11860: var changedVal;
11861: $jstext
11862: var newpos = 'addcategory_pos';
11863: if (parent == '') {
11864: var has_instcode = 0;
11865: var maxtop = categories[idx].length;
11866: for (var j=0; j<maxtop; j++) {
11867: if (categories[idx][j] == 'instcode::0') {
11868: has_instcode == 1;
11869: }
11870: }
11871: if (has_instcode == 0) {
11872: categories[idx][maxtop] = 'instcode_pos';
11873: }
11874: } else {
11875: newpos += '_'+parent;
11876: }
11877: var maxh = 1 + categories[idx].length;
11878: var current = new Array;
11879: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11880: if (item == newpos) {
11881: changedVal = newitemVal;
11882: } else {
11883: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
11884: current[newitemVal] = newpos;
11885: }
11886: for (var i=0; i<categories[idx].length; i++) {
11887: var elementName = categories[idx][i];
11888: if (elementName != item) {
11889: if (form.elements[elementName]) {
11890: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11891: current[currVal] = elementName;
11892: }
11893: }
11894: }
11895: var oldVal;
11896: for (var j=0; j<maxh; j++) {
11897: if (current[j] == undefined) {
11898: oldVal = j;
11899: }
11900: }
11901: if (oldVal < changedVal) {
11902: for (var k=oldVal+1; k<=changedVal ; k++) {
11903: var elementName = current[k];
11904: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11905: }
11906: } else {
11907: for (var k=changedVal; k<oldVal; k++) {
11908: var elementName = current[k];
11909: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11910: }
11911: }
11912: return;
11913: }
1.120 raeburn 11914:
11915: function categoryCheck(form) {
11916: if (form.elements['addcategory_name'].value == 'instcode') {
11917: alert('$instcode_reserved\\n$choose_again');
11918: return false;
11919: }
11920: if (form.elements['addcategory_name'].value == 'communities') {
11921: alert('$communities_reserved\\n$choose_again');
11922: return false;
11923: }
1.272 raeburn 11924: if (form.elements['addcategory_name'].value == 'placement') {
11925: alert('$placement_reserved\\n$choose_again');
11926: return false;
11927: }
1.120 raeburn 11928: return true;
11929: }
11930:
1.109 raeburn 11931: // ]]>
1.49 raeburn 11932: </script>
11933:
11934: ENDSCRIPT
11935: return $output;
11936: }
11937:
1.48 raeburn 11938: sub initialize_categories {
11939: my ($itemcount) = @_;
1.120 raeburn 11940: my ($datatable,$css_class,$chgstr);
1.380 raeburn 11941: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 11942: instcode => 'Official courses (with institutional codes)',
11943: communities => 'Communities',
1.272 raeburn 11944: placement => 'Placement Tests',
1.120 raeburn 11945: );
1.328 raeburn 11946: my %selnum = (
11947: instcode => '0',
11948: communities => '1',
11949: placement => '2',
11950: );
11951: my %selected;
1.272 raeburn 11952: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11953: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 11954: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 11955: map { $selected{$selnum{$_}} = '' } keys(%selnum);
11956: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 11957: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 11958: .'<select name="'.$default.'_pos"'.$chgstr.'>'
11959: .'<option value="0"'.$selected{'0'}.'>1</option>'
11960: .'<option value="1"'.$selected{'1'}.'>2</option>'
11961: .'<option value="2"'.$selected{'2'}.'>3</option>'
11962: .'<option value="3">4</option></select> '
1.120 raeburn 11963: .$default_names{$default}
11964: .'</span></td><td><span class="LC_nobreak">'
11965: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
11966: .&mt('Display').'</label> <label>'
11967: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 11968: .'</label></span></td></tr>';
1.120 raeburn 11969: $itemcount ++;
11970: }
1.48 raeburn 11971: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 11972: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 11973: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 11974: .'<select name="addcategory_pos"'.$chgstr.'>'
11975: .'<option value="0">1</option>'
11976: .'<option value="1">2</option>'
1.328 raeburn 11977: .'<option value="2">3</option>'
11978: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 11979: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
11980: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
11981: .'</td></tr>';
1.48 raeburn 11982: return $datatable;
11983: }
11984:
11985: sub build_category_rows {
1.49 raeburn 11986: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
11987: my ($text,$name,$item,$chgstr);
1.48 raeburn 11988: if (ref($cats) eq 'ARRAY') {
11989: my $maxdepth = scalar(@{$cats});
11990: if (ref($cats->[$depth]) eq 'HASH') {
11991: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
11992: my $numchildren = @{$cats->[$depth]{$parent}};
11993: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 11994: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 11995: my ($idxnum,$parent_name,$parent_item);
11996: my $higher = $depth - 1;
11997: if ($higher == 0) {
11998: $parent_name = &escape($parent).'::'.$higher;
11999: } else {
12000: if (ref($path) eq 'ARRAY') {
12001: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
12002: }
12003: }
12004: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 12005: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 12006: if ($j < $numchildren) {
1.48 raeburn 12007: $name = $cats->[$depth]{$parent}[$j];
12008: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 12009: $idxnum = $idx->{$item};
12010: } else {
12011: $name = $parent_name;
12012: $item = $parent_item;
1.48 raeburn 12013: }
1.49 raeburn 12014: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
12015: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 12016: for (my $i=0; $i<=$numchildren; $i++) {
12017: my $vpos = $i+1;
12018: my $selstr;
12019: if ($j == $i) {
12020: $selstr = ' selected="selected" ';
12021: }
12022: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
12023: }
12024: $text .= '</select> ';
12025: if ($j < $numchildren) {
12026: my $deeper = $depth+1;
12027: $text .= $name.' '
12028: .'<label><input type="checkbox" name="deletecategory" value="'
12029: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
12030: if(ref($path) eq 'ARRAY') {
12031: push(@{$path},$name);
1.49 raeburn 12032: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 12033: pop(@{$path});
12034: }
12035: } else {
1.330 raeburn 12036: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 12037: if ($j == $numchildren) {
12038: $text .= $name;
12039: } else {
12040: $text .= $item;
12041: }
12042: $text .= '" value="" />';
12043: }
12044: $text .= '</td></tr>';
12045: }
12046: $text .= '</table></td>';
12047: } else {
12048: my $higher = $depth-1;
12049: if ($higher == 0) {
12050: $name = &escape($parent).'::'.$higher;
12051: } else {
12052: if (ref($path) eq 'ARRAY') {
12053: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
12054: }
12055: }
12056: my $colspan;
12057: if ($parent ne 'instcode') {
12058: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 12059: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 12060: }
12061: }
12062: }
12063: }
12064: return $text;
12065: }
12066:
1.33 raeburn 12067: sub modifiable_userdata_row {
1.305 raeburn 12068: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357 raeburn 12069: $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228 raeburn 12070: my ($role,$rolename,$statustype);
12071: $role = $item;
1.224 raeburn 12072: if ($context eq 'cancreate') {
1.305 raeburn 12073: if ($item =~ /^(emailusername)_(.+)$/) {
12074: $role = $1;
12075: $statustype = $2;
1.228 raeburn 12076: if (ref($usertypes) eq 'HASH') {
12077: if ($usertypes->{$statustype}) {
12078: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
12079: } else {
12080: $rolename = &mt('Data provided by user');
12081: }
12082: }
1.224 raeburn 12083: }
12084: } elsif ($context eq 'selfcreate') {
1.63 raeburn 12085: if (ref($usertypes) eq 'HASH') {
12086: $rolename = $usertypes->{$role};
12087: } else {
12088: $rolename = $role;
12089: }
1.325 raeburn 12090: } elsif ($context eq 'lti') {
12091: $rolename = &mt('Institutional data used (if available)');
1.357 raeburn 12092: } elsif ($context eq 'privacy') {
12093: $rolename = $itemdesc;
1.33 raeburn 12094: } else {
1.63 raeburn 12095: if ($role eq 'cr') {
12096: $rolename = &mt('Custom role');
12097: } else {
12098: $rolename = &Apache::lonnet::plaintext($role);
12099: }
1.33 raeburn 12100: }
1.224 raeburn 12101: my (@fields,%fieldtitles);
12102: if (ref($fieldsref) eq 'ARRAY') {
12103: @fields = @{$fieldsref};
12104: } else {
12105: @fields = ('lastname','firstname','middlename','generation',
12106: 'permanentemail','id');
12107: }
12108: if ((ref($titlesref) eq 'HASH')) {
12109: %fieldtitles = %{$titlesref};
12110: } else {
12111: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12112: }
1.33 raeburn 12113: my $output;
1.305 raeburn 12114: my $css_class;
12115: if ($rowcount%2) {
12116: $css_class = 'LC_odd_row';
12117: }
12118: if ($customcss) {
12119: $css_class .= " $customcss";
12120: }
12121: $css_class =~ s/^\s+//;
12122: if ($css_class) {
12123: $css_class = ' class="'.$css_class.'"';
12124: }
12125: if ($rowstyle) {
12126: $css_class .= ' style="'.$rowstyle.'"';
12127: }
12128: if ($rowid) {
12129: $rowid = ' id="'.$rowid.'"';
12130: }
12131: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 12132: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
12133: '<td class="LC_left_item" colspan="2"><table>';
12134: my $rem;
12135: my %checks;
12136: if (ref($settings) eq 'HASH') {
1.325 raeburn 12137: my $hashref;
12138: if ($context eq 'lti') {
12139: if (ref($settings) eq 'HASH') {
12140: $hashref = $settings->{'instdata'};
12141: }
1.357 raeburn 12142: } elsif ($context eq 'privacy') {
12143: my ($key,$inner) = split(/_/,$role);
12144: if (ref($settings) eq 'HASH') {
12145: if (ref($settings->{$key}) eq 'HASH') {
12146: $hashref = $settings->{$key}->{$inner};
12147: }
12148: }
1.325 raeburn 12149: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 12150: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 12151: $hashref = $settings->{'lti_instdata'};
12152: }
12153: if ($role eq 'emailusername') {
12154: if ($statustype) {
12155: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
12156: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 12157: }
1.325 raeburn 12158: }
12159: }
12160: }
1.425 raeburn 12161: if (ref($hashref) eq 'HASH') {
1.325 raeburn 12162: foreach my $field (@fields) {
12163: if ($hashref->{$field}) {
12164: if ($role eq 'emailusername') {
12165: $checks{$field} = $hashref->{$field};
12166: } else {
12167: $checks{$field} = ' checked="checked" ';
1.33 raeburn 12168: }
12169: }
12170: }
12171: }
12172: }
1.305 raeburn 12173: my $total = scalar(@fields);
12174: for (my $i=0; $i<$total; $i++) {
12175: $rem = $i%($numinrow);
1.33 raeburn 12176: if ($rem == 0) {
12177: if ($i > 0) {
12178: $output .= '</tr>';
12179: }
12180: $output .= '<tr>';
12181: }
12182: my $check = ' ';
1.228 raeburn 12183: unless ($role eq 'emailusername') {
12184: if (exists($checks{$fields[$i]})) {
1.354 raeburn 12185: $check = $checks{$fields[$i]};
1.357 raeburn 12186: } elsif ($context eq 'privacy') {
12187: if ($role =~ /^priv_(domain|course)$/) {
12188: if (ref($settings) ne 'HASH') {
12189: $check = ' checked="checked" ';
12190: }
12191: } elsif ($role =~ /^priv_(author|community)$/) {
12192: if (ref($settings) ne 'HASH') {
12193: unless ($fields[$i] eq 'id') {
12194: $check = ' checked="checked" ';
12195: }
12196: }
12197: } elsif ($role =~ /^(unpriv|othdom)_/) {
12198: if (ref($settings) ne 'HASH') {
12199: if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
12200: $check = ' checked="checked" ';
12201: }
12202: }
12203: }
1.325 raeburn 12204: } elsif ($context ne 'lti') {
1.228 raeburn 12205: if ($role eq 'st') {
12206: if (ref($settings) ne 'HASH') {
12207: $check = ' checked="checked" ';
12208: }
1.33 raeburn 12209: }
12210: }
12211: }
12212: $output .= '<td class="LC_left_item">'.
1.228 raeburn 12213: '<span class="LC_nobreak">';
1.325 raeburn 12214: my $prefix = 'canmodify';
1.228 raeburn 12215: if ($role eq 'emailusername') {
12216: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
12217: $checks{$fields[$i]} = 'omit';
12218: }
12219: foreach my $option ('required','optional','omit') {
12220: my $checked='';
12221: if ($checks{$fields[$i]} eq $option) {
12222: $checked='checked="checked" ';
12223: }
12224: $output .= '<label>'.
1.325 raeburn 12225: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 12226: &mt($option).'</label>'.(' ' x2);
12227: }
12228: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
12229: } else {
1.325 raeburn 12230: if ($context eq 'lti') {
12231: $prefix = 'lti';
1.357 raeburn 12232: } elsif ($context eq 'privacy') {
12233: $prefix = 'privacy';
1.325 raeburn 12234: }
1.228 raeburn 12235: $output .= '<label>'.
1.325 raeburn 12236: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 12237: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
12238: '</label>';
12239: }
12240: $output .= '</span></td>';
1.33 raeburn 12241: }
1.305 raeburn 12242: $rem = $total%$numinrow;
12243: my $colsleft;
12244: if ($rem) {
12245: $colsleft = $numinrow - $rem;
12246: }
12247: if ($colsleft > 1) {
1.33 raeburn 12248: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
12249: ' </td>';
12250: } elsif ($colsleft == 1) {
12251: $output .= '<td class="LC_left_item"> </td>';
12252: }
12253: $output .= '</tr></table></td></tr>';
12254: return $output;
12255: }
1.28 raeburn 12256:
1.93 raeburn 12257: sub insttypes_row {
1.305 raeburn 12258: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
12259: $customcss,$rowstyle) = @_;
1.93 raeburn 12260: my %lt = &Apache::lonlocal::texthash (
1.429 raeburn 12261: cansearch => 'Users allowed to search',
1.93 raeburn 12262: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.429 raeburn 12263: lockablenames => 'User preference to lock name',
12264: selfassign => 'Self-reportable affiliations',
12265: overrides => "Override domain's helpdesk settings based on requester's affiliation",
12266: webdav => 'WebDAV access available',
12267: authorquota => 'Authoring Space quota (MB)',
1.93 raeburn 12268: );
1.429 raeburn 12269: my ($showdom,$defaultquota);
1.93 raeburn 12270: if ($context eq 'cansearch') {
12271: $showdom = ' ('.$dom.')';
1.429 raeburn 12272: } elsif ($context eq 'authorquota') {
12273: $defaultquota = 500;
1.93 raeburn 12274: }
1.165 raeburn 12275: my $class = 'LC_left_item';
12276: if ($context eq 'statustocreate') {
12277: $class = 'LC_right_item';
12278: }
1.305 raeburn 12279: my $css_class;
12280: if ($$rowtotal%2) {
12281: $css_class = 'LC_odd_row';
12282: }
12283: if ($customcss) {
12284: $css_class .= ' '.$customcss;
12285: }
12286: $css_class =~ s/^\s+//;
12287: if ($css_class) {
12288: $css_class = ' class="'.$css_class.'"';
12289: }
12290: if ($rowstyle) {
12291: $css_class .= ' style="'.$rowstyle.'"';
12292: }
12293: if ($onclick) {
12294: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 12295: }
12296: my $output = '<tr'.$css_class.'>'.
12297: '<td>'.$lt{$context}.$showdom.
12298: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 12299: my $rem;
12300: if (ref($types) eq 'ARRAY') {
12301: for (my $i=0; $i<@{$types}; $i++) {
12302: if (defined($usertypes->{$types->[$i]})) {
12303: my $rem = $i%($numinrow);
12304: if ($rem == 0) {
12305: if ($i > 0) {
12306: $output .= '</tr>';
12307: }
12308: $output .= '<tr>';
1.23 raeburn 12309: }
1.429 raeburn 12310: if ($context eq 'authorquota') {
12311: my $currquota;
12312: if ($settings->{$context}->{$types->[$i]} =~ /^\d+$/) {
12313: $currquota = $settings->{$context}->{$types->[$i]};
12314: } else {
12315: $currquota = $defaultquota;
12316: }
12317: $output .= '<td class="LC_left_item">'."\n".
12318: '<label><span class="LC_nobreak">'."\n".
12319: $usertypes->{$types->[$i]}.'</span><br />'."\n".
12320: '<input type="text" name="'.$context.'_'.$types->[$i].'" '.
12321: 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
12322: '</label></td>';
12323: } else {
12324: my $check = ' ';
12325: if (ref($settings) eq 'HASH') {
12326: if (ref($settings->{$context}) eq 'ARRAY') {
12327: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
12328: $check = ' checked="checked" ';
12329: }
12330: } elsif (ref($settings->{$context}) eq 'HASH') {
12331: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
12332: $check = ' checked="checked" ';
12333: } elsif ($context eq 'webdav') {
12334: if ($settings->{$context}->{$types->[$i]}) {
12335: $check = ' checked="checked" ';
12336: }
12337: }
12338: } elsif ($context eq 'statustocreate') {
1.315 raeburn 12339: $check = ' checked="checked" ';
12340: }
1.26 raeburn 12341: }
1.429 raeburn 12342: $output .= '<td class="LC_left_item">'.
12343: '<span class="LC_nobreak"><label>'.
12344: '<input type="checkbox" name="'.$context.'" '.
12345: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
12346: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 12347: }
12348: }
12349: }
1.26 raeburn 12350: $rem = @{$types}%($numinrow);
1.23 raeburn 12351: }
12352: my $colsleft = $numinrow - $rem;
1.315 raeburn 12353: if ($context eq 'overrides') {
12354: if ($colsleft > 1) {
12355: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12356: } else {
12357: $output .= '<td class="LC_left_item">';
12358: }
1.425 raeburn 12359: $output .= ' ';
1.23 raeburn 12360: } else {
1.334 raeburn 12361: if ($rem == 0) {
1.315 raeburn 12362: $output .= '<tr>';
12363: }
12364: if ($colsleft > 1) {
12365: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12366: } else {
12367: $output .= '<td class="LC_left_item">';
12368: }
1.429 raeburn 12369: if ($context eq 'authorquota') {
12370: my $currquota = 500;
12371: if ((ref($settings) eq 'HASH') && (ref($settings->{$context}) eq 'HASH')) {
12372: if ($settings->{$context}{'default'} =~ /^\d+$/) {
12373: $currquota = $settings->{$context}{'default'};
12374: }
12375: }
12376: $output .= '<label><span class="LC_nobreak">'.$othertitle.'</span><br />'."\n".
12377: '<input type="text" name="'.$context.'_default" '.
12378: 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
12379: '</label>';
12380: } else {
12381: my $defcheck = ' ';
12382: if (ref($settings) eq 'HASH') {
12383: if (ref($settings->{$context}) eq 'ARRAY') {
12384: if (grep(/^default$/,@{$settings->{$context}})) {
12385: $defcheck = ' checked="checked" ';
12386: }
12387: } elsif (ref($settings->{$context}) eq 'HASH') {
12388: if (ref($settings->{$context}->{'default'}) eq 'HASH') {
12389: $defcheck = ' checked="checked" ';
12390: } elsif ($context eq 'webdav') {
12391: if ($settings->{$context}->{'default'}) {
12392: $defcheck = ' checked="checked" ';
12393: }
12394: }
12395: } elsif ($context eq 'statustocreate') {
1.315 raeburn 12396: $defcheck = ' checked="checked" ';
12397: }
1.99 raeburn 12398: }
1.429 raeburn 12399: $output .= '<span class="LC_nobreak"><label>'.
12400: '<input type="checkbox" name="'.$context.'" '.
12401: 'value="default"'.$defcheck.$onclick.'/>'.
12402: $othertitle.'</label></span>';
1.26 raeburn 12403: }
1.23 raeburn 12404: }
1.315 raeburn 12405: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 12406: return $output;
1.23 raeburn 12407: }
12408:
12409: sub sorted_searchtitles {
12410: my %searchtitles = &Apache::lonlocal::texthash(
12411: 'uname' => 'username',
12412: 'lastname' => 'last name',
12413: 'lastfirst' => 'last name, first name',
12414: );
12415: my @titleorder = ('uname','lastname','lastfirst');
12416: return (\%searchtitles,\@titleorder);
12417: }
12418:
1.25 raeburn 12419: sub sorted_searchtypes {
12420: my %srchtypes_desc = (
12421: exact => 'is exact match',
12422: contains => 'contains ..',
12423: begins => 'begins with ..',
12424: );
12425: my @srchtypeorder = ('exact','begins','contains');
12426: return (\%srchtypes_desc,\@srchtypeorder);
12427: }
12428:
1.3 raeburn 12429: sub usertype_update_row {
12430: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
12431: my $datatable;
12432: my $numinrow = 4;
12433: foreach my $type (@{$types}) {
12434: if (defined($usertypes->{$type})) {
12435: $$rownums ++;
12436: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
12437: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
12438: '</td><td class="LC_left_item"><table>';
12439: for (my $i=0; $i<@{$fields}; $i++) {
12440: my $rem = $i%($numinrow);
12441: if ($rem == 0) {
12442: if ($i > 0) {
12443: $datatable .= '</tr>';
12444: }
12445: $datatable .= '<tr>';
12446: }
12447: my $check = ' ';
1.39 raeburn 12448: if (ref($settings) eq 'HASH') {
12449: if (ref($settings->{'fields'}) eq 'HASH') {
12450: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
12451: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
12452: $check = ' checked="checked" ';
12453: }
1.3 raeburn 12454: }
12455: }
12456: }
12457:
12458: if ($i == @{$fields}-1) {
12459: my $colsleft = $numinrow - $rem;
12460: if ($colsleft > 1) {
12461: $datatable .= '<td colspan="'.$colsleft.'">';
12462: } else {
12463: $datatable .= '<td>';
12464: }
12465: } else {
12466: $datatable .= '<td>';
12467: }
1.8 raeburn 12468: $datatable .= '<span class="LC_nobreak"><label>'.
12469: '<input type="checkbox" name="updateable_'.$type.
12470: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
12471: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 12472: }
12473: $datatable .= '</tr></table></td></tr>';
12474: }
12475: }
12476: return $datatable;
1.1 raeburn 12477: }
12478:
12479: sub modify_login {
1.205 raeburn 12480: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 12481: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.386 raeburn 12482: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
1.412 raeburn 12483: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso);
1.168 raeburn 12484: %title = ( coursecatalog => 'Display course catalog',
12485: adminmail => 'Display administrator E-mail address',
1.188 raeburn 12486: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 12487: newuser => 'Link for visitors to create a user account',
1.386 raeburn 12488: loginheader => 'Log-in box header',
12489: saml => 'Dual SSO and non-SSO login');
1.168 raeburn 12490: @offon = ('off','on');
1.112 raeburn 12491: if (ref($domconfig{login}) eq 'HASH') {
12492: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
12493: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
12494: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
12495: }
12496: }
1.386 raeburn 12497: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
12498: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
12499: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
12500: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
12501: $saml{$lonhost} = 1;
12502: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
12503: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
12504: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
12505: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
12506: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
1.412 raeburn 12507: $samlwindow{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'window'};
1.386 raeburn 12508: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
12509: }
12510: }
12511: }
1.112 raeburn 12512: }
1.9 raeburn 12513: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
12514: \%domconfig,\%loginhash);
1.188 raeburn 12515: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12516: foreach my $item (@toggles) {
12517: $loginhash{login}{$item} = $env{'form.'.$item};
12518: }
1.41 raeburn 12519: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 12520: if (ref($colchanges{'login'}) eq 'HASH') {
12521: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
12522: \%loginhash);
12523: }
1.110 raeburn 12524:
1.149 raeburn 12525: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 12526: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 12527: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 12528: if (keys(%servers) > 1) {
12529: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 12530: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
12531: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
12532: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
12533: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
12534: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
12535: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12536: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12537: $changes{'loginvia'}{$lonhost} = 1;
12538: } else {
12539: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
12540: $changes{'loginvia'}{$lonhost} = 1;
12541: }
12542: } else {
12543: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12544: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12545: $changes{'loginvia'}{$lonhost} = 1;
12546: }
12547: }
12548: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
12549: foreach my $item (@loginvia_attribs) {
12550: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
12551: }
12552: } else {
12553: foreach my $item (@loginvia_attribs) {
12554: my $new = $env{'form.'.$lonhost.'_'.$item};
12555: if (($item eq 'serverpath') && ($new eq 'custom')) {
12556: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
12557: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12558: $new = '/';
12559: }
12560: }
12561: if (($item eq 'custompath') &&
12562: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12563: $new = '';
12564: }
12565: if ($new ne $curr_loginvia{$lonhost}{$item}) {
12566: $changes{'loginvia'}{$lonhost} = 1;
12567: }
12568: if ($item eq 'exempt') {
1.256 raeburn 12569: $new = &check_exempt_addresses($new);
1.128 raeburn 12570: }
12571: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12572: }
12573: }
1.112 raeburn 12574: } else {
1.128 raeburn 12575: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12576: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 12577: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 12578: foreach my $item (@loginvia_attribs) {
12579: my $new = $env{'form.'.$lonhost.'_'.$item};
12580: if (($item eq 'serverpath') && ($new eq 'custom')) {
12581: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12582: $new = '/';
12583: }
12584: }
12585: if (($item eq 'custompath') &&
12586: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12587: $new = '';
12588: }
12589: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12590: }
1.110 raeburn 12591: }
12592: }
12593: }
12594: }
1.119 raeburn 12595:
1.168 raeburn 12596: my $servadm = $r->dir_config('lonAdmEMail');
12597: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
12598: if (ref($domconfig{'login'}) eq 'HASH') {
12599: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
12600: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
12601: if ($lang eq 'nolang') {
12602: push(@currlangs,$lang);
12603: } elsif (defined($langchoices{$lang})) {
12604: push(@currlangs,$lang);
12605: } else {
12606: next;
12607: }
12608: }
12609: }
12610: }
12611: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
12612: if (@currlangs > 0) {
12613: foreach my $lang (@currlangs) {
12614: if (grep(/^\Q$lang\E$/,@delurls)) {
12615: $changes{'helpurl'}{$lang} = 1;
12616: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
12617: $changes{'helpurl'}{$lang} = 1;
12618: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
12619: push(@newlangs,$lang);
12620: } else {
12621: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12622: }
12623: }
12624: }
12625: unless (grep(/^nolang$/,@currlangs)) {
12626: if ($env{'form.loginhelpurl_nolang.filename'}) {
12627: $changes{'helpurl'}{'nolang'} = 1;
12628: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
12629: push(@newlangs,'nolang');
12630: }
12631: }
12632: if ($env{'form.loginhelpurl_add_lang'}) {
12633: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
12634: ($env{'form.loginhelpurl_add_file.filename'})) {
12635: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
12636: $addedfile = $env{'form.loginhelpurl_add_lang'};
12637: }
12638: }
12639: if ((@newlangs > 0) || ($addedfile)) {
12640: my $error;
12641: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12642: if ($configuserok eq 'ok') {
12643: if ($switchserver) {
12644: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
12645: } elsif ($author_ok eq 'ok') {
12646: my @allnew = @newlangs;
12647: if ($addedfile ne '') {
12648: push(@allnew,$addedfile);
12649: }
1.421 raeburn 12650: my $modified = [];
1.168 raeburn 12651: foreach my $lang (@allnew) {
12652: my $formelem = 'loginhelpurl_'.$lang;
12653: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
12654: $formelem = 'loginhelpurl_add_file';
12655: }
1.425 raeburn 12656: (my $result,$newurl{$lang}) =
1.421 raeburn 12657: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12658: "help/$lang",'','',$newfile{$lang},
12659: $modified);
1.168 raeburn 12660: if ($result eq 'ok') {
12661: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
12662: $changes{'helpurl'}{$lang} = 1;
12663: } else {
12664: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
12665: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 12666: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 12667: (!grep(/^\Q$lang\E$/,@delurls))) {
12668: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12669: }
12670: }
12671: }
1.421 raeburn 12672: &update_modify_urls($r,$modified);
1.168 raeburn 12673: } else {
12674: $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);
12675: }
12676: } else {
12677: $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);
12678: }
12679: if ($error) {
12680: &Apache::lonnet::logthis($error);
12681: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12682: }
12683: }
1.256 raeburn 12684:
12685: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
12686: if (ref($domconfig{'login'}) eq 'HASH') {
12687: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
12688: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
12689: if ($domservers{$lonhost}) {
12690: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12691: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 12692: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 12693: }
12694: }
12695: }
12696: }
12697: }
12698: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
12699: foreach my $lonhost (sort(keys(%domservers))) {
12700: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12701: $changes{'headtag'}{$lonhost} = 1;
12702: } else {
12703: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
12704: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
12705: }
12706: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
12707: push(@newhosts,$lonhost);
12708: } elsif ($currheadtagurls{$lonhost}) {
12709: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
12710: if ($currexempt{$lonhost}) {
1.289 raeburn 12711: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 12712: $changes{'headtag'}{$lonhost} = 1;
12713: }
12714: } elsif ($possexempt{$lonhost}) {
12715: $changes{'headtag'}{$lonhost} = 1;
12716: }
12717: if ($possexempt{$lonhost}) {
12718: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12719: }
12720: }
12721: }
12722: }
12723: if (@newhosts) {
12724: my $error;
12725: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12726: if ($configuserok eq 'ok') {
12727: if ($switchserver) {
12728: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
12729: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12730: my $modified = [];
1.256 raeburn 12731: foreach my $lonhost (@newhosts) {
12732: my $formelem = 'loginheadtag_'.$lonhost;
1.425 raeburn 12733: (my $result,$newheadtagurls{$lonhost}) =
1.421 raeburn 12734: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12735: "login/headtag/$lonhost",'','',
12736: $env{'form.loginheadtag_'.$lonhost.'.filename'},
12737: $modified);
1.256 raeburn 12738: if ($result eq 'ok') {
12739: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
12740: $changes{'headtag'}{$lonhost} = 1;
12741: if ($possexempt{$lonhost}) {
12742: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12743: }
12744: } else {
12745: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
12746: $newheadtagurls{$lonhost},$result);
12747: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12748: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
12749: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
12750: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
12751: }
12752: }
12753: }
1.421 raeburn 12754: &update_modify_urls($r,$modified);
1.256 raeburn 12755: } else {
12756: $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);
12757: }
12758: } else {
12759: $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);
12760: }
12761: if ($error) {
12762: &Apache::lonnet::logthis($error);
12763: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12764: }
12765: }
1.386 raeburn 12766: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
12767: my @newsamlimgs;
12768: foreach my $lonhost (keys(%domservers)) {
12769: if ($env{'form.saml_'.$lonhost}) {
12770: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
12771: push(@newsamlimgs,$lonhost);
12772: }
1.412 raeburn 12773: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12774: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
12775: }
12776: if ($saml{$lonhost}) {
1.412 raeburn 12777: if ($env{'form.saml_window_'.$lonhost} ne '1') {
12778: $env{'form.saml_window_'.$lonhost} = '';
12779: }
1.386 raeburn 12780: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
12781: #FIXME Need to obsolete published image
12782: delete($currsaml{$lonhost}{'img'});
12783: $changes{'saml'}{$lonhost} = 1;
12784: }
12785: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
12786: $changes{'saml'}{$lonhost} = 1;
12787: }
12788: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
12789: $changes{'saml'}{$lonhost} = 1;
12790: }
12791: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
12792: $changes{'saml'}{$lonhost} = 1;
12793: }
12794: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
12795: $changes{'saml'}{$lonhost} = 1;
12796: }
1.412 raeburn 12797: if ($env{'form.saml_window_'.$lonhost} ne $samlwindow{$lonhost}) {
12798: $changes{'saml'}{$lonhost} = 1;
12799: }
1.386 raeburn 12800: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
12801: $changes{'saml'}{$lonhost} = 1;
12802: }
12803: } else {
12804: $changes{'saml'}{$lonhost} = 1;
12805: }
1.412 raeburn 12806: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12807: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
12808: }
12809: } else {
1.425 raeburn 12810: if ($saml{$lonhost}) {
1.389 raeburn 12811: $changes{'saml'}{$lonhost} = 1;
12812: delete($currsaml{$lonhost});
12813: }
1.386 raeburn 12814: }
12815: }
12816: foreach my $posshost (keys(%currsaml)) {
1.425 raeburn 12817: unless (exists($domservers{$posshost})) {
12818: delete($currsaml{$posshost});
1.386 raeburn 12819: }
12820: }
12821: %{$loginhash{'login'}{'saml'}} = %currsaml;
12822: if (@newsamlimgs) {
12823: my $error;
12824: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12825: if ($configuserok eq 'ok') {
12826: if ($switchserver) {
12827: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
12828: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12829: my $modified = [];
1.386 raeburn 12830: foreach my $lonhost (@newsamlimgs) {
12831: my $formelem = 'saml_img_'.$lonhost;
1.425 raeburn 12832: my ($result,$imgurl) =
1.421 raeburn 12833: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12834: "login/saml/$lonhost",'','',
12835: $env{'form.saml_img_'.$lonhost.'.filename'},
12836: $modified);
1.386 raeburn 12837: if ($result eq 'ok') {
12838: $currsaml{$lonhost}{'img'} = $imgurl;
12839: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
12840: $changes{'saml'}{$lonhost} = 1;
12841: } else {
12842: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
12843: $lonhost,$result);
12844: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12845: }
12846: }
1.421 raeburn 12847: &update_modify_urls($r,$modified);
1.386 raeburn 12848: } else {
12849: $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);
12850: }
12851: } else {
12852: $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);
12853: }
12854: if ($error) {
12855: &Apache::lonnet::logthis($error);
12856: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12857: }
12858: }
1.169 raeburn 12859: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 12860:
12861: my $defaulthelpfile = '/adm/loginproblems.html';
12862: my $defaulttext = &mt('Default in use');
12863:
1.1 raeburn 12864: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
12865: $dom);
12866: if ($putresult eq 'ok') {
1.188 raeburn 12867: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12868: my %defaultchecked = (
12869: 'coursecatalog' => 'on',
1.188 raeburn 12870: 'helpdesk' => 'on',
1.42 raeburn 12871: 'adminmail' => 'off',
1.43 raeburn 12872: 'newuser' => 'off',
1.42 raeburn 12873: );
1.55 raeburn 12874: if (ref($domconfig{'login'}) eq 'HASH') {
12875: foreach my $item (@toggles) {
12876: if ($defaultchecked{$item} eq 'on') {
12877: if (($domconfig{'login'}{$item} eq '0') &&
12878: ($env{'form.'.$item} eq '1')) {
12879: $changes{$item} = 1;
12880: } elsif (($domconfig{'login'}{$item} eq '' ||
12881: $domconfig{'login'}{$item} eq '1') &&
12882: ($env{'form.'.$item} eq '0')) {
12883: $changes{$item} = 1;
12884: }
12885: } elsif ($defaultchecked{$item} eq 'off') {
12886: if (($domconfig{'login'}{$item} eq '1') &&
12887: ($env{'form.'.$item} eq '0')) {
12888: $changes{$item} = 1;
12889: } elsif (($domconfig{'login'}{$item} eq '' ||
12890: $domconfig{'login'}{$item} eq '0') &&
12891: ($env{'form.'.$item} eq '1')) {
12892: $changes{$item} = 1;
12893: }
1.42 raeburn 12894: }
12895: }
1.41 raeburn 12896: }
1.6 raeburn 12897: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 12898: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.386 raeburn 12899: if (exists($changes{'saml'})) {
12900: my $hostid_in_use;
12901: my @hosts = &Apache::lonnet::current_machine_ids();
12902: if (@hosts > 1) {
12903: foreach my $hostid (@hosts) {
12904: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
12905: $hostid_in_use = $hostid;
12906: last;
12907: }
12908: }
12909: } else {
12910: $hostid_in_use = $r->dir_config('lonHostID');
12911: }
12912: if (($hostid_in_use) &&
12913: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
1.387 raeburn 12914: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
1.386 raeburn 12915: }
12916: if (ref($lastactref) eq 'HASH') {
12917: if (ref($changes{'saml'}) eq 'HASH') {
12918: my %updates;
12919: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
12920: $lastactref->{'samllanding'} = \%updates;
12921: }
12922: }
12923: }
1.212 raeburn 12924: if (ref($lastactref) eq 'HASH') {
12925: $lastactref->{'domainconfig'} = 1;
12926: }
1.1 raeburn 12927: $resulttext = &mt('Changes made:').'<ul>';
12928: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 12929: if ($item eq 'loginvia') {
1.112 raeburn 12930: if (ref($changes{$item}) eq 'HASH') {
12931: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
12932: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 12933: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
12934: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
12935: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
12936: $protocol = 'http' if ($protocol ne 'https');
12937: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
12938:
12939: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
12940: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
12941: } else {
12942: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
12943: }
12944: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
12945: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
12946: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
12947: }
12948: $resulttext .= '</li>';
12949: } else {
12950: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
12951: }
1.112 raeburn 12952: } else {
1.128 raeburn 12953: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 12954: }
12955: }
1.128 raeburn 12956: $resulttext .= '</ul></li>';
1.112 raeburn 12957: }
1.168 raeburn 12958: } elsif ($item eq 'helpurl') {
12959: if (ref($changes{$item}) eq 'HASH') {
12960: foreach my $lang (sort(keys(%{$changes{$item}}))) {
12961: if (grep(/^\Q$lang\E$/,@delurls)) {
12962: my ($chg,$link);
12963: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
12964: if ($lang eq 'nolang') {
12965: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
12966: } else {
12967: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
12968: }
12969: $resulttext .= '<li>'.$chg.'</li>';
12970: } else {
12971: my $chg;
12972: if ($lang eq 'nolang') {
12973: $chg = &mt('custom log-in help file for no preferred language');
12974: } else {
12975: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
12976: }
12977: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
12978: $loginhash{'login'}{'helpurl'}{$lang}.
12979: '?inhibitmenu=yes',$chg,600,500).
12980: '</li>';
12981: }
12982: }
12983: }
1.256 raeburn 12984: } elsif ($item eq 'headtag') {
12985: if (ref($changes{$item}) eq 'HASH') {
12986: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12987: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12988: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
12989: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12990: $resulttext .= '<li><a href="'.
12991: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
12992: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
12993: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
12994: if ($possexempt{$lonhost}) {
12995: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
12996: } else {
12997: $resulttext .= &mt('included for any client IP');
12998: }
12999: $resulttext .= '</li>';
13000: }
13001: }
13002: }
1.386 raeburn 13003: } elsif ($item eq 'saml') {
13004: if (ref($changes{$item}) eq 'HASH') {
13005: my %notlt = (
13006: text => 'Text for log-in by SSO',
13007: img => 'SSO button image',
13008: alt => 'Alt text for button image',
13009: url => 'SSO URL',
13010: title => 'Tooltip for SSO link',
1.412 raeburn 13011: window => 'Pop-up window if iframe',
1.386 raeburn 13012: notsso => 'Text for non-SSO log-in',
13013: );
13014: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
13015: if (ref($currsaml{$lonhost}) eq 'HASH') {
13016: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
13017: '<ul>';
1.412 raeburn 13018: foreach my $key ('text','img','alt','url','title','window','notsso') {
1.386 raeburn 13019: if ($currsaml{$lonhost}{$key} eq '') {
13020: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
13021: } else {
13022: my $value = "'$currsaml{$lonhost}{$key}'";
13023: if ($key eq 'img') {
13024: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
1.412 raeburn 13025: } elsif ($key eq 'window') {
13026: $value = 'On';
1.386 raeburn 13027: }
13028: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
13029: $value).'</li>';
13030: }
13031: }
13032: $resulttext .= '</ul></li>';
13033: } else {
13034: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
13035: }
13036: }
13037: }
1.169 raeburn 13038: } elsif ($item eq 'captcha') {
13039: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 13040: my $chgtxt;
1.169 raeburn 13041: if ($loginhash{'login'}{$item} eq 'notused') {
13042: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
13043: } else {
13044: my %captchas = &captcha_phrases();
13045: if ($captchas{$loginhash{'login'}{$item}}) {
13046: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
13047: } else {
13048: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
13049: }
13050: }
13051: $resulttext .= '<li>'.$chgtxt.'</li>';
13052: }
13053: } elsif ($item eq 'recaptchakeys') {
13054: if (ref($loginhash{'login'}) eq 'HASH') {
13055: my ($privkey,$pubkey);
13056: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
13057: $pubkey = $loginhash{'login'}{$item}{'public'};
13058: $privkey = $loginhash{'login'}{$item}{'private'};
13059: }
13060: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
13061: if (!$pubkey) {
13062: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
13063: } else {
13064: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
13065: }
13066: if (!$privkey) {
13067: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
13068: } else {
1.251 raeburn 13069: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 13070: }
13071: $chgtxt .= '</ul>';
13072: $resulttext .= '<li>'.$chgtxt.'</li>';
13073: }
1.269 raeburn 13074: } elsif ($item eq 'recaptchaversion') {
13075: if (ref($loginhash{'login'}) eq 'HASH') {
13076: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 13077: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 13078: '</li>';
13079: }
13080: }
1.41 raeburn 13081: } else {
13082: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
13083: }
1.1 raeburn 13084: }
1.6 raeburn 13085: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 13086: } else {
13087: $resulttext = &mt('No changes made to log-in page settings');
13088: }
13089: } else {
1.11 albertel 13090: $resulttext = '<span class="LC_error">'.
13091: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 13092: }
1.6 raeburn 13093: if ($errors) {
1.9 raeburn 13094: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 13095: $errors.'</ul>';
13096: }
13097: return $resulttext;
13098: }
13099:
1.256 raeburn 13100: sub check_exempt_addresses {
13101: my ($iplist) = @_;
13102: $iplist =~ s/^\s+//;
13103: $iplist =~ s/\s+$//;
13104: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
13105: my (@okips,$new);
13106: foreach my $ip (@poss_ips) {
13107: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
13108: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
13109: push(@okips,$ip);
13110: }
13111: }
13112: }
13113: if (@okips > 0) {
13114: $new = join(',',@okips);
13115: } else {
13116: $new = '';
13117: }
13118: return $new;
13119: }
13120:
1.6 raeburn 13121: sub color_font_choices {
13122: my %choices =
13123: &Apache::lonlocal::texthash (
13124: img => "Header",
13125: bgs => "Background colors",
13126: links => "Link colors",
1.55 raeburn 13127: images => "Images",
1.6 raeburn 13128: font => "Font color",
1.201 raeburn 13129: fontmenu => "Font menu",
1.76 raeburn 13130: pgbg => "Page",
1.6 raeburn 13131: tabbg => "Header",
13132: sidebg => "Border",
13133: link => "Link",
13134: alink => "Active link",
13135: vlink => "Visited link",
13136: );
13137: return %choices;
13138: }
13139:
1.394 raeburn 13140: sub modify_ipaccess {
13141: my ($dom,$lastactref,%domconfig) = @_;
13142: my (@allpos,%changes,%confhash,$errors,$resulttext);
13143: my (@items,%deletions,%itemids,@warnings);
13144: my ($typeorder,$types) = &commblocktype_text();
13145: if ($env{'form.ipaccess_add'}) {
13146: my $name = $env{'form.ipaccess_name_add'};
13147: my ($newid,$error) = &get_ipaccess_id($dom,$name);
13148: if ($newid) {
13149: $itemids{'add'} = $newid;
13150: push(@items,'add');
13151: $changes{$newid} = 1;
13152: } else {
13153: $error = &mt('Failed to acquire unique ID for new IP access control item');
13154: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13155: }
13156: }
13157: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
13158: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
13159: if (@todelete) {
13160: map { $deletions{$_} = 1; } @todelete;
13161: }
13162: my $maxnum = $env{'form.ipaccess_maxnum'};
13163: for (my $i=0; $i<$maxnum; $i++) {
13164: my $itemid = $env{'form.ipaccess_id_'.$i};
13165: $itemid =~ s/\D+//g;
13166: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13167: if ($deletions{$itemid}) {
13168: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
13169: } else {
13170: push(@items,$i);
13171: $itemids{$i} = $itemid;
13172: }
13173: }
13174: }
13175: }
13176: foreach my $idx (@items) {
13177: my $itemid = $itemids{$idx};
13178: next unless ($itemid);
13179: my %current;
13180: unless ($idx eq 'add') {
13181: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13182: %current = %{$domconfig{'ipaccess'}{$itemid}};
13183: }
13184: }
13185: my $position = $env{'form.ipaccess_pos_'.$itemid};
13186: $position =~ s/\D+//g;
13187: if ($position ne '') {
13188: $allpos[$position] = $itemid;
13189: }
13190: my $name = $env{'form.ipaccess_name_'.$idx};
13191: $name =~ s/^\s+|\s+$//g;
13192: $confhash{$itemid}{'name'} = $name;
13193: my $possrange = $env{'form.ipaccess_range_'.$idx};
13194: $possrange =~ s/^\s+|\s+$//g;
13195: unless ($possrange eq '') {
13196: $possrange =~ s/[\r\n]+/\s/g;
13197: $possrange =~ s/\s*-\s*/-/g;
13198: $possrange =~ s/\s+/,/g;
13199: $possrange =~ s/,+/,/g;
13200: if ($possrange ne '') {
13201: my (@ok,$count);
1.425 raeburn 13202: $count = 0;
1.394 raeburn 13203: foreach my $poss (split(/\,/,$possrange)) {
13204: $count ++;
13205: $poss = &validate_ip_pattern($poss);
13206: if ($poss ne '') {
13207: push(@ok,$poss);
13208: }
13209: }
13210: my $diff = $count - scalar(@ok);
13211: if ($diff) {
13212: $errors .= '<li><span class="LC_error">'.
13213: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
13214: $diff,$name).
13215: '</span></li>';
13216: }
13217: if (@ok) {
13218: my @cidr_list;
13219: foreach my $item (@ok) {
13220: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
13221: }
13222: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
13223: }
13224: }
13225: }
13226: foreach my $field ('name','ip') {
13227: unless (($idx eq 'add') || ($changes{$itemid})) {
13228: if ($current{$field} ne $confhash{$itemid}{$field}) {
13229: $changes{$itemid} = 1;
13230: last;
13231: }
13232: }
13233: }
13234: $confhash{$itemid}{'commblocks'} = {};
1.425 raeburn 13235:
1.394 raeburn 13236: my %commblocks;
1.425 raeburn 13237: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
1.394 raeburn 13238: foreach my $type (@{$typeorder}) {
13239: if ($commblocks{$type}) {
13240: $confhash{$itemid}{'commblocks'}{$type} = 'on';
13241: }
13242: unless (($idx eq 'add') || ($changes{$itemid})) {
13243: if (ref($current{'commblocks'}) eq 'HASH') {
13244: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
13245: $changes{$itemid} = 1;
13246: }
13247: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
13248: $changes{$itemid} = 1;
13249: }
13250: }
13251: }
13252: $confhash{$itemid}{'courses'} = {};
13253: my %crsdeletions;
13254: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
13255: if (@delcrs) {
13256: map { $crsdeletions{$_} = 1; } @delcrs;
13257: }
13258: if (ref($current{'courses'}) eq 'HASH') {
13259: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
13260: if ($crsdeletions{$cid}) {
13261: $changes{$itemid} = 1;
13262: } else {
13263: $confhash{$itemid}{'courses'}{$cid} = 1;
13264: }
13265: }
13266: }
13267: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
13268: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
1.425 raeburn 13269: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
1.394 raeburn 13270: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
13271: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
13272: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
13273: $errors .= '<li><span class="LC_error">'.
13274: &mt('Invalid courseID [_1] omitted from list of allowed courses',
13275: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
13276: '</span></li>';
13277: } else {
13278: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
13279: $changes{$itemid} = 1;
13280: }
13281: }
13282: }
13283: if (@allpos > 0) {
13284: my $idx = 0;
13285: foreach my $itemid (@allpos) {
13286: if ($itemid ne '') {
13287: $confhash{$itemid}{'order'} = $idx;
13288: unless ($changes{$itemid}) {
13289: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
13290: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13291: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
13292: $changes{$itemid} = 1;
13293: }
13294: }
13295: }
13296: }
13297: $idx ++;
13298: }
13299: }
13300: }
13301: if (keys(%changes)) {
13302: my %defaultshash = (
13303: ipaccess => \%confhash,
13304: );
13305: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13306: $dom);
13307: if ($putresult eq 'ok') {
13308: my $cachetime = 1800;
13309: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
13310: if (ref($lastactref) eq 'HASH') {
13311: $lastactref->{'ipaccess'} = 1;
13312: }
13313: $resulttext = &mt('Changes made:').'<ul>';
13314: my %bynum;
13315: foreach my $itemid (sort(keys(%changes))) {
13316: if (ref($confhash{$itemid}) eq 'HASH') {
13317: my $position = $confhash{$itemid}{'order'};
13318: if ($position =~ /^\d+$/) {
13319: $bynum{$position} = $itemid;
13320: }
13321: }
13322: }
13323: if (keys(%deletions)) {
13324: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
13325: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
13326: }
13327: }
13328: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
13329: my $itemid = $bynum{$pos};
13330: if (ref($confhash{$itemid}) eq 'HASH') {
13331: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
13332: my $position = $pos + 1;
13333: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
13334: if ($confhash{$itemid}{'ip'} eq '') {
13335: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
13336: } else {
13337: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
13338: }
13339: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
13340: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
13341: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
13342: '</li>';
13343: } else {
13344: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
13345: }
13346: if (keys(%{$confhash{$itemid}{'courses'}})) {
13347: my @courses;
13348: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
1.425 raeburn 13349: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1.394 raeburn 13350: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
13351: }
13352: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
13353: join('</li><li>',@courses).'</li></ul>';
13354: } else {
13355: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
13356: }
1.395 raeburn 13357: $resulttext .= '</ul></li>';
1.394 raeburn 13358: }
13359: }
1.395 raeburn 13360: $resulttext .= '</ul>';
1.394 raeburn 13361: } else {
13362: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13363: }
13364: } else {
13365: $resulttext = &mt('No changes made');
13366: }
13367: if ($errors) {
13368: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
13369: $errors.'</ul></p>';
13370: }
13371: return $resulttext;
13372: }
13373:
13374: sub get_ipaccess_id {
13375: my ($domain,$location) = @_;
13376: # get lock on ipaccess db
13377: my $lockhash = {
13378: lock => $env{'user.name'}.
13379: ':'.$env{'user.domain'},
13380: };
13381: my $tries = 0;
13382: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13383: my ($id,$error);
13384:
13385: while (($gotlock ne 'ok') && ($tries<10)) {
13386: $tries ++;
13387: sleep (0.1);
13388: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13389: }
13390: if ($gotlock eq 'ok') {
13391: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
13392: if ($currids{'lock'}) {
13393: delete($currids{'lock'});
13394: if (keys(%currids)) {
13395: my @curr = sort { $a <=> $b } keys(%currids);
13396: if ($curr[-1] =~ /^\d+$/) {
13397: $id = 1 + $curr[-1];
13398: }
13399: } else {
13400: $id = 1;
13401: }
13402: if ($id) {
13403: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
13404: $error = 'nostore';
13405: }
13406: } else {
13407: $error = 'nonumber';
13408: }
13409: }
13410: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
13411: } else {
13412: $error = 'nolock';
13413: }
13414: return ($id,$error);
13415: }
13416:
1.429 raeburn 13417: sub modify_authordefaults {
13418: my ($dom,$lastactref,%domconfig) = @_;
13419: #
13420: # Retrieve current domain configuration for webDAV and Authoring Space quotas from $domconfig{'quotas'}.
13421: #
13422: my (%curr_quotas,%save_quotas,%confhash,%changes,%newvalues);
13423: if (ref($domconfig{'quotas'}) eq 'HASH') {
13424: foreach my $key (keys(%{$domconfig{'quotas'}})) {
13425: if ($key =~ /^webdav|authorquota$/) {
13426: $curr_quotas{$key} = $domconfig{'quotas'}{$key};
13427: } else {
13428: $save_quotas{$key} = $domconfig{'quotas'}{$key};
13429: }
13430: }
13431: }
13432: my %staticdefaults = (
13433: 'copyright' => 'default',
13434: 'sourceavail' => 'closed',
13435: 'nocodemirror' => 'off',
1.437 raeburn 13436: 'daxecollapse' => 'off',
1.429 raeburn 13437: 'domcoordacc' => 'on',
1.439 raeburn 13438: 'editors' => ['edit','xml'],
1.429 raeburn 13439: 'authorquota' => 500,
13440: 'webdav' => 0,
1.440 raeburn 13441: 'archive' => 'off',
1.429 raeburn 13442: );
13443: my %titles = &authordefaults_titles();
1.440 raeburn 13444: foreach my $item ('nocodemirror','daxecollapse','domcoordacc','archive') {
1.429 raeburn 13445: if ($env{'form.'.$item} =~ /^(0|1)$/) {
13446: $confhash{$item} = $env{'form.'.$item};
13447: }
13448: }
13449: if ($env{'form.copyright'} =~ /^(default|domain|public)$/) {
13450: $confhash{'copyright'} = $1;
13451: }
13452: if ($env{'form.sourceavail'} =~ /^(closed|open)$/) {
13453: $confhash{'sourceavail'} = $1;
13454: }
13455: my @posseditors = &Apache::loncommon::get_env_multiple('form.author_editors');
13456: my @okeditors = ('edit','xml','daxe');
13457: my @editors;
13458: foreach my $item (@posseditors) {
13459: if (grep(/^\Q$item\E$/,@okeditors)) {
13460: push(@editors,$item);
13461: }
13462: }
13463: $confhash{'editors'} = \@editors;
1.436 raeburn 13464:
1.429 raeburn 13465: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13466: my @insttypes;
13467: if (ref($types) eq 'ARRAY') {
13468: @insttypes = @{$types};
13469: }
13470: my @webdavon = &Apache::loncommon::get_env_multiple('form.webdav');
13471: my %webdav;
13472: map { $webdav{$_} = 1; } @webdavon;
13473: foreach my $type (@insttypes,'default') {
13474: my $possquota = $env{'form.authorquota_'.$type};
13475: if ($possquota =~ /^\d+$/) {
13476: $save_quotas{'authorquota'}{$type} = $possquota;
13477: }
13478: if ($webdav{$type}) {
13479: $save_quotas{'webdav'}{$type} = 1;
13480: } else {
13481: $save_quotas{'webdav'}{$type} = 0;
13482: }
13483: }
13484: if ($env{'form.webdav_LC_adv'} =~ /^(0|1)$/) {
13485: $save_quotas{'webdav'}{'_LC_adv'} = $env{'form.webdav_LC_adv'};
13486: }
13487: if (ref($domconfig{'authordefaults'}) eq 'HASH') {
1.440 raeburn 13488: foreach my $item ('nocodemirror','daxecollapse','domcoordacc','copyright','sourceavail','archive') {
1.429 raeburn 13489: if ($domconfig{'authordefaults'}{$item} ne $confhash{$item}) {
13490: $changes{$item} = 1;
13491: }
13492: }
13493: if (ref($domconfig{'authordefaults'}{'editors'}) eq 'ARRAY') {
1.436 raeburn 13494: my @diffs =
1.429 raeburn 13495: &Apache::loncommon::compare_arrays($confhash{'editors'},
13496: $domconfig{'authordefaults'}{'editors'});
13497: unless (@diffs == 0) {
13498: $changes{'editors'} = 1;
13499: }
13500: } else {
13501: my @diffs =
13502: &Apache::loncommon::compare_arrays($confhash{'editors'},
13503: $staticdefaults{'editors'});
13504: unless (@diffs == 0) {
13505: $changes{'editors'} = 1;
13506: }
13507: }
13508: } else {
13509: my @offon = ('off','on');
1.440 raeburn 13510: foreach my $item ('nocodemirror','daxecollapse','domcoordacc','archive') {
1.436 raeburn 13511: if ($offon[$confhash{$item}] ne $staticdefaults{$item}) {
1.429 raeburn 13512: $changes{$item} = 1;
13513: }
13514: }
13515: foreach my $item ('copyright','sourceavail') {
13516: if ($confhash{$item} ne $staticdefaults{$item}) {
13517: $changes{$item} = 1;
13518: }
13519: }
1.439 raeburn 13520: my @diffs =
13521: &Apache::loncommon::compare_arrays($confhash{'editors'},
13522: $staticdefaults{'editors'});
13523: unless (@diffs == 0) {
13524: $changes{'editors'} = 1;
13525: }
1.429 raeburn 13526: }
13527: foreach my $key ('authorquota','webdav') {
13528: if (ref($curr_quotas{$key}) eq 'HASH') {
13529: foreach my $type (@insttypes,'default') {
13530: if (exists($save_quotas{$key}{$type})) {
13531: if ($save_quotas{$key}{$type} ne $curr_quotas{$key}{$type}) {
13532: $changes{$key}{$type} = 1;
13533: }
13534: } elsif (exists($curr_quotas{$key}{$type})) {
13535: $save_quotas{$key}{$type} = $curr_quotas{$key}{$type};
13536: } else {
13537: $save_quotas{$key}{$type} = $staticdefaults{$key};
13538: }
13539: }
13540: } else {
13541: foreach my $type (@insttypes,'default') {
13542: if (exists($save_quotas{$key}{$type})) {
13543: unless ($save_quotas{$key}{$type} eq $staticdefaults{$key}) {
13544: $changes{$key}{$type} = 1;
13545: }
13546: } else {
13547: $save_quotas{$key}{$type} = $staticdefaults{$key};
13548: }
13549: }
13550: }
13551: }
13552: if (ref($curr_quotas{'webdav'}) eq 'HASH') {
13553: if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
1.436 raeburn 13554: if ($save_quotas{'webdav'}{'_LC_adv'} ne $curr_quotas{'webdav'}{'_LC_adv'}) {
1.429 raeburn 13555: $changes{'webdav_LC_adv'} = 1;
13556: }
13557: } elsif (exists($curr_quotas{'webdav'}{'_LC_adv'})) {
13558: $changes{'webdav_LC_adv'} = 1;
13559: }
13560: } elsif (exists($save_quotas{'webdav'}{'_LC_adv'})) {
13561: $changes{'webdav_LC_adv'} = 1;
13562: }
13563: my %confighash = (
13564: quotas => \%save_quotas,
13565: authordefaults => \%confhash,
13566: );
13567: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,
13568: $dom);
13569: my $resulttext;
13570: if ($putresult eq 'ok') {
13571: if (keys(%changes)) {
1.431 raeburn 13572: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.429 raeburn 13573: if ((exists($changes{'authorquota'})) || (exists($changes{'webdav'})) ||
1.436 raeburn 13574: ($changes{'webdav_LC_adv'})) {
1.429 raeburn 13575: if ((exists($changes{'authorquota'})) && (ref($save_quotas{'authorquota'}) eq 'HASH')) {
13576: $domdefaults{'authorquota'} = $save_quotas{'authorquota'};
13577: }
13578: if (((exists($changes{'webdav'})) || ($changes{'webdav_LC_adv'})) &&
13579: (ref($save_quotas{'webdav'}) eq 'HASH')) {
13580: $domdefaults{'webdav'} = $save_quotas{'webdav'};
13581: }
13582: }
13583: $resulttext = &mt('Changes made:').'<ul>';
13584: my $authoroverride;
1.437 raeburn 13585: foreach my $key ('nocodemirror','daxecollapse','domcoordacc','copyright','sourceavail') {
1.429 raeburn 13586: if (exists($changes{$key})) {
1.431 raeburn 13587: $domdefaults{$key} = $confhash{$key};
1.429 raeburn 13588: my $shown;
13589: unless ($authoroverride) {
13590: $resulttext .= '<li>'.&mt('Defaults which can be overridden by Author').'<ul>';
13591: $authoroverride = 1;
13592: }
1.437 raeburn 13593: if (($key eq 'nocodemirror') || ($key eq 'daxecollapse') || ($key eq 'domcoordacc')) {
1.429 raeburn 13594: $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
13595: } elsif ($key eq 'copyright') {
13596: $shown = &Apache::loncommon::copyrightdescription($confhash{$key});
13597: } elsif ($key eq 'sourceavail') {
13598: $shown = &Apache::loncommon::source_copyrightdescription($confhash{$key});
13599: }
1.436 raeburn 13600: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
1.429 raeburn 13601: }
13602: }
13603: if ($authoroverride) {
13604: $resulttext .= '</ul></li>';
13605: }
13606: my $domcoordoverride;
1.440 raeburn 13607: foreach my $key ('editors','authorquota','webdav','webdav_LC_adv','archive') {
1.429 raeburn 13608: if (exists($changes{$key})) {
13609: my $shown;
13610: unless ($domcoordoverride) {
13611: $resulttext .= '<li>'.&mt('Defaults which can be overridden by a Domain Coodinator').'<ul>';
13612: $domcoordoverride = 1;
13613: }
13614: if ($key eq 'editors') {
1.431 raeburn 13615: if (ref($confhash{'editors'}) eq 'ARRAY') {
13616: $domdefaults{'editors'} = join(',',@{$confhash{'editors'}});
13617: if (@{$confhash{'editors'}}) {
13618: $shown = join(', ', map { $titles{$_} } @{$confhash{'editors'}});
13619: } else {
13620: $shown = &mt('None');
13621: }
1.429 raeburn 13622: }
13623: } elsif ($key eq 'authorquota') {
13624: foreach my $type (@insttypes) {
13625: $shown .= $usertypes->{$type}.' -- '.$save_quotas{$key}{$type}.', ';
13626: }
13627: $shown .= $othertitle.' -- '.$save_quotas{$key}{'default'};
13628: } elsif ($key eq 'webdav') {
13629: foreach my $type (@insttypes) {
13630: $shown .= $usertypes->{$type}.' -- '. ($save_quotas{$key}{$type} ? &mt('Yes') : &mt('No')).', ';
13631: }
13632: $shown .= $othertitle.' -- '. ($save_quotas{$key}{'default'} ? &mt('Yes') : &mt('No'));
13633: } elsif ($key eq 'webdav_LC_adv') {
13634: if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
13635: $shown = ($save_quotas{'webdav'}{'_LC_adv'} ? $titles{'overon'} : $titles{'overoff'});
13636: } else {
13637: $shown = $titles{'none'};
13638: }
1.440 raeburn 13639: } elsif ($key eq 'archive') {
1.441 raeburn 13640: $domdefaults{$key} = $confhash{$key};
1.440 raeburn 13641: $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
1.429 raeburn 13642: }
13643: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
1.436 raeburn 13644: }
1.429 raeburn 13645: }
13646: if ($domcoordoverride) {
13647: $resulttext .= '</ul></li>';
13648: }
1.439 raeburn 13649: $resulttext .= '</ul>';
1.431 raeburn 13650: my $cachetime = 24*60*60;
13651: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13652: if (ref($lastactref) eq 'HASH') {
13653: $lastactref->{'domdefaults'} = 1;
13654: }
1.429 raeburn 13655: } else {
13656: $resulttext = &mt('No changes made to Authoring Space defaults');
13657: }
13658: }
13659: return $resulttext;
13660: }
13661:
1.6 raeburn 13662: sub modify_rolecolors {
1.205 raeburn 13663: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 13664: my ($resulttext,%rolehash);
13665: $rolehash{'rolecolors'} = {};
1.55 raeburn 13666: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
13667: if ($domconfig{'rolecolors'} eq '') {
13668: $domconfig{'rolecolors'} = {};
13669: }
13670: }
1.9 raeburn 13671: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 13672: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
13673: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
13674: $dom);
13675: if ($putresult eq 'ok') {
13676: if (keys(%changes) > 0) {
1.41 raeburn 13677: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 13678: if (ref($lastactref) eq 'HASH') {
13679: $lastactref->{'domainconfig'} = 1;
13680: }
1.6 raeburn 13681: $resulttext = &display_colorchgs($dom,\%changes,$roles,
13682: $rolehash{'rolecolors'});
13683: } else {
13684: $resulttext = &mt('No changes made to default color schemes');
13685: }
13686: } else {
1.11 albertel 13687: $resulttext = '<span class="LC_error">'.
13688: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 13689: }
13690: if ($errors) {
13691: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
13692: $errors.'</ul>';
13693: }
13694: return $resulttext;
13695: }
13696:
13697: sub modify_colors {
1.9 raeburn 13698: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 13699: my (%changes,%choices);
1.51 raeburn 13700: my @bgs;
1.6 raeburn 13701: my @links = ('link','alink','vlink');
1.41 raeburn 13702: my @logintext;
1.6 raeburn 13703: my @images;
13704: my $servadm = $r->dir_config('lonAdmEMail');
13705: my $errors;
1.200 raeburn 13706: my %defaults;
1.6 raeburn 13707: foreach my $role (@{$roles}) {
13708: if ($role eq 'login') {
1.12 raeburn 13709: %choices = &login_choices();
1.41 raeburn 13710: @logintext = ('textcol','bgcol');
1.12 raeburn 13711: } else {
13712: %choices = &color_font_choices();
13713: }
13714: if ($role eq 'login') {
1.41 raeburn 13715: @images = ('img','logo','domlogo','login');
1.51 raeburn 13716: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 13717: } else {
13718: @images = ('img');
1.200 raeburn 13719: @bgs = ('pgbg','tabbg','sidebg');
13720: }
13721: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
13722: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
13723: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
13724: }
13725: if ($role eq 'login') {
13726: foreach my $item (@logintext) {
1.234 raeburn 13727: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13728: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13729: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13730: }
13731: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 13732: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13733: }
13734: }
13735: } else {
1.234 raeburn 13736: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
13737: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
13738: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
13739: }
13740: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 13741: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
13742: }
1.6 raeburn 13743: }
1.200 raeburn 13744: foreach my $item (@bgs) {
1.234 raeburn 13745: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13746: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13747: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13748: }
13749: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 13750: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13751: }
13752: }
13753: foreach my $item (@links) {
1.234 raeburn 13754: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13755: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13756: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13757: }
13758: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 13759: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13760: }
1.6 raeburn 13761: }
1.46 raeburn 13762: my ($configuserok,$author_ok,$switchserver) =
13763: &config_check($dom,$confname,$servadm);
1.9 raeburn 13764: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 13765: if (ref($domconfig->{$role}) ne 'HASH') {
13766: $domconfig->{$role} = {};
13767: }
1.8 raeburn 13768: foreach my $img (@images) {
1.402 raeburn 13769: if ($role eq 'login') {
13770: if (($img eq 'img') || ($img eq 'logo')) {
13771: if (defined($env{'form.login_showlogo_'.$img})) {
13772: $confhash->{$role}{'showlogo'}{$img} = 1;
13773: } else {
13774: $confhash->{$role}{'showlogo'}{$img} = 0;
13775: }
13776: }
13777: if ($env{'form.login_alt_'.$img} ne '') {
13778: $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
1.70 raeburn 13779: }
1.402 raeburn 13780: }
1.18 albertel 13781: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
13782: && !defined($domconfig->{$role}{$img})
13783: && !$env{'form.'.$role.'_del_'.$img}
13784: && $env{'form.'.$role.'_import_'.$img}) {
13785: # import the old configured image from the .tab setting
13786: # if they haven't provided a new one
13787: $domconfig->{$role}{$img} =
13788: $env{'form.'.$role.'_import_'.$img};
13789: }
1.6 raeburn 13790: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 13791: my $error;
1.6 raeburn 13792: if ($configuserok eq 'ok') {
1.9 raeburn 13793: if ($switchserver) {
1.12 raeburn 13794: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 13795: } else {
13796: if ($author_ok eq 'ok') {
1.421 raeburn 13797: my $modified = [];
1.9 raeburn 13798: my ($result,$logourl) =
1.421 raeburn 13799: &Apache::lonconfigsettings::publishlogo($r,'upload',$role.'_'.$img,
13800: $dom,$confname,$img,$width,$height,
13801: '',$modified);
1.9 raeburn 13802: if ($result eq 'ok') {
13803: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 13804: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13805: &update_modify_urls($r,$modified);
1.9 raeburn 13806: } else {
1.12 raeburn 13807: $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 13808: }
13809: } else {
1.46 raeburn 13810: $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 13811: }
13812: }
13813: } else {
1.46 raeburn 13814: $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 13815: }
13816: if ($error) {
1.8 raeburn 13817: &Apache::lonnet::logthis($error);
1.11 albertel 13818: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 13819: }
13820: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 13821: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
13822: my $error;
13823: if ($configuserok eq 'ok') {
13824: # is confname an author?
13825: if ($switchserver eq '') {
13826: if ($author_ok eq 'ok') {
1.421 raeburn 13827: my $modified = [];
1.9 raeburn 13828: my ($result,$logourl) =
1.421 raeburn 13829: &Apache::lonconfigsettings::publishlogo($r,'copy',$domconfig->{$role}{$img},
13830: $dom,$confname,$img,$width,$height,
13831: '',$modified);
1.9 raeburn 13832: if ($result eq 'ok') {
13833: $confhash->{$role}{$img} = $logourl;
1.18 albertel 13834: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13835: &update_modify_urls($r,$modified);
1.9 raeburn 13836: }
13837: }
13838: }
13839: }
1.6 raeburn 13840: }
13841: }
13842: }
13843: if (ref($domconfig) eq 'HASH') {
13844: if (ref($domconfig->{$role}) eq 'HASH') {
13845: foreach my $img (@images) {
13846: if ($domconfig->{$role}{$img} ne '') {
13847: if ($env{'form.'.$role.'_del_'.$img}) {
13848: $confhash->{$role}{$img} = '';
1.12 raeburn 13849: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13850: } else {
1.9 raeburn 13851: if ($confhash->{$role}{$img} eq '') {
13852: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
13853: }
1.6 raeburn 13854: }
13855: } else {
13856: if ($env{'form.'.$role.'_del_'.$img}) {
13857: $confhash->{$role}{$img} = '';
1.12 raeburn 13858: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13859: }
13860: }
1.402 raeburn 13861: if ($role eq 'login') {
13862: if (($img eq 'logo') || ($img eq 'img')) {
13863: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
13864: if ($confhash->{$role}{'showlogo'}{$img} ne
13865: $domconfig->{$role}{'showlogo'}{$img}) {
13866: $changes{$role}{'showlogo'}{$img} = 1;
13867: }
13868: } else {
13869: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13870: $changes{$role}{'showlogo'}{$img} = 1;
13871: }
1.70 raeburn 13872: }
1.402 raeburn 13873: }
13874: if ($img ne 'login') {
13875: if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
13876: if ($confhash->{$role}{'alttext'}{$img} ne
13877: $domconfig->{$role}{'alttext'}{$img}) {
13878: $changes{$role}{'alttext'}{$img} = 1;
13879: }
13880: } else {
13881: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13882: $changes{$role}{'alttext'}{$img} = 1;
13883: }
1.70 raeburn 13884: }
13885: }
13886: }
13887: }
1.6 raeburn 13888: if ($domconfig->{$role}{'font'} ne '') {
13889: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
13890: $changes{$role}{'font'} = 1;
13891: }
13892: } else {
13893: if ($confhash->{$role}{'font'}) {
13894: $changes{$role}{'font'} = 1;
13895: }
13896: }
1.107 raeburn 13897: if ($role ne 'login') {
13898: if ($domconfig->{$role}{'fontmenu'} ne '') {
13899: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
13900: $changes{$role}{'fontmenu'} = 1;
13901: }
13902: } else {
13903: if ($confhash->{$role}{'fontmenu'}) {
13904: $changes{$role}{'fontmenu'} = 1;
13905: }
1.97 tempelho 13906: }
13907: }
1.6 raeburn 13908: foreach my $item (@bgs) {
13909: if ($domconfig->{$role}{$item} ne '') {
13910: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13911: $changes{$role}{'bgs'}{$item} = 1;
13912: }
13913: } else {
13914: if ($confhash->{$role}{$item}) {
13915: $changes{$role}{'bgs'}{$item} = 1;
13916: }
13917: }
13918: }
13919: foreach my $item (@links) {
13920: if ($domconfig->{$role}{$item} ne '') {
13921: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13922: $changes{$role}{'links'}{$item} = 1;
13923: }
13924: } else {
13925: if ($confhash->{$role}{$item}) {
13926: $changes{$role}{'links'}{$item} = 1;
13927: }
13928: }
13929: }
1.41 raeburn 13930: foreach my $item (@logintext) {
13931: if ($domconfig->{$role}{$item} ne '') {
13932: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13933: $changes{$role}{'logintext'}{$item} = 1;
13934: }
13935: } else {
13936: if ($confhash->{$role}{$item}) {
13937: $changes{$role}{'logintext'}{$item} = 1;
13938: }
13939: }
13940: }
1.6 raeburn 13941: } else {
13942: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13943: \@logintext,$confhash,\%changes);
1.6 raeburn 13944: }
13945: } else {
13946: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13947: \@logintext,$confhash,\%changes);
1.6 raeburn 13948: }
13949: }
13950: return ($errors,%changes);
13951: }
13952:
1.46 raeburn 13953: sub config_check {
13954: my ($dom,$confname,$servadm) = @_;
13955: my ($configuserok,$author_ok,$switchserver,%currroles);
13956: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
13957: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
13958: $confname,$servadm);
13959: if ($configuserok eq 'ok') {
13960: $switchserver = &check_switchserver($dom,$confname);
13961: if ($switchserver eq '') {
13962: $author_ok = &check_authorstatus($dom,$confname,%currroles);
13963: }
13964: }
13965: return ($configuserok,$author_ok,$switchserver);
13966: }
13967:
1.6 raeburn 13968: sub default_change_checker {
1.41 raeburn 13969: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 13970: foreach my $item (@{$links}) {
13971: if ($confhash->{$role}{$item}) {
13972: $changes->{$role}{'links'}{$item} = 1;
13973: }
13974: }
13975: foreach my $item (@{$bgs}) {
13976: if ($confhash->{$role}{$item}) {
13977: $changes->{$role}{'bgs'}{$item} = 1;
13978: }
13979: }
1.41 raeburn 13980: foreach my $item (@{$logintext}) {
13981: if ($confhash->{$role}{$item}) {
13982: $changes->{$role}{'logintext'}{$item} = 1;
13983: }
13984: }
1.6 raeburn 13985: foreach my $img (@{$images}) {
13986: if ($env{'form.'.$role.'_del_'.$img}) {
13987: $confhash->{$role}{$img} = '';
1.12 raeburn 13988: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 13989: }
1.70 raeburn 13990: if ($role eq 'login') {
13991: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13992: $changes->{$role}{'showlogo'}{$img} = 1;
13993: }
1.402 raeburn 13994: if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
13995: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13996: $changes->{$role}{'alttext'}{$img} = 1;
13997: }
13998: }
1.70 raeburn 13999: }
1.6 raeburn 14000: }
14001: if ($confhash->{$role}{'font'}) {
14002: $changes->{$role}{'font'} = 1;
14003: }
1.48 raeburn 14004: }
1.6 raeburn 14005:
14006: sub display_colorchgs {
14007: my ($dom,$changes,$roles,$confhash) = @_;
14008: my (%choices,$resulttext);
14009: if (!grep(/^login$/,@{$roles})) {
14010: $resulttext = &mt('Changes made:').'<br />';
14011: }
14012: foreach my $role (@{$roles}) {
14013: if ($role eq 'login') {
14014: %choices = &login_choices();
14015: } else {
14016: %choices = &color_font_choices();
14017: }
14018: if (ref($changes->{$role}) eq 'HASH') {
14019: if ($role ne 'login') {
14020: $resulttext .= '<h4>'.&mt($role).'</h4>';
14021: }
14022: foreach my $key (sort(keys(%{$changes->{$role}}))) {
14023: if ($role ne 'login') {
14024: $resulttext .= '<ul>';
14025: }
14026: if (ref($changes->{$role}{$key}) eq 'HASH') {
14027: if ($role ne 'login') {
14028: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
14029: }
14030: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 14031: if (($role eq 'login') && ($key eq 'showlogo')) {
14032: if ($confhash->{$role}{$key}{$item}) {
14033: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
14034: } else {
14035: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
14036: }
1.402 raeburn 14037: } elsif (($role eq 'login') && ($key eq 'alttext')) {
14038: if ($confhash->{$role}{$key}{$item} ne '') {
1.403 raeburn 14039: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
1.402 raeburn 14040: $confhash->{$role}{$key}{$item}).'</li>';
14041: } else {
14042: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
14043: }
1.70 raeburn 14044: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 14045: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
14046: } else {
1.12 raeburn 14047: my $newitem = $confhash->{$role}{$item};
14048: if ($key eq 'images') {
1.306 raeburn 14049: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 14050: }
14051: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 14052: }
14053: }
14054: if ($role ne 'login') {
14055: $resulttext .= '</ul></li>';
14056: }
14057: } else {
14058: if ($confhash->{$role}{$key} eq '') {
14059: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
14060: } else {
14061: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
14062: }
14063: }
14064: if ($role ne 'login') {
14065: $resulttext .= '</ul>';
14066: }
14067: }
14068: }
14069: }
1.3 raeburn 14070: return $resulttext;
1.1 raeburn 14071: }
14072:
1.9 raeburn 14073: sub thumb_dimensions {
14074: return ('200','50');
14075: }
14076:
1.16 raeburn 14077: sub check_dimensions {
14078: my ($inputfile) = @_;
14079: my ($fullwidth,$fullheight);
14080: if ($inputfile =~ m|^[/\w.\-]+$|) {
14081: if (open(PIPE,"identify $inputfile 2>&1 |")) {
14082: my $imageinfo = <PIPE>;
14083: if (!close(PIPE)) {
14084: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
14085: }
14086: chomp($imageinfo);
14087: my ($fullsize) =
1.21 raeburn 14088: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 14089: if ($fullsize) {
14090: ($fullwidth,$fullheight) = split(/x/,$fullsize);
14091: }
14092: }
14093: }
14094: return ($fullwidth,$fullheight);
14095: }
14096:
1.9 raeburn 14097: sub check_configuser {
14098: my ($uhome,$dom,$confname,$servadm) = @_;
14099: my ($configuserok,%currroles);
14100: if ($uhome eq 'no_host') {
14101: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.361 raeburn 14102: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 14103: $configuserok =
14104: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
14105: $configpass,'','','','','',undef,$servadm);
14106: } else {
14107: $configuserok = 'ok';
14108: %currroles =
14109: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
14110: }
14111: return ($configuserok,%currroles);
14112: }
14113:
14114: sub check_authorstatus {
14115: my ($dom,$confname,%currroles) = @_;
14116: my $author_ok;
1.40 raeburn 14117: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 14118: my $start = time;
14119: my $end = 0;
14120: $author_ok =
14121: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 14122: 'au',$end,$start,'','','domconfig');
1.9 raeburn 14123: } else {
14124: $author_ok = 'ok';
14125: }
14126: return $author_ok;
14127: }
14128:
1.421 raeburn 14129: sub update_modify_urls {
14130: my ($r,$modified) = @_;
14131: if ((ref($modified) eq 'ARRAY') && (@{$modified})) {
14132: push(@{$modified_urls},$modified);
14133: unless ($registered_cleanup) {
14134: my $handlers = $r->get_handlers('PerlCleanupHandler');
14135: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
14136: $registered_cleanup=1;
1.9 raeburn 14137: }
14138: }
1.155 raeburn 14139: }
14140:
14141: sub notifysubscribed {
14142: foreach my $targetsource (@{$modified_urls}){
14143: next unless (ref($targetsource) eq 'ARRAY');
14144: my ($target,$source)=@{$targetsource};
14145: if ($source ne '') {
1.316 raeburn 14146: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 14147: print $logfh "\nCleanup phase: Notifications\n";
14148: my @subscribed=&subscribed_hosts($target);
14149: foreach my $subhost (@subscribed) {
14150: print $logfh "\nNotifying host ".$subhost.':';
14151: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
14152: print $logfh $reply;
14153: }
14154: my @subscribedmeta=&subscribed_hosts("$target.meta");
14155: foreach my $subhost (@subscribedmeta) {
14156: print $logfh "\nNotifying host for metadata only ".$subhost.':';
14157: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
14158: $subhost);
14159: print $logfh $reply;
14160: }
14161: print $logfh "\n============ Done ============\n";
1.160 raeburn 14162: close($logfh);
1.155 raeburn 14163: }
14164: }
14165: }
14166: return OK;
14167: }
14168:
14169: sub subscribed_hosts {
14170: my ($target) = @_;
14171: my @subscribed;
1.316 raeburn 14172: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 14173: while (my $subline=<$fh>) {
14174: if ($subline =~ /^($match_lonid):/) {
14175: my $host = $1;
14176: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
14177: unless (grep(/^\Q$host\E$/,@subscribed)) {
14178: push(@subscribed,$host);
14179: }
14180: }
14181: }
14182: }
14183: }
14184: return @subscribed;
1.9 raeburn 14185: }
14186:
14187: sub check_switchserver {
14188: my ($dom,$confname) = @_;
1.424 raeburn 14189: my ($allowed,$switchserver,$home);
14190: if ($confname eq '') {
1.9 raeburn 14191: $home = &Apache::lonnet::domain($dom,'primary');
1.424 raeburn 14192: } else {
14193: $home = &Apache::lonnet::homeserver($confname,$dom);
14194: if ($home eq 'no_host') {
14195: $home = &Apache::lonnet::domain($dom,'primary');
14196: }
1.9 raeburn 14197: }
14198: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 14199: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
14200: if (!$allowed) {
1.426 raeburn 14201: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
14202: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
14203: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 14204: }
14205: return $switchserver;
14206: }
14207:
1.1 raeburn 14208: sub modify_quotas {
1.216 raeburn 14209: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 14210: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 14211: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 14212: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
14213: $validationfieldsref);
1.86 raeburn 14214: if ($action eq 'quotas') {
1.429 raeburn 14215: $context = 'tools';
1.163 raeburn 14216: } else {
1.86 raeburn 14217: $context = $action;
14218: }
14219: if ($context eq 'requestcourses') {
1.325 raeburn 14220: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 14221: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 14222: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
14223: %titles = &courserequest_titles();
14224: $toolregexp = join('|',@usertools);
14225: %conditions = &courserequest_conditions();
1.216 raeburn 14226: $confname = $dom.'-domainconfig';
14227: my $servadm = $r->dir_config('lonAdmEMail');
14228: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 14229: ($validationitemsref,$validationnamesref,$validationfieldsref) =
14230: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 14231: } elsif ($context eq 'requestauthor') {
14232: @usertools = ('author');
14233: %titles = &authorrequest_titles();
1.86 raeburn 14234: } else {
1.430 raeburn 14235: @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.101 raeburn 14236: %titles = &tool_titles();
1.86 raeburn 14237: }
1.212 raeburn 14238: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 14239: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 14240: foreach my $key (keys(%env)) {
1.101 raeburn 14241: if ($context eq 'requestcourses') {
14242: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
14243: my $item = $1;
14244: my $type = $2;
14245: if ($type =~ /^limit_(.+)/) {
14246: $limithash{$item}{$1} = $env{$key};
14247: } else {
14248: $confhash{$item}{$type} = $env{$key};
14249: }
14250: }
1.163 raeburn 14251: } elsif ($context eq 'requestauthor') {
14252: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
14253: $confhash{$1} = $env{$key};
14254: }
1.101 raeburn 14255: } else {
1.86 raeburn 14256: if ($key =~ /^form\.quota_(.+)$/) {
14257: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 14258: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 14259: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
14260: }
1.72 raeburn 14261: }
14262: }
1.163 raeburn 14263: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 14264: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 14265: @approvalnotify = sort(@approvalnotify);
14266: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 14267: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 14268: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
14269: foreach my $type (@hasuniquecode) {
14270: if (grep(/^\Q$type\E$/,@crstypes)) {
14271: $confhash{'uniquecode'}{$type} = 1;
14272: }
1.216 raeburn 14273: }
1.242 raeburn 14274: my (%newbook,%allpos);
1.216 raeburn 14275: if ($context eq 'requestcourses') {
1.242 raeburn 14276: foreach my $type ('textbooks','templates') {
14277: @{$allpos{$type}} = ();
14278: my $invalid;
14279: if ($type eq 'textbooks') {
14280: $invalid = &mt('Invalid LON-CAPA course for textbook');
14281: } else {
14282: $invalid = &mt('Invalid LON-CAPA course for template');
14283: }
14284: if ($env{'form.'.$type.'_addbook'}) {
14285: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
14286: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
14287: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
14288: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
14289: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
14290: } else {
14291: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
14292: my $position = $env{'form.'.$type.'_addbook_pos'};
14293: $position =~ s/\D+//g;
14294: if ($position ne '') {
14295: $allpos{$type}[$position] = $newbook{$type};
14296: }
1.216 raeburn 14297: }
1.242 raeburn 14298: } else {
14299: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 14300: }
14301: }
1.242 raeburn 14302: }
1.216 raeburn 14303: }
1.102 raeburn 14304: if (ref($domconfig{$action}) eq 'HASH') {
14305: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
14306: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
14307: $changes{'notify'}{'approval'} = 1;
14308: }
14309: } else {
1.144 raeburn 14310: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14311: $changes{'notify'}{'approval'} = 1;
14312: }
14313: }
1.218 raeburn 14314: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
14315: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14316: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
14317: unless ($confhash{'uniquecode'}{$crstype}) {
14318: $changes{'uniquecode'} = 1;
14319: }
14320: }
14321: unless ($changes{'uniquecode'}) {
14322: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
14323: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
14324: $changes{'uniquecode'} = 1;
14325: }
14326: }
14327: }
14328: } else {
14329: $changes{'uniquecode'} = 1;
14330: }
14331: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
14332: $changes{'uniquecode'} = 1;
1.216 raeburn 14333: }
14334: if ($context eq 'requestcourses') {
1.242 raeburn 14335: foreach my $type ('textbooks','templates') {
14336: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14337: my %deletions;
14338: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
14339: if (@todelete) {
14340: map { $deletions{$_} = 1; } @todelete;
14341: }
14342: my %imgdeletions;
14343: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
14344: if (@todeleteimages) {
14345: map { $imgdeletions{$_} = 1; } @todeleteimages;
14346: }
14347: my $maxnum = $env{'form.'.$type.'_maxnum'};
14348: for (my $i=0; $i<=$maxnum; $i++) {
14349: my $itemid = $env{'form.'.$type.'_id_'.$i};
14350: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
14351: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
14352: if ($deletions{$key}) {
14353: if ($domconfig{$action}{$type}{$key}{'image'}) {
14354: #FIXME need to obsolete item in RES space
14355: }
14356: next;
14357: } else {
14358: my $newpos = $env{'form.'.$itemid};
14359: $newpos =~ s/\D+//g;
1.243 raeburn 14360: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 14361: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 14362: ($type eq 'templates'));
1.242 raeburn 14363: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
14364: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
14365: $changes{$type}{$key} = 1;
14366: }
14367: }
14368: $allpos{$type}[$newpos] = $key;
14369: }
14370: if ($imgdeletions{$key}) {
14371: $changes{$type}{$key} = 1;
1.216 raeburn 14372: #FIXME need to obsolete item in RES space
1.242 raeburn 14373: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
14374: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 14375: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14376: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14377: } else {
14378: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
14379: $cdom,$cnum,$type,$configuserok,
14380: $switchserver,$author_ok);
14381: if ($imgurl) {
14382: $confhash{$type}{$key}{'image'} = $imgurl;
14383: $changes{$type}{$key} = 1;
14384: }
14385: if ($error) {
14386: &Apache::lonnet::logthis($error);
14387: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14388: }
14389: }
1.242 raeburn 14390: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
14391: $confhash{$type}{$key}{'image'} =
14392: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 14393: }
14394: }
14395: }
14396: }
14397: }
14398: }
1.102 raeburn 14399: } else {
1.144 raeburn 14400: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14401: $changes{'notify'}{'approval'} = 1;
14402: }
1.218 raeburn 14403: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 14404: $changes{'uniquecode'} = 1;
14405: }
14406: }
14407: if ($context eq 'requestcourses') {
1.242 raeburn 14408: foreach my $type ('textbooks','templates') {
14409: if ($newbook{$type}) {
14410: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 14411: foreach my $item ('subject','title','publisher','author') {
14412: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14413: ($type eq 'template'));
1.242 raeburn 14414: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
14415: if ($env{'form.'.$type.'_addbook_'.$item}) {
14416: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
14417: }
14418: }
14419: if ($type eq 'textbooks') {
14420: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
14421: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 14422: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14423: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14424: } else {
14425: my ($imageurl,$error) =
14426: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
14427: $configuserok,$switchserver,$author_ok);
14428: if ($imageurl) {
14429: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
14430: }
14431: if ($error) {
14432: &Apache::lonnet::logthis($error);
14433: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14434: }
1.242 raeburn 14435: }
14436: }
1.216 raeburn 14437: }
14438: }
1.242 raeburn 14439: if (@{$allpos{$type}} > 0) {
14440: my $idx = 0;
14441: foreach my $item (@{$allpos{$type}}) {
14442: if ($item ne '') {
14443: $confhash{$type}{$item}{'order'} = $idx;
14444: if (ref($domconfig{$action}) eq 'HASH') {
14445: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14446: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
14447: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
14448: $changes{$type}{$item} = 1;
14449: }
1.216 raeburn 14450: }
14451: }
14452: }
1.242 raeburn 14453: $idx ++;
1.216 raeburn 14454: }
14455: }
14456: }
14457: }
1.235 raeburn 14458: if (ref($validationitemsref) eq 'ARRAY') {
14459: foreach my $item (@{$validationitemsref}) {
14460: if ($item eq 'fields') {
14461: my @changed;
14462: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
14463: if (@{$confhash{'validation'}{$item}} > 0) {
14464: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
14465: }
1.266 raeburn 14466: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14467: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14468: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
14469: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
14470: $domconfig{'requestcourses'}{'validation'}{$item});
14471: } else {
14472: @changed = @{$confhash{'validation'}{$item}};
14473: }
1.235 raeburn 14474: } else {
14475: @changed = @{$confhash{'validation'}{$item}};
14476: }
14477: } else {
14478: @changed = @{$confhash{'validation'}{$item}};
14479: }
14480: if (@changed) {
14481: if ($confhash{'validation'}{$item}) {
14482: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
14483: } else {
14484: $changes{'validation'}{$item} = &mt('None');
14485: }
14486: }
14487: } else {
14488: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
14489: if ($item eq 'markup') {
14490: if ($env{'form.requestcourses_validation_'.$item}) {
14491: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
14492: }
14493: }
1.266 raeburn 14494: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14495: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14496: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
14497: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14498: }
14499: } else {
14500: if ($confhash{'validation'}{$item} ne '') {
14501: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14502: }
1.235 raeburn 14503: }
14504: } else {
14505: if ($confhash{'validation'}{$item} ne '') {
14506: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14507: }
14508: }
14509: }
14510: }
14511: }
14512: if ($env{'form.validationdc'}) {
14513: my $newval = $env{'form.validationdc'};
1.285 raeburn 14514: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 14515: if (exists($domcoords{$newval})) {
14516: $confhash{'validation'}{'dc'} = $newval;
14517: }
14518: }
14519: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 14520: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14521: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14522: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14523: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
14524: if ($confhash{'validation'}{'dc'} eq '') {
14525: $changes{'validation'}{'dc'} = &mt('None');
14526: } else {
14527: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14528: }
1.235 raeburn 14529: }
1.266 raeburn 14530: } elsif ($confhash{'validation'}{'dc'} ne '') {
14531: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 14532: }
14533: } elsif ($confhash{'validation'}{'dc'} ne '') {
14534: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14535: }
14536: } elsif ($confhash{'validation'}{'dc'} ne '') {
14537: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 14538: }
1.266 raeburn 14539: } else {
14540: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14541: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14542: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14543: $changes{'validation'}{'dc'} = &mt('None');
14544: }
14545: }
1.235 raeburn 14546: }
14547: }
1.102 raeburn 14548: }
14549: } else {
1.86 raeburn 14550: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
14551: }
1.72 raeburn 14552: foreach my $item (@usertools) {
14553: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 14554: my $unset;
1.101 raeburn 14555: if ($context eq 'requestcourses') {
1.104 raeburn 14556: $unset = '0';
14557: if ($type eq '_LC_adv') {
14558: $unset = '';
14559: }
1.101 raeburn 14560: if ($confhash{$item}{$type} eq 'autolimit') {
14561: $confhash{$item}{$type} .= '=';
14562: unless ($limithash{$item}{$type} =~ /\D/) {
14563: $confhash{$item}{$type} .= $limithash{$item}{$type};
14564: }
14565: }
1.163 raeburn 14566: } elsif ($context eq 'requestauthor') {
14567: $unset = '0';
14568: if ($type eq '_LC_adv') {
14569: $unset = '';
14570: }
1.72 raeburn 14571: } else {
1.101 raeburn 14572: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
14573: $confhash{$item}{$type} = 1;
14574: } else {
14575: $confhash{$item}{$type} = 0;
14576: }
1.72 raeburn 14577: }
1.86 raeburn 14578: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 14579: if ($action eq 'requestauthor') {
14580: if ($domconfig{$action}{$type} ne $confhash{$type}) {
14581: $changes{$type} = 1;
14582: }
14583: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 14584: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
14585: $changes{$item}{$type} = 1;
14586: }
14587: } else {
14588: if ($context eq 'requestcourses') {
1.104 raeburn 14589: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 14590: $changes{$item}{$type} = 1;
14591: }
14592: } else {
14593: if (!$confhash{$item}{$type}) {
14594: $changes{$item}{$type} = 1;
14595: }
14596: }
14597: }
14598: } else {
14599: if ($context eq 'requestcourses') {
1.104 raeburn 14600: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 14601: $changes{$item}{$type} = 1;
14602: }
1.163 raeburn 14603: } elsif ($context eq 'requestauthor') {
14604: if ($confhash{$type} ne $unset) {
14605: $changes{$type} = 1;
14606: }
1.72 raeburn 14607: } else {
14608: if (!$confhash{$item}{$type}) {
14609: $changes{$item}{$type} = 1;
14610: }
14611: }
14612: }
1.1 raeburn 14613: }
14614: }
1.163 raeburn 14615: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 14616: if (ref($domconfig{'quotas'}) eq 'HASH') {
14617: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14618: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
14619: if (exists($confhash{'defaultquota'}{$key})) {
14620: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
14621: $changes{'defaultquota'}{$key} = 1;
14622: }
14623: } else {
14624: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 14625: }
14626: }
1.86 raeburn 14627: } else {
14628: foreach my $key (keys(%{$domconfig{'quotas'}})) {
14629: if (exists($confhash{'defaultquota'}{$key})) {
14630: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
14631: $changes{'defaultquota'}{$key} = 1;
14632: }
14633: } else {
14634: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 14635: }
1.1 raeburn 14636: }
14637: }
1.197 raeburn 14638: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
1.429 raeburn 14639: $confhash{'authorquota'} = $domconfig{'quotas'}{'authorquota'};
14640: }
14641: if (ref($domconfig{'quotas'}{'webdav'}) eq 'HASH') {
14642: $confhash{'webdav'} = $domconfig{'quotas'}{'webdav'};
1.197 raeburn 14643: }
1.1 raeburn 14644: }
1.86 raeburn 14645: if (ref($confhash{'defaultquota'}) eq 'HASH') {
14646: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
14647: if (ref($domconfig{'quotas'}) eq 'HASH') {
14648: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14649: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
14650: $changes{'defaultquota'}{$key} = 1;
14651: }
14652: } else {
14653: if (!exists($domconfig{'quotas'}{$key})) {
14654: $changes{'defaultquota'}{$key} = 1;
14655: }
1.72 raeburn 14656: }
14657: } else {
1.86 raeburn 14658: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 14659: }
1.1 raeburn 14660: }
14661: }
14662: }
1.72 raeburn 14663:
1.163 raeburn 14664: if ($context eq 'requestauthor') {
14665: $domdefaults{'requestauthor'} = \%confhash;
14666: } else {
14667: foreach my $key (keys(%confhash)) {
1.242 raeburn 14668: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 14669: $domdefaults{$key} = $confhash{$key};
14670: }
1.163 raeburn 14671: }
1.72 raeburn 14672: }
1.163 raeburn 14673:
1.1 raeburn 14674: my %quotahash = (
1.86 raeburn 14675: $action => { %confhash }
1.1 raeburn 14676: );
14677: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
14678: $dom);
14679: if ($putresult eq 'ok') {
14680: if (keys(%changes) > 0) {
1.72 raeburn 14681: my $cachetime = 24*60*60;
14682: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 14683: if (ref($lastactref) eq 'HASH') {
14684: $lastactref->{'domdefaults'} = 1;
14685: }
1.1 raeburn 14686: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 14687: unless (($context eq 'requestcourses') ||
1.163 raeburn 14688: ($context eq 'requestauthor')) {
1.86 raeburn 14689: if (ref($changes{'defaultquota'}) eq 'HASH') {
14690: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
14691: foreach my $type (@{$types},'default') {
14692: if (defined($changes{'defaultquota'}{$type})) {
14693: my $typetitle = $usertypes->{$type};
14694: if ($type eq 'default') {
14695: $typetitle = $othertitle;
14696: }
1.213 raeburn 14697: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 14698: }
14699: }
1.86 raeburn 14700: $resulttext .= '</ul></li>';
1.72 raeburn 14701: }
14702: }
1.80 raeburn 14703: my %newenv;
1.72 raeburn 14704: foreach my $item (@usertools) {
1.163 raeburn 14705: my (%haschgs,%inconf);
14706: if ($context eq 'requestauthor') {
14707: %haschgs = %changes;
1.210 raeburn 14708: %inconf = %confhash;
1.163 raeburn 14709: } else {
14710: if (ref($changes{$item}) eq 'HASH') {
14711: %haschgs = %{$changes{$item}};
14712: }
14713: if (ref($confhash{$item}) eq 'HASH') {
14714: %inconf = %{$confhash{$item}};
14715: }
14716: }
14717: if (keys(%haschgs) > 0) {
1.80 raeburn 14718: my $newacc =
14719: &Apache::lonnet::usertools_access($env{'user.name'},
14720: $env{'user.domain'},
1.86 raeburn 14721: $item,'reload',$context);
1.210 raeburn 14722: if (($context eq 'requestcourses') ||
1.163 raeburn 14723: ($context eq 'requestauthor')) {
1.108 raeburn 14724: if ($env{'environment.canrequest.'.$item} ne $newacc) {
14725: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 14726: }
14727: } else {
14728: if ($env{'environment.availabletools.'.$item} ne $newacc) {
14729: $newenv{'environment.availabletools.'.$item} = $newacc;
14730: }
1.80 raeburn 14731: }
1.163 raeburn 14732: unless ($context eq 'requestauthor') {
14733: $resulttext .= '<li>'.$titles{$item}.'<ul>';
14734: }
1.72 raeburn 14735: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 14736: if ($haschgs{$type}) {
1.72 raeburn 14737: my $typetitle = $usertypes->{$type};
14738: if ($type eq 'default') {
14739: $typetitle = $othertitle;
14740: } elsif ($type eq '_LC_adv') {
14741: $typetitle = 'LON-CAPA Advanced Users';
14742: }
1.163 raeburn 14743: if ($inconf{$type}) {
1.101 raeburn 14744: if ($context eq 'requestcourses') {
14745: my $cond;
1.163 raeburn 14746: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 14747: if ($1 eq '') {
14748: $cond = &mt('(Automatic processing of any request).');
14749: } else {
14750: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
14751: }
14752: } else {
1.163 raeburn 14753: $cond = $conditions{$inconf{$type}};
1.101 raeburn 14754: }
14755: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 14756: } elsif ($context eq 'requestauthor') {
14757: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
14758: $titles{$inconf{$type}},$typetitle);
14759:
1.101 raeburn 14760: } else {
14761: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
14762: }
1.72 raeburn 14763: } else {
1.104 raeburn 14764: if ($type eq '_LC_adv') {
1.163 raeburn 14765: if ($inconf{$type} eq '0') {
1.104 raeburn 14766: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14767: } else {
14768: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
14769: }
14770: } else {
14771: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14772: }
1.72 raeburn 14773: }
14774: }
1.26 raeburn 14775: }
1.163 raeburn 14776: unless ($context eq 'requestauthor') {
14777: $resulttext .= '</ul></li>';
14778: }
1.26 raeburn 14779: }
1.1 raeburn 14780: }
1.163 raeburn 14781: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 14782: if (ref($changes{'notify'}) eq 'HASH') {
14783: if ($changes{'notify'}{'approval'}) {
14784: if (ref($confhash{'notify'}) eq 'HASH') {
14785: if ($confhash{'notify'}{'approval'}) {
14786: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
14787: } else {
1.163 raeburn 14788: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 14789: }
14790: }
14791: }
14792: }
14793: }
1.216 raeburn 14794: if ($action eq 'requestcourses') {
14795: my @offon = ('off','on');
14796: if ($changes{'uniquecode'}) {
1.218 raeburn 14797: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14798: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
14799: $resulttext .= '<li>'.
14800: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
14801: '</li>';
14802: } else {
14803: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
14804: '</li>';
14805: }
1.216 raeburn 14806: }
1.242 raeburn 14807: foreach my $type ('textbooks','templates') {
14808: if (ref($changes{$type}) eq 'HASH') {
14809: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
14810: foreach my $key (sort(keys(%{$changes{$type}}))) {
14811: my %coursehash = &Apache::lonnet::coursedescription($key);
14812: my $coursetitle = $coursehash{'description'};
14813: my $position = $confhash{$type}{$key}{'order'} + 1;
14814: $resulttext .= '<li>';
1.243 raeburn 14815: foreach my $item ('subject','title','publisher','author') {
14816: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14817: ($type eq 'templates'));
1.242 raeburn 14818: my $name = $item.':';
14819: $name =~ s/^(\w)/\U$1/;
14820: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
14821: }
14822: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
14823: if ($type eq 'textbooks') {
14824: if ($confhash{$type}{$key}{'image'}) {
14825: $resulttext .= ' '.&mt('Image: [_1]',
14826: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
14827: ' alt="Textbook cover" />').'<br />';
14828: }
14829: }
14830: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 14831: }
1.242 raeburn 14832: $resulttext .= '</ul></li>';
1.216 raeburn 14833: }
14834: }
1.235 raeburn 14835: if (ref($changes{'validation'}) eq 'HASH') {
14836: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
14837: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
14838: foreach my $item (@{$validationitemsref}) {
14839: if (exists($changes{'validation'}{$item})) {
14840: if ($item eq 'markup') {
14841: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14842: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
14843: } else {
14844: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14845: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
14846: }
14847: }
14848: }
14849: if (exists($changes{'validation'}{'dc'})) {
14850: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
14851: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
14852: }
1.442 ! raeburn 14853: $resulttext .= '</ul></li>';
1.235 raeburn 14854: }
14855: }
1.216 raeburn 14856: }
1.1 raeburn 14857: $resulttext .= '</ul>';
1.80 raeburn 14858: if (keys(%newenv)) {
14859: &Apache::lonnet::appenv(\%newenv);
14860: }
1.1 raeburn 14861: } else {
1.86 raeburn 14862: if ($context eq 'requestcourses') {
14863: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 14864: } elsif ($context eq 'requestauthor') {
14865: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 14866: } else {
1.90 weissno 14867: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 14868: }
1.1 raeburn 14869: }
14870: } else {
1.11 albertel 14871: $resulttext = '<span class="LC_error">'.
14872: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14873: }
1.216 raeburn 14874: if ($errors) {
14875: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
14876: '<ul>'.$errors.'</ul></p>';
14877: }
1.3 raeburn 14878: return $resulttext;
1.1 raeburn 14879: }
14880:
1.216 raeburn 14881: sub process_textbook_image {
1.242 raeburn 14882: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 14883: my $filename = $env{'form.'.$caller.'.filename'};
14884: my ($error,$url);
14885: my ($width,$height) = (50,50);
14886: if ($configuserok eq 'ok') {
14887: if ($switchserver) {
14888: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
14889: $switchserver);
14890: } elsif ($author_ok eq 'ok') {
1.421 raeburn 14891: my $modified = [];
1.216 raeburn 14892: my ($result,$imageurl) =
1.421 raeburn 14893: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
14894: "$type/$cdom/$cnum/cover",$width,$height,
14895: '',$modified);
1.216 raeburn 14896: if ($result eq 'ok') {
14897: $url = $imageurl;
1.421 raeburn 14898: &update_modify_urls($r,$modified);
1.216 raeburn 14899: } else {
14900: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14901: }
14902: } else {
14903: $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);
14904: }
14905: } else {
14906: $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);
14907: }
14908: return ($url,$error);
14909: }
14910:
1.267 raeburn 14911: sub modify_ltitools {
14912: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.421 raeburn 14913: my (%currtoolsec,%secchanges,%newtoolsec,%newkeyset);
14914: &fetch_secrets($dom,'toolsec',\%domconfig,\%currtoolsec,\%secchanges,\%newtoolsec,\%newkeyset);
14915:
1.267 raeburn 14916: my $confname = $dom.'-domainconfig';
14917: my $servadm = $r->dir_config('lonAdmEMail');
14918: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.421 raeburn 14919:
14920: my ($resulttext,$ltitoolsoutput,$is_home,$errors,%ltitoolschg,%newtoolsenc,%newltitools);
14921: my $toolserror =
14922: &Apache::courseprefs::process_ltitools($r,$dom,$confname,$domconfig{'ltitools'},\%ltitoolschg,'domain',
14923: $lastactref,$configuserok,$switchserver,$author_ok);
14924:
14925: my $home = &Apache::lonnet::domain($dom,'primary');
14926: unless (($home eq 'no_host') || ($home eq '')) {
14927: my @ids=&Apache::lonnet::current_machine_ids();
14928: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; last; } }
14929: }
14930:
14931: if (keys(%ltitoolschg)) {
14932: foreach my $id (keys(%ltitoolschg)) {
14933: if (ref($ltitoolschg{$id}) eq 'HASH') {
14934: foreach my $inner (keys(%{$ltitoolschg{$id}})) {
14935: if (($inner eq 'secret') || ($inner eq 'key')) {
14936: if ($is_home) {
14937: $newtoolsenc{$id}{$inner} = $ltitoolschg{$id}{$inner};
14938: }
14939: }
14940: }
1.267 raeburn 14941: }
1.421 raeburn 14942: }
14943: $ltitoolsoutput = &Apache::courseprefs::store_ltitools($dom,'','domain',\%ltitoolschg,$domconfig{'ltitools'});
14944: if (keys(%ltitoolschg)) {
14945: %newltitools = %ltitoolschg;
14946: }
14947: }
14948: if (ref($domconfig{'ltitools'}) eq 'HASH') {
14949: foreach my $id (%{$domconfig{'ltitools'}}) {
14950: next if ($id !~ /^\d+$/);
14951: unless (exists($ltitoolschg{$id})) {
14952: if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
14953: foreach my $inner (keys(%{$domconfig{'ltitools'}{$id}})) {
14954: if (($inner eq 'secret') || ($inner eq 'key')) {
14955: if ($is_home) {
14956: $newtoolsenc{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14957: }
14958: } else {
14959: $newltitools{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14960: }
14961: }
14962: } else {
14963: $newltitools{$id} = $domconfig{'ltitools'}{$id};
1.322 raeburn 14964: }
1.421 raeburn 14965: }
14966: }
14967: }
14968: if ($toolserror) {
14969: $errors = '<li>'.$toolserror.'</li>';
14970: }
14971: if ((keys(%ltitoolschg) == 0) && (keys(%secchanges) == 0)) {
14972: $resulttext = &mt('No changes made.');
14973: if ($errors) {
14974: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
14975: $errors.'</ul>';
14976: }
14977: return $resulttext;
14978: }
14979: my %ltitoolshash = (
14980: $action => { %newltitools }
14981: );
14982: if (keys(%secchanges)) {
14983: $ltitoolshash{'toolsec'} = \%newtoolsec;
14984: }
14985: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,$dom);
14986: if ($putresult eq 'ok') {
14987: my %keystore;
14988: if ($is_home) {
14989: my %toolsenchash = (
14990: $action => { %newtoolsenc }
14991: );
14992: &Apache::lonnet::put_dom('encconfig',\%toolsenchash,$dom,undef,1);
1.423 raeburn 14993: my $cachetime = 24*60*60;
14994: &Apache::lonnet::do_cache_new('ltitoolsenc',$dom,\%newtoolsenc,$cachetime);
1.421 raeburn 14995: &store_security($dom,'ltitools',\%secchanges,\%newkeyset,\%keystore,$lastactref);
14996: }
14997: $resulttext = &mt('Changes made:').'<ul>';
14998: if (keys(%secchanges) > 0) {
1.423 raeburn 14999: $resulttext .= <i_security_results($dom,'ltitools',\%secchanges,\%newtoolsec,\%newkeyset,\%keystore);
1.421 raeburn 15000: }
15001: if (keys(%ltitoolschg) > 0) {
15002: $resulttext .= $ltitoolsoutput;
15003: }
1.423 raeburn 15004: my $cachetime = 24*60*60;
15005: &Apache::lonnet::do_cache_new('ltitools',$dom,\%newltitools,$cachetime);
15006: if (ref($lastactref) eq 'HASH') {
15007: $lastactref->{'ltitools'} = 1;
15008: }
1.421 raeburn 15009: } else {
15010: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15011: }
15012: if ($errors) {
15013: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
15014: $errors.'</ul></p>';
15015: }
15016: return $resulttext;
15017: }
15018:
15019: sub fetch_secrets {
15020: my ($dom,$context,$domconfig,$currsec,$secchanges,$newsec,$newkeyset) = @_;
15021: my %keyset;
15022: %{$currsec} = ();
15023: $newsec->{'private'}{'keys'} = [];
15024: $newsec->{'encrypt'} = {};
15025: $newsec->{'rules'} = {};
15026: if ($context eq 'ltisec') {
15027: $newsec->{'linkprot'} = {};
15028: }
15029: if (ref($domconfig->{$context}) eq 'HASH') {
15030: %{$currsec} = %{$domconfig->{$context}};
15031: if ($context eq 'ltisec') {
15032: if (ref($currsec->{'linkprot'}) eq 'HASH') {
15033: foreach my $id (keys(%{$currsec->{'linkprot'}})) {
15034: unless ($id =~ /^\d+$/) {
15035: delete($currsec->{'linkprot'}{$id});
1.297 raeburn 15036: }
1.267 raeburn 15037: }
15038: }
1.421 raeburn 15039: }
15040: if (ref($currsec->{'private'}) eq 'HASH') {
15041: if (ref($currsec->{'private'}{'keys'}) eq 'ARRAY') {
15042: $newsec->{'private'}{'keys'} = $currsec->{'private'}{'keys'};
15043: map { $keyset{$_} = 1; } @{$currsec->{'private'}{'keys'}};
1.267 raeburn 15044: }
1.421 raeburn 15045: }
15046: }
15047: my @items= ('crs','dom');
15048: if ($context eq 'ltisec') {
15049: push(@items,'consumers');
15050: }
15051: foreach my $item (@items) {
15052: my $formelement;
15053: if (($context eq 'toolsec') || ($item eq 'consumers')) {
15054: $formelement = 'form.'.$context.'_'.$item;
15055: } else {
15056: $formelement = 'form.'.$context.'_'.$item.'linkprot';
15057: }
15058: if ($env{$formelement}) {
15059: $newsec->{'encrypt'}{$item} = 1;
15060: if (ref($currsec->{'encrypt'}) eq 'HASH') {
15061: unless ($currsec->{'encrypt'}{$item}) {
15062: $secchanges->{'encrypt'} = 1;
15063: }
15064: } else {
15065: $secchanges->{'encrypt'} = 1;
1.267 raeburn 15066: }
1.421 raeburn 15067: } elsif (ref($currsec->{'encrypt'}) eq 'HASH') {
15068: if ($currsec->{'encrypt'}{$item}) {
15069: $secchanges->{'encrypt'} = 1;
1.323 raeburn 15070: }
1.421 raeburn 15071: }
15072: }
15073: my $secrets;
15074: if ($context eq 'ltisec') {
15075: $secrets = 'ltisecrets';
15076: } else {
15077: $secrets = 'toolsecrets';
15078: }
15079: unless (exists($currsec->{'rules'})) {
15080: $currsec->{'rules'} = {};
15081: }
15082: &password_rule_changes($secrets,$newsec->{'rules'},$currsec->{'rules'},$secchanges);
15083:
15084: my @ids=&Apache::lonnet::current_machine_ids();
15085: my %servers = &Apache::lonnet::get_servers($dom,'library');
15086:
15087: foreach my $hostid (keys(%servers)) {
15088: if (($hostid ne '') && (grep(/^\Q$hostid\E$/,@ids))) {
15089: my $keyitem = 'form.'.$context.'_privkey_'.$hostid;
15090: if (exists($env{$keyitem})) {
15091: $env{$keyitem} =~ s/(`)/'/g;
15092: if ($keyset{$hostid}) {
15093: if ($env{'form.'.$context.'_changeprivkey_'.$hostid}) {
15094: if ($env{$keyitem} ne '') {
15095: $secchanges->{'private'} = 1;
15096: $newkeyset->{$hostid} = $env{$keyitem};
15097: }
1.296 raeburn 15098: }
1.421 raeburn 15099: } elsif ($env{$keyitem} ne '') {
15100: unless (grep(/^\Q$hostid\E$/,@{$newsec->{'private'}{'keys'}})) {
15101: push(@{$newsec->{'private'}{'keys'}},$hostid);
1.296 raeburn 15102: }
1.421 raeburn 15103: $secchanges->{'private'} = 1;
15104: $newkeyset->{$hostid} = $env{$keyitem};
1.267 raeburn 15105: }
15106: }
1.421 raeburn 15107: }
15108: }
15109: }
15110:
15111: sub store_security {
1.424 raeburn 15112: my ($dom,$context,$secchanges,$newkeyset,$keystore) = @_;
1.421 raeburn 15113: return unless ((ref($secchanges) eq 'HASH') && (ref($newkeyset) eq 'HASH') &&
15114: (ref($keystore) eq 'HASH'));
15115: if (keys(%{$secchanges})) {
15116: if ($secchanges->{'private'}) {
15117: my $who = &escape($env{'user.name'}.':'.$env{'user.domain'});
15118: foreach my $hostid (keys(%{$newkeyset})) {
15119: my $storehash = {
15120: key => $newkeyset->{$hostid},
15121: who => $env{'user.name'}.':'.$env{'user.domain'},
15122: };
15123: $keystore->{$hostid} = &Apache::lonnet::store_dom($storehash,$context,'private',
15124: $dom,$hostid);
15125: }
15126: }
15127: }
15128: }
15129:
15130: sub lti_security_results {
1.423 raeburn 15131: my ($dom,$context,$secchanges,$newsec,$newkeyset,$keystore) = @_;
1.421 raeburn 15132: my $output;
1.423 raeburn 15133: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
15134: my $needs_update;
1.421 raeburn 15135: foreach my $item (keys(%{$secchanges})) {
15136: if ($item eq 'encrypt') {
1.423 raeburn 15137: $needs_update = 1;
1.421 raeburn 15138: my %encrypted;
15139: if ($context eq 'lti') {
15140: %encrypted = (
15141: crs => {
15142: on => &mt('Encryption of stored link protection secrets defined in courses enabled'),
15143: off => &mt('Encryption of stored link protection secrets defined in courses disabled'),
15144: },
15145: dom => {
15146: on => &mt('Encryption of stored link protection secrets defined in domain enabled'),
15147: off => &mt('Encryption of stored link protection secrets defined in domain disabled'),
15148: },
15149: consumers => {
15150: on => &mt('Encryption of stored consumer secrets defined in domain enabled'),
15151: off => &mt('Encryption of stored consumer secrets defined in domain disabled'),
15152: },
15153: );
1.267 raeburn 15154: } else {
1.421 raeburn 15155: %encrypted = (
15156: crs => {
15157: on => &mt('Encryption of stored external tool secrets defined in courses enabled'),
15158: off => &mt('Encryption of stored external tool secrets defined in courses disabled'),
15159: },
15160: dom => {
15161: on => &mt('Encryption of stored external tool secrets defined in domain enabled'),
15162: off => &mt('Encryption of stored external tool secrets defined in domain disabled'),
15163: },
15164: );
15165: }
15166: my @types= ('crs','dom');
15167: if ($context eq 'lti') {
1.423 raeburn 15168: foreach my $type (@types) {
15169: undef($domdefaults{'linkprotenc_'.$type});
15170: }
1.421 raeburn 15171: push(@types,'consumers');
1.423 raeburn 15172: undef($domdefaults{'ltienc_consumers'});
15173: } elsif ($context eq 'ltitools') {
15174: foreach my $type (@types) {
15175: undef($domdefaults{'toolenc_'.$type});
15176: }
1.267 raeburn 15177: }
1.421 raeburn 15178: foreach my $type (@types) {
15179: my $shown = $encrypted{$type}{'off'};
15180: if (ref($newsec->{$item}) eq 'HASH') {
15181: if ($newsec->{$item}{$type}) {
1.423 raeburn 15182: if ($context eq 'lti') {
15183: if ($type eq 'consumers') {
15184: $domdefaults{'ltienc_consumers'} = 1;
15185: } else {
15186: $domdefaults{'linkprotenc_'.$type} = 1;
15187: }
15188: } elsif ($context eq 'ltitools') {
15189: $domdefaults{'toolenc_'.$type} = 1;
15190: }
1.421 raeburn 15191: $shown = $encrypted{$type}{'on'};
1.319 raeburn 15192: }
1.267 raeburn 15193: }
1.421 raeburn 15194: $output .= '<li>'.$shown.'</li>';
1.267 raeburn 15195: }
1.421 raeburn 15196: } elsif ($item eq 'rules') {
15197: my %titles = &Apache::lonlocal::texthash(
15198: min => 'Minimum password length',
15199: max => 'Maximum password length',
15200: chars => 'Required characters',
15201: );
15202: foreach my $rule ('min','max') {
15203: if ($newsec->{rules}{$rule} eq '') {
15204: if ($rule eq 'min') {
15205: $output .= '<li>'.&mt('[_1] not set.',$titles{$rule});
15206: ' '.&mt('Default of [_1] will be used',
15207: $Apache::lonnet::passwdmin).'</li>';
15208: } else {
15209: $output .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
15210: }
15211: } else {
15212: $output .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$newsec->{rules}{$rule}).'</li>';
15213: }
15214: }
15215: if (ref($newsec->{'rules'}{'chars'}) eq 'ARRAY') {
15216: if (@{$newsec->{'rules'}{'chars'}} > 0) {
15217: my %rulenames = &Apache::lonlocal::texthash(
15218: uc => 'At least one upper case letter',
15219: lc => 'At least one lower case letter',
15220: num => 'At least one number',
15221: spec => 'At least one non-alphanumeric',
15222: );
15223: my $needed = '<ul><li>'.
15224: join('</li><li>',map {$rulenames{$_} } @{$newsec->{'rules'}{'chars'}}).
15225: '</li></ul>';
15226: $output .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
15227: } else {
15228: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 15229: }
1.421 raeburn 15230: } else {
15231: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 15232: }
1.421 raeburn 15233: } elsif ($item eq 'private') {
1.423 raeburn 15234: $needs_update = 1;
15235: if ($context eq 'lti') {
15236: undef($domdefaults{'ltiprivhosts'});
15237: } elsif ($context eq 'ltitools') {
15238: undef($domdefaults{'toolprivhosts'});
15239: }
1.421 raeburn 15240: if (keys(%{$newkeyset})) {
1.423 raeburn 15241: my @privhosts;
1.421 raeburn 15242: foreach my $hostid (sort(keys(%{$newkeyset}))) {
15243: if ($keystore->{$hostid} eq 'ok') {
15244: $output .= '<li>'.&mt('Encryption key for storage of shared secrets saved for [_1]',$hostid).'</li>';
1.423 raeburn 15245: unless (grep(/^\Q$hostid\E$/,@privhosts)) {
15246: push(@privhosts,$hostid);
15247: }
15248: }
15249: }
15250: if (@privhosts) {
15251: if ($context eq 'lti') {
15252: $domdefaults{'ltiprivhosts'} = \@privhosts;
15253: } elsif ($context eq 'ltitools') {
15254: $domdefaults{'toolprivhosts'} = \@privhosts;
1.267 raeburn 15255: }
15256: }
15257: }
1.421 raeburn 15258: } elsif ($item eq 'linkprot') {
15259: next;
1.434 raeburn 15260: } elsif ($item eq 'suggested') {
15261: if ((ref($secchanges->{'suggested'}) eq 'HASH') &&
15262: (ref($newsec->{'suggested'}) eq 'HASH')) {
15263: my $suggestions;
15264: foreach my $id (sort { $a <=> $b } keys(%{$secchanges->{'suggested'}})) {
15265: if (ref($newsec->{'suggested'}->{$id}) eq 'HASH') {
15266: my $name = $newsec->{'suggested'}->{$id}->{'name'};
15267: my $info = $newsec->{'suggested'}->{$id}->{'info'};
15268: $suggestions .= '<li>'.&mt('Launcher: [_1]',$name).'<br />'.
15269: &mt('Recommend: [_1]','<pre>'.$info.'</pre>').
15270: '</li>';
15271: } else {
15272: $suggestions .= '<li>'.&mt('Recommendations deleted for Launcher: [_1]',
15273: $newsec->{'suggested'}->{$id}).'</li>';
15274: }
15275: }
15276: if ($suggestions) {
15277: $output .= '<li>'.&mt('Hints in Courses for Link Protector Configuration').
15278: '<ul>'.$suggestions.'</ul>'.
15279: '</li>';
15280: }
15281: }
1.267 raeburn 15282: }
15283: }
1.423 raeburn 15284: if ($needs_update) {
15285: my $cachetime = 24*60*60;
15286: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15287: }
1.421 raeburn 15288: return $output;
15289: }
15290:
15291: sub modify_proctoring {
15292: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15293: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15294: my (@allpos,%changes,%confhash,%encconfhash,$errors,$resulttext,%imgdeletions);
15295: my $confname = $dom.'-domainconfig';
15296: my $servadm = $r->dir_config('lonAdmEMail');
1.372 raeburn 15297: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
15298: my %providernames = &proctoring_providernames();
15299: my $maxnum = scalar(keys(%providernames));
15300:
15301: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
15302: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
15303: if (ref($requref) eq 'HASH') {
15304: %requserfields = %{$requref};
15305: }
15306: if (ref($opturef) eq 'HASH') {
15307: %optuserfields = %{$opturef};
15308: }
15309: if (ref($defref) eq 'HASH') {
15310: %defaults = %{$defref};
15311: }
15312: if (ref($extref) eq 'HASH') {
15313: %extended = %{$extref};
15314: }
15315: if (ref($crsref) eq 'HASH') {
15316: %crsconf = %{$crsref};
15317: }
15318: if (ref($rolesref) eq 'ARRAY') {
15319: @courseroles = @{$rolesref};
15320: }
15321: if (ref($ltiref) eq 'ARRAY') {
15322: @ltiroles = @{$ltiref};
15323: }
15324:
15325: if (ref($domconfig{$action}) eq 'HASH') {
15326: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.proctoring_image_del');
15327: if (@todeleteimages) {
15328: map { $imgdeletions{$_} = 1; } @todeleteimages;
15329: }
15330: }
15331: my %customadds;
15332: my @newcustom = &Apache::loncommon::get_env_multiple('form.proctoring_customadd');
15333: if (@newcustom) {
15334: map { $customadds{$_} = 1; } @newcustom;
15335: }
15336: foreach my $provider (sort(keys(%providernames))) {
15337: $confhash{$provider} = {};
15338: my $pos = $env{'form.proctoring_pos_'.$provider};
15339: $pos =~ s/\D+//g;
15340: $allpos[$pos] = $provider;
15341: my (%current,%currentenc);
15342: my $showroles = 0;
15343: if (ref($domconfig{$action}) eq 'HASH') {
15344: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15345: %current = %{$domconfig{$action}{$provider}};
15346: foreach my $item ('key','secret') {
15347: $currentenc{$item} = $current{$item};
15348: delete($current{$item});
15349: }
15350: }
15351: }
15352: if ($env{'form.proctoring_available_'.$provider}) {
15353: $confhash{$provider}{'available'} = 1;
15354: unless ($current{'available'}) {
15355: $changes{$provider} = 1;
15356: }
15357: } else {
15358: %{$confhash{$provider}} = %current;
15359: %{$encconfhash{$provider}} = %currentenc;
15360: $confhash{$provider}{'available'} = 0;
15361: if ($current{'available'}) {
15362: $changes{$provider} = 1;
15363: }
15364: }
15365: if ($confhash{$provider}{'available'}) {
15366: foreach my $field ('lifetime','version','sigmethod','url','key','secret') {
15367: my $possval = $env{'form.proctoring_'.$provider.'_'.$field};
15368: if ($field eq 'lifetime') {
15369: if ($possval =~ /^\d+$/) {
15370: $confhash{$provider}{$field} = $possval;
15371: }
15372: } elsif ($field eq 'version') {
15373: if ($possval =~ /^\d+\.\d+$/) {
15374: $confhash{$provider}{$field} = $possval;
15375: }
15376: } elsif ($field eq 'sigmethod') {
15377: if ($possval =~ /^\QHMAC-SHA\E(1|256)$/) {
15378: $confhash{$provider}{$field} = $possval;
15379: }
15380: } elsif ($field eq 'url') {
15381: $confhash{$provider}{$field} = $possval;
15382: } elsif (($field eq 'key') || ($field eq 'secret')) {
15383: $encconfhash{$provider}{$field} = $possval;
15384: unless ($currentenc{$field} eq $possval) {
15385: $changes{$provider} = 1;
15386: }
15387: }
15388: unless (($field eq 'key') || ($field eq 'secret')) {
15389: unless ($current{$field} eq $confhash{$provider}{$field}) {
15390: $changes{$provider} = 1;
15391: }
15392: }
15393: }
15394: if ($imgdeletions{$provider}) {
15395: $changes{$provider} = 1;
15396: } elsif ($env{'form.proctoring_image_'.$provider.'.filename'} ne '') {
15397: my ($imageurl,$error) =
15398: &process_proctoring_image($r,$dom,$confname,'proctoring_image_'.$provider,$provider,
15399: $configuserok,$switchserver,$author_ok);
15400: if ($imageurl) {
15401: $confhash{$provider}{'image'} = $imageurl;
15402: $changes{$provider} = 1;
15403: }
15404: if ($error) {
15405: &Apache::lonnet::logthis($error);
15406: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15407: }
15408: } elsif (exists($current{'image'})) {
15409: $confhash{$provider}{'image'} = $current{'image'};
15410: }
15411: if (ref($requserfields{$provider}) eq 'ARRAY') {
15412: if (@{$requserfields{$provider}} > 0) {
15413: if (grep(/^user$/,@{$requserfields{$provider}})) {
15414: if ($env{'form.proctoring_userincdom_'.$provider}) {
15415: $confhash{$provider}{'incdom'} = 1;
15416: }
15417: unless ($current{'incdom'} eq $confhash{$provider}{'incdom'}) {
15418: $changes{$provider} = 1;
15419: }
15420: }
15421: if (grep(/^roles$/,@{$requserfields{$provider}})) {
15422: $showroles = 1;
15423: }
15424: }
15425: }
15426: $confhash{$provider}{'fields'} = [];
15427: if (ref($optuserfields{$provider}) eq 'ARRAY') {
15428: if (@{$optuserfields{$provider}} > 0) {
15429: my @optfields = &Apache::loncommon::get_env_multiple('form.proctoring_optional_'.$provider);
15430: foreach my $field (@{$optuserfields{$provider}}) {
15431: if (grep(/^\Q$field\E$/,@optfields)) {
15432: push(@{$confhash{$provider}{'fields'}},$field);
15433: }
15434: }
15435: }
15436: if (ref($current{'fields'}) eq 'ARRAY') {
15437: unless ($changes{$provider}) {
15438: my @new = sort(@{$confhash{$provider}{'fields'}});
15439: my @old = sort(@{$current{'fields'}});
15440: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15441: if (@diffs) {
15442: $changes{$provider} = 1;
15443: }
15444: }
15445: } elsif (@{$confhash{$provider}{'fields'}}) {
15446: $changes{$provider} = 1;
15447: }
15448: }
15449: if (ref($defaults{$provider}) eq 'ARRAY') {
15450: if (@{$defaults{$provider}} > 0) {
15451: my %options;
15452: if (ref($extended{$provider}) eq 'HASH') {
15453: %options = %{$extended{$provider}};
15454: }
15455: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_defaults_'.$provider);
15456: foreach my $field (@{$defaults{$provider}}) {
15457: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
15458: my $poss = $env{'form.proctoring_defaults_'.$field.'_'.$provider};
15459: if (grep(/^\Q$poss\E$/,@{$options{$field}})) {
15460: push(@{$confhash{$provider}{'defaults'}},$poss);
15461: }
15462: } elsif ((exists($options{$field})) && (ref($options{$field}) eq 'HASH')) {
15463: foreach my $inner (keys(%{$options{$field}})) {
15464: if (ref($options{$field}{$inner}) eq 'ARRAY') {
15465: my $poss = $env{'form.proctoring_'.$inner.'_'.$provider};
15466: if (grep(/^\Q$poss\E$/,@{$options{$field}{$inner}})) {
15467: $confhash{$provider}{'defaults'}{$inner} = $poss;
15468: }
15469: } else {
15470: $confhash{$provider}{'defaults'}{$inner} = $env{'form.proctoring_'.$inner.'_'.$provider};
15471: }
15472: }
15473: } else {
15474: if (grep(/^\Q$field\E$/,@checked)) {
15475: push(@{$confhash{$provider}{'defaults'}},$field);
15476: }
15477: }
15478: }
15479: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15480: if (ref($current{'defaults'}) eq 'ARRAY') {
15481: unless ($changes{$provider}) {
15482: my @new = sort(@{$confhash{$provider}{'defaults'}});
15483: my @old = sort(@{$current{'defaults'}});
15484: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15485: if (@diffs) {
15486: $changes{$provider} = 1;
15487: }
15488: }
15489: } elsif (ref($current{'defaults'}) eq 'ARRAY') {
15490: if (@{$current{'defaults'}}) {
15491: $changes{$provider} = 1;
15492: }
15493: }
15494: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15495: if (ref($current{'defaults'}) eq 'HASH') {
15496: unless ($changes{$provider}) {
15497: foreach my $key (keys(%{$confhash{$provider}{'defaults'}})) {
15498: unless ($confhash{$provider}{'defaults'}{$key} eq $current{'defaults'}{$key}) {
15499: $changes{$provider} = 1;
15500: last;
15501: }
15502: }
15503: }
15504: unless ($changes{$provider}) {
15505: foreach my $key (keys(%{$current{'defaults'}})) {
15506: unless ($current{'defaults'}{$key} eq $confhash{$provider}{'defaults'}{$key}) {
15507: $changes{$provider} = 1;
15508: last;
15509: }
15510: }
15511: }
15512: } elsif (keys(%{$confhash{$provider}{'defaults'}})) {
15513: $changes{$provider} = 1;
15514: }
15515: }
15516: }
15517: }
15518: if (ref($crsconf{$provider}) eq 'ARRAY') {
15519: if (@{$crsconf{$provider}} > 0) {
15520: $confhash{$provider}{'crsconf'} = [];
15521: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_crsconf_'.$provider);
15522: foreach my $crsfield (@{$crsconf{$provider}}) {
15523: if (grep(/^\Q$crsfield\E$/,@checked)) {
15524: push(@{$confhash{$provider}{'crsconf'}},$crsfield);
15525: }
15526: }
15527: if (ref($current{'crsconf'}) eq 'ARRAY') {
15528: unless ($changes{$provider}) {
15529: my @new = sort(@{$confhash{$provider}{'crsconf'}});
15530: my @old = sort(@{$current{'crsconf'}});
15531: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15532: if (@diffs) {
15533: $changes{$provider} = 1;
15534: }
15535: }
15536: } elsif (@{$confhash{$provider}{'crsconf'}}) {
15537: $changes{$provider} = 1;
15538: }
15539: }
15540: }
15541: if ($showroles) {
15542: $confhash{$provider}{'roles'} = {};
15543: foreach my $role (@courseroles) {
15544: my $poss = $env{'form.proctoring_roles_'.$role.'_'.$provider};
15545: if (grep(/^\Q$poss\E$/,@ltiroles)) {
15546: $confhash{$provider}{'roles'}{$role} = $poss;
15547: }
15548: }
15549: unless ($changes{$provider}) {
15550: if (ref($current{'roles'}) eq 'HASH') {
15551: foreach my $role (keys(%{$current{'roles'}})) {
15552: unless ($current{'roles'}{$role} eq $confhash{$provider}{'roles'}{$role}) {
15553: $changes{$provider} = 1;
15554: last
15555: }
15556: }
15557: unless ($changes{$provider}) {
15558: foreach my $role (keys(%{$confhash{$provider}{'roles'}})) {
15559: unless ($confhash{$provider}{'roles'}{$role} eq $current{'roles'}{$role}) {
15560: $changes{$provider} = 1;
15561: last;
15562: }
15563: }
15564: }
15565: } elsif (keys(%{$confhash{$provider}{'roles'}})) {
15566: $changes{$provider} = 1;
15567: }
15568: }
15569: }
15570: if (ref($current{'custom'}) eq 'HASH') {
15571: my @customdels = &Apache::loncommon::get_env_multiple('form.proctoring_customdel_'.$provider);
15572: foreach my $key (keys(%{$current{'custom'}})) {
15573: if (grep(/^\Q$key\E$/,@customdels)) {
15574: $changes{$provider} = 1;
15575: } else {
15576: $confhash{$provider}{'custom'}{$key} = $env{'form.proctoring_customval_'.$key.'_'.$provider};
15577: if ($confhash{$provider}{'custom'}{$key} ne $current{'custom'}{$key}) {
15578: $changes{$provider} = 1;
15579: }
15580: }
15581: }
15582: }
15583: if ($customadds{$provider}) {
15584: my $name = $env{'form.proctoring_custom_name_'.$provider};
15585: $name =~ s/(`)/'/g;
15586: $name =~ s/^\s+//;
15587: $name =~ s/\s+$//;
15588: my $value = $env{'form.proctoring_custom_value_'.$provider};
15589: $value =~ s/(`)/'/g;
15590: $value =~ s/^\s+//;
15591: $value =~ s/\s+$//;
15592: if ($name ne '') {
15593: $confhash{$provider}{'custom'}{$name} = $value;
15594: $changes{$provider} = 1;
15595: }
15596: }
15597: }
15598: }
15599: if (@allpos > 0) {
15600: my $idx = 0;
15601: foreach my $provider (@allpos) {
15602: if ($provider ne '') {
15603: $confhash{$provider}{'order'} = $idx;
15604: unless ($changes{$provider}) {
15605: if (ref($domconfig{$action}) eq 'HASH') {
15606: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15607: if ($domconfig{$action}{$provider}{'order'} ne $idx) {
15608: $changes{$provider} = 1;
15609: }
15610: }
15611: }
15612: }
15613: $idx ++;
15614: }
15615: }
15616: }
15617: my %proc_hash = (
15618: $action => { %confhash }
15619: );
15620: my $putresult = &Apache::lonnet::put_dom('configuration',\%proc_hash,
15621: $dom);
15622: if ($putresult eq 'ok') {
15623: my %proc_enchash = (
15624: $action => { %encconfhash }
15625: );
1.384 raeburn 15626: &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom,undef,1);
1.372 raeburn 15627: if (keys(%changes) > 0) {
15628: my $cachetime = 24*60*60;
15629: my %procall = %confhash;
15630: foreach my $provider (keys(%procall)) {
15631: if (ref($encconfhash{$provider}) eq 'HASH') {
15632: foreach my $key ('key','secret') {
15633: $procall{$provider}{$key} = $encconfhash{$provider}{$key};
15634: }
15635: }
15636: }
15637: &Apache::lonnet::do_cache_new('proctoring',$dom,\%procall,$cachetime);
15638: if (ref($lastactref) eq 'HASH') {
15639: $lastactref->{'proctoring'} = 1;
15640: }
15641: $resulttext = &mt('Configuration for Provider(s) with changes:').'<ul>';
15642: my %bynum;
15643: foreach my $provider (sort(keys(%changes))) {
15644: my $position = $confhash{$provider}{'order'};
15645: $bynum{$position} = $provider;
15646: }
15647: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
15648: my $provider = $bynum{$pos};
15649: my %lt = &proctoring_titles($provider);
15650: my %fieldtitles = &proctoring_fieldtitles($provider);
15651: if (!$confhash{$provider}{'available'}) {
15652: $resulttext .= '<li>'.&mt('Proctoring integration unavailable for: [_1]','<b>'.$providernames{$provider}.'</b>').'</li>';
15653: } else {
15654: $resulttext .= '<li>'.&mt('Proctoring integration available for: [_1]','<b>'.$providernames{$provider}.'</b>');
15655: if ($confhash{$provider}{'image'}) {
15656: $resulttext .= ' '.
15657: '<img src="'.$confhash{$provider}{'image'}.'"'.
15658: ' alt="'.&mt('Proctoring icon').'" />';
15659: }
15660: $resulttext .= '<ul>';
15661: my $position = $pos + 1;
15662: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
15663: foreach my $key ('version','sigmethod','url','lifetime') {
15664: if ($confhash{$provider}{$key} ne '') {
15665: $resulttext .= '<li>'.$lt{$key}.': '.$confhash{$provider}{$key}.'</li>';
15666: }
15667: }
15668: if ($encconfhash{$provider}{'key'} ne '') {
15669: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfhash{$provider}{'key'}.'</li>';
15670: }
15671: if ($encconfhash{$provider}{'secret'} ne '') {
15672: $resulttext .= '<li>'.$lt{'secret'}.': ';
15673: my $num = length($encconfhash{$provider}{'secret'});
15674: $resulttext .= ('*'x$num).'</li>';
15675: }
15676: my (@fields,$showroles);
15677: if (ref($requserfields{$provider}) eq 'ARRAY') {
15678: push(@fields,@{$requserfields{$provider}});
15679: }
15680: if (ref($confhash{$provider}{'fields'}) eq 'ARRAY') {
15681: push(@fields,@{$confhash{$provider}{'fields'}});
15682: } elsif (ref($confhash{$provider}{'fields'}) eq 'HASH') {
15683: push(@fields,(keys(%{$confhash{$provider}{'fields'}})));
15684: }
15685: if (@fields) {
15686: if (grep(/^roles$/,@fields)) {
15687: $showroles = 1;
15688: }
15689: $resulttext .= '<li>'.$lt{'udsl'}.': "'.
15690: join('", "', map { $lt{$_}; } @fields).'"</li>';
15691: }
15692: if (ref($requserfields{$provider}) eq 'ARRAY') {
15693: if (grep(/^user$/,@{$requserfields{$provider}})) {
15694: if ($confhash{$provider}{'incdom'}) {
15695: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'uname:dom'}).'</li>';
15696: } else {
15697: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'username'}).'</li>';
15698: }
15699: }
15700: }
15701: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15702: if (@{$confhash{$provider}{'defaults'}} > 0) {
15703: $resulttext .= '<li>'.$lt{'defa'};
15704: foreach my $field (@{$confhash{$provider}{'defaults'}}) {
15705: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15706: }
15707: $resulttext =~ s/,$//;
15708: $resulttext .= '</li>';
15709: }
15710: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15711: if (keys(%{$confhash{$provider}{'defaults'}})) {
15712: $resulttext .= '<li>'.$lt{'defa'}.': <ul>';
15713: foreach my $key (sort(keys(%{$confhash{$provider}{'defaults'}}))) {
15714: if ($confhash{$provider}{'defaults'}{$key} ne '') {
15715: $resulttext .= '<li>'.$fieldtitles{$key}.' = '.$confhash{$provider}{'defaults'}{$key}.'</li>';
15716: }
15717: }
15718: $resulttext .= '</ul></li>';
15719: }
15720: }
15721: if (ref($crsconf{$provider}) eq 'ARRAY') {
15722: if (@{$crsconf{$provider}} > 0) {
15723: $resulttext .= '<li>'.&mt('Configurable in course:');
15724: my $numconfig = 0;
15725: if (ref($confhash{$provider}{'crsconf'}) eq 'ARRAY') {
15726: if (@{$confhash{$provider}{'crsconf'}} > 0) {
15727: foreach my $field (@{$confhash{$provider}{'crsconf'}}) {
15728: $numconfig ++;
15729: if ($provider eq 'examity') {
15730: $resulttext .= ' "'.$lt{'crs'.$field}.'",';
15731: } else {
15732: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15733: }
15734: }
15735: $resulttext =~ s/,$//;
15736: }
15737: }
15738: if (!$numconfig) {
15739: $resulttext .= ' '.&mt('None');
15740: }
15741: $resulttext .= '</li>';
15742: }
15743: }
15744: if ($showroles) {
15745: if (ref($confhash{$provider}{'roles'}) eq 'HASH') {
15746: my $rolemaps;
15747: foreach my $role (@courseroles) {
15748: if ($confhash{$provider}{'roles'}{$role}) {
15749: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
15750: $confhash{$provider}{'roles'}{$role}.',';
15751: }
15752: }
15753: if ($rolemaps) {
15754: $rolemaps =~ s/,$//;
15755: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
15756: }
15757: }
15758: }
15759: if (ref($confhash{$provider}{'custom'}) eq 'HASH') {
15760: my $customlist;
15761: if (keys(%{$confhash{$provider}{'custom'}})) {
15762: foreach my $key (sort(keys(%{$confhash{$provider}{'custom'}}))) {
15763: $customlist .= $key.'='.$confhash{$provider}{'custom'}{$key}.', ';
15764: }
15765: $customlist =~ s/,$//;
15766: }
15767: if ($customlist) {
15768: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
15769: }
15770: }
15771: $resulttext .= '</ul></li>';
15772: }
15773: }
15774: $resulttext .= '</ul>';
15775: } else {
15776: $resulttext = &mt('No changes made.');
15777: }
15778: } else {
15779: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15780: }
15781: if ($errors) {
15782: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15783: $errors.'</ul>';
15784: }
15785: return $resulttext;
15786: }
15787:
15788: sub process_proctoring_image {
15789: my ($r,$dom,$confname,$caller,$provider,$configuserok,$switchserver,$author_ok) = @_;
15790: my $filename = $env{'form.'.$caller.'.filename'};
15791: my ($error,$url);
15792: my ($width,$height) = (21,21);
15793: if ($configuserok eq 'ok') {
15794: if ($switchserver) {
15795: $error = &mt('Upload of Remote Proctoring Provider icon is not permitted to this server: [_1]',
15796: $switchserver);
15797: } elsif ($author_ok eq 'ok') {
1.421 raeburn 15798: my $modified = [];
1.372 raeburn 15799: my ($result,$imageurl,$madethumb) =
1.421 raeburn 15800: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
15801: "proctoring/$provider/icon",$width,$height,
15802: '',$modified);
1.372 raeburn 15803: if ($result eq 'ok') {
15804: if ($madethumb) {
15805: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
15806: my $imagethumb = "$path/tn-".$imagefile;
15807: $url = $imagethumb;
15808: } else {
15809: $url = $imageurl;
15810: }
1.421 raeburn 15811: &update_modify_urls($r,$modified);
1.372 raeburn 15812: } else {
15813: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
15814: }
15815: } else {
15816: $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);
15817: }
15818: } else {
15819: $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);
15820: }
15821: return ($url,$error);
15822: }
15823:
1.320 raeburn 15824: sub modify_lti {
15825: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15826: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.424 raeburn 15827: my ($newid,@allpos,%changes,%confhash,%ltienc,$errors,$resulttext);
1.320 raeburn 15828: my (%posslti,%posslticrs,%posscrstype);
15829: my @courseroles = ('cc','in','ta','ep','st');
15830: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
15831: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
1.392 raeburn 15832: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 15833: my %coursetypetitles = &Apache::lonlocal::texthash (
15834: official => 'Official',
15835: unofficial => 'Unofficial',
15836: community => 'Community',
15837: textbook => 'Textbook',
15838: placement => 'Placement Test',
1.392 raeburn 15839: lti => 'LTI Provider',
1.320 raeburn 15840: );
1.325 raeburn 15841: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 15842: my %lt = <i_names();
15843: map { $posslti{$_} = 1; } @ltiroles;
15844: map { $posslticrs{$_} = 1; } @lticourseroles;
15845: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 15846:
1.326 raeburn 15847: my %menutitles = <imenu_titles();
1.421 raeburn 15848: my (%currltisec,%secchanges,%newltisec,%newltienc,%newkeyset);
1.326 raeburn 15849:
1.421 raeburn 15850: &fetch_secrets($dom,'ltisec',\%domconfig,\%currltisec,\%secchanges,\%newltisec,\%newkeyset);
1.405 raeburn 15851:
1.406 raeburn 15852: my (%linkprotchg,$linkprotoutput,$is_home);
15853: my $proterror = &Apache::courseprefs::process_linkprot($dom,'',$currltisec{'linkprot'},
15854: \%linkprotchg,'domain');
15855: my $home = &Apache::lonnet::domain($dom,'primary');
15856: unless (($home eq 'no_host') || ($home eq '')) {
15857: my @ids=&Apache::lonnet::current_machine_ids();
15858: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; } }
15859: }
15860:
15861: if (keys(%linkprotchg)) {
15862: $secchanges{'linkprot'} = 1;
15863: my %oldlinkprot;
15864: if (ref($currltisec{'linkprot'}) eq 'HASH') {
15865: %oldlinkprot = %{$currltisec{'linkprot'}};
15866: }
15867: foreach my $id (keys(%linkprotchg)) {
15868: if (ref($linkprotchg{$id}) eq 'HASH') {
15869: foreach my $inner (keys(%{$linkprotchg{$id}})) {
15870: if (($inner eq 'secret') || ($inner eq 'key')) {
15871: if ($is_home) {
15872: $newltienc{$id}{$inner} = $linkprotchg{$id}{$inner};
15873: }
15874: }
15875: }
15876: } else {
15877: $newltisec{'linkprot'}{$id} = $linkprotchg{$id};
15878: }
15879: }
15880: $linkprotoutput = &Apache::courseprefs::store_linkprot($dom,'','domain',\%linkprotchg,\%oldlinkprot);
15881: if (keys(%linkprotchg)) {
15882: %{$newltisec{'linkprot'}} = %linkprotchg;
15883: }
15884: }
15885: if (ref($currltisec{'linkprot'}) eq 'HASH') {
1.434 raeburn 15886: foreach my $id (keys(%{$currltisec{'linkprot'}})) {
1.406 raeburn 15887: next if ($id !~ /^\d+$/);
15888: unless (exists($linkprotchg{$id})) {
15889: if (ref($currltisec{'linkprot'}{$id}) eq 'HASH') {
15890: foreach my $inner (keys(%{$currltisec{'linkprot'}{$id}})) {
15891: if (($inner eq 'secret') || ($inner eq 'key')) {
15892: if ($is_home) {
15893: $newltienc{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15894: }
15895: } else {
15896: $newltisec{'linkprot'}{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15897: }
15898: }
15899: } else {
15900: $newltisec{'linkprot'}{$id} = $currltisec{'linkprot'}{$id};
15901: }
15902: }
15903: }
15904: }
15905: if ($proterror) {
15906: $errors .= '<li>'.$proterror.'</li>';
15907: }
1.434 raeburn 15908:
15909: my (%delsuggested,%suggids,@suggested);;
15910: if (ref($currltisec{'suggested'}) eq 'HASH') {
15911: my $maxnum = $env{'form.linkprot_suggested_maxnum'};
15912: my @todelete = &Apache::loncommon::get_env_multiple('form.linkprot_suggested_del');
15913: for (my $i=0; $i<$maxnum; $i++) {
15914: my $itemid = $env{'form.linkprot_suggested_id_'.$i};
15915: $itemid =~ s/\D+//g;
15916: if ($itemid) {
15917: if (ref($currltisec{'suggested'}->{$itemid}) eq 'HASH') {
15918: push(@suggested,$i);
15919: $suggids{$i} = $itemid;
15920: if ((@todelete > 0) && (grep(/^$i$/,@todelete))) {
15921: if (ref($currltisec{'suggested'}{$itemid}) eq 'HASH') {
15922: $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
15923: }
15924: } else {
15925: if ($env{'form.linkprot_suggested_name_'.$i} eq '') {
15926: $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
15927: } else {
15928: $env{'form.linkprot_suggested_name_'.$i} =~ s/(`)/'/g;
15929: $env{'form.linkprot_suggested_info_'.$i} =~ s/(`)/'/g;
15930: $newltisec{'suggested'}{$itemid}{'name'} = $env{'form.linkprot_suggested_name_'.$i};
15931: $newltisec{'suggested'}{$itemid}{'info'} = $env{'form.linkprot_suggested_info_'.$i};
15932: if (($currltisec{'suggested'}{$itemid}{'name'} ne $newltisec{'suggested'}{$itemid}{'name'}) ||
15933: ($currltisec{'suggested'}{$itemid}{'info'} ne $newltisec{'suggested'}{$itemid}{'info'})) {
15934: $secchanges{'suggested'}{$itemid} = 1;
15935: }
15936: }
15937: }
15938: }
15939: }
15940: }
15941: }
15942: foreach my $key (keys(%delsuggested)) {
15943: $newltisec{'suggested'}{$key} = $delsuggested{$key};
15944: $secchanges{'suggested'}{$key} = 1;
15945: }
15946: if (($env{'form.linkprot_suggested_add'}) &&
15947: ($env{'form.linkprot_suggested_name_add'} ne '')) {
15948: $env{'form.linkprot_suggested_name_add'} =~ s/(`)/'/g;
15949: $env{'form.linkprot_suggested_info_add'} =~ s/(`)/'/g;
15950: my ($newsuggid,$errormsg) = &get_lti_id($dom,$env{'form.linkprot_suggested_name_add'},'suggested');
15951: if ($newsuggid) {
15952: $newltisec{'suggested'}{$newsuggid}{'name'} = $env{'form.linkprot_suggested_name_add'};
15953: $newltisec{'suggested'}{$newsuggid}{'info'} = $env{'form.linkprot_suggested_info_add'};
15954: $secchanges{'suggested'}{$newsuggid} = 1;
15955: } else {
15956: my $error = &mt('Failed to acquire unique ID for new Link Protectors in Courses Suggestion');
15957: if ($errormsg) {
15958: $error .= ' ('.$errormsg.')';
15959: }
15960: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15961: }
15962: }
1.320 raeburn 15963: my (@items,%deletions,%itemids);
15964: if ($env{'form.lti_add'}) {
15965: my $consumer = $env{'form.lti_consumer_add'};
15966: $consumer =~ s/(`)/'/g;
1.434 raeburn 15967: ($newid,my $errormsg) = &get_lti_id($dom,$consumer,'lti');
1.320 raeburn 15968: if ($newid) {
15969: $itemids{'add'} = $newid;
15970: push(@items,'add');
15971: $changes{$newid} = 1;
15972: } else {
15973: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
1.434 raeburn 15974: if ($errormsg) {
15975: $error .= ' ('.$errormsg.')';
15976: }
1.320 raeburn 15977: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15978: }
15979: }
15980: if (ref($domconfig{$action}) eq 'HASH') {
15981: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
15982: if (@todelete) {
15983: map { $deletions{$_} = 1; } @todelete;
15984: }
15985: my $maxnum = $env{'form.lti_maxnum'};
1.390 raeburn 15986: for (my $i=0; $i<$maxnum; $i++) {
1.320 raeburn 15987: my $itemid = $env{'form.lti_id_'.$i};
15988: $itemid =~ s/\D+//g;
15989: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
15990: if ($deletions{$itemid}) {
15991: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
15992: } else {
1.390 raeburn 15993: push(@items,$i);
15994: $itemids{$i} = $itemid;
1.320 raeburn 15995: }
15996: }
15997: }
15998: }
1.424 raeburn 15999: my (%keystore,$secstored);
16000: if ($is_home) {
16001: &store_security($dom,'lti',\%secchanges,\%newkeyset,\%keystore);
16002: }
16003:
16004: my ($cipher,$privnum);
16005: if ((@items > 0) && ($is_home)) {
16006: ($cipher,$privnum) = &get_priv_creds($dom,$home,$secchanges{'encrypt'},
16007: $newltisec{'encrypt'},$keystore{$home});
16008: }
1.320 raeburn 16009: foreach my $idx (@items) {
16010: my $itemid = $itemids{$idx};
16011: next unless ($itemid);
1.424 raeburn 16012: my %currlti;
16013: unless ($idx eq 'add') {
16014: if (ref($domconfig{$action}) eq 'HASH') {
16015: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
16016: %currlti = %{$domconfig{$action}{$itemid}};
16017: }
16018: }
16019: }
1.390 raeburn 16020: my $position = $env{'form.lti_pos_'.$itemid};
1.320 raeburn 16021: $position =~ s/\D+//g;
16022: if ($position ne '') {
16023: $allpos[$position] = $itemid;
16024: }
1.424 raeburn 16025: foreach my $item ('consumer','lifetime','requser','crsinc') {
1.320 raeburn 16026: my $formitem = 'form.lti_'.$item.'_'.$idx;
16027: $env{$formitem} =~ s/(`)/'/g;
16028: if ($item eq 'lifetime') {
16029: $env{$formitem} =~ s/[^\d.]//g;
16030: }
16031: if ($env{$formitem} ne '') {
1.424 raeburn 16032: $confhash{$itemid}{$item} = $env{$formitem};
16033: unless (($idx eq 'add') || ($changes{$itemid})) {
16034: if ($currlti{$item} ne $confhash{$itemid}{$item}) {
16035: $changes{$itemid} = 1;
1.320 raeburn 16036: }
16037: }
16038: }
16039: }
16040: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
16041: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
16042: }
1.345 raeburn 16043: if ($confhash{$itemid}{'requser'}) {
16044: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
1.405 raeburn 16045: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
1.345 raeburn 16046: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
16047: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
16048: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
16049: my $mapuser = $env{'form.lti_customuser_'.$idx};
16050: $mapuser =~ s/(`)/'/g;
1.405 raeburn 16051: $mapuser =~ s/^\s+|\s+$//g;
16052: $confhash{$itemid}{'mapuser'} = $mapuser;
1.345 raeburn 16053: }
16054: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
16055: my @makeuser;
16056: foreach my $ltirole (sort(@possmakeuser)) {
16057: if ($posslti{$ltirole}) {
16058: push(@makeuser,$ltirole);
16059: }
16060: }
16061: $confhash{$itemid}{'makeuser'} = \@makeuser;
16062: if (@makeuser) {
16063: my $lcauth = $env{'form.lti_lcauth_'.$idx};
16064: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
16065: $confhash{$itemid}{'lcauth'} = $lcauth;
16066: if ($lcauth ne 'internal') {
16067: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
16068: $lcauthparm =~ s/^(\s+|\s+)$//g;
16069: $lcauthparm =~ s/`//g;
16070: if ($lcauthparm ne '') {
16071: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
16072: }
16073: }
16074: } else {
16075: $confhash{$itemid}{'lcauth'} = 'lti';
16076: }
1.320 raeburn 16077: }
1.345 raeburn 16078: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
16079: if (@possinstdata) {
16080: foreach my $field (@possinstdata) {
16081: if (exists($fieldtitles{$field})) {
16082: push(@{$confhash{$itemid}{'instdata'}});
1.325 raeburn 16083: }
16084: }
16085: }
1.363 raeburn 16086: if ($env{'form.lti_callback_'.$idx}) {
16087: if ($env{'form.lti_callbackparam_'.$idx}) {
16088: my $callback = $env{'form.lti_callbackparam_'.$idx};
16089: $callback =~ s/^\s+|\s+$//g;
16090: $confhash{$itemid}{'callback'} = $callback;
16091: }
16092: }
1.391 raeburn 16093: foreach my $field ('topmenu','inlinemenu') {
1.345 raeburn 16094: if ($env{'form.lti_'.$field.'_'.$idx}) {
16095: $confhash{$itemid}{$field} = 1;
16096: }
1.320 raeburn 16097: }
1.345 raeburn 16098: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
16099: $confhash{$itemid}{lcmenu} = [];
16100: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
16101: foreach my $field (@possmenu) {
16102: if (exists($menutitles{$field})) {
16103: if ($field eq 'grades') {
16104: next unless ($env{'form.lti_inlinemenu_'.$idx});
16105: }
16106: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 16107: }
16108: }
16109: }
1.391 raeburn 16110: if ($confhash{$itemid}{'crsinc'}) {
16111: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
16112: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
16113: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
16114: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
16115: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
16116: $mapcrs =~ s/(`)/'/g;
16117: $mapcrs =~ s/^\s+|\s+$//g;
16118: $confhash{$itemid}{'mapcrs'} = $mapcrs;
16119: }
16120: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
16121: my @crstypes;
16122: foreach my $type (sort(@posstypes)) {
16123: if ($posscrstype{$type}) {
16124: push(@crstypes,$type);
16125: }
16126: }
16127: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
1.392 raeburn 16128: if ($env{'form.lti_storecrs_'.$idx}) {
16129: $confhash{$itemid}{'storecrs'} = 1;
16130: }
1.391 raeburn 16131: if ($env{'form.lti_makecrs_'.$idx}) {
16132: $confhash{$itemid}{'makecrs'} = 1;
16133: }
16134: foreach my $ltirole (@lticourseroles) {
16135: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
16136: if (grep(/^\Q$possrole\E$/,@courseroles)) {
16137: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
16138: }
16139: }
16140: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
16141: my @selfenroll;
16142: foreach my $type (sort(@possenroll)) {
16143: if ($posslticrs{$type}) {
16144: push(@selfenroll,$type);
16145: }
16146: }
16147: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
16148: if ($env{'form.lti_crssec_'.$idx}) {
16149: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
16150: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
16151: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
16152: my $section = $env{'form.lti_customsection_'.$idx};
16153: $section =~ s/(`)/'/g;
16154: $section =~ s/^\s+|\s+$//g;
16155: if ($section ne '') {
16156: $confhash{$itemid}{'section'} = $section;
16157: }
16158: }
16159: }
16160: foreach my $field ('passback','roster') {
16161: if ($env{'form.lti_'.$field.'_'.$idx}) {
16162: $confhash{$itemid}{$field} = 1;
16163: }
16164: }
16165: if ($env{'form.lti_passback_'.$idx}) {
16166: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
16167: $confhash{$itemid}{'passbackformat'} = '1.0';
16168: } else {
16169: $confhash{$itemid}{'passbackformat'} = '1.1';
1.337 raeburn 16170: }
16171: }
1.391 raeburn 16172: }
16173: unless (($idx eq 'add') || ($changes{$itemid})) {
16174: if ($confhash{$itemid}{'crsinc'}) {
1.392 raeburn 16175: foreach my $field ('mapcrs','storecrs','makecrs','section','passback','roster') {
1.424 raeburn 16176: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.320 raeburn 16177: $changes{$itemid} = 1;
16178: }
1.345 raeburn 16179: }
16180: unless ($changes{$itemid}) {
1.424 raeburn 16181: if ($currlti{'passback'} eq $confhash{$itemid}{'passback'}) {
16182: if ($currlti{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 16183: $changes{$itemid} = 1;
16184: }
16185: }
1.345 raeburn 16186: }
1.391 raeburn 16187: foreach my $field ('mapcrstype','selfenroll') {
16188: unless ($changes{$itemid}) {
1.424 raeburn 16189: if (ref($currlti{$field}) eq 'ARRAY') {
1.391 raeburn 16190: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424 raeburn 16191: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391 raeburn 16192: $confhash{$itemid}{$field});
16193: if (@diffs) {
16194: $changes{$itemid} = 1;
16195: }
1.424 raeburn 16196: } elsif (@{$currlti{$field}} > 0) {
1.391 raeburn 16197: $changes{$itemid} = 1;
16198: }
16199: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
16200: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 16201: $changes{$itemid} = 1;
16202: }
16203: }
1.391 raeburn 16204: }
16205: }
16206: unless ($changes{$itemid}) {
1.424 raeburn 16207: if (ref($currlti{'maproles'}) eq 'HASH') {
1.391 raeburn 16208: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
1.424 raeburn 16209: foreach my $ltirole (keys(%{$currlti{'maproles'}})) {
16210: if ($currlti{'maproles'}{$ltirole} ne
1.391 raeburn 16211: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.345 raeburn 16212: $changes{$itemid} = 1;
16213: last;
16214: }
16215: }
1.391 raeburn 16216: unless ($changes{$itemid}) {
16217: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
16218: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
1.424 raeburn 16219: $currlti{'maproles'}{$ltirole}) {
1.391 raeburn 16220: $changes{$itemid} = 1;
16221: last;
16222: }
16223: }
16224: }
1.424 raeburn 16225: } elsif (keys(%{$currlti{'maproles'}}) > 0) {
1.391 raeburn 16226: $changes{$itemid} = 1;
1.345 raeburn 16227: }
1.391 raeburn 16228: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16229: unless ($changes{$itemid}) {
16230: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
16231: $changes{$itemid} = 1;
16232: }
16233: }
16234: }
16235: }
16236: }
16237: unless ($changes{$itemid}) {
16238: foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
1.424 raeburn 16239: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.345 raeburn 16240: $changes{$itemid} = 1;
1.320 raeburn 16241: }
1.391 raeburn 16242: }
16243: unless ($changes{$itemid}) {
16244: foreach my $field ('makeuser','lcmenu') {
1.424 raeburn 16245: if (ref($currlti{$field}) eq 'ARRAY') {
1.391 raeburn 16246: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424 raeburn 16247: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391 raeburn 16248: $confhash{$itemid}{$field});
16249: if (@diffs) {
16250: $changes{$itemid} = 1;
16251: }
1.424 raeburn 16252: } elsif (@{$currlti{$field}} > 0) {
1.391 raeburn 16253: $changes{$itemid} = 1;
16254: }
16255: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
16256: if (@{$confhash{$itemid}{$field}} > 0) {
16257: $changes{$itemid} = 1;
16258: }
1.345 raeburn 16259: }
1.320 raeburn 16260: }
16261: }
16262: }
16263: }
16264: }
1.424 raeburn 16265: if ($is_home) {
16266: my $keyitem = 'form.lti_key_'.$idx;
16267: $env{$keyitem} =~ s/(`)/'/g;
16268: if ($env{$keyitem} ne '') {
16269: $ltienc{$itemid}{'key'} = $env{$keyitem};
16270: unless ($changes{$itemid}) {
16271: if ($currlti{'key'} ne $env{$keyitem}) {
16272: $changes{$itemid} = 1;
16273: }
16274: }
16275: }
16276: my $secretitem = 'form.lti_secret_'.$idx;
16277: $env{$secretitem} =~ s/(`)/'/g;
16278: if ($currlti{'usable'}) {
16279: if ($env{'form.lti_changesecret_'.$idx}) {
16280: if ($env{$secretitem} ne '') {
16281: if ($privnum && $cipher) {
16282: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
16283: $confhash{$itemid}{'cipher'} = $privnum;
16284: } else {
16285: $ltienc{$itemid}{'secret'} = $env{$secretitem};
16286: }
16287: $changes{$itemid} = 1;
16288: }
16289: } else {
16290: $ltienc{$itemid}{'secret'} = $currlti{'secret'};
16291: $confhash{$itemid}{'cipher'} = $currlti{'cipher'};
16292: }
16293: if (ref($ltienc{$itemid}) eq 'HASH') {
16294: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'secret'} ne '')) {
16295: $confhash{$itemid}{'usable'} = 1;
16296: }
16297: }
16298: } elsif ($env{$secretitem} ne '') {
16299: if ($privnum && $cipher) {
16300: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
16301: $confhash{$itemid}{'cipher'} = $privnum;
16302: } else {
16303: $ltienc{$itemid}{'secret'} = $env{$secretitem};
16304: }
16305: if (ref($ltienc{$itemid}) eq 'HASH') {
16306: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'key'} ne '')) {
16307: $confhash{$itemid}{'usable'} = 1;
16308: }
16309: }
16310: $changes{$itemid} = 1;
16311: }
16312: }
16313: unless ($changes{$itemid}) {
16314: foreach my $key (keys(%currlti)) {
16315: if (ref($currlti{$key}) eq 'HASH') {
16316: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
16317: foreach my $innerkey (keys(%{$currlti{$key}})) {
16318: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
16319: $changes{$itemid} = 1;
16320: last;
16321: }
16322: }
16323: } elsif (keys(%{$currlti{$key}}) > 0) {
16324: $changes{$itemid} = 1;
16325: }
16326: }
16327: last if ($changes{$itemid});
16328: }
16329: }
1.320 raeburn 16330: }
16331: if (@allpos > 0) {
16332: my $idx = 0;
16333: foreach my $itemid (@allpos) {
16334: if ($itemid ne '') {
16335: $confhash{$itemid}{'order'} = $idx;
16336: if (ref($domconfig{$action}) eq 'HASH') {
16337: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
16338: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
16339: $changes{$itemid} = 1;
16340: }
16341: }
16342: }
16343: $idx ++;
16344: }
16345: }
16346: }
1.424 raeburn 16347:
16348: if ((keys(%changes) == 0) && (keys(%secchanges) == 0)) {
16349: return &mt('No changes made.');
16350: }
16351:
1.320 raeburn 16352: my %ltihash = (
1.405 raeburn 16353: $action => { %confhash }
16354: );
1.424 raeburn 16355: my %ltienchash;
16356:
16357: if ($is_home) {
16358: %ltienchash = (
16359: $action => { %ltienc }
16360: );
16361: }
1.405 raeburn 16362: if (keys(%secchanges)) {
16363: $ltihash{'ltisec'} = \%newltisec;
1.406 raeburn 16364: if ($secchanges{'linkprot'}) {
16365: if ($is_home) {
16366: $ltienchash{'linkprot'} = \%newltienc;
16367: }
16368: }
1.405 raeburn 16369: }
16370: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,$dom);
1.320 raeburn 16371: if ($putresult eq 'ok') {
1.424 raeburn 16372: if (keys(%ltienchash)) {
16373: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.405 raeburn 16374: }
16375: $resulttext = &mt('Changes made:').'<ul>';
16376: if (keys(%secchanges) > 0) {
1.423 raeburn 16377: $resulttext .= <i_security_results($dom,'lti',\%secchanges,\%newltisec,\%newkeyset,\%keystore);
1.421 raeburn 16378: if (exists($secchanges{'linkprot'})) {
16379: $resulttext .= $linkprotoutput;
1.405 raeburn 16380: }
16381: }
1.320 raeburn 16382: if (keys(%changes) > 0) {
16383: my $cachetime = 24*60*60;
1.424 raeburn 16384: &Apache::lonnet::do_cache_new('lti',$dom,\%confhash,$cachetime);
1.320 raeburn 16385: if (ref($lastactref) eq 'HASH') {
16386: $lastactref->{'lti'} = 1;
16387: }
16388: my %bynum;
16389: foreach my $itemid (sort(keys(%changes))) {
1.424 raeburn 16390: if (ref($confhash{$itemid}) eq 'HASH') {
16391: my $position = $confhash{$itemid}{'order'};
16392: $bynum{$position} = $itemid;
16393: }
1.320 raeburn 16394: }
16395: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
16396: my $itemid = $bynum{$pos};
1.424 raeburn 16397: if (ref($confhash{$itemid}) eq 'HASH') {
1.390 raeburn 16398: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1.320 raeburn 16399: my $position = $pos + 1;
16400: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
16401: foreach my $item ('version','lifetime') {
16402: if ($confhash{$itemid}{$item} ne '') {
16403: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
16404: }
16405: }
1.424 raeburn 16406: if ($ltienc{$itemid}{'key'} ne '') {
16407: $resulttext .= '<li>'.$lt{'key'}.': '.$ltienc{$itemid}{'key'}.'</li>';
1.320 raeburn 16408: }
1.424 raeburn 16409: if ($ltienc{$itemid}{'secret'} ne '') {
16410: $resulttext .= '<li>'.$lt{'secret'}.': ['.&mt('not shown').']</li>';
1.320 raeburn 16411: }
1.345 raeburn 16412: if ($confhash{$itemid}{'requser'}) {
1.391 raeburn 16413: if ($confhash{$itemid}{'callback'}) {
16414: $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
16415: } else {
1.392 raeburn 16416: $resulttext .= '<li>'.&mt('Callback to logout LON-CAPA on log out from Consumer').'</li>';
1.391 raeburn 16417: }
1.345 raeburn 16418: if ($confhash{$itemid}{'mapuser'}) {
16419: my $shownmapuser;
16420: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
16421: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
16422: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
16423: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
16424: } else {
16425: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 16426: }
1.345 raeburn 16427: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 16428: }
1.345 raeburn 16429: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
16430: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
16431: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
16432: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
16433: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
16434: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
16435: } else {
16436: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
16437: $confhash{$itemid}{'lcauth'});
16438: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
16439: $resulttext .= '; '.&mt('a randomly generated password will be created');
16440: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
16441: if ($confhash{$itemid}{'lcauthparm'} ne '') {
16442: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
16443: }
16444: } else {
16445: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
16446: }
16447: }
16448: $resulttext .= '</li>';
16449: } else {
16450: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
16451: }
1.320 raeburn 16452: }
1.345 raeburn 16453: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
16454: if (@{$confhash{$itemid}{'instdata'}} > 0) {
16455: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
16456: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 16457: } else {
1.345 raeburn 16458: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325 raeburn 16459: }
1.320 raeburn 16460: }
1.391 raeburn 16461: foreach my $item ('topmenu','inlinemenu') {
1.345 raeburn 16462: $resulttext .= '<li>'.$lt{$item}.': ';
16463: if ($confhash{$itemid}{$item}) {
16464: $resulttext .= &mt('Yes');
16465: } else {
16466: $resulttext .= &mt('No');
1.337 raeburn 16467: }
1.345 raeburn 16468: $resulttext .= '</li>';
1.320 raeburn 16469: }
1.345 raeburn 16470: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16471: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16472: $resulttext .= '<li>'.&mt('Menu items:').' '.
1.391 raeburn 16473: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16474: } else {
16475: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16476: }
16477: }
16478: if ($confhash{$itemid}{'crsinc'}) {
16479: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16480: my $rolemaps;
16481: foreach my $role (@ltiroles) {
16482: if ($confhash{$itemid}{'maproles'}{$role}) {
16483: $rolemaps .= (' 'x2).$role.'='.
16484: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
16485: 'Course').',';
16486: }
16487: }
16488: if ($rolemaps) {
16489: $rolemaps =~ s/,$//;
16490: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
16491: }
16492: }
16493: if ($confhash{$itemid}{'mapcrs'}) {
16494: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
16495: }
16496: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
16497: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
16498: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
16499: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
16500: '</li>';
16501: } else {
16502: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
16503: }
16504: }
1.392 raeburn 16505: if ($confhash{$itemid}{'storecrs'}) {
16506: $resulttext .= '<li>'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.$confhash{$itemid}{'storecrs'}.'</li>';
16507: }
1.391 raeburn 16508: if ($confhash{$itemid}{'makecrs'}) {
16509: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
16510: } else {
16511: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
16512: }
16513: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
16514: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
16515: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
16516: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
16517: '</li>';
16518: } else {
16519: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
16520: }
16521: }
16522: if ($confhash{$itemid}{'section'}) {
16523: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
16524: $resulttext .= '<li>'.&mt('User section from standard field:').
16525: ' (course_section_sourcedid)'.'</li>';
16526: } else {
16527: $resulttext .= '<li>'.&mt('User section from:').' '.
16528: $confhash{$itemid}{'section'}.'</li>';
16529: }
1.345 raeburn 16530: } else {
1.391 raeburn 16531: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
16532: }
16533: foreach my $item ('passback','roster','topmenu','inlinemenu') {
16534: $resulttext .= '<li>'.$lt{$item}.': ';
16535: if ($confhash{$itemid}{$item}) {
16536: $resulttext .= &mt('Yes');
16537: if ($item eq 'passback') {
16538: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
16539: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
16540: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
16541: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
16542: }
16543: }
16544: } else {
16545: $resulttext .= &mt('No');
16546: }
16547: $resulttext .= '</li>';
16548: }
16549: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16550: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16551: $resulttext .= '<li>'.&mt('Menu items:').' '.
16552: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16553: } else {
16554: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16555: }
1.345 raeburn 16556: }
1.326 raeburn 16557: }
16558: }
1.320 raeburn 16559: $resulttext .= '</ul></li>';
16560: }
16561: }
1.424 raeburn 16562: if (keys(%deletions)) {
16563: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
16564: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
16565: }
16566: }
1.320 raeburn 16567: }
1.405 raeburn 16568: $resulttext .= '</ul>';
1.424 raeburn 16569: if (ref($lastactref) eq 'HASH') {
1.434 raeburn 16570: if (($secchanges{'encrypt'}) || ($secchanges{'private'}) || (exists($secchanges{'suggested'}))) {
16571: &Apache::lonnet::get_domain_defaults($dom,1);
1.424 raeburn 16572: $lastactref->{'domdefaults'} = 1;
16573: }
16574: }
1.320 raeburn 16575: } else {
16576: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
16577: }
16578: if ($errors) {
16579: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
16580: $errors.'</ul>';
16581: }
16582: return $resulttext;
16583: }
16584:
1.424 raeburn 16585: sub get_priv_creds {
16586: my ($dom,$home,$encchg,$encrypt,$storedsec) = @_;
16587: my ($needenc,$cipher,$privnum);
16588: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
16589: if (($encchg) && (ref($encrypt) eq 'HASH')) {
16590: $needenc = $encrypt->{'consumers'}
16591: } else {
16592: $needenc = $domdefs{'ltienc_consumers'};
16593: }
16594: if ($needenc) {
16595: if (($storedsec eq 'ok') || ((ref($domdefs{'ltiprivhosts'}) eq 'ARRAY') &&
16596: (grep(/^\Q$home\E$/,@{$domdefs{'ltiprivhosts'}})))) {
16597: my %privhash = &Apache::lonnet::restore_dom('lti','private',$dom,$home,1);
16598: my $privkey = $privhash{'key'};
16599: $privnum = $privhash{'version'};
16600: if (($privnum) && ($privkey ne '')) {
16601: $cipher = Crypt::CBC->new({'key' => $privkey,
16602: 'cipher' => 'DES'});
16603: }
16604: }
16605: }
16606: return ($cipher,$privnum);
16607: }
16608:
1.320 raeburn 16609: sub get_lti_id {
1.434 raeburn 16610: my ($domain,$consumer,$dbname) = @_;
16611: unless (($dbname eq 'lti') || ($dbname eq 'suggested')) {
16612: return ('','invalid db');
16613: }
16614: # get lock on db
1.320 raeburn 16615: my $lockhash = {
16616: lock => $env{'user.name'}.
16617: ':'.$env{'user.domain'},
16618: };
16619: my $tries = 0;
1.434 raeburn 16620: my $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1.320 raeburn 16621: my ($id,$error);
16622:
16623: while (($gotlock ne 'ok') && ($tries<10)) {
16624: $tries ++;
16625: sleep (0.1);
1.434 raeburn 16626: $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1.320 raeburn 16627: }
16628: if ($gotlock eq 'ok') {
1.434 raeburn 16629: my %currids = &Apache::lonnet::dump_dom($dbname,$domain);
1.320 raeburn 16630: if ($currids{'lock'}) {
16631: delete($currids{'lock'});
16632: if (keys(%currids)) {
16633: my @curr = sort { $a <=> $b } keys(%currids);
16634: if ($curr[-1] =~ /^\d+$/) {
16635: $id = 1 + $curr[-1];
16636: }
16637: } else {
16638: $id = 1;
16639: }
16640: if ($id) {
1.434 raeburn 16641: unless (&Apache::lonnet::newput_dom($dbname,{ $id => $consumer },$domain) eq 'ok') {
1.320 raeburn 16642: $error = 'nostore';
16643: }
16644: } else {
16645: $error = 'nonumber';
16646: }
16647: }
1.434 raeburn 16648: my $dellockoutcome = &Apache::lonnet::del_dom($dbname,['lock'],$domain);
1.320 raeburn 16649: } else {
16650: $error = 'nolock';
16651: }
16652: return ($id,$error);
16653: }
16654:
1.3 raeburn 16655: sub modify_autoenroll {
1.205 raeburn 16656: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 16657: my ($resulttext,%changes);
16658: my %currautoenroll;
16659: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
16660: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
16661: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
16662: }
16663: }
16664: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
16665: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 16666: sender => 'Sender for notification messages',
1.274 raeburn 16667: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.399 raeburn 16668: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 16669: my @offon = ('off','on');
1.17 raeburn 16670: my $sender_uname = $env{'form.sender_uname'};
16671: my $sender_domain = $env{'form.sender_domain'};
16672: if ($sender_domain eq '') {
16673: $sender_uname = '';
16674: } elsif ($sender_uname eq '') {
16675: $sender_domain = '';
16676: }
1.129 raeburn 16677: my $coowners = $env{'form.autoassign_coowners'};
1.399 raeburn 16678: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
16679: $autofailsafe =~ s{^\s+|\s+$}{}g;
16680: if ($autofailsafe =~ /\D/) {
16681: undef($autofailsafe);
16682: }
1.274 raeburn 16683: my $failsafe = $env{'form.autoenroll_failsafe'};
1.399 raeburn 16684: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
16685: $failsafe = 'off';
1.400 raeburn 16686: undef($autofailsafe);
1.274 raeburn 16687: }
1.1 raeburn 16688: my %autoenrollhash = (
1.129 raeburn 16689: autoenroll => { 'run' => $env{'form.autoenroll_run'},
16690: 'sender_uname' => $sender_uname,
16691: 'sender_domain' => $sender_domain,
16692: 'co-owners' => $coowners,
1.399 raeburn 16693: 'autofailsafe' => $autofailsafe,
1.400 raeburn 16694: 'failsafe' => $failsafe,
1.1 raeburn 16695: }
16696: );
1.4 raeburn 16697: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
16698: $dom);
1.1 raeburn 16699: if ($putresult eq 'ok') {
16700: if (exists($currautoenroll{'run'})) {
16701: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
16702: $changes{'run'} = 1;
16703: }
16704: } elsif ($autorun) {
16705: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 16706: $changes{'run'} = 1;
1.1 raeburn 16707: }
16708: }
1.17 raeburn 16709: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 16710: $changes{'sender'} = 1;
16711: }
1.17 raeburn 16712: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 16713: $changes{'sender'} = 1;
16714: }
1.129 raeburn 16715: if ($currautoenroll{'co-owners'} ne '') {
16716: if ($currautoenroll{'co-owners'} ne $coowners) {
16717: $changes{'coowners'} = 1;
16718: }
16719: } elsif ($coowners) {
16720: $changes{'coowners'} = 1;
1.274 raeburn 16721: }
1.399 raeburn 16722: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.274 raeburn 16723: $changes{'autofailsafe'} = 1;
16724: }
1.399 raeburn 16725: if ($currautoenroll{'failsafe'} ne $failsafe) {
16726: $changes{'failsafe'} = 1;
16727: }
1.1 raeburn 16728: if (keys(%changes) > 0) {
16729: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 16730: if ($changes{'run'}) {
1.1 raeburn 16731: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
16732: }
16733: if ($changes{'sender'}) {
1.17 raeburn 16734: if ($sender_uname eq '' || $sender_domain eq '') {
16735: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
16736: } else {
16737: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
16738: }
1.1 raeburn 16739: }
1.129 raeburn 16740: if ($changes{'coowners'}) {
16741: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
16742: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 16743: if (ref($lastactref) eq 'HASH') {
16744: $lastactref->{'domainconfig'} = 1;
16745: }
1.129 raeburn 16746: }
1.274 raeburn 16747: if ($changes{'autofailsafe'}) {
1.399 raeburn 16748: if ($autofailsafe ne '') {
16749: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.274 raeburn 16750: } else {
1.399 raeburn 16751: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.274 raeburn 16752: }
1.399 raeburn 16753: }
16754: if ($changes{'failsafe'}) {
16755: if ($failsafe eq 'off') {
16756: unless ($changes{'autofailsafe'}) {
16757: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
16758: }
16759: } elsif ($failsafe eq 'zero') {
16760: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
16761: } else {
16762: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
16763: }
16764: }
16765: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.274 raeburn 16766: &Apache::lonnet::get_domain_defaults($dom,1);
16767: if (ref($lastactref) eq 'HASH') {
16768: $lastactref->{'domdefaults'} = 1;
16769: }
16770: }
1.1 raeburn 16771: $resulttext .= '</ul>';
16772: } else {
16773: $resulttext = &mt('No changes made to auto-enrollment settings');
16774: }
16775: } else {
1.11 albertel 16776: $resulttext = '<span class="LC_error">'.
16777: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16778: }
1.3 raeburn 16779: return $resulttext;
1.1 raeburn 16780: }
16781:
16782: sub modify_autoupdate {
1.3 raeburn 16783: my ($dom,%domconfig) = @_;
1.1 raeburn 16784: my ($resulttext,%currautoupdate,%fields,%changes);
16785: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
16786: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
16787: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
16788: }
16789: }
16790: my @offon = ('off','on');
16791: my %title = &Apache::lonlocal::texthash (
1.385 raeburn 16792: run => 'Auto-update:',
16793: classlists => 'Updates to user information in classlists?',
16794: unexpired => 'Skip updates for users without active or future roles?',
16795: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 16796: );
1.44 raeburn 16797: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 16798: my %fieldtitles = &Apache::lonlocal::texthash (
16799: id => 'Student/Employee ID',
1.20 raeburn 16800: permanentemail => 'E-mail address',
1.1 raeburn 16801: lastname => 'Last Name',
16802: firstname => 'First Name',
16803: middlename => 'Middle Name',
1.132 raeburn 16804: generation => 'Generation',
1.1 raeburn 16805: );
1.142 raeburn 16806: $othertitle = &mt('All users');
1.1 raeburn 16807: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 16808: $othertitle = &mt('Other users');
1.1 raeburn 16809: }
16810: foreach my $key (keys(%env)) {
16811: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 16812: my ($usertype,$item) = ($1,$2);
16813: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
16814: if ($usertype eq 'default') {
16815: push(@{$fields{$1}},$2);
16816: } elsif (ref($types) eq 'ARRAY') {
16817: if (grep(/^\Q$usertype\E$/,@{$types})) {
16818: push(@{$fields{$1}},$2);
16819: }
16820: }
16821: }
1.1 raeburn 16822: }
16823: }
1.131 raeburn 16824: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
16825: @lockablenames = sort(@lockablenames);
16826: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
16827: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16828: if (@changed) {
16829: $changes{'lockablenames'} = 1;
16830: }
16831: } else {
16832: if (@lockablenames) {
16833: $changes{'lockablenames'} = 1;
16834: }
16835: }
1.1 raeburn 16836: my %updatehash = (
16837: autoupdate => { run => $env{'form.autoupdate_run'},
16838: classlists => $env{'form.classlists'},
1.385 raeburn 16839: unexpired => $env{'form.unexpired'},
1.1 raeburn 16840: fields => {%fields},
1.131 raeburn 16841: lockablenames => \@lockablenames,
1.1 raeburn 16842: }
16843: );
1.385 raeburn 16844: my $lastactivedays;
16845: if ($env{'form.lastactive'}) {
16846: $lastactivedays = $env{'form.lastactivedays'};
16847: $lastactivedays =~ s/^\s+|\s+$//g;
16848: unless ($lastactivedays =~ /^\d+$/) {
16849: undef($lastactivedays);
16850: $env{'form.lastactive'} = 0;
16851: }
16852: }
16853: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 16854: foreach my $key (keys(%currautoupdate)) {
1.385 raeburn 16855: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 16856: if (exists($updatehash{autoupdate}{$key})) {
16857: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
16858: $changes{$key} = 1;
16859: }
16860: }
16861: } elsif ($key eq 'fields') {
16862: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 16863: foreach my $item (@{$types},'default') {
1.1 raeburn 16864: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
16865: my $change = 0;
16866: foreach my $type (@{$currautoupdate{$key}{$item}}) {
16867: if (!exists($fields{$item})) {
16868: $change = 1;
1.132 raeburn 16869: last;
1.1 raeburn 16870: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 16871: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 16872: $change = 1;
1.132 raeburn 16873: last;
1.1 raeburn 16874: }
16875: }
16876: }
16877: if ($change) {
16878: push(@{$changes{$key}},$item);
16879: }
1.26 raeburn 16880: }
1.1 raeburn 16881: }
16882: }
1.131 raeburn 16883: } elsif ($key eq 'lockablenames') {
16884: if (ref($currautoupdate{$key}) eq 'ARRAY') {
16885: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16886: if (@changed) {
16887: $changes{'lockablenames'} = 1;
16888: }
16889: } else {
16890: if (@lockablenames) {
16891: $changes{'lockablenames'} = 1;
16892: }
16893: }
16894: }
16895: }
16896: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
16897: if (@lockablenames) {
16898: $changes{'lockablenames'} = 1;
1.1 raeburn 16899: }
16900: }
1.385 raeburn 16901: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
16902: if ($updatehash{'autoupdate'}{'unexpired'}) {
16903: $changes{'unexpired'} = 1;
16904: }
16905: }
16906: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
16907: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
16908: $changes{'lastactive'} = 1;
16909: }
16910: }
1.26 raeburn 16911: foreach my $item (@{$types},'default') {
16912: if (defined($fields{$item})) {
16913: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 16914: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
16915: my $change = 0;
16916: if (ref($fields{$item}) eq 'ARRAY') {
16917: foreach my $type (@{$fields{$item}}) {
16918: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
16919: $change = 1;
16920: last;
16921: }
16922: }
16923: }
16924: if ($change) {
16925: push(@{$changes{'fields'}},$item);
16926: }
16927: } else {
1.26 raeburn 16928: push(@{$changes{'fields'}},$item);
16929: }
16930: } else {
16931: push(@{$changes{'fields'}},$item);
1.1 raeburn 16932: }
16933: }
16934: }
16935: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
16936: $dom);
16937: if ($putresult eq 'ok') {
16938: if (keys(%changes) > 0) {
16939: $resulttext = &mt('Changes made:').'<ul>';
16940: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 16941: if ($key eq 'lockablenames') {
16942: $resulttext .= '<li>';
16943: if (@lockablenames) {
16944: $usertypes->{'default'} = $othertitle;
16945: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
16946: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
16947: } else {
16948: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
16949: }
16950: $resulttext .= '</li>';
16951: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 16952: foreach my $item (@{$changes{$key}}) {
16953: my @newvalues;
16954: foreach my $type (@{$fields{$item}}) {
16955: push(@newvalues,$fieldtitles{$type});
16956: }
1.3 raeburn 16957: my $newvaluestr;
16958: if (@newvalues > 0) {
16959: $newvaluestr = join(', ',@newvalues);
16960: } else {
16961: $newvaluestr = &mt('none');
1.6 raeburn 16962: }
1.1 raeburn 16963: if ($item eq 'default') {
1.26 raeburn 16964: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 16965: } else {
1.26 raeburn 16966: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 16967: }
16968: }
16969: } else {
16970: my $newvalue;
16971: if ($key eq 'run') {
16972: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.385 raeburn 16973: } elsif ($key eq 'lastactive') {
16974: $newvalue = $offon[$env{'form.lastactive'}];
16975: unless ($lastactivedays eq '') {
16976: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
16977: }
1.1 raeburn 16978: } else {
16979: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 16980: }
1.1 raeburn 16981: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
16982: }
16983: }
16984: $resulttext .= '</ul>';
16985: } else {
1.3 raeburn 16986: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 16987: }
16988: } else {
1.11 albertel 16989: $resulttext = '<span class="LC_error">'.
16990: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16991: }
1.3 raeburn 16992: return $resulttext;
1.1 raeburn 16993: }
16994:
1.125 raeburn 16995: sub modify_autocreate {
16996: my ($dom,%domconfig) = @_;
16997: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
16998: if (ref($domconfig{'autocreate'}) eq 'HASH') {
16999: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
17000: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
17001: }
17002: }
17003: my %title= ( xml => 'Auto-creation of courses in XML course description files',
17004: req => 'Auto-creation of validated requests for official courses',
17005: xmldc => 'Identity of course creator of courses from XML files',
17006: );
17007: my @types = ('xml','req');
17008: foreach my $item (@types) {
17009: $newvals{$item} = $env{'form.autocreate_'.$item};
17010: $newvals{$item} =~ s/\D//g;
17011: $newvals{$item} = 0 if ($newvals{$item} eq '');
17012: }
17013: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 17014: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 17015: unless (exists($domcoords{$newvals{'xmldc'}})) {
17016: $newvals{'xmldc'} = '';
17017: }
17018: %autocreatehash = (
17019: autocreate => { xml => $newvals{'xml'},
17020: req => $newvals{'req'},
17021: }
17022: );
17023: if ($newvals{'xmldc'} ne '') {
17024: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
17025: }
17026: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
17027: $dom);
17028: if ($putresult eq 'ok') {
17029: my @items = @types;
17030: if ($newvals{'xml'}) {
17031: push(@items,'xmldc');
17032: }
17033: foreach my $item (@items) {
17034: if (exists($currautocreate{$item})) {
17035: if ($currautocreate{$item} ne $newvals{$item}) {
17036: $changes{$item} = 1;
17037: }
17038: } elsif ($newvals{$item}) {
17039: $changes{$item} = 1;
17040: }
17041: }
17042: if (keys(%changes) > 0) {
17043: my @offon = ('off','on');
17044: $resulttext = &mt('Changes made:').'<ul>';
17045: foreach my $item (@types) {
17046: if ($changes{$item}) {
17047: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 17048: $resulttext .= '<li>'.
17049: &mt("$title{$item} set to [_1]$newtxt [_2]",
17050: '<b>','</b>').
17051: '</li>';
1.125 raeburn 17052: }
17053: }
17054: if ($changes{'xmldc'}) {
17055: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
17056: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 17057: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 17058: }
17059: $resulttext .= '</ul>';
17060: } else {
17061: $resulttext = &mt('No changes made to auto-creation settings');
17062: }
17063: } else {
17064: $resulttext = '<span class="LC_error">'.
17065: &mt('An error occurred: [_1]',$putresult).'</span>';
17066: }
17067: return $resulttext;
17068: }
17069:
1.23 raeburn 17070: sub modify_directorysrch {
1.295 raeburn 17071: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 17072: my ($resulttext,%changes);
17073: my %currdirsrch;
17074: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
17075: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
17076: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
17077: }
17078: }
1.277 raeburn 17079: my %title = ( available => 'Institutional directory search available',
17080: localonly => 'Other domains can search institution',
17081: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 17082: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 17083: searchby => 'Search types',
17084: searchtypes => 'Search latitude');
17085: my @offon = ('off','on');
1.24 raeburn 17086: my @otherdoms = ('Yes','No');
1.23 raeburn 17087:
1.25 raeburn 17088: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 17089: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
17090: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
17091:
1.44 raeburn 17092: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 17093: if (keys(%{$usertypes}) == 0) {
17094: @cansearch = ('default');
17095: } else {
17096: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
17097: foreach my $type (@{$currdirsrch{'cansearch'}}) {
17098: if (!grep(/^\Q$type\E$/,@cansearch)) {
17099: push(@{$changes{'cansearch'}},$type);
17100: }
1.23 raeburn 17101: }
1.26 raeburn 17102: foreach my $type (@cansearch) {
17103: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
17104: push(@{$changes{'cansearch'}},$type);
17105: }
1.23 raeburn 17106: }
1.26 raeburn 17107: } else {
17108: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 17109: }
17110: }
17111:
17112: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
17113: foreach my $by (@{$currdirsrch{'searchby'}}) {
17114: if (!grep(/^\Q$by\E$/,@searchby)) {
17115: push(@{$changes{'searchby'}},$by);
17116: }
17117: }
17118: foreach my $by (@searchby) {
17119: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
17120: push(@{$changes{'searchby'}},$by);
17121: }
17122: }
17123: } else {
17124: push(@{$changes{'searchby'}},@searchby);
17125: }
1.25 raeburn 17126:
17127: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
17128: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
17129: if (!grep(/^\Q$type\E$/,@searchtypes)) {
17130: push(@{$changes{'searchtypes'}},$type);
17131: }
17132: }
17133: foreach my $type (@searchtypes) {
17134: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
17135: push(@{$changes{'searchtypes'}},$type);
17136: }
17137: }
17138: } else {
17139: if (exists($currdirsrch{'searchtypes'})) {
17140: foreach my $type (@searchtypes) {
17141: if ($type ne $currdirsrch{'searchtypes'}) {
17142: push(@{$changes{'searchtypes'}},$type);
17143: }
17144: }
17145: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
17146: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
17147: }
17148: } else {
17149: push(@{$changes{'searchtypes'}},@searchtypes);
17150: }
17151: }
17152:
1.23 raeburn 17153: my %dirsrch_hash = (
17154: directorysrch => { available => $env{'form.dirsrch_available'},
17155: cansearch => \@cansearch,
1.277 raeburn 17156: localonly => $env{'form.dirsrch_instlocalonly'},
17157: lclocalonly => $env{'form.dirsrch_domlocalonly'},
17158: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 17159: searchby => \@searchby,
1.25 raeburn 17160: searchtypes => \@searchtypes,
1.23 raeburn 17161: }
17162: );
17163: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
17164: $dom);
17165: if ($putresult eq 'ok') {
17166: if (exists($currdirsrch{'available'})) {
17167: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
17168: $changes{'available'} = 1;
17169: }
17170: } else {
17171: if ($env{'form.dirsrch_available'} eq '1') {
17172: $changes{'available'} = 1;
17173: }
17174: }
1.277 raeburn 17175: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 17176: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
17177: $changes{'lcavailable'} = 1;
17178: }
1.277 raeburn 17179: } else {
17180: if ($env{'form.dirsrch_lcavailable'} eq '1') {
17181: $changes{'lcavailable'} = 1;
17182: }
17183: }
1.24 raeburn 17184: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 17185: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
17186: $changes{'localonly'} = 1;
17187: }
1.24 raeburn 17188: } else {
1.277 raeburn 17189: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 17190: $changes{'localonly'} = 1;
17191: }
17192: }
1.277 raeburn 17193: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 17194: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
17195: $changes{'lclocalonly'} = 1;
17196: }
1.277 raeburn 17197: } else {
17198: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
17199: $changes{'lclocalonly'} = 1;
17200: }
17201: }
1.23 raeburn 17202: if (keys(%changes) > 0) {
17203: $resulttext = &mt('Changes made:').'<ul>';
17204: if ($changes{'available'}) {
17205: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
17206: }
1.277 raeburn 17207: if ($changes{'lcavailable'}) {
17208: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
17209: }
1.24 raeburn 17210: if ($changes{'localonly'}) {
1.277 raeburn 17211: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 17212: }
1.277 raeburn 17213: if ($changes{'lclocalonly'}) {
17214: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 17215: }
1.23 raeburn 17216: if (ref($changes{'cansearch'}) eq 'ARRAY') {
17217: my $chgtext;
1.26 raeburn 17218: if (ref($usertypes) eq 'HASH') {
17219: if (keys(%{$usertypes}) > 0) {
17220: foreach my $type (@{$types}) {
17221: if (grep(/^\Q$type\E$/,@cansearch)) {
17222: $chgtext .= $usertypes->{$type}.'; ';
17223: }
17224: }
17225: if (grep(/^default$/,@cansearch)) {
17226: $chgtext .= $othertitle;
17227: } else {
17228: $chgtext =~ s/\; $//;
17229: }
1.210 raeburn 17230: $resulttext .=
1.178 raeburn 17231: '<li>'.
17232: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
17233: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
17234: '</li>';
1.23 raeburn 17235: }
17236: }
17237: }
17238: if (ref($changes{'searchby'}) eq 'ARRAY') {
17239: my ($searchtitles,$titleorder) = &sorted_searchtitles();
17240: my $chgtext;
17241: foreach my $type (@{$titleorder}) {
17242: if (grep(/^\Q$type\E$/,@searchby)) {
17243: if (defined($searchtitles->{$type})) {
17244: $chgtext .= $searchtitles->{$type}.'; ';
17245: }
17246: }
17247: }
17248: $chgtext =~ s/\; $//;
17249: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
17250: }
1.25 raeburn 17251: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
17252: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
17253: my $chgtext;
17254: foreach my $type (@{$srchtypeorder}) {
17255: if (grep(/^\Q$type\E$/,@searchtypes)) {
17256: if (defined($srchtypes_desc->{$type})) {
17257: $chgtext .= $srchtypes_desc->{$type}.'; ';
17258: }
17259: }
17260: }
17261: $chgtext =~ s/\; $//;
1.178 raeburn 17262: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 17263: }
17264: $resulttext .= '</ul>';
1.295 raeburn 17265: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
17266: if (ref($lastactref) eq 'HASH') {
17267: $lastactref->{'directorysrch'} = 1;
17268: }
1.23 raeburn 17269: } else {
1.277 raeburn 17270: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 17271: }
17272: } else {
17273: $resulttext = '<span class="LC_error">'.
1.27 raeburn 17274: &mt('An error occurred: [_1]',$putresult).'</span>';
17275: }
17276: return $resulttext;
17277: }
17278:
1.28 raeburn 17279: sub modify_contacts {
1.205 raeburn 17280: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 17281: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
17282: if (ref($domconfig{'contacts'}) eq 'HASH') {
17283: foreach my $key (keys(%{$domconfig{'contacts'}})) {
17284: $currsetting{$key} = $domconfig{'contacts'}{$key};
17285: }
17286: }
1.286 raeburn 17287: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 17288: my @contacts = ('supportemail','adminemail');
1.286 raeburn 17289: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350 raeburn 17290: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340 raeburn 17291: my @toggles = ('reporterrors','reportupdates','reportstatus');
17292: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 17293: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 17294: foreach my $type (@mailings) {
17295: @{$newsetting{$type}} =
17296: &Apache::loncommon::get_env_multiple('form.'.$type);
17297: foreach my $item (@contacts) {
17298: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
17299: $contacts_hash{contacts}{$type}{$item} = 1;
17300: } else {
17301: $contacts_hash{contacts}{$type}{$item} = 0;
17302: }
1.289 raeburn 17303: }
1.28 raeburn 17304: $others{$type} = $env{'form.'.$type.'_others'};
17305: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 17306: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17307: $bcc{$type} = $env{'form.'.$type.'_bcc'};
17308: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 17309: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
17310: $includestr{$type} = $env{'form.'.$type.'_includestr'};
17311: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
17312: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17313: }
1.134 raeburn 17314: }
1.28 raeburn 17315: }
17316: foreach my $item (@contacts) {
17317: $to{$item} = $env{'form.'.$item};
17318: $contacts_hash{'contacts'}{$item} = $to{$item};
17319: }
1.203 raeburn 17320: foreach my $item (@toggles) {
17321: if ($env{'form.'.$item} =~ /^(0|1)$/) {
17322: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
17323: }
17324: }
1.340 raeburn 17325: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
17326: foreach my $item (@lonstatus) {
17327: if ($item eq 'excluded') {
17328: my (%serverhomes,@excluded);
17329: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
17330: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
17331: if (@possexcluded) {
17332: foreach my $id (sort(@possexcluded)) {
17333: if ($serverhomes{$id}) {
17334: push(@excluded,$id);
17335: }
17336: }
17337: }
17338: if (@excluded) {
17339: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
17340: }
17341: } elsif ($item eq 'weights') {
1.377 raeburn 17342: foreach my $type ('E','W','N','U') {
1.340 raeburn 17343: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
17344: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
17345: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
17346: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
17347: $env{'form.error'.$item.'_'.$type};
17348: }
17349: }
17350: }
17351: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
17352: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
17353: if ($env{'form.error'.$item} =~ /^\d+$/) {
17354: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
17355: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
17356: }
17357: }
17358: }
17359: }
1.286 raeburn 17360: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
17361: foreach my $field (@{$fields}) {
17362: if (ref($possoptions->{$field}) eq 'ARRAY') {
17363: my $value = $env{'form.helpform_'.$field};
17364: $value =~ s/^\s+|\s+$//g;
17365: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 17366: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 17367: if ($field eq 'screenshot') {
17368: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
17369: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 17370: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 17371: }
17372: }
17373: }
17374: }
17375: }
17376: }
1.315 raeburn 17377: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17378: my (@statuses,%usertypeshash,@overrides);
17379: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
17380: @statuses = @{$types};
17381: if (ref($usertypes) eq 'HASH') {
17382: %usertypeshash = %{$usertypes};
17383: }
17384: }
17385: if (@statuses) {
17386: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
17387: foreach my $type (@possoverrides) {
17388: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
17389: push(@overrides,$type);
17390: }
17391: }
17392: if (@overrides) {
17393: foreach my $type (@overrides) {
17394: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
17395: foreach my $item (@contacts) {
17396: if (grep(/^\Q$item\E$/,@standard)) {
17397: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
17398: $newsetting{'override_'.$type}{$item} = 1;
17399: } else {
17400: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
17401: $newsetting{'override_'.$type}{$item} = 0;
17402: }
17403: }
17404: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
17405: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17406: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
17407: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17408: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
17409: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
17410: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
17411: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17412: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
17413: }
1.425 raeburn 17414: }
1.315 raeburn 17415: }
17416: }
1.28 raeburn 17417: if (keys(%currsetting) > 0) {
17418: foreach my $item (@contacts) {
17419: if ($to{$item} ne $currsetting{$item}) {
17420: $changes{$item} = 1;
17421: }
17422: }
17423: foreach my $type (@mailings) {
17424: foreach my $item (@contacts) {
17425: if (ref($currsetting{$type}) eq 'HASH') {
17426: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
17427: push(@{$changes{$type}},$item);
17428: }
17429: } else {
17430: push(@{$changes{$type}},@{$newsetting{$type}});
17431: }
17432: }
17433: if ($others{$type} ne $currsetting{$type}{'others'}) {
17434: push(@{$changes{$type}},'others');
17435: }
1.289 raeburn 17436: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17437: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
17438: push(@{$changes{$type}},'bcc');
17439: }
1.286 raeburn 17440: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
17441: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
17442: push(@{$changes{$type}},'include');
17443: }
17444: }
17445: }
17446: if (ref($fields) eq 'ARRAY') {
17447: if (ref($currsetting{'helpform'}) eq 'HASH') {
17448: foreach my $field (@{$fields}) {
17449: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
17450: push(@{$changes{'helpform'}},$field);
17451: }
17452: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17453: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
17454: push(@{$changes{'helpform'}},'maxsize');
17455: }
17456: }
17457: }
17458: } else {
17459: foreach my $field (@{$fields}) {
17460: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17461: push(@{$changes{'helpform'}},$field);
17462: }
17463: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17464: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17465: push(@{$changes{'helpform'}},'maxsize');
17466: }
17467: }
17468: }
1.134 raeburn 17469: }
1.28 raeburn 17470: }
1.315 raeburn 17471: if (@statuses) {
1.425 raeburn 17472: if (ref($currsetting{'overrides'}) eq 'HASH') {
1.315 raeburn 17473: foreach my $key (keys(%{$currsetting{'overrides'}})) {
17474: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
17475: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
17476: foreach my $item (@contacts,'bcc','others','include') {
1.425 raeburn 17477: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
1.315 raeburn 17478: push(@{$changes{'overrides'}},$key);
17479: last;
17480: }
17481: }
17482: } else {
17483: push(@{$changes{'overrides'}},$key);
17484: }
17485: }
17486: }
17487: foreach my $key (@overrides) {
17488: unless (exists($currsetting{'overrides'}{$key})) {
17489: push(@{$changes{'overrides'}},$key);
17490: }
17491: }
17492: } else {
17493: foreach my $key (@overrides) {
1.425 raeburn 17494: push(@{$changes{'overrides'}},$key);
1.315 raeburn 17495: }
17496: }
17497: }
1.340 raeburn 17498: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
17499: foreach my $key ('excluded','weights','threshold','sysmail') {
17500: if ($key eq 'excluded') {
17501: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17502: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
17503: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17504: (@{$currsetting{'lonstatus'}{$key}})) {
17505: my @diffs =
17506: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
17507: $currsetting{'lonstatus'}{$key});
17508: if (@diffs) {
17509: push(@{$changes{'lonstatus'}},$key);
17510: }
17511: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
17512: push(@{$changes{'lonstatus'}},$key);
17513: }
17514: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17515: (@{$currsetting{'lonstatus'}{$key}})) {
17516: push(@{$changes{'lonstatus'}},$key);
17517: }
17518: } elsif ($key eq 'weights') {
17519: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17520: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
17521: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17522: foreach my $type ('E','W','N','U') {
1.340 raeburn 17523: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
17524: $currsetting{'lonstatus'}{$key}{$type}) {
17525: push(@{$changes{'lonstatus'}},$key);
17526: last;
17527: }
17528: }
17529: } else {
1.341 raeburn 17530: foreach my $type ('E','W','N','U') {
1.340 raeburn 17531: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
17532: push(@{$changes{'lonstatus'}},$key);
17533: last;
17534: }
17535: }
17536: }
17537: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17538: foreach my $type ('E','W','N','U') {
1.340 raeburn 17539: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
17540: push(@{$changes{'lonstatus'}},$key);
17541: last;
17542: }
17543: }
17544: }
17545: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
17546: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17547: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17548: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
17549: push(@{$changes{'lonstatus'}},$key);
17550: }
17551: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
17552: push(@{$changes{'lonstatus'}},$key);
17553: }
17554: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17555: push(@{$changes{'lonstatus'}},$key);
17556: }
17557: }
17558: }
17559: } else {
17560: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17561: foreach my $key ('excluded','weights','threshold','sysmail') {
17562: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17563: push(@{$changes{'lonstatus'}},$key);
17564: }
17565: }
17566: }
17567: }
1.28 raeburn 17568: } else {
17569: my %default;
17570: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
17571: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
17572: $default{'errormail'} = 'adminemail';
17573: $default{'packagesmail'} = 'adminemail';
17574: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 17575: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 17576: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 17577: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 17578: $default{'updatesmail'} = 'adminemail';
1.350 raeburn 17579: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 17580: foreach my $item (@contacts) {
17581: if ($to{$item} ne $default{$item}) {
1.286 raeburn 17582: $changes{$item} = 1;
1.203 raeburn 17583: }
1.28 raeburn 17584: }
17585: foreach my $type (@mailings) {
17586: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
17587: push(@{$changes{$type}},@{$newsetting{$type}});
17588: }
17589: if ($others{$type} ne '') {
17590: push(@{$changes{$type}},'others');
1.134 raeburn 17591: }
1.286 raeburn 17592: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17593: if ($bcc{$type} ne '') {
17594: push(@{$changes{$type}},'bcc');
17595: }
1.286 raeburn 17596: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
17597: push(@{$changes{$type}},'include');
17598: }
1.134 raeburn 17599: }
1.28 raeburn 17600: }
1.286 raeburn 17601: if (ref($fields) eq 'ARRAY') {
17602: foreach my $field (@{$fields}) {
17603: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17604: push(@{$changes{'helpform'}},$field);
17605: }
17606: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17607: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17608: push(@{$changes{'helpform'}},'maxsize');
17609: }
17610: }
17611: }
1.289 raeburn 17612: }
1.340 raeburn 17613: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17614: foreach my $key ('excluded','weights','threshold','sysmail') {
17615: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17616: push(@{$changes{'lonstatus'}},$key);
17617: }
17618: }
17619: }
1.28 raeburn 17620: }
1.203 raeburn 17621: foreach my $item (@toggles) {
17622: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
17623: $changes{$item} = 1;
17624: } elsif ((!$env{'form.'.$item}) &&
17625: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
17626: $changes{$item} = 1;
17627: }
17628: }
1.28 raeburn 17629: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
17630: $dom);
17631: if ($putresult eq 'ok') {
17632: if (keys(%changes) > 0) {
1.205 raeburn 17633: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 17634: if (ref($lastactref) eq 'HASH') {
17635: $lastactref->{'domainconfig'} = 1;
17636: }
1.28 raeburn 17637: my ($titles,$short_titles) = &contact_titles();
17638: $resulttext = &mt('Changes made:').'<ul>';
17639: foreach my $item (@contacts) {
17640: if ($changes{$item}) {
17641: $resulttext .= '<li>'.$titles->{$item}.
17642: &mt(' set to: ').
17643: '<span class="LC_cusr_emph">'.
17644: $to{$item}.'</span></li>';
17645: }
17646: }
17647: foreach my $type (@mailings) {
17648: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 17649: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 17650: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 17651: } else {
17652: $resulttext .= '<li>'.$titles->{$type}.': ';
17653: }
1.28 raeburn 17654: my @text;
17655: foreach my $item (@{$newsetting{$type}}) {
17656: push(@text,$short_titles->{$item});
17657: }
17658: if ($others{$type} ne '') {
17659: push(@text,$others{$type});
17660: }
1.286 raeburn 17661: if (@text) {
17662: $resulttext .= '<span class="LC_cusr_emph">'.
17663: join(', ',@text).'</span>';
17664: }
17665: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17666: if ($bcc{$type} ne '') {
1.286 raeburn 17667: my $bcctext;
17668: if (@text) {
1.289 raeburn 17669: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 17670: } else {
17671: $bcctext = '(Bcc)';
17672: }
17673: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
17674: } elsif (!@text) {
17675: $resulttext .= &mt('No one');
1.425 raeburn 17676: }
1.289 raeburn 17677: if ($includestr{$type} ne '') {
1.286 raeburn 17678: if ($includeloc{$type} eq 'b') {
17679: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
17680: } elsif ($includeloc{$type} eq 's') {
17681: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
17682: }
1.134 raeburn 17683: }
1.286 raeburn 17684: } elsif (!@text) {
17685: $resulttext .= &mt('No recipients');
1.134 raeburn 17686: }
17687: $resulttext .= '</li>';
1.28 raeburn 17688: }
17689: }
1.315 raeburn 17690: if (ref($changes{'overrides'}) eq 'ARRAY') {
17691: my @deletions;
17692: foreach my $type (@{$changes{'overrides'}}) {
17693: if ($usertypeshash{$type}) {
17694: if (grep(/^\Q$type\E/,@overrides)) {
17695: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
17696: $usertypeshash{$type}).'<ul><li>';
17697: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
17698: my @text;
17699: foreach my $item (@contacts) {
1.425 raeburn 17700: if ($newsetting{'override_'.$type}{$item}) {
1.315 raeburn 17701: push(@text,$short_titles->{$item});
17702: }
17703: }
17704: if ($newsetting{'override_'.$type}{'others'} ne '') {
17705: push(@text,$newsetting{'override_'.$type}{'others'});
17706: }
1.425 raeburn 17707:
1.315 raeburn 17708: if (@text) {
17709: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
17710: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
17711: }
17712: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
17713: my $bcctext;
17714: if (@text) {
17715: $bcctext = ' '.&mt('with Bcc to');
17716: } else {
17717: $bcctext = '(Bcc)';
17718: }
17719: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
17720: } elsif (!@text) {
17721: $resulttext .= &mt('Helpdesk e-mail sent to no one');
17722: }
17723: $resulttext .= '</li>';
17724: if ($newsetting{'override_'.$type}{'include'} ne '') {
17725: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
17726: if ($loc eq 'b') {
17727: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
17728: } elsif ($loc eq 's') {
17729: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
17730: }
17731: }
17732: }
17733: $resulttext .= '</li></ul></li>';
17734: } else {
17735: push(@deletions,$usertypeshash{$type});
17736: }
17737: }
17738: }
17739: if (@deletions) {
17740: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
17741: join(', ',@deletions)).'</li>';
17742: }
17743: }
1.203 raeburn 17744: my @offon = ('off','on');
1.340 raeburn 17745: my $corelink = &core_link_msu();
1.203 raeburn 17746: if ($changes{'reporterrors'}) {
17747: $resulttext .= '<li>'.
17748: &mt('E-mail error reports to [_1] set to "'.
17749: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 17750: $corelink).
1.203 raeburn 17751: '</li>';
17752: }
17753: if ($changes{'reportupdates'}) {
17754: $resulttext .= '<li>'.
17755: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
17756: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 17757: $corelink).
1.203 raeburn 17758: '</li>';
17759: }
1.340 raeburn 17760: if ($changes{'reportstatus'}) {
17761: $resulttext .= '<li>'.
17762: &mt('E-mail status if errors above threshold to [_1] set to "'.
17763: $offon[$env{'form.reportstatus'}].'".',
17764: $corelink).
17765: '</li>';
17766: }
17767: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
17768: $resulttext .= '<li>'.
17769: &mt('Nightly status check e-mail settings').':<ul>';
17770: my (%defval,%use_def,%shown);
17771: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
17772: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
17773: $defval{'weights'} =
1.341 raeburn 17774: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 17775: $defval{'excluded'} = &mt('None');
17776: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
17777: foreach my $item ('threshold','sysmail','weights','excluded') {
17778: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
17779: if (($item eq 'threshold') || ($item eq 'sysmail')) {
17780: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
17781: } elsif ($item eq 'weights') {
17782: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 17783: foreach my $type ('E','W','N','U') {
1.340 raeburn 17784: $shown{$item} .= $lonstatus_names->{$type}.'=';
17785: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
17786: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
17787: } else {
17788: $shown{$item} .= $lonstatus_defs->{$type};
17789: }
17790: $shown{$item} .= ', ';
17791: }
17792: $shown{$item} =~ s/, $//;
17793: } else {
17794: $shown{$item} = $defval{$item};
17795: }
17796: } elsif ($item eq 'excluded') {
17797: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
17798: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
17799: } else {
17800: $shown{$item} = $defval{$item};
17801: }
17802: }
17803: } else {
17804: $shown{$item} = $defval{$item};
17805: }
17806: }
17807: } else {
17808: foreach my $item ('threshold','weights','excluded','sysmail') {
17809: $shown{$item} = $defval{$item};
17810: }
17811: }
17812: foreach my $item ('threshold','weights','excluded','sysmail') {
17813: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
17814: $shown{$item}).'</li>';
17815: }
17816: $resulttext .= '</ul></li>';
17817: }
1.286 raeburn 17818: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
17819: my (@optional,@required,@unused,$maxsizechg);
17820: foreach my $field (@{$changes{'helpform'}}) {
17821: if ($field eq 'maxsize') {
17822: $maxsizechg = 1;
17823: next;
17824: }
17825: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 17826: push(@optional,$field);
1.286 raeburn 17827: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
17828: push(@unused,$field);
17829: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 17830: push(@required,$field);
1.286 raeburn 17831: }
17832: }
17833: if (@optional) {
17834: $resulttext .= '<li>'.
17835: &mt('Help form fields changed to "Optional": [_1].',
17836: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
17837: '</li>';
17838: }
17839: if (@required) {
17840: $resulttext .= '<li>'.
17841: &mt('Help form fields changed to "Required": [_1].',
17842: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
17843: '</li>';
17844: }
17845: if (@unused) {
17846: $resulttext .= '<li>'.
17847: &mt('Help form fields changed to "Not shown": [_1].',
17848: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
17849: '</li>';
17850: }
17851: if ($maxsizechg) {
17852: $resulttext .= '<li>'.
17853: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
17854: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
17855: '</li>';
17856: }
17857: }
1.28 raeburn 17858: $resulttext .= '</ul>';
17859: } else {
1.288 raeburn 17860: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 17861: }
17862: } else {
17863: $resulttext = '<span class="LC_error">'.
17864: &mt('An error occurred: [_1].',$putresult).'</span>';
17865: }
17866: return $resulttext;
17867: }
17868:
1.357 raeburn 17869: sub modify_privacy {
1.427 raeburn 17870: my ($dom,$lastactref,%domconfig) = @_;
1.357 raeburn 17871: my ($resulttext,%current,%changes);
17872: if (ref($domconfig{'privacy'}) eq 'HASH') {
17873: %current = %{$domconfig{'privacy'}};
17874: }
17875: my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
17876: my @items = ('domain','author','course','community');
17877: my %names = &Apache::lonlocal::texthash (
17878: domain => 'Assigned domain role(s)',
17879: author => 'Assigned co-author role(s)',
17880: course => 'Assigned course role(s)',
1.416 raeburn 17881: community => 'Assigned community role(s)',
1.357 raeburn 17882: );
17883: my %roles = &Apache::lonlocal::texthash (
17884: domain => 'Domain role',
17885: author => 'Co-author role',
17886: course => 'Course role',
17887: community => 'Community role',
17888: );
17889: my %titles = &Apache::lonlocal::texthash (
17890: approval => 'Approval for role in different domain',
17891: othdom => 'User information available in other domain',
17892: priv => 'Information viewable by privileged user in same domain',
17893: unpriv => 'Information viewable by unprivileged user in same domain',
17894: instdom => 'Other domain shares institution/provider',
17895: extdom => 'Other domain has different institution/provider',
17896: none => 'Not allowed',
17897: user => 'User authorizes',
17898: domain => 'Domain Coordinator authorizes',
17899: auto => 'Unrestricted',
1.418 raeburn 17900: notify => 'Notify when role needs authorization',
1.357 raeburn 17901: );
17902: my %fieldnames = &Apache::lonlocal::texthash (
17903: id => 'Student/Employee ID',
17904: permanentemail => 'E-mail address',
17905: lastname => 'Last Name',
17906: firstname => 'First Name',
17907: middlename => 'Middle Name',
17908: generation => 'Generation',
17909: );
17910: my ($othertitle,$usertypes,$types) =
17911: &Apache::loncommon::sorted_inst_types($dom);
17912: my (%by_ip,%by_location,@intdoms,@instdoms);
17913: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
17914:
17915: my %privacyhash = (
17916: 'approval' => {
17917: instdom => {},
17918: extdom => {},
17919: },
17920: 'othdom' => {},
17921: 'priv' => {},
17922: 'unpriv' => {},
17923: );
17924: foreach my $item (@items) {
17925: if (@instdoms > 1) {
1.416 raeburn 17926: if ($env{'form.privacy_approval_instdom_'.$item} =~ /^(none|user|domain|auto)$/) {
1.357 raeburn 17927: $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
17928: }
17929: if (ref($current{'approval'}) eq 'HASH') {
17930: if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
17931: unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
17932: $changes{'approval'} = 1;
17933: }
17934: }
17935: } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
17936: $changes{'approval'} = 1;
17937: }
17938: }
17939: if (keys(%by_location) > 0) {
17940: if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
17941: $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
17942: }
17943: if (ref($current{'approval'}) eq 'HASH') {
17944: if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
17945: unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
17946: $changes{'approval'} = 1;
17947: }
17948: }
17949: } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
17950: $changes{'approval'} = 1;
17951: }
17952: }
17953: foreach my $status ('priv','unpriv') {
17954: my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
17955: my @newvalues;
17956: foreach my $field (@possibles) {
17957: if (grep(/^\Q$field\E$/,@fields)) {
17958: $privacyhash{$status}{$item}{$field} = 1;
17959: push(@newvalues,$field);
17960: }
17961: }
17962: @newvalues = sort(@newvalues);
17963: if (ref($current{$status}) eq 'HASH') {
17964: if (ref($current{$status}{$item}) eq 'HASH') {
17965: my @currvalues = sort(keys(%{$current{$status}{$item}}));
17966: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
17967: if (@diffs > 0) {
17968: $changes{$status} = 1;
17969: }
17970: }
17971: } else {
17972: my @stdfields;
17973: foreach my $field (@fields) {
17974: if ($field eq 'id') {
17975: next if ($status eq 'unpriv');
17976: next if (($status eq 'priv') && ($item eq 'community'));
17977: }
17978: push(@stdfields,$field);
17979: }
17980: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
17981: if (@diffs > 0) {
17982: $changes{$status} = 1;
17983: }
17984: }
17985: }
17986: }
17987: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
17988: my @statuses;
17989: if (ref($types) eq 'ARRAY') {
17990: @statuses = @{$types};
17991: }
17992: foreach my $type (@statuses,'default') {
17993: my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
17994: my @newvalues;
17995: foreach my $field (sort(@possfields)) {
17996: if (grep(/^\Q$field\E$/,@fields)) {
17997: $privacyhash{'othdom'}{$type}{$field} = 1;
17998: push(@newvalues,$field);
17999: }
18000: }
18001: @newvalues = sort(@newvalues);
18002: if (ref($current{'othdom'}) eq 'HASH') {
18003: if (ref($current{'othdom'}{$type}) eq 'HASH') {
18004: my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
18005: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
18006: if (@diffs > 0) {
18007: $changes{'othdom'} = 1;
18008: }
18009: }
18010: } else {
18011: my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
18012: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
18013: if (@diffs > 0) {
18014: $changes{'othdom'} = 1;
18015: }
18016: }
18017: }
1.417 raeburn 18018: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
18019: my %notify;
18020: foreach my $possdc (&Apache::loncommon::get_env_multiple('form.privacy_notify')) {
18021: if (exists($domcoords{$possdc})) {
18022: $notify{$possdc} = 1;
18023: }
18024: }
18025: my $notify = join(',',sort(keys(%notify)));
18026: if ($current{'notify'} ne $notify) {
18027: $changes{'notify'} = 1;
18028: }
18029: $privacyhash{'notify'} = $notify;
1.357 raeburn 18030: }
18031: my %confighash = (
18032: privacy => \%privacyhash,
18033: );
18034: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
18035: if ($putresult eq 'ok') {
18036: if (keys(%changes) > 0) {
18037: $resulttext = &mt('Changes made: ').'<ul>';
1.417 raeburn 18038: foreach my $key ('approval','notify','othdom','priv','unpriv') {
1.357 raeburn 18039: if ($changes{$key}) {
18040: $resulttext .= '<li>'.$titles{$key}.':<ul>';
18041: if ($key eq 'approval') {
18042: if (keys(%{$privacyhash{$key}{instdom}})) {
18043: $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
18044: foreach my $item (@items) {
18045: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
18046: }
18047: $resulttext .= '</ul></li>';
18048: }
18049: if (keys(%{$privacyhash{$key}{extdom}})) {
18050: $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
18051: foreach my $item (@items) {
18052: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
18053: }
18054: $resulttext .= '</ul></li>';
18055: }
1.417 raeburn 18056: } elsif ($key eq 'notify') {
18057: if ($privacyhash{$key}) {
18058: foreach my $dc (split(/,/,$privacyhash{$key})) {
18059: my ($dcname,$dcdom) = split(/:/,$dc);
18060: $resulttext .= '<li>'.&Apache::loncommon::plainname($dcname,$dcdom).'</li>';
18061: }
18062: } else {
18063: $resulttext .= '<li>'.&mt('No DCs to notify').'</li>';
18064: }
1.357 raeburn 18065: } elsif ($key eq 'othdom') {
18066: my @statuses;
18067: if (ref($types) eq 'ARRAY') {
18068: @statuses = @{$types};
18069: }
18070: if (ref($privacyhash{$key}) eq 'HASH') {
18071: foreach my $status (@statuses,'default') {
18072: if ($status eq 'default') {
18073: $resulttext .= '<li>'.$othertitle.': ';
18074: } elsif (ref($usertypes) eq 'HASH') {
18075: $resulttext .= '<li>'.$usertypes->{$status}.': ';
18076: } else {
18077: next;
18078: }
18079: if (ref($privacyhash{$key}{$status}) eq 'HASH') {
18080: if (keys(%{$privacyhash{$key}{$status}})) {
18081: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
18082: } else {
18083: $resulttext .= &mt('none');
18084: }
18085: }
18086: $resulttext .= '</li>';
18087: }
18088: }
18089: } else {
18090: foreach my $item (@items) {
18091: if (ref($privacyhash{$key}{$item}) eq 'HASH') {
18092: $resulttext .= '<li>'.$names{$item}.': ';
18093: if (keys(%{$privacyhash{$key}{$item}})) {
18094: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
18095: } else {
18096: $resulttext .= &mt('none');
18097: }
18098: $resulttext .= '</li>';
18099: }
18100: }
18101: }
18102: $resulttext .= '</ul></li>';
18103: }
18104: }
1.421 raeburn 18105: $resulttext .= '</ul>';
1.427 raeburn 18106: if ($changes{'approval'}) {
18107: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
18108: delete($domdefaults{'userapprovals'});
18109: if (ref($privacyhash{'approval'}) eq 'HASH') {
18110: foreach my $domtype ('instdom','extdom') {
18111: if (ref($privacyhash{'approval'}{$domtype}) eq 'HASH') {
18112: foreach my $roletype ('domain','author','course','community') {
18113: if ($privacyhash{'approval'}{$domtype}{$roletype} eq 'user') {
18114: $domdefaults{'userapprovals'} = 1;
18115: last;
18116: }
18117: }
18118: }
18119: last if ($domdefaults{'userapprovals'});
18120: }
18121: }
18122: my $cachetime = 24*60*60;
18123: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18124: if (ref($lastactref) eq 'HASH') {
18125: $lastactref->{'domdefaults'} = 1;
18126: }
18127: }
1.357 raeburn 18128: } else {
18129: $resulttext = &mt('No changes made to user information settings');
18130: }
18131: } else {
18132: $resulttext = '<span class="LC_error">'.
18133: &mt('An error occurred: [_1]',$putresult).'</span>';
18134: }
18135: return $resulttext;
18136: }
18137:
1.354 raeburn 18138: sub modify_passwords {
18139: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 raeburn 18140: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
18141: $updatedefaults,$updateconf);
1.354 raeburn 18142: my $customfn = 'resetpw.html';
18143: if (ref($domconfig{'passwords'}) eq 'HASH') {
18144: %current = %{$domconfig{'passwords'}};
18145: }
18146: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
18147: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
18148: if (ref($types) eq 'ARRAY') {
18149: @oktypes = @{$types};
18150: }
18151: push(@oktypes,'default');
18152:
18153: my %titles = &Apache::lonlocal::texthash (
18154: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
18155: intauth_check => 'Check bcrypt cost if authenticated',
18156: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
18157: permanent => 'Permanent e-mail address',
18158: critical => 'Critical notification address',
18159: notify => 'Notification address',
18160: min => 'Minimum password length',
18161: max => 'Maximum password length',
18162: chars => 'Required characters',
18163: expire => 'Password expiration (days)',
1.356 raeburn 18164: numsaved => 'Number of previous passwords to save',
1.354 raeburn 18165: reset => 'Resetting Forgotten Password',
18166: intauth => 'Encryption of Stored Passwords (Internal Auth)',
18167: rules => 'Rules for LON-CAPA Passwords',
18168: crsownerchg => 'Course Owner Changing Student Passwords',
18169: username => 'Username',
18170: email => 'E-mail address',
18171: );
18172:
18173: #
18174: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
18175: #
18176: my (%curr_defaults,%save_defaults);
18177: if (ref($domconfig{'defaults'}) eq 'HASH') {
18178: foreach my $key (keys(%{$domconfig{'defaults'}})) {
18179: if ($key =~ /^intauth_(cost|check|switch)$/) {
18180: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
18181: } else {
18182: $save_defaults{$key} = $domconfig{'defaults'}{$key};
18183: }
18184: }
18185: }
18186: my %staticdefaults = (
18187: 'resetlink' => 2,
18188: 'resetcase' => \@oktypes,
18189: 'resetprelink' => 'both',
18190: 'resetemail' => ['critical','notify','permanent'],
18191: 'intauth_cost' => 10,
18192: 'intauth_check' => 0,
18193: 'intauth_switch' => 0,
18194: );
1.365 raeburn 18195: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354 raeburn 18196: foreach my $type (@oktypes) {
18197: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
18198: }
18199: my $linklife = $env{'form.passwords_link'};
18200: $linklife =~ s/^\s+|\s+$//g;
18201: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
18202: $newvalues{'resetlink'} = $linklife;
18203: if ($current{'resetlink'}) {
18204: if ($current{'resetlink'} ne $linklife) {
18205: $changes{'reset'} = 1;
18206: }
1.368 raeburn 18207: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18208: if ($staticdefaults{'resetlink'} ne $linklife) {
18209: $changes{'reset'} = 1;
18210: }
18211: }
18212: } elsif ($current{'resetlink'}) {
18213: $changes{'reset'} = 1;
18214: }
18215: my @casesens;
18216: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
18217: foreach my $case (sort(@posscase)) {
18218: if (grep(/^\Q$case\E$/,@oktypes)) {
18219: push(@casesens,$case);
18220: }
18221: }
18222: $newvalues{'resetcase'} = \@casesens;
18223: if (ref($current{'resetcase'}) eq 'ARRAY') {
18224: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
18225: if (@diffs > 0) {
18226: $changes{'reset'} = 1;
18227: }
1.368 raeburn 18228: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18229: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
18230: if (@diffs > 0) {
18231: $changes{'reset'} = 1;
18232: }
18233: }
18234: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
18235: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
18236: if (exists($current{'resetprelink'})) {
18237: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
18238: $changes{'reset'} = 1;
18239: }
1.368 raeburn 18240: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18241: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
18242: $changes{'reset'} = 1;
18243: }
18244: }
18245: } elsif ($current{'resetprelink'}) {
18246: $changes{'reset'} = 1;
18247: }
18248: foreach my $type (@oktypes) {
18249: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
18250: my @postlink;
18251: foreach my $item (sort(@possplink)) {
18252: if ($item =~ /^(email|username)$/) {
18253: push(@postlink,$item);
18254: }
18255: }
18256: $newvalues{'resetpostlink'}{$type} = \@postlink;
18257: unless ($changes{'reset'}) {
18258: if (ref($current{'resetpostlink'}) eq 'HASH') {
18259: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
18260: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
18261: if (@diffs > 0) {
18262: $changes{'reset'} = 1;
18263: }
18264: } else {
18265: $changes{'reset'} = 1;
18266: }
1.368 raeburn 18267: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18268: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
18269: if (@diffs > 0) {
18270: $changes{'reset'} = 1;
18271: }
18272: }
18273: }
18274: }
18275: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
18276: my @resetemail;
18277: foreach my $item (sort(@possemailsrc)) {
18278: if ($item =~ /^(permanent|critical|notify)$/) {
18279: push(@resetemail,$item);
18280: }
18281: }
18282: $newvalues{'resetemail'} = \@resetemail;
18283: unless ($changes{'reset'}) {
18284: if (ref($current{'resetemail'}) eq 'ARRAY') {
18285: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
18286: if (@diffs > 0) {
18287: $changes{'reset'} = 1;
18288: }
1.368 raeburn 18289: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18290: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
18291: if (@diffs > 0) {
18292: $changes{'reset'} = 1;
18293: }
18294: }
18295: }
18296: if ($env{'form.passwords_stdtext'} == 0) {
18297: $newvalues{'resetremove'} = 1;
18298: unless ($current{'resetremove'}) {
18299: $changes{'reset'} = 1;
18300: }
18301: } elsif ($current{'resetremove'}) {
18302: $changes{'reset'} = 1;
18303: }
18304: if ($env{'form.passwords_customfile.filename'} ne '') {
18305: my $servadm = $r->dir_config('lonAdmEMail');
18306: my ($configuserok,$author_ok,$switchserver) =
18307: &config_check($dom,$confname,$servadm);
18308: my $error;
18309: if ($configuserok eq 'ok') {
18310: if ($switchserver) {
18311: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
18312: } else {
18313: if ($author_ok eq 'ok') {
1.421 raeburn 18314: my $modified = [];
1.354 raeburn 18315: my ($result,$customurl) =
1.421 raeburn 18316: &Apache::lonconfigsettings::publishlogo($r,'upload','passwords_customfile',$dom,
18317: $confname,'customtext/resetpw','','',$customfn,
18318: $modified);
1.354 raeburn 18319: if ($result eq 'ok') {
18320: $newvalues{'resetcustom'} = $customurl;
18321: $changes{'reset'} = 1;
1.421 raeburn 18322: &update_modify_urls($r,$modified);
1.354 raeburn 18323: } else {
18324: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
18325: }
18326: } else {
18327: $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);
18328: }
18329: }
18330: } else {
18331: $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);
18332: }
18333: if ($error) {
18334: &Apache::lonnet::logthis($error);
18335: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
18336: }
18337: } elsif ($current{'resetcustom'}) {
18338: if ($env{'form.passwords_custom_del'}) {
18339: $changes{'reset'} = 1;
18340: } else {
18341: $newvalues{'resetcustom'} = $current{'resetcustom'};
18342: }
18343: }
18344: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
18345: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
18346: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
18347: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
18348: $changes{'intauth'} = 1;
18349: }
18350: } else {
18351: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
18352: }
18353: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
18354: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
18355: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
18356: $changes{'intauth'} = 1;
18357: }
18358: } else {
18359: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18360: }
18361: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
18362: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
18363: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
18364: $changes{'intauth'} = 1;
18365: }
18366: } else {
18367: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18368: }
18369: foreach my $item ('cost','check','switch') {
18370: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
18371: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
18372: $updatedefaults = 1;
18373: }
18374: }
1.405 raeburn 18375: &password_rule_changes('passwords',\%newvalues,\%current,\%changes);
1.359 raeburn 18376: my %crsownerchg = (
18377: by => [],
18378: for => [],
18379: );
18380: foreach my $item ('by','for') {
18381: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
18382: foreach my $type (sort(@posstypes)) {
18383: if (grep(/^\Q$type\E$/,@oktypes)) {
18384: push(@{$crsownerchg{$item}},$type);
18385: }
18386: }
18387: }
18388: $newvalues{'crsownerchg'} = \%crsownerchg;
18389: if (ref($current{'crsownerchg'}) eq 'HASH') {
18390: foreach my $item ('by','for') {
18391: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
18392: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
18393: if (@diffs > 0) {
18394: $changes{'crsownerchg'} = 1;
18395: last;
18396: }
18397: }
18398: }
1.368 raeburn 18399: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359 raeburn 18400: foreach my $item ('by','for') {
18401: if (@{$crsownerchg{$item}} > 0) {
18402: $changes{'crsownerchg'} = 1;
18403: last;
18404: }
1.354 raeburn 18405: }
18406: }
18407:
18408: my %confighash = (
18409: defaults => \%save_defaults,
18410: passwords => \%newvalues,
18411: );
18412: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
18413:
18414: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
18415: if ($putresult eq 'ok') {
18416: if (keys(%changes) > 0) {
18417: $resulttext = &mt('Changes made: ').'<ul>';
18418: foreach my $key ('reset','intauth','rules','crsownerchg') {
18419: if ($changes{$key}) {
1.355 raeburn 18420: unless ($key eq 'intauth') {
18421: $updateconf = 1;
18422: }
1.354 raeburn 18423: $resulttext .= '<li>'.$titles{$key}.':<ul>';
18424: if ($key eq 'reset') {
18425: if ($confighash{'passwords'}{'captcha'} eq 'original') {
18426: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
18427: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
18428: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369 raeburn 18429: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
18430: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
18431: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
18432: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
18433: }
1.354 raeburn 18434: } else {
18435: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
18436: }
18437: if ($confighash{'passwords'}{'resetlink'}) {
18438: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
18439: } else {
18440: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
18441: &mt('Will default to 2 hours').'</li>';
18442: }
18443: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
18444: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
18445: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
18446: } else {
18447: my $casesens;
18448: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
18449: if ($type eq 'default') {
18450: $casesens .= $othertitle.', ';
18451: } elsif ($usertypes->{$type} ne '') {
18452: $casesens .= $usertypes->{$type}.', ';
18453: }
18454: }
18455: $casesens =~ s/\Q, \E$//;
18456: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
18457: }
18458: } else {
18459: $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>';
18460: }
18461: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
18462: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
18463: } else {
18464: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
18465: }
18466: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
18467: my $output;
18468: if (ref($types) eq 'ARRAY') {
18469: foreach my $type (@{$types}) {
18470: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
18471: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
18472: $output .= $usertypes->{$type}.' -- '.&mt('none');
18473: } else {
18474: $output .= $usertypes->{$type}.' -- '.
18475: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
18476: }
18477: }
18478: }
18479: }
18480: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
18481: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
18482: $output .= $othertitle.' -- '.&mt('none');
18483: } else {
18484: $output .= $othertitle.' -- '.
18485: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
18486: }
18487: }
18488: if ($output) {
18489: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
18490: } else {
18491: $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>';
18492: }
18493: } else {
18494: $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>';
18495: }
18496: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
18497: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
18498: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
18499: } else {
18500: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
18501: }
18502: } else {
1.379 raeburn 18503: $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 18504: }
18505: if ($confighash{'passwords'}{'resetremove'}) {
18506: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
18507: } else {
18508: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
18509: }
18510: if ($confighash{'passwords'}{'resetcustom'}) {
18511: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369 raeburn 18512: &mt('custom text'),600,500,undef,undef,
18513: undef,undef,'background-color:#ffffff');
18514: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354 raeburn 18515: } else {
18516: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
18517: }
18518: } elsif ($key eq 'intauth') {
18519: foreach my $item ('cost','switch','check') {
18520: my $value = $save_defaults{$key.'_'.$item};
18521: if ($item eq 'switch') {
18522: my %optiondesc = &Apache::lonlocal::texthash (
18523: 0 => 'No',
18524: 1 => 'Yes',
18525: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
18526: );
18527: if ($value =~ /^(0|1|2)$/) {
18528: $value = $optiondesc{$value};
18529: } else {
18530: $value = &mt('none -- defaults to No');
18531: }
18532: } elsif ($item eq 'check') {
18533: my %optiondesc = &Apache::lonlocal::texthash (
18534: 0 => 'No',
18535: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
18536: 2 => 'Yes, disallow login if stored cost is less than domain default',
18537: );
18538: if ($value =~ /^(0|1|2)$/) {
18539: $value = $optiondesc{$value};
18540: } else {
18541: $value = &mt('none -- defaults to No');
18542: }
18543: }
18544: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
18545: }
18546: } elsif ($key eq 'rules') {
1.356 raeburn 18547: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 18548: if ($confighash{'passwords'}{$rule} eq '') {
18549: if ($rule eq 'min') {
1.356 raeburn 18550: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365 raeburn 18551: ' '.&mt('Default of [_1] will be used',
18552: $Apache::lonnet::passwdmin).'</li>';
1.356 raeburn 18553: } else {
18554: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354 raeburn 18555: }
18556: } else {
18557: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
18558: }
18559: }
1.370 raeburn 18560: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
18561: if (@{$confighash{'passwords'}{'chars'}} > 0) {
18562: my %rulenames = &Apache::lonlocal::texthash(
18563: uc => 'At least one upper case letter',
18564: lc => 'At least one lower case letter',
18565: num => 'At least one number',
18566: spec => 'At least one non-alphanumeric',
18567: );
18568: my $needed = '<ul><li>'.
18569: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
1.425 raeburn 18570: '</li></ul>';
1.370 raeburn 18571: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
18572: } else {
18573: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18574: }
18575: } else {
18576: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18577: }
1.354 raeburn 18578: } elsif ($key eq 'crsownerchg') {
1.359 raeburn 18579: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
18580: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
18581: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
18582: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
18583: } else {
18584: my %crsownerstr;
18585: foreach my $item ('by','for') {
18586: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
18587: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
18588: if ($type eq 'default') {
18589: $crsownerstr{$item} .= $othertitle.', ';
18590: } elsif ($usertypes->{$type} ne '') {
18591: $crsownerstr{$item} .= $usertypes->{$type}.', ';
18592: }
18593: }
18594: $crsownerstr{$item} =~ s/\Q, \E$//;
18595: }
18596: }
18597: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
18598: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
18599: }
1.354 raeburn 18600: } else {
1.359 raeburn 18601: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354 raeburn 18602: }
18603: }
18604: $resulttext .= '</ul></li>';
18605: }
18606: }
18607: $resulttext .= '</ul>';
18608: } else {
18609: $resulttext = &mt('No changes made to password settings');
18610: }
1.355 raeburn 18611: my $cachetime = 24*60*60;
1.354 raeburn 18612: if ($updatedefaults) {
18613: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18614: if (ref($lastactref) eq 'HASH') {
18615: $lastactref->{'domdefaults'} = 1;
18616: }
18617: }
1.355 raeburn 18618: if ($updateconf) {
18619: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
18620: if (ref($lastactref) eq 'HASH') {
18621: $lastactref->{'passwdconf'} = 1;
18622: }
18623: }
1.354 raeburn 18624: } else {
18625: $resulttext = '<span class="LC_error">'.
18626: &mt('An error occurred: [_1]',$putresult).'</span>';
18627: }
18628: if ($errors) {
18629: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
18630: $errors.'</ul></p>';
18631: }
18632: return $resulttext;
18633: }
18634:
1.405 raeburn 18635: sub password_rule_changes {
18636: my ($prefix,$newvalues,$current,$changes) = @_;
18637: return unless ((ref($newvalues) eq 'HASH') &&
18638: (ref($current) eq 'HASH') &&
18639: (ref($changes) eq 'HASH'));
18640: my (@rules,%staticdefaults);
18641: if ($prefix eq 'passwords') {
18642: @rules = ('min','max','expire','numsaved');
1.421 raeburn 18643: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 18644: @rules = ('min','max');
18645: }
18646: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
18647: foreach my $rule (@rules) {
18648: $env{'form.'.$prefix.'_'.$rule} =~ s/^\s+|\s+$//g;
18649: my $ruleok;
18650: if ($rule eq 'expire') {
18651: if (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+(|\.\d*)$/) &&
18652: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18653: $ruleok = 1;
18654: }
18655: } elsif ($rule eq 'min') {
18656: if ($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) {
18657: if ($env{'form.'.$prefix.'_'.$rule} >= $staticdefaults{$rule}) {
18658: $ruleok = 1;
18659: }
18660: }
18661: } elsif (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) &&
18662: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18663: $ruleok = 1;
18664: }
18665: if ($ruleok) {
18666: $newvalues->{$rule} = $env{'form.'.$prefix.'_'.$rule};
18667: if (exists($current->{$rule})) {
18668: if ($newvalues->{$rule} ne $current->{$rule}) {
18669: $changes->{'rules'} = 1;
18670: }
18671: } elsif ($rule eq 'min') {
18672: if ($staticdefaults{$rule} ne $newvalues->{$rule}) {
18673: $changes->{'rules'} = 1;
18674: }
18675: } else {
18676: $changes->{'rules'} = 1;
18677: }
18678: } elsif (exists($current->{$rule})) {
18679: $changes->{'rules'} = 1;
18680: }
18681: }
18682: my @posschars = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_chars');
18683: my @chars;
18684: foreach my $item (sort(@posschars)) {
18685: if ($item =~ /^(uc|lc|num|spec)$/) {
18686: push(@chars,$item);
18687: }
18688: }
18689: $newvalues->{'chars'} = \@chars;
18690: unless ($changes->{'rules'}) {
18691: if (ref($current->{'chars'}) eq 'ARRAY') {
18692: my @diffs = &Apache::loncommon::compare_arrays($current->{'chars'},\@chars);
18693: if (@diffs > 0) {
18694: $changes->{'rules'} = 1;
18695: }
18696: } else {
18697: if (@chars > 0) {
18698: $changes->{'rules'} = 1;
18699: }
18700: }
18701: }
18702: return;
18703: }
18704:
1.28 raeburn 18705: sub modify_usercreation {
1.27 raeburn 18706: my ($dom,%domconfig) = @_;
1.224 raeburn 18707: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 18708: my $warningmsg;
1.27 raeburn 18709: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18710: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 18711: if ($key eq 'cancreate') {
18712: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18713: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 18714: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
18715: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18716: } else {
1.224 raeburn 18717: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18718: }
18719: }
18720: }
18721: } elsif ($key eq 'email_rule') {
18722: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18723: } else {
18724: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18725: }
1.27 raeburn 18726: }
18727: }
18728: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 18729: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 18730: my @contexts = ('author','course','requestcrs');
1.34 raeburn 18731: foreach my $item(@contexts) {
1.224 raeburn 18732: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 18733: }
1.34 raeburn 18734: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
18735: foreach my $item (@contexts) {
1.224 raeburn 18736: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
18737: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 18738: }
1.27 raeburn 18739: }
1.34 raeburn 18740: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
18741: foreach my $item (@contexts) {
1.43 raeburn 18742: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 18743: if ($cancreate{$item} ne 'any') {
18744: push(@{$changes{'cancreate'}},$item);
18745: }
18746: } else {
18747: if ($cancreate{$item} ne 'none') {
18748: push(@{$changes{'cancreate'}},$item);
18749: }
1.27 raeburn 18750: }
18751: }
18752: } else {
1.43 raeburn 18753: foreach my $item (@contexts) {
1.34 raeburn 18754: push(@{$changes{'cancreate'}},$item);
18755: }
1.27 raeburn 18756: }
1.34 raeburn 18757:
1.27 raeburn 18758: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
18759: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
18760: if (!grep(/^\Q$type\E$/,@username_rule)) {
18761: push(@{$changes{'username_rule'}},$type);
18762: }
18763: }
18764: foreach my $type (@username_rule) {
18765: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
18766: push(@{$changes{'username_rule'}},$type);
18767: }
18768: }
18769: } else {
18770: push(@{$changes{'username_rule'}},@username_rule);
18771: }
18772:
1.32 raeburn 18773: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
18774: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
18775: if (!grep(/^\Q$type\E$/,@id_rule)) {
18776: push(@{$changes{'id_rule'}},$type);
18777: }
18778: }
18779: foreach my $type (@id_rule) {
18780: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
18781: push(@{$changes{'id_rule'}},$type);
18782: }
18783: }
18784: } else {
18785: push(@{$changes{'id_rule'}},@id_rule);
18786: }
18787:
1.43 raeburn 18788: my @authen_contexts = ('author','course','domain');
1.325 raeburn 18789: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 18790: my %authhash;
1.43 raeburn 18791: foreach my $item (@authen_contexts) {
1.28 raeburn 18792: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
18793: foreach my $auth (@authtypes) {
18794: if (grep(/^\Q$auth\E$/,@authallowed)) {
18795: $authhash{$item}{$auth} = 1;
18796: } else {
18797: $authhash{$item}{$auth} = 0;
18798: }
18799: }
18800: }
18801: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 18802: foreach my $item (@authen_contexts) {
1.28 raeburn 18803: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
18804: foreach my $auth (@authtypes) {
18805: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
18806: push(@{$changes{'authtypes'}},$item);
18807: last;
18808: }
18809: }
18810: }
18811: }
18812: } else {
1.43 raeburn 18813: foreach my $item (@authen_contexts) {
1.28 raeburn 18814: push(@{$changes{'authtypes'}},$item);
18815: }
18816: }
18817:
1.224 raeburn 18818: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
18819: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
18820: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
18821: $save_usercreate{'id_rule'} = \@id_rule;
18822: $save_usercreate{'username_rule'} = \@username_rule,
18823: $save_usercreate{'authtypes'} = \%authhash;
18824:
1.27 raeburn 18825: my %usercreation_hash = (
1.224 raeburn 18826: usercreation => \%save_usercreate,
18827: );
1.27 raeburn 18828:
18829: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
18830: $dom);
1.50 raeburn 18831:
1.224 raeburn 18832: if ($putresult eq 'ok') {
18833: if (keys(%changes) > 0) {
18834: $resulttext = &mt('Changes made:').'<ul>';
18835: if (ref($changes{'cancreate'}) eq 'ARRAY') {
18836: my %lt = &usercreation_types();
18837: foreach my $type (@{$changes{'cancreate'}}) {
18838: my $chgtext = $lt{$type}.', ';
18839: if ($cancreate{$type} eq 'none') {
18840: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
18841: } elsif ($cancreate{$type} eq 'any') {
18842: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
18843: } elsif ($cancreate{$type} eq 'official') {
18844: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
18845: } elsif ($cancreate{$type} eq 'unofficial') {
18846: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
18847: }
18848: $resulttext .= '<li>'.$chgtext.'</li>';
18849: }
18850: }
18851: if (ref($changes{'username_rule'}) eq 'ARRAY') {
18852: my ($rules,$ruleorder) =
18853: &Apache::lonnet::inst_userrules($dom,'username');
18854: my $chgtext = '<ul>';
18855: foreach my $type (@username_rule) {
18856: if (ref($rules->{$type}) eq 'HASH') {
18857: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
18858: }
18859: }
18860: $chgtext .= '</ul>';
18861: if (@username_rule > 0) {
18862: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18863: } else {
18864: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
18865: }
18866: }
18867: if (ref($changes{'id_rule'}) eq 'ARRAY') {
18868: my ($idrules,$idruleorder) =
18869: &Apache::lonnet::inst_userrules($dom,'id');
18870: my $chgtext = '<ul>';
18871: foreach my $type (@id_rule) {
18872: if (ref($idrules->{$type}) eq 'HASH') {
18873: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
18874: }
18875: }
18876: $chgtext .= '</ul>';
18877: if (@id_rule > 0) {
18878: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18879: } else {
18880: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
18881: }
18882: }
18883: my %authname = &authtype_names();
18884: my %context_title = &context_names();
18885: if (ref($changes{'authtypes'}) eq 'ARRAY') {
18886: my $chgtext = '<ul>';
18887: foreach my $type (@{$changes{'authtypes'}}) {
18888: my @allowed;
18889: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
18890: foreach my $auth (@authtypes) {
18891: if ($authhash{$type}{$auth}) {
18892: push(@allowed,$authname{$auth});
18893: }
18894: }
18895: if (@allowed > 0) {
18896: $chgtext .= join(', ',@allowed).'</li>';
18897: } else {
18898: $chgtext .= &mt('none').'</li>';
18899: }
18900: }
18901: $chgtext .= '</ul>';
18902: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
18903: $resulttext .= '</li>';
18904: }
18905: $resulttext .= '</ul>';
18906: } else {
18907: $resulttext = &mt('No changes made to user creation settings');
18908: }
18909: } else {
18910: $resulttext = '<span class="LC_error">'.
18911: &mt('An error occurred: [_1]',$putresult).'</span>';
18912: }
18913: if ($warningmsg ne '') {
18914: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
18915: }
18916: return $resulttext;
18917: }
18918:
18919: sub modify_selfcreation {
1.305 raeburn 18920: my ($dom,$lastactref,%domconfig) = @_;
18921: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
18922: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
18923: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 18924: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
18925: if (ref($typesref) eq 'ARRAY') {
18926: @types = @{$typesref};
18927: }
18928: if (ref($usertypesref) eq 'HASH') {
18929: %usertypes = %{$usertypesref};
1.228 raeburn 18930: }
1.303 raeburn 18931: $usertypes{'default'} = $othertitle;
1.224 raeburn 18932: #
18933: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
18934: #
18935: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18936: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
18937: if ($key eq 'cancreate') {
18938: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18939: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
18940: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 18941: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
18942: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
18943: ($item eq 'emailusername') || ($item eq 'shibenv') ||
18944: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 18945: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 18946: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18947: } else {
18948: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18949: }
18950: }
18951: }
18952: } elsif ($key eq 'email_rule') {
18953: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18954: } else {
18955: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18956: }
18957: }
18958: }
18959: #
18960: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
18961: #
18962: if (ref($domconfig{'usermodification'}) eq 'HASH') {
18963: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
18964: if ($key eq 'selfcreate') {
18965: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
18966: } else {
18967: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
18968: }
18969: }
18970: }
1.305 raeburn 18971: #
18972: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
18973: #
18974: if (ref($domconfig{'inststatus'}) eq 'HASH') {
18975: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
18976: if ($key eq 'inststatusguest') {
18977: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
18978: } else {
18979: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
18980: }
18981: }
18982: }
1.224 raeburn 18983:
18984: my @contexts = ('selfcreate');
18985: @{$cancreate{'selfcreate'}} = ();
18986: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 18987: if (@types) {
18988: @{$cancreate{'statustocreate'}} = ();
18989: }
1.236 raeburn 18990: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 18991: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 18992: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 18993: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 18994: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 18995: my %selfcreatetypes = (
18996: sso => 'users authenticated by institutional single sign on',
18997: login => 'users authenticated by institutional log-in',
1.303 raeburn 18998: email => 'users verified by e-mail',
1.50 raeburn 18999: );
1.224 raeburn 19000: #
19001: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
19002: # is permitted.
19003: #
1.305 raeburn 19004: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 19005:
1.305 raeburn 19006: my (@statuses,%email_rule);
1.228 raeburn 19007: foreach my $item ('login','sso','email') {
1.224 raeburn 19008: if ($item eq 'email') {
1.236 raeburn 19009: if ($env{'form.cancreate_email'}) {
1.305 raeburn 19010: if (@types) {
19011: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
19012: foreach my $status (@poss_statuses) {
19013: if (grep(/^\Q$status\E$/,(@types,'default'))) {
19014: push(@statuses,$status);
19015: }
19016: }
19017: $save_inststatus{'inststatusguest'} = \@statuses;
19018: } else {
19019: push(@statuses,'default');
19020: }
19021: if (@statuses) {
19022: my %curr_rule;
19023: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
19024: foreach my $type (@statuses) {
19025: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 19026: }
1.305 raeburn 19027: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
19028: foreach my $type (@statuses) {
19029: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
19030: }
19031: }
19032: push(@{$cancreate{'selfcreate'}},'email');
19033: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
19034: my %curremaildom;
19035: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
19036: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
19037: }
19038: foreach my $type (@statuses) {
19039: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
19040: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
19041: }
19042: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
19043: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
19044: }
19045: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
19046: #
19047: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
19048: #
19049: my $chosen = $1;
19050: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
19051: my $emaildom;
19052: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
1.425 raeburn 19053: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
1.305 raeburn 19054: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
19055: if (ref($curremaildom{$type}) eq 'HASH') {
19056: if (exists($curremaildom{$type}{$chosen})) {
19057: if ($curremaildom{$type}{$chosen} ne $emaildom) {
19058: push(@{$changes{'cancreate'}},'emaildomain');
19059: }
19060: } elsif ($emaildom ne '') {
19061: push(@{$changes{'cancreate'}},'emaildomain');
19062: }
19063: } elsif ($emaildom ne '') {
19064: push(@{$changes{'cancreate'}},'emaildomain');
1.425 raeburn 19065: }
1.305 raeburn 19066: }
19067: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
19068: } elsif ($chosen eq 'custom') {
19069: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
19070: $email_rule{$type} = [];
19071: if (ref($emailrules) eq 'HASH') {
19072: foreach my $rule (@possemail_rules) {
19073: if (exists($emailrules->{$rule})) {
19074: push(@{$email_rule{$type}},$rule);
19075: }
19076: }
19077: }
19078: if (@{$email_rule{$type}}) {
19079: $cancreate{'emailoptions'}{$type} = 'custom';
19080: if (ref($curr_rule{$type}) eq 'ARRAY') {
19081: if (@{$curr_rule{$type}} > 0) {
19082: foreach my $rule (@{$curr_rule{$type}}) {
19083: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
19084: push(@{$changes{'email_rule'}},$type);
19085: }
19086: }
19087: }
19088: foreach my $type (@{$email_rule{$type}}) {
19089: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
19090: push(@{$changes{'email_rule'}},$type);
19091: }
19092: }
19093: } else {
19094: push(@{$changes{'email_rule'}},$type);
19095: }
19096: }
19097: } else {
19098: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
19099: }
19100: }
19101: }
19102: if (@types) {
19103: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19104: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
19105: if (@changed) {
19106: push(@{$changes{'inststatus'}},'inststatusguest');
19107: }
19108: } else {
19109: push(@{$changes{'inststatus'}},'inststatusguest');
19110: }
19111: }
19112: } else {
19113: delete($env{'form.cancreate_email'});
19114: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19115: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
19116: push(@{$changes{'inststatus'}},'inststatusguest');
19117: }
19118: }
19119: }
19120: } else {
19121: $save_inststatus{'inststatusguest'} = [];
19122: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19123: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
19124: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 19125: }
19126: }
1.224 raeburn 19127: }
19128: } else {
19129: if ($env{'form.cancreate_'.$item}) {
19130: push(@{$cancreate{'selfcreate'}},$item);
19131: }
19132: }
19133: }
1.305 raeburn 19134: my (%userinfo,%savecaptcha);
1.224 raeburn 19135: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
19136: #
1.228 raeburn 19137: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
19138: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 19139: #
1.236 raeburn 19140:
1.244 raeburn 19141: if ($env{'form.cancreate_email'}) {
1.228 raeburn 19142: push(@contexts,'emailusername');
1.305 raeburn 19143: if (@statuses) {
19144: foreach my $type (@statuses) {
1.228 raeburn 19145: if (ref($infofields) eq 'ARRAY') {
19146: foreach my $field (@{$infofields}) {
19147: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
19148: $cancreate{'emailusername'}{$type}{$field} = $1;
19149: }
19150: }
1.224 raeburn 19151: }
19152: }
19153: }
19154: #
19155: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 19156: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 19157: #
19158:
19159: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
19160: @approvalnotify = sort(@approvalnotify);
19161: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
19162: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
19163: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
19164: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
19165: push(@{$changes{'cancreate'}},'notify');
19166: }
19167: } else {
19168: if ($cancreate{'notify'}{'approval'}) {
19169: push(@{$changes{'cancreate'}},'notify');
19170: }
19171: }
19172: } elsif ($cancreate{'notify'}{'approval'}) {
19173: push(@{$changes{'cancreate'}},'notify');
19174: }
19175:
19176: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
19177: }
19178: #
1.236 raeburn 19179: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 19180: # institutional log-in.
19181: #
19182: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
19183: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
19184: ($domdefaults{'auth_def'} eq 'localauth'))) {
19185: $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.').' '.
19186: &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.');
19187: }
19188: }
19189: my @fields = ('lastname','firstname','middlename','generation',
19190: 'permanentemail','id');
1.240 raeburn 19191: my @shibfields = (@fields,'inststatus');
1.224 raeburn 19192: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19193: #
19194: # Where usernames may created for institutional log-in and/or institutional single sign on:
19195: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
19196: # may self-create accounts
19197: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
19198: # which the user may supply, if institutional data is unavailable.
19199: #
19200: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 19201: if (@types) {
1.305 raeburn 19202: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
19203: push(@contexts,'statustocreate');
1.303 raeburn 19204: foreach my $type (@types) {
1.224 raeburn 19205: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
19206: foreach my $field (@fields) {
19207: if (grep(/^\Q$field\E$/,@modifiable)) {
19208: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
19209: } else {
19210: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
19211: }
19212: }
19213: }
19214: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 19215: foreach my $type (@types) {
1.224 raeburn 19216: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
19217: foreach my $field (@fields) {
19218: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
19219: $curr_usermodify{'selfcreate'}{$type}{$field}) {
19220: push(@{$changes{'selfcreate'}},$type);
19221: last;
19222: }
19223: }
19224: }
19225: }
19226: } else {
1.303 raeburn 19227: foreach my $type (@types) {
1.224 raeburn 19228: push(@{$changes{'selfcreate'}},$type);
19229: }
19230: }
19231: }
1.240 raeburn 19232: foreach my $field (@shibfields) {
19233: if ($env{'form.shibenv_'.$field} ne '') {
19234: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
19235: }
19236: }
19237: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
19238: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
19239: foreach my $field (@shibfields) {
19240: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
19241: push(@{$changes{'cancreate'}},'shibenv');
19242: }
19243: }
19244: } else {
19245: foreach my $field (@shibfields) {
19246: if ($env{'form.shibenv_'.$field}) {
19247: push(@{$changes{'cancreate'}},'shibenv');
19248: last;
19249: }
19250: }
19251: }
19252: }
1.224 raeburn 19253: }
19254: foreach my $item (@contexts) {
19255: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
19256: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
19257: if (ref($cancreate{$item}) eq 'ARRAY') {
19258: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
19259: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19260: push(@{$changes{'cancreate'}},$item);
19261: }
19262: }
19263: }
19264: }
19265: if (ref($cancreate{$item}) eq 'ARRAY') {
19266: foreach my $type (@{$cancreate{$item}}) {
19267: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
19268: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19269: push(@{$changes{'cancreate'}},$item);
19270: }
19271: }
19272: }
19273: }
19274: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
19275: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 19276: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
19277: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19278: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
19279: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19280: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19281: push(@{$changes{'cancreate'}},$item);
19282: }
19283: }
19284: }
1.305 raeburn 19285: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19286: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19287: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19288: push(@{$changes{'cancreate'}},$item);
19289: }
1.224 raeburn 19290: }
19291: }
19292: }
1.305 raeburn 19293: foreach my $type (keys(%{$cancreate{$item}})) {
19294: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19295: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19296: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19297: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19298: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19299: push(@{$changes{'cancreate'}},$item);
19300: }
19301: }
19302: } else {
19303: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19304: push(@{$changes{'cancreate'}},$item);
19305: }
19306: }
19307: }
1.305 raeburn 19308: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19309: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19310: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19311: push(@{$changes{'cancreate'}},$item);
19312: }
1.224 raeburn 19313: }
19314: }
19315: }
19316: }
19317: } elsif ($curr_usercreation{'cancreate'}{$item}) {
19318: if (ref($cancreate{$item}) eq 'ARRAY') {
19319: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
19320: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19321: push(@{$changes{'cancreate'}},$item);
19322: }
19323: }
1.305 raeburn 19324: }
19325: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19326: if (ref($cancreate{$item}) eq 'HASH') {
19327: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19328: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 19329: }
19330: }
19331: } elsif ($item eq 'emailusername') {
1.228 raeburn 19332: if (ref($cancreate{$item}) eq 'HASH') {
19333: foreach my $type (keys(%{$cancreate{$item}})) {
19334: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19335: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19336: if ($cancreate{$item}{$type}{$field}) {
19337: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19338: push(@{$changes{'cancreate'}},$item);
19339: }
19340: last;
19341: }
19342: }
19343: }
19344: }
1.224 raeburn 19345: }
19346: }
19347: }
19348: #
19349: # Populate %save_usercreate hash with updates to self-creation configuration.
19350: #
19351: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
19352: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 19353: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 19354: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
19355: if (ref($cancreate{'notify'}) eq 'HASH') {
19356: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
19357: }
1.236 raeburn 19358: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
19359: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
19360: }
1.303 raeburn 19361: if (ref($cancreate{'emailverified'}) eq 'HASH') {
19362: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
19363: }
1.305 raeburn 19364: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
19365: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
19366: }
1.303 raeburn 19367: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
19368: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
19369: }
1.224 raeburn 19370: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19371: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
19372: }
1.240 raeburn 19373: if (ref($cancreate{'shibenv'}) eq 'HASH') {
19374: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
19375: }
1.224 raeburn 19376: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 19377: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 19378:
19379: my %userconfig_hash = (
19380: usercreation => \%save_usercreate,
19381: usermodification => \%save_usermodify,
1.305 raeburn 19382: inststatus => \%save_inststatus,
1.224 raeburn 19383: );
1.305 raeburn 19384:
1.224 raeburn 19385: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
19386: $dom);
19387: #
1.305 raeburn 19388: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 19389: #
1.27 raeburn 19390: if ($putresult eq 'ok') {
19391: if (keys(%changes) > 0) {
19392: $resulttext = &mt('Changes made:').'<ul>';
19393: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 19394: my %lt = &selfcreation_types();
1.34 raeburn 19395: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 19396: my $chgtext = '';
1.45 raeburn 19397: if ($type eq 'selfcreate') {
1.50 raeburn 19398: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 19399: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 19400: } else {
1.224 raeburn 19401: $chgtext .= &mt('Self-creation of a new account is permitted for:').
19402: '<ul>';
1.50 raeburn 19403: foreach my $case (@{$cancreate{$type}}) {
19404: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
19405: }
19406: $chgtext .= '</ul>';
1.100 raeburn 19407: if (ref($cancreate{$type}) eq 'ARRAY') {
19408: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
19409: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19410: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 19411: $chgtext .= '<span class="LC_warning">'.
19412: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
19413: '</span><br />';
19414: }
19415: }
19416: }
19417: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 19418: if (!@statuses) {
19419: $chgtext .= '<span class="LC_warning">'.
19420: &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.").
19421: '</span><br />';
1.303 raeburn 19422:
1.100 raeburn 19423: }
19424: }
19425: }
1.43 raeburn 19426: }
1.240 raeburn 19427: } elsif ($type eq 'shibenv') {
19428: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 19429: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 19430: } else {
19431: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
19432: '<ul>';
19433: foreach my $field (@shibfields) {
19434: next if ($cancreate{$type}{$field} eq '');
19435: if ($field eq 'inststatus') {
19436: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
19437: } else {
19438: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
19439: }
19440: }
19441: $chgtext .= '</ul>';
1.303 raeburn 19442: }
1.93 raeburn 19443: } elsif ($type eq 'statustocreate') {
1.96 raeburn 19444: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
19445: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
19446: if (@{$cancreate{'selfcreate'}} > 0) {
19447: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 19448: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 19449: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 19450: $chgtext .= '<br />'.
19451: '<span class="LC_warning">'.
19452: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
19453: '</span>';
19454: }
1.303 raeburn 19455: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 19456: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 19457: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
19458: } else {
19459: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
19460: }
19461: $chgtext .= '<ul>';
19462: foreach my $case (@{$cancreate{$type}}) {
19463: if ($case eq 'default') {
19464: $chgtext .= '<li>'.$othertitle.'</li>';
19465: } else {
1.303 raeburn 19466: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 19467: }
19468: }
1.100 raeburn 19469: $chgtext .= '</ul>';
19470: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 19471: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 19472: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
19473: '</span>';
1.100 raeburn 19474: }
19475: }
19476: } else {
19477: if (@{$cancreate{$type}} == 0) {
19478: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
19479: } else {
19480: $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 19481: }
19482: }
1.303 raeburn 19483: $chgtext .= '<br />';
1.93 raeburn 19484: }
1.236 raeburn 19485: } elsif ($type eq 'selfcreateprocessing') {
19486: my %choices = &Apache::lonlocal::texthash (
19487: automatic => 'Automatic approval',
19488: approval => 'Queued for approval',
19489: );
1.305 raeburn 19490: if (@types) {
19491: if (@statuses) {
1.425 raeburn 19492: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 19493: '<ul>';
1.305 raeburn 19494: foreach my $status (@statuses) {
19495: if ($status eq 'default') {
19496: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19497: } else {
1.305 raeburn 19498: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19499: }
19500: }
19501: $chgtext .= '</ul>';
19502: }
19503: } else {
19504: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
19505: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
19506: }
19507: } elsif ($type eq 'emailverified') {
19508: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 19509: all => 'Same as e-mail',
19510: first => 'Omit @domain',
19511: free => 'Free to choose',
1.303 raeburn 19512: );
1.305 raeburn 19513: if (@types) {
19514: if (@statuses) {
1.303 raeburn 19515: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
19516: '<ul>';
1.305 raeburn 19517: foreach my $status (@statuses) {
1.362 raeburn 19518: if ($status eq 'default') {
1.305 raeburn 19519: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19520: } else {
1.305 raeburn 19521: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19522: }
19523: }
19524: $chgtext .= '</ul>';
19525: }
19526: } else {
1.305 raeburn 19527: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 19528: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 19529: }
1.305 raeburn 19530: } elsif ($type eq 'emailoptions') {
19531: my %options = &Apache::lonlocal::texthash (
19532: any => 'Any e-mail',
19533: inst => 'Institutional only',
19534: noninst => 'Non-institutional only',
19535: custom => 'Custom restrictions',
19536: );
19537: if (@types) {
19538: if (@statuses) {
19539: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
19540: '<ul>';
19541: foreach my $status (@statuses) {
19542: if ($type eq 'default') {
19543: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
19544: } else {
19545: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 19546: }
19547: }
1.305 raeburn 19548: $chgtext .= '</ul>';
19549: }
19550: } else {
19551: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
19552: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
19553: } else {
19554: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
19555: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 19556: }
1.305 raeburn 19557: }
19558: } elsif ($type eq 'emaildomain') {
19559: my $output;
19560: if (@statuses) {
19561: foreach my $type (@statuses) {
19562: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
19563: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
19564: if ($type eq 'default') {
19565: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19566: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19567: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19568: } else {
19569: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
19570: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
19571: }
1.303 raeburn 19572: } else {
1.305 raeburn 19573: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19574: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19575: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19576: } else {
19577: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
1.421 raeburn 19578: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
1.305 raeburn 19579: }
1.303 raeburn 19580: }
1.305 raeburn 19581: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
19582: if ($type eq 'default') {
19583: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19584: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19585: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19586: } else {
19587: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
19588: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
19589: }
1.303 raeburn 19590: } else {
1.305 raeburn 19591: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19592: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19593: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19594: } else {
19595: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
1.421 raeburn 19596: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
1.305 raeburn 19597: }
1.303 raeburn 19598: }
19599: }
19600: }
19601: }
1.305 raeburn 19602: }
19603: if ($output ne '') {
19604: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
19605: '<ul>'.$output.'</ul>';
1.236 raeburn 19606: }
1.165 raeburn 19607: } elsif ($type eq 'captcha') {
1.224 raeburn 19608: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 19609: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
19610: } else {
19611: my %captchas = &captcha_phrases();
1.224 raeburn 19612: if ($captchas{$savecaptcha{$type}}) {
19613: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 19614: } else {
1.210 raeburn 19615: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 19616: }
19617: }
19618: } elsif ($type eq 'recaptchakeys') {
19619: my ($privkey,$pubkey);
1.224 raeburn 19620: if (ref($savecaptcha{$type}) eq 'HASH') {
19621: $pubkey = $savecaptcha{$type}{'public'};
19622: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 19623: }
19624: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
19625: if (!$pubkey) {
19626: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
19627: } else {
19628: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
19629: }
19630: if (!$privkey) {
19631: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
19632: } else {
19633: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
19634: }
19635: $chgtext .= '</ul>';
1.269 raeburn 19636: } elsif ($type eq 'recaptchaversion') {
19637: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 19638: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 19639: }
1.224 raeburn 19640: } elsif ($type eq 'emailusername') {
19641: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 19642: if (@statuses) {
19643: foreach my $type (@statuses) {
1.228 raeburn 19644: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
19645: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 19646: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 19647: '<ul>';
19648: foreach my $field (@{$infofields}) {
19649: if ($cancreate{'emailusername'}{$type}{$field}) {
19650: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
19651: }
19652: }
1.245 raeburn 19653: $chgtext .= '</ul>';
19654: } else {
1.303 raeburn 19655: $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 19656: }
19657: } else {
1.303 raeburn 19658: $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 19659: }
19660: }
19661: }
19662: }
19663: } elsif ($type eq 'notify') {
1.303 raeburn 19664: my $numapprove = 0;
1.224 raeburn 19665: if (ref($changes{'cancreate'}) eq 'ARRAY') {
19666: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
19667: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 19668: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
19669: $numapprove ++;
1.224 raeburn 19670: }
19671: }
1.43 raeburn 19672: }
1.303 raeburn 19673: unless ($numapprove) {
19674: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
19675: }
1.34 raeburn 19676: }
1.224 raeburn 19677: if ($chgtext) {
19678: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 19679: }
19680: }
19681: }
1.305 raeburn 19682: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 19683: my ($emailrules,$emailruleorder) =
19684: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 19685: foreach my $type (@{$changes{'email_rule'}}) {
19686: if (ref($email_rule{$type}) eq 'ARRAY') {
19687: my $chgtext = '<ul>';
19688: foreach my $rule (@{$email_rule{$type}}) {
19689: if (ref($emailrules->{$rule}) eq 'HASH') {
19690: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
19691: }
19692: }
19693: $chgtext .= '</ul>';
1.310 raeburn 19694: my $typename;
1.305 raeburn 19695: if (@types) {
19696: if ($type eq 'default') {
19697: $typename = $othertitle;
19698: } else {
19699: $typename = $usertypes{$type};
1.425 raeburn 19700: }
1.305 raeburn 19701: $chgtext .= &mt('(Affiliation: [_1])',$typename);
19702: }
19703: if (@{$email_rule{$type}} > 0) {
19704: $resulttext .= '<li>'.
19705: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
19706: $usertypes{$type}).
19707: $chgtext.
19708: '</li>';
19709: } else {
19710: $resulttext .= '<li>'.
1.310 raeburn 19711: &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 19712: '</li>'.
1.310 raeburn 19713: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 19714: }
1.43 raeburn 19715: }
19716: }
1.305 raeburn 19717: }
19718: if (ref($changes{'inststatus'}) eq 'ARRAY') {
19719: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
19720: if (@{$save_inststatus{'inststatusguest'}} > 0) {
19721: my $chgtext = '<ul>';
19722: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
19723: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
19724: }
19725: $chgtext .= '</ul>';
19726: $resulttext .= '<li>'.
19727: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
19728: $chgtext.
19729: '</li>';
19730: } else {
19731: $resulttext .= '<li>'.
19732: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
19733: '</li>';
19734: }
1.43 raeburn 19735: }
19736: }
1.224 raeburn 19737: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
19738: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
19739: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19740: foreach my $type (@{$changes{'selfcreate'}}) {
19741: my $typename = $type;
1.303 raeburn 19742: if (keys(%usertypes) > 0) {
19743: if ($usertypes{$type} ne '') {
19744: $typename = $usertypes{$type};
1.224 raeburn 19745: }
19746: }
19747: my @modifiable;
19748: $resulttext .= '<li>'.
19749: &mt('Self-creation of account by users with status: [_1]',
19750: '<span class="LC_cusr_emph">'.$typename.'</span>').
19751: ' - '.&mt('modifiable fields (if institutional data blank): ');
19752: foreach my $field (@fields) {
19753: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
19754: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 19755: }
19756: }
1.224 raeburn 19757: if (@modifiable > 0) {
19758: $resulttext .= join(', ',@modifiable);
1.43 raeburn 19759: } else {
1.224 raeburn 19760: $resulttext .= &mt('none');
1.43 raeburn 19761: }
1.224 raeburn 19762: $resulttext .= '</li>';
1.28 raeburn 19763: }
1.224 raeburn 19764: $resulttext .= '</ul></li>';
1.28 raeburn 19765: }
1.27 raeburn 19766: $resulttext .= '</ul>';
1.305 raeburn 19767: my $cachetime = 24*60*60;
19768: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
19769: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19770: if (ref($lastactref) eq 'HASH') {
19771: $lastactref->{'domdefaults'} = 1;
19772: }
1.27 raeburn 19773: } else {
1.224 raeburn 19774: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 19775: }
19776: } else {
19777: $resulttext = '<span class="LC_error">'.
1.23 raeburn 19778: &mt('An error occurred: [_1]',$putresult).'</span>';
19779: }
1.43 raeburn 19780: if ($warningmsg ne '') {
19781: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
19782: }
1.23 raeburn 19783: return $resulttext;
19784: }
19785:
1.165 raeburn 19786: sub process_captcha {
1.369 raeburn 19787: my ($container,$changes,$newsettings,$currsettings) = @_;
19788: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165 raeburn 19789: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
19790: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
19791: $newsettings->{'captcha'} = 'original';
19792: }
1.369 raeburn 19793: my %current;
19794: if (ref($currsettings) eq 'HASH') {
19795: %current = %{$currsettings};
19796: }
19797: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 19798: if ($container eq 'cancreate') {
1.169 raeburn 19799: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19800: push(@{$changes->{'cancreate'}},'captcha');
19801: } elsif (!defined($changes->{'cancreate'})) {
19802: $changes->{'cancreate'} = ['captcha'];
19803: }
1.368 raeburn 19804: } elsif ($container eq 'passwords') {
19805: $changes->{'reset'} = 1;
1.169 raeburn 19806: } else {
19807: $changes->{'captcha'} = 1;
1.165 raeburn 19808: }
19809: }
1.269 raeburn 19810: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 19811: if ($newsettings->{'captcha'} eq 'recaptcha') {
19812: $newpub = $env{'form.'.$container.'_recaptchapub'};
19813: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 19814: $newpub =~ s/[^\w\-]//g;
19815: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 19816: $newsettings->{'recaptchakeys'} = {
19817: public => $newpub,
19818: private => $newpriv,
19819: };
1.269 raeburn 19820: $newversion = $env{'form.'.$container.'_recaptchaversion'};
19821: $newversion =~ s/\D//g;
19822: if ($newversion ne '2') {
19823: $newversion = 1;
19824: }
19825: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 19826: }
1.369 raeburn 19827: if (ref($current{'recaptchakeys'}) eq 'HASH') {
19828: $currpub = $current{'recaptchakeys'}{'public'};
19829: $currpriv = $current{'recaptchakeys'}{'private'};
1.179 raeburn 19830: unless ($newsettings->{'captcha'} eq 'recaptcha') {
19831: $newsettings->{'recaptchakeys'} = {
19832: public => '',
19833: private => '',
19834: }
19835: }
1.165 raeburn 19836: }
1.369 raeburn 19837: if ($current{'captcha'} eq 'recaptcha') {
19838: $currversion = $current{'recaptchaversion'};
1.269 raeburn 19839: if ($currversion ne '2') {
19840: $currversion = 1;
19841: }
19842: }
19843: if ($currversion ne $newversion) {
19844: if ($container eq 'cancreate') {
19845: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19846: push(@{$changes->{'cancreate'}},'recaptchaversion');
19847: } elsif (!defined($changes->{'cancreate'})) {
19848: $changes->{'cancreate'} = ['recaptchaversion'];
19849: }
1.368 raeburn 19850: } elsif ($container eq 'passwords') {
19851: $changes->{'reset'} = 1;
1.269 raeburn 19852: } else {
19853: $changes->{'recaptchaversion'} = 1;
19854: }
19855: }
1.165 raeburn 19856: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 19857: if ($container eq 'cancreate') {
19858: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19859: push(@{$changes->{'cancreate'}},'recaptchakeys');
19860: } elsif (!defined($changes->{'cancreate'})) {
19861: $changes->{'cancreate'} = ['recaptchakeys'];
19862: }
1.368 raeburn 19863: } elsif ($container eq 'passwords') {
19864: $changes->{'reset'} = 1;
1.169 raeburn 19865: } else {
1.210 raeburn 19866: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 19867: }
19868: }
19869: return;
19870: }
19871:
1.33 raeburn 19872: sub modify_usermodification {
19873: my ($dom,%domconfig) = @_;
1.224 raeburn 19874: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 19875: if (ref($domconfig{'usermodification'}) eq 'HASH') {
19876: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 19877: if ($key eq 'selfcreate') {
19878: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
19879: } else {
19880: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
19881: }
1.33 raeburn 19882: }
19883: }
1.224 raeburn 19884: my @contexts = ('author','course');
1.33 raeburn 19885: my %context_title = (
19886: author => 'In author context',
19887: course => 'In course context',
19888: );
19889: my @fields = ('lastname','firstname','middlename','generation',
19890: 'permanentemail','id');
19891: my %roles = (
19892: author => ['ca','aa'],
19893: course => ['st','ep','ta','in','cr'],
19894: );
19895: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19896: foreach my $context (@contexts) {
19897: foreach my $role (@{$roles{$context}}) {
19898: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
19899: foreach my $item (@fields) {
19900: if (grep(/^\Q$item\E$/,@modifiable)) {
19901: $modifyhash{$context}{$role}{$item} = 1;
19902: } else {
19903: $modifyhash{$context}{$role}{$item} = 0;
19904: }
19905: }
19906: }
19907: if (ref($curr_usermodification{$context}) eq 'HASH') {
19908: foreach my $role (@{$roles{$context}}) {
19909: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
19910: foreach my $field (@fields) {
19911: if ($modifyhash{$context}{$role}{$field} ne
19912: $curr_usermodification{$context}{$role}{$field}) {
19913: push(@{$changes{$context}},$role);
19914: last;
19915: }
19916: }
19917: }
19918: }
19919: } else {
19920: foreach my $context (@contexts) {
19921: foreach my $role (@{$roles{$context}}) {
19922: push(@{$changes{$context}},$role);
19923: }
19924: }
19925: }
19926: }
19927: my %usermodification_hash = (
19928: usermodification => \%modifyhash,
19929: );
19930: my $putresult = &Apache::lonnet::put_dom('configuration',
19931: \%usermodification_hash,$dom);
19932: if ($putresult eq 'ok') {
19933: if (keys(%changes) > 0) {
19934: $resulttext = &mt('Changes made: ').'<ul>';
19935: foreach my $context (@contexts) {
19936: if (ref($changes{$context}) eq 'ARRAY') {
19937: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
19938: if (ref($changes{$context}) eq 'ARRAY') {
19939: foreach my $role (@{$changes{$context}}) {
19940: my $rolename;
1.224 raeburn 19941: if ($role eq 'cr') {
19942: $rolename = &mt('Custom');
1.33 raeburn 19943: } else {
1.224 raeburn 19944: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 19945: }
19946: my @modifiable;
1.224 raeburn 19947: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 19948: foreach my $field (@fields) {
19949: if ($modifyhash{$context}{$role}{$field}) {
19950: push(@modifiable,$fieldtitles{$field});
19951: }
19952: }
19953: if (@modifiable > 0) {
19954: $resulttext .= join(', ',@modifiable);
19955: } else {
19956: $resulttext .= &mt('none');
19957: }
19958: $resulttext .= '</li>';
19959: }
19960: $resulttext .= '</ul></li>';
19961: }
19962: }
19963: }
19964: $resulttext .= '</ul>';
19965: } else {
19966: $resulttext = &mt('No changes made to user modification settings');
19967: }
19968: } else {
19969: $resulttext = '<span class="LC_error">'.
19970: &mt('An error occurred: [_1]',$putresult).'</span>';
19971: }
19972: return $resulttext;
19973: }
19974:
1.43 raeburn 19975: sub modify_defaults {
1.212 raeburn 19976: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 19977: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 19978: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 19979: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 19980: 'portal_def');
1.325 raeburn 19981: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 19982: foreach my $item (@items) {
19983: $newvalues{$item} = $env{'form.'.$item};
19984: if ($item eq 'auth_def') {
19985: if ($newvalues{$item} ne '') {
19986: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
19987: push(@errors,$item);
19988: }
19989: }
19990: } elsif ($item eq 'lang_def') {
19991: if ($newvalues{$item} ne '') {
19992: if ($newvalues{$item} =~ /^(\w+)/) {
19993: my $langcode = $1;
1.103 raeburn 19994: if ($langcode ne 'x_chef') {
19995: if (code2language($langcode) eq '') {
19996: push(@errors,$item);
19997: }
1.43 raeburn 19998: }
19999: } else {
20000: push(@errors,$item);
20001: }
20002: }
1.54 raeburn 20003: } elsif ($item eq 'timezone_def') {
20004: if ($newvalues{$item} ne '') {
1.62 raeburn 20005: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 20006: push(@errors,$item);
20007: }
20008: }
1.68 raeburn 20009: } elsif ($item eq 'datelocale_def') {
20010: if ($newvalues{$item} ne '') {
20011: my @datelocale_ids = DateTime::Locale->ids();
20012: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
20013: push(@errors,$item);
20014: }
20015: }
1.141 raeburn 20016: } elsif ($item eq 'portal_def') {
20017: if ($newvalues{$item} ne '') {
1.414 raeburn 20018: 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])\/?$/) {
20019: foreach my $field ('email','web') {
20020: if ($env{'form.'.$item.'_'.$field}) {
20021: $newvalues{$item.'_'.$field} = $env{'form.'.$item.'_'.$field};
20022: }
20023: }
20024: } else {
1.141 raeburn 20025: push(@errors,$item);
20026: }
20027: }
1.43 raeburn 20028: }
20029: if (grep(/^\Q$item\E$/,@errors)) {
20030: $newvalues{$item} = $domdefaults{$item};
1.414 raeburn 20031: if ($item eq 'portal_def') {
20032: if ($domdefaults{$item}) {
20033: foreach my $field ('email','web') {
20034: if (exists($domdefaults{$item.'_'.$field})) {
20035: $newvalues{$item.'_'.$field} = $domdefaults{$item.'_'.$field};
20036: }
20037: }
20038: }
20039: }
1.43 raeburn 20040: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
20041: $changes{$item} = 1;
20042: }
1.414 raeburn 20043: if ($item eq 'portal_def') {
20044: unless (grep(/^\Q$item\E$/,@errors)) {
1.425 raeburn 20045: if ($newvalues{$item} eq '') {
1.414 raeburn 20046: foreach my $field ('email','web') {
20047: if (exists($domdefaults{$item.'_'.$field})) {
20048: delete($domdefaults{$item.'_'.$field});
20049: }
20050: }
20051: } else {
20052: unless ($changes{$item}) {
20053: foreach my $field ('email','web') {
20054: if ($domdefaults{$item.'_'.$field} ne $newvalues{$item.'_'.$field}) {
20055: $changes{$item} = 1;
20056: last;
20057: }
20058: }
20059: }
20060: foreach my $field ('email','web') {
20061: if ($newvalues{$item.'_'.$field}) {
20062: $domdefaults{$item.'_'.$field} = $newvalues{$item.'_'.$field};
20063: } elsif (exists($domdefaults{$item.'_'.$field})) {
20064: delete($domdefaults{$item.'_'.$field});
20065: }
20066: }
20067: }
20068: }
20069: }
1.72 raeburn 20070: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 20071: }
1.354 raeburn 20072: my %staticdefaults = (
20073: 'intauth_cost' => 10,
20074: 'intauth_check' => 0,
20075: 'intauth_switch' => 0,
20076: );
20077: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
20078: if (exists($domdefaults{$item})) {
20079: $newvalues{$item} = $domdefaults{$item};
20080: } else {
20081: $newvalues{$item} = $staticdefaults{$item};
20082: }
20083: }
1.409 raeburn 20084: my ($unamemaprules,$ruleorder);
20085: my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
20086: if (@possunamemaprules) {
20087: ($unamemaprules,$ruleorder) =
20088: &Apache::lonnet::inst_userrules($dom,'unamemap');
20089: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
20090: if (@{$ruleorder} > 0) {
20091: my %possrules;
20092: map { $possrules{$_} = 1; } @possunamemaprules;
20093: foreach my $rule (@{$ruleorder}) {
20094: if ($possrules{$rule}) {
20095: push(@{$newvalues{'unamemap_rule'}},$rule);
20096: }
20097: }
20098: }
20099: }
20100: }
20101: if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
20102: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20103: my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
20104: $newvalues{'unamemap_rule'});
20105: if (@rulediffs) {
20106: $changes{'unamemap_rule'} = 1;
20107: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
20108: }
20109: } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
20110: $changes{'unamemap_rule'} = 1;
20111: delete($domdefaults{'unamemap_rule'});
20112: }
20113: } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20114: if (@{$newvalues{'unamemap_rule'}} > 0) {
20115: $changes{'unamemap_rule'} = 1;
20116: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
20117: }
20118: }
1.43 raeburn 20119: my %defaults_hash = (
1.72 raeburn 20120: defaults => \%newvalues,
20121: );
1.43 raeburn 20122: my $title = &defaults_titles();
1.236 raeburn 20123:
20124: my $currinststatus;
20125: if (ref($domconfig{'inststatus'}) eq 'HASH') {
20126: $currinststatus = $domconfig{'inststatus'};
20127: } else {
20128: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
20129: $currinststatus = {
20130: inststatustypes => $usertypes,
20131: inststatusorder => $types,
20132: inststatusguest => [],
20133: };
20134: }
20135: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
20136: my @allpos;
20137: my %alltypes;
1.305 raeburn 20138: my @inststatusguest;
20139: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
20140: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
20141: unless (grep(/^\Q$type\E$/,@todelete)) {
20142: push(@inststatusguest,$type);
20143: }
20144: }
20145: }
20146: my ($currtitles,$currorder);
1.236 raeburn 20147: if (ref($currinststatus) eq 'HASH') {
20148: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
20149: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
20150: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
20151: if ($currinststatus->{inststatustypes}->{$type} ne '') {
20152: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
20153: }
20154: }
20155: unless (grep(/^\Q$type\E$/,@todelete)) {
20156: my $position = $env{'form.inststatus_pos_'.$type};
20157: $position =~ s/\D+//g;
20158: $allpos[$position] = $type;
20159: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
20160: $alltypes{$type} =~ s/`//g;
20161: }
20162: }
20163: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
20164: $currtitles =~ s/,$//;
20165: }
20166: }
20167: if ($env{'form.addinststatus'}) {
20168: my $newtype = $env{'form.addinststatus'};
20169: $newtype =~ s/\W//g;
20170: unless (exists($alltypes{$newtype})) {
20171: $alltypes{$newtype} = $env{'form.addinststatus_title'};
20172: $alltypes{$newtype} =~ s/`//g;
20173: my $position = $env{'form.addinststatus_pos'};
20174: $position =~ s/\D+//g;
20175: if ($position ne '') {
20176: $allpos[$position] = $newtype;
20177: }
20178: }
20179: }
1.305 raeburn 20180: my @orderedstatus;
1.236 raeburn 20181: foreach my $type (@allpos) {
20182: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
20183: push(@orderedstatus,$type);
20184: }
20185: }
20186: foreach my $type (keys(%alltypes)) {
20187: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
20188: delete($alltypes{$type});
20189: }
20190: }
20191: $defaults_hash{'inststatus'} = {
20192: inststatustypes => \%alltypes,
20193: inststatusorder => \@orderedstatus,
1.305 raeburn 20194: inststatusguest => \@inststatusguest,
1.236 raeburn 20195: };
20196: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
20197: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
20198: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
20199: }
20200: }
20201: if ($currorder ne join(',',@orderedstatus)) {
20202: $changes{'inststatus'}{'inststatusorder'} = 1;
20203: }
20204: my $newtitles;
20205: foreach my $item (@orderedstatus) {
20206: $newtitles .= $alltypes{$item}.',';
20207: }
20208: $newtitles =~ s/,$//;
20209: if ($currtitles ne $newtitles) {
20210: $changes{'inststatus'}{'inststatustypes'} = 1;
20211: }
1.43 raeburn 20212: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
20213: $dom);
20214: if ($putresult eq 'ok') {
20215: if (keys(%changes) > 0) {
20216: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 20217: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 20218: 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";
20219: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 20220: if ($item eq 'inststatus') {
20221: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 20222: if (@orderedstatus) {
1.236 raeburn 20223: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
20224: foreach my $type (@orderedstatus) {
20225: $resulttext .= $alltypes{$type}.', ';
20226: }
20227: $resulttext =~ s/, $//;
20228: $resulttext .= '</li>';
1.305 raeburn 20229: } else {
1.425 raeburn 20230: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 20231: }
20232: }
1.409 raeburn 20233: } elsif ($item eq 'unamemap_rule') {
20234: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20235: my @rulenames;
20236: if (ref($unamemaprules) eq 'HASH') {
20237: foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
20238: if (ref($unamemaprules->{$rule}) eq 'HASH') {
20239: push(@rulenames,$unamemaprules->{$rule}->{'name'});
20240: }
20241: }
20242: }
20243: if (@rulenames) {
20244: $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
20245: '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
20246: '</li>';
20247: } else {
20248: $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
20249: }
20250: } else {
20251: $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
20252: }
1.236 raeburn 20253: } else {
20254: my $value = $env{'form.'.$item};
20255: if ($value eq '') {
20256: $value = &mt('none');
20257: } elsif ($item eq 'auth_def') {
20258: my %authnames = &authtype_names();
20259: my %shortauth = (
20260: internal => 'int',
20261: krb4 => 'krb4',
20262: krb5 => 'krb5',
20263: localauth => 'loc',
1.325 raeburn 20264: lti => 'lti',
1.236 raeburn 20265: );
20266: $value = $authnames{$shortauth{$value}};
20267: }
20268: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
1.414 raeburn 20269: $mailmsgtext .= "$title->{$item} set to $value\n";
20270: if ($item eq 'portal_def') {
20271: if ($env{'form.'.$item} ne '') {
20272: foreach my $field ('email','web') {
20273: $value = $env{'form.'.$item.'_'.$field};
20274: if ($value) {
20275: $value = &mt('Yes');
20276: } else {
20277: $value = &mt('No');
20278: }
20279: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$field},$value).'</li>';
20280: }
20281: }
20282: }
1.43 raeburn 20283: }
20284: }
20285: $resulttext .= '</ul>';
20286: $mailmsgtext .= "\n";
20287: my $cachetime = 24*60*60;
1.72 raeburn 20288: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 20289: if (ref($lastactref) eq 'HASH') {
20290: $lastactref->{'domdefaults'} = 1;
20291: }
1.68 raeburn 20292: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 20293: my $notify = 1;
20294: if (ref($domconfig{'contacts'}) eq 'HASH') {
20295: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
20296: $notify = 0;
20297: }
20298: }
20299: if ($notify) {
20300: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
20301: "LON-CAPA Domain Settings Change - $dom",
20302: $mailmsgtext);
20303: }
1.54 raeburn 20304: }
1.43 raeburn 20305: } else {
1.54 raeburn 20306: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 20307: }
20308: } else {
20309: $resulttext = '<span class="LC_error">'.
20310: &mt('An error occurred: [_1]',$putresult).'</span>';
20311: }
20312: if (@errors > 0) {
20313: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
20314: foreach my $item (@errors) {
20315: $resulttext .= ' "'.$title->{$item}.'",';
20316: }
20317: $resulttext =~ s/,$//;
20318: }
20319: return $resulttext;
20320: }
20321:
1.46 raeburn 20322: sub modify_scantron {
1.205 raeburn 20323: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 20324: my ($resulttext,%confhash,%changes,$errors);
20325: my $custom = 'custom.tab';
20326: my $default = 'default.tab';
20327: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 20328: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 20329: &config_check($dom,$confname,$servadm);
20330: if ($env{'form.scantronformat.filename'} ne '') {
20331: my $error;
20332: if ($configuserok eq 'ok') {
20333: if ($switchserver) {
1.130 raeburn 20334: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 20335: } else {
20336: if ($author_ok eq 'ok') {
1.421 raeburn 20337: my $modified = [];
1.46 raeburn 20338: my ($result,$scantronurl) =
1.421 raeburn 20339: &Apache::lonconfigsettings::publishlogo($r,'upload','scantronformat',$dom,
20340: $confname,'scantron','','',$custom,
20341: $modified);
1.46 raeburn 20342: if ($result eq 'ok') {
20343: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 20344: $changes{'scantronformat'} = 1;
1.421 raeburn 20345: &update_modify_urls($r,$modified);
1.46 raeburn 20346: } else {
20347: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
20348: }
20349: } else {
20350: $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);
20351: }
20352: }
20353: } else {
20354: $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);
20355: }
20356: if ($error) {
20357: &Apache::lonnet::logthis($error);
20358: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
20359: }
20360: }
1.48 raeburn 20361: if (ref($domconfig{'scantron'}) eq 'HASH') {
20362: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
20363: if ($env{'form.scantronformat_del'}) {
20364: $confhash{'scantron'}{'scantronformat'} = '';
20365: $changes{'scantronformat'} = 1;
1.347 raeburn 20366: } else {
20367: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 20368: }
20369: }
20370: }
1.347 raeburn 20371: my @options = ('hdr','pad','rem');
1.346 raeburn 20372: my @fields = &scantroncsv_fields();
20373: my %titles = &scantronconfig_titles();
1.347 raeburn 20374: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 20375: my ($newdat,$currdat,%newcol,%currcol);
20376: if (grep(/^dat$/,@formats)) {
20377: $confhash{'scantron'}{config}{dat} = 1;
20378: $newdat = 1;
20379: } else {
20380: $newdat = 0;
20381: }
20382: if (grep(/^csv$/,@formats)) {
20383: my %bynum;
20384: foreach my $field (@fields) {
20385: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
20386: my $posscol = $1;
20387: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 20388: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 20389: $bynum{$posscol} = $field;
20390: $newcol{$field} = $posscol;
20391: }
20392: }
20393: }
1.347 raeburn 20394: if (keys(%newcol)) {
20395: foreach my $option (@options) {
20396: if ($env{'form.scantroncsv_'.$option}) {
20397: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
20398: }
20399: }
20400: }
1.346 raeburn 20401: }
20402: $currdat = 1;
20403: if (ref($domconfig{'scantron'}) eq 'HASH') {
20404: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 20405: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 20406: $currdat = 0;
20407: }
20408: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20409: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20410: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
20411: }
1.346 raeburn 20412: }
20413: }
20414: }
20415: if ($currdat != $newdat) {
20416: $changes{'config'} = 1;
20417: } else {
20418: foreach my $field (@fields) {
20419: if ($currcol{$field} ne '') {
20420: if ($currcol{$field} ne $newcol{$field}) {
20421: $changes{'config'} = 1;
20422: last;
1.347 raeburn 20423: }
1.346 raeburn 20424: } elsif ($newcol{$field} ne '') {
20425: $changes{'config'} = 1;
20426: last;
20427: }
20428: }
20429: }
1.46 raeburn 20430: if (keys(%confhash) > 0) {
20431: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
20432: $dom);
20433: if ($putresult eq 'ok') {
20434: if (keys(%changes) > 0) {
1.48 raeburn 20435: if (ref($confhash{'scantron'}) eq 'HASH') {
20436: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 20437: if ($changes{'scantronformat'}) {
20438: if ($confhash{'scantron'}{'scantronformat'} eq '') {
20439: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
20440: } else {
20441: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
20442: }
20443: }
1.347 raeburn 20444: if ($changes{'config'}) {
1.346 raeburn 20445: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
20446: if ($confhash{'scantron'}{'config'}{'dat'}) {
20447: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
20448: }
20449: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20450: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20451: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
20452: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
20453: foreach my $field (@fields) {
20454: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
20455: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
20456: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
20457: }
20458: }
20459: $resulttext .= '</ul></li>';
20460: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
20461: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
20462: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
20463: foreach my $option (@options) {
20464: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
20465: $resulttext .= '<li>'.$titles{$option}.'</li>';
20466: }
20467: }
20468: $resulttext .= '</ul></li>';
20469: }
1.346 raeburn 20470: }
20471: }
20472: }
20473: }
20474: } else {
20475: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
20476: }
1.46 raeburn 20477: }
1.48 raeburn 20478: $resulttext .= '</ul>';
20479: } else {
1.130 raeburn 20480: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 20481: }
20482: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 20483: if (ref($lastactref) eq 'HASH') {
20484: $lastactref->{'domainconfig'} = 1;
20485: }
1.46 raeburn 20486: } else {
1.346 raeburn 20487: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 20488: }
20489: } else {
20490: $resulttext = '<span class="LC_error">'.
20491: &mt('An error occurred: [_1]',$putresult).'</span>';
20492: }
20493: } else {
1.130 raeburn 20494: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 20495: }
20496: if ($errors) {
1.353 raeburn 20497: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
20498: $errors.'</ul></p>';
1.46 raeburn 20499: }
20500: return $resulttext;
20501: }
20502:
1.48 raeburn 20503: sub modify_coursecategories {
1.239 raeburn 20504: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 20505: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
20506: $cathash);
1.48 raeburn 20507: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 20508: my @catitems = ('unauth','auth');
20509: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 20510: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 20511: $cathash = $domconfig{'coursecategories'}{'cats'};
20512: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
20513: $changes{'togglecats'} = 1;
20514: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
20515: }
20516: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
20517: $changes{'categorize'} = 1;
20518: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
20519: }
1.120 raeburn 20520: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
20521: $changes{'togglecatscomm'} = 1;
20522: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
20523: }
20524: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
20525: $changes{'categorizecomm'} = 1;
20526: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 20527:
20528: }
20529: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
20530: $changes{'togglecatsplace'} = 1;
20531: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
20532: }
20533: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
20534: $changes{'categorizeplace'} = 1;
20535: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 20536: }
1.238 raeburn 20537: foreach my $item (@catitems) {
20538: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20539: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
20540: $changes{$item} = 1;
20541: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20542: }
20543: }
20544: }
1.57 raeburn 20545: } else {
20546: $changes{'togglecats'} = 1;
20547: $changes{'categorize'} = 1;
1.124 raeburn 20548: $changes{'togglecatscomm'} = 1;
20549: $changes{'categorizecomm'} = 1;
1.272 raeburn 20550: $changes{'togglecatsplace'} = 1;
20551: $changes{'categorizeplace'} = 1;
1.87 raeburn 20552: $domconfig{'coursecategories'} = {
20553: togglecats => $env{'form.togglecats'},
20554: categorize => $env{'form.categorize'},
1.124 raeburn 20555: togglecatscomm => $env{'form.togglecatscomm'},
20556: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 20557: togglecatsplace => $env{'form.togglecatsplace'},
20558: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 20559: };
1.238 raeburn 20560: foreach my $item (@catitems) {
20561: if ($env{'form.coursecat_'.$item} ne 'std') {
20562: $changes{$item} = 1;
20563: }
20564: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20565: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20566: }
20567: }
1.57 raeburn 20568: }
20569: if (ref($cathash) eq 'HASH') {
20570: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 20571: push (@deletecategory,'instcode::0');
20572: }
1.120 raeburn 20573: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
20574: push(@deletecategory,'communities::0');
20575: }
1.272 raeburn 20576: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
20577: push(@deletecategory,'placement::0');
20578: }
1.48 raeburn 20579: }
1.57 raeburn 20580: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
20581: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20582: if (@deletecategory > 0) {
20583: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 20584: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 20585: foreach my $item (@deletecategory) {
1.57 raeburn 20586: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
20587: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 20588: $deletions{$item} = 1;
1.57 raeburn 20589: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 20590: }
20591: }
20592: }
1.57 raeburn 20593: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 20594: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 20595: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 20596: $reorderings{$item} = 1;
1.57 raeburn 20597: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 20598: }
20599: if ($env{'form.addcategory_name_'.$item} ne '') {
20600: my $newcat = $env{'form.addcategory_name_'.$item};
20601: my $newdepth = $depth+1;
20602: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20603: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 20604: $adds{$newitem} = 1;
20605: }
20606: if ($env{'form.subcat_'.$item} ne '') {
20607: my $newcat = $env{'form.subcat_'.$item};
20608: my $newdepth = $depth+1;
20609: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20610: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 20611: $adds{$newitem} = 1;
20612: }
20613: }
20614: }
20615: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 20616: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20617: my $newitem = 'instcode::0';
1.57 raeburn 20618: if ($cathash->{$newitem} eq '') {
20619: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20620: $adds{$newitem} = 1;
20621: }
20622: } else {
20623: my $newitem = 'instcode::0';
1.57 raeburn 20624: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20625: $adds{$newitem} = 1;
20626: }
20627: }
1.120 raeburn 20628: if ($env{'form.communities'} eq '1') {
20629: if (ref($cathash) eq 'HASH') {
20630: my $newitem = 'communities::0';
20631: if ($cathash->{$newitem} eq '') {
20632: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20633: $adds{$newitem} = 1;
20634: }
20635: } else {
20636: my $newitem = 'communities::0';
20637: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20638: $adds{$newitem} = 1;
20639: }
20640: }
1.272 raeburn 20641: if ($env{'form.placement'} eq '1') {
20642: if (ref($cathash) eq 'HASH') {
20643: my $newitem = 'placement::0';
20644: if ($cathash->{$newitem} eq '') {
20645: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20646: $adds{$newitem} = 1;
20647: }
20648: } else {
20649: my $newitem = 'placement::0';
20650: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20651: $adds{$newitem} = 1;
20652: }
20653: }
1.48 raeburn 20654: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 20655: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 20656: ($env{'form.addcategory_name'} ne 'communities') &&
20657: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 20658: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
20659: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
20660: $adds{$newitem} = 1;
20661: }
1.48 raeburn 20662: }
1.57 raeburn 20663: my $putresult;
1.48 raeburn 20664: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20665: if (keys(%deletions) > 0) {
20666: foreach my $key (keys(%deletions)) {
20667: if ($predelallitems{$key} ne '') {
20668: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
20669: }
20670: }
20671: }
20672: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 20673: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 20674: if (ref($chkcats[0]) eq 'ARRAY') {
20675: my $depth = 0;
20676: my $chg = 0;
20677: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
20678: my $name = $chkcats[0][$i];
20679: my $item;
20680: if ($name eq '') {
20681: $chg ++;
20682: } else {
20683: $item = &escape($name).'::0';
20684: if ($chg) {
1.57 raeburn 20685: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 20686: }
20687: $depth ++;
1.57 raeburn 20688: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 20689: $depth --;
20690: }
20691: }
20692: }
1.57 raeburn 20693: }
20694: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20695: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 20696: if ($putresult eq 'ok') {
1.57 raeburn 20697: my %title = (
1.120 raeburn 20698: togglecats => 'Show/Hide a course in catalog',
20699: categorize => 'Assign a category to a course',
20700: togglecatscomm => 'Show/Hide a community in catalog',
20701: categorizecomm => 'Assign a category to a community',
1.57 raeburn 20702: );
20703: my %level = (
1.120 raeburn 20704: dom => 'set in Domain ("Modify Course/Community")',
20705: crs => 'set in Course ("Course Configuration")',
20706: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 20707: none => 'No catalog',
20708: std => 'Standard catalog',
20709: domonly => 'Domain-only catalog',
20710: codesrch => 'Code search form',
1.57 raeburn 20711: );
1.48 raeburn 20712: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 20713: if ($changes{'togglecats'}) {
20714: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
20715: }
20716: if ($changes{'categorize'}) {
20717: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 20718: }
1.120 raeburn 20719: if ($changes{'togglecatscomm'}) {
20720: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
20721: }
20722: if ($changes{'categorizecomm'}) {
20723: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
20724: }
1.238 raeburn 20725: if ($changes{'unauth'}) {
20726: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
20727: }
20728: if ($changes{'auth'}) {
20729: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
20730: }
1.57 raeburn 20731: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20732: my $cathash;
20733: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
20734: $cathash = $domconfig{'coursecategories'}{'cats'};
20735: } else {
20736: $cathash = {};
20737: }
20738: my (@cats,@trails,%allitems);
20739: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
20740: if (keys(%deletions) > 0) {
20741: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
20742: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
20743: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
20744: }
20745: $resulttext .= '</ul></li>';
20746: }
20747: if (keys(%reorderings) > 0) {
20748: my %sort_by_trail;
20749: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
20750: foreach my $key (keys(%reorderings)) {
20751: if ($allitems{$key} ne '') {
20752: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20753: }
1.48 raeburn 20754: }
1.57 raeburn 20755: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20756: $resulttext .= '<li>'.$trails[$trail].'</li>';
20757: }
20758: $resulttext .= '</ul></li>';
1.48 raeburn 20759: }
1.57 raeburn 20760: if (keys(%adds) > 0) {
20761: my %sort_by_trail;
20762: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
20763: foreach my $key (keys(%adds)) {
20764: if ($allitems{$key} ne '') {
20765: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20766: }
20767: }
20768: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20769: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 20770: }
1.57 raeburn 20771: $resulttext .= '</ul></li>';
1.48 raeburn 20772: }
1.364 raeburn 20773: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
20774: if (ref($lastactref) eq 'HASH') {
20775: $lastactref->{'cats'} = 1;
20776: }
1.48 raeburn 20777: }
20778: $resulttext .= '</ul>';
1.239 raeburn 20779: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 20780: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
20781: if ($changes{'auth'}) {
20782: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
20783: }
20784: if ($changes{'unauth'}) {
20785: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
20786: }
20787: my $cachetime = 24*60*60;
20788: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 20789: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 20790: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 20791: }
20792: }
1.48 raeburn 20793: } else {
20794: $resulttext = '<span class="LC_error">'.
1.57 raeburn 20795: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 20796: }
20797: } else {
1.120 raeburn 20798: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 20799: }
20800: return $resulttext;
20801: }
20802:
1.69 raeburn 20803: sub modify_serverstatuses {
20804: my ($dom,%domconfig) = @_;
20805: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
20806: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
20807: %currserverstatus = %{$domconfig{'serverstatuses'}};
20808: }
20809: my @pages = &serverstatus_pages();
20810: foreach my $type (@pages) {
20811: $newserverstatus{$type}{'namedusers'} = '';
20812: $newserverstatus{$type}{'machines'} = '';
20813: if (defined($env{'form.'.$type.'_namedusers'})) {
20814: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
20815: my @okusers;
20816: foreach my $user (@users) {
20817: my ($uname,$udom) = split(/:/,$user);
20818: if (($udom =~ /^$match_domain$/) &&
20819: (&Apache::lonnet::domain($udom)) &&
20820: ($uname =~ /^$match_username$/)) {
20821: if (!grep(/^\Q$user\E/,@okusers)) {
20822: push(@okusers,$user);
20823: }
20824: }
20825: }
20826: if (@okusers > 0) {
20827: @okusers = sort(@okusers);
20828: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
20829: }
20830: }
20831: if (defined($env{'form.'.$type.'_machines'})) {
20832: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
20833: my @okmachines;
20834: foreach my $ip (@machines) {
20835: my @parts = split(/\./,$ip);
20836: next if (@parts < 4);
20837: my $badip = 0;
20838: for (my $i=0; $i<4; $i++) {
20839: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
20840: $badip = 1;
20841: last;
20842: }
20843: }
20844: if (!$badip) {
20845: push(@okmachines,$ip);
20846: }
20847: }
20848: @okmachines = sort(@okmachines);
20849: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
20850: }
20851: }
20852: my %serverstatushash = (
20853: serverstatuses => \%newserverstatus,
20854: );
20855: foreach my $type (@pages) {
1.83 raeburn 20856: foreach my $setting ('namedusers','machines') {
1.84 raeburn 20857: my (@current,@new);
1.83 raeburn 20858: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 20859: if ($currserverstatus{$type}{$setting} ne '') {
20860: @current = split(/,/,$currserverstatus{$type}{$setting});
20861: }
20862: }
20863: if ($newserverstatus{$type}{$setting} ne '') {
20864: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 20865: }
20866: if (@current > 0) {
20867: if (@new > 0) {
20868: foreach my $item (@current) {
20869: if (!grep(/^\Q$item\E$/,@new)) {
20870: $changes{$type}{$setting} = 1;
1.82 raeburn 20871: last;
20872: }
20873: }
1.84 raeburn 20874: foreach my $item (@new) {
20875: if (!grep(/^\Q$item\E$/,@current)) {
20876: $changes{$type}{$setting} = 1;
20877: last;
1.82 raeburn 20878: }
20879: }
20880: } else {
1.83 raeburn 20881: $changes{$type}{$setting} = 1;
1.69 raeburn 20882: }
1.83 raeburn 20883: } elsif (@new > 0) {
20884: $changes{$type}{$setting} = 1;
1.69 raeburn 20885: }
20886: }
20887: }
20888: if (keys(%changes) > 0) {
1.81 raeburn 20889: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 20890: my $putresult = &Apache::lonnet::put_dom('configuration',
20891: \%serverstatushash,$dom);
20892: if ($putresult eq 'ok') {
20893: $resulttext .= &mt('Changes made:').'<ul>';
20894: foreach my $type (@pages) {
1.84 raeburn 20895: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 20896: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 20897: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 20898: if ($newserverstatus{$type}{'namedusers'} eq '') {
20899: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
20900: } else {
20901: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
20902: }
1.84 raeburn 20903: }
20904: if ($changes{$type}{'machines'}) {
1.69 raeburn 20905: if ($newserverstatus{$type}{'machines'} eq '') {
20906: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
20907: } else {
20908: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
20909: }
20910:
20911: }
20912: $resulttext .= '</ul></li>';
20913: }
20914: }
20915: $resulttext .= '</ul>';
20916: } else {
20917: $resulttext = '<span class="LC_error">'.
20918: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
20919:
20920: }
20921: } else {
20922: $resulttext = &mt('No changes made to access to server status pages');
20923: }
20924: return $resulttext;
20925: }
20926:
1.118 jms 20927: sub modify_helpsettings {
1.285 raeburn 20928: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 20929: my ($resulttext,$errors,%changes,%helphash);
20930: my %defaultchecked = ('submitbugs' => 'on');
20931: my @offon = ('off','on');
1.118 jms 20932: my @toggles = ('submitbugs');
1.285 raeburn 20933: my %current = ('submitbugs' => '',
20934: 'adhoc' => {},
20935: );
1.118 jms 20936: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 20937: %current = %{$domconfig{'helpsettings'}};
20938: }
1.285 raeburn 20939: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 20940: foreach my $item (@toggles) {
20941: if ($defaultchecked{$item} eq 'on') {
20942: if ($current{$item} eq '') {
20943: if ($env{'form.'.$item} eq '0') {
20944: $changes{$item} = 1;
20945: }
20946: } elsif ($current{$item} ne $env{'form.'.$item}) {
20947: $changes{$item} = 1;
20948: }
20949: } elsif ($defaultchecked{$item} eq 'off') {
20950: if ($current{$item} eq '') {
20951: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 20952: $changes{$item} = 1;
20953: }
1.282 raeburn 20954: } elsif ($current{$item} ne $env{'form.'.$item}) {
20955: $changes{$item} = 1;
20956: }
20957: }
20958: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
20959: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
20960: }
20961: }
1.285 raeburn 20962: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 20963: my $confname = $dom.'-domainconfig';
20964: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 20965: my (@allpos,%newsettings,%changedprivs,$newrole);
20966: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 20967: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 20968: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 20969: my %lt = &Apache::lonlocal::texthash(
20970: s => 'system',
20971: d => 'domain',
20972: order => 'Display order',
20973: access => 'Role usage',
1.291 raeburn 20974: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 20975: dh => 'All with domain helpdesk role',
20976: da => 'All with domain helpdesk assistant role',
1.285 raeburn 20977: none => 'None',
20978: status => 'Determined based on institutional status',
20979: inc => 'Include all, but exclude specific personnel',
20980: exc => 'Exclude all, but include specific personnel',
20981: );
20982: for (my $num=0; $num<=$maxnum; $num++) {
20983: my ($prefix,$identifier,$rolename,%curr);
20984: if ($num == $maxnum) {
20985: next unless ($env{'form.newcusthelp'} == $maxnum);
20986: $identifier = 'custhelp'.$num;
20987: $prefix = 'helproles_'.$num;
20988: $rolename = $env{'form.custhelpname'.$num};
20989: $rolename=~s/[^A-Za-z0-9]//gs;
20990: next if ($rolename eq '');
20991: next if (exists($existing{'rolesdef_'.$rolename}));
20992: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
20993: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
20994: $newprivs{'c'},$confname,$dom);
20995: if ($result ne 'ok') {
20996: $errors .= '<li><span class="LC_error">'.
20997: &mt('An error occurred storing the new custom role: [_1]',
20998: $result).'</span></li>';
20999: next;
21000: } else {
21001: $changedprivs{$rolename} = \%newprivs;
21002: $newrole = $rolename;
21003: }
21004: } else {
21005: $prefix = 'helproles_'.$num;
21006: $rolename = $env{'form.'.$prefix};
21007: next if ($rolename eq '');
21008: next unless (exists($existing{'rolesdef_'.$rolename}));
21009: $identifier = 'custhelp'.$num;
21010: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
21011: my %currprivs;
1.289 raeburn 21012: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 21013: split(/\_/,$existing{'rolesdef_'.$rolename});
21014: foreach my $level ('c','d','s') {
21015: if ($newprivs{$level} ne $currprivs{$level}) {
21016: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
21017: $newprivs{'c'},$confname,$dom);
21018: if ($result ne 'ok') {
21019: $errors .= '<li><span class="LC_error">'.
21020: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
21021: $rolename,$result).'</span></li>';
21022: } else {
21023: $changedprivs{$rolename} = \%newprivs;
21024: }
21025: last;
21026: }
21027: }
21028: if (ref($current{'adhoc'}) eq 'HASH') {
21029: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
21030: %curr = %{$current{'adhoc'}{$rolename}};
21031: }
21032: }
21033: }
21034: my $newpos = $env{'form.'.$prefix.'_pos'};
21035: $newpos =~ s/\D+//g;
21036: $allpos[$newpos] = $rolename;
21037: my $newdesc = $env{'form.'.$prefix.'_desc'};
21038: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
21039: if ($curr{'desc'}) {
21040: if ($curr{'desc'} ne $newdesc) {
21041: $changes{'customrole'}{$rolename}{'desc'} = 1;
21042: $newsettings{$rolename}{'desc'} = $newdesc;
21043: }
21044: } elsif ($newdesc ne '') {
21045: $changes{'customrole'}{$rolename}{'desc'} = 1;
21046: $newsettings{$rolename}{'desc'} = $newdesc;
21047: }
21048: my $access = $env{'form.'.$prefix.'_access'};
21049: if (grep(/^\Q$access\E$/,@accesstypes)) {
21050: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
21051: if ($access eq 'status') {
21052: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
21053: if (scalar(@statuses) == 0) {
1.289 raeburn 21054: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 21055: } else {
21056: my (@shownstatus,$numtypes);
21057: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
21058: if (ref($types) eq 'ARRAY') {
21059: $numtypes = scalar(@{$types});
21060: foreach my $type (sort(@statuses)) {
21061: if ($type eq 'default') {
21062: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
21063: } elsif (grep(/^\Q$type\E$/,@{$types})) {
21064: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
21065: push(@shownstatus,$usertypes->{$type});
21066: }
21067: }
21068: }
21069: if (grep(/^default$/,@statuses)) {
21070: push(@shownstatus,$othertitle);
21071: }
21072: if (scalar(@shownstatus) == 1+$numtypes) {
21073: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
21074: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
21075: } else {
21076: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
21077: if (ref($curr{'status'}) eq 'ARRAY') {
21078: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
21079: if (@diffs) {
21080: $changes{'customrole'}{$rolename}{$access} = 1;
21081: }
21082: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21083: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 21084: }
1.166 raeburn 21085: }
21086: }
1.285 raeburn 21087: } elsif (($access eq 'inc') || ($access eq 'exc')) {
21088: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
21089: my @newspecstaff;
21090: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
21091: foreach my $person (sort(@personnel)) {
21092: if ($domhelpdesk{$person}) {
21093: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
21094: }
21095: }
21096: if (ref($curr{$access}) eq 'ARRAY') {
21097: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
21098: if (@diffs) {
21099: $changes{'customrole'}{$rolename}{$access} = 1;
21100: }
21101: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21102: $changes{'customrole'}{$rolename}{$access} = 1;
21103: }
21104: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21105: my ($uname,$udom) = split(/:/,$person);
21106: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
21107: }
21108: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 21109: }
1.285 raeburn 21110: } else {
21111: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
21112: }
21113: unless ($curr{'access'} eq $access) {
21114: $changes{'customrole'}{$rolename}{'access'} = 1;
21115: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 21116: }
21117: }
1.285 raeburn 21118: if (@allpos > 0) {
21119: my $idx = 0;
21120: foreach my $rolename (@allpos) {
21121: if ($rolename ne '') {
21122: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
21123: if (ref($current{'adhoc'}) eq 'HASH') {
21124: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
21125: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
21126: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 21127: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 21128: }
21129: }
1.282 raeburn 21130: }
1.285 raeburn 21131: $idx ++;
1.166 raeburn 21132: }
21133: }
1.118 jms 21134: }
1.123 jms 21135: my $putresult;
21136: if (keys(%changes) > 0) {
1.166 raeburn 21137: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 21138: if ($putresult eq 'ok') {
1.285 raeburn 21139: if (ref($helphash{'helpsettings'}) eq 'HASH') {
21140: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
21141: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
21142: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
21143: }
21144: }
21145: my $cachetime = 24*60*60;
21146: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21147: if (ref($lastactref) eq 'HASH') {
21148: $lastactref->{'domdefaults'} = 1;
21149: }
21150: } else {
21151: $errors .= '<li><span class="LC_error">'.
21152: &mt('An error occurred storing the settings: [_1]',
21153: $putresult).'</span></li>';
21154: }
21155: }
21156: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
21157: $resulttext = &mt('Changes made:').'<ul>';
21158: my (%shownprivs,@levelorder);
21159: @levelorder = ('c','d','s');
21160: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 21161: foreach my $item (sort(keys(%changes))) {
21162: if ($item eq 'submitbugs') {
21163: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
21164: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
21165: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 21166: } elsif ($item eq 'customrole') {
21167: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 21168: my @keyorder = ('order','desc','access','status','exc','inc');
21169: my %keytext = &Apache::lonlocal::texthash(
21170: order => 'Order',
21171: desc => 'Role description',
21172: access => 'Role usage',
1.300 droeschl 21173: status => 'Allowed institutional types',
1.285 raeburn 21174: exc => 'Allowed personnel',
21175: inc => 'Disallowed personnel',
21176: );
1.282 raeburn 21177: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 21178: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
21179: if ($role eq $newrole) {
21180: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
21181: $role).'<ul>';
21182: } else {
21183: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
21184: $role).'<ul>';
21185: }
21186: foreach my $key (@keyorder) {
21187: if ($changes{'customrole'}{$role}{$key}) {
21188: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
21189: $keytext{$key},$newsettings{$role}{$key}).
21190: '</li>';
21191: }
21192: }
21193: if (ref($changedprivs{$role}) eq 'HASH') {
21194: $shownprivs{$role} = 1;
21195: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
21196: foreach my $level (@levelorder) {
21197: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
21198: next if ($item eq '');
21199: my ($priv) = split(/\&/,$item,2);
21200: if (&Apache::lonnet::plaintext($priv)) {
21201: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
21202: unless ($level eq 'c') {
21203: $resulttext .= ' ('.$lt{$level}.')';
21204: }
21205: $resulttext .= '</li>';
21206: }
21207: }
21208: }
21209: $resulttext .= '</ul>';
21210: }
21211: $resulttext .= '</ul></li>';
21212: }
21213: }
21214: }
21215: }
21216: }
21217: }
21218: if (keys(%changedprivs)) {
21219: foreach my $role (sort(keys(%changedprivs))) {
21220: unless ($shownprivs{$role}) {
21221: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
21222: $role).'<ul>'.
21223: '<li>'.&mt('Privileges set to :').'<ul>';
21224: foreach my $level (@levelorder) {
21225: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
21226: next if ($item eq '');
21227: my ($priv) = split(/\&/,$item,2);
21228: if (&Apache::lonnet::plaintext($priv)) {
21229: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
21230: unless ($level eq 'c') {
21231: $resulttext .= ' ('.$lt{$level}.')';
21232: }
21233: $resulttext .= '</li>';
21234: }
1.282 raeburn 21235: }
21236: }
1.285 raeburn 21237: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 21238: }
21239: }
21240: }
1.285 raeburn 21241: $resulttext .= '</ul>';
21242: } else {
21243: $resulttext = &mt('No changes made to help settings');
1.118 jms 21244: }
21245: if ($errors) {
1.168 raeburn 21246: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 21247: $errors.'</ul>';
1.118 jms 21248: }
21249: return $resulttext;
21250: }
21251:
1.121 raeburn 21252: sub modify_coursedefaults {
1.212 raeburn 21253: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 21254: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 21255: my %defaultchecked = (
21256: 'canuse_pdfforms' => 'off',
21257: 'uselcmath' => 'on',
1.398 raeburn 21258: 'usejsme' => 'on',
21259: 'inline_chem' => 'on',
1.404 raeburn 21260: 'ltiauth' => 'off',
1.257 raeburn 21261: );
1.404 raeburn 21262: my @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem','ltiauth');
1.198 raeburn 21263: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 21264: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
1.428 raeburn 21265: 'coursequota_official','coursequota_unofficial','coursequota_community',
21266: 'coursequota_textbook','coursequota_placement','mysqltables_official',
21267: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook',
21268: 'mysqltables_placement');
1.271 raeburn 21269: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 21270: my %staticdefaults = (
21271: anonsurvey_threshold => 10,
21272: uploadquota => 500,
1.428 raeburn 21273: coursequota => 20,
1.257 raeburn 21274: postsubmit => 60,
1.276 raeburn 21275: mysqltables => 172800,
1.422 raeburn 21276: domexttool => 1,
1.432 raeburn 21277: crsauthor => 1,
1.438 raeburn 21278: crseditors => ['edit','xml'],
1.198 raeburn 21279: );
1.314 raeburn 21280: my %texoptions = (
21281: MathJax => 'MathJax',
21282: mimetex => &mt('Convert to Images'),
21283: tth => &mt('TeX to HTML'),
21284: );
1.438 raeburn 21285:
21286: my @editors = ('edit','xml','daxe');
21287: my %editornames = &crseditor_titles();
21288:
1.121 raeburn 21289: $defaultshash{'coursedefaults'} = {};
21290:
21291: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
21292: if ($domconfig{'coursedefaults'} eq '') {
21293: $domconfig{'coursedefaults'} = {};
21294: }
21295: }
21296:
21297: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
21298: foreach my $item (@toggles) {
21299: if ($defaultchecked{$item} eq 'on') {
21300: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21301: ($env{'form.'.$item} eq '0')) {
21302: $changes{$item} = 1;
1.192 raeburn 21303: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 21304: $changes{$item} = 1;
21305: }
21306: } elsif ($defaultchecked{$item} eq 'off') {
21307: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21308: ($env{'form.'.$item} eq '1')) {
21309: $changes{$item} = 1;
21310: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
21311: $changes{$item} = 1;
21312: }
21313: }
21314: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
21315: }
1.198 raeburn 21316: foreach my $item (@numbers) {
21317: my ($currdef,$newdef);
1.208 raeburn 21318: $newdef = $env{'form.'.$item};
1.198 raeburn 21319: if ($item eq 'anonsurvey_threshold') {
21320: $currdef = $domconfig{'coursedefaults'}{$item};
21321: $newdef =~ s/\D//g;
21322: if ($newdef eq '' || $newdef < 1) {
21323: $newdef = 1;
21324: }
21325: $defaultshash{'coursedefaults'}{$item} = $newdef;
21326: } else {
1.428 raeburn 21327: my ($setting,$type) = ($item =~ /^(uploadquota|coursequota|mysqltables)_(\w+)$/);
1.276 raeburn 21328: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
21329: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 21330: }
21331: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 21332: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 21333: }
21334: if ($currdef ne $newdef) {
21335: if ($item eq 'anonsurvey_threshold') {
21336: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
21337: $changes{$item} = 1;
21338: }
1.428 raeburn 21339: } elsif ($item =~ /^(uploadquota|coursequota|mysqltables)_/) {
1.289 raeburn 21340: my $setting = $1;
1.276 raeburn 21341: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
21342: $changes{$setting} = 1;
1.198 raeburn 21343: }
21344: }
1.139 raeburn 21345: }
21346: }
1.314 raeburn 21347: my $texengine;
21348: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
21349: $texengine = $env{'form.texengine'};
1.349 raeburn 21350: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
21351: if ($currdef eq '') {
21352: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 21353: $changes{'texengine'} = 1;
21354: }
1.349 raeburn 21355: } elsif ($currdef ne $texengine) {
1.314 raeburn 21356: $changes{'texengine'} = 1;
21357: }
21358: }
21359: if ($texengine ne '') {
21360: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
21361: }
1.264 raeburn 21362: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
21363: my @currclonecode;
21364: if (ref($currclone) eq 'HASH') {
21365: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
21366: @currclonecode = @{$currclone->{'instcode'}};
21367: }
21368: }
21369: my $newclone;
1.289 raeburn 21370: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 21371: $newclone = $env{'form.canclone'};
21372: }
21373: if ($newclone eq 'instcode') {
21374: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
21375: my (%codedefaults,@code_order,@clonecode);
21376: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
21377: \@code_order);
21378: foreach my $item (@code_order) {
21379: if (grep(/^\Q$item\E$/,@newcodes)) {
21380: push(@clonecode,$item);
21381: }
21382: }
21383: if (@clonecode) {
21384: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
21385: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
21386: if (@diffs) {
21387: $changes{'canclone'} = 1;
21388: }
21389: } else {
21390: $newclone eq '';
21391: }
21392: } elsif ($newclone ne '') {
1.289 raeburn 21393: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
21394: }
1.264 raeburn 21395: if ($newclone ne $currclone) {
21396: $changes{'canclone'} = 1;
21397: }
1.257 raeburn 21398: my %credits;
21399: foreach my $type (@types) {
21400: unless ($type eq 'community') {
21401: $credits{$type} = $env{'form.'.$type.'_credits'};
21402: $credits{$type} =~ s/[^\d.]+//g;
21403: }
21404: }
21405: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
21406: ($env{'form.coursecredits'} eq '1')) {
21407: $changes{'coursecredits'} = 1;
21408: foreach my $type (keys(%credits)) {
21409: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21410: }
21411: } else {
1.289 raeburn 21412: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 21413: foreach my $type (@types) {
21414: unless ($type eq 'community') {
1.289 raeburn 21415: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 21416: $changes{'coursecredits'} = 1;
21417: }
21418: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21419: }
21420: }
21421: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21422: foreach my $type (@types) {
21423: unless ($type eq 'community') {
21424: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
21425: $changes{'coursecredits'} = 1;
21426: last;
21427: }
21428: }
21429: }
21430: }
21431: }
21432: if ($env{'form.postsubmit'} eq '1') {
21433: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
21434: my %currtimeout;
21435: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21436: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
21437: $changes{'postsubmit'} = 1;
21438: }
21439: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21440: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
21441: }
21442: } else {
21443: $changes{'postsubmit'} = 1;
21444: }
21445: foreach my $type (@types) {
21446: my $timeout = $env{'form.'.$type.'_timeout'};
21447: $timeout =~ s/\D//g;
21448: if ($timeout == $staticdefaults{'postsubmit'}) {
21449: $timeout = '';
21450: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
21451: $timeout = '0';
21452: }
21453: unless ($timeout eq '') {
21454: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
21455: }
21456: if (exists($currtimeout{$type})) {
21457: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 21458: $changes{'postsubmit'} = 1;
1.257 raeburn 21459: }
21460: } elsif ($timeout ne '') {
21461: $changes{'postsubmit'} = 1;
21462: }
21463: }
21464: } else {
21465: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
21466: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21467: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
21468: $changes{'postsubmit'} = 1;
21469: }
21470: } else {
21471: $changes{'postsubmit'} = 1;
21472: }
1.192 raeburn 21473: }
1.438 raeburn 21474: my (%newdomexttool,%newexttool,%newcrsauthor,%olddomexttool,%oldexttool,%oldcrsauthor,
21475: %posscrseditors);
1.422 raeburn 21476: map { $newdomexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.domexttool');
1.425 raeburn 21477: map { $newexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.exttool');
1.432 raeburn 21478: map { $newcrsauthor{$_} = 1; } &Apache::loncommon::get_env_multiple('form.crsauthor');
1.438 raeburn 21479: map { $posscrseditors{$_} = 1; } &Apache::loncommon::get_env_multiple('form.crseditors');
1.422 raeburn 21480: if (ref($domconfig{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21481: %olddomexttool = %{$domconfig{'coursedefaults'}{'domexttool'}};
21482: } else {
21483: foreach my $type (@types) {
21484: if ($staticdefaults{'domexttool'}) {
21485: $olddomexttool{$type} = 1;
21486: } else {
21487: $olddomexttool{$type} = 0;
21488: }
21489: }
21490: }
21491: if (ref($domconfig{'coursedefaults'}{'exttool'}) eq 'HASH') {
1.425 raeburn 21492: %oldexttool = %{$domconfig{'coursedefaults'}{'exttool'}};
1.422 raeburn 21493: } else {
21494: foreach my $type (@types) {
21495: if ($staticdefaults{'exttool'}) {
21496: $oldexttool{$type} = 1;
21497: } else {
21498: $oldexttool{$type} = 0;
21499: }
21500: }
21501: }
1.432 raeburn 21502: if (ref($domconfig{'coursedefaults'}{'crsauthor'}) eq 'HASH') {
21503: %oldcrsauthor = %{$domconfig{'coursedefaults'}{'crsauthor'}};
21504: } else {
21505: foreach my $type (@types) {
21506: if ($staticdefaults{'crsauthor'}) {
21507: $oldcrsauthor{$type} = 1;
21508: } else {
21509: $oldcrsauthor{$type} = 0;
21510: }
21511: }
21512: }
1.438 raeburn 21513: my @newcrseditors = ();
21514: foreach my $editor (@editors) {
21515: if ($posscrseditors{$editor}) {
21516: push(@newcrseditors,$editor);
21517: }
21518: }
21519: if (ref($domconfig{'coursedefaults'}{'crseditors'}) eq 'ARRAY') {
21520: my @diffs =
21521: &Apache::loncommon::compare_arrays($domconfig{'coursedefaults'}{'crseditors'},
21522: \@newcrseditors);
21523: if (@diffs) {
21524: $changes{'crseditors'} = 1;
21525: }
21526: } else {
21527: my @diffs =
21528: &Apache::loncommon::compare_arrays($staticdefaults{'crseditors'},
21529: \@newcrseditors);
21530: unless (@diffs == 0) {
21531: $changes{'crseditors'} = 1;
21532: }
21533: }
1.422 raeburn 21534: foreach my $type (@types) {
21535: unless ($newdomexttool{$type}) {
21536: $newdomexttool{$type} = 0;
21537: }
21538: unless ($newexttool{$type}) {
21539: $newexttool{$type} = 0;
21540: }
1.432 raeburn 21541: unless ($newcrsauthor{$type}) {
21542: $newcrsauthor{$type} = 0;
21543: }
1.422 raeburn 21544: if ($newdomexttool{$type} != $olddomexttool{$type}) {
21545: $changes{'domexttool'} = 1;
21546: }
21547: if ($newexttool{$type} != $oldexttool{$type}) {
21548: $changes{'exttool'} = 1;
21549: }
1.432 raeburn 21550: if ($newcrsauthor{$type} != $oldcrsauthor{$type}) {
21551: $changes{'crsauthor'} = 1;
21552: }
1.422 raeburn 21553: }
21554: $defaultshash{'coursedefaults'}{'domexttool'} = \%newdomexttool;
21555: $defaultshash{'coursedefaults'}{'exttool'} = \%newexttool;
1.432 raeburn 21556: $defaultshash{'coursedefaults'}{'crsauthor'} = \%newcrsauthor;
1.438 raeburn 21557: $defaultshash{'coursedefaults'}{'crseditors'} = \@newcrseditors;
1.121 raeburn 21558: }
21559: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21560: $dom);
21561: if ($putresult eq 'ok') {
21562: if (keys(%changes) > 0) {
1.213 raeburn 21563: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 21564: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 21565: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.398 raeburn 21566: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
1.422 raeburn 21567: ($changes{'inline_chem'}) || ($changes{'ltiauth'}) || ($changes{'domexttool'}) ||
1.432 raeburn 21568: ($changes{'exttool'}) || ($changes{'coursequota'}) || ($changes{'crsauthor'})) {
1.422 raeburn 21569: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','inline_chem','texengine',
21570: 'ltiauth') {
1.257 raeburn 21571: if ($changes{$item}) {
21572: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
21573: }
1.289 raeburn 21574: }
1.192 raeburn 21575: if ($changes{'coursecredits'}) {
21576: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 21577: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
21578: $domdefaults{$type.'credits'} =
21579: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
21580: }
21581: }
21582: }
21583: if ($changes{'postsubmit'}) {
21584: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21585: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
21586: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21587: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
21588: $domdefaults{$type.'postsubtimeout'} =
21589: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21590: }
21591: }
1.192 raeburn 21592: }
21593: }
1.198 raeburn 21594: if ($changes{'uploadquota'}) {
21595: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21596: foreach my $type (@types) {
21597: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
21598: }
21599: }
21600: }
1.428 raeburn 21601: if ($changes{'coursequota'}) {
21602: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
21603: foreach my $type (@types) {
21604: $domdefaults{$type.'coursequota'}=$defaultshash{'coursedefaults'}{'coursequota'}{$type};
21605: }
21606: }
21607: }
1.264 raeburn 21608: if ($changes{'canclone'}) {
21609: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21610: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21611: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
21612: if (@clonecodes) {
21613: $domdefaults{'canclone'} = join('+',@clonecodes);
21614: }
21615: }
21616: } else {
21617: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
21618: }
21619: }
1.422 raeburn 21620: if ($changes{'domexttool'}) {
21621: if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21622: foreach my $type (@types) {
21623: $domdefaults{$type.'domexttool'}=$defaultshash{'coursedefaults'}{'domexttool'}{$type};
21624: }
21625: }
21626: }
21627: if ($changes{'exttool'}) {
21628: if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
21629: foreach my $type (@types) {
21630: $domdefaults{$type.'exttool'}=$defaultshash{'coursedefaults'}{'exttool'}{$type};
21631: }
21632: }
21633: }
1.432 raeburn 21634: if ($changes{'crsauthor'}) {
21635: if (ref($defaultshash{'coursedefaults'}{'crsauthor'}) eq 'HASH') {
21636: foreach my $type (@types) {
21637: $domdefaults{$type.'crsauthor'}=$defaultshash{'coursedefaults'}{'crsauthor'}{$type};
21638: }
21639: }
21640: }
1.438 raeburn 21641: if ($changes{'crseditors'}) {
21642: if (ref($defaultshash{'coursedefaults'}{'crseditors'}) eq 'ARRAY') {
21643: $domdefaults{'crseditors'}=join(',',@{$defaultshash{'coursedefaults'}{'crseditors'}});
21644: }
21645: }
1.121 raeburn 21646: my $cachetime = 24*60*60;
21647: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 21648: if (ref($lastactref) eq 'HASH') {
21649: $lastactref->{'domdefaults'} = 1;
21650: }
1.121 raeburn 21651: }
21652: $resulttext = &mt('Changes made:').'<ul>';
21653: foreach my $item (sort(keys(%changes))) {
21654: if ($item eq 'canuse_pdfforms') {
21655: if ($env{'form.'.$item} eq '1') {
21656: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
21657: } else {
21658: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
21659: }
1.257 raeburn 21660: } elsif ($item eq 'uselcmath') {
21661: if ($env{'form.'.$item} eq '1') {
21662: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
21663: } else {
21664: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
21665: }
21666: } elsif ($item eq 'usejsme') {
21667: if ($env{'form.'.$item} eq '1') {
21668: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
21669: } else {
1.289 raeburn 21670: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 21671: }
1.398 raeburn 21672: } elsif ($item eq 'inline_chem') {
21673: if ($env{'form.'.$item} eq '1') {
21674: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
21675: } else {
21676: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
21677: }
1.314 raeburn 21678: } elsif ($item eq 'texengine') {
21679: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
21680: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
21681: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
21682: }
1.139 raeburn 21683: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 21684: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 21685: } elsif ($item eq 'uploadquota') {
21686: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21687: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
21688: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
21689: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 21690: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 21691: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 21692: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
21693: '</ul>'.
21694: '</li>';
21695: } else {
21696: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
21697: }
1.428 raeburn 21698: } elsif ($item eq 'coursequota') {
21699: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
21700: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course set as follows:').'<ul>'.
21701: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'official'}.'</b>').'</li>'.
21702: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'unofficial'}.'</b>').'</li>'.
21703: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'textbook'}.'</b>').'</li>'.
21704: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'placement'}.'</b>').'</li>'.
21705: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'community'}.'</b>').'</li>'.
21706: '</ul>'.
21707: '</li>';
21708: } else {
21709: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course remains default: [_1] MB',$staticdefaults{'coursequota'}).'</li>';
21710: }
1.276 raeburn 21711: } elsif ($item eq 'mysqltables') {
21712: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
21713: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
21714: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
21715: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
21716: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
21717: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
21718: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
21719: '</ul>'.
21720: '</li>';
21721: } else {
21722: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
21723: }
1.257 raeburn 21724: } elsif ($item eq 'postsubmit') {
21725: if ($domdefaults{'postsubmit'} eq 'off') {
21726: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
21727: } else {
21728: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 21729: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 21730: $resulttext .= &mt('durations:').'<ul>';
21731: foreach my $type (@types) {
21732: $resulttext .= '<li>';
21733: my $timeout;
21734: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21735: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21736: }
21737: my $display;
21738: if ($timeout eq '0') {
21739: $display = &mt('unlimited');
21740: } elsif ($timeout eq '') {
21741: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
21742: } else {
21743: $display = &mt('[quant,_1,second]',$timeout);
21744: }
21745: if ($type eq 'community') {
21746: $resulttext .= &mt('Communities');
21747: } elsif ($type eq 'official') {
21748: $resulttext .= &mt('Official courses');
21749: } elsif ($type eq 'unofficial') {
21750: $resulttext .= &mt('Unofficial courses');
21751: } elsif ($type eq 'textbook') {
21752: $resulttext .= &mt('Textbook courses');
1.271 raeburn 21753: } elsif ($type eq 'placement') {
21754: $resulttext .= &mt('Placement tests');
1.257 raeburn 21755: }
21756: $resulttext .= ' -- '.$display.'</li>';
21757: }
21758: $resulttext .= '</ul>';
21759: }
1.289 raeburn 21760: $resulttext .= '</li>';
1.257 raeburn 21761: }
1.192 raeburn 21762: } elsif ($item eq 'coursecredits') {
21763: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21764: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 21765: ($domdefaults{'unofficialcredits'} eq '') &&
21766: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 21767: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21768: } else {
21769: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
21770: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
21771: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 21772: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 21773: '</ul>'.
21774: '</li>';
21775: }
21776: } else {
21777: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21778: }
1.264 raeburn 21779: } elsif ($item eq 'canclone') {
21780: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21781: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21782: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
21783: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
21784: }
21785: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
21786: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
21787: } else {
1.289 raeburn 21788: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 21789: }
1.404 raeburn 21790: } elsif ($item eq 'ltiauth') {
21791: if ($env{'form.'.$item} eq '1') {
21792: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
21793: } else {
21794: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
21795: }
1.432 raeburn 21796: } elsif (($item eq 'domexttool') || ($item eq 'exttool') || ($item eq 'crsauthor')) {
1.422 raeburn 21797: my @noyes = (&mt('no'),&mt('yes'));
1.432 raeburn 21798: my %status = (
21799: domexttool => {
21800: ishash => &mt('External Tools defined in the domain may be used as follows:'),
21801: default => &mt('External Tools defined in the domain may be used in all course types, by default'),
21802: },
21803: exttool => {
21804: ishash => &mt('External Tools can be defined and configured in course containers as follows:'),
21805: default => &mt('External Tools can not be defined in any course types, by default'),
21806: },
21807: crsauthor => {
21808: ishash => &mt('Standard Problems can be created within course containers as follows:'),
21809: default => &mt('Standard Problems can be created within any course type, by default'),
21810: },
21811: );
21812:
21813: if (ref($defaultshash{'coursedefaults'}{$item}) eq 'HASH') {
21814: $resulttext .= '<li>'.$status{$item}{'ishash'}.'<ul>'.
21815: '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'official'}].'</b>').'</li>'.
21816: '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'unofficial'}].'</b>').'</li>'.
21817: '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'textbook'}].'</b>').'</li>'.
21818: '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'placement'}].'</b>').'</li>'.
21819: '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'community'}].'</b>').'</li>'.
1.422 raeburn 21820: '</ul>'.
21821: '</li>';
21822: } else {
1.432 raeburn 21823: $resulttext .= '<li>'.$status{$item}{'default'}.'</li>';
1.422 raeburn 21824: }
1.438 raeburn 21825: } elsif ($item eq 'crseditors') {
21826: if (ref($defaultshash{'coursedefaults'}{$item}) eq 'ARRAY') {
21827: my $shown;
21828: if (@{$defaultshash{'coursedefaults'}{$item}}) {
21829: $shown = join(', ', map { $editornames{$_} } @{$defaultshash{'coursedefaults'}{$item}});
21830: } else {
21831: $shown = &mt('None');
21832: }
21833: $resulttext .= '<li>'.&mt('Available editors for course/community resources: [_1]',$shown).'</li>';
21834: }
1.140 raeburn 21835: }
1.121 raeburn 21836: }
21837: $resulttext .= '</ul>';
21838: } else {
21839: $resulttext = &mt('No changes made to course defaults');
21840: }
21841: } else {
21842: $resulttext = '<span class="LC_error">'.
21843: &mt('An error occurred: [_1]',$putresult).'</span>';
21844: }
21845: return $resulttext;
21846: }
21847:
1.231 raeburn 21848: sub modify_selfenrollment {
21849: my ($dom,$lastactref,%domconfig) = @_;
21850: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 21851: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 21852: my %titles = &tool_titles();
1.232 raeburn 21853: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
21854: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 21855: $ordered{'default'} = ['types','registered','approval','limit'];
21856:
21857: my (%roles,%shown,%toplevel);
21858: $roles{'0'} = &Apache::lonnet::plaintext('dc');
21859:
21860: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
21861: if ($domconfig{'selfenrollment'} eq '') {
21862: $domconfig{'selfenrollment'} = {};
21863: }
21864: }
21865: %toplevel = (
21866: admin => 'Configuration Rights',
21867: default => 'Default settings',
21868: validation => 'Validation of self-enrollment requests',
21869: );
1.233 raeburn 21870: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 21871:
21872: if (ref($ordered{'admin'}) eq 'ARRAY') {
21873: foreach my $item (@{$ordered{'admin'}}) {
21874: foreach my $type (@types) {
21875: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
21876: $selfenrollhash{'admin'}{$type}{$item} = 1;
21877: } else {
21878: $selfenrollhash{'admin'}{$type}{$item} = 0;
21879: }
21880: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
21881: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
21882: if ($selfenrollhash{'admin'}{$type}{$item} ne
21883: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
21884: push(@{$changes{'admin'}{$type}},$item);
21885: }
21886: } else {
21887: if (!$selfenrollhash{'admin'}{$type}{$item}) {
21888: push(@{$changes{'admin'}{$type}},$item);
21889: }
21890: }
21891: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
21892: push(@{$changes{'admin'}{$type}},$item);
21893: }
21894: }
21895: }
21896: }
21897:
21898: foreach my $item (@{$ordered{'default'}}) {
21899: foreach my $type (@types) {
21900: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
21901: if ($item eq 'types') {
21902: unless (($value eq 'all') || ($value eq 'dom')) {
21903: $value = '';
21904: }
21905: } elsif ($item eq 'registered') {
21906: unless ($value eq '1') {
21907: $value = 0;
21908: }
21909: } elsif ($item eq 'approval') {
21910: unless ($value =~ /^[012]$/) {
21911: $value = 0;
21912: }
21913: } else {
21914: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21915: $value = 'none';
21916: }
21917: }
21918: $selfenrollhash{'default'}{$type}{$item} = $value;
21919: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
21920: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21921: if ($selfenrollhash{'default'}{$type}{$item} ne
21922: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
21923: push(@{$changes{'default'}{$type}},$item);
21924: }
21925: } else {
21926: push(@{$changes{'default'}{$type}},$item);
21927: }
21928: } else {
21929: push(@{$changes{'default'}{$type}},$item);
21930: }
21931: if ($item eq 'limit') {
21932: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21933: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
21934: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
21935: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
21936: }
21937: } else {
21938: $selfenrollhash{'default'}{$type}{'cap'} = '';
21939: }
21940: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21941: if ($selfenrollhash{'default'}{$type}{'cap'} ne
21942: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
21943: push(@{$changes{'default'}{$type}},'cap');
21944: }
21945: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
21946: push(@{$changes{'default'}{$type}},'cap');
21947: }
21948: }
21949: }
21950: }
21951:
21952: foreach my $item (@{$itemsref}) {
21953: if ($item eq 'fields') {
21954: my @changed;
21955: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
21956: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
21957: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
21958: }
21959: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21960: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
21961: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
21962: $domconfig{'selfenrollment'}{'validation'}{$item});
21963: } else {
21964: @changed = @{$selfenrollhash{'validation'}{$item}};
21965: }
21966: } else {
21967: @changed = @{$selfenrollhash{'validation'}{$item}};
21968: }
21969: if (@changed) {
21970: if ($selfenrollhash{'validation'}{$item}) {
21971: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
21972: } else {
21973: $changes{'validation'}{$item} = &mt('None');
21974: }
21975: }
21976: } else {
21977: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
21978: if ($item eq 'markup') {
21979: if ($env{'form.selfenroll_validation_'.$item}) {
21980: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
21981: }
21982: }
21983: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21984: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
21985: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
21986: }
21987: }
21988: }
21989: }
21990:
21991: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
21992: $dom);
21993: if ($putresult eq 'ok') {
21994: if (keys(%changes) > 0) {
21995: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
21996: $resulttext = &mt('Changes made:').'<ul>';
21997: foreach my $key ('admin','default','validation') {
21998: if (ref($changes{$key}) eq 'HASH') {
21999: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
22000: if ($key eq 'validation') {
22001: foreach my $item (@{$itemsref}) {
22002: if (exists($changes{$key}{$item})) {
22003: if ($item eq 'markup') {
22004: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
22005: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
22006: } else {
22007: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
22008: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
22009: }
22010: }
22011: }
22012: } else {
22013: foreach my $type (@types) {
22014: if ($type eq 'community') {
22015: $roles{'1'} = &mt('Community personnel');
22016: } else {
22017: $roles{'1'} = &mt('Course personnel');
22018: }
22019: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 22020: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
22021: if ($key eq 'admin') {
22022: my @mgrdc = ();
22023: if (ref($ordered{$key}) eq 'ARRAY') {
22024: foreach my $item (@{$ordered{'admin'}}) {
22025: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
22026: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
22027: push(@mgrdc,$item);
22028: }
22029: }
22030: }
22031: if (@mgrdc) {
22032: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
22033: } else {
22034: delete($domdefaults{$type.'selfenrolladmdc'});
22035: }
22036: }
22037: } else {
22038: if (ref($ordered{$key}) eq 'ARRAY') {
22039: foreach my $item (@{$ordered{$key}}) {
22040: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
22041: $domdefaults{$type.'selfenroll'.$item} =
22042: $selfenrollhash{$key}{$type}{$item};
22043: }
22044: }
22045: }
22046: }
22047: }
1.231 raeburn 22048: $resulttext .= '<li>'.$titles{$type}.'<ul>';
22049: foreach my $item (@{$ordered{$key}}) {
22050: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
22051: $resulttext .= '<li>';
22052: if ($key eq 'admin') {
22053: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
22054: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
22055: } else {
22056: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
22057: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
22058: }
22059: $resulttext .= '</li>';
22060: }
22061: }
22062: $resulttext .= '</ul></li>';
22063: }
22064: }
22065: $resulttext .= '</ul></li>';
22066: }
22067: }
1.305 raeburn 22068: }
22069: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
22070: my $cachetime = 24*60*60;
22071: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22072: if (ref($lastactref) eq 'HASH') {
22073: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 22074: }
1.231 raeburn 22075: }
22076: $resulttext .= '</ul>';
22077: } else {
22078: $resulttext = &mt('No changes made to self-enrollment settings');
22079: }
22080: } else {
22081: $resulttext = '<span class="LC_error">'.
22082: &mt('An error occurred: [_1]',$putresult).'</span>';
22083: }
22084: return $resulttext;
22085: }
22086:
1.373 raeburn 22087: sub modify_wafproxy {
22088: my ($dom,$action,$lastactref,%domconfig) = @_;
22089: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 22090: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
22091: %wafproxy,%changes,%expirecache,%expiresaml);
1.373 raeburn 22092: foreach my $server (sort(keys(%servers))) {
22093: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
22094: if ($serverhome eq $server) {
22095: my $serverdom = &Apache::lonnet::host_domain($server);
22096: if ($serverdom eq $dom) {
22097: $canset{$server} = 1;
22098: }
22099: }
22100: }
1.381 raeburn 22101: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
22102: %{$values{$dom}} = ();
22103: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
22104: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
22105: }
1.388 raeburn 22106: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
22107: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
22108: }
1.382 raeburn 22109: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.381 raeburn 22110: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
22111: }
22112: }
1.373 raeburn 22113: my $output;
22114: if (keys(%canset)) {
22115: %{$wafproxy{'alias'}} = ();
1.388 raeburn 22116: %{$wafproxy{'saml'}} = ();
1.373 raeburn 22117: foreach my $key (sort(keys(%canset))) {
1.381 raeburn 22118: if ($env{'form.wafproxy_'.$dom}) {
22119: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
22120: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
22121: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
22122: $changes{'alias'} = 1;
22123: }
1.388 raeburn 22124: if ($env{'form.wafproxy_alias_saml_'.$key}) {
22125: $wafproxy{'saml'}{$key} = 1;
22126: }
22127: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
22128: $changes{'saml'} = 1;
22129: }
1.381 raeburn 22130: } else {
22131: $wafproxy{'alias'}{$key} = '';
1.388 raeburn 22132: $wafproxy{'saml'}{$key} = '';
1.381 raeburn 22133: if ($curralias{$key}) {
22134: $changes{'alias'} = 1;
22135: }
1.388 raeburn 22136: if ($currsaml{$key}) {
22137: $changes{'saml'} = 1;
22138: }
1.373 raeburn 22139: }
22140: if ($wafproxy{'alias'}{$key} eq '') {
22141: if ($curralias{$key}) {
22142: $expirecache{$key} = 1;
22143: }
22144: delete($wafproxy{'alias'}{$key});
22145: }
1.388 raeburn 22146: if ($wafproxy{'saml'}{$key} eq '') {
22147: if ($currsaml{$key}) {
22148: $expiresaml{$key} = 1;
22149: }
22150: delete($wafproxy{'saml'}{$key});
22151: }
1.373 raeburn 22152: }
22153: unless (keys(%{$wafproxy{'alias'}})) {
22154: delete($wafproxy{'alias'});
22155: }
1.388 raeburn 22156: unless (keys(%{$wafproxy{'saml'}})) {
22157: delete($wafproxy{'saml'});
22158: }
22159: # Localization for values in %warn occurs in &mt() calls separately.
1.373 raeburn 22160: my %warn = (
22161: trusted => 'trusted IP range(s)',
1.381 raeburn 22162: vpnint => 'internal IP range(s) for VPN sessions(s)',
22163: vpnext => 'IP range(s) for backend WAF connections',
1.373 raeburn 22164: );
1.382 raeburn 22165: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22166: my $possible = $env{'form.wafproxy_'.$item};
22167: $possible =~ s/^\s+|\s+$//g;
22168: if ($possible ne '') {
1.381 raeburn 22169: if ($item eq 'remoteip') {
22170: if ($possible =~ /^[mhn]$/) {
22171: $wafproxy{$item} = $possible;
22172: }
22173: } elsif ($item eq 'ipheader') {
22174: if ($wafproxy{'remoteip'} eq 'h') {
22175: $wafproxy{$item} = $possible;
22176: }
1.382 raeburn 22177: } elsif ($item eq 'sslopt') {
22178: if ($possible =~ /^0|1$/) {
22179: $wafproxy{$item} = $possible;
22180: }
1.373 raeburn 22181: } else {
22182: my (@ok,$count);
1.381 raeburn 22183: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
22184: unless ($env{'form.wafproxy_vpnaccess'}) {
22185: $possible = '';
22186: }
22187: } elsif ($item eq 'trusted') {
22188: unless ($wafproxy{'remoteip'} eq 'h') {
22189: $possible = '';
22190: }
22191: }
22192: unless ($possible eq '') {
22193: $possible =~ s/[\r\n]+/\s/g;
22194: $possible =~ s/\s*-\s*/-/g;
22195: $possible =~ s/\s+/,/g;
1.393 raeburn 22196: $possible =~ s/,+/,/g;
1.381 raeburn 22197: }
1.373 raeburn 22198: $count = 0;
1.381 raeburn 22199: if ($possible ne '') {
1.373 raeburn 22200: foreach my $poss (split(/\,/,$possible)) {
22201: $count ++;
1.393 raeburn 22202: $poss = &validate_ip_pattern($poss);
22203: if ($poss ne '') {
1.373 raeburn 22204: push(@ok,$poss);
22205: }
22206: }
22207: my $diff = $count - scalar(@ok);
22208: if ($diff) {
22209: push(@warnings,'<li>'.
22210: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
22211: $diff,$warn{$item}).
22212: '</li>');
22213: }
1.393 raeburn 22214: if (@ok) {
22215: my @cidr_list;
22216: foreach my $item (@ok) {
22217: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
22218: }
22219: $wafproxy{$item} = join(',',@cidr_list);
22220: }
1.373 raeburn 22221: }
22222: }
1.381 raeburn 22223: if ($wafproxy{$item} ne $currvalue{$item}) {
1.373 raeburn 22224: $changes{$item} = 1;
22225: }
1.381 raeburn 22226: } elsif ($currvalue{$item}) {
22227: $changes{$item} = 1;
1.425 raeburn 22228: }
1.381 raeburn 22229: }
22230: } else {
22231: if (keys(%curralias)) {
22232: $changes{'alias'} = 1;
1.388 raeburn 22233: }
22234: if (keys(%currsaml)) {
22235: $changes{'saml'} = 1;
1.425 raeburn 22236: }
1.381 raeburn 22237: if (keys(%currvalue)) {
22238: foreach my $key (keys(%currvalue)) {
22239: $changes{$key} = 1;
1.373 raeburn 22240: }
22241: }
22242: }
22243: if (keys(%changes)) {
22244: my %defaultshash = (
22245: wafproxy => \%wafproxy,
1.425 raeburn 22246: );
1.373 raeburn 22247: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22248: $dom);
22249: if ($putresult eq 'ok') {
22250: my $cachetime = 24*60*60;
22251: my (%domdefaults,$updatedomdefs);
1.382 raeburn 22252: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22253: if ($changes{$item}) {
22254: unless ($updatedomdefs) {
22255: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
22256: $updatedomdefs = 1;
22257: }
22258: if ($wafproxy{$item}) {
22259: $domdefaults{'waf_'.$item} = $wafproxy{$item};
22260: } elsif (exists($domdefaults{'waf_'.$item})) {
22261: delete($domdefaults{'waf_'.$item});
1.425 raeburn 22262: }
1.373 raeburn 22263: }
22264: }
22265: if ($updatedomdefs) {
22266: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22267: if (ref($lastactref) eq 'HASH') {
22268: $lastactref->{'domdefaults'} = 1;
22269: }
22270: }
22271: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
22272: my %updates = %expirecache;
22273: foreach my $key (keys(%expirecache)) {
22274: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
22275: }
22276: if (ref($wafproxy{'alias'}) eq 'HASH') {
22277: my $cachetime = 24*60*60;
22278: foreach my $key (keys(%{$wafproxy{'alias'}})) {
22279: $updates{$key} = 1;
22280: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
22281: $cachetime);
22282: }
22283: }
22284: if (ref($lastactref) eq 'HASH') {
22285: $lastactref->{'proxyalias'} = \%updates;
22286: }
22287: }
1.388 raeburn 22288: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
22289: my %samlupdates = %expiresaml;
22290: foreach my $key (keys(%expiresaml)) {
22291: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
22292: }
22293: if (ref($wafproxy{'saml'}) eq 'HASH') {
22294: my $cachetime = 24*60*60;
22295: foreach my $key (keys(%{$wafproxy{'saml'}})) {
22296: $samlupdates{$key} = 1;
22297: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
22298: $cachetime);
22299: }
22300: }
22301: if (ref($lastactref) eq 'HASH') {
22302: $lastactref->{'proxysaml'} = \%samlupdates;
22303: }
22304: }
1.373 raeburn 22305: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.401 raeburn 22306: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22307: if ($changes{$item}) {
22308: if ($item eq 'alias') {
22309: my $numaliased = 0;
22310: if (ref($wafproxy{'alias'}) eq 'HASH') {
22311: my $shown;
22312: if (keys(%{$wafproxy{'alias'}})) {
22313: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
22314: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
22315: &Apache::lonnet::hostname($server),
22316: $wafproxy{'alias'}{$server}).'</li>';
22317: $numaliased ++;
22318: }
22319: if ($numaliased) {
22320: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
22321: '<ul>'.$shown.'</ul>').'</li>';
22322: }
22323: }
22324: }
22325: unless ($numaliased) {
22326: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
22327: }
1.388 raeburn 22328: } elsif ($item eq 'saml') {
1.425 raeburn 22329: my $shown;
1.388 raeburn 22330: if (ref($wafproxy{'saml'}) eq 'HASH') {
22331: if (keys(%{$wafproxy{'saml'}})) {
22332: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
22333: }
22334: }
22335: if ($shown) {
1.396 raeburn 22336: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
1.388 raeburn 22337: $shown).'</li>';
22338: } else {
1.396 raeburn 22339: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
1.388 raeburn 22340: }
1.373 raeburn 22341: } else {
1.381 raeburn 22342: if ($item eq 'remoteip') {
22343: my %ip_methods = &remoteip_methods();
22344: if ($wafproxy{$item} =~ /^[mh]$/) {
22345: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
22346: $ip_methods{$wafproxy{$item}}).'</li>';
22347: } else {
22348: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
22349: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
22350: '</li>';
22351: } else {
22352: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
22353: }
22354: }
22355: } elsif ($item eq 'ipheader') {
1.373 raeburn 22356: if ($wafproxy{$item}) {
1.381 raeburn 22357: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
1.373 raeburn 22358: $wafproxy{$item}).'</li>';
22359: } else {
1.381 raeburn 22360: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
1.373 raeburn 22361: }
22362: } elsif ($item eq 'trusted') {
22363: if ($wafproxy{$item}) {
1.381 raeburn 22364: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
1.373 raeburn 22365: $wafproxy{$item}).'</li>';
22366: } else {
22367: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
22368: }
1.381 raeburn 22369: } elsif ($item eq 'vpnint') {
22370: if ($wafproxy{$item}) {
22371: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
22372: $wafproxy{$item}).'</li>';
22373: } else {
22374: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
22375: }
22376: } elsif ($item eq 'vpnext') {
1.373 raeburn 22377: if ($wafproxy{$item}) {
1.381 raeburn 22378: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
1.373 raeburn 22379: $wafproxy{$item}).'</li>';
22380: } else {
1.381 raeburn 22381: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
1.373 raeburn 22382: }
1.382 raeburn 22383: } elsif ($item eq 'sslopt') {
22384: if ($wafproxy{$item}) {
22385: $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>';
22386: } else {
22387: $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>';
22388: }
1.373 raeburn 22389: }
22390: }
22391: }
22392: }
1.420 raeburn 22393: $output .= '</ul>';
1.373 raeburn 22394: } else {
22395: $output = '<span class="LC_error">'.
22396: &mt('An error occurred: [_1]',$putresult).'</span>';
22397: }
22398: } elsif (keys(%canset)) {
22399: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
22400: }
22401: if (@warnings) {
22402: $output .= '<br />'.&mt('Warnings:').'<ul>'.
22403: join("\n",@warnings).'</ul>';
22404: }
22405: return $output;
22406: }
22407:
22408: sub validate_ip_pattern {
22409: my ($pattern) = @_;
22410: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
22411: my ($start,$end) = ($1,$2);
22412: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
1.393 raeburn 22413: if (($start !~ m{/}) && ($end !~ m{/})) {
22414: return $start.'-'.$end;
22415: }
22416: }
22417: } elsif ($pattern ne '') {
22418: $pattern = &Net::CIDR::cidrvalidate($pattern);
22419: if ($pattern ne '') {
22420: return $pattern;
1.373 raeburn 22421: }
22422: }
1.393 raeburn 22423: return;
1.373 raeburn 22424: }
22425:
1.137 raeburn 22426: sub modify_usersessions {
1.212 raeburn 22427: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 22428: my @hostingtypes = ('version','excludedomain','includedomain');
22429: my @offloadtypes = ('primary','default');
22430: my %types = (
22431: remote => \@hostingtypes,
22432: hosted => \@hostingtypes,
22433: spares => \@offloadtypes,
22434: );
22435: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 22436: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 22437: my (%by_ip,%by_location,@intdoms,@instdoms);
22438: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 22439: my @locations = sort(keys(%by_location));
1.137 raeburn 22440: my (%defaultshash,%changes);
22441: foreach my $prefix (@prefixes) {
22442: $defaultshash{'usersessions'}{$prefix} = {};
22443: }
1.212 raeburn 22444: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 22445: my $resulttext;
1.138 raeburn 22446: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 22447: foreach my $prefix (@prefixes) {
1.145 raeburn 22448: next if ($prefix eq 'spares');
22449: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 22450: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22451: if ($type eq 'version') {
22452: my $value = $env{'form.'.$prefix.'_'.$type};
22453: my $okvalue;
22454: if ($value ne '') {
22455: if (grep(/^\Q$value\E$/,@lcversions)) {
22456: $okvalue = $value;
22457: }
22458: }
22459: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22460: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22461: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
22462: if ($inuse == 0) {
22463: $changes{$prefix}{$type} = 1;
22464: } else {
22465: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
22466: $changes{$prefix}{$type} = 1;
22467: }
22468: if ($okvalue ne '') {
22469: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22470: }
22471: }
22472: } else {
22473: if (($inuse == 1) && ($okvalue ne '')) {
22474: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22475: $changes{$prefix}{$type} = 1;
22476: }
22477: }
22478: } else {
22479: if (($inuse == 1) && ($okvalue ne '')) {
22480: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22481: $changes{$prefix}{$type} = 1;
22482: }
22483: }
22484: } else {
22485: if (($inuse == 1) && ($okvalue ne '')) {
22486: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22487: $changes{$prefix}{$type} = 1;
22488: }
22489: }
22490: } else {
22491: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22492: my @okvals;
22493: foreach my $val (@vals) {
1.138 raeburn 22494: if ($val =~ /:/) {
22495: my @items = split(/:/,$val);
22496: foreach my $item (@items) {
22497: if (ref($by_location{$item}) eq 'ARRAY') {
22498: push(@okvals,$item);
22499: }
22500: }
22501: } else {
22502: if (ref($by_location{$val}) eq 'ARRAY') {
22503: push(@okvals,$val);
22504: }
1.137 raeburn 22505: }
22506: }
22507: @okvals = sort(@okvals);
22508: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22509: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22510: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22511: if ($inuse == 0) {
22512: $changes{$prefix}{$type} = 1;
22513: } else {
22514: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22515: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
22516: if (@changed > 0) {
22517: $changes{$prefix}{$type} = 1;
22518: }
22519: }
22520: } else {
22521: if ($inuse == 1) {
22522: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22523: $changes{$prefix}{$type} = 1;
22524: }
22525: }
22526: } else {
22527: if ($inuse == 1) {
22528: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22529: $changes{$prefix}{$type} = 1;
22530: }
22531: }
22532: } else {
22533: if ($inuse == 1) {
22534: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22535: $changes{$prefix}{$type} = 1;
22536: }
22537: }
22538: }
22539: }
22540: }
1.145 raeburn 22541:
22542: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 22543: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 22544: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
22545: my $savespares;
22546:
22547: foreach my $lonhost (sort(keys(%servers))) {
22548: my $serverhomeID =
22549: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 22550: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 22551: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
22552: my %spareschg;
22553: foreach my $type (@{$types{'spares'}}) {
22554: my @okspares;
22555: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
22556: foreach my $server (@checked) {
1.152 raeburn 22557: if (&Apache::lonnet::hostname($server) ne '') {
22558: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
22559: unless (grep(/^\Q$server\E$/,@okspares)) {
22560: push(@okspares,$server);
22561: }
1.145 raeburn 22562: }
22563: }
22564: }
22565: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
22566: my $newspare;
1.152 raeburn 22567: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
22568: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 22569: $newspare = $new;
22570: }
22571: }
1.152 raeburn 22572: my @spares;
22573: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
22574: @spares = sort(@okspares,$newspare);
22575: } else {
22576: @spares = sort(@okspares);
22577: }
22578: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 22579: if (ref($spareid{$lonhost}) eq 'HASH') {
22580: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 22581: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 22582: if (@diffs > 0) {
22583: $spareschg{$type} = 1;
22584: }
22585: }
22586: }
22587: }
22588: if (keys(%spareschg) > 0) {
22589: $changes{'spares'}{$lonhost} = \%spareschg;
22590: }
22591: }
1.261 raeburn 22592: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371 raeburn 22593: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261 raeburn 22594: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
22595: my @okoffload;
22596: if (@offloadnow) {
22597: foreach my $server (@offloadnow) {
22598: if (&Apache::lonnet::hostname($server) ne '') {
22599: unless (grep(/^\Q$server\E$/,@okoffload)) {
22600: push(@okoffload,$server);
22601: }
22602: }
22603: }
22604: if (@okoffload) {
22605: foreach my $lonhost (@okoffload) {
22606: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
22607: }
22608: }
22609: }
1.371 raeburn 22610: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
22611: my @okoffloadoth;
22612: if (@offloadoth) {
22613: foreach my $server (@offloadoth) {
22614: if (&Apache::lonnet::hostname($server) ne '') {
22615: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
22616: push(@okoffloadoth,$server);
22617: }
22618: }
22619: }
22620: if (@okoffloadoth) {
22621: foreach my $lonhost (@okoffloadoth) {
22622: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
22623: }
22624: }
22625: }
1.145 raeburn 22626: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22627: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
22628: if (ref($changes{'spares'}) eq 'HASH') {
22629: if (keys(%{$changes{'spares'}}) > 0) {
22630: $savespares = 1;
22631: }
22632: }
22633: } else {
22634: $savespares = 1;
22635: }
1.371 raeburn 22636: foreach my $offload ('offloadnow','offloadoth') {
22637: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
22638: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
22639: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
22640: $changes{$offload} = 1;
22641: last;
22642: }
1.261 raeburn 22643: }
1.371 raeburn 22644: unless ($changes{$offload}) {
22645: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
22646: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
22647: $changes{$offload} = 1;
22648: last;
22649: }
1.261 raeburn 22650: }
22651: }
1.371 raeburn 22652: } else {
22653: if (($offload eq 'offloadnow') && (@okoffload)) {
22654: $changes{'offloadnow'} = 1;
22655: }
22656: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
22657: $changes{'offloadoth'} = 1;
22658: }
1.425 raeburn 22659: }
1.371 raeburn 22660: }
22661: } else {
22662: if (@okoffload) {
1.261 raeburn 22663: $changes{'offloadnow'} = 1;
22664: }
1.371 raeburn 22665: if (@okoffloadoth) {
22666: $changes{'offloadoth'} = 1;
22667: }
1.145 raeburn 22668: }
1.147 raeburn 22669: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
22670: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 22671: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22672: $dom);
22673: if ($putresult eq 'ok') {
22674: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22675: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
22676: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
22677: }
22678: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
22679: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
22680: }
1.261 raeburn 22681: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22682: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
22683: }
1.371 raeburn 22684: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22685: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
22686: }
1.137 raeburn 22687: }
22688: my $cachetime = 24*60*60;
22689: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 22690: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 22691: if (ref($lastactref) eq 'HASH') {
22692: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 22693: $lastactref->{'usersessions'} = 1;
1.212 raeburn 22694: }
1.147 raeburn 22695: if (keys(%changes) > 0) {
22696: my %lt = &usersession_titles();
22697: $resulttext = &mt('Changes made:').'<ul>';
22698: foreach my $prefix (@prefixes) {
22699: if (ref($changes{$prefix}) eq 'HASH') {
22700: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
22701: if ($prefix eq 'spares') {
22702: if (ref($changes{$prefix}) eq 'HASH') {
22703: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
22704: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 22705: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 22706: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
22707: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 22708: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
22709: foreach my $type (@{$types{$prefix}}) {
22710: if ($changes{$prefix}{$lonhost}{$type}) {
22711: my $offloadto = &mt('None');
22712: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
22713: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
22714: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
22715: }
1.145 raeburn 22716: }
1.147 raeburn 22717: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 22718: }
1.137 raeburn 22719: }
22720: }
1.147 raeburn 22721: $resulttext .= '</li>';
1.137 raeburn 22722: }
22723: }
1.147 raeburn 22724: } else {
22725: foreach my $type (@{$types{$prefix}}) {
22726: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22727: my ($newvalue,$notinuse);
1.147 raeburn 22728: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22729: if (ref($defaultshash{'usersessions'}{$prefix})) {
22730: if ($type eq 'version') {
22731: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 22732: } else {
22733: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22734: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
22735: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
22736: }
22737: } else {
22738: $notinuse = 1;
1.147 raeburn 22739: }
1.145 raeburn 22740: }
22741: }
22742: }
1.147 raeburn 22743: if ($newvalue eq '') {
22744: if ($type eq 'version') {
22745: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 22746: } elsif ($notinuse) {
22747: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 22748: } else {
22749: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
22750: }
1.145 raeburn 22751: } else {
1.147 raeburn 22752: if ($type eq 'version') {
1.344 raeburn 22753: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 22754: }
22755: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 22756: }
1.137 raeburn 22757: }
22758: }
22759: }
1.147 raeburn 22760: $resulttext .= '</ul>';
1.137 raeburn 22761: }
22762: }
1.261 raeburn 22763: if ($changes{'offloadnow'}) {
22764: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22765: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371 raeburn 22766: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261 raeburn 22767: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
22768: $resulttext .= '<li>'.$lonhost.'</li>';
22769: }
22770: $resulttext .= '</ul>';
22771: } else {
1.371 raeburn 22772: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
22773: }
22774: } else {
22775: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
22776: }
22777: }
22778: if ($changes{'offloadoth'}) {
22779: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22780: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
22781: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
22782: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
22783: $resulttext .= '<li>'.$lonhost.'</li>';
22784: }
22785: $resulttext .= '</ul>';
22786: } else {
22787: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261 raeburn 22788: }
22789: } else {
1.371 raeburn 22790: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261 raeburn 22791: }
22792: }
1.147 raeburn 22793: $resulttext .= '</ul>';
22794: } else {
22795: $resulttext = $nochgmsg;
1.137 raeburn 22796: }
22797: } else {
22798: $resulttext = '<span class="LC_error">'.
22799: &mt('An error occurred: [_1]',$putresult).'</span>';
22800: }
22801: } else {
1.147 raeburn 22802: $resulttext = $nochgmsg;
1.137 raeburn 22803: }
22804: return $resulttext;
22805: }
22806:
1.275 raeburn 22807: sub modify_ssl {
22808: my ($dom,$lastactref,%domconfig) = @_;
22809: my (%by_ip,%by_location,@intdoms,@instdoms);
22810: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
22811: my @locations = sort(keys(%by_location));
22812: my %servers = &Apache::lonnet::internet_dom_servers($dom);
22813: my (%defaultshash,%changes);
22814: my $action = 'ssl';
1.293 raeburn 22815: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 22816: foreach my $prefix (@prefixes) {
22817: $defaultshash{$action}{$prefix} = {};
22818: }
22819: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22820: my $resulttext;
22821: my %iphost = &Apache::lonnet::get_iphost();
22822: my @reptypes = ('certreq','nocertreq');
22823: my @connecttypes = ('dom','intdom','other');
22824: my %types = (
1.293 raeburn 22825: connto => \@connecttypes,
22826: connfrom => \@connecttypes,
22827: replication => \@reptypes,
1.275 raeburn 22828: );
22829: foreach my $prefix (sort(keys(%types))) {
22830: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 22831: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22832: my $value = 'yes';
22833: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
22834: $value = $env{'form.'.$prefix.'_'.$type};
22835: }
1.335 raeburn 22836: if (ref($domconfig{$action}) eq 'HASH') {
22837: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22838: if ($domconfig{$action}{$prefix}{$type} ne '') {
22839: if ($value ne $domconfig{$action}{$prefix}{$type}) {
22840: $changes{$prefix}{$type} = 1;
22841: }
22842: $defaultshash{$action}{$prefix}{$type} = $value;
22843: } else {
22844: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 22845: $changes{$prefix}{$type} = 1;
22846: }
22847: } else {
22848: $defaultshash{$action}{$prefix}{$type} = $value;
22849: $changes{$prefix}{$type} = 1;
22850: }
22851: } else {
22852: $defaultshash{$action}{$prefix}{$type} = $value;
22853: $changes{$prefix}{$type} = 1;
22854: }
22855: if (($type eq 'dom') && (keys(%servers) == 1)) {
22856: delete($changes{$prefix}{$type});
22857: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
22858: delete($changes{$prefix}{$type});
22859: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
22860: delete($changes{$prefix}{$type});
22861: }
22862: } elsif ($prefix eq 'replication') {
22863: if (@locations > 0) {
22864: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22865: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22866: my @okvals;
22867: foreach my $val (@vals) {
22868: if ($val =~ /:/) {
22869: my @items = split(/:/,$val);
22870: foreach my $item (@items) {
22871: if (ref($by_location{$item}) eq 'ARRAY') {
22872: push(@okvals,$item);
22873: }
22874: }
22875: } else {
22876: if (ref($by_location{$val}) eq 'ARRAY') {
22877: push(@okvals,$val);
22878: }
22879: }
22880: }
22881: @okvals = sort(@okvals);
22882: if (ref($domconfig{$action}) eq 'HASH') {
22883: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22884: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
22885: if ($inuse == 0) {
22886: $changes{$prefix}{$type} = 1;
22887: } else {
22888: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22889: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
22890: if (@changed > 0) {
22891: $changes{$prefix}{$type} = 1;
22892: }
22893: }
22894: } else {
22895: if ($inuse == 1) {
22896: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22897: $changes{$prefix}{$type} = 1;
22898: }
22899: }
22900: } else {
22901: if ($inuse == 1) {
22902: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22903: $changes{$prefix}{$type} = 1;
22904: }
22905: }
22906: } else {
22907: if ($inuse == 1) {
22908: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22909: $changes{$prefix}{$type} = 1;
22910: }
22911: }
22912: }
22913: }
22914: }
22915: }
1.336 raeburn 22916: if (keys(%changes)) {
22917: foreach my $prefix (keys(%changes)) {
22918: if (ref($changes{$prefix}) eq 'HASH') {
22919: if (scalar(keys(%{$changes{$prefix}})) == 0) {
22920: delete($changes{$prefix});
22921: }
22922: } else {
22923: delete($changes{$prefix});
22924: }
22925: }
22926: }
1.275 raeburn 22927: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
22928: if (keys(%changes) > 0) {
22929: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22930: $dom);
22931: if ($putresult eq 'ok') {
22932: if (ref($defaultshash{$action}) eq 'HASH') {
22933: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
22934: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
22935: }
1.293 raeburn 22936: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 22937: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 22938: }
22939: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 22940: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 22941: }
22942: }
22943: my $cachetime = 24*60*60;
22944: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22945: if (ref($lastactref) eq 'HASH') {
22946: $lastactref->{'domdefaults'} = 1;
22947: }
22948: if (keys(%changes) > 0) {
22949: my %titles = &ssl_titles();
22950: $resulttext = &mt('Changes made:').'<ul>';
22951: foreach my $prefix (@prefixes) {
22952: if (ref($changes{$prefix}) eq 'HASH') {
22953: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
22954: foreach my $type (@{$types{$prefix}}) {
22955: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22956: my ($newvalue,$notinuse);
1.275 raeburn 22957: if (ref($defaultshash{$action}) eq 'HASH') {
22958: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 22959: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22960: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 22961: } else {
22962: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
22963: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
22964: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
22965: }
22966: } else {
22967: $notinuse = 1;
1.275 raeburn 22968: }
22969: }
22970: }
1.344 raeburn 22971: if ($notinuse) {
22972: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
22973: } elsif ($newvalue eq '') {
1.275 raeburn 22974: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
22975: } else {
22976: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
22977: }
22978: }
22979: }
22980: }
22981: $resulttext .= '</ul>';
22982: }
22983: }
22984: } else {
22985: $resulttext = $nochgmsg;
22986: }
22987: } else {
22988: $resulttext = '<span class="LC_error">'.
22989: &mt('An error occurred: [_1]',$putresult).'</span>';
22990: }
22991: } else {
22992: $resulttext = $nochgmsg;
22993: }
22994: return $resulttext;
22995: }
22996:
1.279 raeburn 22997: sub modify_trust {
22998: my ($dom,$lastactref,%domconfig) = @_;
22999: my (%by_ip,%by_location,@intdoms,@instdoms);
23000: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
23001: my @locations = sort(keys(%by_location));
23002: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
23003: my @types = ('exc','inc');
23004: my (%defaultshash,%changes);
23005: foreach my $prefix (@prefixes) {
23006: $defaultshash{'trust'}{$prefix} = {};
23007: }
23008: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
23009: my $resulttext;
23010: foreach my $prefix (@prefixes) {
23011: foreach my $type (@types) {
23012: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
23013: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
23014: my @okvals;
23015: foreach my $val (@vals) {
23016: if ($val =~ /:/) {
23017: my @items = split(/:/,$val);
23018: foreach my $item (@items) {
23019: if (ref($by_location{$item}) eq 'ARRAY') {
23020: push(@okvals,$item);
23021: }
23022: }
23023: } else {
23024: if (ref($by_location{$val}) eq 'ARRAY') {
23025: push(@okvals,$val);
23026: }
23027: }
23028: }
23029: @okvals = sort(@okvals);
23030: if (ref($domconfig{'trust'}) eq 'HASH') {
23031: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
23032: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
23033: if ($inuse == 0) {
23034: $changes{$prefix}{$type} = 1;
23035: } else {
23036: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23037: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
23038: if (@changed > 0) {
23039: $changes{$prefix}{$type} = 1;
23040: }
23041: }
23042: } else {
23043: if ($inuse == 1) {
23044: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23045: $changes{$prefix}{$type} = 1;
23046: }
23047: }
23048: } else {
23049: if ($inuse == 1) {
23050: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23051: $changes{$prefix}{$type} = 1;
23052: }
23053: }
23054: } else {
23055: if ($inuse == 1) {
23056: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23057: $changes{$prefix}{$type} = 1;
23058: }
23059: }
23060: }
23061: }
23062: my $nochgmsg = &mt('No changes made to trust settings.');
23063: if (keys(%changes) > 0) {
23064: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
23065: $dom);
23066: if ($putresult eq 'ok') {
23067: if (ref($defaultshash{'trust'}) eq 'HASH') {
23068: foreach my $prefix (@prefixes) {
23069: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
23070: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
23071: }
23072: }
23073: }
23074: my $cachetime = 24*60*60;
23075: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.410 raeburn 23076: &Apache::lonnet::do_cache_new('trust',$dom,$defaultshash{'trust'},3600);
1.279 raeburn 23077: if (ref($lastactref) eq 'HASH') {
23078: $lastactref->{'domdefaults'} = 1;
1.410 raeburn 23079: $lastactref->{'trust'} = 1;
1.279 raeburn 23080: }
23081: if (keys(%changes) > 0) {
23082: my %lt = &trust_titles();
23083: $resulttext = &mt('Changes made:').'<ul>';
23084: foreach my $prefix (@prefixes) {
23085: if (ref($changes{$prefix}) eq 'HASH') {
23086: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
23087: foreach my $type (@types) {
23088: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 23089: my ($newvalue,$notinuse);
1.279 raeburn 23090: if (ref($defaultshash{'trust'}) eq 'HASH') {
23091: if (ref($defaultshash{'trust'}{$prefix})) {
23092: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
23093: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
23094: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
23095: }
1.344 raeburn 23096: } else {
23097: $notinuse = 1;
1.279 raeburn 23098: }
23099: }
23100: }
1.344 raeburn 23101: if ($notinuse) {
23102: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
23103: } elsif ($newvalue eq '') {
1.279 raeburn 23104: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
23105: } else {
23106: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
23107: }
23108: }
23109: }
23110: $resulttext .= '</ul>';
23111: }
23112: }
23113: $resulttext .= '</ul>';
23114: } else {
23115: $resulttext = $nochgmsg;
23116: }
23117: } else {
23118: $resulttext = '<span class="LC_error">'.
23119: &mt('An error occurred: [_1]',$putresult).'</span>';
23120: }
23121: } else {
23122: $resulttext = $nochgmsg;
23123: }
23124: return $resulttext;
23125: }
23126:
1.150 raeburn 23127: sub modify_loadbalancing {
23128: my ($dom,%domconfig) = @_;
23129: my $primary_id = &Apache::lonnet::domain($dom,'primary');
23130: my $intdom = &Apache::lonnet::internet_dom($primary_id);
23131: my ($othertitle,$usertypes,$types) =
23132: &Apache::loncommon::sorted_inst_types($dom);
23133: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 23134: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 23135: my @sparestypes = ('primary','default');
23136: my %typetitles = &sparestype_titles();
23137: my $resulttext;
1.342 raeburn 23138: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 23139: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
23140: %existing = %{$domconfig{'loadbalancing'}};
23141: }
23142: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 23143: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 23144: my ($saveloadbalancing,%defaultshash,%changes);
23145: my ($alltypes,$othertypes,$titles) =
23146: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
23147: my %ruletitles = &offloadtype_text();
23148: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
23149: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
23150: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
23151: if ($balancer eq '') {
23152: next;
23153: }
1.210 raeburn 23154: if (!exists($servers{$balancer})) {
1.171 raeburn 23155: if (exists($currbalancer{$balancer})) {
23156: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 23157: }
1.171 raeburn 23158: next;
23159: }
23160: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
23161: push(@{$changes{'delete'}},$balancer);
23162: next;
23163: }
23164: if (!exists($currbalancer{$balancer})) {
23165: push(@{$changes{'add'}},$balancer);
23166: }
23167: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
23168: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
23169: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
23170: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
23171: $saveloadbalancing = 1;
23172: }
23173: foreach my $sparetype (@sparestypes) {
23174: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
23175: my @offloadto;
23176: foreach my $target (@targets) {
23177: if (($servers{$target}) && ($target ne $balancer)) {
23178: if ($sparetype eq 'default') {
23179: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
23180: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 23181: }
23182: }
1.171 raeburn 23183: unless(grep(/^\Q$target\E$/,@offloadto)) {
23184: push(@offloadto,$target);
23185: }
1.150 raeburn 23186: }
23187: }
1.284 raeburn 23188: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
23189: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
23190: push(@offloadto,$balancer);
23191: }
23192: }
23193: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 23194: }
1.342 raeburn 23195: if ($env{'form.loadbalancing_cookie_'.$i}) {
23196: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
1.425 raeburn 23197: if (exists($currbalancer{$balancer})) {
1.342 raeburn 23198: unless ($currcookies{$balancer}) {
23199: $changes{'curr'}{$balancer}{'cookie'} = 1;
23200: }
23201: }
23202: } elsif (exists($currbalancer{$balancer})) {
23203: if ($currcookies{$balancer}) {
23204: $changes{'curr'}{$balancer}{'cookie'} = 1;
23205: }
23206: }
1.171 raeburn 23207: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 23208: foreach my $sparetype (@sparestypes) {
1.171 raeburn 23209: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
23210: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 23211: if (@targetdiffs > 0) {
1.171 raeburn 23212: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 23213: }
1.171 raeburn 23214: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23215: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23216: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 23217: }
23218: }
23219: }
23220: } else {
1.171 raeburn 23221: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 23222: foreach my $sparetype (@sparestypes) {
1.171 raeburn 23223: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23224: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23225: $changes{'curr'}{$balancer}{'targets'} = 1;
23226: }
1.150 raeburn 23227: }
23228: }
1.210 raeburn 23229: }
1.150 raeburn 23230: }
23231: my $ishomedom;
1.171 raeburn 23232: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
23233: $ishomedom = 1;
1.150 raeburn 23234: }
23235: if (ref($alltypes) eq 'ARRAY') {
23236: foreach my $type (@{$alltypes}) {
23237: my $rule;
1.210 raeburn 23238: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 23239: (!$ishomedom)) {
1.171 raeburn 23240: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
23241: }
23242: if ($rule eq 'specific') {
1.255 raeburn 23243: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 23244: if (exists($servers{$specifiedhost})) {
1.255 raeburn 23245: $rule = $specifiedhost;
23246: }
1.150 raeburn 23247: }
1.171 raeburn 23248: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
23249: if (ref($currrules{$balancer}) eq 'HASH') {
23250: if ($rule ne $currrules{$balancer}{$type}) {
23251: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 23252: }
23253: } elsif ($rule ne '') {
1.171 raeburn 23254: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 23255: }
23256: }
23257: }
1.171 raeburn 23258: }
23259: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
23260: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
23261: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
23262: $defaultshash{'loadbalancing'} = {};
23263: }
23264: my $putresult = &Apache::lonnet::put_dom('configuration',
23265: \%defaultshash,$dom);
23266: if ($putresult eq 'ok') {
23267: if (keys(%changes) > 0) {
1.252 raeburn 23268: my %toupdate;
1.171 raeburn 23269: if (ref($changes{'delete'}) eq 'ARRAY') {
23270: foreach my $balancer (sort(@{$changes{'delete'}})) {
23271: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 23272: $toupdate{$balancer} = 1;
1.150 raeburn 23273: }
1.171 raeburn 23274: }
23275: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 23276: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 23277: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 23278: $toupdate{$balancer} = 1;
1.171 raeburn 23279: }
23280: }
23281: if (ref($changes{'curr'}) eq 'HASH') {
23282: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 23283: $toupdate{$balancer} = 1;
1.171 raeburn 23284: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
23285: if ($changes{'curr'}{$balancer}{'targets'}) {
23286: my %offloadstr;
23287: foreach my $sparetype (@sparestypes) {
23288: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23289: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23290: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
23291: }
23292: }
1.150 raeburn 23293: }
1.171 raeburn 23294: if (keys(%offloadstr) == 0) {
23295: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 23296: } else {
1.171 raeburn 23297: my $showoffload;
23298: foreach my $sparetype (@sparestypes) {
23299: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
23300: if (defined($offloadstr{$sparetype})) {
23301: $showoffload .= $offloadstr{$sparetype};
23302: } else {
23303: $showoffload .= &mt('None');
23304: }
23305: $showoffload .= (' 'x3);
23306: }
23307: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 23308: }
23309: }
23310: }
1.171 raeburn 23311: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
23312: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
23313: foreach my $type (@{$alltypes}) {
23314: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
23315: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23316: my $balancetext;
23317: if ($rule eq '') {
23318: $balancetext = $ruletitles{'default'};
1.209 raeburn 23319: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 23320: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 23321: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 23322: foreach my $sparetype (@sparestypes) {
23323: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23324: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
23325: }
23326: }
1.253 raeburn 23327: foreach my $item (@{$alltypes}) {
23328: next if ($item =~ /^_LC_ipchange/);
23329: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
23330: if ($hasrule eq 'homeserver') {
23331: map { $toupdate{$_} = 1; } (keys(%libraryservers));
23332: } else {
23333: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
23334: if ($servers{$hasrule}) {
23335: $toupdate{$hasrule} = 1;
23336: }
23337: }
23338: }
23339: }
1.254 raeburn 23340: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
23341: $balancetext = $ruletitles{$rule};
23342: } else {
23343: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23344: $balancetext = $ruletitles{'particular'}.' '.$receiver;
23345: if ($receiver) {
23346: $toupdate{$receiver};
23347: }
23348: }
23349: } else {
23350: $balancetext = $ruletitles{$rule};
1.252 raeburn 23351: }
1.171 raeburn 23352: } else {
23353: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
23354: }
1.210 raeburn 23355: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 23356: }
23357: }
23358: }
23359: }
1.342 raeburn 23360: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.389 raeburn 23361: if ($currcookies{$balancer}) {
23362: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
23363: $balancer).'</li>';
23364: } else {
23365: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
23366: $balancer).'</li>';
23367: }
1.342 raeburn 23368: }
1.375 raeburn 23369: }
23370: }
23371: if (keys(%toupdate)) {
23372: my %thismachine;
23373: my $updatedhere;
23374: my $cachetime = 60*60*24;
23375: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
23376: foreach my $lonhost (keys(%toupdate)) {
23377: if ($thismachine{$lonhost}) {
23378: unless ($updatedhere) {
23379: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
23380: $defaultshash{'loadbalancing'},
23381: $cachetime);
23382: $updatedhere = 1;
1.252 raeburn 23383: }
1.375 raeburn 23384: } else {
23385: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
23386: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.252 raeburn 23387: }
1.150 raeburn 23388: }
1.171 raeburn 23389: }
23390: if ($resulttext ne '') {
23391: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 23392: } else {
23393: $resulttext = $nochgmsg;
23394: }
23395: } else {
1.171 raeburn 23396: $resulttext = $nochgmsg;
1.150 raeburn 23397: }
23398: } else {
1.171 raeburn 23399: $resulttext = '<span class="LC_error">'.
23400: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 23401: }
23402: } else {
1.171 raeburn 23403: $resulttext = $nochgmsg;
1.150 raeburn 23404: }
23405: return $resulttext;
23406: }
23407:
1.48 raeburn 23408: sub recurse_check {
23409: my ($chkcats,$categories,$depth,$name) = @_;
23410: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
23411: my $chg = 0;
23412: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
23413: my $category = $chkcats->[$depth]{$name}[$j];
23414: my $item;
23415: if ($category eq '') {
23416: $chg ++;
23417: } else {
23418: my $deeper = $depth + 1;
23419: $item = &escape($category).':'.&escape($name).':'.$depth;
23420: if ($chg) {
23421: $categories->{$item} -= $chg;
23422: }
23423: &recurse_check($chkcats,$categories,$deeper,$category);
23424: $deeper --;
23425: }
23426: }
23427: }
23428: return;
23429: }
23430:
23431: sub recurse_cat_deletes {
23432: my ($item,$coursecategories,$deletions) = @_;
23433: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
23434: my $subdepth = $depth + 1;
23435: if (ref($coursecategories) eq 'HASH') {
23436: foreach my $subitem (keys(%{$coursecategories})) {
23437: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
23438: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
23439: delete($coursecategories->{$subitem});
23440: $deletions->{$subitem} = 1;
23441: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 23442: }
1.48 raeburn 23443: }
23444: }
23445: return;
23446: }
23447:
1.125 raeburn 23448: sub active_dc_picker {
1.191 raeburn 23449: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 23450: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 23451: my @domcoord = keys(%domcoords);
23452: if (keys(%currhash)) {
23453: foreach my $dc (keys(%currhash)) {
23454: unless (exists($domcoords{$dc})) {
23455: push(@domcoord,$dc);
23456: }
23457: }
23458: }
23459: @domcoord = sort(@domcoord);
1.210 raeburn 23460: my $numdcs = scalar(@domcoord);
1.191 raeburn 23461: my $rows = 0;
23462: my $table;
1.125 raeburn 23463: if ($numdcs > 1) {
1.191 raeburn 23464: $table = '<table>';
23465: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 23466: my $rem = $i%($numinrow);
23467: if ($rem == 0) {
23468: if ($i > 0) {
1.191 raeburn 23469: $table .= '</tr>';
1.125 raeburn 23470: }
1.191 raeburn 23471: $table .= '<tr>';
23472: $rows ++;
1.125 raeburn 23473: }
1.191 raeburn 23474: my $check = '';
23475: if ($inputtype eq 'radio') {
23476: if (keys(%currhash) == 0) {
23477: if (!$i) {
23478: $check = ' checked="checked"';
23479: }
23480: } elsif (exists($currhash{$domcoord[$i]})) {
23481: $check = ' checked="checked"';
23482: }
23483: } else {
23484: if (exists($currhash{$domcoord[$i]})) {
23485: $check = ' checked="checked"';
1.125 raeburn 23486: }
23487: }
1.191 raeburn 23488: if ($i == @domcoord - 1) {
1.125 raeburn 23489: my $colsleft = $numinrow - $rem;
23490: if ($colsleft > 1) {
1.191 raeburn 23491: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 23492: } else {
1.191 raeburn 23493: $table .= '<td class="LC_left_item">';
1.125 raeburn 23494: }
23495: } else {
1.191 raeburn 23496: $table .= '<td class="LC_left_item">';
23497: }
23498: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
23499: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
23500: $table .= '<span class="LC_nobreak"><label>'.
23501: '<input type="'.$inputtype.'" name="'.$name.'"'.
23502: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
23503: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 23504: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 23505: }
1.219 raeburn 23506: $table .= '</label></span></td>';
1.191 raeburn 23507: }
23508: $table .= '</tr></table>';
23509: } elsif ($numdcs == 1) {
1.219 raeburn 23510: my ($dcname,$dcdom) = split(':',$domcoord[0]);
23511: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 23512: if ($inputtype eq 'radio') {
1.247 raeburn 23513: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 23514: if ($user ne $dcname.':'.$dcdom) {
23515: $table .= ' ('.$dcname.':'.$dcdom.')';
23516: }
1.191 raeburn 23517: } else {
23518: my $check;
23519: if (exists($currhash{$domcoord[0]})) {
23520: $check = ' checked="checked"';
1.125 raeburn 23521: }
1.247 raeburn 23522: $table = '<span class="LC_nobreak"><label>'.
23523: '<input type="checkbox" name="'.$name.'" '.
23524: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 23525: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 23526: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 23527: }
1.220 raeburn 23528: $table .= '</label></span>';
1.191 raeburn 23529: $rows ++;
1.125 raeburn 23530: }
23531: }
1.191 raeburn 23532: return ($numdcs,$table,$rows);
1.125 raeburn 23533: }
23534:
1.137 raeburn 23535: sub usersession_titles {
23536: return &Apache::lonlocal::texthash(
23537: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
23538: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 23539: spares => 'Servers offloaded to, when busy',
1.137 raeburn 23540: version => 'LON-CAPA version requirement',
1.138 raeburn 23541: excludedomain => 'Allow all, but exclude specific domains',
23542: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 23543: primary => 'Primary (checked first)',
1.154 raeburn 23544: default => 'Default',
1.137 raeburn 23545: );
23546: }
23547:
1.152 raeburn 23548: sub id_for_thisdom {
23549: my (%servers) = @_;
23550: my %altids;
23551: foreach my $server (keys(%servers)) {
23552: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
23553: if ($serverhome ne $server) {
23554: $altids{$serverhome} = $server;
23555: }
23556: }
23557: return %altids;
23558: }
23559:
1.150 raeburn 23560: sub count_servers {
23561: my ($currbalancer,%servers) = @_;
23562: my (@spares,$numspares);
23563: foreach my $lonhost (sort(keys(%servers))) {
23564: next if ($currbalancer eq $lonhost);
23565: push(@spares,$lonhost);
23566: }
23567: if ($currbalancer) {
23568: $numspares = scalar(@spares);
23569: } else {
23570: $numspares = scalar(@spares) - 1;
23571: }
23572: return ($numspares,@spares);
23573: }
23574:
23575: sub lonbalance_targets_js {
1.171 raeburn 23576: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 23577: my $select = &mt('Select');
23578: my ($alltargets,$allishome,$allinsttypes,@alltypes);
23579: if (ref($servers) eq 'HASH') {
23580: $alltargets = join("','",sort(keys(%{$servers})));
23581: my @homedoms;
23582: foreach my $server (sort(keys(%{$servers}))) {
23583: if (&Apache::lonnet::host_domain($server) eq $dom) {
23584: push(@homedoms,'1');
23585: } else {
23586: push(@homedoms,'0');
23587: }
23588: }
23589: $allishome = join("','",@homedoms);
23590: }
23591: if (ref($types) eq 'ARRAY') {
23592: if (@{$types} > 0) {
23593: @alltypes = @{$types};
23594: }
23595: }
23596: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
23597: $allinsttypes = join("','",@alltypes);
1.342 raeburn 23598: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 23599: if (ref($settings) eq 'HASH') {
23600: %existing = %{$settings};
23601: }
23602: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 23603: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 23604: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 23605: return <<"END";
23606:
23607: <script type="text/javascript">
23608: // <![CDATA[
23609:
1.171 raeburn 23610: currBalancers = new Array('$balancers');
23611:
23612: function toggleTargets(balnum) {
23613: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23614: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
23615: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
23616: var prevbalancer = prevhostitem.value;
23617: var baltotal = document.getElementById('loadbalancing_total').value;
23618: prevhostitem.value = balancer;
23619: if (prevbalancer != '') {
23620: var prevIdx = currBalancers.indexOf(prevbalancer);
23621: if (prevIdx != -1) {
23622: currBalancers.splice(prevIdx,1);
23623: }
23624: }
1.150 raeburn 23625: if (balancer == '') {
1.171 raeburn 23626: hideSpares(balnum);
1.150 raeburn 23627: } else {
1.171 raeburn 23628: var currIdx = currBalancers.indexOf(balancer);
23629: if (currIdx == -1) {
23630: currBalancers.push(balancer);
23631: }
1.150 raeburn 23632: var homedoms = new Array('$allishome');
1.171 raeburn 23633: var ishomedom = homedoms[lonhostitem.selectedIndex];
23634: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 23635: }
1.171 raeburn 23636: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 23637: return;
23638: }
23639:
1.171 raeburn 23640: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 23641: var alltargets = new Array('$alltargets');
23642: var insttypes = new Array('$allinsttypes');
1.151 raeburn 23643: var offloadtypes = new Array('primary','default');
23644:
1.171 raeburn 23645: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
23646: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 23647:
1.151 raeburn 23648: for (var i=0; i<offloadtypes.length; i++) {
23649: var count = 0;
23650: for (var j=0; j<alltargets.length; j++) {
23651: if (alltargets[j] != balancer) {
1.171 raeburn 23652: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
23653: item.value = alltargets[j];
23654: item.style.textAlign='left';
23655: item.style.textFace='normal';
23656: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
23657: if (currBalancers.indexOf(alltargets[j]) == -1) {
23658: item.disabled = '';
23659: } else {
23660: item.disabled = 'disabled';
23661: item.checked = false;
23662: }
1.151 raeburn 23663: count ++;
23664: }
1.150 raeburn 23665: }
23666: }
1.151 raeburn 23667: for (var k=0; k<insttypes.length; k++) {
23668: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 23669: if (ishomedom == 1) {
1.171 raeburn 23670: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23671: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23672: } else {
1.171 raeburn 23673: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23674: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 23675: }
23676: } else {
1.171 raeburn 23677: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23678: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23679: }
1.151 raeburn 23680: if ((insttypes[k] != '_LC_external') &&
23681: ((insttypes[k] != '_LC_internetdom') ||
23682: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 23683: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
23684: item.options.length = 0;
23685: item.options[0] = new Option("","",true,true);
1.210 raeburn 23686: var idx = 0;
1.151 raeburn 23687: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 23688: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
23689: idx ++;
23690: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 23691: }
23692: }
23693: }
23694: }
23695: return;
23696: }
23697:
1.171 raeburn 23698: function hideSpares(balnum) {
1.150 raeburn 23699: var alltargets = new Array('$alltargets');
23700: var insttypes = new Array('$allinsttypes');
23701: var offloadtypes = new Array('primary','default');
23702:
1.171 raeburn 23703: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
23704: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 23705:
23706: var total = alltargets.length - 1;
23707: for (var i=0; i<offloadtypes; i++) {
23708: for (var j=0; j<total; j++) {
1.171 raeburn 23709: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
23710: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
23711: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 23712: }
1.150 raeburn 23713: }
23714: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 23715: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23716: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 23717: if (insttypes[k] != '_LC_external') {
1.171 raeburn 23718: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
23719: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 23720: }
23721: }
23722: return;
23723: }
23724:
1.171 raeburn 23725: function checkOffloads(item,balnum,type) {
1.150 raeburn 23726: var alltargets = new Array('$alltargets');
23727: var offloadtypes = new Array('primary','default');
23728: if (item.checked) {
23729: var total = alltargets.length - 1;
23730: var other;
23731: if (type == offloadtypes[0]) {
1.151 raeburn 23732: other = offloadtypes[1];
1.150 raeburn 23733: } else {
1.151 raeburn 23734: other = offloadtypes[0];
1.150 raeburn 23735: }
23736: for (var i=0; i<total; i++) {
1.171 raeburn 23737: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 23738: if (server == item.value) {
1.171 raeburn 23739: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
23740: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 23741: }
23742: }
23743: }
23744: }
23745: return;
23746: }
23747:
1.171 raeburn 23748: function singleServerToggle(balnum,type) {
23749: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 23750: if (offloadtoSelIdx == 0) {
1.171 raeburn 23751: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
23752: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23753:
23754: } else {
1.171 raeburn 23755: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
23756: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 23757: }
23758: return;
23759: }
23760:
1.171 raeburn 23761: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 23762: if (type == '_LC_external') {
1.171 raeburn 23763: return;
1.150 raeburn 23764: }
1.171 raeburn 23765: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 23766: for (var i=0; i<typesRules.length; i++) {
23767: if (formname.elements[typesRules[i]].checked) {
23768: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 23769: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
23770: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23771: } else {
1.171 raeburn 23772: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
23773: }
23774: }
23775: }
23776: return;
23777: }
23778:
23779: function balancerDeleteChange(balnum) {
23780: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23781: var baltotal = document.getElementById('loadbalancing_total').value;
23782: var addtarget;
23783: var removetarget;
23784: var action = 'delete';
23785: if (document.getElementById('loadbalancing_delete_'+balnum)) {
23786: var lonhost = hostitem.value;
23787: var currIdx = currBalancers.indexOf(lonhost);
23788: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
23789: if (currIdx != -1) {
23790: currBalancers.splice(currIdx,1);
23791: }
23792: addtarget = lonhost;
23793: } else {
23794: if (currIdx == -1) {
23795: currBalancers.push(lonhost);
23796: }
23797: removetarget = lonhost;
23798: action = 'undelete';
23799: }
23800: balancerChange(balnum,baltotal,action,addtarget,removetarget);
23801: }
23802: return;
23803: }
23804:
23805: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
23806: if (baltotal > 1) {
23807: var offloadtypes = new Array('primary','default');
23808: var alltargets = new Array('$alltargets');
23809: var insttypes = new Array('$allinsttypes');
23810: for (var i=0; i<baltotal; i++) {
23811: if (i != balnum) {
23812: for (var j=0; j<offloadtypes.length; j++) {
23813: var total = alltargets.length - 1;
23814: for (var k=0; k<total; k++) {
23815: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
23816: var server = serveritem.value;
23817: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23818: if (server == addtarget) {
23819: serveritem.disabled = '';
23820: }
23821: }
23822: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23823: if (server == removetarget) {
23824: serveritem.disabled = 'disabled';
23825: serveritem.checked = false;
23826: }
23827: }
23828: }
23829: }
23830: for (var j=0; j<insttypes.length; j++) {
23831: if (insttypes[j] != '_LC_external') {
23832: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
23833: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
23834: var currSel = singleserver.selectedIndex;
23835: var currVal = singleserver.options[currSel].value;
23836: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23837: var numoptions = singleserver.options.length;
23838: var needsnew = 1;
23839: for (var k=0; k<numoptions; k++) {
23840: if (singleserver.options[k] == addtarget) {
23841: needsnew = 0;
23842: break;
23843: }
23844: }
23845: if (needsnew == 1) {
23846: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
23847: }
23848: }
23849: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23850: singleserver.options.length = 0;
23851: if ((currVal) && (currVal != removetarget)) {
23852: singleserver.options[0] = new Option("","",false,false);
23853: } else {
23854: singleserver.options[0] = new Option("","",true,true);
23855: }
23856: var idx = 0;
23857: for (var m=0; m<alltargets.length; m++) {
23858: if (currBalancers.indexOf(alltargets[m]) == -1) {
23859: idx ++;
23860: if (currVal == alltargets[m]) {
23861: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
23862: } else {
23863: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
23864: }
23865: }
23866: }
23867: }
23868: }
23869: }
23870: }
1.150 raeburn 23871: }
23872: }
23873: }
23874: return;
23875: }
23876:
1.152 raeburn 23877: // ]]>
23878: </script>
23879:
23880: END
23881: }
23882:
23883: sub new_spares_js {
23884: my @sparestypes = ('primary','default');
23885: my $types = join("','",@sparestypes);
23886: my $select = &mt('Select');
23887: return <<"END";
23888:
23889: <script type="text/javascript">
23890: // <![CDATA[
23891:
23892: function updateNewSpares(formname,lonhost) {
23893: var types = new Array('$types');
23894: var include = new Array();
23895: var exclude = new Array();
23896: for (var i=0; i<types.length; i++) {
23897: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
23898: for (var j=0; j<spareboxes.length; j++) {
23899: if (formname.elements[spareboxes[j]].checked) {
23900: exclude.push(formname.elements[spareboxes[j]].value);
23901: } else {
23902: include.push(formname.elements[spareboxes[j]].value);
23903: }
23904: }
23905: }
23906: for (var i=0; i<types.length; i++) {
23907: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
23908: var selIdx = newSpare.selectedIndex;
23909: var currnew = newSpare.options[selIdx].value;
23910: var okSpares = new Array();
23911: for (var j=0; j<newSpare.options.length; j++) {
23912: var possible = newSpare.options[j].value;
23913: if (possible != '') {
23914: if (exclude.indexOf(possible) == -1) {
23915: okSpares.push(possible);
23916: } else {
23917: if (currnew == possible) {
23918: selIdx = 0;
23919: }
23920: }
23921: }
23922: }
23923: for (var k=0; k<include.length; k++) {
23924: if (okSpares.indexOf(include[k]) == -1) {
23925: okSpares.push(include[k]);
23926: }
23927: }
23928: okSpares.sort();
23929: newSpare.options.length = 0;
23930: if (selIdx == 0) {
23931: newSpare.options[0] = new Option("$select","",true,true);
23932: } else {
23933: newSpare.options[0] = new Option("$select","",false,false);
23934: }
23935: for (var m=0; m<okSpares.length; m++) {
23936: var idx = m+1;
23937: var selThis = 0;
23938: if (selIdx != 0) {
23939: if (okSpares[m] == currnew) {
23940: selThis = 1;
23941: }
23942: }
23943: if (selThis == 1) {
23944: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
23945: } else {
23946: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
23947: }
23948: }
23949: }
23950: return;
23951: }
23952:
23953: function checkNewSpares(lonhost,type) {
23954: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
23955: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.372 raeburn 23956: if (chosen != '') {
1.152 raeburn 23957: var othertype;
23958: var othernewSpare;
23959: if (type == 'primary') {
23960: othernewSpare = document.getElementById('newspare_default_'+lonhost);
23961: }
23962: if (type == 'default') {
23963: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
23964: }
23965: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
23966: othernewSpare.selectedIndex = 0;
23967: }
23968: }
23969: return;
23970: }
23971:
23972: // ]]>
23973: </script>
23974:
23975: END
23976:
23977: }
23978:
23979: sub common_domprefs_js {
23980: return <<"END";
23981:
23982: <script type="text/javascript">
23983: // <![CDATA[
23984:
1.150 raeburn 23985: function getIndicesByName(formname,item) {
1.152 raeburn 23986: var group = new Array();
1.150 raeburn 23987: for (var i=0;i<formname.elements.length;i++) {
23988: if (formname.elements[i].name == item) {
1.152 raeburn 23989: group.push(formname.elements[i].id);
1.150 raeburn 23990: }
23991: }
1.152 raeburn 23992: return group;
1.150 raeburn 23993: }
23994:
23995: // ]]>
23996: </script>
23997:
23998: END
1.152 raeburn 23999:
1.150 raeburn 24000: }
24001:
1.165 raeburn 24002: sub recaptcha_js {
24003: my %lt = &captcha_phrases();
24004: return <<"END";
24005:
24006: <script type="text/javascript">
24007: // <![CDATA[
24008:
24009: function updateCaptcha(caller,context) {
24010: var privitem;
24011: var pubitem;
24012: var privtext;
24013: var pubtext;
1.269 raeburn 24014: var versionitem;
24015: var versiontext;
1.165 raeburn 24016: if (document.getElementById(context+'_recaptchapub')) {
24017: pubitem = document.getElementById(context+'_recaptchapub');
24018: } else {
24019: return;
24020: }
24021: if (document.getElementById(context+'_recaptchapriv')) {
24022: privitem = document.getElementById(context+'_recaptchapriv');
24023: } else {
24024: return;
24025: }
24026: if (document.getElementById(context+'_recaptchapubtxt')) {
24027: pubtext = document.getElementById(context+'_recaptchapubtxt');
24028: } else {
24029: return;
24030: }
24031: if (document.getElementById(context+'_recaptchaprivtxt')) {
24032: privtext = document.getElementById(context+'_recaptchaprivtxt');
24033: } else {
24034: return;
24035: }
1.269 raeburn 24036: if (document.getElementById(context+'_recaptchaversion')) {
24037: versionitem = document.getElementById(context+'_recaptchaversion');
24038: } else {
24039: return;
24040: }
24041: if (document.getElementById(context+'_recaptchavertxt')) {
24042: versiontext = document.getElementById(context+'_recaptchavertxt');
24043: } else {
24044: return;
24045: }
1.165 raeburn 24046: if (caller.checked) {
24047: if (caller.value == 'recaptcha') {
24048: pubitem.type = 'text';
24049: privitem.type = 'text';
24050: pubitem.size = '40';
24051: privitem.size = '40';
24052: pubtext.innerHTML = "$lt{'pub'}";
24053: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 24054: versionitem.type = 'text';
24055: versionitem.size = '3';
1.289 raeburn 24056: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 24057: } else {
24058: pubitem.type = 'hidden';
24059: privitem.type = 'hidden';
1.269 raeburn 24060: versionitem.type = 'hidden';
1.165 raeburn 24061: pubtext.innerHTML = '';
24062: privtext.innerHTML = '';
1.269 raeburn 24063: versiontext.innerHTML = '';
1.165 raeburn 24064: }
24065: }
24066: return;
24067: }
24068:
24069: // ]]>
24070: </script>
24071:
24072: END
24073:
24074: }
24075:
1.236 raeburn 24076: sub toggle_display_js {
1.192 raeburn 24077: return <<"END";
24078:
24079: <script type="text/javascript">
24080: // <![CDATA[
24081:
1.236 raeburn 24082: function toggleDisplay(domForm,caller) {
24083: if (document.getElementById(caller)) {
24084: var divitem = document.getElementById(caller);
24085: var optionsElement = domForm.coursecredits;
1.264 raeburn 24086: var checkval = 1;
24087: var dispval = 'block';
1.303 raeburn 24088: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 24089: if (caller == 'emailoptions') {
1.372 raeburn 24090: optionsElement = domForm.cancreate_email;
1.236 raeburn 24091: }
1.257 raeburn 24092: if (caller == 'studentsubmission') {
24093: optionsElement = domForm.postsubmit;
24094: }
1.264 raeburn 24095: if (caller == 'cloneinstcode') {
24096: optionsElement = domForm.canclone;
24097: checkval = 'instcode';
24098: }
1.303 raeburn 24099: if (selfcreateRegExp.test(caller)) {
24100: optionsElement = domForm.elements[caller];
24101: checkval = 'other';
24102: dispval = 'inline'
24103: }
1.236 raeburn 24104: if (optionsElement.length) {
1.192 raeburn 24105: var currval;
1.236 raeburn 24106: for (var i=0; i<optionsElement.length; i++) {
24107: if (optionsElement[i].checked) {
24108: currval = optionsElement[i].value;
1.192 raeburn 24109: }
24110: }
1.264 raeburn 24111: if (currval == checkval) {
24112: divitem.style.display = dispval;
1.192 raeburn 24113: } else {
1.236 raeburn 24114: divitem.style.display = 'none';
1.192 raeburn 24115: }
24116: }
24117: }
24118: return;
24119: }
24120:
24121: // ]]>
24122: </script>
24123:
24124: END
24125:
24126: }
24127:
1.165 raeburn 24128: sub captcha_phrases {
24129: return &Apache::lonlocal::texthash (
24130: priv => 'Private key',
24131: pub => 'Public key',
24132: original => 'original (CAPTCHA)',
24133: recaptcha => 'successor (ReCAPTCHA)',
24134: notused => 'unused',
1.289 raeburn 24135: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 24136: );
24137: }
24138:
1.205 raeburn 24139: sub devalidate_remote_domconfs {
1.212 raeburn 24140: my ($dom,$cachekeys) = @_;
24141: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 24142: my %servers = &Apache::lonnet::internet_dom_servers($dom);
24143: my %thismachine;
24144: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 raeburn 24145: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.394 raeburn 24146: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
1.410 raeburn 24147: 'ipaccess','trust');
1.386 raeburn 24148: my %cache_by_lonhost;
24149: if (exists($cachekeys->{'samllanding'})) {
24150: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
24151: my %landing = %{$cachekeys->{'samllanding'}};
24152: my %domservers = &Apache::lonnet::get_servers($dom);
24153: if (keys(%domservers)) {
24154: foreach my $server (keys(%domservers)) {
24155: my @cached;
24156: next if ($thismachine{$server});
24157: if ($landing{$server}) {
24158: push(@cached,&escape('samllanding').':'.&escape($server));
24159: }
24160: if (@cached) {
24161: $cache_by_lonhost{$server} = \@cached;
24162: }
24163: }
24164: }
24165: }
24166: }
1.260 raeburn 24167: if (keys(%servers)) {
1.205 raeburn 24168: foreach my $server (keys(%servers)) {
24169: next if ($thismachine{$server});
1.212 raeburn 24170: my @cached;
24171: foreach my $name (@posscached) {
24172: if ($cachekeys->{$name}) {
1.388 raeburn 24173: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
1.386 raeburn 24174: if (ref($cachekeys->{$name}) eq 'HASH') {
1.373 raeburn 24175: foreach my $key (keys(%{$cachekeys->{$name}})) {
24176: push(@cached,&escape($name).':'.&escape($key));
24177: }
24178: }
24179: } else {
24180: push(@cached,&escape($name).':'.&escape($dom));
24181: }
1.212 raeburn 24182: }
24183: }
1.386 raeburn 24184: if ((exists($cache_by_lonhost{$server})) &&
24185: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
24186: push(@cached,@{$cache_by_lonhost{$server}});
24187: }
1.212 raeburn 24188: if (@cached) {
24189: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
24190: }
1.205 raeburn 24191: }
24192: }
24193: return;
24194: }
24195:
1.3 raeburn 24196: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>