Annotation of loncom/interface/domainprefs.pm, revision 1.447
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.447 ! raeburn 4: # $Id: domainprefs.pm,v 1.446 2024/12/31 18:51:53 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
1.286 raeburn 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
1.1 raeburn 24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: ###############################################################
1.297 raeburn 30: ###############################################################
1.1 raeburn 31:
1.101 raeburn 32: =pod
33:
34: =head1 NAME
35:
36: Apache::domainprefs.pm
37:
38: =head1 SYNOPSIS
39:
40: Handles configuration of a LON-CAPA domain.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
45:
46: =head1 OVERVIEW
47:
48: Each institution using LON-CAPA will typically have a single domain designated
1.183 bisitz 49: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 50: may define a default set of logos and a color scheme which can be used to "brand"
51: the LON-CAPA instance. In addition, an institution will typically have a language
52: and timezone which are used for the majority of courses.
53:
54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
55: host of other domain-wide settings which determine the types of functionality
56: available to users and courses in the domain.
57:
58: There is also a mechanism to configure cataloging of courses in the domain, and
59: controls on the operation of automated processes which govern such things as
60: roster updates, user directory updates and processing of course requests.
61:
62: The domain coordination manual which is built dynamically on install/update of
63: LON-CAPA from the relevant help items provides more information about domain
64: configuration.
65:
66: Most of the domain settings are stored in the configuration.db GDBM file which is
67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
68: where $dom is the domain. The configuration.db stores settings in a number of
69: frozen hashes of hashes. In a few cases, domain information must be uploaded to
70: the domain as files (e.g., image files for logos etc., or plain text files for
71: bubblesheet formats). In this case the domainprefs.pm must be running in a user
72: session hosted on the primary library server in the domain, as these files are
73: stored in author space belonging to a special $dom-domainconfig user.
74:
75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
76: the current settings, and provides an interface to make modifications.
77:
78: =head1 SUBROUTINES
79:
80: =over
81:
82: =item print_quotas()
83:
84: Inputs: 4
85:
86: $dom,$settings,$rowtotal,$action.
87:
88: $dom is the domain, $settings is a reference to a hash of current settings for
89: the current context, $rowtotal is a reference to the scalar used to record the
1.210 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.163 raeburn 91: requestcourses or requestauthor).
1.101 raeburn 92:
93: The print_quotas routine was orginally created to display/store information
94: about default quota sizes for portfolio spaces for the different types of
95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
96: but is now also used to manage availability of user tools:
97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.429 raeburn 98: used by course owners to request creation of a course.
1.101 raeburn 99:
100: Outputs: 1
101:
102: $datatable - HTML containing form elements which allow settings to be changed.
103:
104: In the case of course requests, radio buttons are displayed for each institutional
105: affiliate type (and also default, and _LC_adv) for each of the course types
1.325 raeburn 106: (official, unofficial, community, textbook, placement, and lti).
1.425 raeburn 107: In each case the radio buttons allow the selection of one of four values:
1.101 raeburn 108:
1.104 raeburn 109: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 110: which have the following effects:
111:
112: 0
113:
114: =over
115:
116: - course requests are not allowed for this course types/affiliation
117:
118: =back
119:
1.104 raeburn 120: approval
1.101 raeburn 121:
122: =over
123:
124: - course requests must be approved by a Doman Coordinator in the
125: course's domain
126:
127: =back
128:
129: validate
130:
131: =over
132:
133: - an institutional validation (e.g., check requestor is instructor
134: of record) needs to be passed before the course will be created. The required
135: validation is in localenroll.pm on the primary library server for the course
136: domain.
137:
138: =back
139:
140: autolimit
141:
142: =over
143:
1.143 raeburn 144: - course requests will be processed automatically up to a limit of
1.101 raeburn 145: N requests for the course type for the particular requestor.
146: If N is undefined, there is no limit to the number of course requests
147: which a course owner may submit and have processed automatically.
148:
149: =back
150:
151: =item modify_quotas()
152:
153: =back
154:
155: =cut
156:
1.1 raeburn 157: package Apache::domainprefs;
158:
159: use strict;
160: use Apache::Constants qw(:common :http);
161: use Apache::lonnet;
162: use Apache::loncommon();
163: use Apache::lonhtmlcommon();
164: use Apache::lonlocal;
1.43 raeburn 165: use Apache::lonmsg();
1.91 raeburn 166: use Apache::lonconfigsettings;
1.232 raeburn 167: use Apache::lonuserutils();
1.235 raeburn 168: use Apache::loncoursequeueadmin();
1.419 raeburn 169: use Apache::courseprefs();
1.69 raeburn 170: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 171: use LONCAPA::Enrollment;
1.81 raeburn 172: use LONCAPA::lonauthcgi();
1.275 raeburn 173: use LONCAPA::SSL;
1.9 raeburn 174: use File::Copy;
1.43 raeburn 175: use Locale::Language;
1.62 raeburn 176: use DateTime::TimeZone;
1.68 raeburn 177: use DateTime::Locale;
1.267 raeburn 178: use Time::HiRes qw( sleep );
1.373 raeburn 179: use Net::CIDR;
1.424 raeburn 180: use Crypt::CBC;
1.1 raeburn 181:
1.155 raeburn 182: my $registered_cleanup;
183: my $modified_urls;
184:
1.1 raeburn 185: sub handler {
186: my $r=shift;
187: if ($r->header_only) {
188: &Apache::loncommon::content_type($r,'text/html');
189: $r->send_http_header;
190: return OK;
191: }
192:
1.91 raeburn 193: my $context = 'domain';
1.1 raeburn 194: my $dom = $env{'request.role.domain'};
1.5 albertel 195: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 196: if (&Apache::lonnet::allowed('mau',$dom)) {
197: &Apache::loncommon::content_type($r,'text/html');
198: $r->send_http_header;
199: } else {
200: $env{'user.error.msg'}=
201: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
202: return HTTP_NOT_ACCEPTABLE;
203: }
1.155 raeburn 204:
205: $registered_cleanup=0;
206: @{$modified_urls}=();
207:
1.1 raeburn 208: &Apache::lonhtmlcommon::clear_breadcrumbs();
209: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 210: ['phase','actions']);
1.30 raeburn 211: my $phase = 'pickactions';
1.3 raeburn 212: if ( exists($env{'form.phase'}) ) {
213: $phase = $env{'form.phase'};
214: }
1.150 raeburn 215: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 216: my %domconfig =
1.6 raeburn 217: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 218: 'quotas','autoenroll','autoupdate','autocreate',
219: 'directorysrch','usercreation','usermodification',
220: 'contacts','defaults','scantron','coursecategories',
221: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 222: 'coursedefaults','usersessions','loadbalancing',
1.267 raeburn 223: 'requestauthor','selfenrollment','inststatus',
1.421 raeburn 224: 'ltitools','toolsec','ssl','trust','lti','ltisec',
1.429 raeburn 225: 'privacy','passwords','proctoring','wafproxy',
226: 'ipaccess','authordefaults'],$dom);
1.320 raeburn 227: my %encconfig =
1.405 raeburn 228: &Apache::lonnet::get_dom('encconfig',['ltitools','lti','proctoring','linkprot'],$dom,undef,1);
1.424 raeburn 229: my ($checked_is_home,$is_home);
1.297 raeburn 230: if (ref($domconfig{'ltitools'}) eq 'HASH') {
231: if (ref($encconfig{'ltitools'}) eq 'HASH') {
1.423 raeburn 232: my $home = &Apache::lonnet::domain($dom,'primary');
233: unless (($home eq 'no_host') || ($home eq '')) {
234: my @ids=&Apache::lonnet::current_machine_ids();
235: if (grep(/^\Q$home\E$/,@ids)) {
236: $is_home = 1;
237: }
238: }
1.425 raeburn 239: $checked_is_home = 1;
1.297 raeburn 240: foreach my $id (keys(%{$domconfig{'ltitools'}})) {
1.320 raeburn 241: if ((ref($domconfig{'ltitools'}{$id}) eq 'HASH') &&
242: (ref($encconfig{'ltitools'}{$id}) eq 'HASH')) {
1.421 raeburn 243: $domconfig{'ltitools'}{$id}{'key'} = $encconfig{'ltitools'}{$id}{'key'};
1.423 raeburn 244: if (($is_home) && ($phase eq 'process')) {
245: $domconfig{'ltitools'}{$id}{'secret'} = $encconfig{'ltitools'}{$id}{'secret'};
246: }
1.297 raeburn 247: }
248: }
249: }
250: }
1.320 raeburn 251: if (ref($domconfig{'lti'}) eq 'HASH') {
252: if (ref($encconfig{'lti'}) eq 'HASH') {
1.424 raeburn 253: unless ($checked_is_home) {
254: my $home = &Apache::lonnet::domain($dom,'primary');
255: unless (($home eq 'no_host') || ($home eq '')) {
256: my @ids=&Apache::lonnet::current_machine_ids();
257: if (grep(/^\Q$home\E$/,@ids)) {
258: $is_home = 1;
259: }
260: }
261: $checked_is_home = 1;
262: }
1.320 raeburn 263: foreach my $id (keys(%{$domconfig{'lti'}})) {
264: if ((ref($domconfig{'lti'}{$id}) eq 'HASH') &&
265: (ref($encconfig{'lti'}{$id}) eq 'HASH')) {
1.424 raeburn 266: $domconfig{'lti'}{$id}{'key'} = $encconfig{'lti'}{$id}{'key'};
267: if (($is_home) && ($phase eq 'process')) {
268: $domconfig{'lti'}{$id}{'secret'} = $encconfig{'lti'}{$id}{'secret'};
1.320 raeburn 269: }
270: }
271: }
272: }
273: }
1.405 raeburn 274: if (ref($domconfig{'ltisec'}) eq 'HASH') {
1.406 raeburn 275: if (ref($domconfig{'ltisec'}{'linkprot'}) eq 'HASH') {
1.405 raeburn 276: if (ref($encconfig{'linkprot'}) eq 'HASH') {
1.406 raeburn 277: foreach my $id (keys(%{$domconfig{'ltisec'}{'linkprot'}})) {
278: unless ($id =~ /^\d+$/) {
279: delete($domconfig{'ltisec'}{'linkprot'}{$id});
280: }
281: if ((ref($domconfig{'ltisec'}{'linkprot'}{$id}) eq 'HASH') &&
1.405 raeburn 282: (ref($encconfig{'linkprot'}{$id}) eq 'HASH')) {
283: foreach my $item ('key','secret') {
1.406 raeburn 284: $domconfig{'ltisec'}{'linkprot'}{$id}{$item} = $encconfig{'linkprot'}{$id}{$item};
1.405 raeburn 285: }
286: }
287: }
288: }
289: }
290: }
1.372 raeburn 291: if (ref($domconfig{'proctoring'}) eq 'HASH') {
292: if (ref($encconfig{'proctoring'}) eq 'HASH') {
293: foreach my $provider (keys(%{$domconfig{'proctoring'}})) {
294: if ((ref($domconfig{'proctoring'}{$provider}) eq 'HASH') &&
295: (ref($encconfig{'proctoring'}{$provider}) eq 'HASH')) {
296: foreach my $item ('key','secret') {
297: $domconfig{'proctoring'}{$provider}{$item} = $encconfig{'proctoring'}{$provider}{$item};
298: }
299: }
300: }
301: }
302: }
1.394 raeburn 303: my @prefs_order = ('rolecolors','login','ipaccess','defaults','wafproxy','passwords',
304: 'quotas','autoenroll','autoupdate','autocreate','directorysrch',
1.373 raeburn 305: 'contacts','privacy','usercreation','selfcreation',
1.374 raeburn 306: 'usermodification','scantron','requestcourses','requestauthor',
1.373 raeburn 307: 'coursecategories','serverstatuses','helpsettings','coursedefaults',
1.429 raeburn 308: 'authordefaults','ltitools','proctoring','selfenrollment',
309: 'usersessions','ssl','trust','lti');
1.171 raeburn 310: my %existing;
311: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
312: %existing = %{$domconfig{'loadbalancing'}};
313: }
314: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 315: push(@prefs_order,'loadbalancing');
316: }
1.30 raeburn 317: my %prefs = (
318: 'rolecolors' =>
319: { text => 'Default color schemes',
1.67 raeburn 320: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 321: header => [{col1 => 'Student Settings',
322: col2 => '',},
323: {col1 => 'Coordinator Settings',
324: col2 => '',},
325: {col1 => 'Author Settings',
326: col2 => '',},
327: {col1 => 'Administrator Settings',
328: col2 => '',}],
1.230 raeburn 329: print => \&print_rolecolors,
330: modify => \&modify_rolecolors,
1.30 raeburn 331: },
1.110 raeburn 332: 'login' =>
1.30 raeburn 333: { text => 'Log-in page options',
1.67 raeburn 334: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 335: header => [{col1 => 'Log-in Page Items',
336: col2 => '',},
337: {col1 => 'Log-in Help',
1.256 raeburn 338: col2 => 'Value'},
339: {col1 => 'Custom HTML in document head',
1.386 raeburn 340: col2 => 'Value'},
341: {col1 => 'SSO',
342: col2 => 'Dual login: SSO and non-SSO options'},
343: ],
1.230 raeburn 344: print => \&print_login,
345: modify => \&modify_login,
1.30 raeburn 346: },
1.43 raeburn 347: 'defaults' =>
1.236 raeburn 348: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 349: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 350: header => [{col1 => 'Setting',
1.236 raeburn 351: col2 => 'Value'},
352: {col1 => 'Institutional user types',
1.409 raeburn 353: col2 => 'Name displayed'},
354: {col1 => 'Mapping for missing usernames via standard log-in',
355: col2 => 'Rules in use'}],
1.230 raeburn 356: print => \&print_defaults,
357: modify => \&modify_defaults,
1.43 raeburn 358: },
1.381 raeburn 359: 'wafproxy' =>
360: { text => 'Web Application Firewall/Reverse Proxy',
1.373 raeburn 361: help => 'Domain_Configuration_WAF_Proxy',
1.381 raeburn 362: header => [{col1 => 'Domain(s)',
363: col2 => 'Servers and WAF/Reverse Proxy alias(es)',
1.373 raeburn 364: },
1.381 raeburn 365: {col1 => 'Domain(s)',
366: col2 => 'WAF Configuration',}],
1.373 raeburn 367: print => \&print_wafproxy,
1.381 raeburn 368: modify => \&modify_wafproxy,
1.373 raeburn 369: },
1.354 raeburn 370: 'passwords' =>
371: { text => 'Passwords (Internal authentication)',
372: help => 'Domain_Configuration_Passwords',
373: header => [{col1 => 'Resetting Forgotten Password',
374: col2 => 'Settings'},
375: {col1 => 'Encryption of Stored Passwords (Internal Auth)',
376: col2 => 'Settings'},
377: {col1 => 'Rules for LON-CAPA Passwords',
378: col2 => 'Settings'},
379: {col1 => 'Course Owner Changing Student Passwords',
380: col2 => 'Settings'}],
381: print => \&print_passwords,
382: modify => \&modify_passwords,
383: },
1.30 raeburn 384: 'quotas' =>
1.429 raeburn 385: { text => 'Blogs, personal pages/timezones, portfolio/quotas',
1.67 raeburn 386: help => 'Domain_Configuration_Quotas',
1.77 raeburn 387: header => [{col1 => 'User affiliation',
1.72 raeburn 388: col2 => 'Available tools',
1.435 raeburn 389: col3 => 'Portfolio quota (MB)',}],
1.230 raeburn 390: print => \&print_quotas,
391: modify => \&modify_quotas,
1.30 raeburn 392: },
393: 'autoenroll' =>
394: { text => 'Auto-enrollment settings',
1.67 raeburn 395: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 396: header => [{col1 => 'Configuration setting',
397: col2 => 'Value(s)'}],
1.230 raeburn 398: print => \&print_autoenroll,
399: modify => \&modify_autoenroll,
1.30 raeburn 400: },
401: 'autoupdate' =>
402: { text => 'Auto-update settings',
1.67 raeburn 403: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 404: header => [{col1 => 'Setting',
405: col2 => 'Value',},
1.131 raeburn 406: {col1 => 'Setting',
407: col2 => 'Affiliation'},
1.43 raeburn 408: {col1 => 'User population',
1.227 bisitz 409: col2 => 'Updatable user data'}],
1.230 raeburn 410: print => \&print_autoupdate,
411: modify => \&modify_autoupdate,
1.30 raeburn 412: },
1.125 raeburn 413: 'autocreate' =>
414: { text => 'Auto-course creation settings',
415: help => 'Domain_Configuration_Auto_Creation',
416: header => [{col1 => 'Configuration Setting',
417: col2 => 'Value',}],
1.230 raeburn 418: print => \&print_autocreate,
419: modify => \&modify_autocreate,
1.125 raeburn 420: },
1.30 raeburn 421: 'directorysrch' =>
1.277 raeburn 422: { text => 'Directory searches',
1.67 raeburn 423: help => 'Domain_Configuration_InstDirectory_Search',
1.277 raeburn 424: header => [{col1 => 'Institutional Directory Setting',
425: col2 => 'Value',},
426: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 427: col2 => 'Value',}],
1.230 raeburn 428: print => \&print_directorysrch,
429: modify => \&modify_directorysrch,
1.30 raeburn 430: },
431: 'contacts' =>
1.286 raeburn 432: { text => 'E-mail addresses and helpform',
1.67 raeburn 433: help => 'Domain_Configuration_Contact_Info',
1.286 raeburn 434: header => [{col1 => 'Default e-mail addresses',
435: col2 => 'Value',},
436: {col1 => 'Recipient(s) for notifications',
437: col2 => 'Value',},
1.340 raeburn 438: {col1 => 'Nightly status check e-mail',
439: col2 => 'Settings',},
1.286 raeburn 440: {col1 => 'Ask helpdesk form settings',
441: col2 => 'Value',},],
1.230 raeburn 442: print => \&print_contacts,
443: modify => \&modify_contacts,
1.30 raeburn 444: },
445: 'usercreation' =>
446: { text => 'User creation',
1.67 raeburn 447: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 448: header => [{col1 => 'Format rule type',
449: col2 => 'Format rules in force'},
1.34 raeburn 450: {col1 => 'User account creation',
451: col2 => 'Usernames which may be created',},
1.30 raeburn 452: {col1 => 'Context',
1.43 raeburn 453: col2 => 'Assignable authentication types'}],
1.230 raeburn 454: print => \&print_usercreation,
455: modify => \&modify_usercreation,
1.30 raeburn 456: },
1.224 raeburn 457: 'selfcreation' =>
458: { text => 'Users self-creating accounts',
459: help => 'Domain_Configuration_Self_Creation',
460: header => [{col1 => 'Self-creation with institutional username',
461: col2 => 'Enabled?'},
462: {col1 => 'Institutional user type (login/SSO self-creation)',
463: col2 => 'Information user can enter'},
1.303 raeburn 464: {col1 => 'Self-creation with e-mail verification',
1.224 raeburn 465: col2 => 'Settings'}],
1.230 raeburn 466: print => \&print_selfcreation,
467: modify => \&modify_selfcreation,
1.224 raeburn 468: },
1.69 raeburn 469: 'usermodification' =>
1.33 raeburn 470: { text => 'User modification',
1.67 raeburn 471: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 472: header => [{col1 => 'Target user has role',
1.227 bisitz 473: col2 => 'User information updatable in author context'},
1.33 raeburn 474: {col1 => 'Target user has role',
1.443 raeburn 475: col2 => 'User information updatable by co-author manager'},
476: {col1 => 'Target user has role',
1.227 bisitz 477: col2 => 'User information updatable in course context'}],
1.230 raeburn 478: print => \&print_usermodification,
479: modify => \&modify_usermodification,
1.33 raeburn 480: },
1.69 raeburn 481: 'scantron' =>
1.346 raeburn 482: { text => 'Bubblesheet format',
1.67 raeburn 483: help => 'Domain_Configuration_Scantron_Format',
1.346 raeburn 484: header => [ {col1 => 'Bubblesheet format file',
485: col2 => ''},
486: {col1 => 'Bubblesheet data upload formats',
487: col2 => 'Settings'}],
1.230 raeburn 488: print => \&print_scantron,
489: modify => \&modify_scantron,
1.46 raeburn 490: },
1.86 raeburn 491: 'requestcourses' =>
492: {text => 'Request creation of courses',
493: help => 'Domain_Configuration_Request_Courses',
494: header => [{col1 => 'User affiliation',
1.102 raeburn 495: col2 => 'Availability/Processing of requests',},
496: {col1 => 'Setting',
1.216 raeburn 497: col2 => 'Value'},
498: {col1 => 'Available textbooks',
1.235 raeburn 499: col2 => ''},
1.242 raeburn 500: {col1 => 'Available templates',
501: col2 => ''},
1.235 raeburn 502: {col1 => 'Validation (not official courses)',
503: col2 => 'Value'},],
1.230 raeburn 504: print => \&print_quotas,
505: modify => \&modify_quotas,
1.86 raeburn 506: },
1.163 raeburn 507: 'requestauthor' =>
1.223 bisitz 508: {text => 'Request Authoring Space',
1.163 raeburn 509: help => 'Domain_Configuration_Request_Author',
510: header => [{col1 => 'User affiliation',
511: col2 => 'Availability/Processing of requests',},
512: {col1 => 'Setting',
513: col2 => 'Value'}],
1.230 raeburn 514: print => \&print_quotas,
515: modify => \&modify_quotas,
1.163 raeburn 516: },
1.69 raeburn 517: 'coursecategories' =>
1.120 raeburn 518: { text => 'Cataloging of courses/communities',
1.67 raeburn 519: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 520: header => [{col1 => 'Catalog type/availability',
521: col2 => '',},
522: {col1 => 'Category settings for standard catalog',
1.57 raeburn 523: col2 => '',},
524: {col1 => 'Categories',
525: col2 => '',
526: }],
1.230 raeburn 527: print => \&print_coursecategories,
528: modify => \&modify_coursecategories,
1.69 raeburn 529: },
530: 'serverstatuses' =>
1.77 raeburn 531: {text => 'Access to server status pages',
1.69 raeburn 532: help => 'Domain_Configuration_Server_Status',
533: header => [{col1 => 'Status Page',
534: col2 => 'Other named users',
535: col3 => 'Specific IPs',
536: }],
1.230 raeburn 537: print => \&print_serverstatuses,
538: modify => \&modify_serverstatuses,
1.69 raeburn 539: },
1.118 jms 540: 'helpsettings' =>
1.282 raeburn 541: {text => 'Support settings',
1.118 jms 542: help => 'Domain_Configuration_Help_Settings',
1.282 raeburn 543: header => [{col1 => 'Help Page Settings (logged-in users)',
544: col2 => 'Value'},
545: {col1 => 'Helpdesk Roles',
546: col2 => 'Settings'},],
1.230 raeburn 547: print => \&print_helpsettings,
548: modify => \&modify_helpsettings,
1.118 jms 549: },
1.121 raeburn 550: 'coursedefaults' =>
551: {text => 'Course/Community defaults',
552: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 553: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
554: col2 => 'Value',},
555: {col1 => 'Defaults which can be overridden for each course by a DC',
556: col2 => 'Value',},],
1.230 raeburn 557: print => \&print_coursedefaults,
558: modify => \&modify_coursedefaults,
1.121 raeburn 559: },
1.231 raeburn 560: 'selfenrollment' =>
561: {text => 'Self-enrollment in Course/Community',
562: help => 'Domain_Configuration_Selfenrollment',
563: header => [{col1 => 'Configuration Rights',
564: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
565: {col1 => 'Defaults',
566: col2 => 'Value'},
567: {col1 => 'Self-enrollment validation (optional)',
568: col2 => 'Value'},],
569: print => \&print_selfenrollment,
570: modify => \&modify_selfenrollment,
571: },
1.120 raeburn 572: 'privacy' =>
1.427 raeburn 573: {text => 'Role assignments and user privacy',
1.120 raeburn 574: help => 'Domain_Configuration_User_Privacy',
1.357 raeburn 575: header => [{col1 => 'Role assigned in different domain',
576: col2 => 'Approval options'},
577: {col1 => 'Role assigned in different domain to user of type',
578: col2 => 'User information available in that domain'},
579: {col1 => "Role assigned in user's domain",
580: col2 => 'Information viewable by privileged user'},
581: {col1 => "Role assigned in user's domain",
582: col2 => 'Information viewable by unprivileged user'}],
1.230 raeburn 583: print => \&print_privacy,
584: modify => \&modify_privacy,
1.120 raeburn 585: },
1.141 raeburn 586: 'usersessions' =>
1.145 raeburn 587: {text => 'User session hosting/offloading',
1.137 raeburn 588: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 589: header => [{col1 => 'Domain server',
590: col2 => 'Servers to offload sessions to when busy'},
591: {col1 => 'Hosting of users from other domains',
1.137 raeburn 592: col2 => 'Rules'},
593: {col1 => "Hosting domain's own users elsewhere",
594: col2 => 'Rules'}],
1.230 raeburn 595: print => \&print_usersessions,
596: modify => \&modify_usersessions,
1.137 raeburn 597: },
1.279 raeburn 598: 'loadbalancing' =>
1.185 raeburn 599: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 600: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 601: header => [{col1 => 'Balancers',
1.150 raeburn 602: col2 => 'Default destinations',
1.183 bisitz 603: col3 => 'User affiliation',
1.150 raeburn 604: col4 => 'Overrides'},
605: ],
1.230 raeburn 606: print => \&print_loadbalancing,
607: modify => \&modify_loadbalancing,
1.150 raeburn 608: },
1.425 raeburn 609: 'ltitools' =>
1.267 raeburn 610: {text => 'External Tools (LTI)',
1.296 raeburn 611: help => 'Domain_Configuration_LTI_Tools',
1.421 raeburn 612: header => [{col1 => 'Encryption of shared secrets',
613: col2 => 'Settings'},
614: {col1 => 'Rules for shared secrets',
615: col2 => 'Settings'},
616: {col1 => 'Providers',
617: col2 => 'Settings',}],
1.267 raeburn 618: print => \&print_ltitools,
619: modify => \&modify_ltitools,
620: },
1.372 raeburn 621: 'proctoring' =>
622: {text => 'Remote Proctoring Integration',
623: help => 'Domain_Configuration_Proctoring',
624: header => [{col1 => 'Name',
625: col2 => 'Configuration'}],
626: print => \&print_proctoring,
627: modify => \&modify_proctoring,
628: },
1.279 raeburn 629: 'ssl' =>
1.275 raeburn 630: {text => 'LON-CAPA Network (SSL)',
631: help => 'Domain_Configuration_Network_SSL',
632: header => [{col1 => 'Server',
633: col2 => 'Certificate Status'},
634: {col1 => 'Connections to other servers',
635: col2 => 'Rules'},
1.293 raeburn 636: {col1 => 'Connections from other servers',
637: col2 => 'Rules'},
1.275 raeburn 638: {col1 => "Replicating domain's published content",
639: col2 => 'Rules'}],
640: print => \&print_ssl,
641: modify => \&modify_ssl,
642: },
1.279 raeburn 643: 'trust' =>
644: {text => 'Trust Settings',
645: help => 'Domain_Configuration_Trust',
646: header => [{col1 => "Access to this domain's content by others",
647: col2 => 'Rules'},
648: {col1 => "Access to other domain's content by this domain",
649: col2 => 'Rules'},
650: {col1 => "Enrollment in this domain's courses by others",
651: col2 => 'Rules',},
652: {col1 => "Co-author roles in this domain for others",
653: col2 => 'Rules',},
654: {col1 => "Co-author roles for this domain's users elsewhere",
655: col2 => 'Rules',},
656: {col1 => "Domain roles in this domain assignable to others",
657: col2 => 'Rules'},
658: {col1 => "Course catalog for this domain displayed elsewhere",
659: col2 => 'Rules'},
660: {col1 => "Requests for creation of courses in this domain by others",
661: col2 => 'Rules'},
662: {col1 => "Users in other domains can send messages to this domain",
663: col2 => 'Rules'},],
664: print => \&print_trust,
665: modify => \&modify_trust,
666: },
1.425 raeburn 667: 'lti' =>
1.405 raeburn 668: {text => 'LTI Link Protection and LTI Consumers',
1.320 raeburn 669: help => 'Domain_Configuration_LTI_Provider',
1.405 raeburn 670: header => [{col1 => 'Encryption of shared secrets',
671: col2 => 'Settings'},
1.425 raeburn 672: {col1 => 'Rules for shared secrets',
1.405 raeburn 673: col2 => 'Settings'},
1.434 raeburn 674: {col1 => 'Link Protectors in Courses',
1.436 raeburn 675: col2 => 'Values'},
1.406 raeburn 676: {col1 => 'Link Protectors',
1.405 raeburn 677: col2 => 'Settings'},
678: {col1 => 'Consumers',
679: col2 => 'Settings'},],
1.320 raeburn 680: print => \&print_lti,
681: modify => \&modify_lti,
682: },
1.425 raeburn 683: 'ipaccess' =>
1.394 raeburn 684: {text => 'IP-based access control',
685: help => 'Domain_Configuration_IP_Access',
686: header => [{col1 => 'Setting',
687: col2 => 'Value'},],
688: print => \&print_ipaccess,
689: modify => \&modify_ipaccess,
690: },
1.436 raeburn 691: 'authordefaults' =>
1.429 raeburn 692: {text => 'Authoring Space defaults',
693: help => 'Domain_Configuration_Author_Defaults',
694: header => [{col1 => 'Defaults which can be overridden by Author',
695: col2 => 'Settings',},
696: {col1 => 'Defaults which can be overridden by a Dom. Coord.',
697: col2 => 'Settings',},],
698: print => \&print_authordefaults,
699: modify => \&modify_authordefaults,
700: },
1.3 raeburn 701: );
1.110 raeburn 702: if (keys(%servers) > 1) {
703: $prefs{'login'} = { text => 'Log-in page options',
704: help => 'Domain_Configuration_Login_Page',
705: header => [{col1 => 'Log-in Service',
706: col2 => 'Server Setting',},
707: {col1 => 'Log-in Page Items',
1.405 raeburn 708: col2 => 'Settings'},
1.168 raeburn 709: {col1 => 'Log-in Help',
1.256 raeburn 710: col2 => 'Value'},
711: {col1 => 'Custom HTML in document head',
1.386 raeburn 712: col2 => 'Value'},
713: {col1 => 'SSO',
714: col2 => 'Dual login: SSO and non-SSO options'},
715: ],
1.230 raeburn 716: print => \&print_login,
717: modify => \&modify_login,
1.110 raeburn 718: };
719: }
1.174 foxr 720:
1.6 raeburn 721: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 722: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 723: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 724: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 725: text=>"Settings to display/modify"});
1.9 raeburn 726: my $confname = $dom.'-domainconfig';
1.174 foxr 727:
1.3 raeburn 728: if ($phase eq 'process') {
1.212 raeburn 729: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
730: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 731: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 732: $r->rflush();
1.212 raeburn 733: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 734: }
1.30 raeburn 735: } elsif ($phase eq 'display') {
1.192 raeburn 736: my $js = &recaptcha_js().
1.236 raeburn 737: &toggle_display_js();
1.171 raeburn 738: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 739: my ($othertitle,$usertypes,$types) =
740: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 741: $js .= &lonbalance_targets_js($dom,$types,\%servers,
742: $domconfig{'loadbalancing'}).
1.170 raeburn 743: &new_spares_js().
744: &common_domprefs_js().
745: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 746: }
1.216 raeburn 747: if (grep(/^requestcourses$/,@actions)) {
748: my $javascript_validations;
749: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
750: $js .= <<END;
751: <script type="text/javascript">
752: $javascript_validations
753: </script>
754: $coursebrowserjs
755: END
1.394 raeburn 756: } elsif (grep(/^ipaccess$/,@actions)) {
757: $js .= &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
1.216 raeburn 758: }
1.305 raeburn 759: if (grep(/^selfcreation$/,@actions)) {
760: $js .= &selfcreate_javascript();
761: }
1.286 raeburn 762: if (grep(/^contacts$/,@actions)) {
763: $js .= &contacts_javascript();
764: }
1.346 raeburn 765: if (grep(/^scantron$/,@actions)) {
766: $js .= &scantron_javascript();
767: }
1.150 raeburn 768: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 769: } else {
1.180 raeburn 770: # check if domconfig user exists for the domain.
771: my $servadm = $r->dir_config('lonAdmEMail');
772: my ($configuserok,$author_ok,$switchserver) =
773: &config_check($dom,$confname,$servadm);
774: unless ($configuserok eq 'ok') {
1.181 raeburn 775: &Apache::lonconfigsettings::print_header($r,$phase,$context);
776: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 777: $confname).
1.181 raeburn 778: '<br />'
779: );
1.180 raeburn 780: if ($switchserver) {
1.181 raeburn 781: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
782: '<br />'.
783: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
784: '<br />'.
785: &mt('The "[_1]" user can be created automatically when a Domain Coordinator visits the web-based "Set domain configuration" screen, in a session hosted on the primary library server.',$confname).
786: '<br />'.
787: &mt('To do that now, use the following link: [_1]',$switchserver)
788: );
789: } else {
790: $r->print(&mt('To create that user from the command line run the ./UPDATE script found in the top level directory of the extracted LON-CAPA tarball.').
791: '<br />'.
792: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
793: );
1.180 raeburn 794: }
795: $r->print(&Apache::loncommon::end_page());
796: return OK;
797: }
1.21 raeburn 798: if (keys(%domconfig) == 0) {
799: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 800: my @ids=&Apache::lonnet::current_machine_ids();
801: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 802: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 803: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 804: my $custom_img_count = 0;
805: foreach my $img (@loginimages) {
806: if ($designhash{$dom.'.login.'.$img} ne '') {
807: $custom_img_count ++;
808: }
809: }
810: foreach my $role (@roles) {
811: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
812: $custom_img_count ++;
813: }
814: }
815: if ($custom_img_count > 0) {
1.94 raeburn 816: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 817: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 818: $r->print(
819: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
820: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
821: &mt("Thereafter, (with a Domain Coordinator role selected in the domain) you will be able to update settings when logged in to any server in the LON-CAPA network.").'<br />'.
822: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
823: if ($switch_server) {
1.30 raeburn 824: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 825: }
1.91 raeburn 826: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 827: return OK;
828: }
829: }
830: }
1.91 raeburn 831: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 832: }
833: return OK;
834: }
835:
836: sub process_changes {
1.205 raeburn 837: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 838: my %domconfig;
839: if (ref($values) eq 'HASH') {
840: %domconfig = %{$values};
841: }
1.3 raeburn 842: my $output;
843: if ($action eq 'login') {
1.205 raeburn 844: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 845: } elsif ($action eq 'rolecolors') {
1.9 raeburn 846: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 847: $lastactref,%domconfig);
1.3 raeburn 848: } elsif ($action eq 'quotas') {
1.216 raeburn 849: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 850: } elsif ($action eq 'autoenroll') {
1.205 raeburn 851: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 852: } elsif ($action eq 'autoupdate') {
853: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 854: } elsif ($action eq 'autocreate') {
855: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 856: } elsif ($action eq 'directorysrch') {
1.295 raeburn 857: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 858: } elsif ($action eq 'usercreation') {
1.28 raeburn 859: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 860: } elsif ($action eq 'selfcreation') {
1.305 raeburn 861: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 862: } elsif ($action eq 'usermodification') {
863: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 864: } elsif ($action eq 'contacts') {
1.205 raeburn 865: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 866: } elsif ($action eq 'defaults') {
1.212 raeburn 867: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 868: } elsif ($action eq 'scantron') {
1.205 raeburn 869: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 870: } elsif ($action eq 'coursecategories') {
1.239 raeburn 871: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 872: } elsif ($action eq 'serverstatuses') {
873: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 874: } elsif ($action eq 'requestcourses') {
1.216 raeburn 875: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 876: } elsif ($action eq 'requestauthor') {
1.216 raeburn 877: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 878: } elsif ($action eq 'helpsettings') {
1.285 raeburn 879: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 880: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 881: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 882: } elsif ($action eq 'selfenrollment') {
883: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 884: } elsif ($action eq 'usersessions') {
1.212 raeburn 885: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 886: } elsif ($action eq 'loadbalancing') {
887: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 888: } elsif ($action eq 'ltitools') {
889: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.372 raeburn 890: } elsif ($action eq 'proctoring') {
891: $output = &modify_proctoring($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 892: } elsif ($action eq 'ssl') {
893: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 894: } elsif ($action eq 'trust') {
895: $output = &modify_trust($dom,$lastactref,%domconfig);
1.320 raeburn 896: } elsif ($action eq 'lti') {
897: $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.357 raeburn 898: } elsif ($action eq 'privacy') {
1.427 raeburn 899: $output = &modify_privacy($dom,$lastactref,%domconfig);
1.354 raeburn 900: } elsif ($action eq 'passwords') {
901: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.373 raeburn 902: } elsif ($action eq 'wafproxy') {
903: $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
1.394 raeburn 904: } elsif ($action eq 'ipaccess') {
905: $output = &modify_ipaccess($dom,$lastactref,%domconfig);
1.429 raeburn 906: } elsif ($action eq 'authordefaults') {
907: $output = &modify_authordefaults($dom,$lastactref,%domconfig);
1.3 raeburn 908: }
909: return $output;
910: }
911:
912: sub print_config_box {
1.9 raeburn 913: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 914: my $rowtotal = 0;
1.49 raeburn 915: my $output;
916: if ($action eq 'coursecategories') {
917: $output = &coursecategories_javascript($settings);
1.236 raeburn 918: } elsif ($action eq 'defaults') {
919: $output = &defaults_javascript($settings);
1.354 raeburn 920: } elsif ($action eq 'passwords') {
1.405 raeburn 921: $output = &passwords_javascript($action);
1.282 raeburn 922: } elsif ($action eq 'helpsettings') {
923: my (%privs,%levelscurrent);
924: my %full=();
925: my %levels=(
926: course => {},
927: domain => {},
928: system => {},
929: );
930: my $context = 'domain';
931: my $crstype = 'Course';
932: my $formname = 'display';
933: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
934: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
935: $output =
1.425 raeburn 936: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
1.282 raeburn 937: \@templateroles);
1.334 raeburn 938: } elsif ($action eq 'ltitools') {
1.421 raeburn 939: $output .= &Apache::lonconfigsettings::ltitools_javascript($settings);
1.334 raeburn 940: } elsif ($action eq 'lti') {
1.421 raeburn 941: $output .= &passwords_javascript('ltisecrets')."\n".
1.405 raeburn 942: <i_javascript($dom,$settings);
1.372 raeburn 943: } elsif ($action eq 'proctoring') {
944: $output .= &proctoring_javascript($settings);
1.381 raeburn 945: } elsif ($action eq 'wafproxy') {
946: $output .= &wafproxy_javascript($dom);
1.385 raeburn 947: } elsif ($action eq 'autoupdate') {
948: $output .= &autoupdate_javascript();
1.399 raeburn 949: } elsif ($action eq 'autoenroll') {
950: $output .= &autoenroll_javascript();
1.386 raeburn 951: } elsif ($action eq 'login') {
952: $output .= &saml_javascript();
1.394 raeburn 953: } elsif ($action eq 'ipaccess') {
954: $output .= &ipaccess_javascript($settings);
1.429 raeburn 955: } elsif ($action eq 'authordefaults') {
956: $output .= &authordefaults_javascript();
1.91 raeburn 957: }
1.236 raeburn 958: $output .=
1.30 raeburn 959: '<table class="LC_nested_outer">
1.3 raeburn 960: <tr>
1.306 raeburn 961: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 962: &mt($item->{text}).' '.
963: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
964: '</tr>';
1.30 raeburn 965: $rowtotal ++;
1.110 raeburn 966: my $numheaders = 1;
967: if (ref($item->{'header'}) eq 'ARRAY') {
968: $numheaders = scalar(@{$item->{'header'}});
969: }
970: if ($numheaders > 1) {
1.64 raeburn 971: my $colspan = '';
1.145 raeburn 972: my $rightcolspan = '';
1.369 raeburn 973: my $leftnobr = '';
1.238 raeburn 974: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 975: ($action eq 'directorysrch') ||
1.386 raeburn 976: (($action eq 'login') && ($numheaders < 5))) {
1.64 raeburn 977: $colspan = ' colspan="2"';
978: }
1.145 raeburn 979: if ($action eq 'usersessions') {
980: $rightcolspan = ' colspan="3"';
981: }
1.369 raeburn 982: if ($action eq 'passwords') {
983: $leftnobr = ' LC_nobreak';
984: }
1.30 raeburn 985: $output .= '
1.3 raeburn 986: <tr>
987: <td>
988: <table class="LC_nested">
989: <tr class="LC_info_row">
1.369 raeburn 990: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 991: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 992: </tr>';
1.69 raeburn 993: $rowtotal ++;
1.230 raeburn 994: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 995: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 996: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 997: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
1.421 raeburn 998: ($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'wafproxy') ||
1.429 raeburn 999: ($action eq 'lti') || ($action eq 'ltitools') || ($action eq 'authordefaults')) {
1.230 raeburn 1000: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.354 raeburn 1001: } elsif ($action eq 'passwords') {
1002: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 1003: } elsif ($action eq 'coursecategories') {
1.230 raeburn 1004: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.346 raeburn 1005: } elsif ($action eq 'scantron') {
1006: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 1007: } elsif ($action eq 'login') {
1.386 raeburn 1008: if ($numheaders == 5) {
1.168 raeburn 1009: $colspan = ' colspan="2"';
1010: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
1011: } else {
1012: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
1013: }
1.230 raeburn 1014: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 1015: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 1016: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1017: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 1018: }
1.30 raeburn 1019: $output .= '
1.6 raeburn 1020: </table>
1021: </td>
1022: </tr>
1023: <tr>
1024: <td>
1025: <table class="LC_nested">
1026: <tr class="LC_info_row">
1.230 raeburn 1027: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 1028: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 1029: </tr>';
1030: $rowtotal ++;
1.230 raeburn 1031: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
1032: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 1033: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.409 raeburn 1034: ($action eq 'trust') || ($action eq 'contacts') || ($action eq 'defaults') ||
1.421 raeburn 1035: ($action eq 'privacy') || ($action eq 'passwords') || ($action eq 'lti') ||
1.443 raeburn 1036: ($action eq 'ltitools') || ($action eq 'usermodification')) {
1.238 raeburn 1037: if ($action eq 'coursecategories') {
1038: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
1039: $colspan = ' colspan="2"';
1.279 raeburn 1040: } elsif ($action eq 'trust') {
1041: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.354 raeburn 1042: } elsif ($action eq 'passwords') {
1043: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.434 raeburn 1044: } elsif ($action eq 'lti') {
1045: $output .= $item->{'print'}->('upper',$dom,$settings,\$rowtotal).'
1046: </table>
1047: </td>
1048: </tr>
1049: <tr>
1050: <td>
1051: <table class="LC_nested">
1052: <tr class="LC_info_row">
1053: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1054: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1055: </tr>'."\n".
1056: $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
1.238 raeburn 1057: } else {
1058: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
1059: }
1.279 raeburn 1060: if ($action eq 'trust') {
1061: $output .= '
1062: </table>
1063: </td>
1064: </tr>';
1065: my @trusthdrs = qw(2 3 4 5 6 7);
1066: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
1067: for (my $i=0; $i<@trusthdrs; $i++) {
1068: $output .= '
1069: <tr>
1070: <td>
1071: <table class="LC_nested">
1072: <tr class="LC_info_row">
1073: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
1074: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
1075: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
1076: </table>
1077: </td>
1078: </tr>';
1079: }
1080: $output .= '
1081: <tr>
1082: <td>
1083: <table class="LC_nested">
1084: <tr class="LC_info_row">
1085: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
1086: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
1087: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1088: } else {
1.434 raeburn 1089: my $hdridx = 2;
1090: if ($action eq 'lti') {
1091: $hdridx = 3;
1092: }
1.279 raeburn 1093: $output .= '
1.63 raeburn 1094: </table>
1095: </td>
1096: </tr>
1097: <tr>
1098: <td>
1099: <table class="LC_nested">
1100: <tr class="LC_info_row">
1.434 raeburn 1101: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col1'}).'</td>
1102: <td class="LC_right_item">'.&mt($item->{'header'}->[$hdridx]->{'col2'}).'</td>
1.238 raeburn 1103: </tr>'."\n";
1.279 raeburn 1104: if ($action eq 'coursecategories') {
1105: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.405 raeburn 1106: } elsif (($action eq 'contacts') || ($action eq 'privacy') ||
1107: ($action eq 'passwords') || ($action eq 'lti')) {
1.354 raeburn 1108: if ($action eq 'passwords') {
1109: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
1110: } else {
1111: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
1112: }
1.434 raeburn 1113: $hdridx ++;
1.354 raeburn 1114: $output .= '
1.340 raeburn 1115: </tr>
1116: </table>
1117: </td>
1118: </tr>
1119: <tr>
1120: <td>
1121: <table class="LC_nested">
1122: <tr class="LC_info_row">
1.434 raeburn 1123: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col1'}).'</td>
1124: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col2'}).'</td></tr>'."\n";
1.354 raeburn 1125: if ($action eq 'passwords') {
1126: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
1127: } else {
1128: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1129: }
1130: $output .= '
1.340 raeburn 1131: </table>
1132: </td>
1133: </tr>
1134: <tr>';
1.279 raeburn 1135: } else {
1136: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1137: }
1.238 raeburn 1138: }
1.63 raeburn 1139: $rowtotal ++;
1.443 raeburn 1140: } elsif (($action eq 'coursedefaults') || ($action eq 'authordefaults') ||
1.409 raeburn 1141: ($action eq 'directorysrch') || ($action eq 'helpsettings') ||
1.443 raeburn 1142: ($action eq 'wafproxy')) {
1.230 raeburn 1143: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.346 raeburn 1144: } elsif ($action eq 'scantron') {
1145: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.293 raeburn 1146: } elsif ($action eq 'ssl') {
1147: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
1148: </table>
1149: </td>
1150: </tr>
1151: <tr>
1152: <td>
1153: <table class="LC_nested">
1154: <tr class="LC_info_row">
1155: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1156: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1157: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
1158: </table>
1159: </td>
1160: </tr>
1161: <tr>
1162: <td>
1163: <table class="LC_nested">
1164: <tr class="LC_info_row">
1165: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1166: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
1167: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 1168: } elsif ($action eq 'login') {
1.386 raeburn 1169: if ($numheaders == 5) {
1.168 raeburn 1170: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
1171: </table>
1172: </td>
1173: </tr>
1174: <tr>
1175: <td>
1176: <table class="LC_nested">
1177: <tr class="LC_info_row">
1178: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 1179: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 1180: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1181: $rowtotal ++;
1182: } else {
1183: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1184: }
1.256 raeburn 1185: $output .= '
1186: </table>
1187: </td>
1188: </tr>
1189: <tr>
1190: <td>
1191: <table class="LC_nested">
1192: <tr class="LC_info_row">';
1.386 raeburn 1193: if ($numheaders == 5) {
1.256 raeburn 1194: $output .= '
1195: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1196: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1197: </tr>';
1198: } else {
1199: $output .= '
1200: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1201: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1202: </tr>';
1203: }
1204: $rowtotal ++;
1.386 raeburn 1205: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
1206: </table>
1207: </td>
1208: </tr>
1209: <tr>
1210: <td>
1211: <table class="LC_nested">
1212: <tr class="LC_info_row">';
1213: if ($numheaders == 5) {
1214: $output .= '
1215: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1216: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1217: </tr>';
1218: } else {
1219: $output .= '
1220: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1221: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1222: </tr>';
1223: }
1224: $rowtotal ++;
1225: $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 1226: } elsif ($action eq 'requestcourses') {
1.247 raeburn 1227: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1228: $rowtotal ++;
1229: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 1230: </table>
1231: </td>
1232: </tr>
1233: <tr>
1234: <td>
1235: <table class="LC_nested">
1236: <tr class="LC_info_row">
1237: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1238: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 1239: &textbookcourses_javascript($settings).
1240: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
1241: </table>
1242: </td>
1243: </tr>
1244: <tr>
1245: <td>
1246: <table class="LC_nested">
1247: <tr class="LC_info_row">
1248: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1249: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1250: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 1251: </table>
1252: </td>
1253: </tr>
1254: <tr>
1255: <td>
1256: <table class="LC_nested">
1257: <tr class="LC_info_row">
1.306 raeburn 1258: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1259: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 1260: </tr>'.
1261: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 1262: } elsif ($action eq 'requestauthor') {
1263: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 1264: $rowtotal ++;
1.122 jms 1265: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1266: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1267: </table>
1268: </td>
1269: </tr>
1270: <tr>
1271: <td>
1272: <table class="LC_nested">
1273: <tr class="LC_info_row">
1.306 raeburn 1274: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69 raeburn 1275: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306 raeburn 1276: <td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1277: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1278: </tr>'.
1.30 raeburn 1279: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1280: </table>
1281: </td>
1282: </tr>
1283: <tr>
1284: <td>
1285: <table class="LC_nested">
1286: <tr class="LC_info_row">
1.59 bisitz 1287: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1288: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1289: </tr>'.
1.30 raeburn 1290: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1291: $rowtotal += 2;
1.6 raeburn 1292: }
1.3 raeburn 1293: } else {
1.30 raeburn 1294: $output .= '
1.3 raeburn 1295: <tr>
1296: <td>
1297: <table class="LC_nested">
1.30 raeburn 1298: <tr class="LC_info_row">';
1.277 raeburn 1299: if ($action eq 'login') {
1.30 raeburn 1300: $output .= '
1.59 bisitz 1301: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1302: } elsif ($action eq 'serverstatuses') {
1303: $output .= '
1.306 raeburn 1304: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69 raeburn 1305: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1306:
1.6 raeburn 1307: } else {
1.30 raeburn 1308: $output .= '
1.306 raeburn 1309: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1310: }
1.72 raeburn 1311: if (defined($item->{'header'}->[0]->{'col3'})) {
1.306 raeburn 1312: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72 raeburn 1313: &mt($item->{'header'}->[0]->{'col2'});
1314: if ($action eq 'serverstatuses') {
1315: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1316: }
1.69 raeburn 1317: } else {
1.306 raeburn 1318: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1319: &mt($item->{'header'}->[0]->{'col2'});
1320: }
1321: $output .= '</td>';
1322: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1323: if (defined($item->{'header'}->[0]->{'col4'})) {
1.306 raeburn 1324: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150 raeburn 1325: &mt($item->{'header'}->[0]->{'col3'});
1326: } else {
1.306 raeburn 1327: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1328: &mt($item->{'header'}->[0]->{'col3'});
1329: }
1.69 raeburn 1330: if ($action eq 'serverstatuses') {
1331: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1332: }
1333: $output .= '</td>';
1.6 raeburn 1334: }
1.150 raeburn 1335: if ($item->{'header'}->[0]->{'col4'}) {
1.306 raeburn 1336: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1337: &mt($item->{'header'}->[0]->{'col4'});
1338: }
1.69 raeburn 1339: $output .= '</tr>';
1.48 raeburn 1340: $rowtotal ++;
1.168 raeburn 1341: if ($action eq 'quotas') {
1.86 raeburn 1342: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1343: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1344: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.421 raeburn 1345: ($action eq 'proctoring') || ($action eq 'ipaccess')) {
1.230 raeburn 1346: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1347: }
1.3 raeburn 1348: }
1.30 raeburn 1349: $output .= '
1.3 raeburn 1350: </table>
1351: </td>
1352: </tr>
1.30 raeburn 1353: </table><br />';
1354: return ($output,$rowtotal);
1.1 raeburn 1355: }
1356:
1.3 raeburn 1357: sub print_login {
1.168 raeburn 1358: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.386 raeburn 1359: my ($css_class,$datatable,$switchserver,%lt);
1.6 raeburn 1360: my %choices = &login_choices();
1.386 raeburn 1361: if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
1362: %lt = &login_file_options();
1363: $switchserver = &check_switchserver($dom,$confname);
1364: }
1.168 raeburn 1365: if ($caller eq 'service') {
1.149 raeburn 1366: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1367: my $choice = $choices{'disallowlogin'};
1368: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1369: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306 raeburn 1370: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1371: '<th>'.$choices{'server'}.'</th>'.
1372: '<th>'.$choices{'serverpath'}.'</th>'.
1373: '<th>'.$choices{'custompath'}.'</th>'.
1374: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1375: my %disallowed;
1376: if (ref($settings) eq 'HASH') {
1377: if (ref($settings->{'loginvia'}) eq 'HASH') {
1378: %disallowed = %{$settings->{'loginvia'}};
1379: }
1380: }
1381: foreach my $lonhost (sort(keys(%servers))) {
1382: my $direct = 'selected="selected"';
1.128 raeburn 1383: if (ref($disallowed{$lonhost}) eq 'HASH') {
1384: if ($disallowed{$lonhost}{'server'} ne '') {
1385: $direct = '';
1386: }
1.110 raeburn 1387: }
1.115 raeburn 1388: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1389: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1390: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1391: '</option>';
1.184 raeburn 1392: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1393: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1394: my $selected = '';
1.128 raeburn 1395: if (ref($disallowed{$lonhost}) eq 'HASH') {
1396: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1397: $selected = 'selected="selected"';
1398: }
1.110 raeburn 1399: }
1400: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1401: $servers{$hostid}.'</option>';
1402: }
1.128 raeburn 1403: $datatable .= '</select></td>'.
1404: '<td><select name="'.$lonhost.'_serverpath">';
1405: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1406: my $pathname = $path;
1407: if ($path eq 'custom') {
1408: $pathname = &mt('Custom Path').' ->';
1409: }
1410: my $selected = '';
1411: if (ref($disallowed{$lonhost}) eq 'HASH') {
1412: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1413: $selected = 'selected="selected"';
1414: }
1415: } elsif ($path eq '') {
1416: $selected = 'selected="selected"';
1417: }
1418: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1419: }
1420: $datatable .= '</select></td>';
1421: my ($custom,$exempt);
1422: if (ref($disallowed{$lonhost}) eq 'HASH') {
1423: $custom = $disallowed{$lonhost}{'custompath'};
1424: $exempt = $disallowed{$lonhost}{'exempt'};
1425: }
1426: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1427: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1428: '</tr>';
1.110 raeburn 1429: }
1430: $datatable .= '</table></td></tr>';
1431: return $datatable;
1.168 raeburn 1432: } elsif ($caller eq 'page') {
1433: my %defaultchecked = (
1434: 'coursecatalog' => 'on',
1.188 raeburn 1435: 'helpdesk' => 'on',
1.168 raeburn 1436: 'adminmail' => 'off',
1437: 'newuser' => 'off',
1438: );
1.188 raeburn 1439: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1440: my (%checkedon,%checkedoff);
1.42 raeburn 1441: foreach my $item (@toggles) {
1.168 raeburn 1442: if ($defaultchecked{$item} eq 'on') {
1443: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1444: $checkedoff{$item} = ' ';
1.168 raeburn 1445: } elsif ($defaultchecked{$item} eq 'off') {
1446: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1447: $checkedon{$item} = ' ';
1448: }
1.1 raeburn 1449: }
1.168 raeburn 1450: my @images = ('img','logo','domlogo','login');
1.402 raeburn 1451: my @alttext = ('img','logo','domlogo');
1.168 raeburn 1452: my @logintext = ('textcol','bgcol');
1453: my @bgs = ('pgbg','mainbg','sidebg');
1454: my @links = ('link','alink','vlink');
1455: my %designhash = &Apache::loncommon::get_domainconf($dom);
1456: my %defaultdesign = %Apache::loncommon::defaultdesign;
1457: my (%is_custom,%designs);
1458: my %defaults = (
1459: font => $defaultdesign{'login.font'},
1460: );
1.6 raeburn 1461: foreach my $item (@images) {
1.168 raeburn 1462: $defaults{$item} = $defaultdesign{'login.'.$item};
1463: $defaults{'showlogo'}{$item} = 1;
1464: }
1465: foreach my $item (@bgs) {
1466: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1467: }
1.41 raeburn 1468: foreach my $item (@logintext) {
1.168 raeburn 1469: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1470: }
1.168 raeburn 1471: foreach my $item (@links) {
1472: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1473: }
1.168 raeburn 1474: if (ref($settings) eq 'HASH') {
1475: foreach my $item (@toggles) {
1476: if ($settings->{$item} eq '1') {
1477: $checkedon{$item} = ' checked="checked" ';
1478: $checkedoff{$item} = ' ';
1479: } elsif ($settings->{$item} eq '0') {
1480: $checkedoff{$item} = ' checked="checked" ';
1481: $checkedon{$item} = ' ';
1482: }
1483: }
1484: foreach my $item (@images) {
1485: if (defined($settings->{$item})) {
1486: $designs{$item} = $settings->{$item};
1487: $is_custom{$item} = 1;
1488: }
1489: if (defined($settings->{'showlogo'}{$item})) {
1490: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1491: }
1492: }
1.402 raeburn 1493: foreach my $item (@alttext) {
1494: if (ref($settings->{'alttext'}) eq 'HASH') {
1495: if ($settings->{'alttext'}->{$item} ne '') {
1496: $designs{'alttext'}{$item} = $settings->{'alttext'}{$item};
1497: }
1498: }
1499: }
1.168 raeburn 1500: foreach my $item (@logintext) {
1501: if ($settings->{$item} ne '') {
1502: $designs{'logintext'}{$item} = $settings->{$item};
1503: $is_custom{$item} = 1;
1504: }
1505: }
1506: if ($settings->{'font'} ne '') {
1507: $designs{'font'} = $settings->{'font'};
1508: $is_custom{'font'} = 1;
1509: }
1510: foreach my $item (@bgs) {
1511: if ($settings->{$item} ne '') {
1512: $designs{'bgs'}{$item} = $settings->{$item};
1513: $is_custom{$item} = 1;
1514: }
1515: }
1516: foreach my $item (@links) {
1517: if ($settings->{$item} ne '') {
1518: $designs{'links'}{$item} = $settings->{$item};
1519: $is_custom{$item} = 1;
1520: }
1521: }
1522: } else {
1523: if ($designhash{$dom.'.login.font'} ne '') {
1524: $designs{'font'} = $designhash{$dom.'.login.font'};
1525: $is_custom{'font'} = 1;
1526: }
1527: foreach my $item (@images) {
1528: if ($designhash{$dom.'.login.'.$item} ne '') {
1529: $designs{$item} = $designhash{$dom.'.login.'.$item};
1530: $is_custom{$item} = 1;
1531: }
1532: }
1533: foreach my $item (@bgs) {
1534: if ($designhash{$dom.'.login.'.$item} ne '') {
1535: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1536: $is_custom{$item} = 1;
1537: }
1.6 raeburn 1538: }
1.168 raeburn 1539: foreach my $item (@links) {
1540: if ($designhash{$dom.'.login.'.$item} ne '') {
1541: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1542: $is_custom{$item} = 1;
1543: }
1.6 raeburn 1544: }
1545: }
1.168 raeburn 1546: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1547: logo => 'Institution Logo',
1548: domlogo => 'Domain Logo',
1549: login => 'Login box');
1550: my $itemcount = 1;
1551: foreach my $item (@toggles) {
1552: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1553: $datatable .=
1554: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1555: '</td><td>'.
1556: '<span class="LC_nobreak"><label><input type="radio" name="'.
1557: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1558: '</label> <label><input type="radio" name="'.$item.'"'.
1559: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1560: '</tr>';
1561: $itemcount ++;
1.6 raeburn 1562: }
1.168 raeburn 1563: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1564: $datatable .= '</tr></table></td></tr>';
1565: } elsif ($caller eq 'help') {
1.386 raeburn 1566: my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1.168 raeburn 1567: my $itemcount = 1;
1568: $defaulturl = '/adm/loginproblems.html';
1569: $defaulttype = 'default';
1570: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1571: my @currlangs;
1572: if (ref($settings) eq 'HASH') {
1573: if (ref($settings->{'helpurl'}) eq 'HASH') {
1574: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1575: next if ($settings->{'helpurl'}{$key} eq '');
1576: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1577: $type{$key} = 'custom';
1578: unless ($key eq 'nolang') {
1579: push(@currlangs,$key);
1580: }
1581: }
1582: } elsif ($settings->{'helpurl'} ne '') {
1583: $type{'nolang'} = 'custom';
1584: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1585: }
1586: }
1.168 raeburn 1587: foreach my $lang ('nolang',sort(@currlangs)) {
1588: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1589: $datatable .= '<tr'.$css_class.'>';
1590: if ($url{$lang} eq '') {
1591: $url{$lang} = $defaulturl;
1592: }
1593: if ($type{$lang} eq '') {
1594: $type{$lang} = $defaulttype;
1595: }
1596: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1597: if ($lang eq 'nolang') {
1598: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1599: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1600: } else {
1601: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1602: $langchoices{$lang},
1603: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1604: }
1605: $datatable .= '</span></td>'."\n".
1606: '<td class="LC_left_item">';
1607: if ($type{$lang} eq 'custom') {
1608: $datatable .= '<span class="LC_nobreak"><label>'.
1609: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1610: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1611: } else {
1612: $datatable .= $lt{'upl'};
1613: }
1614: $datatable .='<br />';
1615: if ($switchserver) {
1616: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1617: } else {
1618: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1619: }
1.168 raeburn 1620: $datatable .= '</td></tr>';
1621: $itemcount ++;
1.6 raeburn 1622: }
1.168 raeburn 1623: my @addlangs;
1624: foreach my $lang (sort(keys(%langchoices))) {
1625: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1626: push(@addlangs,$lang);
1627: }
1628: if (@addlangs > 0) {
1629: my %toadd;
1630: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1631: $toadd{''} = &mt('Select');
1632: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1633: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1634: &mt('Add log-in help page for a specific language:').' '.
1635: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1636: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1637: if ($switchserver) {
1638: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1639: } else {
1640: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1641: }
1.168 raeburn 1642: $datatable .= '</td></tr>';
1.169 raeburn 1643: $itemcount ++;
1.6 raeburn 1644: }
1.169 raeburn 1645: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1646: } elsif ($caller eq 'headtag') {
1647: my %domservers = &Apache::lonnet::get_servers($dom);
1648: my $choice = $choices{'headtag'};
1649: $css_class = ' class="LC_odd_row"';
1650: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306 raeburn 1651: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256 raeburn 1652: '<th>'.$choices{'current'}.'</th>'.
1653: '<th>'.$choices{'action'}.'</th>'.
1654: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1655: my (%currurls,%currexempt);
1656: if (ref($settings) eq 'HASH') {
1657: if (ref($settings->{'headtag'}) eq 'HASH') {
1658: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1659: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1660: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1661: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1662: }
1663: }
1664: }
1665: }
1666: foreach my $lonhost (sort(keys(%domservers))) {
1667: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1668: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1669: if ($currurls{$lonhost}) {
1670: $datatable .= '<td class="LC_right_item"><a href="'.
1671: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1672: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1673: '">'.$lt{'curr'}.'</a></td>'.
1674: '<td><span class="LC_nobreak"><label>'.
1675: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1676: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1677: } else {
1678: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1679: }
1680: $datatable .='<br />';
1681: if ($switchserver) {
1682: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1683: } else {
1684: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1685: }
1.330 raeburn 1686: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256 raeburn 1687: }
1688: $datatable .= '</table></td></tr>';
1.386 raeburn 1689: } elsif ($caller eq 'saml') {
1690: my %domservers = &Apache::lonnet::get_servers($dom);
1691: $datatable .= '<tr><td colspan="3" style="text-align: left">'.
1692: '<table><tr><th>'.$choices{'hostid'}.'</th>'.
1693: '<th>'.$choices{'samllanding'}.'</th>'.
1694: '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
1.412 raeburn 1695: my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso,%styleon,%styleoff);
1.386 raeburn 1696: foreach my $lonhost (keys(%domservers)) {
1697: $samlurl{$lonhost} = '/adm/sso';
1698: $styleon{$lonhost} = 'display:none';
1699: $styleoff{$lonhost} = '';
1700: }
1.411 raeburn 1701: if ((ref($settings) eq 'HASH') && (ref($settings->{'saml'}) eq 'HASH')) {
1.386 raeburn 1702: foreach my $lonhost (keys(%{$settings->{'saml'}})) {
1703: if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
1704: $saml{$lonhost} = 1;
1705: $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
1706: $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
1707: $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
1708: $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
1709: $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
1.412 raeburn 1710: $samlwindow{$lonhost} = $settings->{'saml'}{$lonhost}{'window'};
1.386 raeburn 1711: $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
1712: $styleon{$lonhost} = '';
1713: $styleoff{$lonhost} = 'display:none';
1714: } else {
1715: $styleon{$lonhost} = 'display:none';
1716: $styleoff{$lonhost} = '';
1717: }
1718: }
1719: }
1720: my $itemcount = 1;
1721: foreach my $lonhost (sort(keys(%domservers))) {
1722: my $samlon = ' ';
1723: my $samloff = ' checked="checked" ';
1724: if ($saml{$lonhost}) {
1725: $samlon = $samloff;
1726: $samloff = ' ';
1727: }
1.412 raeburn 1728: my $samlwinon = '';
1729: my $samlwinoff = ' checked="checked"';
1730: if ($samlwindow{$lonhost}) {
1731: $samlwinon = $samlwinoff;
1732: $samlwinoff = '';
1733: }
1.386 raeburn 1734: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1735: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
1736: '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
1737: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
1738: &mt('No').'</label>'.(' 'x2).
1739: '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
1740: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
1741: &mt('Yes').'</label></span></td>'.
1742: '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
1.412 raeburn 1743: '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th></tr>'.
1.386 raeburn 1744: '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
1.412 raeburn 1745: '<th>'.&mt('Alt Text').'</th></tr>'.
1746: '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="20" value="'.
1.386 raeburn 1747: $samltext{$lonhost}.'" /></td><td>';
1748: if ($samlimg{$lonhost}) {
1749: $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
1750: '<span class="LC_nobreak"><label>'.
1751: '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
1752: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1753: } else {
1754: $datatable .= $lt{'upl'};
1755: }
1756: $datatable .='<br />';
1757: if ($switchserver) {
1758: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1759: } else {
1760: $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
1761: }
1762: $datatable .= '</td>'.
1.412 raeburn 1763: '<td><input type="text" name="saml_alt_'.$lonhost.'" size="25" '.
1764: 'value="'.$samlalt{$lonhost}.'" /></td></tr></table><br />'.
1765: '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th><th align="center">'.
1766: '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
1767: '<tr><th>'.&mt('URL').'</th><th>'.&mt('Tool Tip').'</th>'.
1768: '<th>'.&mt('Pop-up if iframe').'</th><th>'.&mt('Text').'</th></tr>'.
1769: '<tr'.$css_class.'>'.
1770: '<td><input type="text" name="saml_url_'.$lonhost.'" size="30" '.
1.386 raeburn 1771: 'value="'.$samlurl{$lonhost}.'" /></td>'.
1.412 raeburn 1772: '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="20">'.
1.386 raeburn 1773: $samltitle{$lonhost}.'</textarea></td>'.
1.412 raeburn 1774: '<td><label><input type="radio" name="saml_window_'.$lonhost.'" value=""'.$samlwinoff.'>'.
1775: &mt('No').'</label>'.(' 'x2).'<label><input type="radio" '.
1776: 'name="saml_window_'.$lonhost.'" value="1"'.$samlwinon.'>'.&mt('Yes').'</label></td>'.
1777: '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="12" '.
1.386 raeburn 1778: 'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
1779: '</table></td>'.
1780: '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%"> </td></tr>';
1781: $itemcount ++;
1782: }
1783: $datatable .= '</table></td></tr>';
1.1 raeburn 1784: }
1.6 raeburn 1785: return $datatable;
1786: }
1787:
1788: sub login_choices {
1789: my %choices =
1790: &Apache::lonlocal::texthash (
1.116 bisitz 1791: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1792: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1793: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1794: disallowlogin => "Login page requests redirected",
1795: hostid => "Server",
1.128 raeburn 1796: server => "Redirect to:",
1797: serverpath => "Path",
1798: custompath => "Custom",
1799: exempt => "Exempt IP(s)",
1.110 raeburn 1800: directlogin => "No redirect",
1801: newuser => "Link to create a user account",
1802: img => "Header",
1803: logo => "Main Logo",
1804: domlogo => "Domain Logo",
1805: login => "Log-in Header",
1806: textcol => "Text color",
1807: bgcol => "Box color",
1808: bgs => "Background colors",
1809: links => "Link colors",
1810: font => "Font color",
1811: pgbg => "Header",
1812: mainbg => "Page",
1813: sidebg => "Login box",
1814: link => "Link",
1815: alink => "Active link",
1816: vlink => "Visited link",
1.256 raeburn 1817: headtag => "Custom markup",
1818: action => "Action",
1819: current => "Current",
1.386 raeburn 1820: samllanding => "Dual login?",
1821: samloptions => "Options",
1.402 raeburn 1822: alttext => "Alt text",
1.6 raeburn 1823: );
1824: return %choices;
1825: }
1826:
1.386 raeburn 1827: sub login_file_options {
1828: return &Apache::lonlocal::texthash(
1829: del => 'Delete?',
1830: rep => 'Replace:',
1831: upl => 'Upload:',
1832: curr => 'View contents',
1833: default => 'Default',
1834: custom => 'Custom',
1835: none => 'None',
1836: );
1837: }
1838:
1.394 raeburn 1839: sub print_ipaccess {
1840: my ($dom,$settings,$rowtotal) = @_;
1841: my $css_class;
1842: my $itemcount = 0;
1843: my $datatable;
1844: my %ordered;
1845: if (ref($settings) eq 'HASH') {
1846: foreach my $item (keys(%{$settings})) {
1847: if (ref($settings->{$item}) eq 'HASH') {
1848: my $num = $settings->{$item}{'order'};
1849: if ($num eq '') {
1850: $num = scalar(keys(%{$settings}));
1851: }
1852: $ordered{$num} = $item;
1853: }
1854: }
1855: }
1856: my $maxnum = scalar(keys(%ordered));
1857: if (keys(%ordered)) {
1858: my @items = sort { $a <=> $b } keys(%ordered);
1859: for (my $i=0; $i<@items; $i++) {
1860: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1861: my $item = $ordered{$items[$i]};
1862: my ($name,$ipranges,%commblocks,%courses);
1863: if (ref($settings->{$item}) eq 'HASH') {
1864: $name = $settings->{$item}->{'name'};
1865: $ipranges = $settings->{$item}->{'ip'};
1866: if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
1867: %commblocks = %{$settings->{$item}->{'commblocks'}};
1868: }
1869: if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
1870: %courses = %{$settings->{$item}->{'courses'}};
1871: }
1872: }
1873: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
1874: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1875: .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
1876: for (my $k=0; $k<=$maxnum; $k++) {
1877: my $vpos = $k+1;
1878: my $selstr;
1879: if ($k == $i) {
1880: $selstr = ' selected="selected" ';
1881: }
1882: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1883: }
1884: $datatable .= '</select>'.(' 'x2).
1885: '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
1886: &mt('Delete?').'</label></span></td>'.
1887: '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
1888: &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
1889: '</td></tr>';
1890: $itemcount ++;
1891: }
1892: }
1893: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1894: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
1895: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1896: '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
1897: '<select name="ipaccess_pos_add"'.$chgstr.'>';
1898: for (my $k=0; $k<$maxnum+1; $k++) {
1899: my $vpos = $k+1;
1900: my $selstr;
1901: if ($k == $maxnum) {
1902: $selstr = ' selected="selected" ';
1903: }
1904: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1905: }
1906: $datatable .= '</select> '."\n".
1907: '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1908: '<td colspan="2">'.
1909: &ipaccess_options('add',$itemcount,$dom).
1910: '</td>'."\n".
1911: '</tr>'."\n";
1912: $$rowtotal ++;
1913: return $datatable;
1914: }
1915:
1916: sub ipaccess_options {
1917: my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
1918: my (%currblocks,%currcourses,$output);
1919: if (ref($blocksref) eq 'HASH') {
1920: %currblocks = %{$blocksref};
1921: }
1922: if (ref($coursesref) eq 'HASH') {
1923: %currcourses = %{$coursesref};
1924: }
1925: $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
1926: '<span class="LC_nobreak">'.&mt('Name').': '.
1927: '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
1928: '</span></fieldset>'.
1929: '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
1930: &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
1931: &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
1932: '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
1933: $ipranges.'</textarea></fieldset>'.
1934: '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
1935: &blocker_checkboxes($num,$blocksref).'</fieldset>'.
1936: '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
1937: '<table>';
1938: foreach my $cid (sort(keys(%currcourses))) {
1939: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1940: $output .= '<tr><td><span class="LC_nobreak">'.
1941: '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
1942: &mt('Delete?').' <span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
1943: ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
1944: }
1945: $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').': '.
1946: '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
1947: &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
1948: '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
1949: '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
1950: '</span></td></tr></table>'."\n".
1951: '</fieldset>';
1952: return $output;
1953: }
1954:
1955: sub blocker_checkboxes {
1956: my ($num,$blocks) = @_;
1957: my ($typeorder,$types) = &commblocktype_text();
1958: my $numinrow = 6;
1959: my $output = '<table>';
1960: for (my $i=0; $i<@{$typeorder}; $i++) {
1961: my $block = $typeorder->[$i];
1962: my $blockstatus;
1963: if (ref($blocks) eq 'HASH') {
1964: if ($blocks->{$block} eq 'on') {
1965: $blockstatus = 'checked="checked"';
1966: }
1967: }
1968: my $rem = $i%($numinrow);
1969: if ($rem == 0) {
1970: if ($i > 0) {
1971: $output .= '</tr>';
1972: }
1973: $output .= '<tr>';
1974: }
1975: if ($i == scalar(@{$typeorder})-1) {
1976: my $colsleft = $numinrow-$rem;
1977: if ($colsleft > 1) {
1978: $output .= '<td colspan="'.$colsleft.'">';
1979: } else {
1980: $output .= '<td>';
1981: }
1982: } else {
1983: $output .= '<td>';
1984: }
1985: my $item = 'ipaccess_block_'.$num;
1986: if ($blockstatus) {
1987: $blockstatus = ' '.$blockstatus;
1988: }
1989: $output .= '<span class="LC_nobreak"><label>'."\n".
1990: '<input type="checkbox" name="'.$item.'"'.
1991: $blockstatus.' value="'.$block.'"'.' />'.
1992: $types->{$block}.'</label></span>'."\n".
1993: '<br /></td>';
1994: }
1995: $output .= '</tr></table>';
1996: return $output;
1997: }
1998:
1999: sub commblocktype_text {
2000: my %types = &Apache::lonlocal::texthash(
2001: 'com' => 'Messaging',
2002: 'chat' => 'Chat Room',
2003: 'boards' => 'Discussion',
2004: 'port' => 'Portfolio',
2005: 'groups' => 'Groups',
2006: 'blogs' => 'Blogs',
2007: 'about' => 'User Information',
2008: 'printout' => 'Printouts',
2009: 'passwd' => 'Change Password',
2010: 'grades' => 'Gradebook',
1.397 raeburn 2011: 'search' => 'Course search',
1.447 ! raeburn 2012: 'index' => 'Course content index',
1.397 raeburn 2013: 'wishlist' => 'Stored links',
2014: 'annotate' => 'Annotations',
1.394 raeburn 2015: );
1.447 ! raeburn 2016: my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','index','annotate','passwd'];
1.394 raeburn 2017: return ($typeorder,\%types);
2018: }
2019:
1.6 raeburn 2020: sub print_rolecolors {
1.30 raeburn 2021: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 2022: my %choices = &color_font_choices();
2023: my @bgs = ('pgbg','tabbg','sidebg');
2024: my @links = ('link','alink','vlink');
1.445 raeburn 2025: my @images = ();
1.6 raeburn 2026: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 2027: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 2028: my %defaultdesign = %Apache::loncommon::defaultdesign;
2029: my (%is_custom,%designs);
1.200 raeburn 2030: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 2031: if (ref($settings) eq 'HASH') {
2032: if (ref($settings->{$role}) eq 'HASH') {
2033: if ($settings->{$role}->{'font'} ne '') {
2034: $designs{'font'} = $settings->{$role}->{'font'};
2035: $is_custom{'font'} = 1;
2036: }
1.97 tempelho 2037: if ($settings->{$role}->{'fontmenu'} ne '') {
2038: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
2039: $is_custom{'fontmenu'} = 1;
2040: }
1.6 raeburn 2041: foreach my $item (@bgs) {
2042: if ($settings->{$role}->{$item} ne '') {
2043: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
2044: $is_custom{$item} = 1;
2045: }
2046: }
2047: foreach my $item (@links) {
2048: if ($settings->{$role}->{$item} ne '') {
2049: $designs{'links'}{$item} = $settings->{$role}->{$item};
2050: $is_custom{$item} = 1;
2051: }
2052: }
2053: }
2054: } else {
1.97 tempelho 2055: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
2056: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
2057: $is_custom{'fontmenu'} = 1;
2058: }
1.6 raeburn 2059: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
2060: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
2061: $is_custom{'font'} = 1;
2062: }
2063: foreach my $item (@bgs) {
2064: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
2065: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
2066: $is_custom{$item} = 1;
2067:
2068: }
2069: }
2070: foreach my $item (@links) {
2071: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
2072: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
2073: $is_custom{$item} = 1;
2074: }
2075: }
2076: }
2077: my $itemcount = 1;
1.30 raeburn 2078: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 2079: $datatable .= '</tr></table></td></tr>';
2080: return $datatable;
2081: }
2082:
1.200 raeburn 2083: sub role_defaults {
2084: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 2085: my %defaults;
2086: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 2087: return %defaults;
2088: }
2089: my %defaultdesign = %Apache::loncommon::defaultdesign;
2090: if ($role eq 'login') {
2091: %defaults = (
2092: font => $defaultdesign{$role.'.font'},
2093: );
2094: if (ref($logintext) eq 'ARRAY') {
2095: foreach my $item (@{$logintext}) {
2096: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
2097: }
2098: }
2099: foreach my $item (@{$images}) {
2100: $defaults{'showlogo'}{$item} = 1;
2101: }
2102: } else {
2103: %defaults = (
2104: font => $defaultdesign{$role.'.font'},
2105: fontmenu => $defaultdesign{$role.'.fontmenu'},
2106: );
2107: }
2108: foreach my $item (@{$bgs}) {
2109: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
2110: }
2111: foreach my $item (@{$links}) {
2112: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
2113: }
2114: foreach my $item (@{$images}) {
2115: $defaults{$item} = $defaultdesign{$role.'.'.$item};
2116: }
2117: return %defaults;
2118: }
2119:
1.6 raeburn 2120: sub display_color_options {
1.9 raeburn 2121: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 2122: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 2123: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 2124: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 2125: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 2126: '<td>'.$choices->{'font'}.'</td>';
2127: if (!$is_custom->{'font'}) {
1.329 raeburn 2128: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 2129: } else {
2130: $datatable .= '<td> </td>';
2131: }
1.174 foxr 2132: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
2133:
1.8 raeburn 2134: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2135: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 2136: ' value="'.$current_color.'" /> '.
1.329 raeburn 2137: ' </span></td></tr>';
1.107 raeburn 2138: unless ($role eq 'login') {
2139: $datatable .= '<tr'.$css_class.'>'.
2140: '<td>'.$choices->{'fontmenu'}.'</td>';
2141: if (!$is_custom->{'fontmenu'}) {
1.329 raeburn 2142: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 2143: } else {
2144: $datatable .= '<td> </td>';
2145: }
1.202 raeburn 2146: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 2147: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 2148: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2149: '<input class="colorchooser" type="text" size="10" name="'
2150: .$role.'_fontmenu"'.
2151: ' value="'.$current_color.'" /> '.
1.329 raeburn 2152: ' </span></td></tr>';
1.97 tempelho 2153: }
1.9 raeburn 2154: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 2155: foreach my $img (@{$images}) {
1.18 albertel 2156: $itemcount ++;
1.6 raeburn 2157: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 2158: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 2159: '<td>'.$choices->{$img};
1.402 raeburn 2160: my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext);
1.70 raeburn 2161: if ($role eq 'login') {
2162: if ($img eq 'login') {
2163: $login_hdr_pick =
1.135 bisitz 2164: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 2165: $logincolors =
2166: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 2167: $designs,$defaults);
1.402 raeburn 2168: } else {
2169: if ($img ne 'domlogo') {
2170: $datatable.= &logo_display_options($img,$defaults,$designs);
2171: }
2172: if (ref($designs->{'alttext'}) eq 'HASH') {
2173: $alttext = $designs->{'alttext'}{$img};
2174: }
1.70 raeburn 2175: }
2176: }
2177: $datatable .= '</td>';
1.6 raeburn 2178: if ($designs->{$img} ne '') {
2179: $imgfile = $designs->{$img};
1.18 albertel 2180: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 2181: } else {
2182: $imgfile = $defaults->{$img};
2183: }
2184: if ($imgfile) {
1.9 raeburn 2185: my ($showfile,$fullsize);
2186: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 2187: my $urldir = $1;
2188: my $filename = $2;
2189: my @info = &Apache::lonnet::stat_file($designs->{$img});
2190: if (@info) {
2191: my $thumbfile = 'tn-'.$filename;
2192: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
2193: if (@thumb) {
2194: $showfile = $urldir.'/'.$thumbfile;
2195: } else {
2196: $showfile = $imgfile;
2197: }
2198: } else {
2199: $showfile = '';
2200: }
2201: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 2202: $showfile = $imgfile;
1.6 raeburn 2203: my $imgdir = $1;
2204: my $filename = $2;
1.159 raeburn 2205: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 2206: $showfile = "/$imgdir/tn-".$filename;
2207: } else {
1.159 raeburn 2208: my $input = $londocroot.$imgfile;
2209: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 2210: if (!-e $output) {
1.9 raeburn 2211: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 2212: my ($fullwidth,$fullheight) = &check_dimensions($input);
2213: if ($fullwidth ne '' && $fullheight ne '') {
2214: if ($fullwidth > $width && $fullheight > $height) {
2215: my $size = $width.'x'.$height;
1.316 raeburn 2216: my @args = ('convert','-sample',$size,$input,$output);
2217: system({$args[0]} @args);
1.159 raeburn 2218: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 2219: }
2220: }
1.6 raeburn 2221: }
2222: }
1.16 raeburn 2223: }
1.6 raeburn 2224: if ($showfile) {
1.40 raeburn 2225: if ($showfile =~ m{^/(adm|res)/}) {
2226: if ($showfile =~ m{^/res/}) {
2227: my $local_showfile =
2228: &Apache::lonnet::filelocation('',$showfile);
2229: &Apache::lonnet::repcopy($local_showfile);
2230: }
2231: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
2232: }
2233: if ($imgfile) {
2234: if ($imgfile =~ m{^/(adm|res)/}) {
2235: if ($imgfile =~ m{^/res/}) {
2236: my $local_imgfile =
2237: &Apache::lonnet::filelocation('',$imgfile);
2238: &Apache::lonnet::repcopy($local_imgfile);
2239: }
2240: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
2241: } else {
2242: $fullsize = $imgfile;
2243: }
2244: }
1.41 raeburn 2245: $datatable .= '<td>';
2246: if ($img eq 'login') {
1.135 bisitz 2247: $datatable .= $login_hdr_pick;
2248: }
1.41 raeburn 2249: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
2250: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 2251: } else {
1.201 raeburn 2252: $datatable .= '<td> </td><td class="LC_left_item">'.
2253: &mt('Upload:').'<br />';
1.6 raeburn 2254: }
2255: } else {
1.201 raeburn 2256: $datatable .= '<td> </td><td class="LC_left_item">'.
2257: &mt('Upload:').'<br />';
1.6 raeburn 2258: }
1.9 raeburn 2259: if ($switchserver) {
2260: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2261: } else {
1.135 bisitz 2262: if ($img ne 'login') { # suppress file selection for Log-in header
2263: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
2264: }
1.9 raeburn 2265: }
1.402 raeburn 2266: if (($role eq 'login') && ($img ne 'login')) {
2267: $datatable .= (' ' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'.
2268: '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'.
2269: '</label></span>';
2270: }
1.9 raeburn 2271: $datatable .= '</td></tr>';
1.6 raeburn 2272: }
2273: $itemcount ++;
2274: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2275: $datatable .= '<tr'.$css_class.'>'.
2276: '<td>'.$choices->{'bgs'}.'</td>';
2277: my $bgs_def;
2278: foreach my $item (@{$bgs}) {
2279: if (!$is_custom->{$item}) {
1.329 raeburn 2280: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span class="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 2281: }
2282: }
2283: if ($bgs_def) {
1.8 raeburn 2284: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 2285: } else {
2286: $datatable .= '<td> </td>';
2287: }
2288: $datatable .= '<td class="LC_right_item">'.
2289: '<table border="0"><tr>';
1.174 foxr 2290:
1.6 raeburn 2291: foreach my $item (@{$bgs}) {
1.306 raeburn 2292: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 2293: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 2294: if ($designs->{'bgs'}{$item}) {
1.174 foxr 2295: $datatable .= ' ';
1.6 raeburn 2296: }
1.174 foxr 2297: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 2298: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 2299: }
2300: $datatable .= '</tr></table></td></tr>';
2301: $itemcount ++;
2302: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2303: $datatable .= '<tr'.$css_class.'>'.
2304: '<td>'.$choices->{'links'}.'</td>';
2305: my $links_def;
2306: foreach my $item (@{$links}) {
2307: if (!$is_custom->{$item}) {
1.329 raeburn 2308: $links_def .= '<td>'.$choices->{$item}.'<br /><span class="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 2309: }
2310: }
2311: if ($links_def) {
1.8 raeburn 2312: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 2313: } else {
2314: $datatable .= '<td> </td>';
2315: }
2316: $datatable .= '<td class="LC_right_item">'.
2317: '<table border="0"><tr>';
2318: foreach my $item (@{$links}) {
1.234 raeburn 2319: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 2320: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 2321: if ($designs->{'links'}{$item}) {
1.174 foxr 2322: $datatable.=' ';
1.6 raeburn 2323: }
1.174 foxr 2324: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 2325: '" /></td>';
2326: }
1.30 raeburn 2327: $$rowtotal += $itemcount;
1.3 raeburn 2328: return $datatable;
2329: }
2330:
1.70 raeburn 2331: sub logo_display_options {
2332: my ($img,$defaults,$designs) = @_;
2333: my $checkedon;
2334: if (ref($defaults) eq 'HASH') {
2335: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2336: if ($defaults->{'showlogo'}{$img}) {
2337: $checkedon = 'checked="checked" ';
2338: }
2339: }
2340: }
2341: if (ref($designs) eq 'HASH') {
2342: if (ref($designs->{'showlogo'}) eq 'HASH') {
2343: if (defined($designs->{'showlogo'}{$img})) {
2344: if ($designs->{'showlogo'}{$img} == 0) {
2345: $checkedon = '';
2346: } elsif ($designs->{'showlogo'}{$img} == 1) {
2347: $checkedon = 'checked="checked" ';
2348: }
2349: }
2350: }
2351: }
2352: return '<br /><label> <input type="checkbox" name="'.
2353: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2354: &mt('show').'</label>'."\n";
2355: }
2356:
1.41 raeburn 2357: sub login_header_options {
1.135 bisitz 2358: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2359: my $output = '';
1.41 raeburn 2360: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 2361: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 2362: if (!$is_custom->{'textcol'}) {
2363: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2364: ' ';
2365: }
2366: if (!$is_custom->{'bgcol'}) {
2367: $output .= $choices->{'bgcol'}.': '.
2368: '<span id="css_'.$role.'_font" style="background-color: '.
2369: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2370: }
2371: $output .= '<br />';
2372: }
2373: $output .='<br />';
2374: return $output;
2375: }
2376:
2377: sub login_text_colors {
1.201 raeburn 2378: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 2379: my $color_menu = '<table border="0"><tr>';
2380: foreach my $item (@{$logintext}) {
1.306 raeburn 2381: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 2382: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2383: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2384: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 2385: }
2386: $color_menu .= '</tr></table><br />';
2387: return $color_menu;
2388: }
2389:
2390: sub image_changes {
2391: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2392: my $output;
1.135 bisitz 2393: if ($img eq 'login') {
1.331 raeburn 2394: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 2395: } elsif (!$is_custom) {
1.70 raeburn 2396: if ($img ne 'domlogo') {
1.331 raeburn 2397: $output = &mt('Default image:').'<br />';
1.41 raeburn 2398: } else {
1.331 raeburn 2399: $output = &mt('Default in use:').'<br />';
1.41 raeburn 2400: }
2401: }
1.331 raeburn 2402: if ($img ne 'login') {
1.135 bisitz 2403: if ($img_import) {
2404: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2405: }
2406: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2407: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2408: if ($is_custom) {
2409: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2410: '<input type="checkbox" name="'.
2411: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2412: '</label> '.&mt('Replace:').'</span><br />';
2413: } else {
1.306 raeburn 2414: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 2415: }
1.41 raeburn 2416: }
2417: return $output;
2418: }
2419:
1.3 raeburn 2420: sub print_quotas {
1.86 raeburn 2421: my ($dom,$settings,$rowtotal,$action) = @_;
2422: my $context;
2423: if ($action eq 'quotas') {
2424: $context = 'tools';
2425: } else {
2426: $context = $action;
2427: }
1.429 raeburn 2428: my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44 raeburn 2429: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2430: my $typecount = 0;
1.101 raeburn 2431: my ($css_class,%titles);
1.86 raeburn 2432: if ($context eq 'requestcourses') {
1.325 raeburn 2433: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 2434: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2435: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2436: %titles = &courserequest_titles();
1.163 raeburn 2437: } elsif ($context eq 'requestauthor') {
2438: @usertools = ('author');
2439: @options = ('norequest','approval','automatic');
1.210 raeburn 2440: %titles = &authorrequest_titles();
1.86 raeburn 2441: } else {
1.430 raeburn 2442: @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.101 raeburn 2443: %titles = &tool_titles();
1.86 raeburn 2444: }
1.26 raeburn 2445: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2446: foreach my $type (@{$types}) {
1.429 raeburn 2447: my $currdefquota;
1.163 raeburn 2448: unless (($context eq 'requestcourses') ||
2449: ($context eq 'requestauthor')) {
1.86 raeburn 2450: if (ref($settings) eq 'HASH') {
2451: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 2452: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2453: } else {
2454: $currdefquota = $settings->{$type};
2455: }
1.78 raeburn 2456: }
1.72 raeburn 2457: }
1.3 raeburn 2458: if (defined($usertypes->{$type})) {
2459: $typecount ++;
2460: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2461: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2462: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2463: '<td class="LC_left_item">';
1.101 raeburn 2464: if ($context eq 'requestcourses') {
2465: $datatable .= '<table><tr>';
2466: }
2467: my %cell;
1.72 raeburn 2468: foreach my $item (@usertools) {
1.101 raeburn 2469: if ($context eq 'requestcourses') {
2470: my ($curroption,$currlimit);
2471: if (ref($settings) eq 'HASH') {
2472: if (ref($settings->{$item}) eq 'HASH') {
2473: $curroption = $settings->{$item}->{$type};
2474: if ($curroption =~ /^autolimit=(\d*)$/) {
2475: $currlimit = $1;
2476: }
2477: }
2478: }
2479: if (!$curroption) {
2480: $curroption = 'norequest';
2481: }
2482: $datatable .= '<th>'.$titles{$item}.'</th>';
2483: foreach my $option (@options) {
2484: my $val = $option;
2485: if ($option eq 'norequest') {
2486: $val = 0;
2487: }
2488: if ($option eq 'validate') {
2489: my $canvalidate = 0;
2490: if (ref($validations{$item}) eq 'HASH') {
2491: if ($validations{$item}{$type}) {
2492: $canvalidate = 1;
2493: }
2494: }
2495: next if (!$canvalidate);
2496: }
2497: my $checked = '';
2498: if ($option eq $curroption) {
2499: $checked = ' checked="checked"';
2500: } elsif ($option eq 'autolimit') {
2501: if ($curroption =~ /^autolimit/) {
2502: $checked = ' checked="checked"';
2503: }
2504: }
2505: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2506: '<input type="radio" name="crsreq_'.$item.
2507: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2508: $titles{$option}.'</label>';
1.101 raeburn 2509: if ($option eq 'autolimit') {
1.127 raeburn 2510: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2511: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2512: 'value="'.$currlimit.'" />';
1.101 raeburn 2513: }
1.127 raeburn 2514: $cell{$item} .= '</span> ';
1.103 raeburn 2515: if ($option eq 'autolimit') {
1.127 raeburn 2516: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2517: }
1.101 raeburn 2518: }
1.163 raeburn 2519: } elsif ($context eq 'requestauthor') {
2520: my $curroption;
2521: if (ref($settings) eq 'HASH') {
2522: $curroption = $settings->{$type};
2523: }
2524: if (!$curroption) {
2525: $curroption = 'norequest';
2526: }
2527: foreach my $option (@options) {
2528: my $val = $option;
2529: if ($option eq 'norequest') {
2530: $val = 0;
2531: }
2532: my $checked = '';
2533: if ($option eq $curroption) {
2534: $checked = ' checked="checked"';
2535: }
2536: $datatable .= '<span class="LC_nobreak"><label>'.
2537: '<input type="radio" name="authorreq_'.$type.
2538: '" value="'.$val.'"'.$checked.' />'.
2539: $titles{$option}.'</label></span> ';
2540: }
1.101 raeburn 2541: } else {
2542: my $checked = 'checked="checked" ';
1.413 raeburn 2543: if ($item eq 'timezone') {
2544: $checked = '';
2545: }
1.101 raeburn 2546: if (ref($settings) eq 'HASH') {
2547: if (ref($settings->{$item}) eq 'HASH') {
1.413 raeburn 2548: if (!$settings->{$item}->{$type}) {
1.101 raeburn 2549: $checked = '';
2550: } elsif ($settings->{$item}->{$type} == 1) {
2551: $checked = 'checked="checked" ';
2552: }
1.78 raeburn 2553: }
1.72 raeburn 2554: }
1.101 raeburn 2555: $datatable .= '<span class="LC_nobreak"><label>'.
2556: '<input type="checkbox" name="'.$context.'_'.$item.
2557: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2558: '</label></span> ';
1.72 raeburn 2559: }
1.101 raeburn 2560: }
2561: if ($context eq 'requestcourses') {
2562: $datatable .= '</tr><tr>';
2563: foreach my $item (@usertools) {
1.106 raeburn 2564: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2565: }
2566: $datatable .= '</tr></table>';
1.72 raeburn 2567: }
1.86 raeburn 2568: $datatable .= '</td>';
1.163 raeburn 2569: unless (($context eq 'requestcourses') ||
2570: ($context eq 'requestauthor')) {
1.86 raeburn 2571: $datatable .=
1.197 raeburn 2572: '<td class="LC_right_item">'.
1.429 raeburn 2573: '<span class="LC_nobreak">'.
1.3 raeburn 2574: '<input type="text" name="quota_'.$type.
1.72 raeburn 2575: '" value="'.$currdefquota.
1.197 raeburn 2576: '" size="5" /></span></td>';
1.86 raeburn 2577: }
2578: $datatable .= '</tr>';
1.3 raeburn 2579: }
2580: }
2581: }
1.163 raeburn 2582: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2583: $defaultquota = '20';
2584: if (ref($settings) eq 'HASH') {
2585: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2586: $defaultquota = $settings->{'defaultquota'}->{'default'};
2587: } elsif (defined($settings->{'default'})) {
2588: $defaultquota = $settings->{'default'};
2589: }
1.3 raeburn 2590: }
2591: }
2592: $typecount ++;
2593: $css_class = $typecount%2?' class="LC_odd_row"':'';
2594: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2595: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2596: '<td class="LC_left_item">';
1.101 raeburn 2597: if ($context eq 'requestcourses') {
2598: $datatable .= '<table><tr>';
2599: }
2600: my %defcell;
1.72 raeburn 2601: foreach my $item (@usertools) {
1.101 raeburn 2602: if ($context eq 'requestcourses') {
2603: my ($curroption,$currlimit);
2604: if (ref($settings) eq 'HASH') {
2605: if (ref($settings->{$item}) eq 'HASH') {
2606: $curroption = $settings->{$item}->{'default'};
2607: if ($curroption =~ /^autolimit=(\d*)$/) {
2608: $currlimit = $1;
2609: }
2610: }
2611: }
2612: if (!$curroption) {
2613: $curroption = 'norequest';
2614: }
2615: $datatable .= '<th>'.$titles{$item}.'</th>';
2616: foreach my $option (@options) {
2617: my $val = $option;
2618: if ($option eq 'norequest') {
2619: $val = 0;
2620: }
2621: if ($option eq 'validate') {
2622: my $canvalidate = 0;
2623: if (ref($validations{$item}) eq 'HASH') {
2624: if ($validations{$item}{'default'}) {
2625: $canvalidate = 1;
2626: }
2627: }
2628: next if (!$canvalidate);
2629: }
2630: my $checked = '';
2631: if ($option eq $curroption) {
2632: $checked = ' checked="checked"';
2633: } elsif ($option eq 'autolimit') {
2634: if ($curroption =~ /^autolimit/) {
2635: $checked = ' checked="checked"';
2636: }
2637: }
2638: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2639: '<input type="radio" name="crsreq_'.$item.
2640: '_default" value="'.$val.'"'.$checked.' />'.
2641: $titles{$option}.'</label>';
2642: if ($option eq 'autolimit') {
1.127 raeburn 2643: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2644: $item.'_limit_default" size="1" '.
2645: 'value="'.$currlimit.'" />';
2646: }
1.127 raeburn 2647: $defcell{$item} .= '</span> ';
1.104 raeburn 2648: if ($option eq 'autolimit') {
1.127 raeburn 2649: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2650: }
1.101 raeburn 2651: }
1.163 raeburn 2652: } elsif ($context eq 'requestauthor') {
2653: my $curroption;
2654: if (ref($settings) eq 'HASH') {
1.172 raeburn 2655: $curroption = $settings->{'default'};
1.163 raeburn 2656: }
2657: if (!$curroption) {
2658: $curroption = 'norequest';
2659: }
2660: foreach my $option (@options) {
2661: my $val = $option;
2662: if ($option eq 'norequest') {
2663: $val = 0;
2664: }
2665: my $checked = '';
2666: if ($option eq $curroption) {
2667: $checked = ' checked="checked"';
2668: }
2669: $datatable .= '<span class="LC_nobreak"><label>'.
2670: '<input type="radio" name="authorreq_default"'.
2671: ' value="'.$val.'"'.$checked.' />'.
2672: $titles{$option}.'</label></span> ';
2673: }
1.101 raeburn 2674: } else {
2675: my $checked = 'checked="checked" ';
2676: if (ref($settings) eq 'HASH') {
2677: if (ref($settings->{$item}) eq 'HASH') {
2678: if ($settings->{$item}->{'default'} == 0) {
2679: $checked = '';
2680: } elsif ($settings->{$item}->{'default'} == 1) {
2681: $checked = 'checked="checked" ';
2682: }
1.78 raeburn 2683: }
1.72 raeburn 2684: }
1.101 raeburn 2685: $datatable .= '<span class="LC_nobreak"><label>'.
2686: '<input type="checkbox" name="'.$context.'_'.$item.
2687: '" value="default" '.$checked.'/>'.$titles{$item}.
2688: '</label></span> ';
2689: }
2690: }
2691: if ($context eq 'requestcourses') {
2692: $datatable .= '</tr><tr>';
2693: foreach my $item (@usertools) {
1.106 raeburn 2694: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2695: }
1.101 raeburn 2696: $datatable .= '</tr></table>';
1.72 raeburn 2697: }
1.86 raeburn 2698: $datatable .= '</td>';
1.163 raeburn 2699: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2700: $datatable .= '<td class="LC_right_item">'.
1.429 raeburn 2701: '<span class="LC_nobreak">'.
1.86 raeburn 2702: '<input type="text" name="defaultquota" value="'.
1.429 raeburn 2703: $defaultquota.'" size="5" /></span></td>';
1.86 raeburn 2704: }
2705: $datatable .= '</tr>';
1.72 raeburn 2706: $typecount ++;
2707: $css_class = $typecount%2?' class="LC_odd_row"':'';
2708: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2709: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2710: if ($context eq 'requestcourses') {
1.109 raeburn 2711: $datatable .= &mt('(overrides affiliation, if set)').
2712: '</td>'.
2713: '<td class="LC_left_item">'.
2714: '<table><tr>';
1.101 raeburn 2715: } else {
1.109 raeburn 2716: $datatable .= &mt('(overrides affiliation, if checked)').
2717: '</td>'.
2718: '<td class="LC_left_item" colspan="2">'.
2719: '<br />';
1.101 raeburn 2720: }
2721: my %advcell;
1.72 raeburn 2722: foreach my $item (@usertools) {
1.101 raeburn 2723: if ($context eq 'requestcourses') {
2724: my ($curroption,$currlimit);
2725: if (ref($settings) eq 'HASH') {
2726: if (ref($settings->{$item}) eq 'HASH') {
2727: $curroption = $settings->{$item}->{'_LC_adv'};
2728: if ($curroption =~ /^autolimit=(\d*)$/) {
2729: $currlimit = $1;
2730: }
2731: }
2732: }
2733: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2734: my $checked = '';
2735: if ($curroption eq '') {
2736: $checked = ' checked="checked"';
2737: }
2738: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2739: '<input type="radio" name="crsreq_'.$item.
2740: '__LC_adv" value=""'.$checked.' />'.
2741: &mt('No override set').'</label></span> ';
1.101 raeburn 2742: foreach my $option (@options) {
2743: my $val = $option;
2744: if ($option eq 'norequest') {
2745: $val = 0;
2746: }
2747: if ($option eq 'validate') {
2748: my $canvalidate = 0;
2749: if (ref($validations{$item}) eq 'HASH') {
2750: if ($validations{$item}{'_LC_adv'}) {
2751: $canvalidate = 1;
2752: }
2753: }
2754: next if (!$canvalidate);
2755: }
2756: my $checked = '';
1.104 raeburn 2757: if ($val eq $curroption) {
1.101 raeburn 2758: $checked = ' checked="checked"';
2759: } elsif ($option eq 'autolimit') {
2760: if ($curroption =~ /^autolimit/) {
2761: $checked = ' checked="checked"';
2762: }
2763: }
2764: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2765: '<input type="radio" name="crsreq_'.$item.
2766: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2767: $titles{$option}.'</label>';
2768: if ($option eq 'autolimit') {
1.127 raeburn 2769: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2770: $item.'_limit__LC_adv" size="1" '.
2771: 'value="'.$currlimit.'" />';
2772: }
1.127 raeburn 2773: $advcell{$item} .= '</span> ';
1.104 raeburn 2774: if ($option eq 'autolimit') {
1.127 raeburn 2775: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2776: }
1.101 raeburn 2777: }
1.163 raeburn 2778: } elsif ($context eq 'requestauthor') {
2779: my $curroption;
2780: if (ref($settings) eq 'HASH') {
2781: $curroption = $settings->{'_LC_adv'};
2782: }
2783: my $checked = '';
2784: if ($curroption eq '') {
2785: $checked = ' checked="checked"';
2786: }
2787: $datatable .= '<span class="LC_nobreak"><label>'.
2788: '<input type="radio" name="authorreq__LC_adv"'.
2789: ' value=""'.$checked.' />'.
2790: &mt('No override set').'</label></span> ';
2791: foreach my $option (@options) {
2792: my $val = $option;
2793: if ($option eq 'norequest') {
2794: $val = 0;
2795: }
2796: my $checked = '';
2797: if ($val eq $curroption) {
2798: $checked = ' checked="checked"';
2799: }
2800: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2801: '<input type="radio" name="authorreq__LC_adv"'.
2802: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2803: $titles{$option}.'</label></span> ';
2804: }
1.101 raeburn 2805: } else {
2806: my $checked = 'checked="checked" ';
2807: if (ref($settings) eq 'HASH') {
2808: if (ref($settings->{$item}) eq 'HASH') {
2809: if ($settings->{$item}->{'_LC_adv'} == 0) {
2810: $checked = '';
2811: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2812: $checked = 'checked="checked" ';
2813: }
1.79 raeburn 2814: }
1.72 raeburn 2815: }
1.101 raeburn 2816: $datatable .= '<span class="LC_nobreak"><label>'.
2817: '<input type="checkbox" name="'.$context.'_'.$item.
2818: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2819: '</label></span> ';
2820: }
2821: }
2822: if ($context eq 'requestcourses') {
2823: $datatable .= '</tr><tr>';
2824: foreach my $item (@usertools) {
1.106 raeburn 2825: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2826: }
1.101 raeburn 2827: $datatable .= '</tr></table>';
1.72 raeburn 2828: }
1.98 raeburn 2829: $datatable .= '</td></tr>';
1.30 raeburn 2830: $$rowtotal += $typecount;
1.3 raeburn 2831: return $datatable;
2832: }
2833:
1.163 raeburn 2834: sub print_requestmail {
1.305 raeburn 2835: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2836: my ($now,$datatable,%currapp);
1.102 raeburn 2837: $now = time;
2838: if (ref($settings) eq 'HASH') {
2839: if (ref($settings->{'notify'}) eq 'HASH') {
2840: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2841: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2842: }
2843: }
2844: }
1.191 raeburn 2845: my $numinrow = 2;
1.224 raeburn 2846: my $css_class;
1.305 raeburn 2847: if ($$rowtotal%2) {
2848: $css_class = 'LC_odd_row';
2849: }
2850: if ($customcss) {
2851: $css_class .= " $customcss";
2852: }
2853: $css_class =~ s/^\s+//;
2854: if ($css_class) {
2855: $css_class = ' class="'.$css_class.'"';
2856: }
2857: if ($rowstyle) {
2858: $css_class .= ' style="'.$rowstyle.'"';
2859: }
1.163 raeburn 2860: my $text;
2861: if ($action eq 'requestcourses') {
2862: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2863: } elsif ($action eq 'requestauthor') {
2864: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2865: } else {
1.224 raeburn 2866: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2867: }
1.224 raeburn 2868: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2869: ' <td>'.$text.'</td>'.
1.102 raeburn 2870: ' <td class="LC_left_item">';
1.191 raeburn 2871: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2872: $action.'notifyapproval',%currapp);
1.191 raeburn 2873: if ($numdc > 0) {
2874: $datatable .= $table;
1.102 raeburn 2875: } else {
2876: $datatable .= &mt('There are no active Domain Coordinators');
2877: }
2878: $datatable .='</td></tr>';
2879: return $datatable;
2880: }
2881:
1.216 raeburn 2882: sub print_studentcode {
2883: my ($settings,$rowtotal) = @_;
2884: my $rownum = 0;
1.218 raeburn 2885: my ($output,%current);
1.325 raeburn 2886: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248 raeburn 2887: if (ref($settings) eq 'HASH') {
2888: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2889: foreach my $type (@crstypes) {
2890: $current{$type} = $settings->{'uniquecode'}{$type};
2891: }
1.218 raeburn 2892: }
2893: }
2894: $output .= '<tr>'.
2895: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2896: '<td class="LC_left_item">';
2897: foreach my $type (@crstypes) {
2898: my $check = ' ';
2899: if ($current{$type}) {
2900: $check = ' checked="checked" ';
2901: }
2902: $output .= '<span class="LC_nobreak"><label>'.
2903: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2904: &mt($type).'</label></span>'.(' 'x2).' ';
2905: }
2906: $output .= '</td></tr>';
2907: $$rowtotal ++;
2908: return $output;
1.216 raeburn 2909: }
2910:
2911: sub print_textbookcourses {
1.242 raeburn 2912: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2913: my $rownum = 0;
2914: my $css_class;
2915: my $itemcount = 1;
2916: my $maxnum = 0;
2917: my $bookshash;
2918: if (ref($settings) eq 'HASH') {
1.242 raeburn 2919: $bookshash = $settings->{$type};
1.216 raeburn 2920: }
2921: my %ordered;
2922: if (ref($bookshash) eq 'HASH') {
2923: foreach my $item (keys(%{$bookshash})) {
2924: if (ref($bookshash->{$item}) eq 'HASH') {
2925: my $num = $bookshash->{$item}{'order'};
2926: $ordered{$num} = $item;
2927: }
2928: }
2929: }
2930: my $confname = $dom.'-domainconfig';
2931: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2932: my $maxnum = scalar(keys(%ordered));
2933: my $datatable;
1.216 raeburn 2934: if (keys(%ordered)) {
2935: my @items = sort { $a <=> $b } keys(%ordered);
2936: for (my $i=0; $i<@items; $i++) {
2937: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2938: my $key = $ordered{$items[$i]};
2939: my %coursehash=&Apache::lonnet::coursedescription($key);
2940: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2941: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2942: if (ref($bookshash->{$key}) eq 'HASH') {
2943: $subject = $bookshash->{$key}->{'subject'};
2944: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2945: if ($type eq 'textbooks') {
1.243 raeburn 2946: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2947: $author = $bookshash->{$key}->{'author'};
2948: $image = $bookshash->{$key}->{'image'};
2949: if ($image ne '') {
2950: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2951: my $imagethumb = "$path/tn-".$imagefile;
2952: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2953: }
1.216 raeburn 2954: }
2955: }
1.242 raeburn 2956: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2957: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2958: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2959: for (my $k=0; $k<=$maxnum; $k++) {
2960: my $vpos = $k+1;
2961: my $selstr;
2962: if ($k == $i) {
2963: $selstr = ' selected="selected" ';
2964: }
2965: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2966: }
2967: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2968: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2969: &mt('Delete?').'</label></span></td>'.
2970: '<td colspan="2">'.
1.242 raeburn 2971: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2972: (' 'x2).
1.242 raeburn 2973: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2974: if ($type eq 'textbooks') {
2975: $datatable .= (' 'x2).
1.243 raeburn 2976: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2977: (' 'x2).
1.242 raeburn 2978: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2979: (' 'x2).
2980: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2981: if ($image) {
1.267 raeburn 2982: $datatable .= $imgsrc.
1.242 raeburn 2983: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2984: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2985: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2986: }
2987: if ($switchserver) {
2988: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2989: } else {
2990: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2991: }
1.216 raeburn 2992: }
1.242 raeburn 2993: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2994: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2995: $coursetitle.'</span></td></tr>'."\n";
2996: $itemcount ++;
2997: }
2998: }
2999: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 3000: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 3001: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 3002: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
3003: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 3004: for (my $k=0; $k<$maxnum+1; $k++) {
3005: my $vpos = $k+1;
3006: my $selstr;
3007: if ($k == $maxnum) {
3008: $selstr = ' selected="selected" ';
3009: }
3010: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3011: }
3012: $datatable .= '</select> '."\n".
1.334 raeburn 3013: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216 raeburn 3014: '<td colspan="2">'.
1.242 raeburn 3015: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 3016: (' 'x2).
1.242 raeburn 3017: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
3018: (' 'x2);
3019: if ($type eq 'textbooks') {
1.243 raeburn 3020: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
3021: (' 'x2).
3022: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 3023: (' 'x2).
3024: '<span class="LC_nobreak">'.&mt('Image:').' ';
3025: if ($switchserver) {
3026: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3027: } else {
3028: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
3029: }
1.334 raeburn 3030: $datatable .= '</span>'."\n";
1.216 raeburn 3031: }
1.334 raeburn 3032: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 3033: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
3034: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 3035: &Apache::loncommon::selectcourse_link
1.334 raeburn 3036: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216 raeburn 3037: '</span></td>'."\n".
3038: '</tr>'."\n";
3039: $itemcount ++;
3040: return $datatable;
3041: }
3042:
1.217 raeburn 3043: sub textbookcourses_javascript {
1.242 raeburn 3044: my ($settings) = @_;
3045: return unless(ref($settings) eq 'HASH');
3046: my (%ordered,%total,%jstext);
3047: foreach my $type ('textbooks','templates') {
3048: $total{$type} = 0;
3049: if (ref($settings->{$type}) eq 'HASH') {
3050: foreach my $item (keys(%{$settings->{$type}})) {
3051: if (ref($settings->{$type}->{$item}) eq 'HASH') {
3052: my $num = $settings->{$type}->{$item}{'order'};
3053: $ordered{$type}{$num} = $item;
3054: }
3055: }
3056: $total{$type} = scalar(keys(%{$settings->{$type}}));
3057: }
3058: my @jsarray = ();
3059: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
3060: push(@jsarray,$ordered{$type}{$item});
3061: }
3062: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 3063: }
3064: return <<"ENDSCRIPT";
3065: <script type="text/javascript">
3066: // <![CDATA[
1.242 raeburn 3067: function reorderBooks(form,item,caller) {
1.217 raeburn 3068: var changedVal;
1.242 raeburn 3069: $jstext{'textbooks'};
3070: $jstext{'templates'};
3071: var newpos;
3072: var maxh;
3073: if (caller == 'textbooks') {
3074: newpos = 'textbooks_addbook_pos';
3075: maxh = 1 + $total{'textbooks'};
3076: } else {
3077: newpos = 'templates_addbook_pos';
3078: maxh = 1 + $total{'templates'};
3079: }
1.217 raeburn 3080: var current = new Array;
3081: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3082: if (item == newpos) {
3083: changedVal = newitemVal;
3084: } else {
3085: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3086: current[newitemVal] = newpos;
3087: }
1.242 raeburn 3088: if (caller == 'textbooks') {
3089: for (var i=0; i<textbooks.length; i++) {
3090: var elementName = 'textbooks_'+textbooks[i];
3091: if (elementName != item) {
3092: if (form.elements[elementName]) {
3093: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3094: current[currVal] = elementName;
3095: }
3096: }
3097: }
3098: }
3099: if (caller == 'templates') {
3100: for (var i=0; i<templates.length; i++) {
3101: var elementName = 'templates_'+templates[i];
3102: if (elementName != item) {
3103: if (form.elements[elementName]) {
3104: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3105: current[currVal] = elementName;
3106: }
1.217 raeburn 3107: }
3108: }
3109: }
3110: var oldVal;
3111: for (var j=0; j<maxh; j++) {
3112: if (current[j] == undefined) {
3113: oldVal = j;
3114: }
3115: }
3116: if (oldVal < changedVal) {
3117: for (var k=oldVal+1; k<=changedVal ; k++) {
3118: var elementName = current[k];
3119: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3120: }
3121: } else {
3122: for (var k=changedVal; k<oldVal; k++) {
3123: var elementName = current[k];
3124: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3125: }
3126: }
3127: return;
3128: }
3129:
3130: // ]]>
3131: </script>
3132:
3133: ENDSCRIPT
3134: }
3135:
1.267 raeburn 3136: sub ltitools_javascript {
3137: my ($settings) = @_;
1.319 raeburn 3138: my $togglejs = <itools_toggle_js();
3139: unless (ref($settings) eq 'HASH') {
3140: return $togglejs;
3141: }
1.267 raeburn 3142: my (%ordered,$total,%jstext);
3143: $total = 0;
3144: foreach my $item (keys(%{$settings})) {
3145: if (ref($settings->{$item}) eq 'HASH') {
3146: my $num = $settings->{$item}{'order'};
3147: $ordered{$num} = $item;
3148: }
3149: }
3150: $total = scalar(keys(%{$settings}));
3151: my @jsarray = ();
3152: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3153: push(@jsarray,$ordered{$item});
3154: }
3155: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
3156: return <<"ENDSCRIPT";
3157: <script type="text/javascript">
3158: // <![CDATA[
1.319 raeburn 3159: function reorderLTITools(form,item) {
1.267 raeburn 3160: var changedVal;
3161: $jstext
3162: var newpos = 'ltitools_add_pos';
3163: var maxh = 1 + $total;
3164: var current = new Array;
3165: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3166: if (item == newpos) {
3167: changedVal = newitemVal;
3168: } else {
3169: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3170: current[newitemVal] = newpos;
3171: }
3172: for (var i=0; i<ltitools.length; i++) {
3173: var elementName = 'ltitools_'+ltitools[i];
3174: if (elementName != item) {
3175: if (form.elements[elementName]) {
3176: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3177: current[currVal] = elementName;
3178: }
3179: }
3180: }
3181: var oldVal;
3182: for (var j=0; j<maxh; j++) {
3183: if (current[j] == undefined) {
3184: oldVal = j;
3185: }
3186: }
3187: if (oldVal < changedVal) {
3188: for (var k=oldVal+1; k<=changedVal ; k++) {
3189: var elementName = current[k];
3190: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3191: }
3192: } else {
3193: for (var k=changedVal; k<oldVal; k++) {
3194: var elementName = current[k];
3195: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3196: }
3197: }
3198: return;
3199: }
3200:
3201: // ]]>
3202: </script>
3203:
1.319 raeburn 3204: $togglejs
3205:
3206: ENDSCRIPT
3207: }
3208:
3209: sub ltitools_toggle_js {
3210: return <<"ENDSCRIPT";
3211: <script type="text/javascript">
3212: // <![CDATA[
3213:
3214: function toggleLTITools(form,setting,item) {
3215: var radioname = '';
3216: var divid = '';
3217: if ((setting == 'passback') || (setting == 'roster')) {
3218: radioname = 'ltitools_'+setting+'_'+item;
3219: divid = 'ltitools_'+setting+'time_'+item;
3220: var num = form.elements[radioname].length;
3221: if (num) {
3222: var setvis = '';
3223: for (var i=0; i<num; i++) {
3224: if (form.elements[radioname][i].checked) {
3225: if (form.elements[radioname][i].value == '1') {
3226: if (document.getElementById(divid)) {
3227: document.getElementById(divid).style.display = 'inline-block';
3228: }
3229: setvis = 1;
3230: }
3231: break;
3232: }
3233: }
3234: }
3235: if (!setvis) {
3236: if (document.getElementById(divid)) {
3237: document.getElementById(divid).style.display = 'none';
3238: }
3239: }
3240: }
1.324 raeburn 3241: if (setting == 'user') {
3242: divid = 'ltitools_'+setting+'_div_'+item;
3243: var checkid = 'ltitools_'+setting+'_field_'+item;
3244: if (document.getElementById(divid)) {
3245: if (document.getElementById(checkid)) {
3246: if (document.getElementById(checkid).checked) {
3247: document.getElementById(divid).style.display = 'inline-block';
3248: } else {
3249: document.getElementById(divid).style.display = 'none';
3250: }
3251: }
3252: }
3253: }
1.319 raeburn 3254: return;
3255: }
3256: // ]]>
3257: </script>
3258:
1.267 raeburn 3259: ENDSCRIPT
3260: }
3261:
1.381 raeburn 3262: sub wafproxy_javascript {
3263: my ($dom) = @_;
3264: return <<"ENDSCRIPT";
3265: <script type="text/javascript">
3266: // <![CDATA[
3267: function updateWAF() {
3268: if (document.getElementById('wafproxy_remoteip')) {
3269: var wafremote = 0;
3270: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
3271: wafremote = 1;
3272: }
3273: var fields = new Array('header','trust');
3274: for (var i=0; i<fields.length; i++) {
3275: if (document.getElementById('wafproxy_'+fields[i])) {
3276: if (wafremote == 1) {
3277: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
3278: }
3279: else {
3280: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
3281: }
3282: }
3283: }
3284: if (document.getElementById('wafproxyranges_$dom')) {
3285: if (wafremote == 1) {
3286: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3287: } else {
3288: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3289: if (document.display.wafproxy_vpnaccess[i].checked) {
3290: if (document.display.wafproxy_vpnaccess[i].value == 0) {
3291: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3292: }
3293: }
3294: }
3295: }
3296: }
3297: }
3298: return;
3299: }
3300:
3301: function checkWAF() {
3302: if (document.getElementById('wafproxy_remoteip')) {
3303: var wafvpn = 0;
3304: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3305: if (document.display.wafproxy_vpnaccess[i].checked) {
3306: if (document.display.wafproxy_vpnaccess[i].value == 1) {
3307: wafvpn = 1;
3308: }
3309: break;
3310: }
3311: }
3312: var vpn = new Array('vpnint','vpnext');
3313: for (var i=0; i<vpn.length; i++) {
3314: if (document.getElementById('wafproxy_show_'+vpn[i])) {
3315: if (wafvpn == 1) {
3316: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
3317: }
3318: else {
3319: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
3320: }
3321: }
3322: }
3323: if (document.getElementById('wafproxyranges_$dom')) {
3324: if (wafvpn == 1) {
3325: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3326: }
3327: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
3328: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3329: }
3330: }
3331: }
3332: return;
3333: }
3334:
3335: function toggleWAF() {
3336: if (document.getElementById('wafproxy_table')) {
3337: var wafproxy = 0;
3338: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
3339: if (document.display.wafproxy_${dom}[i].checked) {
3340: if (document.display.wafproxy_${dom}[i].value == 1) {
3341: wafproxy = 1;
3342: break;
3343: }
3344: }
3345: }
3346: if (wafproxy == 1) {
3347: document.getElementById('wafproxy_table').style.display='inline';
3348: }
3349: else {
3350: document.getElementById('wafproxy_table').style.display='none';
3351: }
3352: if (document.getElementById('wafproxyrow_${dom}')) {
3353: if (wafproxy == 1) {
3354: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
3355: }
3356: else {
3357: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
3358: }
3359: }
3360: if (document.getElementById('nowafproxyrow_$dom')) {
3361: if (wafproxy == 1) {
3362: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
3363: }
3364: else {
3365: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
3366: }
3367: }
3368: }
3369: return;
3370: }
3371: // ]]>
3372: </script>
3373:
3374: ENDSCRIPT
3375: }
3376:
1.372 raeburn 3377: sub proctoring_javascript {
3378: my ($settings) = @_;
3379: my (%ordered,$total,%jstext);
3380: $total = 0;
3381: if (ref($settings) eq 'HASH') {
3382: foreach my $item (keys(%{$settings})) {
3383: if (ref($settings->{$item}) eq 'HASH') {
3384: my $num = $settings->{$item}{'order'};
3385: $ordered{$num} = $item;
3386: }
3387: }
3388: $total = scalar(keys(%{$settings}));
3389: } else {
3390: %ordered = (
3391: 0 => 'proctorio',
3392: 1 => 'examity',
3393: );
3394: $total = 2;
3395: }
3396: my @jsarray = ();
3397: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3398: push(@jsarray,$ordered{$item});
3399: }
3400: my $jstext = ' var proctors = Array('."'".join("','",@jsarray)."'".');'."\n";
3401: return <<"ENDSCRIPT";
3402: <script type="text/javascript">
3403: // <![CDATA[
3404: function reorderProctoring(form,item) {
3405: var changedVal;
3406: $jstext
3407: var maxh = $total;
3408: var current = new Array;
3409: var changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3410: for (var i=0; i<proctors.length; i++) {
3411: var elementName = 'proctoring_pos_'+proctors[i];
3412: if (elementName != item) {
3413: if (form.elements[elementName]) {
3414: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3415: current[currVal] = elementName;
3416: }
3417: }
3418: }
3419: var oldVal;
3420: for (var j=0; j<maxh; j++) {
3421: if (current[j] == undefined) {
3422: oldVal = j;
3423: }
3424: }
3425: if (oldVal < changedVal) {
3426: for (var k=oldVal+1; k<=changedVal ; k++) {
3427: var elementName = current[k];
3428: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3429: }
3430: } else {
3431: for (var k=changedVal; k<oldVal; k++) {
3432: var elementName = current[k];
3433: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3434: }
3435: }
3436: return;
3437: }
3438:
3439: function toggleProctoring(form,item) {
3440: var fieldsets = document.getElementsByClassName('proctoring_'+item);
3441: if (fieldsets.length) {
3442: var radioname = 'proctoring_available_'+item;
3443: var num = form.elements[radioname].length;
3444: if (num) {
3445: var setvis = '';
3446: for (var i=0; i<num; i++) {
3447: if (form.elements[radioname][i].checked) {
3448: if (form.elements[radioname][i].value == '1') {
3449: setvis = 1;
3450: break;
3451: }
3452: }
3453: }
3454: for (var j=0; j<fieldsets.length; j++) {
3455: if (setvis) {
3456: fieldsets[j].style.display = 'block';
3457: } else {
3458: fieldsets[j].style.display = 'none';
3459: }
3460: }
3461: }
3462: }
3463: return;
3464: }
3465:
3466: // ]]>
3467: </script>
3468:
3469: ENDSCRIPT
3470: }
3471:
3472:
1.320 raeburn 3473: sub lti_javascript {
1.405 raeburn 3474: my ($dom,$settings) = @_;
3475: my $togglejs = <i_toggle_js($dom);
1.419 raeburn 3476: my $linkprot_js = &Apache::courseprefs::linkprot_javascript();
1.320 raeburn 3477: unless (ref($settings) eq 'HASH') {
1.419 raeburn 3478: return $togglejs.'
3479: <script type="text/javascript">
3480: // <![CDATA[
3481:
3482: '.$linkprot_js.'
3483:
3484: // ]]>
3485: </script>
3486: ';
1.320 raeburn 3487: }
3488: my (%ordered,$total,%jstext);
1.390 raeburn 3489: $total = scalar(keys(%{$settings}));
1.320 raeburn 3490: foreach my $item (keys(%{$settings})) {
3491: if (ref($settings->{$item}) eq 'HASH') {
3492: my $num = $settings->{$item}{'order'};
1.390 raeburn 3493: if ($num eq '') {
3494: $num = $total - 1;
3495: }
1.320 raeburn 3496: $ordered{$num} = $item;
3497: }
3498: }
3499: my @jsarray = ();
3500: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3501: push(@jsarray,$ordered{$item});
3502: }
3503: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
3504: return <<"ENDSCRIPT";
3505: <script type="text/javascript">
3506: // <![CDATA[
3507: function reorderLTI(form,item) {
3508: var changedVal;
3509: $jstext
3510: var newpos = 'lti_pos_add';
3511: var maxh = 1 + $total;
3512: var current = new Array;
3513: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3514: if (item == newpos) {
3515: changedVal = newitemVal;
3516: } else {
3517: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3518: current[newitemVal] = newpos;
3519: }
3520: for (var i=0; i<lti.length; i++) {
3521: var elementName = 'lti_pos_'+lti[i];
3522: if (elementName != item) {
3523: if (form.elements[elementName]) {
3524: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3525: current[currVal] = elementName;
3526: }
3527: }
3528: }
3529: var oldVal;
3530: for (var j=0; j<maxh; j++) {
3531: if (current[j] == undefined) {
3532: oldVal = j;
3533: }
3534: }
3535: if (oldVal < changedVal) {
3536: for (var k=oldVal+1; k<=changedVal ; k++) {
3537: var elementName = current[k];
3538: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3539: }
3540: } else {
3541: for (var k=changedVal; k<oldVal; k++) {
3542: var elementName = current[k];
3543: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3544: }
3545: }
3546: return;
3547: }
1.406 raeburn 3548:
3549: $linkprot_js
3550:
1.320 raeburn 3551: // ]]>
3552: </script>
3553:
3554: $togglejs
3555:
3556: ENDSCRIPT
3557: }
3558:
3559: sub lti_toggle_js {
1.405 raeburn 3560: my ($dom) = @_;
1.325 raeburn 3561: my %lcauthparmtext = &Apache::lonlocal::texthash (
3562: localauth => 'Local auth argument',
3563: krb => 'Kerberos domain',
3564: );
1.391 raeburn 3565: my $crsincalert = &mt('"User\'s identity sent" needs to be set to "Yes" first,[_1] before setting "Course\'s identity sent" to "Yes"',"\n");
3566: &js_escape(\$crsincalert);
1.405 raeburn 3567: my %servers = &Apache::lonnet::get_servers($dom,'library');
3568: my $primary = &Apache::lonnet::domain($dom,'primary');
3569: my $course_servers = "'".join("','",keys(%servers))."'";
1.320 raeburn 3570: return <<"ENDSCRIPT";
3571: <script type="text/javascript">
3572: // <![CDATA[
3573:
3574: function toggleLTI(form,setting,item) {
1.391 raeburn 3575: if ((setting == 'requser') || (setting == 'crsinc')) {
3576: var usrfieldsets = document.getElementsByClassName('ltioption_usr_'+item);
3577: var setvis = '';
3578: var radioname = 'lti_requser_'+item;
3579: var num = form.elements[radioname].length;
3580: if (num) {
3581: for (var i=0; i<num; i++) {
3582: if (form.elements[radioname][i].checked) {
3583: if (form.elements[radioname][i].value == '1') {
3584: setvis = 1;
3585: break;
3586: }
3587: }
3588: }
3589: }
3590: if (usrfieldsets.length) {
3591: for (var j=0; j<usrfieldsets.length; j++) {
3592: if (setvis) {
3593: usrfieldsets[j].style.display = 'block';
3594: } else {
3595: usrfieldsets[j].style.display = 'none';
3596: }
3597: }
3598: }
3599: var crsfieldsets = document.getElementsByClassName('ltioption_crs_'+item);
3600: if (crsfieldsets.length) {
3601: radioname = 'lti_crsinc_'+item;
1.345 raeburn 3602: var num = form.elements[radioname].length;
3603: if (num) {
1.391 raeburn 3604: var crsvis = '';
1.345 raeburn 3605: for (var i=0; i<num; i++) {
3606: if (form.elements[radioname][i].checked) {
3607: if (form.elements[radioname][i].value == '1') {
1.391 raeburn 3608: if (setvis == '') {
3609: if (setting == 'crsinc'){
3610: alert("$crsincalert");
3611: form.elements[radioname][0].checked = true;
3612: }
3613: } else {
3614: crsvis = 1;
3615: }
3616: break;
1.345 raeburn 3617: }
3618: }
3619: }
1.391 raeburn 3620: setvis = crsvis;
3621: }
3622: for (var j=0; j<crsfieldsets.length; j++) {
3623: if (setvis) {
3624: crsfieldsets[j].style.display = 'block';
3625: } else {
3626: crsfieldsets[j].style.display = 'none';
1.345 raeburn 3627: }
3628: }
3629: }
1.363 raeburn 3630: } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
1.320 raeburn 3631: var radioname = '';
3632: var divid = '';
3633: if (setting == 'user') {
3634: radioname = 'lti_mapuser_'+item;
3635: divid = 'lti_userfield_'+item;
1.343 raeburn 3636: } else if (setting == 'crs') {
1.320 raeburn 3637: radioname = 'lti_mapcrs_'+item;
3638: divid = 'lti_crsfield_'+item;
1.363 raeburn 3639: } else if (setting == 'callback') {
3640: radioname = 'lti_callback_'+item;
3641: divid = 'lti_callbackfield_'+item;
1.337 raeburn 3642: } else {
1.351 raeburn 3643: radioname = 'lti_passback_'+item;
1.337 raeburn 3644: divid = 'lti_passback_'+item;
1.320 raeburn 3645: }
3646: var num = form.elements[radioname].length;
3647: if (num) {
3648: var setvis = '';
3649: for (var i=0; i<num; i++) {
3650: if (form.elements[radioname][i].checked) {
1.363 raeburn 3651: if ((setting == 'passback') || (setting == 'callback')) {
1.337 raeburn 3652: if (form.elements[radioname][i].value == '1') {
3653: if (document.getElementById(divid)) {
3654: document.getElementById(divid).style.display = 'inline-block';
3655: }
3656: setvis = 1;
3657: break;
3658: }
3659: } else {
3660: if (form.elements[radioname][i].value == 'other') {
3661: if (document.getElementById(divid)) {
3662: document.getElementById(divid).style.display = 'inline-block';
3663: }
3664: setvis = 1;
3665: break;
1.320 raeburn 3666: }
3667: }
1.425 raeburn 3668: }
1.320 raeburn 3669: }
3670: if (!setvis) {
3671: if (document.getElementById(divid)) {
3672: document.getElementById(divid).style.display = 'none';
3673: }
3674: }
3675: }
3676: } else if ((setting == 'sec') || (setting == 'secsrc')) {
3677: var numsec = form.elements['lti_crssec_'+item].length;
3678: if (numsec) {
3679: var setvis = '';
3680: for (var i=0; i<numsec; i++) {
3681: if (form.elements['lti_crssec_'+item][i].checked) {
3682: if (form.elements['lti_crssec_'+item][i].value == '1') {
3683: if (document.getElementById('lti_crssecfield_'+item)) {
3684: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
3685: setvis = 1;
3686: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
3687: if (numsrcsec) {
3688: var setsrcvis = '';
3689: for (var j=0; j<numsrcsec; j++) {
3690: if (form.elements['lti_crssecsrc_'+item][j].checked) {
3691: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
3692: if (document.getElementById('lti_secsrcfield_'+item)) {
3693: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
3694: setsrcvis = 1;
3695: }
3696: }
3697: }
3698: }
3699: if (!setsrcvis) {
3700: if (document.getElementById('lti_secsrcfield_'+item)) {
3701: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3702: }
3703: }
3704: }
3705: }
3706: }
3707: }
3708: }
3709: if (!setvis) {
3710: if (document.getElementById('lti_crssecfield_'+item)) {
3711: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
3712: }
3713: if (document.getElementById('lti_secsrcfield_'+item)) {
3714: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3715: }
3716: }
3717: }
1.325 raeburn 3718: } else if (setting == 'lcauth') {
3719: var numauth = form.elements['lti_lcauth_'+item].length;
3720: if (numauth) {
3721: for (var i=0; i<numauth; i++) {
3722: if (form.elements['lti_lcauth_'+item][i].checked) {
3723: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
3724: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
3725: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
3726: } else {
3727: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
3728: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
3729: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
3730: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
3731: } else {
3732: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
3733: }
3734: }
3735: }
3736: }
3737: }
3738: }
3739: }
1.326 raeburn 3740: } else if (setting == 'lcmenu') {
3741: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3742: var divid = 'lti_menufield_'+item;
3743: var setvis = '';
3744: for (var i=0; i<menus.length; i++) {
1.425 raeburn 3745: var radioname = menus[i];
1.326 raeburn 3746: var num = form.elements[radioname].length;
3747: if (num) {
3748: for (var j=0; j<num; j++) {
3749: if (form.elements[radioname][j].checked) {
3750: if (form.elements[radioname][j].value == '1') {
3751: if (document.getElementById(divid)) {
3752: document.getElementById(divid).style.display = 'inline-block';
3753: }
3754: setvis = 1;
3755: break;
3756: }
3757: }
3758: }
3759: }
3760: if (setvis == 1) {
3761: break;
3762: }
3763: }
3764: if (!setvis) {
3765: if (document.getElementById(divid)) {
3766: document.getElementById(divid).style.display = 'none';
3767: }
3768: }
1.320 raeburn 3769: }
3770: return;
3771: }
1.405 raeburn 3772:
1.320 raeburn 3773: // ]]>
3774: </script>
3775:
3776: ENDSCRIPT
3777: }
3778:
1.385 raeburn 3779: sub autoupdate_javascript {
3780: return <<"ENDSCRIPT";
3781: <script type="text/javascript">
3782: // <![CDATA[
3783: function toggleLastActiveDays(form) {
3784: var radioname = 'lastactive';
3785: var divid = 'lastactive_div';
3786: var num = form.elements[radioname].length;
3787: if (num) {
3788: var setvis = '';
3789: for (var i=0; i<num; i++) {
3790: if (form.elements[radioname][i].checked) {
3791: if (form.elements[radioname][i].value == '1') {
3792: if (document.getElementById(divid)) {
3793: document.getElementById(divid).style.display = 'inline-block';
3794: }
3795: setvis = 1;
3796: }
3797: break;
3798: }
3799: }
3800: if (!setvis) {
3801: if (document.getElementById(divid)) {
3802: document.getElementById(divid).style.display = 'none';
3803: }
3804: }
3805: }
3806: return;
3807: }
3808: // ]]>
3809: </script>
3810:
3811: ENDSCRIPT
3812: }
3813:
1.399 raeburn 3814: sub autoenroll_javascript {
3815: return <<"ENDSCRIPT";
3816: <script type="text/javascript">
3817: // <![CDATA[
3818: function toggleFailsafe(form) {
3819: var radioname = 'autoenroll_failsafe';
3820: var divid = 'autoenroll_failsafe_div';
3821: var num = form.elements[radioname].length;
3822: if (num) {
3823: var setvis = '';
3824: for (var i=0; i<num; i++) {
3825: if (form.elements[radioname][i].checked) {
3826: if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
3827: if (document.getElementById(divid)) {
3828: document.getElementById(divid).style.display = 'inline-block';
3829: }
3830: setvis = 1;
3831: }
3832: break;
3833: }
3834: }
3835: if (!setvis) {
3836: if (document.getElementById(divid)) {
3837: document.getElementById(divid).style.display = 'none';
3838: }
3839: }
3840: }
3841: return;
3842: }
3843: // ]]>
3844: </script>
3845:
3846: ENDSCRIPT
3847: }
3848:
1.386 raeburn 3849: sub saml_javascript {
3850: return <<"ENDSCRIPT";
3851: <script type="text/javascript">
3852: // <![CDATA[
1.425 raeburn 3853: function toggleSamlOptions(form,hostid) {
1.386 raeburn 3854: var radioname = 'saml_'+hostid;
3855: var tablecellon = 'samloptionson_'+hostid;
3856: var tablecelloff = 'samloptionsoff_'+hostid;
3857: var num = form.elements[radioname].length;
3858: if (num) {
1.425 raeburn 3859: var setvis = '';
1.386 raeburn 3860: for (var i=0; i<num; i++) {
3861: if (form.elements[radioname][i].checked) {
1.425 raeburn 3862: if (form.elements[radioname][i].value == '1') {
1.386 raeburn 3863: if (document.getElementById(tablecellon)) {
3864: document.getElementById(tablecellon).style.display='';
3865: }
3866: if (document.getElementById(tablecelloff)) {
3867: document.getElementById(tablecelloff).style.display='none';
3868: }
3869: setvis = 1;
3870: }
3871: break;
3872: }
3873: }
3874: if (!setvis) {
3875: if (document.getElementById(tablecellon)) {
3876: document.getElementById(tablecellon).style.display='none';
3877: }
3878: if (document.getElementById(tablecelloff)) {
3879: document.getElementById(tablecelloff).style.display='';
3880: }
3881: }
3882: }
3883: return;
3884: }
3885: // ]]>
3886: </script>
3887:
3888: ENDSCRIPT
3889: }
3890:
1.394 raeburn 3891: sub ipaccess_javascript {
3892: my ($settings) = @_;
3893: my (%ordered,$total,%jstext);
3894: $total = 0;
3895: if (ref($settings) eq 'HASH') {
3896: foreach my $item (keys(%{$settings})) {
3897: if (ref($settings->{$item}) eq 'HASH') {
3898: my $num = $settings->{$item}{'order'};
3899: $ordered{$num} = $item;
3900: }
3901: }
3902: $total = scalar(keys(%{$settings}));
3903: }
3904: my @jsarray = ();
3905: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3906: push(@jsarray,$ordered{$item});
3907: }
3908: my $jstext = ' var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
3909: return <<"ENDSCRIPT";
3910: <script type="text/javascript">
3911: // <![CDATA[
3912: function reorderIPaccess(form,item) {
3913: var changedVal;
3914: $jstext
3915: var newpos = 'ipaccess_pos_add';
3916: var maxh = 1 + $total;
3917: var current = new Array;
3918: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3919: if (item == newpos) {
3920: changedVal = newitemVal;
3921: } else {
3922: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3923: current[newitemVal] = newpos;
3924: }
3925: for (var i=0; i<ipaccess.length; i++) {
3926: var elementName = 'ipaccess_pos_'+ipaccess[i];
3927: if (elementName != item) {
3928: if (form.elements[elementName]) {
3929: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3930: current[currVal] = elementName;
3931: }
3932: }
3933: }
3934: var oldVal;
3935: for (var j=0; j<maxh; j++) {
3936: if (current[j] == undefined) {
3937: oldVal = j;
3938: }
3939: }
3940: if (oldVal < changedVal) {
3941: for (var k=oldVal+1; k<=changedVal ; k++) {
3942: var elementName = current[k];
3943: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3944: }
3945: } else {
3946: for (var k=changedVal; k<oldVal; k++) {
3947: var elementName = current[k];
3948: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3949: }
3950: }
3951: return;
3952: }
3953: // ]]>
3954: </script>
3955:
3956: ENDSCRIPT
3957: }
3958:
1.429 raeburn 3959: sub authordefaults_javascript {
3960: my %alert = &Apache::lonlocal::texthash (
3961: reqd => 'Warning: at least one editor needs to be available.',
3962: rest => 'Unchecking this editor disallowed while others unchecked.',
3963: );
3964: &js_escape(\%alert);
3965: return <<"ENDSCRIPT";
3966: <script type="text/javascript">
3967: // <![CDATA[
3968:
3969: function checkEditors(form,checkbox,current) {
3970: if (form.elements[checkbox].length != undefined) {
3971: var count = 0;
3972: for (var i=0; i<form.elements[checkbox].length; i++) {
3973: if (form.elements[checkbox][i].checked) {
3974: count ++;
3975: }
3976: }
3977: if (count == 0) {
3978: if (current.type =='radio') {
3979: current.checked = true;
3980: alert('$alert{reqd}\\n$alert{rest}');
3981: }
3982: }
3983: }
3984: return;
3985: }
3986: // ]]>
3987: </script>
3988:
3989: ENDSCRIPT
3990: }
3991:
1.3 raeburn 3992: sub print_autoenroll {
1.30 raeburn 3993: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3994: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.399 raeburn 3995: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
3996: $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
3997: $failsafesty = 'none';
3998: %failsafechecked = (
3999: off => ' checked="checked"',
4000: );
1.3 raeburn 4001: if (ref($settings) eq 'HASH') {
4002: if (exists($settings->{'run'})) {
4003: if ($settings->{'run'} eq '0') {
4004: $runoff = ' checked="checked" ';
4005: $runon = ' ';
4006: } else {
4007: $runon = ' checked="checked" ';
4008: $runoff = ' ';
4009: }
4010: } else {
4011: if ($autorun) {
4012: $runon = ' checked="checked" ';
4013: $runoff = ' ';
4014: } else {
4015: $runoff = ' checked="checked" ';
4016: $runon = ' ';
4017: }
4018: }
1.129 raeburn 4019: if (exists($settings->{'co-owners'})) {
4020: if ($settings->{'co-owners'} eq '0') {
4021: $coownersoff = ' checked="checked" ';
4022: $coownerson = ' ';
4023: } else {
4024: $coownerson = ' checked="checked" ';
4025: $coownersoff = ' ';
4026: }
4027: } else {
4028: $coownersoff = ' checked="checked" ';
4029: $coownerson = ' ';
4030: }
1.3 raeburn 4031: if (exists($settings->{'sender_domain'})) {
4032: $defdom = $settings->{'sender_domain'};
4033: }
1.399 raeburn 4034: if (exists($settings->{'failsafe'})) {
4035: $failsafe = $settings->{'failsafe'};
4036: if ($failsafe eq 'zero') {
1.400 raeburn 4037: $failsafechecked{'zero'} = ' checked="checked"';
1.399 raeburn 4038: $failsafechecked{'off'} = '';
4039: $failsafesty = 'inline-block';
4040: } elsif ($failsafe eq 'any') {
4041: $failsafechecked{'any'} = ' checked="checked"';
4042: $failsafechecked{'off'} = '';
4043: }
4044: $autofailsafe = $settings->{'autofailsafe'};
4045: } elsif (exists($settings->{'autofailsafe'})) {
4046: $autofailsafe = $settings->{'autofailsafe'};
4047: if ($autofailsafe ne '') {
4048: $failsafechecked{'zero'} = ' checked="checked"';
4049: $failsafe = 'zero';
1.400 raeburn 4050: $failsafechecked{'off'} = '';
1.399 raeburn 4051: }
1.274 raeburn 4052: }
1.14 raeburn 4053: } else {
4054: if ($autorun) {
4055: $runon = ' checked="checked" ';
4056: $runoff = ' ';
4057: } else {
4058: $runoff = ' checked="checked" ';
4059: $runon = ' ';
4060: }
1.3 raeburn 4061: }
4062: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 4063: my $notif_sender;
4064: if (ref($settings) eq 'HASH') {
4065: $notif_sender = $settings->{'sender_uname'};
4066: }
1.3 raeburn 4067: my $datatable='<tr class="LC_odd_row">'.
4068: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 4069: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 4070: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 4071: $runon.' value="1" />'.&mt('Yes').'</label> '.
4072: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 4073: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 4074: '</tr><tr>'.
4075: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 4076: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 4077: &mt('username').': '.
4078: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 4079: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 4080: ': '.$domform.'</span></td></tr>'.
4081: '<tr class="LC_odd_row">'.
4082: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
4083: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4084: '<input type="radio" name="autoassign_coowners"'.
4085: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
4086: '<label><input type="radio" name="autoassign_coowners"'.
4087: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 4088: '</tr><tr>'.
4089: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
1.400 raeburn 4090: '<td class="LC_left_item"><span class="LC_nobreak">'.
4091: '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="off" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'off'}.' />'.&mt('Not in use').'</label></span> '.
4092: '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="zero" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'zero'}.' />'.&mt('Retrieved section enrollment is zero').'</label></span><br />'.
4093: '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="any" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'any'}.' />'.&mt('Retrieved section enrollment is zero or greater').'</label></span>'.
1.399 raeburn 4094: '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
4095: '<span class="LC_nobreak">'.
4096: &mt('Threshold for number of students in section to drop: [_1]',
4097: '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
4098: '</span></div></td></tr>';
1.274 raeburn 4099: $$rowtotal += 4;
1.3 raeburn 4100: return $datatable;
4101: }
4102:
4103: sub print_autoupdate {
1.30 raeburn 4104: my ($position,$dom,$settings,$rowtotal) = @_;
1.385 raeburn 4105: my ($enable,$datatable);
1.3 raeburn 4106: if ($position eq 'top') {
1.385 raeburn 4107: my %choices = &Apache::lonlocal::texthash (
4108: run => 'Auto-update active?',
4109: classlists => 'Update information in classlists?',
4110: unexpired => 'Skip updates for users without active or future roles?',
4111: lastactive => 'Skip updates for inactive users?',
4112: );
4113: my $itemcount = 0;
1.3 raeburn 4114: my $updateon = ' ';
4115: my $updateoff = ' checked="checked" ';
4116: if (ref($settings) eq 'HASH') {
4117: if ($settings->{'run'} eq '1') {
4118: $updateon = $updateoff;
4119: $updateoff = ' ';
4120: }
4121: }
1.385 raeburn 4122: $enable = '<tr class="LC_odd_row">'.
4123: '<td>'.$choices{'run'}.'</td>'.
4124: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 4125: '<input type="radio" name="autoupdate_run"'.
1.397 raeburn 4126: $updateoff.'value="0" />'.&mt('No').'</label> '.
1.8 raeburn 4127: '<label><input type="radio" name="autoupdate_run"'.
1.385 raeburn 4128: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 4129: '</tr>';
1.385 raeburn 4130: my @toggles = ('classlists','unexpired');
4131: my %defaultchecked = ('classlists' => 'off',
4132: 'unexpired' => 'off'
4133: );
4134: $$rowtotal ++;
4135: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4136: \%choices,$itemcount,'','','left','no');
4137: $datatable = $enable.$datatable;
4138: $$rowtotal += $itemcount;
4139: my $lastactiveon = ' ';
4140: my $lastactiveoff = ' checked="checked" ';
4141: my $lastactivestyle = 'none';
4142: my $lastactivedays;
4143: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
4144: if (ref($settings) eq 'HASH') {
4145: if ($settings->{'lastactive'} =~ /^\d+$/) {
4146: $lastactiveon = $lastactiveoff;
4147: $lastactiveoff = ' ';
4148: $lastactivestyle = 'inline-block';
4149: $lastactivedays = $settings->{'lastactive'};
4150: }
4151: }
4152: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4153: $datatable .= '<tr'.$css_class.'>'.
4154: '<td>'.$choices{'lastactive'}.'</td>'.
4155: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
4156: '<input type="radio" name="lastactive"'.
4157: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
4158: ' <label>'.
4159: '<input type="radio" name="lastactive"'.
4160: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
4161: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
4162: ': '.&mt('inactive = no activity in last [_1] days',
4163: '<input type="text" size="5" name="lastactivedays" value="'.
4164: $lastactivedays.'" />').
4165: '</span></td>'.
4166: '</tr>';
4167: $$rowtotal ++;
1.131 raeburn 4168: } elsif ($position eq 'middle') {
4169: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4170: my $numinrow = 3;
4171: my $locknamesettings;
4172: $datatable .= &insttypes_row($settings,$types,$usertypes,
4173: $dom,$numinrow,$othertitle,
1.305 raeburn 4174: 'lockablenames',$rowtotal);
1.131 raeburn 4175: $$rowtotal ++;
1.3 raeburn 4176: } else {
1.44 raeburn 4177: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 4178: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 4179: 'permanentemail','id');
1.33 raeburn 4180: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 4181: my $numrows = 0;
1.26 raeburn 4182: if (ref($types) eq 'ARRAY') {
4183: if (@{$types} > 0) {
4184: $datatable =
4185: &usertype_update_row($settings,$usertypes,\%fieldtitles,
4186: \@fields,$types,\$numrows);
1.30 raeburn 4187: $$rowtotal += @{$types};
1.26 raeburn 4188: }
1.3 raeburn 4189: }
4190: $datatable .=
4191: &usertype_update_row($settings,{'default' => $othertitle},
4192: \%fieldtitles,\@fields,['default'],
4193: \$numrows);
1.30 raeburn 4194: $$rowtotal ++;
1.3 raeburn 4195: }
4196: return $datatable;
4197: }
4198:
1.125 raeburn 4199: sub print_autocreate {
4200: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 4201: my (%createon,%createoff,%currhash);
1.125 raeburn 4202: my @types = ('xml','req');
4203: if (ref($settings) eq 'HASH') {
4204: foreach my $item (@types) {
4205: $createoff{$item} = ' checked="checked" ';
4206: $createon{$item} = ' ';
4207: if (exists($settings->{$item})) {
4208: if ($settings->{$item}) {
4209: $createon{$item} = ' checked="checked" ';
4210: $createoff{$item} = ' ';
4211: }
4212: }
4213: }
1.210 raeburn 4214: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 4215: $currhash{$settings->{'xmldc'}} = 1;
4216: }
1.125 raeburn 4217: } else {
4218: foreach my $item (@types) {
4219: $createoff{$item} = ' checked="checked" ';
4220: $createon{$item} = ' ';
4221: }
4222: }
4223: $$rowtotal += 2;
1.191 raeburn 4224: my $numinrow = 2;
1.125 raeburn 4225: my $datatable='<tr class="LC_odd_row">'.
4226: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
4227: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4228: '<input type="radio" name="autocreate_xml"'.
4229: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
4230: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 4231: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
4232: '</td></tr><tr>'.
4233: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
4234: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4235: '<input type="radio" name="autocreate_req"'.
4236: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
4237: '<label><input type="radio" name="autocreate_req"'.
4238: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 4239: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4240: 'autocreate_xmldc',%currhash);
1.247 raeburn 4241: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 4242: if ($numdc > 1) {
1.247 raeburn 4243: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
4244: '</td><td class="LC_left_item">';
1.125 raeburn 4245: } else {
1.247 raeburn 4246: $datatable .= &mt('Course creation processed as:').
4247: '</td><td class="LC_right_item">';
1.125 raeburn 4248: }
1.247 raeburn 4249: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 4250: $$rowtotal += $rows;
1.125 raeburn 4251: return $datatable;
4252: }
4253:
1.23 raeburn 4254: sub print_directorysrch {
1.277 raeburn 4255: my ($position,$dom,$settings,$rowtotal) = @_;
4256: my $datatable;
4257: if ($position eq 'top') {
4258: my $instsrchon = ' ';
4259: my $instsrchoff = ' checked="checked" ';
4260: my ($exacton,$containson,$beginson);
4261: my $instlocalon = ' ';
4262: my $instlocaloff = ' checked="checked" ';
4263: if (ref($settings) eq 'HASH') {
4264: if ($settings->{'available'} eq '1') {
4265: $instsrchon = $instsrchoff;
4266: $instsrchoff = ' ';
4267: }
4268: if ($settings->{'localonly'} eq '1') {
4269: $instlocalon = $instlocaloff;
4270: $instlocaloff = ' ';
4271: }
4272: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
4273: foreach my $type (@{$settings->{'searchtypes'}}) {
4274: if ($type eq 'exact') {
4275: $exacton = ' checked="checked" ';
4276: } elsif ($type eq 'contains') {
4277: $containson = ' checked="checked" ';
4278: } elsif ($type eq 'begins') {
4279: $beginson = ' checked="checked" ';
4280: }
4281: }
4282: } else {
4283: if ($settings->{'searchtypes'} eq 'exact') {
4284: $exacton = ' checked="checked" ';
4285: } elsif ($settings->{'searchtypes'} eq 'contains') {
4286: $containson = ' checked="checked" ';
4287: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 4288: $exacton = ' checked="checked" ';
4289: $containson = ' checked="checked" ';
4290: }
4291: }
1.277 raeburn 4292: }
4293: my ($searchtitles,$titleorder) = &sorted_searchtitles();
4294: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4295:
4296: my $numinrow = 4;
4297: my $cansrchrow = 0;
4298: $datatable='<tr class="LC_odd_row">'.
4299: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
4300: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4301: '<input type="radio" name="dirsrch_available"'.
4302: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
4303: '<label><input type="radio" name="dirsrch_available"'.
4304: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4305: '</tr><tr>'.
4306: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
4307: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4308: '<input type="radio" name="dirsrch_instlocalonly"'.
4309: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4310: '<label><input type="radio" name="dirsrch_instlocalonly"'.
4311: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4312: '</tr>';
4313: $$rowtotal += 2;
4314: if (ref($usertypes) eq 'HASH') {
4315: if (keys(%{$usertypes}) > 0) {
4316: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 4317: $numinrow,$othertitle,'cansearch',
4318: $rowtotal);
1.277 raeburn 4319: $cansrchrow = 1;
1.25 raeburn 4320: }
1.23 raeburn 4321: }
1.277 raeburn 4322: if ($cansrchrow) {
4323: $$rowtotal ++;
4324: $datatable .= '<tr>';
4325: } else {
4326: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 4327: }
1.277 raeburn 4328: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
4329: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
4330: foreach my $title (@{$titleorder}) {
4331: if (defined($searchtitles->{$title})) {
4332: my $check = ' ';
4333: if (ref($settings) eq 'HASH') {
4334: if (ref($settings->{'searchby'}) eq 'ARRAY') {
4335: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
4336: $check = ' checked="checked" ';
4337: }
1.39 raeburn 4338: }
1.25 raeburn 4339: }
1.277 raeburn 4340: $datatable .= '<td class="LC_left_item">'.
4341: '<span class="LC_nobreak"><label>'.
4342: '<input type="checkbox" name="searchby" '.
4343: 'value="'.$title.'"'.$check.'/>'.
4344: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 4345: }
4346: }
1.277 raeburn 4347: $datatable .= '</tr></table></td></tr>';
4348: $$rowtotal ++;
4349: if ($cansrchrow) {
4350: $datatable .= '<tr class="LC_odd_row">';
4351: } else {
4352: $datatable .= '<tr>';
4353: }
4354: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
4355: '<td class="LC_left_item" colspan="2">'.
4356: '<span class="LC_nobreak"><label>'.
4357: '<input type="checkbox" name="searchtypes" '.
4358: $exacton.' value="exact" />'.&mt('Exact match').
4359: '</label> '.
4360: '<label><input type="checkbox" name="searchtypes" '.
4361: $beginson.' value="begins" />'.&mt('Begins with').
4362: '</label> '.
4363: '<label><input type="checkbox" name="searchtypes" '.
4364: $containson.' value="contains" />'.&mt('Contains').
4365: '</label></span></td></tr>';
4366: $$rowtotal ++;
1.26 raeburn 4367: } else {
1.277 raeburn 4368: my $domsrchon = ' checked="checked" ';
4369: my $domsrchoff = ' ';
4370: my $domlocalon = ' ';
4371: my $domlocaloff = ' checked="checked" ';
4372: if (ref($settings) eq 'HASH') {
4373: if ($settings->{'lclocalonly'} eq '1') {
4374: $domlocalon = $domlocaloff;
4375: $domlocaloff = ' ';
4376: }
4377: if ($settings->{'lcavailable'} eq '0') {
4378: $domsrchoff = $domsrchon;
4379: $domsrchon = ' ';
4380: }
4381: }
4382: $datatable='<tr class="LC_odd_row">'.
4383: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
4384: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4385: '<input type="radio" name="dirsrch_domavailable"'.
4386: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
4387: '<label><input type="radio" name="dirsrch_domavailable"'.
4388: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4389: '</tr><tr>'.
4390: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
4391: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4392: '<input type="radio" name="dirsrch_domlocalonly"'.
4393: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4394: '<label><input type="radio" name="dirsrch_domlocalonly"'.
4395: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4396: '</tr>';
4397: $$rowtotal += 2;
1.26 raeburn 4398: }
1.25 raeburn 4399: return $datatable;
4400: }
4401:
1.28 raeburn 4402: sub print_contacts {
1.286 raeburn 4403: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 4404: my $datatable;
4405: my @contacts = ('adminemail','supportemail');
1.286 raeburn 4406: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340 raeburn 4407: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286 raeburn 4408: if ($position eq 'top') {
4409: if (ref($settings) eq 'HASH') {
4410: foreach my $item (@contacts) {
4411: if (exists($settings->{$item})) {
4412: $to{$item} = $settings->{$item};
4413: }
4414: }
4415: }
4416: } elsif ($position eq 'middle') {
4417: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350 raeburn 4418: 'updatesmail','idconflictsmail','hostipmail');
1.288 raeburn 4419: foreach my $type (@mailings) {
4420: $otheremails{$type} = '';
4421: }
1.340 raeburn 4422: } elsif ($position eq 'lower') {
4423: if (ref($settings) eq 'HASH') {
4424: if (ref($settings->{'lonstatus'}) eq 'HASH') {
4425: %lonstatus = %{$settings->{'lonstatus'}};
4426: }
4427: }
1.286 raeburn 4428: } else {
4429: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 4430: foreach my $type (@mailings) {
4431: $otheremails{$type} = '';
4432: }
1.286 raeburn 4433: $bccemails{'helpdeskmail'} = '';
4434: $bccemails{'otherdomsmail'} = '';
4435: $includestr{'helpdeskmail'} = '';
4436: $includestr{'otherdomsmail'} = '';
4437: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
4438: }
1.28 raeburn 4439: if (ref($settings) eq 'HASH') {
1.340 raeburn 4440: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4441: foreach my $type (@mailings) {
4442: if (exists($settings->{$type})) {
4443: if (ref($settings->{$type}) eq 'HASH') {
4444: foreach my $item (@contacts) {
4445: if ($settings->{$type}{$item}) {
4446: $checked{$type}{$item} = ' checked="checked" ';
4447: }
4448: }
4449: $otheremails{$type} = $settings->{$type}{'others'};
4450: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4451: $bccemails{$type} = $settings->{$type}{'bcc'};
4452: if ($settings->{$type}{'include'} ne '') {
4453: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4454: $includestr{$type} = &unescape($includestr{$type});
4455: }
4456: }
4457: }
4458: } elsif ($type eq 'lonstatusmail') {
4459: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
4460: }
1.28 raeburn 4461: }
4462: }
1.286 raeburn 4463: if ($position eq 'bottom') {
4464: foreach my $type (@mailings) {
4465: $bccemails{$type} = $settings->{$type}{'bcc'};
4466: if ($settings->{$type}{'include'} ne '') {
4467: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4468: $includestr{$type} = &unescape($includestr{$type});
4469: }
4470: }
4471: if (ref($settings->{'helpform'}) eq 'HASH') {
4472: if (ref($fields) eq 'ARRAY') {
4473: foreach my $field (@{$fields}) {
4474: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 4475: }
1.286 raeburn 4476: }
4477: if (exists($settings->{'helpform'}{'maxsize'})) {
4478: $maxsize = $settings->{'helpform'}{'maxsize'};
4479: } else {
1.289 raeburn 4480: $maxsize = '1.0';
1.286 raeburn 4481: }
4482: } else {
4483: if (ref($fields) eq 'ARRAY') {
4484: foreach my $field (@{$fields}) {
4485: $currfield{$field} = 'yes';
1.134 raeburn 4486: }
1.28 raeburn 4487: }
1.286 raeburn 4488: $maxsize = '1.0';
1.28 raeburn 4489: }
4490: }
4491: } else {
1.286 raeburn 4492: if ($position eq 'top') {
4493: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
4494: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
4495: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
4496: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 4497: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4498: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
4499: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
4500: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350 raeburn 4501: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4502: } elsif ($position eq 'bottom') {
4503: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
4504: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
4505: if (ref($fields) eq 'ARRAY') {
4506: foreach my $field (@{$fields}) {
4507: $currfield{$field} = 'yes';
4508: }
4509: }
4510: $maxsize = '1.0';
4511: }
1.28 raeburn 4512: }
4513: my ($titles,$short_titles) = &contact_titles();
4514: my $rownum = 0;
4515: my $css_class;
1.286 raeburn 4516: if ($position eq 'top') {
4517: foreach my $item (@contacts) {
4518: $css_class = $rownum%2?' class="LC_odd_row"':'';
4519: $datatable .= '<tr'.$css_class.'>'.
4520: '<td><span class="LC_nobreak">'.$titles->{$item}.
4521: '</span></td><td class="LC_right_item">'.
4522: '<input type="text" name="'.$item.'" value="'.
4523: $to{$item}.'" /></td></tr>';
4524: $rownum ++;
4525: }
1.315 raeburn 4526: } elsif ($position eq 'bottom') {
4527: $css_class = $rownum%2?' class="LC_odd_row"':'';
4528: $datatable .= '<tr'.$css_class.'>'.
4529: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
4530: &mt('(e-mail, subject, and description always shown)').
4531: '</td><td class="LC_left_item">';
4532: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
4533: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
4534: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
4535: foreach my $field (@{$fields}) {
4536: $datatable .= '<tr><td>'.$fieldtitles->{$field};
4537: if (($field eq 'screenshot') || ($field eq 'cc')) {
4538: $datatable .= ' '.&mt('(logged-in users)');
4539: }
4540: $datatable .='</td><td>';
4541: my $clickaction;
4542: if ($field eq 'screenshot') {
4543: $clickaction = ' onclick="screenshotSize(this);"';
4544: }
4545: if (ref($possoptions->{$field}) eq 'ARRAY') {
4546: foreach my $option (@{$possoptions->{$field}}) {
4547: my $checked;
4548: if ($currfield{$field} eq $option) {
4549: $checked = ' checked="checked"';
4550: }
4551: $datatable .= '<span class="LC_nobreak"><label>'.
4552: '<input type="radio" name="helpform_'.$field.'" '.
4553: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
4554: '</label></span>'.(' 'x2);
4555: }
4556: }
4557: if ($field eq 'screenshot') {
4558: my $display;
4559: if ($currfield{$field} eq 'no') {
4560: $display = ' style="display:none"';
4561: }
1.334 raeburn 4562: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315 raeburn 4563: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
4564: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
4565: }
4566: $datatable .= '</td></tr>';
4567: }
4568: $datatable .= '</table>';
4569: }
4570: $datatable .= '</td></tr>'."\n";
4571: $rownum ++;
4572: }
1.340 raeburn 4573: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4574: foreach my $type (@mailings) {
4575: $css_class = $rownum%2?' class="LC_odd_row"':'';
4576: $datatable .= '<tr'.$css_class.'>'.
4577: '<td><span class="LC_nobreak">'.
4578: $titles->{$type}.': </span></td>'.
4579: '<td class="LC_left_item">';
4580: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4581: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
4582: }
4583: $datatable .= '<span class="LC_nobreak">';
4584: foreach my $item (@contacts) {
4585: $datatable .= '<label>'.
4586: '<input type="checkbox" name="'.$type.'"'.
4587: $checked{$type}{$item}.
4588: ' value="'.$item.'" />'.$short_titles->{$item}.
4589: '</label> ';
4590: }
4591: $datatable .= '</span><br />'.&mt('Others').': '.
4592: '<input type="text" name="'.$type.'_others" '.
4593: 'value="'.$otheremails{$type}.'" />';
4594: my %locchecked;
4595: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4596: foreach my $loc ('s','b') {
4597: if ($includeloc{$type} eq $loc) {
4598: $locchecked{$loc} = ' checked="checked"';
4599: last;
4600: }
4601: }
4602: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
4603: '<input type="text" name="'.$type.'_bcc" '.
4604: 'value="'.$bccemails{$type}.'" /></fieldset>'.
4605: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4606: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4607: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286 raeburn 4608: '<span class="LC_nobreak">'.&mt('Location:').' '.
4609: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4610: (' 'x2).
4611: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4612: '</span></fieldset>';
4613: }
4614: $datatable .= '</td></tr>'."\n";
4615: $rownum ++;
4616: }
1.28 raeburn 4617: }
1.286 raeburn 4618: if ($position eq 'middle') {
4619: my %choices;
1.340 raeburn 4620: my $corelink = &core_link_msu();
4621: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286 raeburn 4622: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340 raeburn 4623: $corelink);
4624: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
4625: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286 raeburn 4626: my %defaultchecked = ('reporterrors' => 'on',
1.340 raeburn 4627: 'reportupdates' => 'on',
4628: 'reportstatus' => 'on');
1.286 raeburn 4629: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4630: \%choices,$rownum);
4631: $datatable .= $reports;
1.340 raeburn 4632: } elsif ($position eq 'lower') {
1.378 raeburn 4633: my (%current,%excluded,%weights);
1.340 raeburn 4634: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
4635: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.378 raeburn 4636: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.340 raeburn 4637: } else {
1.378 raeburn 4638: $current{'errorthreshold'} = $defaults->{'threshold'};
1.340 raeburn 4639: }
4640: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.378 raeburn 4641: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.340 raeburn 4642: } else {
1.378 raeburn 4643: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.340 raeburn 4644: }
4645: if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341 raeburn 4646: foreach my $type ('E','W','N','U') {
1.340 raeburn 4647: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
4648: $weights{$type} = $lonstatus{'weights'}{$type};
4649: } else {
4650: $weights{$type} = $defaults->{$type};
4651: }
4652: }
4653: } else {
1.341 raeburn 4654: foreach my $type ('E','W','N','U') {
1.340 raeburn 4655: $weights{$type} = $defaults->{$type};
4656: }
4657: }
4658: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
4659: if (@{$lonstatus{'excluded'}} > 0) {
4660: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
4661: }
4662: }
1.425 raeburn 4663: foreach my $item ('errorthreshold','errorsysmail') {
1.378 raeburn 4664: $css_class = $rownum%2?' class="LC_odd_row"':'';
4665: $datatable .= '<tr'.$css_class.'>'.
4666: '<td class="LC_left_item"><span class="LC_nobreak">'.
4667: $titles->{$item}.
4668: '</span></td><td class="LC_left_item">'.
4669: '<input type="text" name="'.$item.'" value="'.
4670: $current{$item}.'" size="5" /></td></tr>';
4671: $rownum ++;
4672: }
1.340 raeburn 4673: $css_class = $rownum%2?' class="LC_odd_row"':'';
4674: $datatable .= '<tr'.$css_class.'>'.
4675: '<td class="LC_left_item">'.
4676: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
4677: '</span></td><td class="LC_left_item"><table><tr>';
1.341 raeburn 4678: foreach my $type ('E','W','N','U') {
1.340 raeburn 4679: $datatable .= '<td>'.$names->{$type}.'<br />'.
4680: '<input type="text" name="errorweights_'.$type.'" value="'.
4681: $weights{$type}.'" size="5" /></td>';
4682: }
4683: $datatable .= '</tr></table></tr>';
4684: $rownum ++;
4685: $css_class = $rownum%2?' class="LC_odd_row"':'';
4686: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
4687: $titles->{'errorexcluded'}.'</td>'.
4688: '<td class="LC_left_item"><table>';
4689: my $numinrow = 4;
4690: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
4691: for (my $i=0; $i<@ids; $i++) {
4692: my $rem = $i%($numinrow);
4693: if ($rem == 0) {
4694: if ($i > 0) {
4695: $datatable .= '</tr>';
4696: }
4697: $datatable .= '<tr>';
4698: }
4699: my $check;
4700: if ($excluded{$ids[$i]}) {
4701: $check = ' checked="checked" ';
4702: }
4703: $datatable .= '<td class="LC_left_item">'.
4704: '<span class="LC_nobreak"><label>'.
4705: '<input type="checkbox" name="errorexcluded" '.
4706: 'value="'.$ids[$i].'"'.$check.' />'.
4707: $ids[$i].'</label></span></td>';
4708: }
4709: my $colsleft = $numinrow - @ids%($numinrow);
4710: if ($colsleft > 1 ) {
4711: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4712: ' </td>';
4713: } elsif ($colsleft == 1) {
4714: $datatable .= '<td class="LC_left_item"> </td>';
4715: }
4716: $datatable .= '</tr></table></td></tr>';
4717: $rownum ++;
1.286 raeburn 4718: } elsif ($position eq 'bottom') {
1.315 raeburn 4719: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4720: my (@posstypes,%usertypeshash);
4721: if (ref($types) eq 'ARRAY') {
4722: @posstypes = @{$types};
4723: }
4724: if (@posstypes) {
4725: if (ref($usertypes) eq 'HASH') {
4726: %usertypeshash = %{$usertypes};
4727: }
4728: my @overridden;
4729: my $numinrow = 4;
4730: if (ref($settings) eq 'HASH') {
4731: if (ref($settings->{'overrides'}) eq 'HASH') {
4732: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
4733: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
4734: push(@overridden,$key);
4735: foreach my $item (@contacts) {
4736: if ($settings->{'overrides'}{$key}{$item}) {
4737: $checked{'override_'.$key}{$item} = ' checked="checked" ';
4738: }
4739: }
4740: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
4741: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
4742: $includeloc{'override_'.$key} = '';
4743: $includestr{'override_'.$key} = '';
4744: if ($settings->{'overrides'}{$key}{'include'} ne '') {
1.425 raeburn 4745: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
1.315 raeburn 4746: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
4747: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
4748: }
1.286 raeburn 4749: }
4750: }
4751: }
1.315 raeburn 4752: }
4753: my $customclass = 'LC_helpdesk_override';
4754: my $optionsprefix = 'LC_options_helpdesk_';
4755:
4756: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
4757: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
4758: $numinrow,$othertitle,'overrides',
4759: \$rownum,$onclicktypes,$customclass);
4760: $rownum ++;
4761: $usertypeshash{'default'} = $othertitle;
4762: foreach my $status (@posstypes) {
4763: my $css_class;
4764: if ($rownum%2) {
4765: $css_class = 'LC_odd_row ';
4766: }
4767: $css_class .= $customclass;
4768: my $rowid = $optionsprefix.$status;
4769: my $hidden = 1;
4770: my $currstyle = 'display:none';
4771: if (grep(/^\Q$status\E$/,@overridden)) {
4772: $currstyle = 'display:table-row';
4773: $hidden = 0;
4774: }
4775: my $key = 'override_'.$status;
4776: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
4777: $includeloc{$key},$includestr{$key},$status,$rowid,
4778: $usertypeshash{$status},$css_class,$currstyle,
4779: \@contacts,$short_titles);
4780: unless ($hidden) {
4781: $rownum ++;
1.286 raeburn 4782: }
4783: }
1.134 raeburn 4784: }
1.28 raeburn 4785: }
1.30 raeburn 4786: $$rowtotal += $rownum;
1.28 raeburn 4787: return $datatable;
4788: }
4789:
1.340 raeburn 4790: sub core_link_msu {
4791: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
4792: &mt('LON-CAPA core group - MSU'),600,500);
4793: }
4794:
1.315 raeburn 4795: sub overridden_helpdesk {
4796: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
4797: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
4798: my $class = 'LC_left_item';
4799: if ($css_class) {
4800: $css_class = ' class="'.$css_class.'"';
4801: }
4802: if ($rowid) {
4803: $rowid = ' id="'.$rowid.'"';
4804: }
4805: if ($rowstyle) {
4806: $rowstyle = ' style="'.$rowstyle.'"';
4807: }
4808: my ($output,$description);
4809: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
4810: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
4811: "<td>$description</td>\n".
4812: '<td class="'.$class.'" colspan="2">'.
4813: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
4814: '<span class="LC_nobreak">';
4815: if (ref($contacts) eq 'ARRAY') {
4816: foreach my $item (@{$contacts}) {
4817: my $check;
4818: if (ref($checked) eq 'HASH') {
4819: $check = $checked->{$item};
4820: }
4821: my $title;
4822: if (ref($short_titles) eq 'HASH') {
1.425 raeburn 4823: $title = $short_titles->{$item};
1.315 raeburn 4824: }
4825: $output .= '<label>'.
4826: '<input type="checkbox" name="override_'.$type.'"'.$check.
4827: ' value="'.$item.'" />'.$title.'</label> ';
4828: }
4829: }
4830: $output .= '</span><br />'.&mt('Others').': '.
4831: '<input type="text" name="override_'.$type.'_others" '.
4832: 'value="'.$otheremails.'" />';
4833: my %locchecked;
4834: foreach my $loc ('s','b') {
4835: if ($includeloc eq $loc) {
4836: $locchecked{$loc} = ' checked="checked"';
4837: last;
4838: }
4839: }
4840: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4841: '<input type="text" name="override_'.$type.'_bcc" '.
4842: 'value="'.$bccemails.'" /></fieldset>'.
4843: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4844: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4845: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315 raeburn 4846: '<span class="LC_nobreak">'.&mt('Location:').' '.
4847: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4848: (' 'x2).
4849: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4850: '</span></fieldset>'.
4851: '</td></tr>'."\n";
4852: return $output;
4853: }
4854:
1.286 raeburn 4855: sub contacts_javascript {
4856: return <<"ENDSCRIPT";
4857:
4858: <script type="text/javascript">
4859: // <![CDATA[
4860:
4861: function screenshotSize(field) {
4862: if (document.getElementById('help_screenshotsize')) {
4863: if (field.value == 'no') {
1.289 raeburn 4864: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 4865: } else {
4866: document.getElementById('help_screenshotsize').style.display="";
4867: }
4868: }
4869: return;
4870: }
4871:
1.315 raeburn 4872: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4873: if (form.elements[checkbox].length != undefined) {
4874: var count = 0;
4875: if (docount) {
4876: for (var i=0; i<form.elements[checkbox].length; i++) {
4877: if (form.elements[checkbox][i].checked) {
4878: count ++;
4879: }
4880: }
4881: }
4882: for (var i=0; i<form.elements[checkbox].length; i++) {
4883: var type = form.elements[checkbox][i].value;
4884: if (document.getElementById(prefix+type)) {
4885: if (form.elements[checkbox][i].checked) {
4886: document.getElementById(prefix+type).style.display = 'table-row';
4887: if (count % 2 == 1) {
4888: document.getElementById(prefix+type).className = target+' LC_odd_row';
4889: } else {
4890: document.getElementById(prefix+type).className = target;
4891: }
4892: count ++;
4893: } else {
4894: document.getElementById(prefix+type).style.display = 'none';
4895: }
4896: }
4897: }
4898: }
4899: return;
4900: }
4901:
1.286 raeburn 4902: // ]]>
4903: </script>
4904:
4905: ENDSCRIPT
4906: }
4907:
1.118 jms 4908: sub print_helpsettings {
1.282 raeburn 4909: my ($position,$dom,$settings,$rowtotal) = @_;
4910: my $confname = $dom.'-domainconfig';
1.285 raeburn 4911: my $formname = 'display';
1.168 raeburn 4912: my ($datatable,$itemcount);
1.282 raeburn 4913: if ($position eq 'top') {
4914: $itemcount = 1;
4915: my (%choices,%defaultchecked,@toggles);
4916: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4917: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4918: &mt('LON-CAPA bug tracker'),600,500));
4919: %defaultchecked = ('submitbugs' => 'on');
4920: @toggles = ('submitbugs');
4921: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4922: \%choices,$itemcount);
4923: $$rowtotal ++;
4924: } else {
4925: my $css_class;
4926: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 4927: my (%customroles,%ordered,%current);
1.301 raeburn 4928: if (ref($settings) eq 'HASH') {
4929: if (ref($settings->{'adhoc'}) eq 'HASH') {
4930: %current = %{$settings->{'adhoc'}};
4931: }
1.285 raeburn 4932: }
4933: my $count = 0;
4934: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 4935: if ($key=~/^rolesdef\_(\w+)$/) {
4936: my $rolename = $1;
1.285 raeburn 4937: my (%privs,$order);
1.282 raeburn 4938: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4939: $customroles{$rolename} = \%privs;
1.285 raeburn 4940: if (ref($current{$rolename}) eq 'HASH') {
4941: $order = $current{$rolename}{'order'};
4942: }
4943: if ($order eq '') {
4944: $order = $count;
4945: }
4946: $ordered{$order} = $rolename;
4947: $count++;
4948: }
4949: }
4950: my $maxnum = scalar(keys(%ordered));
4951: my @roles_by_num = ();
4952: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4953: push(@roles_by_num,$item);
4954: }
4955: my $context = 'domprefs';
4956: my $crstype = 'Course';
4957: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 4958: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 4959: my ($numstatustypes,@jsarray);
4960: if (ref($types) eq 'ARRAY') {
4961: if (@{$types} > 0) {
4962: $numstatustypes = scalar(@{$types});
4963: push(@accesstypes,'status');
4964: @jsarray = ('bystatus');
1.282 raeburn 4965: }
4966: }
1.290 raeburn 4967: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 4968: if (keys(%domhelpdesk)) {
4969: push(@accesstypes,('inc','exc'));
4970: push(@jsarray,('notinc','notexc'));
4971: }
4972: my $hiddenstr = join("','",@jsarray);
1.282 raeburn 4973: my $context = 'domprefs';
4974: my $crstype = 'Course';
1.285 raeburn 4975: my $prefix = 'helproles_';
4976: my $add_class = 'LC_hidden';
4977: foreach my $num (@roles_by_num) {
4978: my $role = $ordered{$num};
4979: my ($desc,$access,@statuses);
4980: if (ref($current{$role}) eq 'HASH') {
4981: $desc = $current{$role}{'desc'};
4982: $access = $current{$role}{'access'};
4983: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4984: @statuses = @{$current{$role}{'insttypes'}};
4985: }
4986: }
4987: if ($desc eq '') {
4988: $desc = $role;
4989: }
4990: my $identifier = 'custhelp'.$num;
1.282 raeburn 4991: my %full=();
4992: my %levels= (
4993: course => {},
4994: domain => {},
4995: system => {},
4996: );
4997: my %levelscurrent=(
4998: course => {},
4999: domain => {},
5000: system => {},
5001: );
5002: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
5003: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
5004: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 5005: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 5006: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 5007: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
5008: for (my $k=0; $k<=$maxnum; $k++) {
5009: my $vpos = $k+1;
5010: my $selstr;
5011: if ($k == $num) {
5012: $selstr = ' selected="selected" ';
5013: }
5014: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5015: }
5016: $datatable .= '</select>'.(' 'x2).
5017: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
5018: '</td>'.
5019: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
5020: &mt('Name shown to users:').
5021: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
5022: '</fieldset>'.
5023: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
5024: $othertitle,$usertypes,$types,\%domhelpdesk).
5025: '<fieldset>'.
5026: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 5027: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 5028: \%levelscurrent,$identifier,
5029: 'LC_hidden',$prefix.$num.'_privs').
5030: '</fieldset></td>';
1.282 raeburn 5031: $itemcount ++;
5032: }
5033: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5034: my $newcust = 'custhelp'.$count;
5035: my (%privs,%levelscurrent);
5036: my %full=();
5037: my %levels= (
5038: course => {},
5039: domain => {},
5040: system => {},
5041: );
5042: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
5043: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 5044: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 5045: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 5046: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
5047: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
5048: for (my $k=0; $k<$maxnum+1; $k++) {
5049: my $vpos = $k+1;
5050: my $selstr;
5051: if ($k == $maxnum) {
5052: $selstr = ' selected="selected" ';
5053: }
5054: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5055: }
5056: $datatable .= '</select> '."\n".
1.282 raeburn 5057: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
5058: '</label></span></td>'.
1.285 raeburn 5059: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
5060: '<span class="LC_nobreak">'.
5061: &mt('Internal name:').
5062: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
5063: '</span>'.(' 'x4).
5064: '<span class="LC_nobreak">'.
5065: &mt('Name shown to users:').
5066: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
5067: '</span></fieldset>'.
5068: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
5069: $usertypes,$types,\%domhelpdesk).
5070: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 5071: &Apache::lonuserutils::custom_role_header($context,$crstype,
5072: \@templateroles,$newcust).
5073: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
5074: \%levelscurrent,$newcust).
1.334 raeburn 5075: '</fieldset>'.
5076: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
5077: '</td></tr>';
1.282 raeburn 5078: $count ++;
5079: $$rowtotal += $count;
5080: }
1.166 raeburn 5081: return $datatable;
1.121 raeburn 5082: }
5083:
1.285 raeburn 5084: sub adhocbutton {
5085: my ($prefix,$num,$field,$visibility) = @_;
5086: my %lt = &Apache::lonlocal::texthash(
5087: show => 'Show details',
5088: hide => 'Hide details',
5089: );
5090: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
5091: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
5092: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
5093: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
5094: }
5095:
5096: sub helpsettings_javascript {
5097: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
5098: return unless(ref($roles_by_num) eq 'ARRAY');
5099: my %html_js_lt = &Apache::lonlocal::texthash(
5100: show => 'Show details',
5101: hide => 'Hide details',
5102: );
5103: &html_escape(\%html_js_lt);
5104: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
5105: return <<"ENDSCRIPT";
5106: <script type="text/javascript">
5107: // <![CDATA[
5108:
5109: function reorderHelpRoles(form,item) {
5110: var changedVal;
5111: $jstext
5112: var newpos = 'helproles_${total}_pos';
5113: var maxh = 1 + $total;
5114: var current = new Array();
5115: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5116: if (item == newpos) {
5117: changedVal = newitemVal;
5118: } else {
5119: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5120: current[newitemVal] = newpos;
5121: }
5122: for (var i=0; i<helproles.length; i++) {
5123: var elementName = 'helproles_'+helproles[i]+'_pos';
5124: if (elementName != item) {
5125: if (form.elements[elementName]) {
5126: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5127: current[currVal] = elementName;
5128: }
5129: }
5130: }
5131: var oldVal;
5132: for (var j=0; j<maxh; j++) {
5133: if (current[j] == undefined) {
5134: oldVal = j;
5135: }
5136: }
5137: if (oldVal < changedVal) {
5138: for (var k=oldVal+1; k<=changedVal ; k++) {
5139: var elementName = current[k];
5140: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5141: }
5142: } else {
5143: for (var k=changedVal; k<oldVal; k++) {
5144: var elementName = current[k];
5145: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5146: }
5147: }
5148: return;
5149: }
5150:
5151: function helpdeskAccess(num) {
5152: var curraccess = null;
5153: if (document.$formname.elements['helproles_'+num+'_access'].length) {
5154: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
5155: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
5156: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
5157: }
5158: }
5159: }
5160: var shown = Array();
5161: var hidden = Array();
5162: if (curraccess == 'none') {
5163: hidden = Array('$hiddenstr');
5164: } else {
5165: if (curraccess == 'status') {
5166: shown = Array('bystatus');
5167: hidden = Array('notinc','notexc');
5168: } else {
5169: if (curraccess == 'exc') {
5170: shown = Array('notexc');
5171: hidden = Array('notinc','bystatus');
5172: }
5173: if (curraccess == 'inc') {
5174: shown = Array('notinc');
5175: hidden = Array('notexc','bystatus');
5176: }
1.293 raeburn 5177: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 5178: hidden = Array('notinc','notexc','bystatus');
5179: }
5180: }
5181: }
5182: if (hidden.length > 0) {
5183: for (var i=0; i<hidden.length; i++) {
5184: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
5185: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
5186: }
5187: }
5188: }
5189: if (shown.length > 0) {
5190: for (var i=0; i<shown.length; i++) {
5191: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
5192: if (shown[i] == 'privs') {
5193: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
5194: } else {
5195: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
5196: }
5197: }
5198: }
5199: }
5200: return;
5201: }
5202:
5203: function toggleHelpdeskItem(num,field) {
5204: if (document.getElementById('helproles_'+num+'_'+field)) {
5205: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 5206: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 5207: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
5208: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5209: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
5210: }
5211: } else {
5212: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
5213: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5214: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
5215: }
5216: }
5217: }
5218: return;
5219: }
5220:
5221: // ]]>
5222: </script>
5223:
5224: ENDSCRIPT
5225: }
5226:
5227: sub helpdeskroles_access {
5228: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
5229: $usertypes,$types,$domhelpdesk) = @_;
5230: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
5231: my %lt = &Apache::lonlocal::texthash(
5232: 'rou' => 'Role usage',
5233: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 5234: 'all' => 'All with domain helpdesk or helpdesk assistant role',
5235: 'dh' => 'All with domain helpdesk role',
5236: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 5237: 'none' => 'None',
5238: 'status' => 'Determined based on institutional status',
5239: 'inc' => 'Include all, but exclude specific personnel',
5240: 'exc' => 'Exclude all, but include specific personnel',
5241: );
5242: my %usecheck = (
5243: all => ' checked="checked"',
5244: );
5245: my %displaydiv = (
5246: status => 'none',
5247: inc => 'none',
5248: exc => 'none',
5249: priv => 'block',
5250: );
5251: my $output;
5252: if (ref($current) eq 'HASH') {
5253: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
5254: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
5255: $usecheck{$current->{access}} = $usecheck{'all'};
5256: delete($usecheck{'all'});
5257: if ($current->{access} =~ /^(status|inc|exc)$/) {
5258: my $access = $1;
5259: $displaydiv{$access} = 'inline';
5260: } elsif ($current->{access} eq 'none') {
5261: $displaydiv{'priv'} = 'none';
5262: }
5263: }
5264: }
5265: }
5266: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
5267: '<p>'.$lt{'whi'}.'</p>';
5268: foreach my $access (@{$accesstypes}) {
5269: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
5270: ' onclick="helpdeskAccess('."'$num'".');" />'.
5271: $lt{$access}.'</label>';
5272: if ($access eq 'status') {
5273: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
5274: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
5275: $othertitle,$usertypes,$types).
5276: '</div>';
5277: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
5278: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
5279: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5280: '</div>';
5281: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
5282: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
5283: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5284: '</div>';
5285: }
5286: $output .= '</p>';
5287: }
5288: $output .= '</fieldset>';
5289: return $output;
5290: }
5291:
1.121 raeburn 5292: sub radiobutton_prefs {
1.192 raeburn 5293: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.385 raeburn 5294: $additional,$align,$firstval) = @_;
1.121 raeburn 5295: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
5296: (ref($choices) eq 'HASH'));
5297:
1.170 raeburn 5298: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 5299:
5300: foreach my $item (@{$toggles}) {
5301: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 5302: $checkedon{$item} = ' checked="checked" ';
5303: $checkedoff{$item} = ' ';
1.121 raeburn 5304: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 5305: $checkedoff{$item} = ' checked="checked" ';
5306: $checkedon{$item} = ' ';
5307: }
5308: }
5309: if (ref($settings) eq 'HASH') {
1.121 raeburn 5310: foreach my $item (@{$toggles}) {
1.118 jms 5311: if ($settings->{$item} eq '1') {
5312: $checkedon{$item} = ' checked="checked" ';
5313: $checkedoff{$item} = ' ';
5314: } elsif ($settings->{$item} eq '0') {
5315: $checkedoff{$item} = ' checked="checked" ';
5316: $checkedon{$item} = ' ';
5317: }
5318: }
1.121 raeburn 5319: }
1.192 raeburn 5320: if ($onclick) {
5321: $onclick = ' onclick="'.$onclick.'"';
5322: }
1.121 raeburn 5323: foreach my $item (@{$toggles}) {
1.118 jms 5324: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 5325: $datatable .=
1.306 raeburn 5326: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 5327: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 5328: '</span></td>';
5329: if ($align eq 'left') {
5330: $datatable .= '<td class="LC_left_item">';
5331: } else {
5332: $datatable .= '<td class="LC_right_item">';
5333: }
1.385 raeburn 5334: $datatable .= '<span class="LC_nobreak">';
5335: if ($firstval eq 'no') {
5336: $datatable .=
5337: '<label><input type="radio" name="'.
5338: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
5339: '</label> <label><input type="radio" name="'.$item.'" '.
5340: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
5341: } else {
5342: $datatable .=
5343: '<label><input type="radio" name="'.
5344: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
5345: '</label> <label><input type="radio" name="'.$item.'" '.
5346: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
5347: }
5348: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 5349: $itemcount ++;
1.121 raeburn 5350: }
5351: return ($datatable,$itemcount);
5352: }
5353:
1.267 raeburn 5354: sub print_ltitools {
1.421 raeburn 5355: my ($position,$dom,$settings,$rowtotal) = @_;
5356: my (%rules,%encrypt,%privkeys,%linkprot);
1.267 raeburn 5357: if (ref($settings) eq 'HASH') {
1.421 raeburn 5358: if ($position eq 'top') {
5359: if (exists($settings->{'encrypt'})) {
5360: if (ref($settings->{'encrypt'}) eq 'HASH') {
5361: foreach my $key (keys(%{$settings->{'encrypt'}})) {
5362: $encrypt{'toolsec_'.$key} = $settings->{'encrypt'}{$key};
1.324 raeburn 5363: }
5364: }
1.267 raeburn 5365: }
1.421 raeburn 5366: if (exists($settings->{'private'})) {
5367: if (ref($settings->{'private'}) eq 'HASH') {
5368: if (ref($settings->{'private'}) eq 'HASH') {
5369: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
5370: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
1.267 raeburn 5371: }
5372: }
5373: }
5374: }
1.421 raeburn 5375: } elsif ($position eq 'middle') {
5376: if (exists($settings->{'rules'})) {
5377: if (ref($settings->{'rules'}) eq 'HASH') {
5378: %rules = %{$settings->{'rules'}};
1.273 raeburn 5379: }
5380: }
1.421 raeburn 5381: } else {
5382: foreach my $key ('encrypt','private','rules') {
5383: if (exists($settings->{$key})) {
5384: delete($settings->{$key});
1.267 raeburn 5385: }
5386: }
5387: }
5388: }
1.421 raeburn 5389: my $datatable;
5390: my $itemcount = 1;
5391: if ($position eq 'top') {
5392: $datatable = &secrets_form($dom,'toolsec',\%encrypt,\%privkeys,$rowtotal);
5393: } elsif ($position eq 'middle') {
5394: $datatable = &password_rules('toolsecrets',\$itemcount,\%rules);
5395: $$rowtotal += $itemcount;
5396: } else {
5397: $datatable = &Apache::courseprefs::print_ltitools($dom,'',$settings,\$rowtotal,'','','domain');
1.267 raeburn 5398: }
5399: return $datatable;
5400: }
5401:
5402: sub ltitools_names {
5403: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 5404: 'title' => 'Title',
5405: 'version' => 'Version',
5406: 'msgtype' => 'Message Type',
1.323 raeburn 5407: 'sigmethod' => 'Signature Method',
1.296 raeburn 5408: 'url' => 'URL',
5409: 'key' => 'Key',
1.322 raeburn 5410: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 5411: 'secret' => 'Secret',
1.425 raeburn 5412: 'icon' => 'Icon',
1.324 raeburn 5413: 'user' => 'User',
1.296 raeburn 5414: 'fullname' => 'Full Name',
5415: 'firstname' => 'First Name',
5416: 'lastname' => 'Last Name',
5417: 'email' => 'E-mail',
5418: 'roles' => 'Role',
1.298 raeburn 5419: 'window' => 'Window',
5420: 'tab' => 'Tab',
1.296 raeburn 5421: 'iframe' => 'iFrame',
5422: 'height' => 'Height',
5423: 'width' => 'Width',
5424: 'linktext' => 'Default Link Text',
5425: 'explanation' => 'Default Explanation',
5426: 'passback' => 'Tool can return grades:',
5427: 'roster' => 'Tool can retrieve roster:',
5428: 'crstarget' => 'Display target',
5429: 'crslabel' => 'Course label',
1.425 raeburn 5430: 'crstitle' => 'Course title',
1.296 raeburn 5431: 'crslinktext' => 'Link Text',
5432: 'crsexplanation' => 'Explanation',
1.318 raeburn 5433: 'crsappend' => 'Provider URL',
1.267 raeburn 5434: );
5435: return %lt;
5436: }
5437:
1.421 raeburn 5438: sub secrets_form {
5439: my ($dom,$context,$encrypt,$privkeys,$rowtotal) = @_;
5440: my @ids=&Apache::lonnet::current_machine_ids();
5441: my %servers = &Apache::lonnet::get_servers($dom,'library');
5442: my $primary = &Apache::lonnet::domain($dom,'primary');
5443: my ($css_class,$extra,$numshown,$itemcount,$output);
5444: $itemcount = 0;
5445: foreach my $hostid (sort(keys(%servers))) {
5446: my ($showextra,$divsty,$switch);
5447: if ($hostid eq $primary) {
5448: if ($context eq 'ltisec') {
5449: if (($encrypt->{'ltisec_consumers'}) || ($encrypt->{'ltisec_domlinkprot'})) {
5450: $showextra = 1;
5451: }
5452: if ($encrypt->{'ltisec_crslinkprot'}) {
5453: $showextra = 1;
5454: }
5455: } else {
5456: if (($encrypt->{'toolsec_crs'}) || ($encrypt->{'toolsec_dom'})) {
5457: $showextra = 1;
5458: }
5459: }
5460: unless (grep(/^\Q$hostid\E$/,@ids)) {
5461: $switch = 1;
5462: }
5463: if ($showextra) {
5464: $numshown ++;
5465: $divsty = 'display:inline-block';
5466: } else {
5467: $divsty = 'display:none';
5468: }
5469: $extra .= '<fieldset id="'.$context.'_info_'.$hostid.'" style="'.$divsty.'">'.
5470: '<legend>'.$hostid.'</legend>';
5471: if ($switch) {
5472: my $switchserver = '<a href="/adm/switchserver?otherserver='.$hostid.'&role='.
5473: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
5474: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
5475: if (exists($privkeys->{$hostid})) {
5476: $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" />'.
5477: '<span class="LC_nobreak">'.
5478: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5479: '<span class="LC_nobreak">'.&mt('Change?').
5480: '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5481: (' 'x2).
5482: '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5483: '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5484: '<span class="LC_nobreak"> - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5485: '</span></div>';
5486: } else {
5487: $extra .= '<span class="LC_nobreak">'.
5488: &mt('Key required').' - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5489: '</span>'."\n";
5490: }
5491: } elsif (exists($privkeys->{$hostid})) {
5492: $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" /><span class="LC_nobreak">'.
5493: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5494: '<span class="LC_nobreak">'.&mt('Change?').
5495: '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5496: (' 'x2).
5497: '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5498: '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5499: '<span class="LC_nobreak">'.&mt('New Key').':'.
5500: '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5501: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.'.$context.'_privkey_'.$hostid.'.type='."'text'".' } else { this.form.'.$context.'_privkey_'.$hostid.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
5502: '</span></div>';
5503: } else {
5504: $extra .= '<span class="LC_nobreak">'.&mt('Encryption Key').':'.
5505: '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5506: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.'.$context.'_privkey_'.$hostid.'.type='."'text'".' } else { this.form.'.$context.'_privkey_'.$hostid.'.type='."'password'".' }" />'.&mt('Visible input').'</label>';
5507: }
5508: $extra .= '</fieldset>';
5509: }
5510: }
5511: my (%choices,@toggles,%defaultchecked);
5512: if ($context eq 'ltisec') {
5513: %choices = &Apache::lonlocal::texthash (
5514: ltisec_crslinkprot => 'Encrypt stored link protection secrets defined in courses',
5515: ltisec_domlinkprot => 'Encrypt stored link protection secrets defined in domain',
5516: ltisec_consumers => 'Encrypt stored consumer secrets defined in domain',
5517: );
5518: @toggles = qw(ltisec_crslinkprot ltisec_domlinkprot ltisec_consumers);
5519: %defaultchecked = (
5520: 'ltisec_crslinkprot' => 'off',
5521: 'ltisec_domlinkprot' => 'off',
5522: 'ltisec_consumers' => 'off',
5523: );
5524: } else {
5525: %choices = &Apache::lonlocal::texthash (
5526: toolsec_crs => 'Encrypt stored external tool secrets defined in courses',
5527: toolsec_dom => 'Encrypt stored external tool secrets defined in domain',
5528: );
5529: @toggles = qw(toolsec_crs toolsec_dom);
5530: %defaultchecked = (
5531: 'toolsec_crs' => 'off',
5532: 'toolsec_dom' => 'off',
5533: );
5534: }
5535: my ($onclick,$itemcount);
5536: $onclick = 'javascript:toggleLTIEncKey(this.form,'."'$context'".');';
5537: ($output,$itemcount) = &radiobutton_prefs($encrypt,\@toggles,\%defaultchecked,
5538: \%choices,$itemcount,$onclick,'','left','no');
5539:
5540: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5541: my $noprivkeysty = 'display:inline-block';
5542: if ($numshown) {
5543: $noprivkeysty = 'display:none';
5544: }
5545: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.&mt('Encryption Key(s)').'</td>'.
5546: '<td><div id="'.$context.'_noprivkey" style="'.$noprivkeysty.'" >'.
5547: '<span class="LC_nobreak">'.&mt('Not in use').'</span></div>'.
5548: $extra.
5549: '</td></tr>';
5550: $itemcount ++;
5551: $$rowtotal += $itemcount;
5552: return $output;
5553: }
5554:
1.372 raeburn 5555: sub print_proctoring {
5556: my ($dom,$settings,$rowtotal) = @_;
5557: my $itemcount = 1;
5558: my (%ordered,%providernames,%current,%currentdef);
5559: my $confname = $dom.'-domainconfig';
5560: my $switchserver = &check_switchserver($dom,$confname);
5561: if (ref($settings) eq 'HASH') {
5562: foreach my $item (keys(%{$settings})) {
5563: if (ref($settings->{$item}) eq 'HASH') {
5564: my $num = $settings->{$item}{'order'};
5565: $ordered{$num} = $item;
5566: }
5567: }
5568: } else {
5569: %ordered = (
5570: 1 => 'proctorio',
5571: 2 => 'examity',
5572: );
5573: }
5574: %providernames = &proctoring_providernames();
5575: my $maxnum = scalar(keys(%ordered));
5576: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
5577: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
5578: if (ref($requref) eq 'HASH') {
5579: %requserfields = %{$requref};
5580: }
5581: if (ref($opturef) eq 'HASH') {
5582: %optuserfields = %{$opturef};
5583: }
5584: if (ref($defref) eq 'HASH') {
5585: %defaults = %{$defref};
5586: }
5587: if (ref($extref) eq 'HASH') {
5588: %extended = %{$extref};
5589: }
5590: if (ref($crsref) eq 'HASH') {
5591: %crsconf = %{$crsref};
5592: }
5593: if (ref($rolesref) eq 'ARRAY') {
5594: @courseroles = @{$rolesref};
5595: }
5596: if (ref($ltiref) eq 'ARRAY') {
5597: @ltiroles = @{$ltiref};
5598: }
5599: my $datatable;
5600: my $css_class;
5601: if (keys(%ordered)) {
5602: my @items = sort { $a <=> $b } keys(%ordered);
5603: for (my $i=0; $i<@items; $i++) {
5604: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5605: my $provider = $ordered{$items[$i]};
5606: my $optionsty = 'none';
5607: my ($available,$version,$lifetime,$imgsrc,$userincdom,$showroles,
5608: %checkedfields,%rolemaps,%inuse,%crsconfig,%current);
5609: if (ref($settings) eq 'HASH') {
5610: if (ref($settings->{$provider}) eq 'HASH') {
5611: %current = %{$settings->{$provider}};
5612: if ($current{'available'}) {
5613: $optionsty = 'block';
5614: $available = 1;
5615: }
5616: if ($current{'lifetime'} =~ /^\d+$/) {
5617: $lifetime = $current{'lifetime'};
5618: }
5619: if ($current{'version'} =~ /^\d+\.\d+$/) {
5620: $version = $current{'version'};
5621: }
5622: if ($current{'image'} ne '') {
5623: $imgsrc = '<img src="'.$current{'image'}.'" alt="'.&mt('Proctoring service icon').'" />';
5624: }
5625: if (ref($current{'fields'}) eq 'ARRAY') {
5626: map { $checkedfields{$_} = 1; } @{$current{'fields'}};
5627: }
5628: $userincdom = $current{'incdom'};
5629: if (ref($current{'roles'}) eq 'HASH') {
5630: %rolemaps = %{$current{'roles'}};
5631: $checkedfields{'roles'} = 1;
5632: }
5633: if (ref($current{'defaults'}) eq 'ARRAY') {
5634: foreach my $val (@{$current{'defaults'}}) {
5635: if (grep(/^\Q$val\E$/,@{$defaults{$provider}})) {
5636: $inuse{$val} = 1;
5637: } else {
5638: foreach my $poss (keys(%{$extended{$provider}})) {
5639: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5640: if (grep(/^\Q$val\E$/,@{$extended{$provider}{$poss}})) {
5641: $inuse{$poss} = $val;
5642: last;
5643: }
5644: }
5645: }
5646: }
5647: }
5648: } elsif (ref($current{'defaults'}) eq 'HASH') {
5649: foreach my $key (keys(%{$current{'defaults'}})) {
5650: my $currval = $current{'defaults'}{$key};
5651: if (grep(/^\Q$key\E$/,@{$defaults{$provider}})) {
5652: $inuse{$key} = 1;
5653: } else {
5654: my $match;
5655: foreach my $poss (keys(%{$extended{$provider}})) {
5656: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5657: if (grep(/^\Q$key\E$/,@{$extended{$provider}{$poss}})) {
5658: $inuse{$poss} = $key;
5659: last;
5660: }
5661: } elsif (ref($extended{$provider}{$poss}) eq 'HASH') {
5662: foreach my $inner (sort(keys(%{$extended{$provider}{$poss}}))) {
5663: if (ref($extended{$provider}{$poss}{$inner}) eq 'ARRAY') {
5664: if (grep(/^\Q$currval\E$/,@{$extended{$provider}{$poss}{$inner}})) {
5665: $currentdef{$inner} = $currval;
5666: $match = 1;
5667: last;
5668: }
5669: } elsif ($inner eq $key) {
5670: $currentdef{$key} = $currval;
5671: $match = 1;
5672: last;
5673: }
5674: }
5675: }
5676: last if ($match);
5677: }
5678: }
5679: }
5680: }
5681: if (ref($current{'crsconf'}) eq 'ARRAY') {
5682: map { $crsconfig{$_} = 1; } @{$current{'crsconf'}};
5683: }
5684: }
5685: }
5686: my %lt = &proctoring_titles($provider);
5687: my %fieldtitles = &proctoring_fieldtitles($provider);
5688: my $onclickavailable = ' onclick="toggleProctoring(this.form,'."'$provider'".');"';
5689: my %checkedavailable = (
5690: yes => '',
5691: no => ' checked="checked"',
5692: );
5693: if ($available) {
5694: $checkedavailable{'yes'} = $checkedavailable{'no'};
5695: $checkedavailable{'no'} = '';
5696: }
5697: my $chgstr = ' onchange="javascript:reorderProctoring(this.form,'."'proctoring_pos_".$provider."'".');"';
5698: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5699: .'<select name="proctoring_pos_'.$provider.'"'.$chgstr.'>';
5700: for (my $k=0; $k<$maxnum; $k++) {
5701: my $vpos = $k+1;
5702: my $selstr;
5703: if ($k == $i) {
5704: $selstr = ' selected="selected" ';
5705: }
5706: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5707: }
5708: if ($version eq '') {
5709: if ($provider eq 'proctorio') {
5710: $version = '1.0';
5711: } elsif ($provider eq 'examity') {
5712: $version = '1.1';
5713: }
5714: }
5715: if ($lifetime eq '') {
5716: $lifetime = '300';
5717: }
5718: $datatable .=
5719: '</select>'.(' 'x2).'<b>'.$providernames{$provider}.'</b></span><br />'.
5720: '<span class="LC_nobreak">'.$lt{'avai'}.' '.
5721: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="1"'.$onclickavailable.$checkedavailable{yes}.' />'.&mt('Yes').'</label> '."\n".
5722: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="0"'.$onclickavailable.$checkedavailable{no}.' />'.&mt('No').'</label></span>'."\n".
5723: '</td>'.
5724: '<td colspan="2">'.
5725: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'base'}.'</legend>'.
5726: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="proctoring_'.$provider.'_version">'.
5727: '<option value="'.$version.'" selected="selected">'.$version.'</option></select></span> '."\n".
5728: (' 'x2).
5729: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="proctoring_'.$provider.'_sigmethod">'.
5730: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5731: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
5732: (' 'x2).
5733: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="proctoring_'.$provider.'_lifetime" value="'.$lifetime.'" /></span> '."\n".
5734: '<br />'.
5735: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="proctoring_'.$provider.'_url" value="'.$current{'url'}.'" /></span> '."\n".
5736: '<br />'.
5737: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="proctoring_'.$provider.'_key" value="'.$current{'key'}.'" /></span> '."\n".
5738: (' 'x2).
5739: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="proctoring_'.$provider.'_secret" value="'.$current{'secret'}.'" />'.
5740: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.proctoring_'.$provider.'_secret.type='."'text'".' } else { this.form.proctoring_'.$provider.'_secret.type='."'password'".' }" />'.$lt{'visible'}.'</label></span><br />'."\n";
5741: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
5742: if ($imgsrc) {
5743: $datatable .= $imgsrc.
5744: '<label><input type="checkbox" name="proctoring_image_del"'.
5745: ' value="'.$provider.'" />'.&mt('Delete?').'</label></span> '.
5746: '<span class="LC_nobreak"> '.&mt('Replace:');
5747: }
5748: $datatable .= ' ';
5749: if ($switchserver) {
5750: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5751: } else {
5752: $datatable .= '<input type="file" name="proctoring_image_'.$provider.'" value="" />';
5753: }
5754: unless ($imgsrc) {
5755: $datatable .= '<br />('.&mt('if larger than 21x21 pixels, image will be scaled').')';
5756: }
5757: $datatable .= '</fieldset>'."\n";
5758: if (ref($requserfields{$provider}) eq 'ARRAY') {
5759: if (@{$requserfields{$provider}} > 0) {
5760: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'requ'}.'</legend>';
5761: foreach my $field (@{$requserfields{$provider}}) {
5762: $datatable .= '<span class="LC_nobreak">'.
5763: '<label><input type="checkbox" name="proctoring_reqd_'.$provider.'" value="'.$field.'" checked="checked" disabled="disabled" />'.
5764: $lt{$field}.'</label>';
5765: if ($field eq 'user') {
5766: my $seluserdom = '';
5767: my $unseluserdom = ' selected="selected"';
5768: if ($userincdom) {
5769: $seluserdom = $unseluserdom;
5770: $unseluserdom = '';
5771: }
5772: $datatable .= ': '.
5773: '<select name="proctoring_userincdom_'.$provider.'">'.
5774: '<option value="0"'.$unseluserdom.'>'.$lt{'username'}.'</option>'.
5775: '<option value="1"'.$seluserdom.'>'.$lt{'uname:dom'}.'</option>'.
5776: '</select> ';
5777: } else {
5778: $datatable .= ' ';
5779: if ($field eq 'roles') {
5780: $showroles = 1;
5781: }
5782: }
5783: $datatable .= '</span> ';
5784: }
5785: }
5786: $datatable .= '</fieldset>'."\n";
5787: }
5788: if (ref($optuserfields{$provider}) eq 'ARRAY') {
5789: if (@{$optuserfields{$provider}} > 0) {
5790: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'optu'}.'</legend>';
5791: foreach my $field (@{$optuserfields{$provider}}) {
5792: my $checked;
5793: if ($checkedfields{$field}) {
5794: $checked = ' checked="checked"';
5795: }
5796: $datatable .= '<span class="LC_nobreak">'.
5797: '<label><input type="checkbox" name="proctoring_optional_'.$provider.'" value="'.$field.'"'.$checked.' />'.$lt{$field}.'</label></span> ';
5798: }
5799: $datatable .= '</fieldset>'."\n";
5800: }
5801: }
5802: if (ref($defaults{$provider}) eq 'ARRAY') {
5803: if (@{$defaults{$provider}}) {
5804: my (%options,@selectboxes);
5805: if (ref($extended{$provider}) eq 'HASH') {
5806: %options = %{$extended{$provider}};
5807: }
5808: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'defa'}.'</legend>';
5809: my ($rem,$numinrow,$dropdowns);
5810: if ($provider eq 'proctorio') {
5811: $datatable .= '<table>';
5812: $numinrow = 4;
5813: }
5814: my $i = 0;
5815: foreach my $field (@{$defaults{$provider}}) {
5816: my $checked;
5817: if ($inuse{$field}) {
5818: $checked = ' checked="checked"';
5819: }
5820: if ($provider eq 'examity') {
5821: if ($field eq 'display') {
5822: $datatable .= '<span class="LC_nobreak">'.&mt('Display target:');
5823: foreach my $option ('iframe','tab','window') {
5824: my $checkdisp;
5825: if ($currentdef{'target'} eq $option) {
5826: $checkdisp = ' checked="checked"';
5827: }
5828: $datatable .= '<label><input type="radio" name="proctoring_target_'.$provider.'" value="'.$option.'"'.$checkdisp.' />'.
5829: $fieldtitles{$option}.'</label>'.(' 'x2);
5830: }
5831: $datatable .= (' 'x4);
5832: foreach my $dimen ('width','height') {
5833: $datatable .= '<label>'.$fieldtitles{$dimen}.' '.
5834: '<input type="text" name="proctoring_'.$dimen.'_'.$provider.'" size="5" '.
5835: 'value="'.$currentdef{$dimen}.'" /></label>'.
5836: (' 'x2);
5837: }
5838: $datatable .= '</span><br />'.
5839: '<div class="LC_left_float">'.$fieldtitles{'linktext'}.'<br />'.
5840: '<input type="text" name="proctoring_linktext_'.$provider.'" '.
5841: 'size="25" value="'.$currentdef{'linktext'}.'" /></div>'.
5842: '<div class="LC_left_float">'.$fieldtitles{'explanation'}.'<br />'.
5843: '<textarea name="proctoring_explanation_'.$provider.'" rows="5" cols="40">'.
5844: $currentdef{'explanation'}.
5845: '</textarea></div><div style=""></div><br />';
5846: }
5847: } else {
5848: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
5849: my ($output,$selnone);
5850: unless ($checked) {
5851: $selnone = ' selected="selected"';
5852: }
5853: $output .= '<span class="LC_nobreak">'.$fieldtitles{$field}.': '.
5854: '<select name="proctoring_defaults_'.$field.'_'.$provider.'">'.
5855: '<option value=""'.$selnone.'>'.&mt('Not in use').'</option>';
5856: foreach my $option (@{$options{$field}}) {
5857: my $sel;
5858: if ($inuse{$field} eq $option) {
5859: $sel = ' selected="selected"';
5860: }
5861: $output .= '<option value="'.$option.'"'.$sel.'>'.$fieldtitles{$option}.'</option>';
5862: }
5863: $output .= '</select></span>';
5864: push(@selectboxes,$output);
5865: } else {
5866: $rem = $i%($numinrow);
5867: if ($rem == 0) {
5868: if ($i > 0) {
5869: $datatable .= '</tr>';
5870: }
5871: $datatable .= '<tr>';
5872: }
5873: $datatable .= '<td class="LC_left_item">'.
5874: '<span class="LC_nobreak">'.
5875: '<label><input type="checkbox" name="proctoring_defaults_'.$provider.'" value="'.$field.'"'.$checked.' />'.
5876: $fieldtitles{$field}.'</label></span></td>';
5877: $i++;
5878: }
5879: }
5880: }
5881: if ($provider eq 'proctorio') {
5882: if ($numinrow) {
5883: $rem = $i%$numinrow;
5884: }
5885: my $colsleft = $numinrow - $rem;
5886: if ($colsleft > 1) {
5887: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5888: } else {
5889: $datatable .= '<td class="LC_left_item">';
5890: }
5891: $datatable .= ' '.
5892: '</td></tr></table>';
5893: if (@selectboxes) {
5894: $datatable .= '<hr /><table>';
5895: $numinrow = 2;
5896: for (my $i=0; $i<@selectboxes; $i++) {
5897: $rem = $i%($numinrow);
5898: if ($rem == 0) {
5899: if ($i > 0) {
5900: $datatable .= '</tr>';
5901: }
5902: $datatable .= '<tr>';
5903: }
5904: $datatable .= '<td class="LC_left_item">'.
5905: $selectboxes[$i].'</td>';
5906: }
5907: if ($numinrow) {
5908: $rem = $i%$numinrow;
5909: }
5910: $colsleft = $numinrow - $rem;
5911: if ($colsleft > 1) {
5912: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5913: } else {
5914: $datatable .= '<td class="LC_left_item">';
5915: }
5916: $datatable .= ' '.
5917: '</td></tr></table>';
5918: }
5919: }
5920: $datatable .= '</fieldset>';
5921: }
5922: if (ref($crsconf{$provider}) eq 'ARRAY') {
5923: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5924: '<legend>'.&mt('Configurable in course').'</legend>';
5925: my ($rem,$numinrow);
5926: if ($provider eq 'proctorio') {
5927: $datatable .= '<table>';
5928: $numinrow = 4;
5929: }
5930: my $i = 0;
5931: foreach my $item (@{$crsconf{$provider}}) {
5932: my $name;
5933: if ($provider eq 'examity') {
5934: $name = $lt{'crs'.$item};
5935: } elsif ($provider eq 'proctorio') {
5936: $name = $fieldtitles{$item};
5937: $rem = $i%($numinrow);
5938: if ($rem == 0) {
5939: if ($i > 0) {
5940: $datatable .= '</tr>';
5941: }
5942: $datatable .= '<tr>';
5943: }
5944: $datatable .= '<td class="LC_left_item>';
5945: }
5946: my $checked;
5947: if ($crsconfig{$item}) {
5948: $checked = ' checked="checked"';
5949: }
5950: $datatable .= '<span class="LC_nobreak"><label>'.
5951: '<input type="checkbox" name="proctoring_crsconf_'.$provider.'" value="'.$item.'"'.$checked.' />'.
5952: $name.'</label></span>';
5953: if ($provider eq 'examity') {
5954: $datatable .= ' ';
5955: }
5956: $datatable .= "\n";
5957: $i++;
5958: }
5959: if ($provider eq 'proctorio') {
5960: if ($numinrow) {
5961: $rem = $i%$numinrow;
5962: }
5963: my $colsleft = $numinrow - $rem;
5964: if ($colsleft > 1) {
5965: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5966: } else {
5967: $datatable .= '<td class="LC_left_item">';
5968: }
5969: $datatable .= ' '.
5970: '</td></tr></table>';
5971: }
5972: $datatable .= '</fieldset>';
5973: }
5974: if ($showroles) {
5975: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5976: '<legend>'.&mt('Role mapping').'</legend><table><tr>';
5977: foreach my $role (@courseroles) {
5978: my ($selected,$selectnone);
5979: if (!$rolemaps{$role}) {
5980: $selectnone = ' selected="selected"';
5981: }
5982: $datatable .= '<td style="text-align: center">'.
5983: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5984: '<select name="proctoring_roles_'.$role.'_'.$provider.'">'.
5985: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5986: foreach my $ltirole (@ltiroles) {
5987: unless ($selectnone) {
5988: if ($rolemaps{$role} eq $ltirole) {
5989: $selected = ' selected="selected"';
5990: } else {
5991: $selected = '';
5992: }
5993: }
5994: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
5995: }
5996: $datatable .= '</select></td>';
5997: }
5998: $datatable .= '</tr></table></fieldset>'.
5999: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
6000: '<legend>'.&mt('Custom items sent on launch').'</legend>'.
6001: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
6002: '<tr><td></td><td>lms</td>'.
6003: '<td><input type="text" name="proctoring_customval_lms_'.$provider.'"'.
6004: ' value="Loncapa" disabled="disabled"/></td></tr>';
6005: if ((ref($settings) eq 'HASH') && (ref($settings->{$provider}) eq 'HASH') &&
6006: (ref($settings->{$provider}->{'custom'}) eq 'HASH')) {
6007: my %custom = %{$settings->{$provider}->{'custom'}};
6008: if (keys(%custom) > 0) {
6009: foreach my $key (sort(keys(%custom))) {
6010: next if ($key eq 'lms');
6011: $datatable .= '<tr><td><span class="LC_nobreak">'.
6012: '<label><input type="checkbox" name="proctoring_customdel_'.$provider.'" value="'.
6013: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
6014: '<td><input type="text" name="proctoring_customval_'.$key.'_'.$provider.'"'.
6015: ' value="'.$custom{$key}.'" /></td></tr>';
6016: }
6017: }
6018: }
6019: $datatable .= '<tr><td><span class="LC_nobreak">'.
6020: '<label><input type="checkbox" name="proctoring_customadd" value="'.$provider.'" />'.
6021: &mt('Add more').'</label></span></td><td><input type="text" name="proctoring_custom_name_'.$provider.'" />'.
6022: '</td><td><input type="text" name="proctoring_custom_value_'.$provider.'" /></td></tr>'.
6023: '</table></fieldset></td></tr>'."\n";
6024: }
6025: $datatable .= '</td></tr>';
6026: }
6027: $itemcount ++;
6028: }
6029: }
6030: return $datatable;
6031: }
6032:
6033: sub proctoring_data {
6034: my $requserfields = {
6035: proctorio => ['user'],
6036: examity => ['roles','user'],
6037: };
6038: my $optuserfields = {
6039: proctorio => ['fullname'],
6040: examity => ['fullname','firstname','lastname','email'],
6041: };
6042: my $defaults = {
6043: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6044: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6045: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6046: 'closetabs','onescreen','print','downloads','cache','rightclick',
6047: 'reentry','calculator','whiteboard'],
6048: examity => ['display'],
6049: };
6050: my $extended = {
6051: proctorio => {
6052: verifyid => ['verifyidauto','verifyidlive'],
6053: fullscreen => ['fullscreenlenient','fullscreenmoderate','fullscreensever'],
6054: tabslinks => ['notabs','linksonly'],
6055: reentry => ['noreentry','agentreentry'],
6056: calculator => ['calculatorbasic','calculatorsci'],
6057: },
6058: examity => {
6059: display => {
6060: target => ['iframe','tab','window'],
6061: width => '',
6062: height => '',
6063: linktext => '',
6064: explanation => '',
6065: },
6066: },
6067: };
6068: my $crsconf = {
6069: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6070: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6071: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6072: 'closetabs','onescreen','print','downloads','cache','rightclick',
6073: 'reentry','calculator','whiteboard'],
6074: examity => ['label','title','target','linktext','explanation','append'],
6075: };
6076: my $courseroles = ['cc','in','ta','ep','st'];
6077: my $ltiroles = ['Instructor','ContentDeveloper','TeachingAssistant','Learner'];
6078: return ($requserfields,$optuserfields,$defaults,$extended,$crsconf,$courseroles,$ltiroles);
6079: }
6080:
6081: sub proctoring_titles {
6082: my ($item) = @_;
6083: my (%common_lt,%custom_lt);
6084: %common_lt = &Apache::lonlocal::texthash (
6085: 'avai' => 'Available?',
6086: 'base' => 'Basic Settings',
6087: 'requ' => 'User data required to be sent on launch',
6088: 'optu' => 'User data optionally sent on launch',
6089: 'udsl' => 'User data sent on launch',
6090: 'defa' => 'Defaults for items configurable in course',
6091: 'sigmethod' => 'Signature Method',
6092: 'key' => 'Key',
6093: 'lifetime' => 'Nonce lifetime (s)',
6094: 'secret' => 'Secret',
6095: 'icon' => 'Icon',
6096: 'fullname' => 'Full Name',
6097: 'visible' => 'Visible input',
6098: 'username' => 'username',
6099: 'user' => 'User',
6100: );
6101: if ($item eq 'proctorio') {
6102: %custom_lt = &Apache::lonlocal::texthash (
6103: 'version' => 'OAuth version',
6104: 'url' => 'API URL',
6105: 'uname:dom' => 'username-domain',
6106: );
6107: } elsif ($item eq 'examity') {
6108: %custom_lt = &Apache::lonlocal::texthash (
6109: 'version' => 'LTI Version',
6110: 'url' => 'URL',
6111: 'uname:dom' => 'username:domain',
6112: 'msgtype' => 'Message Type',
6113: 'firstname' => 'First Name',
6114: 'lastname' => 'Last Name',
6115: 'email' => 'E-mail',
6116: 'roles' => 'Role',
6117: 'crstarget' => 'Display target',
6118: 'crslabel' => 'Course label',
6119: 'crstitle' => 'Course title',
6120: 'crslinktext' => 'Link Text',
6121: 'crsexplanation' => 'Explanation',
6122: 'crsappend' => 'Provider URL',
6123: );
6124: }
6125: my %lt = (%common_lt,%custom_lt);
6126: return %lt;
6127: }
6128:
6129: sub proctoring_fieldtitles {
6130: my ($item) = @_;
6131: if ($item eq 'proctorio') {
6132: return &Apache::lonlocal::texthash (
6133: 'recordvideo' => 'Record video',
6134: 'recordaudio' => 'Record audio',
6135: 'recordscreen' => 'Record screen',
6136: 'recordwebtraffic' => 'Record web traffic',
6137: 'recordroomstart' => 'Record room scan',
6138: 'verifyvideo' => 'Verify webcam',
6139: 'verifyaudio' => 'Verify microphone',
6140: 'verifydesktop' => 'Verify desktop recording',
6141: 'verifyid' => 'Photo ID verification',
6142: 'verifysignature' => 'Require signature',
6143: 'fullscreen' => 'Fullscreen',
6144: 'clipboard' => 'Disable copy/paste',
6145: 'tabslinks' => 'New tabs/windows',
6146: 'closetabs' => 'Close other tabs',
6147: 'onescreen' => 'Limit to single screen',
6148: 'print' => 'Disable Printing',
6149: 'downloads' => 'Disable Downloads',
6150: 'cache' => 'Empty cache after exam',
6151: 'rightclick' => 'Disable right click',
6152: 'reentry' => 'Re-entry to exam',
6153: 'calculator' => 'Onscreen calculator',
6154: 'whiteboard' => 'Onscreen whiteboard',
6155: 'verifyidauto' => 'Automated verification',
6156: 'verifyidlive' => 'Live agent verification',
6157: 'fullscreenlenient' => 'Forced, but can navigate away for up to 30s',
6158: 'fullscreenmoderate' => 'Forced, but can navigate away for up to 15s',
6159: 'fullscreensever' => 'Forced, navigation away ends exam',
6160: 'notabs' => 'Disaallowed',
6161: 'linksonly' => 'Allowed from links in exam',
6162: 'noreentry' => 'Disallowed',
6163: 'agentreentry' => 'Agent required for re-entry',
6164: 'calculatorbasic' => 'Basic',
6165: 'calculatorsci' => 'Scientific',
6166: );
6167: } elsif ($item eq 'examity') {
6168: return &Apache::lonlocal::texthash (
6169: 'target' => 'Display target',
6170: 'window' => 'Window',
6171: 'tab' => 'Tab',
6172: 'iframe' => 'iFrame',
6173: 'height' => 'Height (pixels)',
6174: 'width' => 'Width (pixels)',
6175: 'linktext' => 'Default Link Text',
6176: 'explanation' => 'Default Explanation',
6177: 'append' => 'Provider URL',
6178: );
6179: }
6180: }
6181:
6182: sub proctoring_providernames {
6183: return (
6184: proctorio => 'Proctorio',
6185: examity => 'Examity',
6186: );
6187: }
6188:
1.320 raeburn 6189: sub print_lti {
1.405 raeburn 6190: my ($position,$dom,$settings,$rowtotal) = @_;
1.320 raeburn 6191: my $itemcount = 1;
1.405 raeburn 6192: my ($datatable,$css_class);
1.434 raeburn 6193: my (%rules,%encrypt,%privkeys,%linkprot,%suggestions);
1.320 raeburn 6194: if (ref($settings) eq 'HASH') {
1.405 raeburn 6195: if ($position eq 'top') {
6196: if (exists($settings->{'encrypt'})) {
6197: if (ref($settings->{'encrypt'}) eq 'HASH') {
6198: foreach my $key (keys(%{$settings->{'encrypt'}})) {
6199: if ($key eq 'consumers') {
6200: $encrypt{'ltisec_'.$key} = $settings->{'encrypt'}{$key};
6201: } else {
6202: $encrypt{'ltisec_'.$key.'linkprot'} = $settings->{'encrypt'}{$key};
6203: }
6204: }
6205: }
6206: }
6207: if (exists($settings->{'private'})) {
6208: if (ref($settings->{'private'}) eq 'HASH') {
6209: if (ref($settings->{'private'}) eq 'HASH') {
6210: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
6211: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
6212: }
6213: }
6214: }
6215: }
1.434 raeburn 6216: } elsif ($position eq 'upper') {
1.405 raeburn 6217: if (exists($settings->{'rules'})) {
6218: if (ref($settings->{'rules'}) eq 'HASH') {
6219: %rules = %{$settings->{'rules'}};
6220: }
6221: }
1.434 raeburn 6222: } elsif ($position eq 'middle') {
6223: if (exists($settings->{'suggested'})) {
6224: if (ref($settings->{'suggested'}) eq 'HASH') {
6225: %suggestions = %{$settings->{'suggested'}};
6226: }
6227: }
1.405 raeburn 6228: } elsif ($position eq 'lower') {
6229: if (exists($settings->{'linkprot'})) {
6230: if (ref($settings->{'linkprot'}) eq 'HASH') {
6231: %linkprot = %{$settings->{'linkprot'}};
1.406 raeburn 6232: if ($linkprot{'lock'}) {
6233: delete($linkprot{'lock'});
6234: }
1.405 raeburn 6235: }
6236: }
6237: } else {
1.434 raeburn 6238: foreach my $key ('encrypt','private','rules','linkprot','suggestions') {
1.405 raeburn 6239: if (exists($settings->{$key})) {
6240: delete($settings->{$key});
1.390 raeburn 6241: }
1.320 raeburn 6242: }
6243: }
6244: }
1.405 raeburn 6245: if ($position eq 'top') {
1.421 raeburn 6246: $datatable = &secrets_form($dom,'ltisec',\%encrypt,\%privkeys,$rowtotal);
1.434 raeburn 6247: } elsif ($position eq 'upper') {
6248: $datatable = &password_rules('ltisecrets',\$itemcount,\%rules);
6249: $$rowtotal += $itemcount;
1.421 raeburn 6250: } elsif ($position eq 'middle') {
1.434 raeburn 6251: $datatable = &linkprot_suggestions(\%suggestions,\$itemcount);
1.421 raeburn 6252: $$rowtotal += $itemcount;
6253: } elsif ($position eq 'lower') {
1.434 raeburn 6254: $datatable .= &Apache::courseprefs::print_linkprotection($dom,'',$settings,$rowtotal,'','','domain');
1.421 raeburn 6255: } else {
1.424 raeburn 6256: my ($switchserver,$switchmessage);
6257: $switchserver = &check_switchserver($dom);
6258: $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
1.421 raeburn 6259: my $maxnum = 0;
6260: my %ordered;
6261: if (ref($settings) eq 'HASH') {
6262: foreach my $item (keys(%{$settings})) {
6263: if (ref($settings->{$item}) eq 'HASH') {
6264: my $num = $settings->{$item}{'order'};
6265: if ($num eq '') {
6266: $num = scalar(keys(%{$settings}));
6267: }
6268: $ordered{$num} = $item;
1.405 raeburn 6269: }
1.352 raeburn 6270: }
1.405 raeburn 6271: }
6272: $maxnum = scalar(keys(%ordered));
6273: my %lt = <i_names();
6274: if (keys(%ordered)) {
6275: my @items = sort { $a <=> $b } keys(%ordered);
6276: for (my $i=0; $i<@items; $i++) {
6277: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6278: my $item = $ordered{$items[$i]};
1.424 raeburn 6279: my ($key,$secret,$usable,$lifetime,$consumer,$requser,$crsinc,$current);
1.405 raeburn 6280: if (ref($settings->{$item}) eq 'HASH') {
6281: $key = $settings->{$item}->{'key'};
1.424 raeburn 6282: $usable = $settings->{$item}->{'usable'};
1.405 raeburn 6283: $lifetime = $settings->{$item}->{'lifetime'};
6284: $consumer = $settings->{$item}->{'consumer'};
6285: $requser = $settings->{$item}->{'requser'};
6286: $crsinc = $settings->{$item}->{'crsinc'};
6287: $current = $settings->{$item};
6288: }
6289: my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
6290: my %checkedrequser = (
6291: yes => ' checked="checked"',
6292: no => '',
6293: );
6294: if (!$requser) {
6295: $checkedrequser{'no'} = $checkedrequser{'yes'};
6296: $checkedrequser{'yes'} = '';
6297: }
6298: my $onclickcrsinc = ' onclick="toggleLTI(this.form,'."'crsinc','$i'".');"';
6299: my %checkedcrsinc = (
1.391 raeburn 6300: yes => ' checked="checked"',
6301: no => '',
1.405 raeburn 6302: );
6303: if (!$crsinc) {
6304: $checkedcrsinc{'no'} = $checkedcrsinc{'yes'};
6305: $checkedcrsinc{'yes'} = '';
6306: }
6307: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
6308: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6309: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
6310: for (my $k=0; $k<=$maxnum; $k++) {
6311: my $vpos = $k+1;
6312: my $selstr;
6313: if ($k == $i) {
6314: $selstr = ' selected="selected" ';
6315: }
6316: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320 raeburn 6317: }
1.405 raeburn 6318: $datatable .= '</select>'.(' 'x2).
6319: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
6320: &mt('Delete?').'</label></span></td>'.
6321: '<td colspan="2">'.
6322: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6323: '<span class="LC_nobreak">'.$lt{'consumer'}.
6324: ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
6325: (' 'x2).
6326: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
6327: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
6328: (' 'x2).
6329: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
1.424 raeburn 6330: 'value="'.$lifetime.'" size="3" /></span><br /><br />';
6331: if ($key ne '') {
6332: $datatable .= '<span class="LC_nobreak">'.$lt{'key'};
6333: if ($switchserver) {
6334: $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
6335: } else {
6336: $datatable .= ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />';
6337: }
6338: $datatable .= '</span> '.(' 'x2);
6339: } elsif (!$switchserver) {
6340: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':'.
6341: '<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />'.
6342: '</span> '.(' 'x2);
6343: }
6344: if ($switchserver) {
6345: if ($usable ne '') {
6346: $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6347: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6348: '<span class="LC_nobreak">'.&mt('Change secret?').
6349: '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
6350: (' 'x2).
6351: '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').'</label>'.(' 'x2).
6352: '</span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
6353: '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
6354: '</div>';
6355: } elsif ($key eq '') {
6356: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6357: } else {
6358: $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
6359: }
6360: } else {
6361: if ($usable ne '') {
6362: $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6363: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6364: '<span class="LC_nobreak">'.&mt('Change?').
6365: '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
6366: (' 'x2).
6367: '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').
6368: '</label> </span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
6369: '<span class="LC_nobreak">'.&mt('New Secret').':'.
6370: '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
6371: '<label><input type="checkbox" name="lti_visible_'.$i.'" id="lti_visible_'.$i.'" onclick="if (this.checked) { this.form.lti_secret_'.$i.'.type='."'text'".' } else { this.form.lti_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label></span></div>';
6372: } else {
6373: $datatable .=
6374: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
6375: '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
6376: '<label><input type="checkbox" name="lti_visible_'.$i.'" id="lti_visible_'.$i.'" onclick="if (this.checked) { this.form.lti_secret_'.$i.'.type='."'text'".' } else { this.form.lti_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label>';
6377: }
6378: }
1.425 raeburn 6379: $datatable .= '<br /><br />'.
1.405 raeburn 6380: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6381: '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
6382: '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
6383: '<br /><br />'.
6384: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6385: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="1"'.$onclickcrsinc.$checkedcrsinc{yes}.' />'.&mt('Yes').'</label> '."\n".
6386: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="0"'.$onclickcrsinc.$checkedcrsinc{no}.' />'.&mt('No').'</label></span>'."\n".
6387: (' 'x4).
6388: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
6389: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
6390: $itemcount ++;
1.320 raeburn 6391: }
6392: }
1.405 raeburn 6393: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6394: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
6395: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6396: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
6397: '<select name="lti_pos_add"'.$chgstr.'>';
6398: for (my $k=0; $k<$maxnum+1; $k++) {
6399: my $vpos = $k+1;
6400: my $selstr;
6401: if ($k == $maxnum) {
6402: $selstr = ' selected="selected" ';
6403: }
6404: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320 raeburn 6405: }
1.405 raeburn 6406: $datatable .= '</select> '."\n".
6407: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6408: '<td colspan="2">'.
6409: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6410: '<span class="LC_nobreak">'.$lt{'consumer'}.
6411: ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
6412: (' 'x2).
6413: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
6414: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
6415: (' 'x2).
1.424 raeburn 6416: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span><br /><br />'."\n";
6417: if ($switchserver) {
6418: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6419: } else {
6420: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" autocomplete="off" /></span> '."\n".
6421: (' 'x2).
6422: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" autocomplete="new-password" />'.
6423: '<label><input type="checkbox" name="lti_add_visible" id="lti_add_visible" onclick="if (this.checked) { this.form.lti_secret_add.type='."'text'".' } else { this.form.lti_secret_add.type='."'password'".' }" />'.&mt('Visible input').'</label></span> '."\n";
6424: }
6425: $datatable .= '<br /><br />'.
1.405 raeburn 6426: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6427: '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6428: '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
6429: '<br /><br />'.
6430: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6431: '<label><input type="radio" name="lti_crsinc_add" value="1" onclick="toggleLTI(this.form,'."'crsinc','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6432: '<label><input type="radio" name="lti_crsinc_add" value="0" onclick="toggleLTI(this.form,'."'crsinc','add'".');" />'.&mt('No').'</label></span>'."\n".
6433: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
6434: '</td>'."\n".
6435: '</tr>'."\n";
6436: $itemcount ++;
1.320 raeburn 6437: }
1.405 raeburn 6438: $$rowtotal += $itemcount;
6439: return $datatable;
1.320 raeburn 6440: }
6441:
6442: sub lti_names {
6443: my %lt = &Apache::lonlocal::texthash(
6444: 'version' => 'LTI Version',
6445: 'url' => 'URL',
6446: 'key' => 'Key',
1.322 raeburn 6447: 'lifetime' => 'Nonce lifetime (s)',
1.345 raeburn 6448: 'consumer' => 'Consumer',
1.320 raeburn 6449: 'secret' => 'Secret',
1.345 raeburn 6450: 'requser' => "User's identity sent",
1.391 raeburn 6451: 'crsinc' => "Course's identity sent",
1.320 raeburn 6452: 'email' => 'Email address',
6453: 'sourcedid' => 'User ID',
6454: 'other' => 'Other',
6455: 'passback' => 'Can return grades to Consumer:',
6456: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 6457: 'topmenu' => 'Display LON-CAPA page header',
1.345 raeburn 6458: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 6459: );
6460: return %lt;
6461: }
6462:
6463: sub lti_options {
1.325 raeburn 6464: my ($num,$current,$itemcount,%lt) = @_;
1.363 raeburn 6465: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
1.320 raeburn 6466: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
6467: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
1.392 raeburn 6468: $checked{'storecrs'}{'Y'} = ' checked="checked"';
6469: $checked{'makecrs'}{'N'} = ' checked="checked"';
1.320 raeburn 6470: $checked{'mapcrstype'} = {};
6471: $checked{'makeuser'} = {};
6472: $checked{'selfenroll'} = {};
6473: $checked{'crssec'} = {};
6474: $checked{'crssecsrc'} = {};
1.325 raeburn 6475: $checked{'lcauth'} = {};
1.326 raeburn 6476: $checked{'menuitem'} = {};
1.325 raeburn 6477: if ($num eq 'add') {
6478: $checked{'lcauth'}{'lti'} = ' checked="checked"';
6479: }
1.320 raeburn 6480: my $userfieldsty = 'none';
6481: my $crsfieldsty = 'none';
6482: my $crssecfieldsty = 'none';
6483: my $secsrcfieldsty = 'none';
1.363 raeburn 6484: my $callbacksty = 'none';
1.337 raeburn 6485: my $passbacksty = 'none';
1.345 raeburn 6486: my $optionsty = 'block';
1.391 raeburn 6487: my $crssty = 'block';
1.325 raeburn 6488: my $lcauthparm;
6489: my $lcauthparmstyle = 'display:none';
6490: my $lcauthparmtext;
1.326 raeburn 6491: my $menusty;
1.325 raeburn 6492: my $numinrow = 4;
1.326 raeburn 6493: my %menutitles = <imenu_titles();
1.320 raeburn 6494:
6495: if (ref($current) eq 'HASH') {
1.345 raeburn 6496: if (!$current->{'requser'}) {
6497: $optionsty = 'none';
1.391 raeburn 6498: $crssty = 'none';
6499: } elsif (!$current->{'crsinc'}) {
6500: $crssty = 'none';
1.345 raeburn 6501: }
1.320 raeburn 6502: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
6503: $checked{'mapuser'}{'sourcedid'} = '';
6504: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
1.425 raeburn 6505: $checked{'mapuser'}{'email'} = ' checked="checked"';
1.320 raeburn 6506: } else {
6507: $checked{'mapuser'}{'other'} = ' checked="checked"';
6508: $userfield = $current->{'mapuser'};
6509: $userfieldsty = 'inline-block';
6510: }
6511: }
6512: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
6513: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
6514: if ($current->{'mapcrs'} eq 'context_id') {
1.425 raeburn 6515: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
1.320 raeburn 6516: } else {
6517: $checked{'mapcrs'}{'other'} = ' checked="checked"';
6518: $cidfield = $current->{'mapcrs'};
6519: $crsfieldsty = 'inline-block';
6520: }
6521: }
6522: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
6523: foreach my $type (@{$current->{'mapcrstype'}}) {
6524: $checked{'mapcrstype'}{$type} = ' checked="checked"';
6525: }
6526: }
1.392 raeburn 6527: if (!$current->{'storecrs'}) {
6528: $checked{'storecrs'}{'N'} = $checked{'storecrs'}{'Y'};
6529: $checked{'storecrs'}{'Y'} = '';
6530: }
1.345 raeburn 6531: if ($current->{'makecrs'}) {
1.320 raeburn 6532: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 6533: }
1.320 raeburn 6534: if (ref($current->{'makeuser'}) eq 'ARRAY') {
6535: foreach my $role (@{$current->{'makeuser'}}) {
6536: $checked{'makeuser'}{$role} = ' checked="checked"';
6537: }
6538: }
1.325 raeburn 6539: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
6540: $checked{'lcauth'}{$1} = ' checked="checked"';
6541: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
6542: $lcauthparm = $current->{'lcauthparm'};
1.425 raeburn 6543: $lcauthparmstyle = 'display:table-row';
1.325 raeburn 6544: if ($current->{'lcauth'} eq 'localauth') {
6545: $lcauthparmtext = &mt('Local auth argument');
6546: } else {
6547: $lcauthparmtext = &mt('Kerberos domain');
6548: }
6549: }
6550: }
1.320 raeburn 6551: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
6552: foreach my $role (@{$current->{'selfenroll'}}) {
6553: $checked{'selfenroll'}{$role} = ' checked="checked"';
6554: }
6555: }
6556: if (ref($current->{'maproles'}) eq 'HASH') {
6557: %rolemaps = %{$current->{'maproles'}};
6558: }
6559: if ($current->{'section'} ne '') {
1.425 raeburn 6560: $checked{'crssec'}{'Y'} = ' checked="checked"';
1.320 raeburn 6561: $crssecfieldsty = 'inline-block';
6562: if ($current->{'section'} eq 'course_section_sourcedid') {
6563: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
6564: } else {
6565: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
6566: $crssecsrc = $current->{'section'};
6567: $secsrcfieldsty = 'inline-block';
6568: }
6569: } else {
6570: $checked{'crssec'}{'N'} = ' checked="checked"';
6571: }
1.363 raeburn 6572: if ($current->{'callback'} ne '') {
6573: $callback = $current->{'callback'};
6574: $checked{'callback'}{'Y'} = ' checked="checked"';
6575: $callbacksty = 'inline-block';
6576: } else {
6577: $checked{'callback'}{'N'} = ' checked="checked"';
6578: }
1.326 raeburn 6579: if ($current->{'topmenu'}) {
6580: $checked{'topmenu'}{'Y'} = ' checked="checked"';
6581: } else {
6582: $checked{'topmenu'}{'N'} = ' checked="checked"';
6583: }
6584: if ($current->{'inlinemenu'}) {
6585: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
6586: } else {
6587: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
6588: }
6589: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
6590: $menusty = 'inline-block';
6591: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
6592: foreach my $item (@{$current->{'lcmenu'}}) {
6593: if (exists($menutitles{$item})) {
6594: $checked{'menuitem'}{$item} = ' checked="checked"';
6595: }
6596: }
6597: }
6598: } else {
6599: $menusty = 'none';
6600: }
1.320 raeburn 6601: } else {
6602: $checked{'makecrs'}{'N'} = ' checked="checked"';
6603: $checked{'crssec'}{'N'} = ' checked="checked"';
1.363 raeburn 6604: $checked{'callback'}{'N'} = ' checked="checked"';
1.326 raeburn 6605: $checked{'topmenu'}{'N'} = ' checked="checked"';
1.425 raeburn 6606: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
1.326 raeburn 6607: $checked{'menuitem'}{'grades'} = ' checked="checked"';
1.425 raeburn 6608: $menusty = 'inline-block';
1.320 raeburn 6609: }
1.325 raeburn 6610: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 6611: my %coursetypetitles = &Apache::lonlocal::texthash (
6612: official => 'Official',
6613: unofficial => 'Unofficial',
6614: community => 'Community',
6615: textbook => 'Textbook',
6616: placement => 'Placement Test',
1.325 raeburn 6617: lti => 'LTI Provider',
1.320 raeburn 6618: );
1.325 raeburn 6619: my @authtypes = ('internal','krb4','krb5','localauth');
6620: my %shortauth = (
6621: internal => 'int',
6622: krb4 => 'krb4',
6623: krb5 => 'krb5',
6624: localauth => 'loc'
6625: );
6626: my %authnames = &authtype_names();
1.320 raeburn 6627: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
6628: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
6629: my @courseroles = ('cc','in','ta','ep','st');
6630: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
6631: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
6632: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
1.363 raeburn 6633: my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
1.320 raeburn 6634: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 6635: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 6636: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.391 raeburn 6637: my $output = '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Logout options').'</legend>'.
1.392 raeburn 6638: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback to logout LON-CAPA on log out from Consumer').': '.
1.391 raeburn 6639: '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
6640: $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.(' 'x2).
6641: '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
6642: $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
6643: '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
6644: '<span class="LC_nobreak">'.&mt('Parameter').': '.
6645: '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
6646: '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
6647: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320 raeburn 6648: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
6649: foreach my $option ('sourcedid','email','other') {
6650: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
6651: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
6652: ($option eq 'other' ? '' : (' 'x2) );
6653: }
6654: $output .= '</span></div>'.
6655: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
6656: '<input type="text" name="lti_customuser_'.$num.'" '.
1.372 raeburn 6657: 'value="'.$userfield.'" /></div></fieldset>'.
1.391 raeburn 6658: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320 raeburn 6659: foreach my $ltirole (@ltiroles) {
6660: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
1.425 raeburn 6661: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
1.320 raeburn 6662: }
6663: $output .= '</fieldset>'.
1.391 raeburn 6664: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325 raeburn 6665: '<table>'.
6666: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
6667: '</table>'.
6668: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
6669: '<td class="LC_left_item">';
6670: foreach my $auth ('lti',@authtypes) {
6671: my $authtext;
6672: if ($auth eq 'lti') {
6673: $authtext = &mt('None');
6674: } else {
6675: $authtext = $authnames{$shortauth{$auth}};
6676: }
6677: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
6678: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
6679: $authtext.'</label></span> ';
6680: }
6681: $output .= '</td></tr>'.
6682: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
6683: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
6684: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
6685: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
6686: '</table></fieldset>'.
1.391 raeburn 6687: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.
6688: &mt('LON-CAPA menu items (Course Coordinator can override)').'</legend>'.
6689: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
6690: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
6691: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6692: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
6693: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
6694: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6695: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
6696: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
6697: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6698: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
6699: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
6700: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6701: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
6702: '<span class="LC_nobreak">'.&mt('Menu items').': ';
6703: foreach my $type ('fullname','coursetitle','role','logout','grades') {
6704: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
6705: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
6706: (' 'x2);
6707: }
6708: $output .= '</span></div></fieldset>'.
6709: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320 raeburn 6710: '<div class="LC_floatleft"><span class="LC_nobreak">'.
6711: &mt('Unique course identifier').': ';
6712: foreach my $option ('course_offering_sourcedid','context_id','other') {
6713: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
6714: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
6715: ($option eq 'other' ? '' : (' 'x2) );
6716: }
1.334 raeburn 6717: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320 raeburn 6718: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
6719: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
6720: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
6721: foreach my $type (@coursetypes) {
6722: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
6723: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
6724: (' 'x2);
6725: }
1.392 raeburn 6726: $output .= '</span><br /><br />'.
6727: '<span class="LC_nobreak">'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.
6728: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="0"'.
6729: $checked{'storecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6730: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="1"'.
6731: $checked{'storecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6732: '</fieldset>'.
1.391 raeburn 6733: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
6734: foreach my $ltirole (@lticourseroles) {
6735: my ($selected,$selectnone);
6736: if ($rolemaps{$ltirole} eq '') {
6737: $selectnone = ' selected="selected"';
6738: }
6739: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
6740: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
6741: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
6742: foreach my $role (@courseroles) {
6743: unless ($selectnone) {
6744: if ($rolemaps{$ltirole} eq $role) {
6745: $selected = ' selected="selected"';
6746: } else {
6747: $selected = '';
6748: }
6749: }
6750: $output .= '<option value="'.$role.'"'.$selected.'>'.
6751: &Apache::lonnet::plaintext($role,'Course').
6752: '</option>';
6753: }
6754: $output .= '</select></td>';
6755: }
6756: $output .= '</tr></table></fieldset>'.
6757: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320 raeburn 6758: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
6759: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
6760: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6761: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
6762: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6763: '</fieldset>'.
1.391 raeburn 6764: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320 raeburn 6765: foreach my $lticrsrole (@lticourseroles) {
6766: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
6767: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
6768: }
6769: $output .= '</fieldset>'.
1.391 raeburn 6770: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Course options').'</legend>'.
1.320 raeburn 6771: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
6772: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
6773: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
6774: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334 raeburn 6775: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320 raeburn 6776: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
6777: '<span class="LC_nobreak">'.&mt('From').':<label>'.
6778: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
6779: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
6780: &mt('Standard field').'</label>'.(' 'x2).
6781: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
6782: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334 raeburn 6783: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320 raeburn 6784: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337 raeburn 6785: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6786: my ($pb1p1chk,$pb1p0chk,$onclickpb);
6787: foreach my $extra ('roster','passback') {
1.320 raeburn 6788: my $checkedon = '';
6789: my $checkedoff = ' checked="checked"';
1.337 raeburn 6790: if ($extra eq 'passback') {
6791: $pb1p1chk = ' checked="checked"';
6792: $pb1p0chk = '';
1.425 raeburn 6793: $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
1.337 raeburn 6794: } else {
1.425 raeburn 6795: $onclickpb = '';
1.337 raeburn 6796: }
1.320 raeburn 6797: if (ref($current) eq 'HASH') {
6798: if (($current->{$extra})) {
6799: $checkedon = $checkedoff;
6800: $checkedoff = '';
1.337 raeburn 6801: if ($extra eq 'passback') {
6802: $passbacksty = 'inline-block';
6803: }
6804: if ($current->{'passbackformat'} eq '1.0') {
6805: $pb1p0chk = ' checked="checked"';
6806: $pb1p1chk = '';
6807: }
1.320 raeburn 6808: }
6809: }
6810: $output .= $lt{$extra}.' '.
1.337 raeburn 6811: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320 raeburn 6812: &mt('No').'</label>'.(' 'x2).
1.339 raeburn 6813: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320 raeburn 6814: &mt('Yes').'</label><br />';
6815: }
1.337 raeburn 6816: $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
6817: '<span class="LC_nobreak">'.&mt('Grade format').
6818: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
6819: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
6820: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
1.363 raeburn 6821: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
1.391 raeburn 6822: '<div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>';
1.334 raeburn 6823: $output .= '</span></div></fieldset>';
1.320 raeburn 6824: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
6825: #
6826: # $output .= '</fieldset>'.
6827: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
6828: return $output;
6829: }
6830:
1.326 raeburn 6831: sub ltimenu_titles {
6832: return &Apache::lonlocal::texthash(
6833: fullname => 'Full name',
6834: coursetitle => 'Course title',
6835: role => 'Role',
6836: logout => 'Logout',
6837: grades => 'Grades',
6838: );
6839: }
6840:
1.434 raeburn 6841: sub linkprot_suggestions {
6842: my ($suggested,$itemcount) = @_;
6843: my $count = 0;
6844: my $next = 1;
6845: my %lt = &Apache::lonlocal::texthash(
6846: 'name' => 'Suggested Launcher',
6847: 'info' => 'Recommendations',
6848: );
6849: my ($datatable,$css_class,$dest);
6850: if (ref($suggested) eq 'HASH') {
6851: my @current = sort { $a <=> $b } keys(%{$suggested});
6852: $next += $current[-1];
6853: for (my $i=0; $i<@current; $i++) {
6854: my $num = $current[$i];
6855: my %values;
6856: if (ref($suggested->{$num}) eq 'HASH') {
6857: %values = %{$suggested->{$num}};
6858: } else {
6859: next;
6860: }
6861: $css_class = $$itemcount%2?' class="LC_odd_row"':'';
6862: $datatable .=
6863: '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6864: '<label><input type="checkbox" name="linkprot_suggested_del" value="'.$i.'" />'."\n".
6865: &mt('Delete?').'</label></span></td><td>'."\n".
6866: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'name'}.'</legend>'."\n".
6867: '<input type="text" size="15" name="linkprot_suggested_name_'.$i.'" value="'.$values{'name'}.'" autocomplete="off" />'."\n".
6868: '</fieldset></div>'.
6869: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'info'}.'</legend>'."\n".
6870: '<textarea cols="55" rows="5" name="linkprot_suggested_info_'.$i.'">'.$values{'info'}.'</textarea>'.
6871: '</fieldset></div>'.
6872: '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
6873: '<input type="hidden" name="linkprot_suggested_id_'.$i.'" value="'.$num.'" /></td></tr>'."\n";
6874: $$itemcount ++;
6875: }
6876: }
6877: $css_class = $$itemcount%2?' class="LC_odd_row"':'';
6878: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6879: '<input type="hidden" name="linkprot_suggested_maxnum" value="'.$next.'" />'."\n".
6880: '<input type="checkbox" name="linkprot_suggested_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6881: '<td>'."\n".
6882: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'name'}.'</legend>'."\n".
6883: '<input type="text" size="15" name="linkprot_suggested_name_add" value="" autocomplete="off" />'."\n".
6884: '</fieldset></div>'.
6885: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'info'}.'</legend>'."\n".
6886: '<textarea cols="55" rows="5" name="linkprot_suggested_info_add"></textarea>'.
6887: '</fieldset></div>'.
6888: '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
6889: '</td></tr>'."\n";
6890: return $datatable;
6891: }
6892:
1.121 raeburn 6893: sub print_coursedefaults {
1.139 raeburn 6894: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 6895: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 6896: my $itemcount = 1;
1.192 raeburn 6897: my %choices = &Apache::lonlocal::texthash (
6898: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 6899: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.432 raeburn 6900: coursequota => 'Default cumulative quota for all group portfolio spaces in course (MB)',
1.192 raeburn 6901: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
6902: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 6903: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
6904: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.398 raeburn 6905: inline_chem => 'Use inline previewer for chemical reaction response in place of pop-up',
1.314 raeburn 6906: texengine => 'Default method to display mathematics',
1.257 raeburn 6907: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 6908: canclone => "People who may clone a course (besides course's owner and coordinators)",
6909: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.405 raeburn 6910: ltiauth => 'Student username in LTI launch of deep-linked URL can be accepted without re-authentication',
1.422 raeburn 6911: domexttool => 'External Tools defined in the domain may be used in courses/communities (by type)',
6912: exttool => 'External Tools can be defined and configured in courses/communities (by type)',
1.432 raeburn 6913: crsauthor => 'Standard LON-CAPA problems can be created within a course/community (by type)',
1.438 raeburn 6914: crseditors => 'Available editors for web pages and/or problems created in a course/community',
1.192 raeburn 6915: );
1.198 raeburn 6916: my %staticdefaults = (
6917: anonsurvey_threshold => 10,
6918: uploadquota => 500,
1.428 raeburn 6919: coursequota => 20,
1.257 raeburn 6920: postsubmit => 60,
1.276 raeburn 6921: mysqltables => 172800,
1.422 raeburn 6922: domexttool => 1,
6923: exttool => 0,
1.432 raeburn 6924: crsauthor => 1,
1.438 raeburn 6925: crseditors => ['edit','xml'],
1.198 raeburn 6926: );
1.139 raeburn 6927: if ($position eq 'top') {
1.257 raeburn 6928: %defaultchecked = (
6929: 'canuse_pdfforms' => 'off',
6930: 'uselcmath' => 'on',
6931: 'usejsme' => 'on',
1.398 raeburn 6932: 'inline_chem' => 'on',
1.289 raeburn 6933: 'canclone' => 'none',
1.257 raeburn 6934: );
1.398 raeburn 6935: @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem');
1.349 raeburn 6936: my $deftex = $Apache::lonnet::deftex;
1.314 raeburn 6937: if (ref($settings) eq 'HASH') {
6938: if ($settings->{'texengine'}) {
6939: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
6940: $deftex = $settings->{'texengine'};
6941: }
6942: }
6943: }
6944: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6945: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
6946: '<span class="LC_nobreak">'.$choices{'texengine'}.
6947: '</span></td><td class="LC_right_item">'.
6948: '<select name="texengine">'."\n";
6949: my %texoptions = (
6950: MathJax => 'MathJax',
6951: mimetex => &mt('Convert to Images'),
6952: tth => &mt('TeX to HTML'),
6953: );
6954: foreach my $renderer ('MathJax','mimetex','tth') {
6955: my $selected = '';
6956: if ($renderer eq $deftex) {
6957: $selected = ' selected="selected"';
6958: }
6959: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
6960: }
6961: $mathdisp .= '</select></td></tr>'."\n";
6962: $itemcount ++;
1.139 raeburn 6963: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 6964: \%choices,$itemcount);
1.314 raeburn 6965: $datatable = $mathdisp.$datatable;
1.264 raeburn 6966: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6967: $datatable .=
1.306 raeburn 6968: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 6969: '<span class="LC_nobreak">'.$choices{'canclone'}.
6970: '</span></td><td class="LC_left_item">';
6971: my $currcanclone = 'none';
6972: my $onclick;
6973: my @cloneoptions = ('none','domain');
1.380 raeburn 6974: my %clonetitles = &Apache::lonlocal::texthash (
1.264 raeburn 6975: none => 'No additional course requesters',
6976: domain => "Any course requester in course's domain",
6977: instcode => 'Course requests for official courses ...',
6978: );
6979: my (%codedefaults,@code_order,@posscodes);
6980: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
6981: \@code_order) eq 'ok') {
6982: if (@code_order > 0) {
6983: push(@cloneoptions,'instcode');
6984: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
6985: }
6986: }
6987: if (ref($settings) eq 'HASH') {
6988: if ($settings->{'canclone'}) {
6989: if (ref($settings->{'canclone'}) eq 'HASH') {
6990: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
6991: if (@code_order > 0) {
6992: $currcanclone = 'instcode';
6993: @posscodes = @{$settings->{'canclone'}{'instcode'}};
6994: }
6995: }
6996: } elsif ($settings->{'canclone'} eq 'domain') {
6997: $currcanclone = $settings->{'canclone'};
6998: }
6999: }
1.289 raeburn 7000: }
1.264 raeburn 7001: foreach my $option (@cloneoptions) {
7002: my ($checked,$additional);
7003: if ($currcanclone eq $option) {
7004: $checked = ' checked="checked"';
7005: }
7006: if ($option eq 'instcode') {
7007: if (@code_order) {
7008: my $show = 'none';
7009: if ($checked) {
7010: $show = 'block';
7011: }
1.317 raeburn 7012: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 7013: &mt('Institutional codes for new and cloned course have identical:').
7014: '<br />';
7015: foreach my $item (@code_order) {
7016: my $codechk;
7017: if ($checked) {
7018: if (grep(/^\Q$item\E$/,@posscodes)) {
7019: $codechk = ' checked="checked"';
7020: }
7021: }
7022: $additional .= '<label>'.
7023: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
7024: $item.'</label>';
7025: }
7026: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
7027: }
7028: }
7029: $datatable .=
7030: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
7031: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
7032: '</label> '.$additional.'</span><br />';
7033: }
7034: $datatable .= '</td>'.
7035: '</tr>';
7036: $itemcount ++;
1.139 raeburn 7037: } else {
7038: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.428 raeburn 7039: my ($currdefresponder,%defcredits,%curruploadquota,%currcoursequota,
7040: %deftimeout,%currmysql);
1.192 raeburn 7041: my $currusecredits = 0;
1.257 raeburn 7042: my $postsubmitclient = 1;
1.405 raeburn 7043: my $ltiauth = 0;
1.422 raeburn 7044: my %domexttool;
7045: my %exttool;
1.432 raeburn 7046: my %crsauthor;
1.438 raeburn 7047: my %crseditors;
1.271 raeburn 7048: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 7049: if (ref($settings) eq 'HASH') {
1.404 raeburn 7050: if ($settings->{'ltiauth'}) {
7051: $ltiauth = 1;
1.405 raeburn 7052: }
1.422 raeburn 7053: if (ref($settings->{'domexttool'}) eq 'HASH') {
7054: foreach my $type (@types) {
7055: if ($settings->{'domexttool'}->{$type}) {
7056: $domexttool{$type} = ' checked="checked"';
7057: }
7058: }
7059: } else {
7060: foreach my $type (@types) {
7061: if ($staticdefaults{'domexttool'}) {
7062: $domexttool{$type} = ' checked="checked"';
7063: }
7064: }
7065: }
7066: if (ref($settings->{'exttool'}) eq 'HASH') {
7067: foreach my $type (@types) {
7068: if ($settings->{'exttool'}->{$type}) {
7069: $exttool{$type} = ' checked="checked"';
7070: }
7071: }
7072: }
1.432 raeburn 7073: if (ref($settings->{'crsauthor'}) eq 'HASH') {
7074: foreach my $type (@types) {
7075: if ($settings->{'crsauthor'}->{$type}) {
7076: $crsauthor{$type} = ' checked="checked"';
7077: }
7078: }
7079: } else {
7080: foreach my $type (@types) {
7081: if ($staticdefaults{'crsauthor'}) {
7082: $crsauthor{$type} = ' checked="checked"';
7083: }
7084: }
7085: }
1.438 raeburn 7086: if (ref($settings->{'crseditors'}) eq 'ARRAY') {
7087: foreach my $editor (@{$settings->{'crseditors'}}) {
7088: $crseditors{$editor} = ' checked="checked"';
7089: }
7090: } else {
7091: foreach my $editor (@{$staticdefaults{'crseditors'}}) {
7092: $crseditors{$editor} = ' checked="checked"';
7093: }
7094: }
1.139 raeburn 7095: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 7096: if (ref($settings->{'uploadquota'}) eq 'HASH') {
7097: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
7098: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
7099: }
7100: }
1.428 raeburn 7101: if (ref($settings->{'coursequota'}) eq 'HASH') {
7102: foreach my $type (keys(%{$settings->{'coursequota'}})) {
7103: $currcoursequota{$type} = $settings->{'coursequota'}{$type};
7104: }
7105: }
1.192 raeburn 7106: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 7107: foreach my $type (@types) {
7108: next if ($type eq 'community');
7109: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
7110: if ($defcredits{$type} ne '') {
7111: $currusecredits = 1;
7112: }
7113: }
7114: }
7115: if (ref($settings->{'postsubmit'}) eq 'HASH') {
7116: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
7117: $postsubmitclient = 0;
7118: foreach my $type (@types) {
7119: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7120: }
7121: } else {
7122: foreach my $type (@types) {
7123: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
7124: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 7125: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 7126: } else {
7127: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7128: }
7129: } else {
7130: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7131: }
7132: }
7133: }
7134: } else {
7135: foreach my $type (@types) {
7136: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 7137: }
7138: }
1.276 raeburn 7139: if (ref($settings->{'mysqltables'}) eq 'HASH') {
7140: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
7141: $currmysql{$type} = $settings->{'mysqltables'}{$type};
7142: }
7143: } else {
7144: foreach my $type (@types) {
7145: $currmysql{$type} = $staticdefaults{'mysqltables'};
7146: }
7147: }
1.258 raeburn 7148: } else {
7149: foreach my $type (@types) {
7150: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.422 raeburn 7151: if ($staticdefaults{'domexttool'}) {
7152: $domexttool{$type} = ' checked="checked"';
7153: }
1.432 raeburn 7154: if ($staticdefaults{'crsauthor'}) {
7155: $crsauthor{$type} = ' checked="checked"';
7156: }
1.258 raeburn 7157: }
1.438 raeburn 7158: foreach my $editor (@{$staticdefaults{'crseditors'}}) {
7159: $crseditors{$editor} = ' checked="checked"';
7160: }
1.139 raeburn 7161: }
7162: if (!$currdefresponder) {
1.198 raeburn 7163: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 7164: } elsif ($currdefresponder < 1) {
7165: $currdefresponder = 1;
7166: }
1.198 raeburn 7167: foreach my $type (@types) {
7168: if ($curruploadquota{$type} eq '') {
7169: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
7170: }
1.428 raeburn 7171: if ($currcoursequota{$type} eq '') {
7172: $currcoursequota{$type} = $staticdefaults{'coursequota'};
7173: }
1.198 raeburn 7174: }
1.139 raeburn 7175: $datatable .=
1.192 raeburn 7176: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7177: $choices{'anonsurvey_threshold'}.
1.139 raeburn 7178: '</span></td>'.
7179: '<td class="LC_right_item"><span class="LC_nobreak">'.
7180: '<input type="text" name="anonsurvey_threshold"'.
7181: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 7182: '</td></tr>'."\n";
7183: $itemcount ++;
7184: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7185: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7186: $choices{'uploadquota'}.
7187: '</span></td>'.
1.306 raeburn 7188: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 7189: '<table><tr>';
1.198 raeburn 7190: foreach my $type (@types) {
1.306 raeburn 7191: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 7192: '<input type="text" name="uploadquota_'.$type.'"'.
7193: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
7194: }
7195: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 7196: $itemcount ++;
1.428 raeburn 7197: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7198: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7199: $choices{'coursequota'}.
7200: '</span></td>'.
7201: '<td style="text-align: right" class="LC_right_item">'.
7202: '<table><tr>';
7203: foreach my $type (@types) {
7204: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
7205: '<input type="text" name="coursequota_'.$type.'"'.
7206: ' value="'.$currcoursequota{$type}.'" size="5" /></td>';
7207: }
7208: $datatable .= '</tr></table></td></tr>'."\n";
7209: $itemcount ++;
1.236 raeburn 7210: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 7211: my $display = 'none';
1.192 raeburn 7212: if ($currusecredits) {
7213: $display = 'block';
7214: }
7215: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 7216: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
7217: foreach my $type (@types) {
7218: next if ($type eq 'community');
1.306 raeburn 7219: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7220: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 7221: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 7222: }
7223: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 7224: %defaultchecked = ('coursecredits' => 'off');
7225: @toggles = ('coursecredits');
7226: my $current = {
7227: 'coursecredits' => $currusecredits,
7228: };
7229: (my $table,$itemcount) =
7230: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 7231: \%choices,$itemcount,$onclick,$additional,'left');
7232: $datatable .= $table;
7233: $onclick = "toggleDisplay(this.form,'studentsubmission');";
7234: my $display = 'none';
7235: if ($postsubmitclient) {
7236: $display = 'block';
7237: }
7238: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 7239: &mt('Number of seconds submit is disabled').'<br />'.
7240: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
7241: '<table><tr>';
1.257 raeburn 7242: foreach my $type (@types) {
1.306 raeburn 7243: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7244: '<input type="text" name="'.$type.'_timeout" value="'.
7245: $deftimeout{$type}.'" size="5" /></td>';
7246: }
7247: $additional .= '</tr></table></div>'."\n";
7248: %defaultchecked = ('postsubmit' => 'on');
7249: @toggles = ('postsubmit');
1.280 raeburn 7250: $current = {
7251: 'postsubmit' => $postsubmitclient,
7252: };
1.257 raeburn 7253: ($table,$itemcount) =
7254: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7255: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 7256: $datatable .= $table;
1.276 raeburn 7257: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7258: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7259: $choices{'mysqltables'}.
7260: '</span></td>'.
1.306 raeburn 7261: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 7262: '<table><tr>';
7263: foreach my $type (@types) {
1.306 raeburn 7264: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 7265: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 7266: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 7267: }
7268: $datatable .= '</tr></table></td></tr>'."\n";
7269: $itemcount ++;
1.404 raeburn 7270: %defaultchecked = ('ltiauth' => 'off');
7271: @toggles = ('ltiauth');
7272: $current = {
7273: 'ltiauth' => $ltiauth,
7274: };
7275: ($table,$itemcount) =
7276: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7277: \%choices,$itemcount,undef,undef,'left');
7278: $datatable .= $table;
1.422 raeburn 7279: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7280: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7281: $choices{'domexttool'}.
7282: '</span></td>'.
7283: '<td style="text-align: right" class="LC_right_item">'.
7284: '<table><tr>';
7285: foreach my $type (@types) {
7286: $datatable .= '<td style="text-align: left">'.
7287: '<span class="LC_nobreak">'.
1.438 raeburn 7288: '<label><input type="checkbox" name="domexttool"'.
1.422 raeburn 7289: ' value="'.$type.'"'.$domexttool{$type}.' />'.
1.438 raeburn 7290: &mt($type).'</label></span></td>'."\n";
1.422 raeburn 7291: }
7292: $datatable .= '</tr></table></td></tr>'."\n";
1.404 raeburn 7293: $itemcount ++;
1.422 raeburn 7294: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7295: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7296: $choices{'exttool'}.
7297: '</span></td>'.
7298: '<td style="text-align: right" class="LC_right_item">'.
7299: '<table><tr>';
7300: foreach my $type (@types) {
7301: $datatable .= '<td style="text-align: left">'.
7302: '<span class="LC_nobreak">'.
1.438 raeburn 7303: '<label><input type="checkbox" name="exttool"'.
1.422 raeburn 7304: ' value="'.$type.'"'.$exttool{$type}.' />'.
1.438 raeburn 7305: &mt($type).'</label></span></td>'."\n";
1.422 raeburn 7306: }
7307: $datatable .= '</tr></table></td></tr>'."\n";
1.432 raeburn 7308: $itemcount ++;
7309: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7310: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7311: $choices{'crsauthor'}.
7312: '</span></td>'.
7313: '<td style="text-align: right" class="LC_right_item">'.
7314: '<table><tr>';
7315: foreach my $type (@types) {
7316: $datatable .= '<td style="text-align: left">'.
7317: '<span class="LC_nobreak">'.
1.438 raeburn 7318: '<label><input type="checkbox" name="crsauthor"'.
1.432 raeburn 7319: ' value="'.$type.'"'.$crsauthor{$type}.' />'.
1.438 raeburn 7320: &mt($type).'</label></span></td>'."\n";
7321: }
7322: $datatable .= '</tr></table></td></tr>'."\n";
7323: $itemcount ++;
7324: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7325: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7326: $choices{'crseditors'}.
7327: '</span></td>'.
7328: '<td style="text-align: right" class="LC_right_item">'.
7329: '<table><tr>';
7330: my @editors = ('edit','xml','daxe');
7331: my %editornames = &crseditor_titles();
7332: foreach my $editor (@editors) {
7333: $datatable .= '<td style="text-align: left">'.
7334: '<span class="LC_nobreak">'.
7335: '<label><input type="checkbox" name="crseditors"'.
7336: ' value="'.$editor.'"'.$crseditors{$editor}.' />'.
7337: $editornames{$editor}.'</label></span></td>'."\n";
1.432 raeburn 7338: }
7339: $datatable .= '</tr></table></td></tr>'."\n";
1.139 raeburn 7340: }
1.192 raeburn 7341: $$rowtotal += $itemcount;
1.121 raeburn 7342: return $datatable;
1.118 jms 7343: }
7344:
1.438 raeburn 7345: sub crseditor_titles {
7346: return &Apache::lonlocal::texthash(
7347: edit => 'Standard editor (Edit)',
7348: xml => 'Text editor (EditXML)',
7349: daxe => 'Daxe editor (Daxe)',
7350: );
7351: }
7352:
1.429 raeburn 7353: sub print_authordefaults {
7354: my ($position,$dom,$settings,$rowtotal) = @_;
7355: my ($css_class,$datatable,%checkedon,%checkedoff);
7356: my $itemcount = 1;
7357: my %titles = &authordefaults_titles();
7358: if ($position eq 'top') {
7359: my %defaultchecked = (
7360: 'nocodemirror' => 'off',
1.437 raeburn 7361: 'daxecollapse' => 'off',
1.429 raeburn 7362: 'domcoordacc' => 'on',
7363: );
1.437 raeburn 7364: my @toggles = ('nocodemirror','daxecollapse','domcoordacc');
1.429 raeburn 7365: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
7366: \%titles,$itemcount);
7367: my %staticdefaults = (
7368: 'copyright' => 'default',
7369: 'sourceavail' => 'closed',
7370: );
7371: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7372: my %currrights;
7373: foreach my $item ('copyright','sourceavail') {
7374: $currrights{$item} = $staticdefaults{$item};
7375: if (ref($settings) eq 'HASH') {
7376: if (exists($settings->{$item})) {
7377: $currrights{$item} = $settings->{$item};
7378: }
7379: }
7380: }
7381: $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
7382: '<span class="LC_nobreak">'.$titles{'copyright'}.
7383: '</span></td><td class="LC_right_item">'.
7384: &selectbox('copyright',$currrights{'copyright'},'',
7385: \&Apache::loncommon::copyrightdescription,
7386: (grep !/^priv|custom$/,(&Apache::loncommon::copyrightids))).
7387: '</td></tr>'."\n";
7388: $itemcount ++;
7389: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7390: $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
7391: '<span class="LC_nobreak">'.$titles{'sourceavail'}.
7392: '</span></td><td class="LC_right_item">'.
7393: &selectbox('sourceavail',$currrights{'sourceavail'},'',
7394: \&Apache::loncommon::source_copyrightdescription,
7395: (&Apache::loncommon::source_copyrightids)).
7396: '</td></tr>'."\n";
7397: } else {
7398: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7399: my $curreditors;
7400: my %staticdefaults = (
7401: editors => ['edit','xml'],
7402: authorquota => 500,
7403: webdav => 0,
7404: );
7405: my $curreditors = $staticdefaults{'editors'};
7406: if ((ref($settings) eq 'HASH') &&
7407: (ref($settings->{'editors'}) eq 'ARRAY')) {
7408: $curreditors = $settings->{'editors'};
7409: } else {
7410: $curreditors = $staticdefaults{'editors'};
7411: }
7412: my @editors = ('edit','xml','daxe');
7413: $datatable = '<tr'.$css_class.'>'."\n".
7414: '<td>'.$titles{'editors'}.'</td>'."\n".
7415: '<td class="LC_left_item">'."\n".
7416: '<span class="LC_nobreak">';
7417: foreach my $editor (@editors) {
7418: my $checked;
7419: if (grep(/^\Q$editor\E$/,@{$curreditors})) {
7420: $checked = ' checked="checked"';
7421: }
7422: $datatable .= '<label>'.
7423: '<input type="checkbox" name="author_editors" '.
7424: $checked.' value="'.$editor.'" '.
7425: 'onclick="javascript:checkEditors(this.form,'."'author_editors'".',this);" />'.
7426: $titles{$editor}.'</label> ';
7427: }
7428: $datatable .= '</span>'."\n".'</td>'."\n".'</tr>'."\n";
7429: $itemcount ++;
7430: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7431: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7432: my @insttypes;
7433: if (ref($types) eq 'ARRAY') {
7434: @insttypes = @{$types};
7435: }
7436: my $typecount = 0;
7437: my %domconf = &Apache::lonnet::get_dom('configuration',['quotas'],$dom);
7438: my @items = ('webdav','authorquota');
7439: my %quotas;
7440: if (ref($domconf{'quotas'}) eq 'HASH') {
7441: %quotas = %{$domconf{'quotas'}};
7442: foreach my $item (@items) {
7443: if (ref($quotas{$item}) eq 'HASH') {
7444: foreach my $type (@insttypes,'default') {
7445: if ($item eq 'authorquota') {
7446: if ($quotas{$item}{$type} !~ /^\d+$/) {
7447: $quotas{$item}{$type} = $staticdefaults{$item};
7448: }
7449: } elsif ($item eq 'webdav') {
7450: if ($quotas{$item}{$type} !~ /^(0|1)$/) {
7451: $quotas{$item}{$type} = $staticdefaults{$item};
7452: }
7453: }
7454: }
7455: } else {
7456: foreach my $type (@insttypes,'default') {
7457: $quotas{$item}{$type} = $staticdefaults{$item};
7458: }
7459: }
7460: }
7461: } else {
7462: foreach my $item (@items) {
7463: foreach my $type (@insttypes,'default') {
7464: $quotas{$item}{$type} = $staticdefaults{$item};
7465: }
7466: }
7467: }
7468: if (ref($usertypes) eq 'HASH') {
7469: my $numinrow = 4;
7470: my $onclick = '';
7471: $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
7472: $numinrow,$othertitle,'authorquota',
7473: \$itemcount,$onclick);
7474: $itemcount ++;
7475: $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
7476: $numinrow,$othertitle,'webdav',
7477: \$itemcount);
7478: $itemcount ++;
7479: }
7480: my $checkedno = ' checked="checked"';
7481: my ($checkedon,$checkedoff);
7482: if (ref($quotas{'webdav'}) eq 'HASH') {
1.436 raeburn 7483: if ($quotas{'webdav'}{'_LC_adv'} =~ /^0|1$/) {
1.429 raeburn 7484: if ($quotas{'webdav'}{'_LC_adv'}) {
7485: $checkedon = $checkedno;
7486: } else {
7487: $checkedoff = $checkedno;
7488: }
7489: undef($checkedno);
7490: }
7491: }
7492: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7493: $datatable .= '<tr'.$css_class.'>'.
7494: '<td>'.$titles{'webdav_LC_adv'}.'<br />'.
7495: $titles{'webdav_LC_adv_over'}.
7496: '</td>'.
7497: '<td class="LC_left_item">';
7498: foreach my $option ('none','off','on') {
7499: my ($text,$val,$checked);
7500: if ($option eq 'none') {
7501: $text = $titles{'none'};
7502: $val = '';
7503: $checked = $checkedno;
7504: } elsif ($option eq 'off') {
7505: $text = $titles{'overoff'};
7506: $val = 0;
7507: $checked = $checkedoff;
7508: } elsif ($option eq 'on') {
7509: $text = $titles{'overon'};
7510: $val = 1;
7511: $checked = $checkedon;
1.436 raeburn 7512: }
1.429 raeburn 7513: $datatable .= '<span class="LC_nobreak"><label>'.
7514: '<input type="radio" name="webdav_LC_adv"'.
7515: ' value="'.$val.'"'.$checked.' />'.
7516: $text.'</label></span> ';
7517: }
7518: $datatable .= '</td></tr>';
7519: $itemcount ++;
1.440 raeburn 7520: my %defchecked = (
7521: 'archive' => 'off',
7522: );
7523: my @toggles = ('archive');
7524: (my $archive,$itemcount) = &radiobutton_prefs($settings,['archive'],
7525: {'archive' => 'off'},
7526: \%titles,$itemcount);
7527: $datatable .= $archive."\n";
7528: $itemcount ++;
1.429 raeburn 7529: }
7530: $$rowtotal += $itemcount;
7531: return $datatable;
7532: }
7533:
7534: sub authordefaults_titles {
7535: return &Apache::lonlocal::texthash(
7536: copyright => 'Copyright/Distribution',
7537: sourceavail => ' Source Available',
7538: editors => 'Available Editors',
7539: webdav => 'WebDAV',
7540: authorquota => 'Authoring Space quotas (MB)',
7541: nocodemirror => 'Deactivate CodeMirror for EditXML editor',
1.437 raeburn 7542: daxecollapse => 'Daxe editor: LON-CAPA standard menus start collapsed',
1.429 raeburn 7543: domcoordacc => 'Dom. Coords. can enter Authoring Spaces in domain',
7544: edit => 'Standard editor (Edit)',
7545: xml => 'Text editor (EditXML)',
7546: daxe => 'Daxe editor (Daxe)',
7547: webdav_LC_adv => 'WebDAV access for LON-CAPA "advanced" users',
7548: webdav_LC_adv_over => '(overrides access based on affiliation, if set)',
7549: none => 'No override set',
7550: overon => 'Override -- webDAV on',
1.436 raeburn 7551: overoff => 'Override -- webDAV off',
1.440 raeburn 7552: archive => 'Authors can download tar.gz file of Authoring Space',
1.429 raeburn 7553: );
7554: }
7555:
7556: sub selectbox {
7557: my ($name,$value,$readonly,$functionref,@idlist)=@_;
7558: my $selout = '<select name="'.$name.'">';
7559: foreach my $id (@idlist) {
7560: $selout.='<option value="'.$id.'"';
7561: if ($id eq $value) {
7562: $selout.=' selected="selected"';
7563: }
7564: if ($readonly) {
7565: $selout .= ' disabled="disabled"';
7566: }
7567: $selout.='>'.&{$functionref}($id).'</option>';
7568: }
7569: $selout.='</select>';
7570: return $selout;
7571: }
7572:
1.231 raeburn 7573: sub print_selfenrollment {
7574: my ($position,$dom,$settings,$rowtotal) = @_;
7575: my ($css_class,$datatable);
7576: my $itemcount = 1;
1.271 raeburn 7577: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 7578: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 7579: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
7580: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 7581: my @rows;
7582: my $key;
7583: if ($position eq 'top') {
7584: $key = 'admin';
7585: if (ref($rowsref) eq 'ARRAY') {
7586: @rows = @{$rowsref};
7587: }
7588: } elsif ($position eq 'middle') {
7589: $key = 'default';
7590: @rows = ('types','registered','approval','limit');
7591: }
7592: foreach my $row (@rows) {
7593: if (defined($titlesref->{$row})) {
7594: $itemcount ++;
7595: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7596: $datatable .= '<tr'.$css_class.'>'.
7597: '<td>'.$titlesref->{$row}.'</td>'.
7598: '<td class="LC_left_item">'.
7599: '<table><tr>';
7600: my (%current,%currentcap);
7601: if (ref($settings) eq 'HASH') {
7602: if (ref($settings->{$key}) eq 'HASH') {
7603: foreach my $type (@types) {
7604: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7605: $current{$type} = $settings->{$key}->{$type}->{$row};
7606: }
7607: if (($row eq 'limit') && ($key eq 'default')) {
7608: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7609: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
7610: }
7611: }
7612: }
7613: }
7614: }
7615: my %roles = (
7616: '0' => &Apache::lonnet::plaintext('dc'),
7617: );
7618:
7619: foreach my $type (@types) {
7620: unless (($row eq 'registered') && ($key eq 'default')) {
7621: $datatable .= '<th>'.&mt($type).'</th>';
7622: }
7623: }
7624: unless (($row eq 'registered') && ($key eq 'default')) {
7625: $datatable .= '</tr><tr>';
7626: }
7627: foreach my $type (@types) {
7628: if ($type eq 'community') {
7629: $roles{'1'} = &mt('Community personnel');
7630: } else {
7631: $roles{'1'} = &mt('Course personnel');
7632: }
7633: $datatable .= '<td style="vertical-align: top">';
7634: if ($position eq 'top') {
7635: my %checked;
7636: if ($current{$type} eq '0') {
7637: $checked{'0'} = ' checked="checked"';
7638: } else {
7639: $checked{'1'} = ' checked="checked"';
7640: }
7641: foreach my $role ('1','0') {
7642: $datatable .= '<span class="LC_nobreak"><label>'.
7643: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
7644: 'value="'.$role.'"'.$checked{$role}.' />'.
7645: $roles{$role}.'</label></span> ';
7646: }
7647: } else {
7648: if ($row eq 'types') {
7649: my %checked;
7650: if ($current{$type} =~ /^(all|dom)$/) {
7651: $checked{$1} = ' checked="checked"';
7652: } else {
7653: $checked{''} = ' checked="checked"';
7654: }
7655: foreach my $val ('','dom','all') {
7656: $datatable .= '<span class="LC_nobreak"><label>'.
7657: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7658: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7659: }
7660: } elsif ($row eq 'registered') {
7661: my %checked;
7662: if ($current{$type} eq '1') {
7663: $checked{'1'} = ' checked="checked"';
7664: } else {
7665: $checked{'0'} = ' checked="checked"';
7666: }
7667: foreach my $val ('0','1') {
7668: $datatable .= '<span class="LC_nobreak"><label>'.
7669: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7670: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7671: }
7672: } elsif ($row eq 'approval') {
7673: my %checked;
7674: if ($current{$type} =~ /^([12])$/) {
7675: $checked{$1} = ' checked="checked"';
7676: } else {
7677: $checked{'0'} = ' checked="checked"';
7678: }
7679: for my $val (0..2) {
7680: $datatable .= '<span class="LC_nobreak"><label>'.
7681: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7682: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7683: }
7684: } elsif ($row eq 'limit') {
7685: my %checked;
7686: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
7687: $checked{$1} = ' checked="checked"';
7688: } else {
7689: $checked{'none'} = ' checked="checked"';
7690: }
7691: my $cap;
7692: if ($currentcap{$type} =~ /^\d+$/) {
7693: $cap = $currentcap{$type};
7694: }
7695: foreach my $val ('none','allstudents','selfenrolled') {
7696: $datatable .= '<span class="LC_nobreak"><label>'.
7697: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7698: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7699: }
7700: $datatable .= '<br />'.
7701: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
7702: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
7703: '</span>';
7704: }
7705: }
7706: $datatable .= '</td>';
7707: }
7708: $datatable .= '</tr>';
7709: }
7710: $datatable .= '</table></td></tr>';
7711: }
7712: } elsif ($position eq 'bottom') {
1.235 raeburn 7713: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
7714: }
7715: $$rowtotal += $itemcount;
7716: return $datatable;
7717: }
7718:
7719: sub print_validation_rows {
7720: my ($caller,$dom,$settings,$rowtotal) = @_;
7721: my ($itemsref,$namesref,$fieldsref);
7722: if ($caller eq 'selfenroll') {
7723: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
7724: } elsif ($caller eq 'requestcourses') {
7725: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
7726: }
7727: my %currvalidation;
7728: if (ref($settings) eq 'HASH') {
7729: if (ref($settings->{'validation'}) eq 'HASH') {
7730: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 7731: }
1.235 raeburn 7732: }
7733: my $datatable;
7734: my $itemcount = 0;
7735: foreach my $item (@{$itemsref}) {
7736: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7737: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7738: $namesref->{$item}.
7739: '</span></td>'.
7740: '<td class="LC_left_item">';
7741: if (($item eq 'url') || ($item eq 'button')) {
7742: $datatable .= '<span class="LC_nobreak">'.
7743: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
7744: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
7745: } elsif ($item eq 'fields') {
7746: my @currfields;
7747: if (ref($currvalidation{$item}) eq 'ARRAY') {
7748: @currfields = @{$currvalidation{$item}};
7749: }
7750: foreach my $field (@{$fieldsref}) {
7751: my $check = '';
7752: if (grep(/^\Q$field\E$/,@currfields)) {
7753: $check = ' checked="checked"';
7754: }
7755: $datatable .= '<span class="LC_nobreak"><label>'.
7756: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
7757: ' value="'.$field.'"'.$check.' />'.$field.
7758: '</label></span> ';
7759: }
7760: } elsif ($item eq 'markup') {
1.334 raeburn 7761: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 7762: $currvalidation{$item}.
1.231 raeburn 7763: '</textarea>';
1.235 raeburn 7764: }
7765: $datatable .= '</td></tr>'."\n";
7766: if (ref($rowtotal)) {
1.231 raeburn 7767: $itemcount ++;
7768: }
7769: }
1.235 raeburn 7770: if ($caller eq 'requestcourses') {
7771: my %currhash;
1.248 raeburn 7772: if (ref($settings) eq 'HASH') {
7773: if (ref($settings->{'validation'}) eq 'HASH') {
7774: if ($settings->{'validation'}{'dc'} ne '') {
7775: $currhash{$settings->{'validation'}{'dc'}} = 1;
7776: }
1.235 raeburn 7777: }
7778: }
7779: my $numinrow = 2;
7780: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
7781: 'validationdc',%currhash);
1.247 raeburn 7782: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 7783: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 7784: if ($numdc > 1) {
1.247 raeburn 7785: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 7786: } else {
1.247 raeburn 7787: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 7788: }
1.247 raeburn 7789: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 7790: $itemcount ++;
7791: }
7792: if (ref($rowtotal)) {
7793: $$rowtotal += $itemcount;
7794: }
1.231 raeburn 7795: return $datatable;
7796: }
7797:
1.357 raeburn 7798: sub print_privacy {
7799: my ($position,$dom,$settings,$rowtotal) = @_;
7800: my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
7801: my $itemcount = 0;
1.417 raeburn 7802: if ($position eq 'top') {
7803: $numinrow = 2;
7804: } else {
1.357 raeburn 7805: @items = ('domain','author','course','community');
7806: %names = &Apache::lonlocal::texthash (
7807: domain => 'Assigned domain role(s)',
7808: author => 'Assigned co-author role(s)',
7809: course => 'Assigned course role(s)',
1.416 raeburn 7810: community => 'Assigned community role(s)',
1.357 raeburn 7811: );
7812: $numinrow = 4;
7813: ($othertitle,$usertypes,$types) =
7814: &Apache::loncommon::sorted_inst_types($dom);
7815: }
7816: if (($position eq 'top') || ($position eq 'middle')) {
7817: my (%by_ip,%by_location,@intdoms,@instdoms);
7818: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
7819: if ($position eq 'top') {
7820: my %curr;
7821: my @options = ('none','user','domain','auto');
7822: my %titles = &Apache::lonlocal::texthash (
7823: none => 'Not allowed',
7824: user => 'User authorizes',
7825: domain => 'DC authorizes',
7826: auto => 'Unrestricted',
7827: instdom => 'Other domain shares institution/provider',
7828: extdom => 'Other domain has different institution/provider',
1.418 raeburn 7829: notify => 'Notify when role needs authorization',
1.357 raeburn 7830: );
7831: my %names = &Apache::lonlocal::texthash (
7832: domain => 'Domain role',
7833: author => 'Co-author role',
7834: course => 'Course role',
7835: community => 'Community role',
7836: );
7837: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7838: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7839: foreach my $domtype ('instdom','extdom') {
7840: my (%checked,$skip);
7841: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7842: $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
7843: '<td class="LC_left_item">';
7844: if ($domtype eq 'instdom') {
7845: unless (@instdoms > 1) {
7846: $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
7847: $skip = 1;
7848: }
7849: } elsif ($domtype eq 'extdom') {
7850: if (keys(%by_location) == 0) {
7851: $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
7852: $skip = 1;
7853: }
7854: }
7855: unless ($skip) {
7856: foreach my $roletype ('domain','author','course','community') {
7857: $checked{'auto'} = ' checked="checked"';
7858: if (ref($settings) eq 'HASH') {
7859: if (ref($settings->{approval}) eq 'HASH') {
7860: if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
7861: if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
7862: $checked{$1} = ' checked="checked"';
7863: $checked{'auto'} = '';
7864: }
7865: }
7866: }
7867: }
7868: $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
7869: foreach my $option (@options) {
7870: $datatable .= '<span class="LC_nobreak"><label>'.
7871: '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
7872: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
7873: '</label></span> ';
7874: }
7875: $datatable .= '</fieldset>';
7876: }
7877: }
7878: $datatable .= '</td></tr>';
7879: $itemcount ++;
7880: }
1.417 raeburn 7881: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7882: $datatable .= '<tr'.$css_class.'><td>'.$titles{'notify'}.'</td>'.
7883: '<td class="LC_left_item">';
7884: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7885: my %curr;
7886: if (ref($settings) eq 'HASH') {
7887: if ($settings->{'notify'} ne '') {
7888: map {$curr{$_}=1;} split(/,/,$settings->{'notify'});
7889: }
7890: }
7891: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7892: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
7893: 'privacy_notify',%curr);
7894: if ($numdc > 0) {
7895: $datatable .= $table;
7896: } else {
7897: $datatable .= &mt('There are no active Domain Coordinators');
7898: }
7899: } else {
7900: $datatable .= &mt('Nothing to set here, as there are no other domains');
7901: }
7902: $datatable .='</td></tr>';
1.357 raeburn 7903: } elsif ($position eq 'middle') {
7904: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7905: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7906: foreach my $item (@{$types}) {
7907: $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
7908: $numinrow,$itemcount,'','','','','',
7909: '',$usertypes->{$item});
7910: $itemcount ++;
7911: }
7912: }
7913: $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
7914: $numinrow,$itemcount,'','','','','',
7915: '',$othertitle);
7916: $itemcount ++;
7917: } else {
1.360 raeburn 7918: my (@insttypes,%insttitles);
7919: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7920: @insttypes = @{$types};
7921: %insttitles = %{$usertypes};
7922: }
7923: foreach my $item (@insttypes,'default') {
7924: my $title;
7925: if ($item eq 'default') {
7926: $title = $othertitle;
7927: } else {
7928: $title = $insttitles{$item};
7929: }
7930: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7931: $datatable .= '<tr'.$css_class.'>'.
7932: '<td class="LC_left_item">'.$title.'</td>'.
7933: '<td class="LC_left_item">'.
7934: &mt('Nothing to set here, as there are no other domains').
7935: '</td></tr>';
7936: $itemcount ++;
7937: }
1.357 raeburn 7938: }
7939: }
7940: } else {
7941: my $prefix;
7942: if ($position eq 'lower') {
7943: $prefix = 'priv';
7944: } else {
7945: $prefix = 'unpriv';
7946: }
7947: foreach my $item (@items) {
7948: $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
7949: $numinrow,$itemcount,'','','','','',
7950: '',$names{$item});
7951: $itemcount ++;
7952: }
7953: }
7954: if (ref($rowtotal)) {
7955: $$rowtotal += $itemcount;
7956: }
7957: return $datatable;
7958: }
7959:
1.354 raeburn 7960: sub print_passwords {
7961: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
7962: my ($datatable,$css_class);
7963: my $itemcount = 0;
7964: my %titles = &Apache::lonlocal::texthash (
7965: captcha => '"Forgot Password" CAPTCHA validation',
7966: link => 'Reset link expiration (hours)',
7967: case => 'Case-sensitive usernames/e-mail',
7968: prelink => 'Information required (form 1)',
7969: postlink => 'Information required (form 2)',
7970: emailsrc => 'LON-CAPA e-mail address type(s)',
7971: customtext => 'Domain specific text (HTML)',
7972: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
7973: intauth_check => 'Check bcrypt cost if authenticated',
7974: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
7975: permanent => 'Permanent e-mail address',
7976: critical => 'Critical notification address',
7977: notify => 'Notification address',
7978: min => 'Minimum password length',
7979: max => 'Maximum password length',
7980: chars => 'Required characters',
7981: expire => 'Password expiration (days)',
1.356 raeburn 7982: numsaved => 'Number of previous passwords to save and disallow reuse',
1.354 raeburn 7983: );
7984: if ($position eq 'top') {
7985: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7986: my $shownlinklife = 2;
7987: my $prelink = 'both';
7988: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
7989: if (ref($settings) eq 'HASH') {
7990: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
7991: $shownlinklife = $settings->{resetlink};
7992: }
7993: if (ref($settings->{resetcase}) eq 'ARRAY') {
7994: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
7995: }
7996: if ($settings->{resetprelink} =~ /^(both|either)$/) {
7997: $prelink = $settings->{resetprelink};
7998: }
7999: if (ref($settings->{resetpostlink}) eq 'HASH') {
8000: %postlink = %{$settings->{resetpostlink}};
8001: }
8002: if (ref($settings->{resetemail}) eq 'ARRAY') {
8003: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
8004: }
8005: if ($settings->{resetremove}) {
8006: $nostdtext = 1;
8007: }
8008: if ($settings->{resetcustom}) {
8009: $customurl = $settings->{resetcustom};
8010: }
8011: } else {
8012: if (ref($types) eq 'ARRAY') {
8013: foreach my $item (@{$types}) {
8014: $casesens{$item} = 1;
8015: $postlink{$item} = ['username','email'];
8016: }
8017: }
8018: $casesens{'default'} = 1;
8019: $postlink{'default'} = ['username','email'];
8020: $prelink = 'both';
8021: %emailsrc = (
8022: permanent => 1,
8023: critical => 1,
8024: notify => 1,
8025: );
8026: }
8027: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
8028: $itemcount ++;
8029: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8030: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
8031: '<td class="LC_left_item">'.
8032: '<input type="textbox" value="'.$shownlinklife.'" '.
8033: 'name="passwords_link" size="3" /></td></tr>';
8034: $itemcount ++;
8035: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8036: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
8037: '<td class="LC_left_item">';
8038: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8039: foreach my $item (@{$types}) {
8040: my $checkedcase;
8041: if ($casesens{$item}) {
8042: $checkedcase = ' checked="checked"';
8043: }
8044: $datatable .= '<span class="LC_nobreak"><label>'.
8045: '<input type="checkbox" name="passwords_case_sensitive" value="'.
8046: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369 raeburn 8047: '</span> ';
1.354 raeburn 8048: }
8049: }
8050: my $checkedcase;
8051: if ($casesens{'default'}) {
8052: $checkedcase = ' checked="checked"';
8053: }
8054: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
8055: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
8056: $othertitle.'</label></span></td>';
8057: $itemcount ++;
8058: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8059: my %checkedpre = (
8060: both => ' checked="checked"',
8061: either => '',
8062: );
8063: if ($prelink eq 'either') {
8064: $checkedpre{either} = ' checked="checked"';
8065: $checkedpre{both} = '';
8066: }
8067: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
8068: '<td class="LC_left_item"><span class="LC_nobreak">'.
8069: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
8070: &mt('Both username and e-mail address').'</label></span> '.
8071: '<span class="LC_nobreak"><label>'.
8072: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
8073: &mt('Either username or e-mail address').'</label></span></td></tr>';
8074: $itemcount ++;
8075: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8076: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
8077: '<td class="LC_left_item">';
8078: my %postlinked;
8079: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8080: foreach my $item (@{$types}) {
8081: undef(%postlinked);
8082: $datatable .= '<fieldset style="display: inline-block;">'.
8083: '<legend>'.$usertypes->{$item}.'</legend>';
8084: if (ref($postlink{$item}) eq 'ARRAY') {
8085: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
8086: }
8087: foreach my $field ('email','username') {
8088: my $checked;
8089: if ($postlinked{$field}) {
8090: $checked = ' checked="checked"';
8091: }
8092: $datatable .= '<span class="LC_nobreak"><label>'.
8093: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
8094: $field.'"'.$checked.' />'.$field.'</label>'.
8095: '<span> ';
8096: }
8097: $datatable .= '</fieldset>';
8098: }
8099: }
8100: if (ref($postlink{'default'}) eq 'ARRAY') {
8101: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
8102: }
8103: $datatable .= '<fieldset style="display: inline-block;">'.
8104: '<legend>'.$othertitle.'</legend>';
8105: foreach my $field ('email','username') {
8106: my $checked;
8107: if ($postlinked{$field}) {
8108: $checked = ' checked="checked"';
8109: }
8110: $datatable .= '<span class="LC_nobreak"><label>'.
8111: '<input type="checkbox" name="passwords_postlink_default" value="'.
8112: $field.'"'.$checked.' />'.$field.'</label>'.
8113: '<span> ';
8114: }
8115: $datatable .= '</fieldset></td></tr>';
8116: $itemcount ++;
8117: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8118: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
8119: '<td class="LC_left_item">';
8120: foreach my $type ('permanent','critical','notify') {
8121: my $checkedemail;
8122: if ($emailsrc{$type}) {
8123: $checkedemail = ' checked="checked"';
8124: }
8125: $datatable .= '<span class="LC_nobreak"><label>'.
8126: '<input type="checkbox" name="passwords_emailsrc" value="'.
8127: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
8128: '<span> ';
8129: }
8130: $datatable .= '</td></tr>';
8131: $itemcount ++;
8132: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8133: my $switchserver = &check_switchserver($dom,$confname);
8134: my ($showstd,$noshowstd);
8135: if ($nostdtext) {
8136: $noshowstd = ' checked="checked"';
8137: } else {
8138: $showstd = ' checked="checked"';
8139: }
8140: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
8141: '<td class="LC_left_item"><span class="LC_nobreak">'.
8142: &mt('Retain standard text:').
8143: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
8144: &mt('Yes').'</label>'.' '.
8145: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
8146: &mt('No').'</label></span><br />'.
8147: '<span class="LC_fontsize_small">'.
8148: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
8149: &mt('Include custom text:');
8150: if ($customurl) {
1.369 raeburn 8151: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354 raeburn 8152: undef,undef,undef,undef,'background-color:#ffffff');
8153: $datatable .= '<span class="LC_nobreak"> '.$link.
8154: '<label><input type="checkbox" name="passwords_custom_del"'.
8155: ' value="1" />'.&mt('Delete?').'</label></span>'.
8156: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
8157: }
8158: if ($switchserver) {
8159: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
8160: } else {
8161: $datatable .='<span class="LC_nobreak"> '.
8162: '<input type="file" name="passwords_customfile" /></span>';
8163: }
8164: $datatable .= '</td></tr>';
8165: } elsif ($position eq 'middle') {
8166: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
8167: my @items = ('intauth_cost','intauth_check','intauth_switch');
8168: my %defaults;
8169: if (ref($domconf{'defaults'}) eq 'HASH') {
8170: %defaults = %{$domconf{'defaults'}};
8171: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
8172: $defaults{'intauth_cost'} = 10;
8173: }
8174: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
8175: $defaults{'intauth_check'} = 0;
8176: }
8177: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
8178: $defaults{'intauth_switch'} = 0;
8179: }
8180: } else {
8181: %defaults = (
8182: 'intauth_cost' => 10,
8183: 'intauth_check' => 0,
8184: 'intauth_switch' => 0,
8185: );
8186: }
8187: foreach my $item (@items) {
8188: if ($itemcount%2) {
8189: $css_class = '';
8190: } else {
8191: $css_class = ' class="LC_odd_row" ';
8192: }
8193: $datatable .= '<tr'.$css_class.'>'.
8194: '<td><span class="LC_nobreak">'.$titles{$item}.
8195: '</span></td><td class="LC_left_item" colspan="3">';
8196: if ($item eq 'intauth_switch') {
8197: my @options = (0,1,2);
8198: my %optiondesc = &Apache::lonlocal::texthash (
8199: 0 => 'No',
8200: 1 => 'Yes',
8201: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
8202: );
8203: $datatable .= '<table width="100%">';
8204: foreach my $option (@options) {
8205: my $checked = ' ';
8206: if ($defaults{$item} eq $option) {
8207: $checked = ' checked="checked"';
8208: }
8209: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8210: '<label><input type="radio" name="'.$item.
8211: '" value="'.$option.'"'.$checked.' />'.
8212: $optiondesc{$option}.'</label></span></td></tr>';
8213: }
8214: $datatable .= '</table>';
8215: } elsif ($item eq 'intauth_check') {
8216: my @options = (0,1,2);
8217: my %optiondesc = &Apache::lonlocal::texthash (
8218: 0 => 'No',
8219: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
8220: 2 => 'Yes, disallow login if stored cost is less than domain default',
8221: );
8222: $datatable .= '<table width="100%">';
8223: foreach my $option (@options) {
8224: my $checked = ' ';
8225: my $onclick;
8226: if ($defaults{$item} eq $option) {
8227: $checked = ' checked="checked"';
8228: }
8229: if ($option == 2) {
8230: $onclick = ' onclick="javascript:warnIntAuth(this);"';
8231: }
8232: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8233: '<label><input type="radio" name="'.$item.
8234: '" value="'.$option.'"'.$checked.$onclick.' />'.
8235: $optiondesc{$option}.'</label></span></td></tr>';
8236: }
8237: $datatable .= '</table>';
8238: } else {
8239: $datatable .= '<input type="text" name="'.$item.'" value="'.
8240: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
8241: }
8242: $datatable .= '</td></tr>';
8243: $itemcount ++;
8244: }
8245: } elsif ($position eq 'lower') {
1.405 raeburn 8246: $datatable .= &password_rules('passwords',\$itemcount,$settings);
1.354 raeburn 8247: } else {
1.359 raeburn 8248: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8249: my %ownerchg = (
8250: by => {},
8251: for => {},
8252: );
8253: my %ownertitles = &Apache::lonlocal::texthash (
8254: by => 'Course owner status(es) allowed',
8255: for => 'Student status(es) allowed',
8256: );
1.354 raeburn 8257: if (ref($settings) eq 'HASH') {
1.359 raeburn 8258: if (ref($settings->{crsownerchg}) eq 'HASH') {
8259: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
8260: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
8261: }
8262: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
8263: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
8264: }
1.354 raeburn 8265: }
8266: }
8267: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8268: $datatable .= '<tr '.$css_class.'>'.
8269: '<td>'.
8270: &mt('Requirements').'<ul>'.
1.359 raeburn 8271: '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354 raeburn 8272: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
8273: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359 raeburn 8274: '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354 raeburn 8275: '</ul>'.
8276: '</td>'.
1.359 raeburn 8277: '<td class="LC_left_item">';
8278: foreach my $item ('by','for') {
8279: $datatable .= '<fieldset style="display: inline-block;">'.
8280: '<legend>'.$ownertitles{$item}.'</legend>';
8281: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8282: foreach my $type (@{$types}) {
8283: my $checked;
8284: if ($ownerchg{$item}{$type}) {
8285: $checked = ' checked="checked"';
8286: }
8287: $datatable .= '<span class="LC_nobreak"><label>'.
8288: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
8289: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369 raeburn 8290: '</span> ';
1.359 raeburn 8291: }
8292: }
8293: my $checked;
8294: if ($ownerchg{$item}{'default'}) {
8295: $checked = ' checked="checked"';
8296: }
8297: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
8298: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
8299: $othertitle.'</label></span></fieldset>';
8300: }
8301: $datatable .= '</td></tr>';
1.354 raeburn 8302: }
8303: return $datatable;
8304: }
8305:
1.405 raeburn 8306: sub password_rules {
8307: my ($prefix,$itemcountref,$settings) = @_;
8308: my ($min,$max,%chars,$expire,$numsaved,$numinrow);
8309: my %titles;
8310: if ($prefix eq 'passwords') {
8311: %titles = &Apache::lonlocal::texthash (
8312: min => 'Minimum password length',
8313: max => 'Maximum password length',
8314: chars => 'Required characters',
8315: );
1.421 raeburn 8316: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 8317: %titles = &Apache::lonlocal::texthash (
8318: min => 'Minimum secret length',
8319: max => 'Maximum secret length',
8320: chars => 'Required characters',
8321: );
8322: }
8323: $min = $Apache::lonnet::passwdmin;
8324: my $datatable;
8325: my $itemcount;
8326: if (ref($itemcountref)) {
8327: $itemcount = $$itemcountref;
8328: }
8329: if (ref($settings) eq 'HASH') {
8330: if ($settings->{min}) {
8331: $min = $settings->{min};
8332: }
8333: if ($settings->{max}) {
8334: $max = $settings->{max};
8335: }
8336: if (ref($settings->{chars}) eq 'ARRAY') {
8337: map { $chars{$_} = 1; } (@{$settings->{chars}});
8338: }
1.425 raeburn 8339: if ($prefix eq 'passwords') {
1.405 raeburn 8340: if ($settings->{expire}) {
8341: $expire = $settings->{expire};
8342: }
8343: if ($settings->{numsaved}) {
8344: $numsaved = $settings->{numsaved};
8345: }
8346: }
8347: }
8348: my %rulenames = &Apache::lonlocal::texthash(
8349: uc => 'At least one upper case letter',
8350: lc => 'At least one lower case letter',
8351: num => 'At least one number',
8352: spec => 'At least one non-alphanumeric',
8353: );
8354: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
8355: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
8356: '<td class="LC_left_item"><span class="LC_nobreak">'.
8357: '<input type="text" name="'.$prefix.'_min" value="'.$min.'" size="3" '.
8358: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8359: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
8360: '</span></td></tr>';
8361: $itemcount ++;
8362: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8363: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
8364: '<td class="LC_left_item"><span class="LC_nobreak">'.
8365: '<input type="text" name="'.$prefix.'_max" value="'.$max.'" size="3" '.
8366: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8367: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
8368: '</span></td></tr>';
8369: $itemcount ++;
8370: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8371: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
8372: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
8373: '</span></td>';
8374: my $numinrow = 2;
8375: my @possrules = ('uc','lc','num','spec');
8376: $datatable .= '<td class="LC_left_item"><table>';
8377: for (my $i=0; $i<@possrules; $i++) {
8378: my ($rem,$checked);
8379: if ($chars{$possrules[$i]}) {
8380: $checked = ' checked="checked"';
8381: }
8382: $rem = $i%($numinrow);
8383: if ($rem == 0) {
8384: if ($i > 0) {
8385: $datatable .= '</tr>';
8386: }
8387: $datatable .= '<tr>';
8388: }
8389: $datatable .= '<td><span class="LC_nobreak"><label>'.
8390: '<input type="checkbox" name="'.$prefix.'_chars" value="'.$possrules[$i].'"'.$checked.' />'.
8391: $rulenames{$possrules[$i]}.'</label></span></td>';
8392: }
8393: my $rem = @possrules%($numinrow);
8394: my $colsleft = $numinrow - $rem;
8395: if ($colsleft > 1 ) {
8396: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8397: ' </td>';
8398: } elsif ($colsleft == 1) {
8399: $datatable .= '<td class="LC_left_item"> </td>';
8400: }
8401: $datatable .='</table></td></tr>';
8402: $itemcount ++;
8403: if ($prefix eq 'passwords') {
8404: $titles{'expire'} = &mt('Password expiration (days)');
8405: $titles{'numsaved'} = &mt('Number of previous passwords to save and disallow reuse');
8406: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8407: $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
8408: '<td class="LC_left_item"><span class="LC_nobreak">'.
8409: '<input type="text" name="'.$prefix.'_expire" value="'.$expire.'" size="4" '.
8410: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8411: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
8412: '</span></td></tr>';
8413: $itemcount ++;
8414: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8415: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
8416: '<td class="LC_left_item"><span class="LC_nobreak">'.
8417: '<input type="text" name="'.$prefix.'_numsaved" value="'.$numsaved.'" size="3" '.
8418: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8419: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
8420: '</span></td></tr>';
8421: $itemcount ++;
8422: }
8423: if (ref($itemcountref)) {
8424: $$itemcountref += $itemcount;
8425: }
8426: return $datatable;
8427: }
8428:
1.373 raeburn 8429: sub print_wafproxy {
8430: my ($position,$dom,$settings,$rowtotal) = @_;
8431: my $css_class;
8432: my $itemcount = 0;
8433: my $datatable;
8434: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 8435: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
1.374 raeburn 8436: my %lt = &wafproxy_titles();
1.373 raeburn 8437: foreach my $server (sort(keys(%servers))) {
8438: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
1.381 raeburn 8439: next if ($serverhome eq '');
1.373 raeburn 8440: my $serverdom;
8441: if ($serverhome ne $server) {
8442: $serverdom = &Apache::lonnet::host_domain($serverhome);
1.381 raeburn 8443: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
8444: $othercontrol{$server} = $serverdom;
8445: }
1.373 raeburn 8446: } else {
8447: $serverdom = &Apache::lonnet::host_domain($server);
1.381 raeburn 8448: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
1.373 raeburn 8449: if ($serverdom ne $dom) {
8450: $othercontrol{$server} = $serverdom;
8451: } else {
8452: $setdom = 1;
8453: if (ref($settings) eq 'HASH') {
8454: if (ref($settings->{'alias'}) eq 'HASH') {
8455: $aliases{$dom} = $settings->{'alias'};
1.381 raeburn 8456: if ($aliases{$dom} ne '') {
8457: $showdom = 1;
8458: }
1.373 raeburn 8459: }
1.388 raeburn 8460: if (ref($settings->{'saml'}) eq 'HASH') {
8461: $saml{$dom} = $settings->{'saml'};
8462: }
1.373 raeburn 8463: }
8464: }
8465: }
8466: }
1.381 raeburn 8467: if ($setdom) {
8468: %{$values{$dom}} = ();
8469: if (ref($settings) eq 'HASH') {
8470: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8471: $values{$dom}{$item} = $settings->{$item};
8472: }
8473: }
8474: }
1.373 raeburn 8475: if (keys(%othercontrol)) {
8476: %otherdoms = reverse(%othercontrol);
8477: foreach my $domain (keys(%otherdoms)) {
8478: %{$values{$domain}} = ();
8479: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
1.383 raeburn 8480: if (ref($config{'wafproxy'}) eq 'HASH') {
8481: $aliases{$domain} = $config{'wafproxy'}{'alias'};
1.425 raeburn 8482: if (exists($config{'wafproxy'}{'saml'})) {
1.388 raeburn 8483: $saml{$domain} = $config{'wafproxy'}{'saml'};
8484: }
1.383 raeburn 8485: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8486: $values{$domain}{$item} = $config{'wafproxy'}{$item};
1.373 raeburn 8487: }
8488: }
8489: }
8490: }
8491: if ($position eq 'top') {
8492: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.381 raeburn 8493: my %aliasinfo;
1.373 raeburn 8494: foreach my $server (sort(keys(%servers))) {
1.381 raeburn 8495: $itemcount ++;
8496: my $dom_in_effect;
8497: my $aliasrows = '<tr>'.
1.383 raeburn 8498: '<td class="LC_left_item" style="vertical-align: baseline;">'.
1.433 raeburn 8499: &mt('Hostname').': '.
8500: '<span class="LC_nobreak LC_cusr_emph">'.
8501: &Apache::lonnet::hostname($server).
8502: '</span></td><td> </td>';
1.373 raeburn 8503: if ($othercontrol{$server}) {
1.381 raeburn 8504: $dom_in_effect = $othercontrol{$server};
1.388 raeburn 8505: my ($current,$forsaml);
1.383 raeburn 8506: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
8507: $current = $aliases{$dom_in_effect}{$server};
1.373 raeburn 8508: }
1.388 raeburn 8509: if (ref($saml{$dom_in_effect}) eq 'HASH') {
8510: if ($saml{$dom_in_effect}{$server}) {
8511: $forsaml = 1;
8512: }
8513: }
1.383 raeburn 8514: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8515: &mt('Alias').': ';
1.373 raeburn 8516: if ($current) {
1.381 raeburn 8517: $aliasrows .= $current;
1.388 raeburn 8518: if ($forsaml) {
1.396 raeburn 8519: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
1.388 raeburn 8520: }
1.373 raeburn 8521: } else {
1.383 raeburn 8522: $aliasrows .= &mt('None');
1.373 raeburn 8523: }
1.383 raeburn 8524: $aliasrows .= ' <span class="LC_small">('.
8525: &mt('controlled by domain: [_1]',
8526: '<b>'.$dom_in_effect.'</b>').')</span></td>';
1.373 raeburn 8527: } else {
1.381 raeburn 8528: $dom_in_effect = $dom;
1.388 raeburn 8529: my ($current,$samlon,$samloff);
8530: $samloff = ' checked="checked"';
1.373 raeburn 8531: if (ref($aliases{$dom}) eq 'HASH') {
8532: if ($aliases{$dom}{$server}) {
8533: $current = $aliases{$dom}{$server};
8534: }
8535: }
1.388 raeburn 8536: if (ref($saml{$dom}) eq 'HASH') {
8537: if ($saml{$dom}{$server}) {
8538: $samlon = $samloff;
8539: undef($samloff);
8540: }
8541: }
1.383 raeburn 8542: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8543: &mt('Alias').': '.
1.381 raeburn 8544: '<input type="text" name="wafproxy_alias_'.$server.'" '.
1.388 raeburn 8545: 'value="'.$current.'" size="30" />'.
8546: (' 'x2).'<span class="LC_nobreak">'.
1.396 raeburn 8547: &mt('Alias used for SSO Auth').': <label>'.
1.388 raeburn 8548: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
1.425 raeburn 8549: &mt('No').'</label> <label>'.
1.388 raeburn 8550: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
8551: &mt('Yes').'</label></span>'.
1.425 raeburn 8552: '</td>';
1.381 raeburn 8553: }
8554: $aliasrows .= '</tr>';
8555: $aliasinfo{$dom_in_effect} .= $aliasrows;
8556: }
8557: if ($aliasinfo{$dom}) {
8558: my ($onclick,$wafon,$wafoff,$showtable);
8559: $onclick = ' onclick="javascript:toggleWAF();"';
8560: $wafoff = ' checked="checked"';
8561: $showtable = ' style="display:none";';
8562: if ($showdom) {
8563: $wafon = $wafoff;
8564: $wafoff = '';
8565: $showtable = ' style="display:inline;"';
8566: }
8567: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8568: $datatable = '<tr'.$css_class.'>'.
8569: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
8570: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
8571: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
8572: &mt('Yes').'</label>'.(' 'x2).'<label>'.
8573: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
8574: &mt('No').'</label></span></td>'.
8575: '<td class="LC_left_item">'.
8576: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
8577: '</table></td></tr>';
8578: $itemcount++;
8579: }
1.383 raeburn 8580: if (keys(%otherdoms)) {
8581: foreach my $key (sort(keys(%otherdoms))) {
1.381 raeburn 8582: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.383 raeburn 8583: $datatable .= '<tr'.$css_class.'>'.
8584: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
8585: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
8586: '</table></td></tr>';
1.381 raeburn 8587: $itemcount++;
1.373 raeburn 8588: }
8589: }
8590: } else {
1.383 raeburn 8591: my %ip_methods = &remoteip_methods();
1.373 raeburn 8592: if ($setdom) {
8593: $itemcount ++;
8594: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.381 raeburn 8595: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
1.382 raeburn 8596: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
1.381 raeburn 8597: $wafstyle = ' style="display:none;"';
8598: $nowafstyle = ' style="display:table-row;"';
8599: $currwafdisplay = ' style="display: none"';
8600: $wafrangestyle = ' style="display: none"';
8601: $curr_remotip = 'n';
1.382 raeburn 8602: $ssltossl = ' checked="checked"';
1.381 raeburn 8603: if ($showdom) {
8604: $wafstyle = ' style="display:table-row;"';
8605: $nowafstyle = ' style="display:none;"';
8606: if (keys(%{$values{$dom}})) {
8607: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
8608: $curr_remotip = $values{$dom}{remoteip};
8609: }
8610: if ($curr_remotip eq 'h') {
8611: $currwafdisplay = ' style="display:table-row"';
8612: $wafrangestyle = ' style="display:inline-block;"';
8613: }
1.382 raeburn 8614: if ($values{$dom}{'sslopt'}) {
8615: $alltossl = ' checked="checked"';
8616: $ssltossl = '';
8617: }
1.381 raeburn 8618: }
8619: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
8620: $vpndircheck = ' checked="checked"';
8621: $currwafvpn = ' style="display:table-row;"';
8622: $wafrangestyle = ' style="display:inline-block;"';
8623: } else {
8624: $vpnaliascheck = ' checked="checked"';
8625: $currwafvpn = ' style="display:none;"';
8626: }
8627: }
8628: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
8629: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
8630: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
8631: '</tr>'.
8632: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
1.374 raeburn 8633: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
1.381 raeburn 8634: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
1.393 raeburn 8635: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
8636: &mt('Range(s) stored in CIDR notation').'</div></td>'.
1.381 raeburn 8637: '<td class="LC_left_item"><table>'.
8638: '<tr>'.
8639: '<td valign="top">'.$lt{'remoteip'}.': '.
8640: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
8641: foreach my $option ('m','h','n') {
8642: my $sel;
8643: if ($option eq $curr_remotip) {
8644: $sel = ' selected="selected"';
8645: }
8646: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
8647: $ip_methods{$option}.'</option>';
8648: }
8649: $datatable .= '</select></td></tr>'."\n".
8650: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
8651: $lt{'ipheader'}.': '.
8652: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
8653: 'name="wafproxy_ipheader" />'.
8654: '</td></tr>'."\n".
8655: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
1.382 raeburn 8656: $lt{'trusted'}.':<br />'.
1.381 raeburn 8657: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
8658: $values{$dom}{'trusted'}.'</textarea>'.
8659: '</td></tr>'."\n".
8660: '<tr><td><hr /></td></tr>'."\n".
8661: '<tr>'.
8662: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
8663: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
8664: $lt{'vpndirect'}.'</label>'.(' 'x2).
8665: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
8666: $lt{'vpnaliased'}.'</label></span></td></tr>';
8667: foreach my $item ('vpnint','vpnext') {
8668: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
1.382 raeburn 8669: '<td valign="top">'.$lt{$item}.':<br />'.
1.381 raeburn 8670: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
8671: $values{$dom}{$item}.'</textarea>'.
8672: '</td></tr>'."\n";
1.373 raeburn 8673: }
1.382 raeburn 8674: $datatable .= '<tr><td><hr /></td></tr>'."\n".
8675: '<tr>'.
8676: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
8677: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
8678: $lt{'alltossl'}.'</label>'.(' 'x2).
8679: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
8680: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
8681: '</table></td></tr>';
1.373 raeburn 8682: }
8683: if (keys(%otherdoms)) {
8684: foreach my $domain (sort(keys(%otherdoms))) {
8685: $itemcount ++;
8686: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8687: $datatable .= '<tr'.$css_class.'>'.
1.383 raeburn 8688: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
1.374 raeburn 8689: '<td class="LC_left_item"><table>';
1.382 raeburn 8690: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 8691: my $showval = &mt('None');
1.382 raeburn 8692: if ($item eq 'ssl') {
8693: $showval = $lt{'ssltossl'};
8694: }
1.373 raeburn 8695: if ($values{$domain}{$item}) {
1.381 raeburn 8696: $showval = $values{$domain}{$item};
1.382 raeburn 8697: if ($item eq 'ssl') {
8698: $showval = $lt{'alltossl'};
1.383 raeburn 8699: } elsif ($item eq 'remoteip') {
8700: $showval = $ip_methods{$values{$domain}{$item}};
1.382 raeburn 8701: }
1.373 raeburn 8702: }
8703: $datatable .= '<tr>'.
8704: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
8705: }
1.381 raeburn 8706: $datatable .= '</table></td></tr>';
1.373 raeburn 8707: }
8708: }
8709: }
8710: $$rowtotal += $itemcount;
8711: return $datatable;
8712: }
8713:
8714: sub wafproxy_titles {
8715: return &Apache::lonlocal::texthash(
1.381 raeburn 8716: remoteip => "Method for determining user's IP",
8717: ipheader => 'Request header containing remote IP',
8718: trusted => 'Trusted IP range(s)',
8719: vpnaccess => 'Access from institutional VPN',
8720: vpndirect => 'via regular hostname (no WAF)',
8721: vpnaliased => 'via aliased hostname (WAF)',
8722: vpnint => 'Internal IP Range(s) for VPN sessions',
8723: vpnext => 'IP Range(s) for backend WAF connections',
1.382 raeburn 8724: sslopt => 'Forwarding http/https',
1.381 raeburn 8725: alltossl => 'WAF forwards both http and https requests to https',
8726: ssltossl => 'WAF forwards http requests to http and https to https',
8727: );
8728: }
8729:
8730: sub remoteip_methods {
8731: return &Apache::lonlocal::texthash(
8732: m => 'Use Apache mod_remoteip',
8733: h => 'Use headers parsed by LON-CAPA',
8734: n => 'Not in use',
1.373 raeburn 8735: );
8736: }
8737:
1.137 raeburn 8738: sub print_usersessions {
8739: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 8740: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 8741: my (%by_ip,%by_location,@intdoms,@instdoms);
8742: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 8743:
8744: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 8745: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 8746: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 8747: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 8748: if ($position eq 'top') {
1.152 raeburn 8749: if (keys(%serverhomes) > 1) {
1.145 raeburn 8750: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.371 raeburn 8751: my ($curroffloadnow,$curroffloadoth);
1.261 raeburn 8752: if (ref($settings) eq 'HASH') {
8753: if (ref($settings->{'offloadnow'}) eq 'HASH') {
8754: $curroffloadnow = $settings->{'offloadnow'};
8755: }
1.371 raeburn 8756: if (ref($settings->{'offloadoth'}) eq 'HASH') {
8757: $curroffloadoth = $settings->{'offloadoth'};
8758: }
1.261 raeburn 8759: }
1.371 raeburn 8760: my $other_insts = scalar(keys(%by_location));
8761: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
8762: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 8763: } else {
1.140 raeburn 8764: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 8765: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
8766: '</td></tr>';
1.140 raeburn 8767: }
1.137 raeburn 8768: } else {
1.279 raeburn 8769: my %titles = &usersession_titles();
8770: my ($prefix,@types);
8771: if ($position eq 'bottom') {
8772: $prefix = 'remote';
8773: @types = ('version','excludedomain','includedomain');
1.145 raeburn 8774: } else {
1.279 raeburn 8775: $prefix = 'hosted';
8776: @types = ('excludedomain','includedomain');
8777: }
8778: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8779: }
8780: $$rowtotal += $itemcount;
8781: return $datatable;
8782: }
8783:
8784: sub rules_by_location {
8785: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
8786: my ($datatable,$itemcount,$css_class);
8787: if (keys(%{$by_location}) == 0) {
8788: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8789: $datatable = '<tr'.$css_class.'><td colspan="2">'.
8790: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
8791: '</td></tr>';
8792: $itemcount = 1;
8793: } else {
8794: $itemcount = 0;
8795: my $numinrow = 5;
8796: my (%current,%checkedon,%checkedoff);
8797: my @locations = sort(keys(%{$by_location}));
8798: foreach my $type (@{$types}) {
8799: $checkedon{$type} = '';
8800: $checkedoff{$type} = ' checked="checked"';
8801: }
8802: if (ref($settings) eq 'HASH') {
8803: if (ref($settings->{$prefix}) eq 'HASH') {
8804: foreach my $key (keys(%{$settings->{$prefix}})) {
8805: $current{$key} = $settings->{$prefix}{$key};
8806: if ($key eq 'version') {
8807: if ($current{$key} ne '') {
1.145 raeburn 8808: $checkedon{$key} = ' checked="checked"';
8809: $checkedoff{$key} = '';
8810: }
1.279 raeburn 8811: } elsif (ref($current{$key}) eq 'ARRAY') {
8812: $checkedon{$key} = ' checked="checked"';
8813: $checkedoff{$key} = '';
1.137 raeburn 8814: }
8815: }
8816: }
1.279 raeburn 8817: }
8818: foreach my $type (@{$types}) {
8819: next if ($type ne 'version' && !@locations);
8820: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8821: $datatable .= '<tr'.$css_class.'>
8822: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
8823: <span class="LC_nobreak">
8824: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
8825: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
8826: if ($type eq 'version') {
8827: my @lcversions = &Apache::lonnet::all_loncaparevs();
8828: my $selector = '<select name="'.$prefix.'_version">';
8829: foreach my $version (@lcversions) {
8830: my $selected = '';
8831: if ($current{'version'} eq $version) {
8832: $selected = ' selected="selected"';
1.145 raeburn 8833: }
1.279 raeburn 8834: $selector .= ' <option value="'.$version.'"'.
8835: $selected.'>'.$version.'</option>';
8836: }
8837: $selector .= '</select> ';
8838: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
8839: } else {
8840: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
8841: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
8842: ' />'.(' 'x2).
8843: '<input type="button" value="'.&mt('uncheck all').'" '.
8844: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
8845: "\n".
8846: '</div><div><table>';
8847: my $rem;
8848: for (my $i=0; $i<@locations; $i++) {
8849: my ($showloc,$value,$checkedtype);
8850: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
8851: my $ip = $by_location->{$locations[$i]}->[0];
8852: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8853: $value = join(':',@{$by_ip->{$ip}});
8854: $showloc = join(', ',@{$by_ip->{$ip}});
8855: if (ref($current{$type}) eq 'ARRAY') {
8856: foreach my $loc (@{$by_ip->{$ip}}) {
8857: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
8858: $checkedtype = ' checked="checked"';
8859: last;
1.145 raeburn 8860: }
1.138 raeburn 8861: }
8862: }
8863: }
1.137 raeburn 8864: }
1.279 raeburn 8865: $rem = $i%($numinrow);
8866: if ($rem == 0) {
8867: if ($i > 0) {
8868: $datatable .= '</tr>';
8869: }
8870: $datatable .= '<tr>';
8871: }
8872: $datatable .= '<td class="LC_left_item">'.
8873: '<span class="LC_nobreak"><label>'.
8874: '<input type="checkbox" name="'.$prefix.'_'.$type.
8875: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
8876: '</label></span></td>';
8877: }
8878: $rem = @locations%($numinrow);
8879: my $colsleft = $numinrow - $rem;
8880: if ($colsleft > 1 ) {
8881: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8882: ' </td>';
8883: } elsif ($colsleft == 1) {
8884: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 8885: }
1.279 raeburn 8886: $datatable .= '</tr></table>';
1.137 raeburn 8887: }
1.279 raeburn 8888: $datatable .= '</td></tr>';
8889: $itemcount ++;
1.137 raeburn 8890: }
8891: }
1.279 raeburn 8892: return ($datatable,$itemcount);
1.137 raeburn 8893: }
8894:
1.275 raeburn 8895: sub print_ssl {
8896: my ($position,$dom,$settings,$rowtotal) = @_;
8897: my ($css_class,$datatable);
8898: my $itemcount = 1;
8899: if ($position eq 'top') {
1.281 raeburn 8900: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8901: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8902: my $same_institution;
8903: if ($intdom ne '') {
8904: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
8905: if (ref($internet_names) eq 'ARRAY') {
8906: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
8907: $same_institution = 1;
8908: }
8909: }
8910: }
1.275 raeburn 8911: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 8912: $datatable = '<tr'.$css_class.'><td colspan="2">';
8913: if ($same_institution) {
8914: my %domservers = &Apache::lonnet::get_servers($dom);
8915: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
8916: } else {
8917: $datatable .= &mt("You need to be logged into one of your own domain's servers to display information about the status of LON-CAPA SSL certificates.");
8918: }
8919: $datatable .= '</td></tr>';
1.275 raeburn 8920: $itemcount ++;
8921: } else {
8922: my %titles = &ssl_titles();
8923: my (%by_ip,%by_location,@intdoms,@instdoms);
8924: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8925: my @alldoms = &Apache::lonnet::all_domains();
8926: my %serverhomes = %Apache::lonnet::serverhomeIDs;
8927: my @domservers = &Apache::lonnet::get_servers($dom);
8928: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8929: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 8930: if (($position eq 'connto') || ($position eq 'connfrom')) {
8931: my $legacy;
8932: unless (ref($settings) eq 'HASH') {
8933: my $name;
8934: if ($position eq 'connto') {
8935: $name = 'loncAllowInsecure';
8936: } else {
8937: $name = 'londAllowInsecure';
8938: }
8939: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
8940: my @ids=&Apache::lonnet::current_machine_ids();
8941: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
8942: my %what = (
8943: $name => 1,
8944: );
8945: my ($result,$returnhash) =
8946: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
8947: if ($result eq 'ok') {
8948: if (ref($returnhash) eq 'HASH') {
8949: $legacy = $returnhash->{$name};
8950: }
8951: }
8952: } else {
8953: $legacy = $Apache::lonnet::perlvar{$name};
8954: }
8955: }
1.275 raeburn 8956: foreach my $type ('dom','intdom','other') {
8957: my %checked;
8958: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8959: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
8960: '<td class="LC_right_item">';
8961: my $skip;
8962: if ($type eq 'dom') {
8963: unless (keys(%servers) > 1) {
8964: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
8965: $skip = 1;
8966: }
8967: }
8968: if ($type eq 'intdom') {
8969: unless (@instdoms > 1) {
8970: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
8971: $skip = 1;
8972: }
8973: } elsif ($type eq 'other') {
8974: if (keys(%by_location) == 0) {
8975: $datatable .= &mt('Nothing to set here, as there are no other institutions');
8976: $skip = 1;
8977: }
8978: }
8979: unless ($skip) {
8980: $checked{'yes'} = ' checked="checked"';
8981: if (ref($settings) eq 'HASH') {
1.293 raeburn 8982: if (ref($settings->{$position}) eq 'HASH') {
8983: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 8984: $checked{$1} = $checked{'yes'};
8985: delete($checked{'yes'});
8986: }
8987: }
1.293 raeburn 8988: } else {
8989: if ($legacy == 0) {
8990: $checked{'req'} = $checked{'yes'};
8991: delete($checked{'yes'});
8992: }
1.275 raeburn 8993: }
8994: foreach my $option ('no','yes','req') {
8995: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 8996: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 8997: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
8998: '</label></span>'.(' 'x2);
8999: }
9000: }
9001: $datatable .= '</td></tr>';
9002: $itemcount ++;
9003: }
9004: } else {
9005: my $prefix = 'replication';
9006: my @types = ('certreq','nocertreq');
1.279 raeburn 9007: if (keys(%by_location) == 0) {
9008: $datatable .= '<tr'.$css_class.'><td>'.
9009: &mt('Nothing to set here, as there are no other institutions').
9010: '</td></tr>';
9011: $itemcount ++;
1.275 raeburn 9012: } else {
1.279 raeburn 9013: ($datatable,$itemcount) =
9014: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 9015: }
9016: }
9017: }
9018: $$rowtotal += $itemcount;
9019: return $datatable;
9020: }
9021:
9022: sub ssl_titles {
9023: return &Apache::lonlocal::texthash (
9024: dom => 'LON-CAPA servers/VMs from same domain',
9025: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
9026: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 9027: connto => 'Connections to other servers',
9028: connfrom => 'Connections from other servers',
1.275 raeburn 9029: replication => 'Replicating content to other institutions',
9030: certreq => 'Client certificate required, but specific domains exempt',
9031: nocertreq => 'No client certificate required, except for specific domains',
9032: no => 'SSL not used',
9033: yes => 'SSL Optional (used if available)',
9034: req => 'SSL Required',
9035: );
1.279 raeburn 9036: }
9037:
9038: sub print_trust {
9039: my ($prefix,$dom,$settings,$rowtotal) = @_;
9040: my ($css_class,$datatable,%checked,%choices);
9041: my (%by_ip,%by_location,@intdoms,@instdoms);
9042: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
9043: my $itemcount = 1;
9044: my %titles = &trust_titles();
9045: my @types = ('exc','inc');
9046: if ($prefix eq 'top') {
9047: $prefix = 'content';
9048: } elsif ($prefix eq 'bottom') {
9049: $prefix = 'msg';
9050: }
9051: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
9052: $$rowtotal += $itemcount;
9053: return $datatable;
9054: }
9055:
9056: sub trust_titles {
9057: return &Apache::lonlocal::texthash(
9058: content => "Access to this domain's content by others",
9059: shared => "Access to other domain's content by this domain",
9060: enroll => "Enrollment in this domain's courses by others",
9061: othcoau => "Co-author roles in this domain for others",
9062: coaurem => "Co-author roles for this domain's users elsewhere",
9063: domroles => "Domain roles in this domain assignable to others",
9064: catalog => "Course Catalog for this domain displayed elsewhere",
9065: reqcrs => "Requests for creation of courses in this domain by others",
9066: msg => "Users in other domains can send messages to this domain",
9067: exc => "Allow all, but exclude specific domains",
9068: inc => "Deny all, but include specific domains",
9069: );
1.275 raeburn 9070: }
9071:
1.138 raeburn 9072: sub build_location_hashes {
1.275 raeburn 9073: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 9074: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 9075: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 9076: my %iphost = &Apache::lonnet::get_iphost();
9077: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
9078: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
9079: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
9080: foreach my $id (@{$iphost{$primary_ip}}) {
9081: my $intdom = &Apache::lonnet::internet_dom($id);
9082: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
9083: push(@{$intdoms},$intdom);
9084: }
9085: }
9086: }
9087: foreach my $ip (keys(%iphost)) {
9088: if (ref($iphost{$ip}) eq 'ARRAY') {
9089: foreach my $id (@{$iphost{$ip}}) {
9090: my $location = &Apache::lonnet::internet_dom($id);
9091: if ($location) {
1.275 raeburn 9092: if (grep(/^\Q$location\E$/,@{$intdoms})) {
9093: my $dom = &Apache::lonnet::host_domain($id);
9094: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
9095: push(@{$instdoms},$dom);
9096: }
9097: next;
9098: }
1.138 raeburn 9099: if (ref($by_ip->{$ip}) eq 'ARRAY') {
9100: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
9101: push(@{$by_ip->{$ip}},$location);
9102: }
9103: } else {
9104: $by_ip->{$ip} = [$location];
9105: }
9106: }
9107: }
9108: }
9109: }
9110: foreach my $ip (sort(keys(%{$by_ip}))) {
9111: if (ref($by_ip->{$ip}) eq 'ARRAY') {
9112: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
9113: my $first = $by_ip->{$ip}->[0];
9114: if (ref($by_location->{$first}) eq 'ARRAY') {
9115: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
9116: push(@{$by_location->{$first}},$ip);
9117: }
9118: } else {
9119: $by_location->{$first} = [$ip];
9120: }
9121: }
9122: }
9123: return;
9124: }
9125:
1.145 raeburn 9126: sub current_offloads_to {
9127: my ($dom,$settings,$servers) = @_;
9128: my (%spareid,%otherdomconfigs);
1.152 raeburn 9129: if (ref($servers) eq 'HASH') {
1.145 raeburn 9130: foreach my $lonhost (sort(keys(%{$servers}))) {
9131: my $gotspares;
1.152 raeburn 9132: if (ref($settings) eq 'HASH') {
9133: if (ref($settings->{'spares'}) eq 'HASH') {
9134: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
9135: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
9136: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
9137: $gotspares = 1;
9138: }
1.145 raeburn 9139: }
9140: }
9141: unless ($gotspares) {
9142: my $gotspares;
9143: my $serverhomeID =
9144: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
9145: my $serverhomedom =
9146: &Apache::lonnet::host_domain($serverhomeID);
9147: if ($serverhomedom ne $dom) {
9148: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
9149: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
9150: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
9151: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
9152: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
9153: $gotspares = 1;
9154: }
9155: }
9156: } else {
9157: $otherdomconfigs{$serverhomedom} =
9158: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
9159: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
9160: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
9161: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
9162: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
9163: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
9164: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
9165: $gotspares = 1;
9166: }
9167: }
9168: }
9169: }
9170: }
9171: }
9172: }
9173: unless ($gotspares) {
9174: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
9175: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9176: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9177: } else {
9178: my $server_hostname = &Apache::lonnet::hostname($lonhost);
9179: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
9180: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
9181: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9182: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9183: } else {
1.150 raeburn 9184: my %what = (
9185: spareid => 1,
9186: );
9187: my ($result,$returnhash) =
9188: &Apache::lonnet::get_remote_globals($lonhost,\%what);
9189: if ($result eq 'ok') {
9190: if (ref($returnhash) eq 'HASH') {
9191: if (ref($returnhash->{'spareid'}) eq 'HASH') {
9192: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
9193: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
9194: }
9195: }
1.145 raeburn 9196: }
9197: }
9198: }
9199: }
9200: }
9201: }
9202: return %spareid;
9203: }
9204:
9205: sub spares_row {
1.371 raeburn 9206: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
9207: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 9208: my $css_class;
9209: my $numinrow = 4;
9210: my $itemcount = 1;
9211: my $datatable;
1.152 raeburn 9212: my %typetitles = &sparestype_titles();
9213: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 9214: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 9215: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
9216: my ($othercontrol,$serverdom);
9217: if ($serverhome ne $server) {
9218: $serverdom = &Apache::lonnet::host_domain($serverhome);
9219: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9220: } else {
9221: $serverdom = &Apache::lonnet::host_domain($server);
9222: if ($serverdom ne $dom) {
9223: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9224: }
9225: }
9226: next unless (ref($spareid->{$server}) eq 'HASH');
1.371 raeburn 9227: my ($checkednow,$checkedoth);
1.261 raeburn 9228: if (ref($curroffloadnow) eq 'HASH') {
9229: if ($curroffloadnow->{$server}) {
9230: $checkednow = ' checked="checked"';
9231: }
9232: }
1.371 raeburn 9233: if (ref($curroffloadoth) eq 'HASH') {
9234: if ($curroffloadoth->{$server}) {
9235: $checkedoth = ' checked="checked"';
9236: }
9237: }
1.145 raeburn 9238: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
9239: $datatable .= '<tr'.$css_class.'>
9240: <td rowspan="2">
1.183 bisitz 9241: <span class="LC_nobreak">'.
9242: &mt('[_1] when busy, offloads to:'
1.261 raeburn 9243: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 9244: '<span class="LC_nobreak">'."\n".
1.261 raeburn 9245: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.371 raeburn 9246: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.183 bisitz 9247: "\n";
1.371 raeburn 9248: if ($other_insts) {
9249: $datatable .= '<br />'.
9250: '<span class="LC_nobreak">'."\n".
9251: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
9252: ' '.&mt('Switch other institutions on next access').'</label></span>'.
9253: "\n";
9254: }
1.145 raeburn 9255: my (%current,%canselect);
1.152 raeburn 9256: my @choices =
9257: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
9258: foreach my $type ('primary','default') {
9259: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 9260: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
9261: my @spares = @{$spareid->{$server}{$type}};
9262: if (@spares > 0) {
1.152 raeburn 9263: if ($othercontrol) {
9264: $current{$type} = join(', ',@spares);
9265: } else {
9266: $current{$type} .= '<table>';
9267: my $numspares = scalar(@spares);
9268: for (my $i=0; $i<@spares; $i++) {
9269: my $rem = $i%($numinrow);
9270: if ($rem == 0) {
9271: if ($i > 0) {
9272: $current{$type} .= '</tr>';
9273: }
9274: $current{$type} .= '<tr>';
1.145 raeburn 9275: }
1.152 raeburn 9276: $current{$type} .= '<td><label><input type="checkbox" name="spare_'.$type.'_'.$server.'" id="spare_'.$type.'_'.$server.'_'.$i.'" checked="checked" value="'.$spareid->{$server}{$type}[$i].'" onclick="updateNewSpares(this.form,'."'$server'".');" /> '.
9277: $spareid->{$server}{$type}[$i].
9278: '</label></td>'."\n";
9279: }
9280: my $rem = @spares%($numinrow);
9281: my $colsleft = $numinrow - $rem;
9282: if ($colsleft > 1 ) {
9283: $current{$type} .= '<td colspan="'.$colsleft.
9284: '" class="LC_left_item">'.
9285: ' </td>';
9286: } elsif ($colsleft == 1) {
9287: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 9288: }
1.152 raeburn 9289: $current{$type} .= '</tr></table>';
1.150 raeburn 9290: }
1.145 raeburn 9291: }
9292: }
9293: if ($current{$type} eq '') {
9294: $current{$type} = &mt('None specified');
9295: }
1.152 raeburn 9296: if ($othercontrol) {
9297: if ($type eq 'primary') {
9298: $canselect{$type} = $othercontrol;
9299: }
9300: } else {
9301: $canselect{$type} =
9302: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
9303: '<select name="newspare_'.$type.'_'.$server.'" '.
9304: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
9305: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
9306: if (@choices > 0) {
9307: foreach my $lonhost (@choices) {
9308: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
9309: }
9310: }
9311: $canselect{$type} .= '</select>'."\n";
9312: }
9313: } else {
9314: $current{$type} = &mt('Could not be determined');
9315: if ($type eq 'primary') {
9316: $canselect{$type} = $othercontrol;
9317: }
1.145 raeburn 9318: }
1.152 raeburn 9319: if ($type eq 'default') {
9320: $datatable .= '<tr'.$css_class.'>';
9321: }
9322: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
9323: '<td>'.$current{$type}.'</td>'."\n".
9324: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 9325: }
9326: $itemcount ++;
9327: }
9328: }
9329: $$rowtotal += $itemcount;
9330: return $datatable;
9331: }
9332:
1.152 raeburn 9333: sub possible_newspares {
9334: my ($server,$currspares,$serverhomes,$altids) = @_;
9335: my $serverhostname = &Apache::lonnet::hostname($server);
9336: my %excluded;
9337: if ($serverhostname ne '') {
9338: %excluded = (
9339: $serverhostname => 1,
9340: );
9341: }
9342: if (ref($currspares) eq 'HASH') {
9343: foreach my $type (keys(%{$currspares})) {
9344: if (ref($currspares->{$type}) eq 'ARRAY') {
9345: if (@{$currspares->{$type}} > 0) {
9346: foreach my $curr (@{$currspares->{$type}}) {
9347: my $hostname = &Apache::lonnet::hostname($curr);
9348: $excluded{$hostname} = 1;
9349: }
9350: }
9351: }
9352: }
9353: }
9354: my @choices;
9355: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
9356: if (keys(%{$serverhomes}) > 1) {
9357: foreach my $name (sort(keys(%{$serverhomes}))) {
9358: unless ($excluded{$name}) {
9359: if (exists($altids->{$serverhomes->{$name}})) {
9360: push(@choices,$altids->{$serverhomes->{$name}});
9361: } else {
9362: push(@choices,$serverhomes->{$name});
1.145 raeburn 9363: }
9364: }
9365: }
9366: }
9367: }
1.152 raeburn 9368: return sort(@choices);
1.145 raeburn 9369: }
9370:
1.150 raeburn 9371: sub print_loadbalancing {
9372: my ($dom,$settings,$rowtotal) = @_;
9373: my $primary_id = &Apache::lonnet::domain($dom,'primary');
9374: my $intdom = &Apache::lonnet::internet_dom($primary_id);
9375: my $numinrow = 1;
9376: my $datatable;
9377: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 9378: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 9379: if (ref($settings) eq 'HASH') {
9380: %existing = %{$settings};
9381: }
9382: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
9383: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 9384: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 9385: } else {
9386: return;
9387: }
9388: my ($othertitle,$usertypes,$types) =
9389: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 9390: my $rownum = 8;
1.150 raeburn 9391: if (ref($types) eq 'ARRAY') {
9392: $rownum += scalar(@{$types});
9393: }
1.171 raeburn 9394: my @css_class = ('LC_odd_row','LC_even_row');
9395: my $balnum = 0;
9396: my $islast;
9397: my (@toshow,$disabledtext);
9398: if (keys(%currbalancer) > 0) {
9399: @toshow = sort(keys(%currbalancer));
9400: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
9401: push(@toshow,'');
9402: }
9403: } else {
9404: @toshow = ('');
9405: $disabledtext = &mt('No existing load balancer');
9406: }
9407: foreach my $lonhost (@toshow) {
9408: if ($balnum == scalar(@toshow)-1) {
9409: $islast = 1;
9410: } else {
9411: $islast = 0;
9412: }
9413: my $cssidx = $balnum%2;
9414: my $targets_div_style = 'display: none';
9415: my $disabled_div_style = 'display: block';
9416: my $homedom_div_style = 'display: none';
9417: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 9418: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9419: '<p>';
9420: if ($lonhost eq '') {
1.210 raeburn 9421: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 9422: if (keys(%currbalancer) > 0) {
9423: $datatable .= &mt('Add balancer:');
9424: } else {
9425: $datatable .= &mt('Enable balancer:');
9426: }
9427: $datatable .= ' '.
9428: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
9429: ' id="loadbalancing_lonhost_'.$balnum.'"'.
9430: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
9431: '<option value="" selected="selected">'.&mt('None').
9432: '</option>'."\n";
9433: foreach my $server (sort(keys(%servers))) {
9434: next if ($currbalancer{$server});
9435: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
9436: }
1.210 raeburn 9437: $datatable .=
1.171 raeburn 9438: '</select>'."\n".
9439: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
9440: } else {
9441: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
9442: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
9443: &mt('Stop balancing').'</label>'.
9444: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
9445: $targets_div_style = 'display: block';
9446: $disabled_div_style = 'display: none';
9447: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
9448: $homedom_div_style = 'display: block';
9449: }
9450: }
1.306 raeburn 9451: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9452: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
9453: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
9454: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
9455: my ($numspares,@spares) = &count_servers($lonhost,%servers);
9456: my @sparestypes = ('primary','default');
9457: my %typetitles = &sparestype_titles();
1.284 raeburn 9458: my %hostherechecked = (
9459: no => ' checked="checked"',
9460: );
1.342 raeburn 9461: my %balcookiechecked = (
1.425 raeburn 9462: no => ' checked="checked"',
1.342 raeburn 9463: );
1.171 raeburn 9464: foreach my $sparetype (@sparestypes) {
9465: my $targettable;
9466: for (my $i=0; $i<$numspares; $i++) {
9467: my $checked;
9468: if (ref($currtargets{$lonhost}) eq 'HASH') {
9469: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9470: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9471: $checked = ' checked="checked"';
9472: }
9473: }
9474: }
9475: my ($chkboxval,$disabled);
9476: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
9477: $chkboxval = $spares[$i];
9478: }
9479: if (exists($currbalancer{$spares[$i]})) {
9480: $disabled = ' disabled="disabled"';
9481: }
1.210 raeburn 9482: $targettable .=
1.253 raeburn 9483: '<td><span class="LC_nobreak"><label>'.
9484: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 9485: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
1.253 raeburn 9486: '</span></label></span></td>';
1.171 raeburn 9487: my $rem = $i%($numinrow);
9488: if ($rem == 0) {
9489: if (($i > 0) && ($i < $numspares-1)) {
9490: $targettable .= '</tr>';
9491: }
9492: if ($i < $numspares-1) {
9493: $targettable .= '<tr>';
1.150 raeburn 9494: }
9495: }
9496: }
1.171 raeburn 9497: if ($targettable ne '') {
9498: my $rem = $numspares%($numinrow);
9499: my $colsleft = $numinrow - $rem;
9500: if ($colsleft > 1 ) {
9501: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9502: ' </td>';
9503: } elsif ($colsleft == 1) {
9504: $targettable .= '<td class="LC_left_item"> </td>';
9505: }
9506: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
9507: '<table><tr>'.$targettable.'</tr></table><br />';
9508: }
1.284 raeburn 9509: $hostherechecked{$sparetype} = '';
9510: if (ref($currtargets{$lonhost}) eq 'HASH') {
9511: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9512: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9513: $hostherechecked{$sparetype} = ' checked="checked"';
9514: $hostherechecked{'no'} = '';
9515: }
9516: }
9517: }
9518: }
1.342 raeburn 9519: if ($currcookies{$lonhost}) {
9520: %balcookiechecked = (
9521: yes => ' checked="checked"',
9522: );
9523: }
1.284 raeburn 9524: $datatable .= &mt('Hosting on balancer itself').'<br />'.
9525: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
9526: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
9527: foreach my $sparetype (@sparestypes) {
9528: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
9529: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
9530: '</i></label><br />';
1.171 raeburn 9531: }
1.342 raeburn 9532: $datatable .= &mt('Use balancer cookie').'<br />'.
9533: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
9534: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
9535: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
9536: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
9537: '</div></td></tr>'.
1.171 raeburn 9538: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
9539: $othertitle,$usertypes,$types,\%servers,
9540: \%currbalancer,$lonhost,
9541: $targets_div_style,$homedom_div_style,
9542: $css_class[$cssidx],$balnum,$islast);
9543: $$rowtotal += $rownum;
9544: $balnum ++;
9545: }
9546: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
9547: return $datatable;
9548: }
9549:
9550: sub get_loadbalancers_config {
1.342 raeburn 9551: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 9552: return unless ((ref($servers) eq 'HASH') &&
9553: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 9554: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
9555: (ref($currcookies) eq 'HASH'));
1.171 raeburn 9556: if (keys(%{$existing}) > 0) {
9557: my $oldlonhost;
9558: foreach my $key (sort(keys(%{$existing}))) {
9559: if ($key eq 'lonhost') {
9560: $oldlonhost = $existing->{'lonhost'};
9561: $currbalancer->{$oldlonhost} = 1;
9562: } elsif ($key eq 'targets') {
9563: if ($oldlonhost) {
9564: $currtargets->{$oldlonhost} = $existing->{'targets'};
9565: }
9566: } elsif ($key eq 'rules') {
9567: if ($oldlonhost) {
9568: $currrules->{$oldlonhost} = $existing->{'rules'};
9569: }
9570: } elsif (ref($existing->{$key}) eq 'HASH') {
9571: $currbalancer->{$key} = 1;
9572: $currtargets->{$key} = $existing->{$key}{'targets'};
9573: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 9574: if ($existing->{$key}{'cookie'}) {
9575: $currcookies->{$key} = 1;
9576: }
1.150 raeburn 9577: }
9578: }
1.171 raeburn 9579: } else {
9580: my ($balancerref,$targetsref) =
9581: &Apache::lonnet::get_lonbalancer_config($servers);
9582: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
9583: foreach my $server (sort(keys(%{$balancerref}))) {
9584: $currbalancer->{$server} = 1;
9585: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 9586: }
9587: }
9588: }
1.171 raeburn 9589: return;
1.150 raeburn 9590: }
9591:
9592: sub loadbalancing_rules {
9593: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 9594: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
9595: $css_class,$balnum,$islast) = @_;
1.150 raeburn 9596: my $output;
1.171 raeburn 9597: my $num = 0;
1.210 raeburn 9598: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 9599: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
9600: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
9601: foreach my $type (@{$alltypes}) {
1.171 raeburn 9602: $num ++;
1.150 raeburn 9603: my $current;
9604: if (ref($currrules) eq 'HASH') {
9605: $current = $currrules->{$type};
9606: }
1.253 raeburn 9607: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 9608: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 9609: $current = '';
9610: }
9611: }
9612: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 9613: $servers,$currbalancer,$lonhost,$dom,
9614: $targets_div_style,$homedom_div_style,
9615: $css_class,$balnum,$num,$islast);
1.150 raeburn 9616: }
9617: }
9618: return $output;
9619: }
9620:
9621: sub loadbalancing_titles {
9622: my ($dom,$intdom,$usertypes,$types) = @_;
9623: my %othertypes = (
9624: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
9625: '_LC_author' => &mt('Users from [_1] with author role',$dom),
9626: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
9627: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 9628: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
9629: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 9630: );
1.209 raeburn 9631: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 9632: my @available;
1.150 raeburn 9633: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9634: @available = @{$types};
1.150 raeburn 9635: }
1.302 raeburn 9636: unless (grep(/^default$/,@available)) {
9637: push(@available,'default');
9638: }
9639: unshift(@alltypes,@available);
1.150 raeburn 9640: my %titles;
9641: foreach my $type (@alltypes) {
9642: if ($type =~ /^_LC_/) {
9643: $titles{$type} = $othertypes{$type};
9644: } elsif ($type eq 'default') {
9645: $titles{$type} = &mt('All users from [_1]',$dom);
9646: if (ref($types) eq 'ARRAY') {
9647: if (@{$types} > 0) {
9648: $titles{$type} = &mt('Other users from [_1]',$dom);
9649: }
9650: }
9651: } elsif (ref($usertypes) eq 'HASH') {
9652: $titles{$type} = $usertypes->{$type};
9653: }
9654: }
9655: return (\@alltypes,\%othertypes,\%titles);
9656: }
9657:
9658: sub loadbalance_rule_row {
1.171 raeburn 9659: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
9660: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 9661: my @rulenames;
1.150 raeburn 9662: my %ruletitles = &offloadtype_text();
1.209 raeburn 9663: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 9664: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 9665: } else {
1.209 raeburn 9666: @rulenames = ('default','homeserver');
9667: if ($type eq '_LC_external') {
9668: push(@rulenames,'externalbalancer');
9669: } else {
9670: push(@rulenames,'specific');
9671: }
9672: push(@rulenames,'none');
1.150 raeburn 9673: }
9674: my $style = $targets_div_style;
1.253 raeburn 9675: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 9676: $style = $homedom_div_style;
9677: }
1.171 raeburn 9678: my $space;
9679: if ($islast && $num == 1) {
1.317 raeburn 9680: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 9681: }
1.210 raeburn 9682: my $output =
1.306 raeburn 9683: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 9684: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
9685: '<td valaign="top">'.$space.
9686: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 9687: for (my $i=0; $i<@rulenames; $i++) {
9688: my $rule = $rulenames[$i];
9689: my ($checked,$extra);
9690: if ($rulenames[$i] eq 'default') {
9691: $rule = '';
9692: }
9693: if ($rulenames[$i] eq 'specific') {
9694: if (ref($servers) eq 'HASH') {
9695: my $default;
9696: if (($current ne '') && (exists($servers->{$current}))) {
9697: $checked = ' checked="checked"';
9698: }
9699: unless ($checked) {
9700: $default = ' selected="selected"';
9701: }
1.210 raeburn 9702: $extra =
1.171 raeburn 9703: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
9704: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
9705: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
9706: '<option value=""'.$default.'></option>'."\n";
9707: foreach my $server (sort(keys(%{$servers}))) {
9708: if (ref($currbalancer) eq 'HASH') {
9709: next if (exists($currbalancer->{$server}));
9710: }
1.150 raeburn 9711: my $selected;
1.171 raeburn 9712: if ($server eq $current) {
1.150 raeburn 9713: $selected = ' selected="selected"';
9714: }
1.171 raeburn 9715: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 9716: }
9717: $extra .= '</select>';
9718: }
9719: } elsif ($rule eq $current) {
9720: $checked = ' checked="checked"';
9721: }
9722: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 9723: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
9724: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
9725: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 9726: ')"'.$checked.' /> ';
9727: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
9728: $output .= $ruletitles{'particular'};
9729: } else {
9730: $output .= $ruletitles{$rulenames[$i]};
9731: }
9732: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 9733: }
9734: $output .= '</div></td></tr>'."\n";
9735: return $output;
9736: }
9737:
9738: sub offloadtype_text {
9739: my %ruletitles = &Apache::lonlocal::texthash (
9740: 'default' => 'Offloads to default destinations',
9741: 'homeserver' => "Offloads to user's home server",
9742: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
9743: 'specific' => 'Offloads to specific server',
1.161 raeburn 9744: 'none' => 'No offload',
1.209 raeburn 9745: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
9746: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 9747: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 9748: );
9749: return %ruletitles;
9750: }
9751:
9752: sub sparestype_titles {
9753: my %typestitles = &Apache::lonlocal::texthash (
9754: 'primary' => 'primary',
9755: 'default' => 'default',
9756: );
9757: return %typestitles;
9758: }
9759:
1.28 raeburn 9760: sub contact_titles {
9761: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 9762: 'supportemail' => 'Support E-mail address',
9763: 'adminemail' => 'Default Server Admin E-mail address',
9764: 'errormail' => 'Error reports to be e-mailed to',
9765: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 9766: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
9767: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 9768: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
9769: 'requestsmail' => 'E-mail from course requests requiring approval',
9770: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 9771: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350 raeburn 9772: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.378 raeburn 9773: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
9774: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.340 raeburn 9775: 'errorweights' => 'Weights used to compute error count',
9776: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 9777: );
9778: my %short_titles = &Apache::lonlocal::texthash (
9779: adminemail => 'Admin E-mail address',
9780: supportemail => 'Support E-mail',
9781: );
9782: return (\%titles,\%short_titles);
9783: }
9784:
1.286 raeburn 9785: sub helpform_fields {
9786: my %titles = &Apache::lonlocal::texthash (
9787: 'username' => 'Name',
9788: 'user' => 'Username/domain',
9789: 'phone' => 'Phone',
9790: 'cc' => 'Cc e-mail',
9791: 'course' => 'Course Details',
9792: 'section' => 'Sections',
1.289 raeburn 9793: 'screenshot' => 'File upload',
1.286 raeburn 9794: );
9795: my @fields = ('username','phone','user','course','section','cc','screenshot');
9796: my %possoptions = (
9797: username => ['yes','no','req'],
1.289 raeburn 9798: phone => ['yes','no','req'],
1.286 raeburn 9799: user => ['yes','no'],
1.289 raeburn 9800: cc => ['yes','no'],
1.286 raeburn 9801: course => ['yes','no'],
9802: section => ['yes','no'],
9803: screenshot => ['yes','no'],
9804: );
9805: my %fieldoptions = &Apache::lonlocal::texthash (
9806: 'yes' => 'Optional',
9807: 'req' => 'Required',
9808: 'no' => "Not shown",
9809: );
9810: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
9811: }
9812:
1.72 raeburn 9813: sub tool_titles {
9814: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 9815: aboutme => 'Personal web page',
1.86 raeburn 9816: blog => 'Blog',
9817: portfolio => 'Portfolio',
1.430 raeburn 9818: portaccess => 'Share portfolio files',
1.413 raeburn 9819: timezone => 'Can set time zone',
1.88 bisitz 9820: official => 'Official courses (with institutional codes)',
9821: unofficial => 'Unofficial courses',
1.98 raeburn 9822: community => 'Communities',
1.216 raeburn 9823: textbook => 'Textbook courses',
1.271 raeburn 9824: placement => 'Placement tests',
1.86 raeburn 9825: );
1.72 raeburn 9826: return %titles;
9827: }
9828:
1.101 raeburn 9829: sub courserequest_titles {
9830: my %titles = &Apache::lonlocal::texthash (
9831: official => 'Official',
9832: unofficial => 'Unofficial',
9833: community => 'Communities',
1.216 raeburn 9834: textbook => 'Textbook',
1.271 raeburn 9835: placement => 'Placement tests',
1.325 raeburn 9836: lti => 'LTI Provider',
1.101 raeburn 9837: norequest => 'Not allowed',
1.325 raeburn 9838: approval => 'Approval by DC',
1.101 raeburn 9839: validate => 'With validation',
9840: autolimit => 'Numerical limit',
1.103 raeburn 9841: unlimited => '(blank for unlimited)',
1.101 raeburn 9842: );
9843: return %titles;
9844: }
9845:
1.163 raeburn 9846: sub authorrequest_titles {
9847: my %titles = &Apache::lonlocal::texthash (
9848: norequest => 'Not allowed',
9849: approval => 'Approval by Dom. Coord.',
9850: automatic => 'Automatic approval',
9851: );
9852: return %titles;
1.210 raeburn 9853: }
1.163 raeburn 9854:
1.101 raeburn 9855: sub courserequest_conditions {
9856: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 9857: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 9858: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 9859: );
9860: return %conditions;
9861: }
9862:
9863:
1.27 raeburn 9864: sub print_usercreation {
1.30 raeburn 9865: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 9866: my $numinrow = 4;
1.28 raeburn 9867: my $datatable;
9868: if ($position eq 'top') {
1.30 raeburn 9869: $$rowtotal ++;
1.34 raeburn 9870: my $rowcount = 0;
1.32 raeburn 9871: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 9872: if (ref($rules) eq 'HASH') {
9873: if (keys(%{$rules}) > 0) {
1.32 raeburn 9874: $datatable .= &user_formats_row('username',$settings,$rules,
9875: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 9876: $$rowtotal ++;
1.32 raeburn 9877: $rowcount ++;
9878: }
9879: }
9880: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
9881: if (ref($idrules) eq 'HASH') {
9882: if (keys(%{$idrules}) > 0) {
9883: $datatable .= &user_formats_row('id',$settings,$idrules,
9884: $idruleorder,$numinrow,$rowcount);
9885: $$rowtotal ++;
9886: $rowcount ++;
1.28 raeburn 9887: }
9888: }
1.39 raeburn 9889: if ($rowcount == 0) {
9890: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
9891: $$rowtotal ++;
9892: $rowcount ++;
9893: }
1.34 raeburn 9894: } elsif ($position eq 'middle') {
1.224 raeburn 9895: my @creators = ('author','course','requestcrs');
1.37 raeburn 9896: my ($rules,$ruleorder) =
9897: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 9898: my %lt = &usercreation_types();
9899: my %checked;
9900: if (ref($settings) eq 'HASH') {
9901: if (ref($settings->{'cancreate'}) eq 'HASH') {
9902: foreach my $item (@creators) {
9903: $checked{$item} = $settings->{'cancreate'}{$item};
9904: }
9905: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
9906: foreach my $item (@creators) {
9907: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
9908: $checked{$item} = 'none';
9909: }
9910: }
9911: }
9912: }
9913: my $rownum = 0;
9914: foreach my $item (@creators) {
9915: $rownum ++;
1.224 raeburn 9916: if ($checked{$item} eq '') {
9917: $checked{$item} = 'any';
1.34 raeburn 9918: }
9919: my $css_class;
9920: if ($rownum%2) {
9921: $css_class = '';
9922: } else {
9923: $css_class = ' class="LC_odd_row" ';
9924: }
9925: $datatable .= '<tr'.$css_class.'>'.
9926: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 9927: '</span></td><td style="text-align: right">';
1.224 raeburn 9928: my @options = ('any');
9929: if (ref($rules) eq 'HASH') {
9930: if (keys(%{$rules}) > 0) {
9931: push(@options,('official','unofficial'));
1.37 raeburn 9932: }
9933: }
1.224 raeburn 9934: push(@options,'none');
1.37 raeburn 9935: foreach my $option (@options) {
1.50 raeburn 9936: my $type = 'radio';
1.34 raeburn 9937: my $check = ' ';
1.224 raeburn 9938: if ($checked{$item} eq $option) {
9939: $check = ' checked="checked" ';
1.34 raeburn 9940: }
9941: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 9942: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 9943: $item.'" value="'.$option.'"'.$check.'/> '.
9944: $lt{$option}.'</label> </span>';
9945: }
9946: $datatable .= '</td></tr>';
9947: }
1.28 raeburn 9948: } else {
9949: my @contexts = ('author','course','domain');
1.325 raeburn 9950: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 9951: my %checked;
9952: if (ref($settings) eq 'HASH') {
9953: if (ref($settings->{'authtypes'}) eq 'HASH') {
9954: foreach my $item (@contexts) {
9955: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
9956: foreach my $auth (@authtypes) {
9957: if ($settings->{'authtypes'}{$item}{$auth}) {
9958: $checked{$item}{$auth} = ' checked="checked" ';
9959: }
9960: }
9961: }
9962: }
1.27 raeburn 9963: }
1.35 raeburn 9964: } else {
9965: foreach my $item (@contexts) {
1.36 raeburn 9966: foreach my $auth (@authtypes) {
1.35 raeburn 9967: $checked{$item}{$auth} = ' checked="checked" ';
9968: }
9969: }
1.27 raeburn 9970: }
1.28 raeburn 9971: my %title = &context_names();
9972: my %authname = &authtype_names();
9973: my $rownum = 0;
9974: my $css_class;
9975: foreach my $item (@contexts) {
9976: if ($rownum%2) {
9977: $css_class = '';
9978: } else {
9979: $css_class = ' class="LC_odd_row" ';
9980: }
1.30 raeburn 9981: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 9982: '<td>'.$title{$item}.
9983: '</td><td class="LC_left_item">'.
9984: '<span class="LC_nobreak">';
9985: foreach my $auth (@authtypes) {
9986: $datatable .= '<label>'.
9987: '<input type="checkbox" name="'.$item.'_auth" '.
9988: $checked{$item}{$auth}.' value="'.$auth.'" />'.
9989: $authname{$auth}.'</label> ';
9990: }
9991: $datatable .= '</span></td></tr>';
9992: $rownum ++;
1.27 raeburn 9993: }
1.30 raeburn 9994: $$rowtotal += $rownum;
1.27 raeburn 9995: }
9996: return $datatable;
9997: }
9998:
1.224 raeburn 9999: sub print_selfcreation {
10000: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 10001: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
10002: $emaildomain,$datatable);
1.224 raeburn 10003: if (ref($settings) eq 'HASH') {
10004: if (ref($settings->{'cancreate'}) eq 'HASH') {
10005: $createsettings = $settings->{'cancreate'};
1.236 raeburn 10006: if (ref($createsettings) eq 'HASH') {
10007: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
10008: @selfcreate = @{$createsettings->{'selfcreate'}};
10009: } elsif ($createsettings->{'selfcreate'} ne '') {
10010: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
10011: @selfcreate = ('email','login','sso');
10012: } elsif ($createsettings->{'selfcreate'} ne 'none') {
10013: @selfcreate = ($createsettings->{'selfcreate'});
10014: }
10015: }
10016: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
10017: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 10018: }
1.305 raeburn 10019: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
10020: $emailoptions = $createsettings->{'emailoptions'};
10021: }
1.303 raeburn 10022: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
10023: $emailverified = $createsettings->{'emailverified'};
10024: }
10025: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
10026: $emaildomain = $createsettings->{'emaildomain'};
10027: }
1.224 raeburn 10028: }
10029: }
10030: }
10031: my %radiohash;
10032: my $numinrow = 4;
10033: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 10034: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 10035: if ($position eq 'top') {
10036: my %choices = &Apache::lonlocal::texthash (
10037: cancreate_login => 'Institutional Login',
10038: cancreate_sso => 'Institutional Single Sign On',
10039: );
10040: my @toggles = sort(keys(%choices));
10041: my %defaultchecked = (
10042: 'cancreate_login' => 'off',
10043: 'cancreate_sso' => 'off',
10044: );
1.228 raeburn 10045: my ($onclick,$itemcount);
1.224 raeburn 10046: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
10047: \%choices,$itemcount,$onclick);
1.228 raeburn 10048: $$rowtotal += $itemcount;
1.425 raeburn 10049:
1.224 raeburn 10050: if (ref($usertypes) eq 'HASH') {
10051: if (keys(%{$usertypes}) > 0) {
10052: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
10053: $dom,$numinrow,$othertitle,
1.305 raeburn 10054: 'statustocreate',$rowtotal);
1.224 raeburn 10055: $$rowtotal ++;
10056: }
10057: }
1.240 raeburn 10058: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
10059: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10060: $fieldtitles{'inststatus'} = &mt('Institutional status');
10061: my $rem;
10062: my $numperrow = 2;
10063: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
10064: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 10065: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 10066: '<td class="LC_left_item">'."\n".
1.334 raeburn 10067: '<table>'."\n";
1.240 raeburn 10068: for (my $i=0; $i<@fields; $i++) {
10069: $rem = $i%($numperrow);
10070: if ($rem == 0) {
10071: if ($i > 0) {
10072: $datatable .= '</tr>';
10073: }
10074: $datatable .= '<tr>';
10075: }
10076: my $currval;
1.248 raeburn 10077: if (ref($createsettings) eq 'HASH') {
10078: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
10079: $currval = $createsettings->{'shibenv'}{$fields[$i]};
10080: }
1.240 raeburn 10081: }
10082: $datatable .= '<td class="LC_left_item">'.
10083: '<span class="LC_nobreak">'.
10084: '<input type="text" name="shibenv_'.$fields[$i].'" '.
10085: 'value="'.$currval.'" size="10" /> '.
10086: $fieldtitles{$fields[$i]}.'</span></td>';
10087: }
10088: my $colsleft = $numperrow - $rem;
10089: if ($colsleft > 1 ) {
10090: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10091: ' </td>';
10092: } elsif ($colsleft == 1) {
10093: $datatable .= '<td class="LC_left_item"> </td>';
10094: }
10095: $datatable .= '</tr></table></td></tr>';
10096: $$rowtotal ++;
1.224 raeburn 10097: } elsif ($position eq 'middle') {
10098: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 10099: my @posstypes;
1.224 raeburn 10100: if (ref($types) eq 'ARRAY') {
1.302 raeburn 10101: @posstypes = @{$types};
10102: }
10103: unless (grep(/^default$/,@posstypes)) {
10104: push(@posstypes,'default');
10105: }
10106: my %usertypeshash;
10107: if (ref($usertypes) eq 'HASH') {
10108: %usertypeshash = %{$usertypes};
10109: }
10110: $usertypeshash{'default'} = $othertitle;
10111: foreach my $status (@posstypes) {
10112: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
10113: $numinrow,$$rowtotal,\%usertypeshash);
10114: $$rowtotal ++;
1.224 raeburn 10115: }
10116: } else {
1.236 raeburn 10117: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 10118: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 10119: );
10120: my @toggles = sort(keys(%choices));
10121: my %defaultchecked = (
10122: 'cancreate_email' => 'off',
10123: );
1.305 raeburn 10124: my $customclass = 'LC_selfcreate_email';
10125: my $classprefix = 'LC_canmodify_emailusername_';
10126: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 10127: my $display = 'none';
1.305 raeburn 10128: my $rowstyle = 'display:none';
1.236 raeburn 10129: if (grep(/^\Qemail\E$/,@selfcreate)) {
10130: $display = 'block';
1.305 raeburn 10131: $rowstyle = 'display:table-row';
1.236 raeburn 10132: }
1.305 raeburn 10133: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
10134: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
10135: \%choices,$$rowtotal,$onclick);
10136: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
10137: $rowstyle);
10138: $$rowtotal ++;
10139: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
10140: $rowstyle);
10141: $$rowtotal ++;
10142: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 10143: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 10144: my ($emailrules,$emailruleorder) =
10145: &Apache::lonnet::inst_userrules($dom,'email');
10146: my $primary_id = &Apache::lonnet::domain($dom,'primary');
10147: my $intdom = &Apache::lonnet::internet_dom($primary_id);
10148: if (ref($types) eq 'ARRAY') {
10149: @posstypes = @{$types};
10150: }
10151: if (@posstypes) {
10152: unless (grep(/^default$/,@posstypes)) {
10153: push(@posstypes,'default');
1.302 raeburn 10154: }
10155: if (ref($usertypes) eq 'HASH') {
10156: %usertypeshash = %{$usertypes};
10157: }
1.305 raeburn 10158: my $currassign;
10159: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
10160: $currassign = {
10161: selfassign => $domdefaults{'inststatusguest'},
10162: };
10163: @ordered = @{$domdefaults{'inststatusguest'}};
10164: } else {
10165: $currassign = { selfassign => [] };
10166: }
10167: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
10168: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
10169: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
10170: $numinrow,$othertitle,'selfassign',
10171: $rowtotal,$onclicktypes,$customclass,
10172: $rowstyle);
10173: $$rowtotal ++;
1.302 raeburn 10174: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10175: foreach my $status (@posstypes) {
10176: my $css_class;
10177: if ($$rowtotal%2) {
10178: $css_class = 'LC_odd_row ';
10179: }
10180: $css_class .= $customclass;
10181: my $rowid = $optionsprefix.$status;
10182: my $hidden = 1;
10183: my $currstyle = 'display:none';
10184: if (grep(/^\Q$status\E$/,@ordered)) {
10185: $currstyle = $rowstyle;
1.425 raeburn 10186: $hidden = 0;
1.305 raeburn 10187: }
10188: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10189: $emailrules,$emailruleorder,$settings,$status,$rowid,
10190: $usertypeshash{$status},$css_class,$currstyle,$intdom);
10191: unless ($hidden) {
10192: $$rowtotal ++;
10193: }
1.224 raeburn 10194: }
1.302 raeburn 10195: } else {
1.305 raeburn 10196: my $css_class;
10197: if ($$rowtotal%2) {
10198: $css_class = 'LC_odd_row ';
10199: }
10200: $css_class .= $customclass;
1.302 raeburn 10201: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10202: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10203: $emailrules,$emailruleorder,$settings,'default','',
10204: $othertitle,$css_class,$rowstyle,$intdom);
10205: $$rowtotal ++;
1.224 raeburn 10206: }
10207: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 10208: $numinrow = 1;
1.305 raeburn 10209: if (@posstypes) {
10210: foreach my $status (@posstypes) {
10211: my $rowid = $classprefix.$status;
10212: my $datarowstyle = 'display:none';
1.425 raeburn 10213: if (grep(/^\Q$status\E$/,@ordered)) {
10214: $datarowstyle = $rowstyle;
1.305 raeburn 10215: }
10216: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
10217: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10218: $infotitles,$rowid,$customclass,$datarowstyle);
10219: unless ($datarowstyle eq 'display:none') {
10220: $$rowtotal ++;
10221: }
1.224 raeburn 10222: }
1.305 raeburn 10223: } else {
10224: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
10225: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10226: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 10227: }
10228: }
10229: return $datatable;
10230: }
10231:
1.305 raeburn 10232: sub selfcreate_javascript {
10233: return <<"ENDSCRIPT";
10234:
10235: <script type="text/javascript">
10236: // <![CDATA[
10237:
10238: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
10239: var x = document.getElementsByClassName(target);
10240: var insttypes = 0;
10241: var insttypeRegExp = new RegExp(prefix);
10242: if ((x.length != undefined) && (x.length > 0)) {
10243: if (form.elements[radio].length != undefined) {
10244: for (var i=0; i<form.elements[radio].length; i++) {
10245: if (form.elements[radio][i].checked) {
10246: if (form.elements[radio][i].value == 1) {
10247: for (var j=0; j<x.length; j++) {
10248: if (x[j].id == 'undefined') {
10249: x[j].style.display = 'table-row';
10250: } else if (insttypeRegExp.test(x[j].id)) {
10251: insttypes ++;
10252: } else {
10253: x[j].style.display = 'table-row';
10254: }
10255: }
10256: } else {
10257: for (var j=0; j<x.length; j++) {
10258: x[j].style.display = 'none';
10259: }
1.236 raeburn 10260: }
1.305 raeburn 10261: break;
10262: }
10263: }
10264: if (insttypes > 0) {
10265: toggleDataRow(form,checkbox,target,altprefix);
10266: toggleDataRow(form,checkbox,target,prefix,1);
10267: }
10268: }
10269: }
10270: return;
10271: }
10272:
10273: function toggleDataRow(form,checkbox,target,prefix,docount) {
10274: if (form.elements[checkbox].length != undefined) {
10275: var count = 0;
10276: if (docount) {
10277: for (var i=0; i<form.elements[checkbox].length; i++) {
10278: if (form.elements[checkbox][i].checked) {
10279: count ++;
1.236 raeburn 10280: }
1.305 raeburn 10281: }
10282: }
10283: for (var i=0; i<form.elements[checkbox].length; i++) {
10284: var type = form.elements[checkbox][i].value;
10285: if (document.getElementById(prefix+type)) {
10286: if (form.elements[checkbox][i].checked) {
10287: document.getElementById(prefix+type).style.display = 'table-row';
10288: if (count % 2 == 1) {
10289: document.getElementById(prefix+type).className = target+' LC_odd_row';
10290: } else {
10291: document.getElementById(prefix+type).className = target;
1.236 raeburn 10292: }
1.305 raeburn 10293: count ++;
1.236 raeburn 10294: } else {
1.305 raeburn 10295: document.getElementById(prefix+type).style.display = 'none';
10296: }
10297: }
10298: }
10299: }
10300: return;
10301: }
10302:
10303: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
10304: var caller = radio+'_'+status;
10305: if (form.elements[caller].length != undefined) {
10306: for (var i=0; i<form.elements[caller].length; i++) {
10307: if (form.elements[caller][i].checked) {
10308: if (document.getElementById(altprefix+'_inst_'+status)) {
10309: var curr = form.elements[caller][i].value;
10310: if (prefix) {
10311: document.getElementById(prefix+'_'+status).style.display = 'none';
10312: }
10313: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
10314: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
10315: if (curr == 'custom') {
1.425 raeburn 10316: if (prefix) {
1.305 raeburn 10317: document.getElementById(prefix+'_'+status).style.display = 'inline';
10318: }
10319: } else if (curr == 'inst') {
10320: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
10321: } else if (curr == 'noninst') {
10322: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 10323: }
1.305 raeburn 10324: break;
1.236 raeburn 10325: }
10326: }
10327: }
10328: }
10329: }
10330:
1.305 raeburn 10331: // ]]>
10332: </script>
10333:
10334: ENDSCRIPT
10335: }
10336:
10337: sub noninst_users {
10338: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
1.425 raeburn 10339: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
1.305 raeburn 10340: my $class = 'LC_left_item';
10341: if ($css_class) {
1.425 raeburn 10342: $css_class = ' class="'.$css_class.'"';
1.305 raeburn 10343: }
10344: if ($rowid) {
10345: $rowid = ' id="'.$rowid.'"';
10346: }
10347: if ($rowstyle) {
10348: $rowstyle = ' style="'.$rowstyle.'"';
10349: }
10350: my ($output,$description);
10351: if ($type eq 'default') {
10352: $description = &mt('Requests for: [_1]',$typetitle);
10353: } else {
10354: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
10355: }
10356: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
1.425 raeburn 10357: "<td>$description</td>\n".
1.305 raeburn 10358: '<td class="'.$class.'" colspan="2">'.
10359: '<table><tr>';
1.425 raeburn 10360: my %headers = &Apache::lonlocal::texthash(
1.305 raeburn 10361: approve => 'Processing',
10362: email => 'E-mail',
10363: username => 'Username',
10364: );
10365: foreach my $item ('approve','email','username') {
10366: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 10367: }
1.305 raeburn 10368: $output .= '</tr><tr>';
10369: foreach my $item ('approve','email','username') {
1.306 raeburn 10370: $output .= '<td style="vertical-align: top">';
1.305 raeburn 10371: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
10372: if ($item eq 'approve') {
10373: %choices = &Apache::lonlocal::texthash (
10374: automatic => 'Automatically approved',
10375: approval => 'Queued for approval',
10376: );
10377: @options = ('automatic','approval');
10378: $hashref = $processing;
10379: $defoption = 'automatic';
10380: $name = 'cancreate_emailprocess_'.$type;
10381: } elsif ($item eq 'email') {
10382: %choices = &Apache::lonlocal::texthash (
10383: any => 'Any e-mail',
10384: inst => 'Institutional only',
10385: noninst => 'Non-institutional only',
10386: custom => 'Custom restrictions',
10387: );
10388: @options = ('any','inst','noninst');
10389: my $showcustom;
10390: if (ref($emailrules) eq 'HASH') {
10391: if (keys(%{$emailrules}) > 0) {
10392: push(@options,'custom');
10393: $showcustom = 'cancreate_emailrule';
10394: if (ref($settings) eq 'HASH') {
10395: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
10396: foreach my $rule (@{$settings->{'email_rule'}}) {
10397: if (exists($emailrules->{$rule})) {
10398: $hascustom ++;
10399: }
10400: }
10401: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
10402: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
10403: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
10404: if (exists($emailrules->{$rule})) {
10405: $hascustom ++;
10406: }
10407: }
10408: }
10409: }
10410: }
10411: }
10412: }
10413: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
10414: "'cancreate_emaildomain','$type'".');"';
10415: $hashref = $emailoptions;
10416: $defoption = 'any';
10417: $name = 'cancreate_emailoptions_'.$type;
10418: } elsif ($item eq 'username') {
10419: %choices = &Apache::lonlocal::texthash (
10420: all => 'Same as e-mail',
10421: first => 'Omit @domain',
10422: free => 'Free to choose',
10423: );
10424: @options = ('all','first','free');
10425: $hashref = $emailverified;
10426: $defoption = 'all';
10427: $name = 'cancreate_usernameoptions_'.$type;
10428: }
10429: foreach my $option (@options) {
10430: my $checked;
10431: if (ref($hashref) eq 'HASH') {
10432: if ($type eq '') {
10433: if (!exists($hashref->{'default'})) {
10434: if ($option eq $defoption) {
10435: $checked = ' checked="checked"';
10436: }
10437: } else {
10438: if ($hashref->{'default'} eq $option) {
10439: $checked = ' checked="checked"';
10440: }
1.303 raeburn 10441: }
10442: } else {
1.305 raeburn 10443: if (!exists($hashref->{$type})) {
10444: if ($option eq $defoption) {
10445: $checked = ' checked="checked"';
10446: }
10447: } else {
10448: if ($hashref->{$type} eq $option) {
10449: $checked = ' checked="checked"';
10450: }
1.303 raeburn 10451: }
10452: }
1.305 raeburn 10453: } elsif (($item eq 'email') && ($hascustom)) {
10454: if ($option eq 'custom') {
10455: $checked = ' checked="checked"';
10456: }
10457: } elsif ($option eq $defoption) {
10458: $checked = ' checked="checked"';
10459: }
10460: $output .= '<span class="LC_nobreak"><label>'.
10461: '<input type="radio" name="'.$name.'"'.
10462: $checked.' value="'.$option.'"'.$onclick.' />'.
10463: $choices{$option}.'</label></span><br />';
10464: if ($item eq 'email') {
10465: if ($option eq 'custom') {
10466: my $id = 'cancreate_emailrule_'.$type;
10467: my $display = 'none';
10468: if ($checked) {
10469: $display = 'inline';
1.303 raeburn 10470: }
1.305 raeburn 10471: my $numinrow = 2;
10472: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
10473: '<legend>'.&mt('Disallow').'</legend><table>'.
10474: &user_formats_row('email',$settings,$emailrules,
10475: $emailruleorder,$numinrow,'',$type);
10476: '</table></fieldset>';
10477: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
10478: my %text = &Apache::lonlocal::texthash (
10479: inst => 'must end:',
10480: noninst => 'cannot end:',
10481: );
10482: my $value;
10483: if (ref($emaildomain) eq 'HASH') {
10484: if (ref($emaildomain->{$type}) eq 'HASH') {
1.425 raeburn 10485: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 10486: }
10487: }
1.305 raeburn 10488: if ($value eq '') {
10489: $value = '@'.$intdom;
10490: }
10491: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
10492: my $display = 'none';
10493: if ($checked) {
10494: $display = 'inline';
10495: }
10496: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
10497: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
10498: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
10499: '</div>';
1.303 raeburn 10500: }
10501: }
10502: }
1.305 raeburn 10503: $output .= '</td>'."\n";
1.303 raeburn 10504: }
1.305 raeburn 10505: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 10506: return $output;
10507: }
10508:
1.165 raeburn 10509: sub captcha_choice {
1.305 raeburn 10510: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 10511: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
10512: $vertext,$currver);
1.165 raeburn 10513: my %lt = &captcha_phrases();
10514: $keyentry = 'hidden';
1.354 raeburn 10515: my $colspan=2;
1.165 raeburn 10516: if ($context eq 'cancreate') {
1.224 raeburn 10517: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 10518: } elsif ($context eq 'login') {
10519: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.354 raeburn 10520: } elsif ($context eq 'passwords') {
10521: $rowname = &mt('"Forgot Password" CAPTCHA validation');
10522: $colspan=1;
1.165 raeburn 10523: }
10524: if (ref($settings) eq 'HASH') {
10525: if ($settings->{'captcha'}) {
10526: $checked{$settings->{'captcha'}} = ' checked="checked"';
10527: } else {
10528: $checked{'original'} = ' checked="checked"';
10529: }
10530: if ($settings->{'captcha'} eq 'recaptcha') {
10531: $pubtext = $lt{'pub'};
10532: $privtext = $lt{'priv'};
10533: $keyentry = 'text';
1.269 raeburn 10534: $vertext = $lt{'ver'};
10535: $currver = $settings->{'recaptchaversion'};
10536: if ($currver ne '2') {
10537: $currver = 1;
10538: }
1.165 raeburn 10539: }
10540: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
10541: $currpub = $settings->{'recaptchakeys'}{'public'};
10542: $currpriv = $settings->{'recaptchakeys'}{'private'};
10543: }
10544: } else {
10545: $checked{'original'} = ' checked="checked"';
10546: }
1.305 raeburn 10547: my $css_class;
10548: if ($itemcount%2) {
10549: $css_class = 'LC_odd_row';
10550: }
10551: if ($customcss) {
10552: $css_class .= " $customcss";
10553: }
10554: $css_class =~ s/^\s+//;
10555: if ($css_class) {
10556: $css_class = ' class="'.$css_class.'"';
10557: }
10558: if ($rowstyle) {
10559: $css_class .= ' style="'.$rowstyle.'"';
10560: }
1.169 raeburn 10561: my $output = '<tr'.$css_class.'>'.
1.354 raeburn 10562: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165 raeburn 10563: '<table><tr><td>'."\n";
10564: foreach my $option ('original','recaptcha','notused') {
10565: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
10566: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
10567: $lt{$option}.'</label></span>';
10568: unless ($option eq 'notused') {
10569: $output .= (' 'x2)."\n";
10570: }
10571: }
10572: #
10573: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
10574: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 10575: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 10576: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 10577: #
1.165 raeburn 10578: $output .= '</td></tr>'."\n".
1.305 raeburn 10579: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 10580: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
10581: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
10582: $currpub.'" size="40" /></span><br />'."\n".
10583: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
10584: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 10585: $currpriv.'" size="40" /></span><br />'.
10586: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
10587: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
10588: $currver.'" size="3" /></span><br />'.
10589: '</td></tr></table>'."\n".
1.165 raeburn 10590: '</td></tr>';
10591: return $output;
10592: }
10593:
1.32 raeburn 10594: sub user_formats_row {
1.305 raeburn 10595: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 10596: my $output;
10597: my %text = (
10598: 'username' => 'new usernames',
10599: 'id' => 'IDs',
10600: );
1.409 raeburn 10601: unless (($type eq 'email') || ($type eq 'unamemap')) {
1.305 raeburn 10602: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
10603: $output = '<tr '.$css_class.'>'.
10604: '<td><span class="LC_nobreak">'.
10605: &mt("Format rules to check for $text{$type}: ").
10606: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 10607: }
1.27 raeburn 10608: my $rem;
10609: if (ref($ruleorder) eq 'ARRAY') {
10610: for (my $i=0; $i<@{$ruleorder}; $i++) {
10611: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
10612: my $rem = $i%($numinrow);
10613: if ($rem == 0) {
10614: if ($i > 0) {
10615: $output .= '</tr>';
10616: }
10617: $output .= '<tr>';
10618: }
10619: my $check = ' ';
1.39 raeburn 10620: if (ref($settings) eq 'HASH') {
10621: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
10622: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
10623: $check = ' checked="checked" ';
10624: }
1.305 raeburn 10625: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
10626: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
10627: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
10628: $check = ' checked="checked" ';
10629: }
10630: }
1.27 raeburn 10631: }
10632: }
1.305 raeburn 10633: my $name = $type.'_rule';
10634: if ($type eq 'email') {
10635: $name .= '_'.$status;
10636: }
1.27 raeburn 10637: $output .= '<td class="LC_left_item">'.
10638: '<span class="LC_nobreak"><label>'.
1.311 raeburn 10639: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 10640: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
10641: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
10642: }
10643: }
10644: $rem = @{$ruleorder}%($numinrow);
10645: }
1.305 raeburn 10646: my $colsleft;
10647: if ($rem) {
10648: $colsleft = $numinrow - $rem;
10649: }
1.27 raeburn 10650: if ($colsleft > 1 ) {
10651: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10652: ' </td>';
10653: } elsif ($colsleft == 1) {
10654: $output .= '<td class="LC_left_item"> </td>';
10655: }
1.409 raeburn 10656: $output .= '</tr>';
10657: unless (($type eq 'email') || ($type eq 'unamemap')) {
10658: $output .= '</table></td></tr>';
1.305 raeburn 10659: }
1.27 raeburn 10660: return $output;
10661: }
10662:
1.34 raeburn 10663: sub usercreation_types {
10664: my %lt = &Apache::lonlocal::texthash (
10665: author => 'When adding a co-author',
10666: course => 'When adding a user to a course',
1.100 raeburn 10667: requestcrs => 'When requesting a course',
1.34 raeburn 10668: any => 'Any',
10669: official => 'Institutional only ',
10670: unofficial => 'Non-institutional only',
10671: none => 'None',
10672: );
10673: return %lt;
1.48 raeburn 10674: }
1.34 raeburn 10675:
1.224 raeburn 10676: sub selfcreation_types {
10677: my %lt = &Apache::lonlocal::texthash (
10678: selfcreate => 'User creates own account',
10679: any => 'Any',
10680: official => 'Institutional only ',
10681: unofficial => 'Non-institutional only',
10682: email => 'E-mail address',
10683: login => 'Institutional Login',
10684: sso => 'SSO',
10685: );
10686: }
10687:
1.28 raeburn 10688: sub authtype_names {
10689: my %lt = &Apache::lonlocal::texthash(
10690: int => 'Internal',
10691: krb4 => 'Kerberos 4',
10692: krb5 => 'Kerberos 5',
10693: loc => 'Local',
1.325 raeburn 10694: lti => 'LTI',
1.28 raeburn 10695: );
10696: return %lt;
10697: }
10698:
10699: sub context_names {
10700: my %context_title = &Apache::lonlocal::texthash(
10701: author => 'Creating users when an Author',
10702: course => 'Creating users when in a course',
10703: domain => 'Creating users when a Domain Coordinator',
10704: );
10705: return %context_title;
10706: }
10707:
1.33 raeburn 10708: sub print_usermodification {
10709: my ($position,$dom,$settings,$rowtotal) = @_;
10710: my $numinrow = 4;
10711: my ($context,$datatable,$rowcount);
10712: if ($position eq 'top') {
10713: $rowcount = 0;
10714: $context = 'author';
10715: foreach my $role ('ca','aa') {
10716: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10717: $numinrow,$rowcount);
10718: $$rowtotal ++;
10719: $rowcount ++;
10720: }
1.443 raeburn 10721: } elsif ($position eq 'middle') {
10722: $rowcount = 0;
10723: $context = 'coauthor';
10724: foreach my $role ('ca','aa') {
10725: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10726: $numinrow,$rowcount);
10727: $$rowtotal ++;
10728: $rowcount ++;
10729: }
1.230 raeburn 10730: } elsif ($position eq 'bottom') {
1.33 raeburn 10731: $context = 'course';
10732: $rowcount = 0;
10733: foreach my $role ('st','ep','ta','in','cr') {
10734: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10735: $numinrow,$rowcount);
10736: $$rowtotal ++;
10737: $rowcount ++;
10738: }
10739: }
10740: return $datatable;
10741: }
10742:
1.43 raeburn 10743: sub print_defaults {
1.236 raeburn 10744: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 10745: my $rownum = 0;
1.294 raeburn 10746: my ($datatable,$css_class,$titles);
10747: unless ($position eq 'bottom') {
10748: $titles = &defaults_titles($dom);
10749: }
1.236 raeburn 10750: if ($position eq 'top') {
10751: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
10752: 'datelocale_def','portal_def');
10753: my %defaults;
10754: if (ref($settings) eq 'HASH') {
10755: %defaults = %{$settings};
1.43 raeburn 10756: } else {
1.236 raeburn 10757: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10758: foreach my $item (@items) {
10759: $defaults{$item} = $domdefaults{$item};
10760: }
1.43 raeburn 10761: }
1.236 raeburn 10762: foreach my $item (@items) {
10763: if ($rownum%2) {
10764: $css_class = '';
10765: } else {
10766: $css_class = ' class="LC_odd_row" ';
10767: }
10768: $datatable .= '<tr'.$css_class.'>'.
10769: '<td><span class="LC_nobreak">'.$titles->{$item}.
10770: '</span></td><td class="LC_right_item" colspan="3">';
10771: if ($item eq 'auth_def') {
1.325 raeburn 10772: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 10773: my %shortauth = (
10774: internal => 'int',
10775: krb4 => 'krb4',
10776: krb5 => 'krb5',
1.325 raeburn 10777: localauth => 'loc',
10778: lti => 'lti',
1.236 raeburn 10779: );
10780: my %authnames = &authtype_names();
10781: foreach my $auth (@authtypes) {
10782: my $checked = ' ';
10783: if ($defaults{$item} eq $auth) {
10784: $checked = ' checked="checked" ';
10785: }
10786: $datatable .= '<label><input type="radio" name="'.$item.
10787: '" value="'.$auth.'"'.$checked.'/>'.
10788: $authnames{$shortauth{$auth}}.'</label> ';
10789: }
10790: } elsif ($item eq 'timezone_def') {
10791: my $includeempty = 1;
10792: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
10793: } elsif ($item eq 'datelocale_def') {
10794: my $includeempty = 1;
10795: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
10796: } elsif ($item eq 'lang_def') {
1.263 raeburn 10797: my $includeempty = 1;
10798: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.414 raeburn 10799: } elsif ($item eq 'portal_def') {
10800: $datatable .= '<input type="text" name="'.$item.'" value="'.
10801: $defaults{$item}.'" size="25" onkeyup="portalExtras(this);" />';
10802: my $portalsty = 'none';
10803: if ($defaults{$item}) {
10804: $portalsty = 'block';
10805: }
10806: foreach my $field ('email','web') {
10807: my $checkedoff = ' checked="checked"';
10808: my $checkedon;
10809: if ($defaults{$item.'_'.$field}) {
10810: $checkedon = $checkedoff;
10811: $checkedoff = '';
1.425 raeburn 10812: }
1.414 raeburn 10813: $datatable .= '<div id="'.$item.'_'.$field.'_div" style="display:'.$portalsty.'">'.
10814: '<span class="LC_nobreak">'.$titles->{$field}.' '.
10815: '<label><input type="radio" name="'.$item.'_'.$field.'" value="1"'.$checkedon.'/>'.&mt('Yes').'</label>'.
10816: (' 'x2).
10817: '<label><input type="radio" name="'.$item.'_'.$field.'" value="0"'.$checkedoff.'/>'.&mt('No').'</label>'.
10818: '</div>';
10819: }
1.236 raeburn 10820: } else {
1.414 raeburn 10821: $datatable .= '<input type="text" name="'.$item.'" value="'.$defaults{$item}.'" />';
1.43 raeburn 10822: }
1.236 raeburn 10823: $datatable .= '</td></tr>';
10824: $rownum ++;
10825: }
1.409 raeburn 10826: } elsif ($position eq 'middle') {
1.294 raeburn 10827: my %defaults;
10828: if (ref($settings) eq 'HASH') {
1.354 raeburn 10829: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
10830: my $maxnum = @{$settings->{'inststatusorder'}};
10831: for (my $i=0; $i<$maxnum; $i++) {
10832: $css_class = $rownum%2?' class="LC_odd_row"':'';
10833: my $item = $settings->{'inststatusorder'}->[$i];
10834: my $title = $settings->{'inststatustypes'}->{$item};
10835: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
10836: $datatable .= '<tr'.$css_class.'>'.
10837: '<td><span class="LC_nobreak">'.
10838: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
10839: for (my $k=0; $k<=$maxnum; $k++) {
10840: my $vpos = $k+1;
10841: my $selstr;
10842: if ($k == $i) {
10843: $selstr = ' selected="selected" ';
10844: }
10845: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10846: }
10847: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
10848: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
10849: &mt('delete').'</span></td>'.
1.380 raeburn 10850: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.354 raeburn 10851: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
10852: '</span></td></tr>';
10853: }
10854: $css_class = $rownum%2?' class="LC_odd_row"':'';
10855: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
10856: $datatable .= '<tr '.$css_class.'>'.
10857: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
10858: for (my $k=0; $k<=$maxnum; $k++) {
10859: my $vpos = $k+1;
10860: my $selstr;
10861: if ($k == $maxnum) {
10862: $selstr = ' selected="selected" ';
10863: }
10864: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10865: }
10866: $datatable .= '</select> '.&mt('Internal ID:').
10867: '<input type="text" size="10" name="addinststatus" value="" />'.
10868: ' '.&mt('(new)').
10869: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.380 raeburn 10870: &mt('Name displayed').':'.
1.354 raeburn 10871: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
10872: '</tr>'."\n";
10873: $rownum ++;
1.294 raeburn 10874: }
1.354 raeburn 10875: }
1.409 raeburn 10876: } else {
10877: my ($unamemaprules,$ruleorder) =
10878: &Apache::lonnet::inst_userrules($dom,'unamemap');
10879: $css_class = $rownum%2?' class="LC_odd_row"':'';
10880: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10881: my $numinrow = 2;
10882: $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
10883: &user_formats_row('unamemap',$settings,$unamemaprules,
10884: $ruleorder,$numinrow).
10885: '</table></td></tr>';
10886: }
10887: if ($datatable eq '') {
10888: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
10889: &mt('No rules set for domain in customized localenroll.pm').
10890: '</td></tr>';
10891: }
1.354 raeburn 10892: }
10893: $$rowtotal += $rownum;
1.43 raeburn 10894: return $datatable;
10895: }
10896:
1.168 raeburn 10897: sub get_languages_hash {
10898: my %langchoices;
10899: foreach my $id (&Apache::loncommon::languageids()) {
10900: my $code = &Apache::loncommon::supportedlanguagecode($id);
10901: if ($code ne '') {
10902: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
10903: }
10904: }
10905: return %langchoices;
10906: }
10907:
1.43 raeburn 10908: sub defaults_titles {
1.141 raeburn 10909: my ($dom) = @_;
1.43 raeburn 10910: my %titles = &Apache::lonlocal::texthash (
10911: 'auth_def' => 'Default authentication type',
10912: 'auth_arg_def' => 'Default authentication argument',
10913: 'lang_def' => 'Default language',
1.54 raeburn 10914: 'timezone_def' => 'Default timezone',
1.68 raeburn 10915: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 10916: 'portal_def' => 'Portal/Default URL',
1.414 raeburn 10917: 'email' => 'Email links use portal URL',
10918: 'web' => 'Public web links use portal URL',
1.294 raeburn 10919: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
10920: 'intauth_check' => 'Check bcrypt cost if authenticated',
10921: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 10922: );
1.141 raeburn 10923: if ($dom) {
10924: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
10925: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
10926: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
10927: $protocol = 'http' if ($protocol ne 'https');
10928: if ($uint_dom) {
10929: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
10930: $uint_dom);
10931: }
10932: }
1.43 raeburn 10933: return (\%titles);
10934: }
10935:
1.346 raeburn 10936: sub print_scantron {
10937: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
10938: if ($position eq 'top') {
10939: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
10940: } else {
10941: return &print_scantronconfig($dom,$settings,\$rowtotal);
10942: }
10943: }
10944:
10945: sub scantron_javascript {
10946: return <<"ENDSCRIPT";
10947:
10948: <script type="text/javascript">
10949: // <![CDATA[
10950:
10951: function toggleScantron(form) {
1.347 raeburn 10952: var csvfieldset = new Array();
1.346 raeburn 10953: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 10954: csvfieldset.push(document.getElementById('scantroncsv_cols'));
10955: }
10956: if (document.getElementById('scantroncsv_options')) {
10957: csvfieldset.push(document.getElementById('scantroncsv_options'));
10958: }
10959: if (csvfieldset.length) {
1.346 raeburn 10960: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 10961: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 10962: if (scantroncsv.checked) {
1.347 raeburn 10963: for (var i=0; i<csvfieldset.length; i++) {
10964: csvfieldset[i].style.display = 'block';
10965: }
1.346 raeburn 10966: } else {
1.347 raeburn 10967: for (var i=0; i<csvfieldset.length; i++) {
10968: csvfieldset[i].style.display = 'none';
10969: }
1.346 raeburn 10970: var csvselects = document.getElementsByClassName('scantronconfig_csv');
10971: if (csvselects.length) {
10972: for (var j=0; j<csvselects.length; j++) {
10973: csvselects[j].selectedIndex = 0;
10974: }
10975: }
10976: }
10977: }
10978: }
10979: return;
10980: }
10981: // ]]>
10982: </script>
10983:
10984: ENDSCRIPT
10985:
10986: }
10987:
1.46 raeburn 10988: sub print_scantronformat {
10989: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
10990: my $itemcount = 1;
1.60 raeburn 10991: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
10992: %confhash);
1.46 raeburn 10993: my $switchserver = &check_switchserver($dom,$confname);
10994: my %lt = &Apache::lonlocal::texthash (
1.95 www 10995: default => 'Default bubblesheet format file error',
10996: custom => 'Custom bubblesheet format file error',
1.46 raeburn 10997: );
10998: my %scantronfiles = (
10999: default => 'default.tab',
11000: custom => 'custom.tab',
11001: );
11002: foreach my $key (keys(%scantronfiles)) {
11003: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
11004: .$scantronfiles{$key};
11005: }
11006: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
11007: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
11008: if (!$switchserver) {
11009: my $servadm = $r->dir_config('lonAdmEMail');
11010: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
11011: if ($configuserok eq 'ok') {
11012: if ($author_ok eq 'ok') {
11013: my %legacyfile = (
1.346 raeburn 11014: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
11015: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 11016: );
11017: my %md5chk;
11018: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 11019: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
11020: chomp($md5chk{$type});
1.46 raeburn 11021: }
11022: if ($md5chk{'default'} ne $md5chk{'custom'}) {
11023: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 11024: ($scantronurls{$type},my $error) =
1.46 raeburn 11025: &legacy_scantronformat($r,$dom,$confname,
11026: $type,$legacyfile{$type},
11027: $scantronurls{$type},
11028: $scantronfiles{$type});
1.60 raeburn 11029: if ($error ne '') {
11030: $error{$type} = $error;
11031: }
11032: }
11033: if (keys(%error) == 0) {
11034: $is_custom = 1;
1.346 raeburn 11035: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 11036: $scantronurls{'custom'};
1.346 raeburn 11037: my $putresult =
1.60 raeburn 11038: &Apache::lonnet::put_dom('configuration',
11039: \%confhash,$dom);
11040: if ($putresult ne 'ok') {
1.346 raeburn 11041: $error{'custom'} =
1.60 raeburn 11042: '<span class="LC_error">'.
11043: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
11044: }
1.46 raeburn 11045: }
11046: } else {
1.60 raeburn 11047: ($scantronurls{'default'},my $error) =
1.46 raeburn 11048: &legacy_scantronformat($r,$dom,$confname,
11049: 'default',$legacyfile{'default'},
11050: $scantronurls{'default'},
11051: $scantronfiles{'default'});
1.60 raeburn 11052: if ($error eq '') {
11053: $confhash{'scantron'}{'scantronformat'} = '';
11054: my $putresult =
11055: &Apache::lonnet::put_dom('configuration',
11056: \%confhash,$dom);
11057: if ($putresult ne 'ok') {
11058: $error{'default'} =
11059: '<span class="LC_error">'.
11060: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
11061: }
11062: } else {
11063: $error{'default'} = $error;
11064: }
1.46 raeburn 11065: }
11066: }
11067: }
11068: } else {
1.95 www 11069: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 11070: }
11071: }
11072: if (ref($settings) eq 'HASH') {
11073: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
11074: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
11075: if ((!@info) || ($info[0] eq 'no_such_dir')) {
11076: $scantronurl = '';
11077: } else {
11078: $scantronurl = $settings->{'scantronformat'};
11079: }
11080: $is_custom = 1;
11081: } else {
11082: $scantronurl = $scantronurls{'default'};
11083: }
11084: } else {
1.60 raeburn 11085: if ($is_custom) {
11086: $scantronurl = $scantronurls{'custom'};
11087: } else {
11088: $scantronurl = $scantronurls{'default'};
11089: }
1.46 raeburn 11090: }
11091: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11092: $datatable .= '<tr'.$css_class.'>';
11093: if (!$is_custom) {
1.65 raeburn 11094: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
11095: '<span class="LC_nobreak">';
1.46 raeburn 11096: if ($scantronurl) {
1.199 raeburn 11097: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
11098: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 11099: } else {
11100: $datatable = &mt('File unavailable for display');
11101: }
1.65 raeburn 11102: $datatable .= '</span></td>';
1.60 raeburn 11103: if (keys(%error) == 0) {
1.306 raeburn 11104: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 11105: if (!$switchserver) {
11106: $datatable .= &mt('Upload:').'<br />';
11107: }
11108: } else {
11109: my $errorstr;
11110: foreach my $key (sort(keys(%error))) {
11111: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
11112: }
11113: $datatable .= '<td>'.$errorstr;
11114: }
1.46 raeburn 11115: } else {
11116: if (keys(%error) > 0) {
11117: my $errorstr;
11118: foreach my $key (sort(keys(%error))) {
11119: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
11120: }
1.60 raeburn 11121: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 11122: } elsif ($scantronurl) {
1.199 raeburn 11123: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
11124: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 11125: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 11126: $link.
11127: '<label><input type="checkbox" name="scantronformat_del"'.
11128: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 11129: '<td><span class="LC_nobreak"> '.
11130: &mt('Replace:').'</span><br />';
1.46 raeburn 11131: }
11132: }
11133: if (keys(%error) == 0) {
11134: if ($switchserver) {
11135: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
11136: } else {
1.65 raeburn 11137: $datatable .='<span class="LC_nobreak"> '.
11138: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 11139: }
11140: }
11141: $datatable .= '</td></tr>';
11142: $$rowtotal ++;
11143: return $datatable;
11144: }
11145:
11146: sub legacy_scantronformat {
11147: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
11148: my ($url,$error);
11149: my @statinfo = &Apache::lonnet::stat_file($newurl);
11150: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
1.421 raeburn 11151: my $modified = [];
1.46 raeburn 11152: (my $result,$url) =
1.421 raeburn 11153: &Apache::lonconfigsettings::publishlogo($r,'copy',$legacyfile,$dom,$confname,
11154: 'scantron','','',$newfile,$modified);
11155: if ($result eq 'ok') {
11156: &update_modify_urls($r,$modified);
11157: } else {
1.130 raeburn 11158: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 11159: }
11160: }
11161: return ($url,$error);
11162: }
1.43 raeburn 11163:
1.346 raeburn 11164: sub print_scantronconfig {
11165: my ($dom,$settings,$rowtotal) = @_;
11166: my $itemcount = 2;
11167: my $is_checked = ' checked="checked"';
1.347 raeburn 11168: my %optionson = (
11169: hdr => ' checked="checked"',
11170: pad => ' checked="checked"',
11171: rem => ' checked="checked"',
11172: );
11173: my %optionsoff = (
11174: hdr => '',
11175: pad => '',
11176: rem => '',
11177: );
1.346 raeburn 11178: my $currcsvsty = 'none';
1.347 raeburn 11179: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 11180: my @fields = &scantroncsv_fields();
11181: my %titles = &scantronconfig_titles();
11182: if (ref($settings) eq 'HASH') {
11183: if (ref($settings->{config}) eq 'HASH') {
11184: if ($settings->{config}->{dat}) {
11185: $checked{'dat'} = $is_checked;
11186: }
11187: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 11188: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
11189: %csvfields = %{$settings->{config}->{csv}->{fields}};
11190: if (keys(%csvfields) > 0) {
11191: $checked{'csv'} = $is_checked;
11192: $currcsvsty = 'block';
11193: }
11194: }
11195: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
11196: %csvoptions = %{$settings->{config}->{csv}->{options}};
11197: foreach my $option (keys(%optionson)) {
11198: unless ($csvoptions{$option}) {
11199: $optionsoff{$option} = $optionson{$option};
11200: $optionson{$option} = '';
11201: }
11202: }
1.346 raeburn 11203: }
11204: }
11205: } else {
11206: $checked{'dat'} = $is_checked;
11207: }
11208: } else {
11209: $checked{'dat'} = $is_checked;
11210: }
11211: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
11212: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11213: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
11214: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
11215: foreach my $item ('dat','csv') {
11216: my $id;
11217: if ($item eq 'csv') {
11218: $id = 'id="scantronconfcsv" ';
1.347 raeburn 11219: }
1.346 raeburn 11220: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
11221: $titles{$item}.'</label>'.(' 'x3);
11222: if ($item eq 'csv') {
11223: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
11224: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
11225: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
11226: foreach my $col (@fields) {
11227: my $selnone;
11228: if ($csvfields{$col} eq '') {
11229: $selnone = ' selected="selected"';
11230: }
11231: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
11232: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
11233: '<option value=""'.$selnone.'></option>';
11234: for (my $i=0; $i<20; $i++) {
11235: my $shown = $i+1;
11236: my $sel;
11237: unless ($selnone) {
11238: if (exists($csvfields{$col})) {
11239: if ($csvfields{$col} == $i) {
11240: $sel = ' selected="selected"';
11241: }
11242: }
11243: }
11244: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
11245: }
11246: $datatable .= '</select></td></tr>';
11247: }
1.347 raeburn 11248: $datatable .= '</table></fieldset>'.
11249: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
11250: '<legend>'.&mt('CSV Options').'</legend>';
11251: foreach my $option ('hdr','pad','rem') {
11252: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
11253: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
11254: &mt('Yes').'</label>'.(' 'x2)."\n".
11255: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
11256: }
11257: $datatable .= '</fieldset>';
1.346 raeburn 11258: $itemcount ++;
11259: }
11260: }
11261: $datatable .= '</td></tr>';
11262: $$rowtotal ++;
11263: return $datatable;
11264: }
11265:
11266: sub scantronconfig_titles {
11267: return &Apache::lonlocal::texthash(
11268: dat => 'Standard format (.dat)',
11269: csv => 'Comma separated values (.csv)',
1.347 raeburn 11270: hdr => 'Remove first line in file (contains column titles)',
11271: pad => 'Prepend 0s to PaperID',
1.348 raeburn 11272: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 11273: CODE => 'CODE',
11274: ID => 'Student ID',
11275: PaperID => 'Paper ID',
11276: FirstName => 'First Name',
11277: LastName => 'Last Name',
11278: FirstQuestion => 'First Question Response',
11279: Section => 'Section',
11280: );
11281: }
11282:
11283: sub scantroncsv_fields {
11284: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
11285: }
11286:
1.49 raeburn 11287: sub print_coursecategories {
1.57 raeburn 11288: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
11289: my $datatable;
11290: if ($position eq 'top') {
1.238 raeburn 11291: my (%checked);
11292: my @catitems = ('unauth','auth');
11293: my @cattypes = ('std','domonly','codesrch','none');
11294: $checked{'unauth'} = 'std';
11295: $checked{'auth'} = 'std';
11296: if (ref($settings) eq 'HASH') {
11297: foreach my $type (@cattypes) {
11298: if ($type eq $settings->{'unauth'}) {
11299: $checked{'unauth'} = $type;
11300: }
11301: if ($type eq $settings->{'auth'}) {
11302: $checked{'auth'} = $type;
11303: }
11304: }
11305: }
11306: my %lt = &Apache::lonlocal::texthash (
11307: unauth => 'Catalog type for unauthenticated users',
11308: auth => 'Catalog type for authenticated users',
11309: none => 'No catalog',
11310: std => 'Standard catalog',
11311: domonly => 'Domain-only catalog',
11312: codesrch => "Code search form",
11313: );
11314: my $itemcount = 0;
11315: foreach my $item (@catitems) {
11316: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11317: $datatable .= '<tr '.$css_class.'>'.
11318: '<td>'.$lt{$item}.'</td>'.
11319: '<td class="LC_right_item"><span class="LC_nobreak">';
11320: foreach my $type (@cattypes) {
11321: my $ischecked;
11322: if ($checked{$item} eq $type) {
11323: $ischecked=' checked="checked"';
11324: }
11325: $datatable .= '<label>'.
11326: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
11327: ' />'.$lt{$type}.'</label> ';
11328: }
1.327 raeburn 11329: $datatable .= '</span></td></tr>';
1.238 raeburn 11330: $itemcount ++;
11331: }
11332: $$rowtotal += $itemcount;
11333: } elsif ($position eq 'middle') {
1.57 raeburn 11334: my $toggle_cats_crs = ' ';
11335: my $toggle_cats_dom = ' checked="checked" ';
11336: my $can_cat_crs = ' ';
11337: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 11338: my $toggle_catscomm_comm = ' ';
11339: my $toggle_catscomm_dom = ' checked="checked" ';
11340: my $can_catcomm_comm = ' ';
11341: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 11342: my $toggle_catsplace_place = ' ';
11343: my $toggle_catsplace_dom = ' checked="checked" ';
11344: my $can_catplace_place = ' ';
11345: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 11346:
1.57 raeburn 11347: if (ref($settings) eq 'HASH') {
11348: if ($settings->{'togglecats'} eq 'crs') {
11349: $toggle_cats_crs = $toggle_cats_dom;
11350: $toggle_cats_dom = ' ';
11351: }
11352: if ($settings->{'categorize'} eq 'crs') {
11353: $can_cat_crs = $can_cat_dom;
11354: $can_cat_dom = ' ';
11355: }
1.120 raeburn 11356: if ($settings->{'togglecatscomm'} eq 'comm') {
11357: $toggle_catscomm_comm = $toggle_catscomm_dom;
11358: $toggle_catscomm_dom = ' ';
11359: }
11360: if ($settings->{'categorizecomm'} eq 'comm') {
11361: $can_catcomm_comm = $can_catcomm_dom;
11362: $can_catcomm_dom = ' ';
11363: }
1.272 raeburn 11364: if ($settings->{'togglecatsplace'} eq 'place') {
11365: $toggle_catsplace_place = $toggle_catsplace_dom;
11366: $toggle_catsplace_dom = ' ';
11367: }
11368: if ($settings->{'categorizeplace'} eq 'place') {
11369: $can_catplace_place = $can_catplace_dom;
11370: $can_catplace_dom = ' ';
11371: }
1.57 raeburn 11372: }
11373: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 11374: togglecats => 'Show/Hide a course in catalog',
11375: togglecatscomm => 'Show/Hide a community in catalog',
11376: togglecatsplace => 'Show/Hide a placement test in catalog',
11377: categorize => 'Assign a category to a course',
11378: categorizecomm => 'Assign a category to a community',
11379: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 11380: );
11381: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 11382: dom => 'Set in Domain',
11383: crs => 'Set in Course',
11384: comm => 'Set in Community',
11385: place => 'Set in Placement Test',
1.57 raeburn 11386: );
11387: $datatable = '<tr class="LC_odd_row">'.
11388: '<td>'.$title{'togglecats'}.'</td>'.
11389: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11390: '<input type="radio" name="togglecats"'.
11391: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11392: '<label><input type="radio" name="togglecats"'.
11393: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
11394: '</tr><tr>'.
11395: '<td>'.$title{'categorize'}.'</td>'.
11396: '<td class="LC_right_item"><span class="LC_nobreak">'.
11397: '<label><input type="radio" name="categorize"'.
11398: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11399: '<label><input type="radio" name="categorize"'.
11400: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 11401: '</tr><tr class="LC_odd_row">'.
11402: '<td>'.$title{'togglecatscomm'}.'</td>'.
11403: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11404: '<input type="radio" name="togglecatscomm"'.
11405: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11406: '<label><input type="radio" name="togglecatscomm"'.
11407: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
11408: '</tr><tr>'.
11409: '<td>'.$title{'categorizecomm'}.'</td>'.
11410: '<td class="LC_right_item"><span class="LC_nobreak">'.
11411: '<label><input type="radio" name="categorizecomm"'.
11412: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11413: '<label><input type="radio" name="categorizecomm"'.
11414: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 11415: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 11416: '<td>'.$title{'togglecatsplace'}.'</td>'.
11417: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11418: '<input type="radio" name="togglecatsplace"'.
11419: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11420: '<label><input type="radio" name="togglecatscomm"'.
11421: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
11422: '</tr><tr>'.
11423: '<td>'.$title{'categorizeplace'}.'</td>'.
11424: '<td class="LC_right_item"><span class="LC_nobreak">'.
11425: '<label><input type="radio" name="categorizeplace"'.
11426: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11427: '<label><input type="radio" name="categorizeplace"'.
11428: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 11429: '</tr>';
1.272 raeburn 11430: $$rowtotal += 6;
1.57 raeburn 11431: } else {
11432: my $css_class;
11433: my $itemcount = 1;
11434: my $cathash;
11435: if (ref($settings) eq 'HASH') {
11436: $cathash = $settings->{'cats'};
11437: }
11438: if (ref($cathash) eq 'HASH') {
11439: my (@cats,@trails,%allitems,%idx,@jsarray);
11440: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
11441: \%allitems,\%idx,\@jsarray);
11442: my $maxdepth = scalar(@cats);
11443: my $colattrib = '';
11444: if ($maxdepth > 2) {
11445: $colattrib = ' colspan="2" ';
11446: }
11447: my @path;
11448: if (@cats > 0) {
11449: if (ref($cats[0]) eq 'ARRAY') {
11450: my $numtop = @{$cats[0]};
11451: my $maxnum = $numtop;
1.120 raeburn 11452: my %default_names = (
11453: instcode => &mt('Official courses'),
11454: communities => &mt('Communities'),
1.272 raeburn 11455: placement => &mt('Placement Tests'),
1.120 raeburn 11456: );
11457:
11458: if ((!grep(/^instcode$/,@{$cats[0]})) ||
11459: ($cathash->{'instcode::0'} eq '') ||
11460: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 11461: ($cathash->{'communities::0'} eq '') ||
11462: (!grep(/^placement$/,@{$cats[0]})) ||
11463: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 11464: $maxnum ++;
11465: }
11466: my $lastidx;
11467: for (my $i=0; $i<$numtop; $i++) {
11468: my $parent = $cats[0][$i];
11469: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11470: my $item = &escape($parent).'::0';
11471: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
11472: $lastidx = $idx{$item};
11473: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
11474: .'<select name="'.$item.'"'.$chgstr.'>';
11475: for (my $k=0; $k<=$maxnum; $k++) {
11476: my $vpos = $k+1;
11477: my $selstr;
11478: if ($k == $i) {
11479: $selstr = ' selected="selected" ';
11480: }
11481: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11482: }
1.214 raeburn 11483: $datatable .= '</select></span></td><td>';
1.272 raeburn 11484: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 11485: $datatable .= '<span class="LC_nobreak">'
11486: .$default_names{$parent}.'</span>';
11487: if ($parent eq 'instcode') {
11488: $datatable .= '<br /><span class="LC_nobreak">('
11489: .&mt('with institutional codes')
11490: .')</span></td><td'.$colattrib.'>';
11491: } else {
11492: $datatable .= '<table><tr><td>';
11493: }
11494: $datatable .= '<span class="LC_nobreak">'
11495: .'<label><input type="radio" name="'
11496: .$parent.'" value="1" checked="checked" />'
11497: .&mt('Display').'</label>';
11498: if ($parent eq 'instcode') {
11499: $datatable .= ' ';
11500: } else {
11501: $datatable .= '</span></td></tr><tr><td>'
11502: .'<span class="LC_nobreak">';
11503: }
11504: $datatable .= '<label><input type="radio" name="'
11505: .$parent.'" value="0" />'
11506: .&mt('Do not display').'</label></span>';
1.272 raeburn 11507: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 11508: $datatable .= '</td></tr></table>';
11509: }
11510: $datatable .= '</td>';
1.57 raeburn 11511: } else {
11512: $datatable .= $parent
1.214 raeburn 11513: .' <span class="LC_nobreak"><label>'
11514: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 11515: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
11516: }
11517: my $depth = 1;
11518: push(@path,$parent);
11519: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
11520: pop(@path);
11521: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
11522: $itemcount ++;
11523: }
1.48 raeburn 11524: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 11525: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
11526: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 11527: for (my $k=0; $k<=$maxnum; $k++) {
11528: my $vpos = $k+1;
11529: my $selstr;
1.57 raeburn 11530: if ($k == $numtop) {
1.48 raeburn 11531: $selstr = ' selected="selected" ';
11532: }
11533: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11534: }
1.59 bisitz 11535: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 11536: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
11537: .'</tr>'."\n";
1.48 raeburn 11538: $itemcount ++;
1.272 raeburn 11539: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11540: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
11541: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11542: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
11543: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
11544: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
11545: for (my $k=0; $k<=$maxnum; $k++) {
11546: my $vpos = $k+1;
11547: my $selstr;
11548: if ($k == $maxnum) {
11549: $selstr = ' selected="selected" ';
11550: }
11551: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 11552: }
1.120 raeburn 11553: $datatable .= '</select></span></td>'.
11554: '<td><span class="LC_nobreak">'.
11555: $default_names{$default}.'</span>';
11556: if ($default eq 'instcode') {
11557: $datatable .= '<br /><span class="LC_nobreak">('
11558: .&mt('with institutional codes').')</span>';
11559: }
11560: $datatable .= '</td>'
11561: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
11562: .&mt('Display').'</label> '
11563: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
11564: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 11565: }
11566: }
11567: }
1.57 raeburn 11568: } else {
11569: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 11570: }
11571: } else {
1.327 raeburn 11572: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 11573: .&initialize_categories($itemcount);
1.48 raeburn 11574: }
1.57 raeburn 11575: $$rowtotal += $itemcount;
1.48 raeburn 11576: }
11577: return $datatable;
11578: }
11579:
1.69 raeburn 11580: sub print_serverstatuses {
11581: my ($dom,$settings,$rowtotal) = @_;
11582: my $datatable;
11583: my @pages = &serverstatus_pages();
11584: my (%namedaccess,%machineaccess);
11585: foreach my $type (@pages) {
11586: $namedaccess{$type} = '';
11587: $machineaccess{$type}= '';
11588: }
11589: if (ref($settings) eq 'HASH') {
11590: foreach my $type (@pages) {
11591: if (exists($settings->{$type})) {
11592: if (ref($settings->{$type}) eq 'HASH') {
11593: foreach my $key (keys(%{$settings->{$type}})) {
11594: if ($key eq 'namedusers') {
11595: $namedaccess{$type} = $settings->{$type}->{$key};
11596: } elsif ($key eq 'machines') {
11597: $machineaccess{$type} = $settings->{$type}->{$key};
11598: }
11599: }
11600: }
11601: }
11602: }
11603: }
1.81 raeburn 11604: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11605: my $rownum = 0;
11606: my $css_class;
11607: foreach my $type (@pages) {
11608: $rownum ++;
11609: $css_class = $rownum%2?' class="LC_odd_row"':'';
11610: $datatable .= '<tr'.$css_class.'>'.
11611: '<td><span class="LC_nobreak">'.
11612: $titles->{$type}.'</span></td>'.
11613: '<td class="LC_left_item">'.
11614: '<input type="text" name="'.$type.'_namedusers" '.
11615: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
11616: '<td class="LC_right_item">'.
11617: '<span class="LC_nobreak">'.
11618: '<input type="text" name="'.$type.'_machines" '.
11619: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 11620: '</span></td></tr>'."\n";
1.69 raeburn 11621: }
11622: $$rowtotal += $rownum;
11623: return $datatable;
11624: }
11625:
11626: sub serverstatus_pages {
11627: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 11628: 'checksums','clusterstatus','certstatus','metadata_keywords',
11629: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
11630: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 11631: }
11632:
1.236 raeburn 11633: sub defaults_javascript {
11634: my ($settings) = @_;
1.354 raeburn 11635: return unless (ref($settings) eq 'HASH');
1.414 raeburn 11636: my $portal_js = <<"ENDPORTAL";
11637:
11638: function portalExtras(caller) {
11639: var x = caller.value;
11640: var y = new Array('email','web');
1.425 raeburn 11641: for (var i=0; i<y.length; i++) {
1.414 raeburn 11642: if (document.getElementById('portal_def_'+y[i]+'_div')) {
11643: var z = document.getElementById('portal_def_'+y[i]+'_div');
11644: if (x.length > 0) {
11645: z.style.display = 'block';
11646: } else {
11647: z.style.display = 'none';
11648: }
11649: }
11650: }
11651: }
11652: ENDPORTAL
1.236 raeburn 11653: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
11654: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
11655: if ($maxnum eq '') {
11656: $maxnum = 0;
11657: }
11658: $maxnum ++;
1.249 raeburn 11659: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 11660: return <<"ENDSCRIPT";
11661: <script type="text/javascript">
11662: // <![CDATA[
11663: function reorderTypes(form,caller) {
11664: var changedVal;
11665: $jstext
11666: var newpos = 'addinststatus_pos';
11667: var current = new Array;
11668: var maxh = $maxnum;
11669: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11670: var oldVal;
11671: if (caller == newpos) {
11672: changedVal = newitemVal;
11673: } else {
11674: var curritem = 'inststatus_pos_'+caller;
11675: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
11676: current[newitemVal] = newpos;
11677: }
11678: for (var i=0; i<inststatuses.length; i++) {
11679: if (inststatuses[i] != caller) {
11680: var elementName = 'inststatus_pos_'+inststatuses[i];
11681: if (form.elements[elementName]) {
11682: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11683: current[currVal] = elementName;
11684: }
11685: }
11686: }
11687: for (var j=0; j<maxh; j++) {
11688: if (current[j] == undefined) {
11689: oldVal = j;
11690: }
11691: }
11692: if (oldVal < changedVal) {
11693: for (var k=oldVal+1; k<=changedVal ; k++) {
11694: var elementName = current[k];
11695: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11696: }
11697: } else {
11698: for (var k=changedVal; k<oldVal; k++) {
11699: var elementName = current[k];
11700: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11701: }
11702: }
11703: return;
11704: }
11705:
1.414 raeburn 11706: $portal_js
11707:
11708: // ]]>
11709: </script>
11710:
11711: ENDSCRIPT
11712: } else {
11713: return <<"ENDSCRIPT";
11714: <script type="text/javascript">
11715: // <![CDATA[
11716: $portal_js
1.236 raeburn 11717: // ]]>
11718: </script>
11719:
11720: ENDSCRIPT
11721: }
1.354 raeburn 11722: return;
11723: }
11724:
11725: sub passwords_javascript {
1.405 raeburn 11726: my ($prefix) = @_;
11727: my %intalert;
11728: if ($prefix eq 'passwords') {
11729: %intalert = &Apache::lonlocal::texthash (
11730: authcheck => 'Warning: disallowing login for an authenticated user if the stored cost is less than the default will require a password reset by/for the user.',
11731: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
11732: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
11733: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
11734: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
11735: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
11736: );
1.421 raeburn 11737: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 11738: %intalert = &Apache::lonlocal::texthash (
11739: passmin => 'Warning: minimum secret length must be a positive integer greater than 6.',
11740: passmax => 'Warning: maximum secret length must be a positive integer (or blank).',
11741: );
11742: }
1.365 raeburn 11743: &js_escape(\%intalert);
11744: my $defmin = $Apache::lonnet::passwdmin;
1.425 raeburn 11745: my $intauthjs;
1.405 raeburn 11746: if ($prefix eq 'passwords') { $intauthjs = <<"ENDSCRIPT";
1.354 raeburn 11747:
11748: function warnIntAuth(field) {
11749: if (field.name == 'intauth_check') {
11750: if (field.value == '2') {
1.365 raeburn 11751: alert('$intalert{authcheck}');
1.354 raeburn 11752: }
11753: }
11754: if (field.name == 'intauth_cost') {
11755: field.value.replace(/\s/g,'');
11756: if (field.value != '') {
11757: var regexdigit=/^\\d+\$/;
11758: if (!regexdigit.test(field.value)) {
1.365 raeburn 11759: alert('$intalert{authcost}');
11760: }
11761: }
11762: }
11763: return;
11764: }
11765:
1.405 raeburn 11766: ENDSCRIPT
11767:
11768: }
11769:
11770: $intauthjs .= <<"ENDSCRIPT";
11771:
11772: function warnInt$prefix(field) {
1.365 raeburn 11773: field.value.replace(/^\s+/,'');
11774: field.value.replace(/\s+\$/,'');
11775: var regexdigit=/^\\d+\$/;
1.408 raeburn 11776: if (field.name == '${prefix}_min') {
1.365 raeburn 11777: if (field.value == '') {
11778: alert('$intalert{passmin}');
11779: field.value = '$defmin';
11780: } else {
11781: if (!regexdigit.test(field.value)) {
11782: alert('$intalert{passmin}');
11783: field.value = '$defmin';
11784: }
1.366 raeburn 11785: var minval = parseInt(field.value,10);
1.365 raeburn 11786: if (minval < $defmin) {
11787: alert('$intalert{passmin}');
11788: field.value = '$defmin';
11789: }
11790: }
11791: } else {
11792: if (field.value == '0') {
11793: field.value = '';
11794: }
11795: if (field.value != '') {
1.408 raeburn 11796: if (field.name == '${prefix}_expire') {
1.365 raeburn 11797: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
11798: if (!regexpposnum.test(field.value)) {
11799: alert('$intalert{passexp}');
11800: field.value = '';
11801: } else {
11802: var expval = parseFloat(field.value);
11803: if (expval == 0) {
11804: alert('$intalert{passexp}');
11805: field.value = '';
11806: }
11807: }
11808: } else {
11809: if (!regexdigit.test(field.value)) {
1.408 raeburn 11810: if (field.name == '${prefix}_max') {
1.365 raeburn 11811: alert('$intalert{passmax}');
11812: } else {
1.408 raeburn 11813: if (field.name == '${prefix}_numsaved') {
1.365 raeburn 11814: alert('$intalert{passnum}');
11815: }
11816: }
1.370 raeburn 11817: field.value = '';
1.365 raeburn 11818: }
1.354 raeburn 11819: }
11820: }
11821: }
11822: return;
11823: }
11824:
11825: ENDSCRIPT
11826: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 11827: }
11828:
1.49 raeburn 11829: sub coursecategories_javascript {
11830: my ($settings) = @_;
1.57 raeburn 11831: my ($output,$jstext,$cathash);
1.49 raeburn 11832: if (ref($settings) eq 'HASH') {
1.57 raeburn 11833: $cathash = $settings->{'cats'};
11834: }
11835: if (ref($cathash) eq 'HASH') {
1.49 raeburn 11836: my (@cats,@jsarray,%idx);
1.57 raeburn 11837: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 11838: if (@jsarray > 0) {
11839: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
11840: for (my $i=0; $i<@jsarray; $i++) {
11841: if (ref($jsarray[$i]) eq 'ARRAY') {
11842: my $catstr = join('","',@{$jsarray[$i]});
11843: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
11844: }
11845: }
11846: }
11847: } else {
11848: $jstext = ' var categories = Array(1);'."\n".
11849: ' categories[0] = Array("instcode_pos");'."\n";
11850: }
1.237 bisitz 11851: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
11852: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 11853: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 11854: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
11855: &js_escape(\$instcode_reserved);
11856: &js_escape(\$communities_reserved);
1.272 raeburn 11857: &js_escape(\$placement_reserved);
1.265 damieng 11858: &js_escape(\$choose_again);
1.49 raeburn 11859: $output = <<"ENDSCRIPT";
11860: <script type="text/javascript">
1.109 raeburn 11861: // <![CDATA[
1.49 raeburn 11862: function reorderCats(form,parent,item,idx) {
11863: var changedVal;
11864: $jstext
11865: var newpos = 'addcategory_pos';
11866: if (parent == '') {
11867: var has_instcode = 0;
11868: var maxtop = categories[idx].length;
11869: for (var j=0; j<maxtop; j++) {
11870: if (categories[idx][j] == 'instcode::0') {
11871: has_instcode == 1;
11872: }
11873: }
11874: if (has_instcode == 0) {
11875: categories[idx][maxtop] = 'instcode_pos';
11876: }
11877: } else {
11878: newpos += '_'+parent;
11879: }
11880: var maxh = 1 + categories[idx].length;
11881: var current = new Array;
11882: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11883: if (item == newpos) {
11884: changedVal = newitemVal;
11885: } else {
11886: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
11887: current[newitemVal] = newpos;
11888: }
11889: for (var i=0; i<categories[idx].length; i++) {
11890: var elementName = categories[idx][i];
11891: if (elementName != item) {
11892: if (form.elements[elementName]) {
11893: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11894: current[currVal] = elementName;
11895: }
11896: }
11897: }
11898: var oldVal;
11899: for (var j=0; j<maxh; j++) {
11900: if (current[j] == undefined) {
11901: oldVal = j;
11902: }
11903: }
11904: if (oldVal < changedVal) {
11905: for (var k=oldVal+1; k<=changedVal ; k++) {
11906: var elementName = current[k];
11907: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11908: }
11909: } else {
11910: for (var k=changedVal; k<oldVal; k++) {
11911: var elementName = current[k];
11912: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11913: }
11914: }
11915: return;
11916: }
1.120 raeburn 11917:
11918: function categoryCheck(form) {
11919: if (form.elements['addcategory_name'].value == 'instcode') {
11920: alert('$instcode_reserved\\n$choose_again');
11921: return false;
11922: }
11923: if (form.elements['addcategory_name'].value == 'communities') {
11924: alert('$communities_reserved\\n$choose_again');
11925: return false;
11926: }
1.272 raeburn 11927: if (form.elements['addcategory_name'].value == 'placement') {
11928: alert('$placement_reserved\\n$choose_again');
11929: return false;
11930: }
1.120 raeburn 11931: return true;
11932: }
11933:
1.109 raeburn 11934: // ]]>
1.49 raeburn 11935: </script>
11936:
11937: ENDSCRIPT
11938: return $output;
11939: }
11940:
1.48 raeburn 11941: sub initialize_categories {
11942: my ($itemcount) = @_;
1.120 raeburn 11943: my ($datatable,$css_class,$chgstr);
1.380 raeburn 11944: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 11945: instcode => 'Official courses (with institutional codes)',
11946: communities => 'Communities',
1.272 raeburn 11947: placement => 'Placement Tests',
1.120 raeburn 11948: );
1.328 raeburn 11949: my %selnum = (
11950: instcode => '0',
11951: communities => '1',
11952: placement => '2',
11953: );
11954: my %selected;
1.272 raeburn 11955: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11956: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 11957: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 11958: map { $selected{$selnum{$_}} = '' } keys(%selnum);
11959: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 11960: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 11961: .'<select name="'.$default.'_pos"'.$chgstr.'>'
11962: .'<option value="0"'.$selected{'0'}.'>1</option>'
11963: .'<option value="1"'.$selected{'1'}.'>2</option>'
11964: .'<option value="2"'.$selected{'2'}.'>3</option>'
11965: .'<option value="3">4</option></select> '
1.120 raeburn 11966: .$default_names{$default}
11967: .'</span></td><td><span class="LC_nobreak">'
11968: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
11969: .&mt('Display').'</label> <label>'
11970: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 11971: .'</label></span></td></tr>';
1.120 raeburn 11972: $itemcount ++;
11973: }
1.48 raeburn 11974: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 11975: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 11976: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 11977: .'<select name="addcategory_pos"'.$chgstr.'>'
11978: .'<option value="0">1</option>'
11979: .'<option value="1">2</option>'
1.328 raeburn 11980: .'<option value="2">3</option>'
11981: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 11982: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
11983: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
11984: .'</td></tr>';
1.48 raeburn 11985: return $datatable;
11986: }
11987:
11988: sub build_category_rows {
1.49 raeburn 11989: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
11990: my ($text,$name,$item,$chgstr);
1.48 raeburn 11991: if (ref($cats) eq 'ARRAY') {
11992: my $maxdepth = scalar(@{$cats});
11993: if (ref($cats->[$depth]) eq 'HASH') {
11994: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
11995: my $numchildren = @{$cats->[$depth]{$parent}};
11996: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 11997: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 11998: my ($idxnum,$parent_name,$parent_item);
11999: my $higher = $depth - 1;
12000: if ($higher == 0) {
12001: $parent_name = &escape($parent).'::'.$higher;
12002: } else {
12003: if (ref($path) eq 'ARRAY') {
12004: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
12005: }
12006: }
12007: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 12008: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 12009: if ($j < $numchildren) {
1.48 raeburn 12010: $name = $cats->[$depth]{$parent}[$j];
12011: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 12012: $idxnum = $idx->{$item};
12013: } else {
12014: $name = $parent_name;
12015: $item = $parent_item;
1.48 raeburn 12016: }
1.49 raeburn 12017: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
12018: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 12019: for (my $i=0; $i<=$numchildren; $i++) {
12020: my $vpos = $i+1;
12021: my $selstr;
12022: if ($j == $i) {
12023: $selstr = ' selected="selected" ';
12024: }
12025: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
12026: }
12027: $text .= '</select> ';
12028: if ($j < $numchildren) {
12029: my $deeper = $depth+1;
12030: $text .= $name.' '
12031: .'<label><input type="checkbox" name="deletecategory" value="'
12032: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
12033: if(ref($path) eq 'ARRAY') {
12034: push(@{$path},$name);
1.49 raeburn 12035: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 12036: pop(@{$path});
12037: }
12038: } else {
1.330 raeburn 12039: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 12040: if ($j == $numchildren) {
12041: $text .= $name;
12042: } else {
12043: $text .= $item;
12044: }
12045: $text .= '" value="" />';
12046: }
12047: $text .= '</td></tr>';
12048: }
12049: $text .= '</table></td>';
12050: } else {
12051: my $higher = $depth-1;
12052: if ($higher == 0) {
12053: $name = &escape($parent).'::'.$higher;
12054: } else {
12055: if (ref($path) eq 'ARRAY') {
12056: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
12057: }
12058: }
12059: my $colspan;
12060: if ($parent ne 'instcode') {
12061: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 12062: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 12063: }
12064: }
12065: }
12066: }
12067: return $text;
12068: }
12069:
1.33 raeburn 12070: sub modifiable_userdata_row {
1.305 raeburn 12071: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357 raeburn 12072: $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228 raeburn 12073: my ($role,$rolename,$statustype);
12074: $role = $item;
1.224 raeburn 12075: if ($context eq 'cancreate') {
1.305 raeburn 12076: if ($item =~ /^(emailusername)_(.+)$/) {
12077: $role = $1;
12078: $statustype = $2;
1.228 raeburn 12079: if (ref($usertypes) eq 'HASH') {
12080: if ($usertypes->{$statustype}) {
12081: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
12082: } else {
12083: $rolename = &mt('Data provided by user');
12084: }
12085: }
1.224 raeburn 12086: }
12087: } elsif ($context eq 'selfcreate') {
1.63 raeburn 12088: if (ref($usertypes) eq 'HASH') {
12089: $rolename = $usertypes->{$role};
12090: } else {
12091: $rolename = $role;
12092: }
1.325 raeburn 12093: } elsif ($context eq 'lti') {
12094: $rolename = &mt('Institutional data used (if available)');
1.357 raeburn 12095: } elsif ($context eq 'privacy') {
12096: $rolename = $itemdesc;
1.33 raeburn 12097: } else {
1.63 raeburn 12098: if ($role eq 'cr') {
12099: $rolename = &mt('Custom role');
12100: } else {
12101: $rolename = &Apache::lonnet::plaintext($role);
12102: }
1.33 raeburn 12103: }
1.224 raeburn 12104: my (@fields,%fieldtitles);
12105: if (ref($fieldsref) eq 'ARRAY') {
12106: @fields = @{$fieldsref};
12107: } else {
12108: @fields = ('lastname','firstname','middlename','generation',
12109: 'permanentemail','id');
12110: }
12111: if ((ref($titlesref) eq 'HASH')) {
12112: %fieldtitles = %{$titlesref};
12113: } else {
12114: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12115: }
1.33 raeburn 12116: my $output;
1.305 raeburn 12117: my $css_class;
12118: if ($rowcount%2) {
12119: $css_class = 'LC_odd_row';
12120: }
12121: if ($customcss) {
12122: $css_class .= " $customcss";
12123: }
12124: $css_class =~ s/^\s+//;
12125: if ($css_class) {
12126: $css_class = ' class="'.$css_class.'"';
12127: }
12128: if ($rowstyle) {
12129: $css_class .= ' style="'.$rowstyle.'"';
12130: }
12131: if ($rowid) {
12132: $rowid = ' id="'.$rowid.'"';
12133: }
12134: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 12135: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
12136: '<td class="LC_left_item" colspan="2"><table>';
12137: my $rem;
12138: my %checks;
12139: if (ref($settings) eq 'HASH') {
1.325 raeburn 12140: my $hashref;
12141: if ($context eq 'lti') {
12142: if (ref($settings) eq 'HASH') {
12143: $hashref = $settings->{'instdata'};
12144: }
1.357 raeburn 12145: } elsif ($context eq 'privacy') {
12146: my ($key,$inner) = split(/_/,$role);
12147: if (ref($settings) eq 'HASH') {
12148: if (ref($settings->{$key}) eq 'HASH') {
12149: $hashref = $settings->{$key}->{$inner};
12150: }
12151: }
1.325 raeburn 12152: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 12153: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 12154: $hashref = $settings->{'lti_instdata'};
12155: }
12156: if ($role eq 'emailusername') {
12157: if ($statustype) {
12158: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
12159: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 12160: }
1.325 raeburn 12161: }
12162: }
12163: }
1.425 raeburn 12164: if (ref($hashref) eq 'HASH') {
1.325 raeburn 12165: foreach my $field (@fields) {
12166: if ($hashref->{$field}) {
12167: if ($role eq 'emailusername') {
12168: $checks{$field} = $hashref->{$field};
12169: } else {
12170: $checks{$field} = ' checked="checked" ';
1.33 raeburn 12171: }
12172: }
12173: }
12174: }
12175: }
1.305 raeburn 12176: my $total = scalar(@fields);
12177: for (my $i=0; $i<$total; $i++) {
12178: $rem = $i%($numinrow);
1.33 raeburn 12179: if ($rem == 0) {
12180: if ($i > 0) {
12181: $output .= '</tr>';
12182: }
12183: $output .= '<tr>';
12184: }
12185: my $check = ' ';
1.228 raeburn 12186: unless ($role eq 'emailusername') {
12187: if (exists($checks{$fields[$i]})) {
1.354 raeburn 12188: $check = $checks{$fields[$i]};
1.357 raeburn 12189: } elsif ($context eq 'privacy') {
12190: if ($role =~ /^priv_(domain|course)$/) {
12191: if (ref($settings) ne 'HASH') {
12192: $check = ' checked="checked" ';
12193: }
12194: } elsif ($role =~ /^priv_(author|community)$/) {
12195: if (ref($settings) ne 'HASH') {
12196: unless ($fields[$i] eq 'id') {
12197: $check = ' checked="checked" ';
12198: }
12199: }
12200: } elsif ($role =~ /^(unpriv|othdom)_/) {
12201: if (ref($settings) ne 'HASH') {
12202: if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
12203: $check = ' checked="checked" ';
12204: }
12205: }
12206: }
1.325 raeburn 12207: } elsif ($context ne 'lti') {
1.228 raeburn 12208: if ($role eq 'st') {
12209: if (ref($settings) ne 'HASH') {
12210: $check = ' checked="checked" ';
12211: }
1.33 raeburn 12212: }
12213: }
12214: }
12215: $output .= '<td class="LC_left_item">'.
1.228 raeburn 12216: '<span class="LC_nobreak">';
1.325 raeburn 12217: my $prefix = 'canmodify';
1.228 raeburn 12218: if ($role eq 'emailusername') {
12219: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
12220: $checks{$fields[$i]} = 'omit';
12221: }
12222: foreach my $option ('required','optional','omit') {
12223: my $checked='';
12224: if ($checks{$fields[$i]} eq $option) {
12225: $checked='checked="checked" ';
12226: }
12227: $output .= '<label>'.
1.325 raeburn 12228: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 12229: &mt($option).'</label>'.(' ' x2);
12230: }
12231: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
12232: } else {
1.325 raeburn 12233: if ($context eq 'lti') {
12234: $prefix = 'lti';
1.443 raeburn 12235: } elsif ($context eq 'coauthor') {
12236: $prefix = 'cacanmodify';
1.357 raeburn 12237: } elsif ($context eq 'privacy') {
12238: $prefix = 'privacy';
1.325 raeburn 12239: }
1.228 raeburn 12240: $output .= '<label>'.
1.325 raeburn 12241: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 12242: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
12243: '</label>';
12244: }
12245: $output .= '</span></td>';
1.33 raeburn 12246: }
1.305 raeburn 12247: $rem = $total%$numinrow;
12248: my $colsleft;
12249: if ($rem) {
12250: $colsleft = $numinrow - $rem;
12251: }
12252: if ($colsleft > 1) {
1.33 raeburn 12253: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
12254: ' </td>';
12255: } elsif ($colsleft == 1) {
12256: $output .= '<td class="LC_left_item"> </td>';
12257: }
12258: $output .= '</tr></table></td></tr>';
12259: return $output;
12260: }
1.28 raeburn 12261:
1.93 raeburn 12262: sub insttypes_row {
1.305 raeburn 12263: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
12264: $customcss,$rowstyle) = @_;
1.93 raeburn 12265: my %lt = &Apache::lonlocal::texthash (
1.429 raeburn 12266: cansearch => 'Users allowed to search',
1.93 raeburn 12267: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.429 raeburn 12268: lockablenames => 'User preference to lock name',
12269: selfassign => 'Self-reportable affiliations',
12270: overrides => "Override domain's helpdesk settings based on requester's affiliation",
12271: webdav => 'WebDAV access available',
12272: authorquota => 'Authoring Space quota (MB)',
1.93 raeburn 12273: );
1.429 raeburn 12274: my ($showdom,$defaultquota);
1.93 raeburn 12275: if ($context eq 'cansearch') {
12276: $showdom = ' ('.$dom.')';
1.429 raeburn 12277: } elsif ($context eq 'authorquota') {
12278: $defaultquota = 500;
1.93 raeburn 12279: }
1.165 raeburn 12280: my $class = 'LC_left_item';
12281: if ($context eq 'statustocreate') {
12282: $class = 'LC_right_item';
12283: }
1.305 raeburn 12284: my $css_class;
12285: if ($$rowtotal%2) {
12286: $css_class = 'LC_odd_row';
12287: }
12288: if ($customcss) {
12289: $css_class .= ' '.$customcss;
12290: }
12291: $css_class =~ s/^\s+//;
12292: if ($css_class) {
12293: $css_class = ' class="'.$css_class.'"';
12294: }
12295: if ($rowstyle) {
12296: $css_class .= ' style="'.$rowstyle.'"';
12297: }
12298: if ($onclick) {
12299: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 12300: }
12301: my $output = '<tr'.$css_class.'>'.
12302: '<td>'.$lt{$context}.$showdom.
12303: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 12304: my $rem;
12305: if (ref($types) eq 'ARRAY') {
12306: for (my $i=0; $i<@{$types}; $i++) {
12307: if (defined($usertypes->{$types->[$i]})) {
12308: my $rem = $i%($numinrow);
12309: if ($rem == 0) {
12310: if ($i > 0) {
12311: $output .= '</tr>';
12312: }
12313: $output .= '<tr>';
1.23 raeburn 12314: }
1.429 raeburn 12315: if ($context eq 'authorquota') {
12316: my $currquota;
12317: if ($settings->{$context}->{$types->[$i]} =~ /^\d+$/) {
12318: $currquota = $settings->{$context}->{$types->[$i]};
12319: } else {
12320: $currquota = $defaultquota;
12321: }
12322: $output .= '<td class="LC_left_item">'."\n".
12323: '<label><span class="LC_nobreak">'."\n".
12324: $usertypes->{$types->[$i]}.'</span><br />'."\n".
12325: '<input type="text" name="'.$context.'_'.$types->[$i].'" '.
12326: 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
12327: '</label></td>';
12328: } else {
12329: my $check = ' ';
12330: if (ref($settings) eq 'HASH') {
12331: if (ref($settings->{$context}) eq 'ARRAY') {
12332: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
12333: $check = ' checked="checked" ';
12334: }
12335: } elsif (ref($settings->{$context}) eq 'HASH') {
12336: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
12337: $check = ' checked="checked" ';
12338: } elsif ($context eq 'webdav') {
12339: if ($settings->{$context}->{$types->[$i]}) {
12340: $check = ' checked="checked" ';
12341: }
12342: }
12343: } elsif ($context eq 'statustocreate') {
1.315 raeburn 12344: $check = ' checked="checked" ';
12345: }
1.26 raeburn 12346: }
1.429 raeburn 12347: $output .= '<td class="LC_left_item">'.
12348: '<span class="LC_nobreak"><label>'.
12349: '<input type="checkbox" name="'.$context.'" '.
12350: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
12351: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 12352: }
12353: }
12354: }
1.26 raeburn 12355: $rem = @{$types}%($numinrow);
1.23 raeburn 12356: }
12357: my $colsleft = $numinrow - $rem;
1.315 raeburn 12358: if ($context eq 'overrides') {
12359: if ($colsleft > 1) {
12360: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12361: } else {
12362: $output .= '<td class="LC_left_item">';
12363: }
1.425 raeburn 12364: $output .= ' ';
1.23 raeburn 12365: } else {
1.334 raeburn 12366: if ($rem == 0) {
1.315 raeburn 12367: $output .= '<tr>';
12368: }
12369: if ($colsleft > 1) {
12370: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12371: } else {
12372: $output .= '<td class="LC_left_item">';
12373: }
1.429 raeburn 12374: if ($context eq 'authorquota') {
12375: my $currquota = 500;
12376: if ((ref($settings) eq 'HASH') && (ref($settings->{$context}) eq 'HASH')) {
12377: if ($settings->{$context}{'default'} =~ /^\d+$/) {
12378: $currquota = $settings->{$context}{'default'};
12379: }
12380: }
12381: $output .= '<label><span class="LC_nobreak">'.$othertitle.'</span><br />'."\n".
12382: '<input type="text" name="'.$context.'_default" '.
12383: 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
12384: '</label>';
12385: } else {
12386: my $defcheck = ' ';
12387: if (ref($settings) eq 'HASH') {
12388: if (ref($settings->{$context}) eq 'ARRAY') {
12389: if (grep(/^default$/,@{$settings->{$context}})) {
12390: $defcheck = ' checked="checked" ';
12391: }
12392: } elsif (ref($settings->{$context}) eq 'HASH') {
12393: if (ref($settings->{$context}->{'default'}) eq 'HASH') {
12394: $defcheck = ' checked="checked" ';
12395: } elsif ($context eq 'webdav') {
12396: if ($settings->{$context}->{'default'}) {
12397: $defcheck = ' checked="checked" ';
12398: }
12399: }
12400: } elsif ($context eq 'statustocreate') {
1.315 raeburn 12401: $defcheck = ' checked="checked" ';
12402: }
1.99 raeburn 12403: }
1.429 raeburn 12404: $output .= '<span class="LC_nobreak"><label>'.
12405: '<input type="checkbox" name="'.$context.'" '.
12406: 'value="default"'.$defcheck.$onclick.'/>'.
12407: $othertitle.'</label></span>';
1.26 raeburn 12408: }
1.23 raeburn 12409: }
1.315 raeburn 12410: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 12411: return $output;
1.23 raeburn 12412: }
12413:
12414: sub sorted_searchtitles {
12415: my %searchtitles = &Apache::lonlocal::texthash(
12416: 'uname' => 'username',
12417: 'lastname' => 'last name',
12418: 'lastfirst' => 'last name, first name',
12419: );
12420: my @titleorder = ('uname','lastname','lastfirst');
12421: return (\%searchtitles,\@titleorder);
12422: }
12423:
1.25 raeburn 12424: sub sorted_searchtypes {
12425: my %srchtypes_desc = (
12426: exact => 'is exact match',
12427: contains => 'contains ..',
12428: begins => 'begins with ..',
12429: );
12430: my @srchtypeorder = ('exact','begins','contains');
12431: return (\%srchtypes_desc,\@srchtypeorder);
12432: }
12433:
1.3 raeburn 12434: sub usertype_update_row {
12435: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
12436: my $datatable;
12437: my $numinrow = 4;
12438: foreach my $type (@{$types}) {
12439: if (defined($usertypes->{$type})) {
12440: $$rownums ++;
12441: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
12442: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
12443: '</td><td class="LC_left_item"><table>';
12444: for (my $i=0; $i<@{$fields}; $i++) {
12445: my $rem = $i%($numinrow);
12446: if ($rem == 0) {
12447: if ($i > 0) {
12448: $datatable .= '</tr>';
12449: }
12450: $datatable .= '<tr>';
12451: }
12452: my $check = ' ';
1.39 raeburn 12453: if (ref($settings) eq 'HASH') {
12454: if (ref($settings->{'fields'}) eq 'HASH') {
12455: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
12456: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
12457: $check = ' checked="checked" ';
12458: }
1.3 raeburn 12459: }
12460: }
12461: }
12462:
12463: if ($i == @{$fields}-1) {
12464: my $colsleft = $numinrow - $rem;
12465: if ($colsleft > 1) {
12466: $datatable .= '<td colspan="'.$colsleft.'">';
12467: } else {
12468: $datatable .= '<td>';
12469: }
12470: } else {
12471: $datatable .= '<td>';
12472: }
1.8 raeburn 12473: $datatable .= '<span class="LC_nobreak"><label>'.
12474: '<input type="checkbox" name="updateable_'.$type.
12475: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
12476: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 12477: }
12478: $datatable .= '</tr></table></td></tr>';
12479: }
12480: }
12481: return $datatable;
1.1 raeburn 12482: }
12483:
12484: sub modify_login {
1.205 raeburn 12485: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 12486: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.386 raeburn 12487: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
1.412 raeburn 12488: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso);
1.168 raeburn 12489: %title = ( coursecatalog => 'Display course catalog',
12490: adminmail => 'Display administrator E-mail address',
1.188 raeburn 12491: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 12492: newuser => 'Link for visitors to create a user account',
1.386 raeburn 12493: loginheader => 'Log-in box header',
12494: saml => 'Dual SSO and non-SSO login');
1.168 raeburn 12495: @offon = ('off','on');
1.112 raeburn 12496: if (ref($domconfig{login}) eq 'HASH') {
12497: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
12498: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
12499: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
12500: }
12501: }
1.386 raeburn 12502: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
12503: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
12504: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
12505: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
12506: $saml{$lonhost} = 1;
12507: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
12508: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
12509: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
12510: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
12511: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
1.412 raeburn 12512: $samlwindow{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'window'};
1.386 raeburn 12513: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
12514: }
12515: }
12516: }
1.112 raeburn 12517: }
1.9 raeburn 12518: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
12519: \%domconfig,\%loginhash);
1.188 raeburn 12520: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12521: foreach my $item (@toggles) {
12522: $loginhash{login}{$item} = $env{'form.'.$item};
12523: }
1.41 raeburn 12524: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 12525: if (ref($colchanges{'login'}) eq 'HASH') {
12526: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
12527: \%loginhash);
12528: }
1.110 raeburn 12529:
1.149 raeburn 12530: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 12531: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 12532: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 12533: if (keys(%servers) > 1) {
12534: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 12535: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
12536: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
12537: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
12538: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
12539: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
12540: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12541: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12542: $changes{'loginvia'}{$lonhost} = 1;
12543: } else {
12544: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
12545: $changes{'loginvia'}{$lonhost} = 1;
12546: }
12547: } else {
12548: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12549: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12550: $changes{'loginvia'}{$lonhost} = 1;
12551: }
12552: }
12553: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
12554: foreach my $item (@loginvia_attribs) {
12555: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
12556: }
12557: } else {
12558: foreach my $item (@loginvia_attribs) {
12559: my $new = $env{'form.'.$lonhost.'_'.$item};
12560: if (($item eq 'serverpath') && ($new eq 'custom')) {
12561: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
12562: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12563: $new = '/';
12564: }
12565: }
12566: if (($item eq 'custompath') &&
12567: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12568: $new = '';
12569: }
12570: if ($new ne $curr_loginvia{$lonhost}{$item}) {
12571: $changes{'loginvia'}{$lonhost} = 1;
12572: }
12573: if ($item eq 'exempt') {
1.256 raeburn 12574: $new = &check_exempt_addresses($new);
1.128 raeburn 12575: }
12576: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12577: }
12578: }
1.112 raeburn 12579: } else {
1.128 raeburn 12580: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12581: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 12582: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 12583: foreach my $item (@loginvia_attribs) {
12584: my $new = $env{'form.'.$lonhost.'_'.$item};
12585: if (($item eq 'serverpath') && ($new eq 'custom')) {
12586: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12587: $new = '/';
12588: }
12589: }
12590: if (($item eq 'custompath') &&
12591: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12592: $new = '';
12593: }
12594: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12595: }
1.110 raeburn 12596: }
12597: }
12598: }
12599: }
1.119 raeburn 12600:
1.168 raeburn 12601: my $servadm = $r->dir_config('lonAdmEMail');
12602: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
12603: if (ref($domconfig{'login'}) eq 'HASH') {
12604: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
12605: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
12606: if ($lang eq 'nolang') {
12607: push(@currlangs,$lang);
12608: } elsif (defined($langchoices{$lang})) {
12609: push(@currlangs,$lang);
12610: } else {
12611: next;
12612: }
12613: }
12614: }
12615: }
12616: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
12617: if (@currlangs > 0) {
12618: foreach my $lang (@currlangs) {
12619: if (grep(/^\Q$lang\E$/,@delurls)) {
12620: $changes{'helpurl'}{$lang} = 1;
12621: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
12622: $changes{'helpurl'}{$lang} = 1;
12623: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
12624: push(@newlangs,$lang);
12625: } else {
12626: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12627: }
12628: }
12629: }
12630: unless (grep(/^nolang$/,@currlangs)) {
12631: if ($env{'form.loginhelpurl_nolang.filename'}) {
12632: $changes{'helpurl'}{'nolang'} = 1;
12633: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
12634: push(@newlangs,'nolang');
12635: }
12636: }
12637: if ($env{'form.loginhelpurl_add_lang'}) {
12638: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
12639: ($env{'form.loginhelpurl_add_file.filename'})) {
12640: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
12641: $addedfile = $env{'form.loginhelpurl_add_lang'};
12642: }
12643: }
12644: if ((@newlangs > 0) || ($addedfile)) {
12645: my $error;
12646: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12647: if ($configuserok eq 'ok') {
12648: if ($switchserver) {
12649: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
12650: } elsif ($author_ok eq 'ok') {
12651: my @allnew = @newlangs;
12652: if ($addedfile ne '') {
12653: push(@allnew,$addedfile);
12654: }
1.421 raeburn 12655: my $modified = [];
1.168 raeburn 12656: foreach my $lang (@allnew) {
12657: my $formelem = 'loginhelpurl_'.$lang;
12658: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
12659: $formelem = 'loginhelpurl_add_file';
12660: }
1.425 raeburn 12661: (my $result,$newurl{$lang}) =
1.421 raeburn 12662: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12663: "help/$lang",'','',$newfile{$lang},
12664: $modified);
1.168 raeburn 12665: if ($result eq 'ok') {
12666: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
12667: $changes{'helpurl'}{$lang} = 1;
12668: } else {
12669: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
12670: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 12671: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 12672: (!grep(/^\Q$lang\E$/,@delurls))) {
12673: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12674: }
12675: }
12676: }
1.421 raeburn 12677: &update_modify_urls($r,$modified);
1.168 raeburn 12678: } else {
12679: $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);
12680: }
12681: } else {
12682: $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);
12683: }
12684: if ($error) {
12685: &Apache::lonnet::logthis($error);
12686: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12687: }
12688: }
1.256 raeburn 12689:
12690: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
12691: if (ref($domconfig{'login'}) eq 'HASH') {
12692: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
12693: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
12694: if ($domservers{$lonhost}) {
12695: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12696: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 12697: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 12698: }
12699: }
12700: }
12701: }
12702: }
12703: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
12704: foreach my $lonhost (sort(keys(%domservers))) {
12705: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12706: $changes{'headtag'}{$lonhost} = 1;
12707: } else {
12708: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
12709: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
12710: }
12711: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
12712: push(@newhosts,$lonhost);
12713: } elsif ($currheadtagurls{$lonhost}) {
12714: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
12715: if ($currexempt{$lonhost}) {
1.289 raeburn 12716: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 12717: $changes{'headtag'}{$lonhost} = 1;
12718: }
12719: } elsif ($possexempt{$lonhost}) {
12720: $changes{'headtag'}{$lonhost} = 1;
12721: }
12722: if ($possexempt{$lonhost}) {
12723: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12724: }
12725: }
12726: }
12727: }
12728: if (@newhosts) {
12729: my $error;
12730: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12731: if ($configuserok eq 'ok') {
12732: if ($switchserver) {
12733: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
12734: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12735: my $modified = [];
1.256 raeburn 12736: foreach my $lonhost (@newhosts) {
12737: my $formelem = 'loginheadtag_'.$lonhost;
1.425 raeburn 12738: (my $result,$newheadtagurls{$lonhost}) =
1.421 raeburn 12739: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12740: "login/headtag/$lonhost",'','',
12741: $env{'form.loginheadtag_'.$lonhost.'.filename'},
12742: $modified);
1.256 raeburn 12743: if ($result eq 'ok') {
12744: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
12745: $changes{'headtag'}{$lonhost} = 1;
12746: if ($possexempt{$lonhost}) {
12747: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12748: }
12749: } else {
12750: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
12751: $newheadtagurls{$lonhost},$result);
12752: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12753: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
12754: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
12755: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
12756: }
12757: }
12758: }
1.421 raeburn 12759: &update_modify_urls($r,$modified);
1.256 raeburn 12760: } else {
12761: $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);
12762: }
12763: } else {
12764: $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);
12765: }
12766: if ($error) {
12767: &Apache::lonnet::logthis($error);
12768: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12769: }
12770: }
1.386 raeburn 12771: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
12772: my @newsamlimgs;
12773: foreach my $lonhost (keys(%domservers)) {
12774: if ($env{'form.saml_'.$lonhost}) {
12775: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
12776: push(@newsamlimgs,$lonhost);
12777: }
1.412 raeburn 12778: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12779: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
12780: }
12781: if ($saml{$lonhost}) {
1.412 raeburn 12782: if ($env{'form.saml_window_'.$lonhost} ne '1') {
12783: $env{'form.saml_window_'.$lonhost} = '';
12784: }
1.386 raeburn 12785: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
12786: #FIXME Need to obsolete published image
12787: delete($currsaml{$lonhost}{'img'});
12788: $changes{'saml'}{$lonhost} = 1;
12789: }
12790: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
12791: $changes{'saml'}{$lonhost} = 1;
12792: }
12793: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
12794: $changes{'saml'}{$lonhost} = 1;
12795: }
12796: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
12797: $changes{'saml'}{$lonhost} = 1;
12798: }
12799: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
12800: $changes{'saml'}{$lonhost} = 1;
12801: }
1.412 raeburn 12802: if ($env{'form.saml_window_'.$lonhost} ne $samlwindow{$lonhost}) {
12803: $changes{'saml'}{$lonhost} = 1;
12804: }
1.386 raeburn 12805: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
12806: $changes{'saml'}{$lonhost} = 1;
12807: }
12808: } else {
12809: $changes{'saml'}{$lonhost} = 1;
12810: }
1.412 raeburn 12811: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12812: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
12813: }
12814: } else {
1.425 raeburn 12815: if ($saml{$lonhost}) {
1.389 raeburn 12816: $changes{'saml'}{$lonhost} = 1;
12817: delete($currsaml{$lonhost});
12818: }
1.386 raeburn 12819: }
12820: }
12821: foreach my $posshost (keys(%currsaml)) {
1.425 raeburn 12822: unless (exists($domservers{$posshost})) {
12823: delete($currsaml{$posshost});
1.386 raeburn 12824: }
12825: }
12826: %{$loginhash{'login'}{'saml'}} = %currsaml;
12827: if (@newsamlimgs) {
12828: my $error;
12829: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12830: if ($configuserok eq 'ok') {
12831: if ($switchserver) {
12832: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
12833: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12834: my $modified = [];
1.386 raeburn 12835: foreach my $lonhost (@newsamlimgs) {
12836: my $formelem = 'saml_img_'.$lonhost;
1.425 raeburn 12837: my ($result,$imgurl) =
1.421 raeburn 12838: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12839: "login/saml/$lonhost",'','',
12840: $env{'form.saml_img_'.$lonhost.'.filename'},
12841: $modified);
1.386 raeburn 12842: if ($result eq 'ok') {
12843: $currsaml{$lonhost}{'img'} = $imgurl;
12844: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
12845: $changes{'saml'}{$lonhost} = 1;
12846: } else {
12847: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
12848: $lonhost,$result);
12849: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12850: }
12851: }
1.421 raeburn 12852: &update_modify_urls($r,$modified);
1.386 raeburn 12853: } else {
12854: $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);
12855: }
12856: } else {
12857: $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);
12858: }
12859: if ($error) {
12860: &Apache::lonnet::logthis($error);
12861: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12862: }
12863: }
1.169 raeburn 12864: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 12865:
12866: my $defaulthelpfile = '/adm/loginproblems.html';
12867: my $defaulttext = &mt('Default in use');
12868:
1.1 raeburn 12869: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
12870: $dom);
12871: if ($putresult eq 'ok') {
1.188 raeburn 12872: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12873: my %defaultchecked = (
12874: 'coursecatalog' => 'on',
1.188 raeburn 12875: 'helpdesk' => 'on',
1.42 raeburn 12876: 'adminmail' => 'off',
1.43 raeburn 12877: 'newuser' => 'off',
1.42 raeburn 12878: );
1.55 raeburn 12879: if (ref($domconfig{'login'}) eq 'HASH') {
12880: foreach my $item (@toggles) {
12881: if ($defaultchecked{$item} eq 'on') {
12882: if (($domconfig{'login'}{$item} eq '0') &&
12883: ($env{'form.'.$item} eq '1')) {
12884: $changes{$item} = 1;
12885: } elsif (($domconfig{'login'}{$item} eq '' ||
12886: $domconfig{'login'}{$item} eq '1') &&
12887: ($env{'form.'.$item} eq '0')) {
12888: $changes{$item} = 1;
12889: }
12890: } elsif ($defaultchecked{$item} eq 'off') {
12891: if (($domconfig{'login'}{$item} eq '1') &&
12892: ($env{'form.'.$item} eq '0')) {
12893: $changes{$item} = 1;
12894: } elsif (($domconfig{'login'}{$item} eq '' ||
12895: $domconfig{'login'}{$item} eq '0') &&
12896: ($env{'form.'.$item} eq '1')) {
12897: $changes{$item} = 1;
12898: }
1.42 raeburn 12899: }
12900: }
1.41 raeburn 12901: }
1.6 raeburn 12902: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 12903: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.386 raeburn 12904: if (exists($changes{'saml'})) {
12905: my $hostid_in_use;
12906: my @hosts = &Apache::lonnet::current_machine_ids();
12907: if (@hosts > 1) {
12908: foreach my $hostid (@hosts) {
12909: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
12910: $hostid_in_use = $hostid;
12911: last;
12912: }
12913: }
12914: } else {
12915: $hostid_in_use = $r->dir_config('lonHostID');
12916: }
12917: if (($hostid_in_use) &&
12918: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
1.387 raeburn 12919: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
1.386 raeburn 12920: }
12921: if (ref($lastactref) eq 'HASH') {
12922: if (ref($changes{'saml'}) eq 'HASH') {
12923: my %updates;
12924: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
12925: $lastactref->{'samllanding'} = \%updates;
12926: }
12927: }
12928: }
1.212 raeburn 12929: if (ref($lastactref) eq 'HASH') {
12930: $lastactref->{'domainconfig'} = 1;
12931: }
1.1 raeburn 12932: $resulttext = &mt('Changes made:').'<ul>';
12933: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 12934: if ($item eq 'loginvia') {
1.112 raeburn 12935: if (ref($changes{$item}) eq 'HASH') {
12936: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
12937: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 12938: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
12939: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
12940: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
12941: $protocol = 'http' if ($protocol ne 'https');
12942: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
12943:
12944: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
12945: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
12946: } else {
12947: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
12948: }
12949: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
12950: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
12951: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
12952: }
12953: $resulttext .= '</li>';
12954: } else {
12955: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
12956: }
1.112 raeburn 12957: } else {
1.128 raeburn 12958: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 12959: }
12960: }
1.128 raeburn 12961: $resulttext .= '</ul></li>';
1.112 raeburn 12962: }
1.168 raeburn 12963: } elsif ($item eq 'helpurl') {
12964: if (ref($changes{$item}) eq 'HASH') {
12965: foreach my $lang (sort(keys(%{$changes{$item}}))) {
12966: if (grep(/^\Q$lang\E$/,@delurls)) {
12967: my ($chg,$link);
12968: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
12969: if ($lang eq 'nolang') {
12970: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
12971: } else {
12972: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
12973: }
12974: $resulttext .= '<li>'.$chg.'</li>';
12975: } else {
12976: my $chg;
12977: if ($lang eq 'nolang') {
12978: $chg = &mt('custom log-in help file for no preferred language');
12979: } else {
12980: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
12981: }
12982: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
12983: $loginhash{'login'}{'helpurl'}{$lang}.
12984: '?inhibitmenu=yes',$chg,600,500).
12985: '</li>';
12986: }
12987: }
12988: }
1.256 raeburn 12989: } elsif ($item eq 'headtag') {
12990: if (ref($changes{$item}) eq 'HASH') {
12991: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12992: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12993: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
12994: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12995: $resulttext .= '<li><a href="'.
12996: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
12997: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
12998: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
12999: if ($possexempt{$lonhost}) {
13000: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
13001: } else {
13002: $resulttext .= &mt('included for any client IP');
13003: }
13004: $resulttext .= '</li>';
13005: }
13006: }
13007: }
1.386 raeburn 13008: } elsif ($item eq 'saml') {
13009: if (ref($changes{$item}) eq 'HASH') {
13010: my %notlt = (
13011: text => 'Text for log-in by SSO',
13012: img => 'SSO button image',
13013: alt => 'Alt text for button image',
13014: url => 'SSO URL',
13015: title => 'Tooltip for SSO link',
1.412 raeburn 13016: window => 'Pop-up window if iframe',
1.386 raeburn 13017: notsso => 'Text for non-SSO log-in',
13018: );
13019: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
13020: if (ref($currsaml{$lonhost}) eq 'HASH') {
13021: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
13022: '<ul>';
1.412 raeburn 13023: foreach my $key ('text','img','alt','url','title','window','notsso') {
1.386 raeburn 13024: if ($currsaml{$lonhost}{$key} eq '') {
13025: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
13026: } else {
13027: my $value = "'$currsaml{$lonhost}{$key}'";
13028: if ($key eq 'img') {
13029: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
1.412 raeburn 13030: } elsif ($key eq 'window') {
13031: $value = 'On';
1.386 raeburn 13032: }
13033: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
13034: $value).'</li>';
13035: }
13036: }
13037: $resulttext .= '</ul></li>';
13038: } else {
13039: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
13040: }
13041: }
13042: }
1.169 raeburn 13043: } elsif ($item eq 'captcha') {
13044: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 13045: my $chgtxt;
1.169 raeburn 13046: if ($loginhash{'login'}{$item} eq 'notused') {
13047: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
13048: } else {
13049: my %captchas = &captcha_phrases();
13050: if ($captchas{$loginhash{'login'}{$item}}) {
13051: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
13052: } else {
13053: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
13054: }
13055: }
13056: $resulttext .= '<li>'.$chgtxt.'</li>';
13057: }
13058: } elsif ($item eq 'recaptchakeys') {
13059: if (ref($loginhash{'login'}) eq 'HASH') {
13060: my ($privkey,$pubkey);
13061: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
13062: $pubkey = $loginhash{'login'}{$item}{'public'};
13063: $privkey = $loginhash{'login'}{$item}{'private'};
13064: }
13065: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
13066: if (!$pubkey) {
13067: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
13068: } else {
13069: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
13070: }
13071: if (!$privkey) {
13072: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
13073: } else {
1.251 raeburn 13074: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 13075: }
13076: $chgtxt .= '</ul>';
13077: $resulttext .= '<li>'.$chgtxt.'</li>';
13078: }
1.269 raeburn 13079: } elsif ($item eq 'recaptchaversion') {
13080: if (ref($loginhash{'login'}) eq 'HASH') {
13081: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 13082: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 13083: '</li>';
13084: }
13085: }
1.41 raeburn 13086: } else {
13087: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
13088: }
1.1 raeburn 13089: }
1.6 raeburn 13090: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 13091: } else {
13092: $resulttext = &mt('No changes made to log-in page settings');
13093: }
13094: } else {
1.11 albertel 13095: $resulttext = '<span class="LC_error">'.
13096: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 13097: }
1.6 raeburn 13098: if ($errors) {
1.9 raeburn 13099: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 13100: $errors.'</ul>';
13101: }
13102: return $resulttext;
13103: }
13104:
1.256 raeburn 13105: sub check_exempt_addresses {
13106: my ($iplist) = @_;
13107: $iplist =~ s/^\s+//;
13108: $iplist =~ s/\s+$//;
13109: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
13110: my (@okips,$new);
13111: foreach my $ip (@poss_ips) {
13112: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
13113: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
13114: push(@okips,$ip);
13115: }
13116: }
13117: }
13118: if (@okips > 0) {
13119: $new = join(',',@okips);
13120: } else {
13121: $new = '';
13122: }
13123: return $new;
13124: }
13125:
1.6 raeburn 13126: sub color_font_choices {
13127: my %choices =
13128: &Apache::lonlocal::texthash (
13129: bgs => "Background colors",
13130: links => "Link colors",
1.55 raeburn 13131: images => "Images",
1.6 raeburn 13132: font => "Font color",
1.201 raeburn 13133: fontmenu => "Font menu",
1.76 raeburn 13134: pgbg => "Page",
1.6 raeburn 13135: tabbg => "Header",
13136: sidebg => "Border",
13137: link => "Link",
13138: alink => "Active link",
13139: vlink => "Visited link",
13140: );
13141: return %choices;
13142: }
13143:
1.394 raeburn 13144: sub modify_ipaccess {
13145: my ($dom,$lastactref,%domconfig) = @_;
13146: my (@allpos,%changes,%confhash,$errors,$resulttext);
13147: my (@items,%deletions,%itemids,@warnings);
13148: my ($typeorder,$types) = &commblocktype_text();
13149: if ($env{'form.ipaccess_add'}) {
13150: my $name = $env{'form.ipaccess_name_add'};
13151: my ($newid,$error) = &get_ipaccess_id($dom,$name);
13152: if ($newid) {
13153: $itemids{'add'} = $newid;
13154: push(@items,'add');
13155: $changes{$newid} = 1;
13156: } else {
13157: $error = &mt('Failed to acquire unique ID for new IP access control item');
13158: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13159: }
13160: }
13161: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
13162: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
13163: if (@todelete) {
13164: map { $deletions{$_} = 1; } @todelete;
13165: }
13166: my $maxnum = $env{'form.ipaccess_maxnum'};
13167: for (my $i=0; $i<$maxnum; $i++) {
13168: my $itemid = $env{'form.ipaccess_id_'.$i};
13169: $itemid =~ s/\D+//g;
13170: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13171: if ($deletions{$itemid}) {
13172: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
13173: } else {
13174: push(@items,$i);
13175: $itemids{$i} = $itemid;
13176: }
13177: }
13178: }
13179: }
13180: foreach my $idx (@items) {
13181: my $itemid = $itemids{$idx};
13182: next unless ($itemid);
1.446 raeburn 13183: my ($position,%current);
13184: if ($idx eq 'add') {
13185: $position = $env{'form.ipaccess_pos_add'};
13186: } else {
13187: $position = $env{'form.ipaccess_pos_'.$itemid};
1.394 raeburn 13188: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13189: %current = %{$domconfig{'ipaccess'}{$itemid}};
13190: }
13191: }
13192: $position =~ s/\D+//g;
13193: if ($position ne '') {
13194: $allpos[$position] = $itemid;
13195: }
13196: my $name = $env{'form.ipaccess_name_'.$idx};
13197: $name =~ s/^\s+|\s+$//g;
13198: $confhash{$itemid}{'name'} = $name;
13199: my $possrange = $env{'form.ipaccess_range_'.$idx};
13200: $possrange =~ s/^\s+|\s+$//g;
13201: unless ($possrange eq '') {
13202: $possrange =~ s/[\r\n]+/\s/g;
13203: $possrange =~ s/\s*-\s*/-/g;
13204: $possrange =~ s/\s+/,/g;
13205: $possrange =~ s/,+/,/g;
13206: if ($possrange ne '') {
13207: my (@ok,$count);
1.425 raeburn 13208: $count = 0;
1.394 raeburn 13209: foreach my $poss (split(/\,/,$possrange)) {
13210: $count ++;
13211: $poss = &validate_ip_pattern($poss);
13212: if ($poss ne '') {
13213: push(@ok,$poss);
13214: }
13215: }
13216: my $diff = $count - scalar(@ok);
13217: if ($diff) {
13218: $errors .= '<li><span class="LC_error">'.
13219: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
13220: $diff,$name).
13221: '</span></li>';
13222: }
13223: if (@ok) {
13224: my @cidr_list;
13225: foreach my $item (@ok) {
13226: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
13227: }
13228: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
13229: }
13230: }
13231: }
13232: foreach my $field ('name','ip') {
13233: unless (($idx eq 'add') || ($changes{$itemid})) {
13234: if ($current{$field} ne $confhash{$itemid}{$field}) {
13235: $changes{$itemid} = 1;
13236: last;
13237: }
13238: }
13239: }
13240: $confhash{$itemid}{'commblocks'} = {};
1.425 raeburn 13241:
1.394 raeburn 13242: my %commblocks;
1.425 raeburn 13243: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
1.394 raeburn 13244: foreach my $type (@{$typeorder}) {
13245: if ($commblocks{$type}) {
13246: $confhash{$itemid}{'commblocks'}{$type} = 'on';
13247: }
13248: unless (($idx eq 'add') || ($changes{$itemid})) {
13249: if (ref($current{'commblocks'}) eq 'HASH') {
13250: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
13251: $changes{$itemid} = 1;
13252: }
13253: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
13254: $changes{$itemid} = 1;
13255: }
13256: }
13257: }
13258: $confhash{$itemid}{'courses'} = {};
13259: my %crsdeletions;
13260: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
13261: if (@delcrs) {
13262: map { $crsdeletions{$_} = 1; } @delcrs;
13263: }
13264: if (ref($current{'courses'}) eq 'HASH') {
13265: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
13266: if ($crsdeletions{$cid}) {
13267: $changes{$itemid} = 1;
13268: } else {
13269: $confhash{$itemid}{'courses'}{$cid} = 1;
13270: }
13271: }
13272: }
13273: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
13274: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
1.425 raeburn 13275: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
1.394 raeburn 13276: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
13277: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
13278: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
13279: $errors .= '<li><span class="LC_error">'.
13280: &mt('Invalid courseID [_1] omitted from list of allowed courses',
13281: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
13282: '</span></li>';
13283: } else {
13284: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
13285: $changes{$itemid} = 1;
13286: }
13287: }
13288: }
13289: if (@allpos > 0) {
13290: my $idx = 0;
13291: foreach my $itemid (@allpos) {
13292: if ($itemid ne '') {
13293: $confhash{$itemid}{'order'} = $idx;
13294: unless ($changes{$itemid}) {
13295: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
13296: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13297: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
13298: $changes{$itemid} = 1;
13299: }
13300: }
13301: }
13302: }
13303: $idx ++;
13304: }
13305: }
13306: }
13307: if (keys(%changes)) {
13308: my %defaultshash = (
13309: ipaccess => \%confhash,
13310: );
13311: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13312: $dom);
13313: if ($putresult eq 'ok') {
13314: my $cachetime = 1800;
13315: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
13316: if (ref($lastactref) eq 'HASH') {
13317: $lastactref->{'ipaccess'} = 1;
13318: }
13319: $resulttext = &mt('Changes made:').'<ul>';
13320: my %bynum;
13321: foreach my $itemid (sort(keys(%changes))) {
13322: if (ref($confhash{$itemid}) eq 'HASH') {
13323: my $position = $confhash{$itemid}{'order'};
13324: if ($position =~ /^\d+$/) {
13325: $bynum{$position} = $itemid;
13326: }
13327: }
13328: }
13329: if (keys(%deletions)) {
13330: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
13331: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
13332: }
13333: }
13334: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
13335: my $itemid = $bynum{$pos};
13336: if (ref($confhash{$itemid}) eq 'HASH') {
13337: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
13338: my $position = $pos + 1;
13339: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
13340: if ($confhash{$itemid}{'ip'} eq '') {
13341: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
13342: } else {
13343: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
13344: }
13345: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
13346: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
13347: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
13348: '</li>';
13349: } else {
13350: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
13351: }
13352: if (keys(%{$confhash{$itemid}{'courses'}})) {
13353: my @courses;
13354: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
1.425 raeburn 13355: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1.394 raeburn 13356: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
13357: }
13358: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
13359: join('</li><li>',@courses).'</li></ul>';
13360: } else {
13361: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
13362: }
1.395 raeburn 13363: $resulttext .= '</ul></li>';
1.394 raeburn 13364: }
13365: }
1.395 raeburn 13366: $resulttext .= '</ul>';
1.394 raeburn 13367: } else {
13368: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13369: }
13370: } else {
13371: $resulttext = &mt('No changes made');
13372: }
13373: if ($errors) {
13374: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
13375: $errors.'</ul></p>';
13376: }
13377: return $resulttext;
13378: }
13379:
13380: sub get_ipaccess_id {
13381: my ($domain,$location) = @_;
13382: # get lock on ipaccess db
13383: my $lockhash = {
13384: lock => $env{'user.name'}.
13385: ':'.$env{'user.domain'},
13386: };
13387: my $tries = 0;
13388: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13389: my ($id,$error);
13390:
13391: while (($gotlock ne 'ok') && ($tries<10)) {
13392: $tries ++;
13393: sleep (0.1);
13394: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13395: }
13396: if ($gotlock eq 'ok') {
13397: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
13398: if ($currids{'lock'}) {
13399: delete($currids{'lock'});
13400: if (keys(%currids)) {
13401: my @curr = sort { $a <=> $b } keys(%currids);
13402: if ($curr[-1] =~ /^\d+$/) {
13403: $id = 1 + $curr[-1];
13404: }
13405: } else {
13406: $id = 1;
13407: }
13408: if ($id) {
13409: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
13410: $error = 'nostore';
13411: }
13412: } else {
13413: $error = 'nonumber';
13414: }
13415: }
13416: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
13417: } else {
13418: $error = 'nolock';
13419: }
13420: return ($id,$error);
13421: }
13422:
1.429 raeburn 13423: sub modify_authordefaults {
13424: my ($dom,$lastactref,%domconfig) = @_;
13425: #
13426: # Retrieve current domain configuration for webDAV and Authoring Space quotas from $domconfig{'quotas'}.
13427: #
13428: my (%curr_quotas,%save_quotas,%confhash,%changes,%newvalues);
13429: if (ref($domconfig{'quotas'}) eq 'HASH') {
13430: foreach my $key (keys(%{$domconfig{'quotas'}})) {
13431: if ($key =~ /^webdav|authorquota$/) {
13432: $curr_quotas{$key} = $domconfig{'quotas'}{$key};
13433: } else {
13434: $save_quotas{$key} = $domconfig{'quotas'}{$key};
13435: }
13436: }
13437: }
13438: my %staticdefaults = (
13439: 'copyright' => 'default',
13440: 'sourceavail' => 'closed',
13441: 'nocodemirror' => 'off',
1.437 raeburn 13442: 'daxecollapse' => 'off',
1.429 raeburn 13443: 'domcoordacc' => 'on',
1.439 raeburn 13444: 'editors' => ['edit','xml'],
1.429 raeburn 13445: 'authorquota' => 500,
13446: 'webdav' => 0,
1.440 raeburn 13447: 'archive' => 'off',
1.429 raeburn 13448: );
13449: my %titles = &authordefaults_titles();
1.440 raeburn 13450: foreach my $item ('nocodemirror','daxecollapse','domcoordacc','archive') {
1.429 raeburn 13451: if ($env{'form.'.$item} =~ /^(0|1)$/) {
13452: $confhash{$item} = $env{'form.'.$item};
13453: }
13454: }
13455: if ($env{'form.copyright'} =~ /^(default|domain|public)$/) {
13456: $confhash{'copyright'} = $1;
13457: }
13458: if ($env{'form.sourceavail'} =~ /^(closed|open)$/) {
13459: $confhash{'sourceavail'} = $1;
13460: }
13461: my @posseditors = &Apache::loncommon::get_env_multiple('form.author_editors');
13462: my @okeditors = ('edit','xml','daxe');
13463: my @editors;
13464: foreach my $item (@posseditors) {
13465: if (grep(/^\Q$item\E$/,@okeditors)) {
13466: push(@editors,$item);
13467: }
13468: }
13469: $confhash{'editors'} = \@editors;
1.436 raeburn 13470:
1.429 raeburn 13471: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13472: my @insttypes;
13473: if (ref($types) eq 'ARRAY') {
13474: @insttypes = @{$types};
13475: }
13476: my @webdavon = &Apache::loncommon::get_env_multiple('form.webdav');
13477: my %webdav;
13478: map { $webdav{$_} = 1; } @webdavon;
13479: foreach my $type (@insttypes,'default') {
13480: my $possquota = $env{'form.authorquota_'.$type};
13481: if ($possquota =~ /^\d+$/) {
13482: $save_quotas{'authorquota'}{$type} = $possquota;
13483: }
13484: if ($webdav{$type}) {
13485: $save_quotas{'webdav'}{$type} = 1;
13486: } else {
13487: $save_quotas{'webdav'}{$type} = 0;
13488: }
13489: }
13490: if ($env{'form.webdav_LC_adv'} =~ /^(0|1)$/) {
13491: $save_quotas{'webdav'}{'_LC_adv'} = $env{'form.webdav_LC_adv'};
13492: }
13493: if (ref($domconfig{'authordefaults'}) eq 'HASH') {
1.440 raeburn 13494: foreach my $item ('nocodemirror','daxecollapse','domcoordacc','copyright','sourceavail','archive') {
1.429 raeburn 13495: if ($domconfig{'authordefaults'}{$item} ne $confhash{$item}) {
13496: $changes{$item} = 1;
13497: }
13498: }
13499: if (ref($domconfig{'authordefaults'}{'editors'}) eq 'ARRAY') {
1.436 raeburn 13500: my @diffs =
1.429 raeburn 13501: &Apache::loncommon::compare_arrays($confhash{'editors'},
13502: $domconfig{'authordefaults'}{'editors'});
13503: unless (@diffs == 0) {
13504: $changes{'editors'} = 1;
13505: }
13506: } else {
13507: my @diffs =
13508: &Apache::loncommon::compare_arrays($confhash{'editors'},
13509: $staticdefaults{'editors'});
13510: unless (@diffs == 0) {
13511: $changes{'editors'} = 1;
13512: }
13513: }
13514: } else {
13515: my @offon = ('off','on');
1.440 raeburn 13516: foreach my $item ('nocodemirror','daxecollapse','domcoordacc','archive') {
1.436 raeburn 13517: if ($offon[$confhash{$item}] ne $staticdefaults{$item}) {
1.429 raeburn 13518: $changes{$item} = 1;
13519: }
13520: }
13521: foreach my $item ('copyright','sourceavail') {
13522: if ($confhash{$item} ne $staticdefaults{$item}) {
13523: $changes{$item} = 1;
13524: }
13525: }
1.439 raeburn 13526: my @diffs =
13527: &Apache::loncommon::compare_arrays($confhash{'editors'},
13528: $staticdefaults{'editors'});
13529: unless (@diffs == 0) {
13530: $changes{'editors'} = 1;
13531: }
1.429 raeburn 13532: }
13533: foreach my $key ('authorquota','webdav') {
13534: if (ref($curr_quotas{$key}) eq 'HASH') {
13535: foreach my $type (@insttypes,'default') {
13536: if (exists($save_quotas{$key}{$type})) {
13537: if ($save_quotas{$key}{$type} ne $curr_quotas{$key}{$type}) {
13538: $changes{$key}{$type} = 1;
13539: }
13540: } elsif (exists($curr_quotas{$key}{$type})) {
13541: $save_quotas{$key}{$type} = $curr_quotas{$key}{$type};
13542: } else {
13543: $save_quotas{$key}{$type} = $staticdefaults{$key};
13544: }
13545: }
13546: } else {
13547: foreach my $type (@insttypes,'default') {
13548: if (exists($save_quotas{$key}{$type})) {
13549: unless ($save_quotas{$key}{$type} eq $staticdefaults{$key}) {
13550: $changes{$key}{$type} = 1;
13551: }
13552: } else {
13553: $save_quotas{$key}{$type} = $staticdefaults{$key};
13554: }
13555: }
13556: }
13557: }
13558: if (ref($curr_quotas{'webdav'}) eq 'HASH') {
13559: if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
1.436 raeburn 13560: if ($save_quotas{'webdav'}{'_LC_adv'} ne $curr_quotas{'webdav'}{'_LC_adv'}) {
1.429 raeburn 13561: $changes{'webdav_LC_adv'} = 1;
13562: }
13563: } elsif (exists($curr_quotas{'webdav'}{'_LC_adv'})) {
13564: $changes{'webdav_LC_adv'} = 1;
13565: }
13566: } elsif (exists($save_quotas{'webdav'}{'_LC_adv'})) {
13567: $changes{'webdav_LC_adv'} = 1;
13568: }
13569: my %confighash = (
13570: quotas => \%save_quotas,
13571: authordefaults => \%confhash,
13572: );
13573: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,
13574: $dom);
13575: my $resulttext;
13576: if ($putresult eq 'ok') {
13577: if (keys(%changes)) {
1.431 raeburn 13578: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.429 raeburn 13579: if ((exists($changes{'authorquota'})) || (exists($changes{'webdav'})) ||
1.436 raeburn 13580: ($changes{'webdav_LC_adv'})) {
1.429 raeburn 13581: if ((exists($changes{'authorquota'})) && (ref($save_quotas{'authorquota'}) eq 'HASH')) {
13582: $domdefaults{'authorquota'} = $save_quotas{'authorquota'};
13583: }
13584: if (((exists($changes{'webdav'})) || ($changes{'webdav_LC_adv'})) &&
13585: (ref($save_quotas{'webdav'}) eq 'HASH')) {
13586: $domdefaults{'webdav'} = $save_quotas{'webdav'};
13587: }
13588: }
13589: $resulttext = &mt('Changes made:').'<ul>';
13590: my $authoroverride;
1.437 raeburn 13591: foreach my $key ('nocodemirror','daxecollapse','domcoordacc','copyright','sourceavail') {
1.429 raeburn 13592: if (exists($changes{$key})) {
1.431 raeburn 13593: $domdefaults{$key} = $confhash{$key};
1.429 raeburn 13594: my $shown;
13595: unless ($authoroverride) {
13596: $resulttext .= '<li>'.&mt('Defaults which can be overridden by Author').'<ul>';
13597: $authoroverride = 1;
13598: }
1.437 raeburn 13599: if (($key eq 'nocodemirror') || ($key eq 'daxecollapse') || ($key eq 'domcoordacc')) {
1.429 raeburn 13600: $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
13601: } elsif ($key eq 'copyright') {
13602: $shown = &Apache::loncommon::copyrightdescription($confhash{$key});
13603: } elsif ($key eq 'sourceavail') {
13604: $shown = &Apache::loncommon::source_copyrightdescription($confhash{$key});
13605: }
1.436 raeburn 13606: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
1.429 raeburn 13607: }
13608: }
13609: if ($authoroverride) {
13610: $resulttext .= '</ul></li>';
13611: }
13612: my $domcoordoverride;
1.440 raeburn 13613: foreach my $key ('editors','authorquota','webdav','webdav_LC_adv','archive') {
1.429 raeburn 13614: if (exists($changes{$key})) {
13615: my $shown;
13616: unless ($domcoordoverride) {
13617: $resulttext .= '<li>'.&mt('Defaults which can be overridden by a Domain Coodinator').'<ul>';
13618: $domcoordoverride = 1;
13619: }
13620: if ($key eq 'editors') {
1.431 raeburn 13621: if (ref($confhash{'editors'}) eq 'ARRAY') {
13622: $domdefaults{'editors'} = join(',',@{$confhash{'editors'}});
13623: if (@{$confhash{'editors'}}) {
13624: $shown = join(', ', map { $titles{$_} } @{$confhash{'editors'}});
13625: } else {
13626: $shown = &mt('None');
13627: }
1.429 raeburn 13628: }
13629: } elsif ($key eq 'authorquota') {
13630: foreach my $type (@insttypes) {
13631: $shown .= $usertypes->{$type}.' -- '.$save_quotas{$key}{$type}.', ';
13632: }
13633: $shown .= $othertitle.' -- '.$save_quotas{$key}{'default'};
13634: } elsif ($key eq 'webdav') {
13635: foreach my $type (@insttypes) {
13636: $shown .= $usertypes->{$type}.' -- '. ($save_quotas{$key}{$type} ? &mt('Yes') : &mt('No')).', ';
13637: }
13638: $shown .= $othertitle.' -- '. ($save_quotas{$key}{'default'} ? &mt('Yes') : &mt('No'));
13639: } elsif ($key eq 'webdav_LC_adv') {
13640: if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
13641: $shown = ($save_quotas{'webdav'}{'_LC_adv'} ? $titles{'overon'} : $titles{'overoff'});
13642: } else {
13643: $shown = $titles{'none'};
13644: }
1.440 raeburn 13645: } elsif ($key eq 'archive') {
1.441 raeburn 13646: $domdefaults{$key} = $confhash{$key};
1.440 raeburn 13647: $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
1.429 raeburn 13648: }
13649: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
1.436 raeburn 13650: }
1.429 raeburn 13651: }
13652: if ($domcoordoverride) {
13653: $resulttext .= '</ul></li>';
13654: }
1.439 raeburn 13655: $resulttext .= '</ul>';
1.431 raeburn 13656: my $cachetime = 24*60*60;
13657: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13658: if (ref($lastactref) eq 'HASH') {
13659: $lastactref->{'domdefaults'} = 1;
13660: }
1.429 raeburn 13661: } else {
13662: $resulttext = &mt('No changes made to Authoring Space defaults');
13663: }
13664: }
13665: return $resulttext;
13666: }
13667:
1.6 raeburn 13668: sub modify_rolecolors {
1.205 raeburn 13669: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 13670: my ($resulttext,%rolehash);
13671: $rolehash{'rolecolors'} = {};
1.55 raeburn 13672: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
13673: if ($domconfig{'rolecolors'} eq '') {
13674: $domconfig{'rolecolors'} = {};
13675: }
13676: }
1.9 raeburn 13677: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 13678: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
13679: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
13680: $dom);
13681: if ($putresult eq 'ok') {
13682: if (keys(%changes) > 0) {
1.41 raeburn 13683: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 13684: if (ref($lastactref) eq 'HASH') {
13685: $lastactref->{'domainconfig'} = 1;
13686: }
1.6 raeburn 13687: $resulttext = &display_colorchgs($dom,\%changes,$roles,
13688: $rolehash{'rolecolors'});
13689: } else {
13690: $resulttext = &mt('No changes made to default color schemes');
13691: }
13692: } else {
1.11 albertel 13693: $resulttext = '<span class="LC_error">'.
13694: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 13695: }
13696: if ($errors) {
13697: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
13698: $errors.'</ul>';
13699: }
13700: return $resulttext;
13701: }
13702:
13703: sub modify_colors {
1.9 raeburn 13704: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 13705: my (%changes,%choices);
1.51 raeburn 13706: my @bgs;
1.6 raeburn 13707: my @links = ('link','alink','vlink');
1.41 raeburn 13708: my @logintext;
1.6 raeburn 13709: my @images;
13710: my $servadm = $r->dir_config('lonAdmEMail');
13711: my $errors;
1.200 raeburn 13712: my %defaults;
1.6 raeburn 13713: foreach my $role (@{$roles}) {
13714: if ($role eq 'login') {
1.12 raeburn 13715: %choices = &login_choices();
1.41 raeburn 13716: @logintext = ('textcol','bgcol');
1.12 raeburn 13717: } else {
13718: %choices = &color_font_choices();
13719: }
13720: if ($role eq 'login') {
1.41 raeburn 13721: @images = ('img','logo','domlogo','login');
1.51 raeburn 13722: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 13723: } else {
1.445 raeburn 13724: @images = ();
1.200 raeburn 13725: @bgs = ('pgbg','tabbg','sidebg');
13726: }
13727: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
1.444 raeburn 13728: $env{'form.'.$role.'_font'} = lc($env{'form.'.$role.'_font'});
13729: if ($env{'form.'.$role.'_font'} =~ /^\w+/) {
13730: $env{'form.'.$role.'_font'} = '#'.$env{'form.'.$role.'_font'};
13731: }
13732: unless ($env{'form.'.$role.'_font'} eq lc($defaults{'font'})) {
1.200 raeburn 13733: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
13734: }
13735: if ($role eq 'login') {
13736: foreach my $item (@logintext) {
1.234 raeburn 13737: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13738: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13739: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13740: }
13741: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 13742: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13743: }
13744: }
13745: } else {
1.234 raeburn 13746: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
13747: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
13748: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
13749: }
1.445 raeburn 13750: unless ($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 13751: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
13752: }
1.6 raeburn 13753: }
1.200 raeburn 13754: foreach my $item (@bgs) {
1.234 raeburn 13755: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13756: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13757: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13758: }
13759: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 13760: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13761: }
13762: }
13763: foreach my $item (@links) {
1.234 raeburn 13764: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13765: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13766: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13767: }
13768: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 13769: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13770: }
1.6 raeburn 13771: }
1.46 raeburn 13772: my ($configuserok,$author_ok,$switchserver) =
13773: &config_check($dom,$confname,$servadm);
1.9 raeburn 13774: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 13775: if (ref($domconfig->{$role}) ne 'HASH') {
13776: $domconfig->{$role} = {};
13777: }
1.8 raeburn 13778: foreach my $img (@images) {
1.402 raeburn 13779: if ($role eq 'login') {
13780: if (($img eq 'img') || ($img eq 'logo')) {
13781: if (defined($env{'form.login_showlogo_'.$img})) {
13782: $confhash->{$role}{'showlogo'}{$img} = 1;
13783: } else {
13784: $confhash->{$role}{'showlogo'}{$img} = 0;
13785: }
13786: }
13787: if ($env{'form.login_alt_'.$img} ne '') {
13788: $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
1.70 raeburn 13789: }
1.402 raeburn 13790: }
1.18 albertel 13791: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
13792: && !defined($domconfig->{$role}{$img})
13793: && !$env{'form.'.$role.'_del_'.$img}
13794: && $env{'form.'.$role.'_import_'.$img}) {
13795: # import the old configured image from the .tab setting
13796: # if they haven't provided a new one
13797: $domconfig->{$role}{$img} =
13798: $env{'form.'.$role.'_import_'.$img};
13799: }
1.6 raeburn 13800: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 13801: my $error;
1.6 raeburn 13802: if ($configuserok eq 'ok') {
1.9 raeburn 13803: if ($switchserver) {
1.12 raeburn 13804: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 13805: } else {
13806: if ($author_ok eq 'ok') {
1.421 raeburn 13807: my $modified = [];
1.9 raeburn 13808: my ($result,$logourl) =
1.421 raeburn 13809: &Apache::lonconfigsettings::publishlogo($r,'upload',$role.'_'.$img,
13810: $dom,$confname,$img,$width,$height,
13811: '',$modified);
1.9 raeburn 13812: if ($result eq 'ok') {
13813: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 13814: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13815: &update_modify_urls($r,$modified);
1.9 raeburn 13816: } else {
1.12 raeburn 13817: $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 13818: }
13819: } else {
1.46 raeburn 13820: $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 13821: }
13822: }
13823: } else {
1.46 raeburn 13824: $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 13825: }
13826: if ($error) {
1.8 raeburn 13827: &Apache::lonnet::logthis($error);
1.11 albertel 13828: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 13829: }
13830: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 13831: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
13832: my $error;
13833: if ($configuserok eq 'ok') {
13834: # is confname an author?
13835: if ($switchserver eq '') {
13836: if ($author_ok eq 'ok') {
1.421 raeburn 13837: my $modified = [];
1.9 raeburn 13838: my ($result,$logourl) =
1.421 raeburn 13839: &Apache::lonconfigsettings::publishlogo($r,'copy',$domconfig->{$role}{$img},
13840: $dom,$confname,$img,$width,$height,
13841: '',$modified);
1.9 raeburn 13842: if ($result eq 'ok') {
13843: $confhash->{$role}{$img} = $logourl;
1.18 albertel 13844: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13845: &update_modify_urls($r,$modified);
1.9 raeburn 13846: }
13847: }
13848: }
13849: }
1.6 raeburn 13850: }
13851: }
13852: }
13853: if (ref($domconfig) eq 'HASH') {
13854: if (ref($domconfig->{$role}) eq 'HASH') {
13855: foreach my $img (@images) {
13856: if ($domconfig->{$role}{$img} ne '') {
13857: if ($env{'form.'.$role.'_del_'.$img}) {
13858: $confhash->{$role}{$img} = '';
1.12 raeburn 13859: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13860: } else {
1.9 raeburn 13861: if ($confhash->{$role}{$img} eq '') {
13862: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
13863: }
1.6 raeburn 13864: }
13865: } else {
13866: if ($env{'form.'.$role.'_del_'.$img}) {
13867: $confhash->{$role}{$img} = '';
1.12 raeburn 13868: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13869: }
13870: }
1.402 raeburn 13871: if ($role eq 'login') {
13872: if (($img eq 'logo') || ($img eq 'img')) {
13873: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
13874: if ($confhash->{$role}{'showlogo'}{$img} ne
13875: $domconfig->{$role}{'showlogo'}{$img}) {
13876: $changes{$role}{'showlogo'}{$img} = 1;
13877: }
13878: } else {
13879: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13880: $changes{$role}{'showlogo'}{$img} = 1;
13881: }
1.70 raeburn 13882: }
1.402 raeburn 13883: }
13884: if ($img ne 'login') {
13885: if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
13886: if ($confhash->{$role}{'alttext'}{$img} ne
13887: $domconfig->{$role}{'alttext'}{$img}) {
13888: $changes{$role}{'alttext'}{$img} = 1;
13889: }
13890: } else {
13891: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13892: $changes{$role}{'alttext'}{$img} = 1;
13893: }
1.70 raeburn 13894: }
13895: }
13896: }
13897: }
1.6 raeburn 13898: if ($domconfig->{$role}{'font'} ne '') {
13899: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
13900: $changes{$role}{'font'} = 1;
13901: }
13902: } else {
13903: if ($confhash->{$role}{'font'}) {
13904: $changes{$role}{'font'} = 1;
13905: }
13906: }
1.107 raeburn 13907: if ($role ne 'login') {
13908: if ($domconfig->{$role}{'fontmenu'} ne '') {
13909: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
13910: $changes{$role}{'fontmenu'} = 1;
13911: }
13912: } else {
13913: if ($confhash->{$role}{'fontmenu'}) {
13914: $changes{$role}{'fontmenu'} = 1;
13915: }
1.97 tempelho 13916: }
13917: }
1.6 raeburn 13918: foreach my $item (@bgs) {
13919: if ($domconfig->{$role}{$item} ne '') {
13920: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13921: $changes{$role}{'bgs'}{$item} = 1;
13922: }
13923: } else {
13924: if ($confhash->{$role}{$item}) {
13925: $changes{$role}{'bgs'}{$item} = 1;
13926: }
13927: }
13928: }
13929: foreach my $item (@links) {
13930: if ($domconfig->{$role}{$item} ne '') {
13931: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13932: $changes{$role}{'links'}{$item} = 1;
13933: }
13934: } else {
13935: if ($confhash->{$role}{$item}) {
13936: $changes{$role}{'links'}{$item} = 1;
13937: }
13938: }
13939: }
1.41 raeburn 13940: foreach my $item (@logintext) {
13941: if ($domconfig->{$role}{$item} ne '') {
13942: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13943: $changes{$role}{'logintext'}{$item} = 1;
13944: }
13945: } else {
13946: if ($confhash->{$role}{$item}) {
13947: $changes{$role}{'logintext'}{$item} = 1;
13948: }
13949: }
13950: }
1.6 raeburn 13951: } else {
13952: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13953: \@logintext,$confhash,\%changes);
1.6 raeburn 13954: }
13955: } else {
13956: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13957: \@logintext,$confhash,\%changes);
1.6 raeburn 13958: }
13959: }
13960: return ($errors,%changes);
13961: }
13962:
1.46 raeburn 13963: sub config_check {
13964: my ($dom,$confname,$servadm) = @_;
13965: my ($configuserok,$author_ok,$switchserver,%currroles);
13966: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
13967: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
13968: $confname,$servadm);
13969: if ($configuserok eq 'ok') {
13970: $switchserver = &check_switchserver($dom,$confname);
13971: if ($switchserver eq '') {
13972: $author_ok = &check_authorstatus($dom,$confname,%currroles);
13973: }
13974: }
13975: return ($configuserok,$author_ok,$switchserver);
13976: }
13977:
1.6 raeburn 13978: sub default_change_checker {
1.41 raeburn 13979: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 13980: foreach my $item (@{$links}) {
13981: if ($confhash->{$role}{$item}) {
13982: $changes->{$role}{'links'}{$item} = 1;
13983: }
13984: }
13985: foreach my $item (@{$bgs}) {
13986: if ($confhash->{$role}{$item}) {
13987: $changes->{$role}{'bgs'}{$item} = 1;
13988: }
13989: }
1.41 raeburn 13990: foreach my $item (@{$logintext}) {
13991: if ($confhash->{$role}{$item}) {
13992: $changes->{$role}{'logintext'}{$item} = 1;
13993: }
13994: }
1.6 raeburn 13995: foreach my $img (@{$images}) {
13996: if ($env{'form.'.$role.'_del_'.$img}) {
13997: $confhash->{$role}{$img} = '';
1.12 raeburn 13998: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 13999: }
1.70 raeburn 14000: if ($role eq 'login') {
14001: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
14002: $changes->{$role}{'showlogo'}{$img} = 1;
14003: }
1.402 raeburn 14004: if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
14005: if ($confhash->{$role}{'alttext'}{$img} ne '') {
14006: $changes->{$role}{'alttext'}{$img} = 1;
14007: }
14008: }
1.70 raeburn 14009: }
1.6 raeburn 14010: }
14011: if ($confhash->{$role}{'font'}) {
14012: $changes->{$role}{'font'} = 1;
14013: }
1.48 raeburn 14014: }
1.6 raeburn 14015:
14016: sub display_colorchgs {
14017: my ($dom,$changes,$roles,$confhash) = @_;
14018: my (%choices,$resulttext);
14019: if (!grep(/^login$/,@{$roles})) {
14020: $resulttext = &mt('Changes made:').'<br />';
14021: }
14022: foreach my $role (@{$roles}) {
14023: if ($role eq 'login') {
14024: %choices = &login_choices();
14025: } else {
14026: %choices = &color_font_choices();
14027: }
14028: if (ref($changes->{$role}) eq 'HASH') {
14029: if ($role ne 'login') {
14030: $resulttext .= '<h4>'.&mt($role).'</h4>';
14031: }
14032: foreach my $key (sort(keys(%{$changes->{$role}}))) {
14033: if ($role ne 'login') {
14034: $resulttext .= '<ul>';
14035: }
14036: if (ref($changes->{$role}{$key}) eq 'HASH') {
14037: if ($role ne 'login') {
14038: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
14039: }
14040: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 14041: if (($role eq 'login') && ($key eq 'showlogo')) {
14042: if ($confhash->{$role}{$key}{$item}) {
14043: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
14044: } else {
14045: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
14046: }
1.402 raeburn 14047: } elsif (($role eq 'login') && ($key eq 'alttext')) {
14048: if ($confhash->{$role}{$key}{$item} ne '') {
1.403 raeburn 14049: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
1.402 raeburn 14050: $confhash->{$role}{$key}{$item}).'</li>';
14051: } else {
14052: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
14053: }
1.70 raeburn 14054: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 14055: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
14056: } else {
1.12 raeburn 14057: my $newitem = $confhash->{$role}{$item};
14058: if ($key eq 'images') {
1.306 raeburn 14059: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 14060: }
14061: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 14062: }
14063: }
14064: if ($role ne 'login') {
14065: $resulttext .= '</ul></li>';
14066: }
14067: } else {
14068: if ($confhash->{$role}{$key} eq '') {
14069: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
14070: } else {
14071: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
14072: }
14073: }
14074: if ($role ne 'login') {
14075: $resulttext .= '</ul>';
14076: }
14077: }
14078: }
14079: }
1.3 raeburn 14080: return $resulttext;
1.1 raeburn 14081: }
14082:
1.9 raeburn 14083: sub thumb_dimensions {
14084: return ('200','50');
14085: }
14086:
1.16 raeburn 14087: sub check_dimensions {
14088: my ($inputfile) = @_;
14089: my ($fullwidth,$fullheight);
14090: if ($inputfile =~ m|^[/\w.\-]+$|) {
14091: if (open(PIPE,"identify $inputfile 2>&1 |")) {
14092: my $imageinfo = <PIPE>;
14093: if (!close(PIPE)) {
14094: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
14095: }
14096: chomp($imageinfo);
14097: my ($fullsize) =
1.21 raeburn 14098: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 14099: if ($fullsize) {
14100: ($fullwidth,$fullheight) = split(/x/,$fullsize);
14101: }
14102: }
14103: }
14104: return ($fullwidth,$fullheight);
14105: }
14106:
1.9 raeburn 14107: sub check_configuser {
14108: my ($uhome,$dom,$confname,$servadm) = @_;
14109: my ($configuserok,%currroles);
14110: if ($uhome eq 'no_host') {
14111: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.361 raeburn 14112: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 14113: $configuserok =
14114: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
14115: $configpass,'','','','','',undef,$servadm);
14116: } else {
14117: $configuserok = 'ok';
14118: %currroles =
14119: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
14120: }
14121: return ($configuserok,%currroles);
14122: }
14123:
14124: sub check_authorstatus {
14125: my ($dom,$confname,%currroles) = @_;
14126: my $author_ok;
1.40 raeburn 14127: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 14128: my $start = time;
14129: my $end = 0;
14130: $author_ok =
14131: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 14132: 'au',$end,$start,'','','domconfig');
1.9 raeburn 14133: } else {
14134: $author_ok = 'ok';
14135: }
14136: return $author_ok;
14137: }
14138:
1.421 raeburn 14139: sub update_modify_urls {
14140: my ($r,$modified) = @_;
14141: if ((ref($modified) eq 'ARRAY') && (@{$modified})) {
14142: push(@{$modified_urls},$modified);
14143: unless ($registered_cleanup) {
14144: my $handlers = $r->get_handlers('PerlCleanupHandler');
14145: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
14146: $registered_cleanup=1;
1.9 raeburn 14147: }
14148: }
1.155 raeburn 14149: }
14150:
14151: sub notifysubscribed {
14152: foreach my $targetsource (@{$modified_urls}){
14153: next unless (ref($targetsource) eq 'ARRAY');
14154: my ($target,$source)=@{$targetsource};
14155: if ($source ne '') {
1.316 raeburn 14156: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 14157: print $logfh "\nCleanup phase: Notifications\n";
14158: my @subscribed=&subscribed_hosts($target);
14159: foreach my $subhost (@subscribed) {
14160: print $logfh "\nNotifying host ".$subhost.':';
14161: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
14162: print $logfh $reply;
14163: }
14164: my @subscribedmeta=&subscribed_hosts("$target.meta");
14165: foreach my $subhost (@subscribedmeta) {
14166: print $logfh "\nNotifying host for metadata only ".$subhost.':';
14167: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
14168: $subhost);
14169: print $logfh $reply;
14170: }
14171: print $logfh "\n============ Done ============\n";
1.160 raeburn 14172: close($logfh);
1.155 raeburn 14173: }
14174: }
14175: }
14176: return OK;
14177: }
14178:
14179: sub subscribed_hosts {
14180: my ($target) = @_;
14181: my @subscribed;
1.316 raeburn 14182: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 14183: while (my $subline=<$fh>) {
14184: if ($subline =~ /^($match_lonid):/) {
14185: my $host = $1;
14186: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
14187: unless (grep(/^\Q$host\E$/,@subscribed)) {
14188: push(@subscribed,$host);
14189: }
14190: }
14191: }
14192: }
14193: }
14194: return @subscribed;
1.9 raeburn 14195: }
14196:
14197: sub check_switchserver {
14198: my ($dom,$confname) = @_;
1.424 raeburn 14199: my ($allowed,$switchserver,$home);
14200: if ($confname eq '') {
1.9 raeburn 14201: $home = &Apache::lonnet::domain($dom,'primary');
1.424 raeburn 14202: } else {
14203: $home = &Apache::lonnet::homeserver($confname,$dom);
14204: if ($home eq 'no_host') {
14205: $home = &Apache::lonnet::domain($dom,'primary');
14206: }
1.9 raeburn 14207: }
14208: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 14209: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
14210: if (!$allowed) {
1.426 raeburn 14211: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
14212: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
14213: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 14214: }
14215: return $switchserver;
14216: }
14217:
1.1 raeburn 14218: sub modify_quotas {
1.216 raeburn 14219: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 14220: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 14221: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 14222: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
14223: $validationfieldsref);
1.86 raeburn 14224: if ($action eq 'quotas') {
1.429 raeburn 14225: $context = 'tools';
1.163 raeburn 14226: } else {
1.86 raeburn 14227: $context = $action;
14228: }
14229: if ($context eq 'requestcourses') {
1.325 raeburn 14230: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 14231: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 14232: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
14233: %titles = &courserequest_titles();
14234: $toolregexp = join('|',@usertools);
14235: %conditions = &courserequest_conditions();
1.216 raeburn 14236: $confname = $dom.'-domainconfig';
14237: my $servadm = $r->dir_config('lonAdmEMail');
14238: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 14239: ($validationitemsref,$validationnamesref,$validationfieldsref) =
14240: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 14241: } elsif ($context eq 'requestauthor') {
14242: @usertools = ('author');
14243: %titles = &authorrequest_titles();
1.86 raeburn 14244: } else {
1.430 raeburn 14245: @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.101 raeburn 14246: %titles = &tool_titles();
1.86 raeburn 14247: }
1.212 raeburn 14248: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 14249: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 14250: foreach my $key (keys(%env)) {
1.101 raeburn 14251: if ($context eq 'requestcourses') {
14252: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
14253: my $item = $1;
14254: my $type = $2;
14255: if ($type =~ /^limit_(.+)/) {
14256: $limithash{$item}{$1} = $env{$key};
14257: } else {
14258: $confhash{$item}{$type} = $env{$key};
14259: }
14260: }
1.163 raeburn 14261: } elsif ($context eq 'requestauthor') {
14262: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
14263: $confhash{$1} = $env{$key};
14264: }
1.101 raeburn 14265: } else {
1.86 raeburn 14266: if ($key =~ /^form\.quota_(.+)$/) {
14267: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 14268: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 14269: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
14270: }
1.72 raeburn 14271: }
14272: }
1.163 raeburn 14273: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 14274: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 14275: @approvalnotify = sort(@approvalnotify);
14276: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 14277: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 14278: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
14279: foreach my $type (@hasuniquecode) {
14280: if (grep(/^\Q$type\E$/,@crstypes)) {
14281: $confhash{'uniquecode'}{$type} = 1;
14282: }
1.216 raeburn 14283: }
1.242 raeburn 14284: my (%newbook,%allpos);
1.216 raeburn 14285: if ($context eq 'requestcourses') {
1.242 raeburn 14286: foreach my $type ('textbooks','templates') {
14287: @{$allpos{$type}} = ();
14288: my $invalid;
14289: if ($type eq 'textbooks') {
14290: $invalid = &mt('Invalid LON-CAPA course for textbook');
14291: } else {
14292: $invalid = &mt('Invalid LON-CAPA course for template');
14293: }
14294: if ($env{'form.'.$type.'_addbook'}) {
14295: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
14296: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
14297: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
14298: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
14299: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
14300: } else {
14301: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
14302: my $position = $env{'form.'.$type.'_addbook_pos'};
14303: $position =~ s/\D+//g;
14304: if ($position ne '') {
14305: $allpos{$type}[$position] = $newbook{$type};
14306: }
1.216 raeburn 14307: }
1.242 raeburn 14308: } else {
14309: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 14310: }
14311: }
1.242 raeburn 14312: }
1.216 raeburn 14313: }
1.102 raeburn 14314: if (ref($domconfig{$action}) eq 'HASH') {
14315: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
14316: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
14317: $changes{'notify'}{'approval'} = 1;
14318: }
14319: } else {
1.144 raeburn 14320: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14321: $changes{'notify'}{'approval'} = 1;
14322: }
14323: }
1.218 raeburn 14324: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
14325: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14326: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
14327: unless ($confhash{'uniquecode'}{$crstype}) {
14328: $changes{'uniquecode'} = 1;
14329: }
14330: }
14331: unless ($changes{'uniquecode'}) {
14332: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
14333: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
14334: $changes{'uniquecode'} = 1;
14335: }
14336: }
14337: }
14338: } else {
14339: $changes{'uniquecode'} = 1;
14340: }
14341: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
14342: $changes{'uniquecode'} = 1;
1.216 raeburn 14343: }
14344: if ($context eq 'requestcourses') {
1.242 raeburn 14345: foreach my $type ('textbooks','templates') {
14346: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14347: my %deletions;
14348: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
14349: if (@todelete) {
14350: map { $deletions{$_} = 1; } @todelete;
14351: }
14352: my %imgdeletions;
14353: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
14354: if (@todeleteimages) {
14355: map { $imgdeletions{$_} = 1; } @todeleteimages;
14356: }
14357: my $maxnum = $env{'form.'.$type.'_maxnum'};
14358: for (my $i=0; $i<=$maxnum; $i++) {
14359: my $itemid = $env{'form.'.$type.'_id_'.$i};
14360: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
14361: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
14362: if ($deletions{$key}) {
14363: if ($domconfig{$action}{$type}{$key}{'image'}) {
14364: #FIXME need to obsolete item in RES space
14365: }
14366: next;
14367: } else {
14368: my $newpos = $env{'form.'.$itemid};
14369: $newpos =~ s/\D+//g;
1.243 raeburn 14370: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 14371: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 14372: ($type eq 'templates'));
1.242 raeburn 14373: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
14374: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
14375: $changes{$type}{$key} = 1;
14376: }
14377: }
14378: $allpos{$type}[$newpos] = $key;
14379: }
14380: if ($imgdeletions{$key}) {
14381: $changes{$type}{$key} = 1;
1.216 raeburn 14382: #FIXME need to obsolete item in RES space
1.242 raeburn 14383: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
14384: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 14385: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14386: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14387: } else {
14388: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
14389: $cdom,$cnum,$type,$configuserok,
14390: $switchserver,$author_ok);
14391: if ($imgurl) {
14392: $confhash{$type}{$key}{'image'} = $imgurl;
14393: $changes{$type}{$key} = 1;
14394: }
14395: if ($error) {
14396: &Apache::lonnet::logthis($error);
14397: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14398: }
14399: }
1.242 raeburn 14400: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
14401: $confhash{$type}{$key}{'image'} =
14402: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 14403: }
14404: }
14405: }
14406: }
14407: }
14408: }
1.102 raeburn 14409: } else {
1.144 raeburn 14410: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14411: $changes{'notify'}{'approval'} = 1;
14412: }
1.218 raeburn 14413: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 14414: $changes{'uniquecode'} = 1;
14415: }
14416: }
14417: if ($context eq 'requestcourses') {
1.242 raeburn 14418: foreach my $type ('textbooks','templates') {
14419: if ($newbook{$type}) {
14420: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 14421: foreach my $item ('subject','title','publisher','author') {
14422: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14423: ($type eq 'template'));
1.242 raeburn 14424: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
14425: if ($env{'form.'.$type.'_addbook_'.$item}) {
14426: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
14427: }
14428: }
14429: if ($type eq 'textbooks') {
14430: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
14431: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 14432: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14433: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14434: } else {
14435: my ($imageurl,$error) =
14436: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
14437: $configuserok,$switchserver,$author_ok);
14438: if ($imageurl) {
14439: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
14440: }
14441: if ($error) {
14442: &Apache::lonnet::logthis($error);
14443: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14444: }
1.242 raeburn 14445: }
14446: }
1.216 raeburn 14447: }
14448: }
1.242 raeburn 14449: if (@{$allpos{$type}} > 0) {
14450: my $idx = 0;
14451: foreach my $item (@{$allpos{$type}}) {
14452: if ($item ne '') {
14453: $confhash{$type}{$item}{'order'} = $idx;
14454: if (ref($domconfig{$action}) eq 'HASH') {
14455: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14456: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
14457: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
14458: $changes{$type}{$item} = 1;
14459: }
1.216 raeburn 14460: }
14461: }
14462: }
1.242 raeburn 14463: $idx ++;
1.216 raeburn 14464: }
14465: }
14466: }
14467: }
1.235 raeburn 14468: if (ref($validationitemsref) eq 'ARRAY') {
14469: foreach my $item (@{$validationitemsref}) {
14470: if ($item eq 'fields') {
14471: my @changed;
14472: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
14473: if (@{$confhash{'validation'}{$item}} > 0) {
14474: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
14475: }
1.266 raeburn 14476: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14477: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14478: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
14479: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
14480: $domconfig{'requestcourses'}{'validation'}{$item});
14481: } else {
14482: @changed = @{$confhash{'validation'}{$item}};
14483: }
1.235 raeburn 14484: } else {
14485: @changed = @{$confhash{'validation'}{$item}};
14486: }
14487: } else {
14488: @changed = @{$confhash{'validation'}{$item}};
14489: }
14490: if (@changed) {
14491: if ($confhash{'validation'}{$item}) {
14492: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
14493: } else {
14494: $changes{'validation'}{$item} = &mt('None');
14495: }
14496: }
14497: } else {
14498: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
14499: if ($item eq 'markup') {
14500: if ($env{'form.requestcourses_validation_'.$item}) {
14501: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
14502: }
14503: }
1.266 raeburn 14504: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14505: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14506: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
14507: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14508: }
14509: } else {
14510: if ($confhash{'validation'}{$item} ne '') {
14511: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14512: }
1.235 raeburn 14513: }
14514: } else {
14515: if ($confhash{'validation'}{$item} ne '') {
14516: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14517: }
14518: }
14519: }
14520: }
14521: }
14522: if ($env{'form.validationdc'}) {
14523: my $newval = $env{'form.validationdc'};
1.285 raeburn 14524: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 14525: if (exists($domcoords{$newval})) {
14526: $confhash{'validation'}{'dc'} = $newval;
14527: }
14528: }
14529: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 14530: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14531: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14532: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14533: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
14534: if ($confhash{'validation'}{'dc'} eq '') {
14535: $changes{'validation'}{'dc'} = &mt('None');
14536: } else {
14537: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14538: }
1.235 raeburn 14539: }
1.266 raeburn 14540: } elsif ($confhash{'validation'}{'dc'} ne '') {
14541: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 14542: }
14543: } elsif ($confhash{'validation'}{'dc'} ne '') {
14544: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14545: }
14546: } elsif ($confhash{'validation'}{'dc'} ne '') {
14547: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 14548: }
1.266 raeburn 14549: } else {
14550: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14551: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14552: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14553: $changes{'validation'}{'dc'} = &mt('None');
14554: }
14555: }
1.235 raeburn 14556: }
14557: }
1.102 raeburn 14558: }
14559: } else {
1.86 raeburn 14560: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
14561: }
1.72 raeburn 14562: foreach my $item (@usertools) {
14563: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 14564: my $unset;
1.101 raeburn 14565: if ($context eq 'requestcourses') {
1.104 raeburn 14566: $unset = '0';
14567: if ($type eq '_LC_adv') {
14568: $unset = '';
14569: }
1.101 raeburn 14570: if ($confhash{$item}{$type} eq 'autolimit') {
14571: $confhash{$item}{$type} .= '=';
14572: unless ($limithash{$item}{$type} =~ /\D/) {
14573: $confhash{$item}{$type} .= $limithash{$item}{$type};
14574: }
14575: }
1.163 raeburn 14576: } elsif ($context eq 'requestauthor') {
14577: $unset = '0';
14578: if ($type eq '_LC_adv') {
14579: $unset = '';
14580: }
1.72 raeburn 14581: } else {
1.101 raeburn 14582: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
14583: $confhash{$item}{$type} = 1;
14584: } else {
14585: $confhash{$item}{$type} = 0;
14586: }
1.72 raeburn 14587: }
1.86 raeburn 14588: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 14589: if ($action eq 'requestauthor') {
14590: if ($domconfig{$action}{$type} ne $confhash{$type}) {
14591: $changes{$type} = 1;
14592: }
14593: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 14594: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
14595: $changes{$item}{$type} = 1;
14596: }
14597: } else {
14598: if ($context eq 'requestcourses') {
1.104 raeburn 14599: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 14600: $changes{$item}{$type} = 1;
14601: }
14602: } else {
14603: if (!$confhash{$item}{$type}) {
14604: $changes{$item}{$type} = 1;
14605: }
14606: }
14607: }
14608: } else {
14609: if ($context eq 'requestcourses') {
1.104 raeburn 14610: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 14611: $changes{$item}{$type} = 1;
14612: }
1.163 raeburn 14613: } elsif ($context eq 'requestauthor') {
14614: if ($confhash{$type} ne $unset) {
14615: $changes{$type} = 1;
14616: }
1.72 raeburn 14617: } else {
14618: if (!$confhash{$item}{$type}) {
14619: $changes{$item}{$type} = 1;
14620: }
14621: }
14622: }
1.1 raeburn 14623: }
14624: }
1.163 raeburn 14625: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 14626: if (ref($domconfig{'quotas'}) eq 'HASH') {
14627: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14628: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
14629: if (exists($confhash{'defaultquota'}{$key})) {
14630: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
14631: $changes{'defaultquota'}{$key} = 1;
14632: }
14633: } else {
14634: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 14635: }
14636: }
1.86 raeburn 14637: } else {
14638: foreach my $key (keys(%{$domconfig{'quotas'}})) {
14639: if (exists($confhash{'defaultquota'}{$key})) {
14640: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
14641: $changes{'defaultquota'}{$key} = 1;
14642: }
14643: } else {
14644: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 14645: }
1.1 raeburn 14646: }
14647: }
1.197 raeburn 14648: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
1.429 raeburn 14649: $confhash{'authorquota'} = $domconfig{'quotas'}{'authorquota'};
14650: }
14651: if (ref($domconfig{'quotas'}{'webdav'}) eq 'HASH') {
14652: $confhash{'webdav'} = $domconfig{'quotas'}{'webdav'};
1.197 raeburn 14653: }
1.1 raeburn 14654: }
1.86 raeburn 14655: if (ref($confhash{'defaultquota'}) eq 'HASH') {
14656: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
14657: if (ref($domconfig{'quotas'}) eq 'HASH') {
14658: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14659: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
14660: $changes{'defaultquota'}{$key} = 1;
14661: }
14662: } else {
14663: if (!exists($domconfig{'quotas'}{$key})) {
14664: $changes{'defaultquota'}{$key} = 1;
14665: }
1.72 raeburn 14666: }
14667: } else {
1.86 raeburn 14668: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 14669: }
1.1 raeburn 14670: }
14671: }
14672: }
1.72 raeburn 14673:
1.163 raeburn 14674: if ($context eq 'requestauthor') {
14675: $domdefaults{'requestauthor'} = \%confhash;
14676: } else {
14677: foreach my $key (keys(%confhash)) {
1.242 raeburn 14678: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 14679: $domdefaults{$key} = $confhash{$key};
14680: }
1.163 raeburn 14681: }
1.72 raeburn 14682: }
1.163 raeburn 14683:
1.1 raeburn 14684: my %quotahash = (
1.86 raeburn 14685: $action => { %confhash }
1.1 raeburn 14686: );
14687: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
14688: $dom);
14689: if ($putresult eq 'ok') {
14690: if (keys(%changes) > 0) {
1.72 raeburn 14691: my $cachetime = 24*60*60;
14692: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 14693: if (ref($lastactref) eq 'HASH') {
14694: $lastactref->{'domdefaults'} = 1;
14695: }
1.1 raeburn 14696: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 14697: unless (($context eq 'requestcourses') ||
1.163 raeburn 14698: ($context eq 'requestauthor')) {
1.86 raeburn 14699: if (ref($changes{'defaultquota'}) eq 'HASH') {
14700: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
14701: foreach my $type (@{$types},'default') {
14702: if (defined($changes{'defaultquota'}{$type})) {
14703: my $typetitle = $usertypes->{$type};
14704: if ($type eq 'default') {
14705: $typetitle = $othertitle;
14706: }
1.213 raeburn 14707: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 14708: }
14709: }
1.86 raeburn 14710: $resulttext .= '</ul></li>';
1.72 raeburn 14711: }
14712: }
1.80 raeburn 14713: my %newenv;
1.72 raeburn 14714: foreach my $item (@usertools) {
1.163 raeburn 14715: my (%haschgs,%inconf);
14716: if ($context eq 'requestauthor') {
14717: %haschgs = %changes;
1.210 raeburn 14718: %inconf = %confhash;
1.163 raeburn 14719: } else {
14720: if (ref($changes{$item}) eq 'HASH') {
14721: %haschgs = %{$changes{$item}};
14722: }
14723: if (ref($confhash{$item}) eq 'HASH') {
14724: %inconf = %{$confhash{$item}};
14725: }
14726: }
14727: if (keys(%haschgs) > 0) {
1.80 raeburn 14728: my $newacc =
14729: &Apache::lonnet::usertools_access($env{'user.name'},
14730: $env{'user.domain'},
1.86 raeburn 14731: $item,'reload',$context);
1.210 raeburn 14732: if (($context eq 'requestcourses') ||
1.163 raeburn 14733: ($context eq 'requestauthor')) {
1.108 raeburn 14734: if ($env{'environment.canrequest.'.$item} ne $newacc) {
14735: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 14736: }
14737: } else {
14738: if ($env{'environment.availabletools.'.$item} ne $newacc) {
14739: $newenv{'environment.availabletools.'.$item} = $newacc;
14740: }
1.80 raeburn 14741: }
1.163 raeburn 14742: unless ($context eq 'requestauthor') {
14743: $resulttext .= '<li>'.$titles{$item}.'<ul>';
14744: }
1.72 raeburn 14745: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 14746: if ($haschgs{$type}) {
1.72 raeburn 14747: my $typetitle = $usertypes->{$type};
14748: if ($type eq 'default') {
14749: $typetitle = $othertitle;
14750: } elsif ($type eq '_LC_adv') {
14751: $typetitle = 'LON-CAPA Advanced Users';
14752: }
1.163 raeburn 14753: if ($inconf{$type}) {
1.101 raeburn 14754: if ($context eq 'requestcourses') {
14755: my $cond;
1.163 raeburn 14756: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 14757: if ($1 eq '') {
14758: $cond = &mt('(Automatic processing of any request).');
14759: } else {
14760: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
14761: }
14762: } else {
1.163 raeburn 14763: $cond = $conditions{$inconf{$type}};
1.101 raeburn 14764: }
14765: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 14766: } elsif ($context eq 'requestauthor') {
14767: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
14768: $titles{$inconf{$type}},$typetitle);
14769:
1.101 raeburn 14770: } else {
14771: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
14772: }
1.72 raeburn 14773: } else {
1.104 raeburn 14774: if ($type eq '_LC_adv') {
1.163 raeburn 14775: if ($inconf{$type} eq '0') {
1.104 raeburn 14776: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14777: } else {
14778: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
14779: }
14780: } else {
14781: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14782: }
1.72 raeburn 14783: }
14784: }
1.26 raeburn 14785: }
1.163 raeburn 14786: unless ($context eq 'requestauthor') {
14787: $resulttext .= '</ul></li>';
14788: }
1.26 raeburn 14789: }
1.1 raeburn 14790: }
1.163 raeburn 14791: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 14792: if (ref($changes{'notify'}) eq 'HASH') {
14793: if ($changes{'notify'}{'approval'}) {
14794: if (ref($confhash{'notify'}) eq 'HASH') {
14795: if ($confhash{'notify'}{'approval'}) {
14796: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
14797: } else {
1.163 raeburn 14798: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 14799: }
14800: }
14801: }
14802: }
14803: }
1.216 raeburn 14804: if ($action eq 'requestcourses') {
14805: my @offon = ('off','on');
14806: if ($changes{'uniquecode'}) {
1.218 raeburn 14807: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14808: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
14809: $resulttext .= '<li>'.
14810: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
14811: '</li>';
14812: } else {
14813: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
14814: '</li>';
14815: }
1.216 raeburn 14816: }
1.242 raeburn 14817: foreach my $type ('textbooks','templates') {
14818: if (ref($changes{$type}) eq 'HASH') {
14819: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
14820: foreach my $key (sort(keys(%{$changes{$type}}))) {
14821: my %coursehash = &Apache::lonnet::coursedescription($key);
14822: my $coursetitle = $coursehash{'description'};
14823: my $position = $confhash{$type}{$key}{'order'} + 1;
14824: $resulttext .= '<li>';
1.243 raeburn 14825: foreach my $item ('subject','title','publisher','author') {
14826: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14827: ($type eq 'templates'));
1.242 raeburn 14828: my $name = $item.':';
14829: $name =~ s/^(\w)/\U$1/;
14830: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
14831: }
14832: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
14833: if ($type eq 'textbooks') {
14834: if ($confhash{$type}{$key}{'image'}) {
14835: $resulttext .= ' '.&mt('Image: [_1]',
14836: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
14837: ' alt="Textbook cover" />').'<br />';
14838: }
14839: }
14840: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 14841: }
1.242 raeburn 14842: $resulttext .= '</ul></li>';
1.216 raeburn 14843: }
14844: }
1.235 raeburn 14845: if (ref($changes{'validation'}) eq 'HASH') {
14846: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
14847: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
14848: foreach my $item (@{$validationitemsref}) {
14849: if (exists($changes{'validation'}{$item})) {
14850: if ($item eq 'markup') {
14851: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14852: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
14853: } else {
14854: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14855: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
14856: }
14857: }
14858: }
14859: if (exists($changes{'validation'}{'dc'})) {
14860: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
14861: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
14862: }
1.442 raeburn 14863: $resulttext .= '</ul></li>';
1.235 raeburn 14864: }
14865: }
1.216 raeburn 14866: }
1.1 raeburn 14867: $resulttext .= '</ul>';
1.80 raeburn 14868: if (keys(%newenv)) {
14869: &Apache::lonnet::appenv(\%newenv);
14870: }
1.1 raeburn 14871: } else {
1.86 raeburn 14872: if ($context eq 'requestcourses') {
14873: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 14874: } elsif ($context eq 'requestauthor') {
14875: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 14876: } else {
1.90 weissno 14877: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 14878: }
1.1 raeburn 14879: }
14880: } else {
1.11 albertel 14881: $resulttext = '<span class="LC_error">'.
14882: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14883: }
1.216 raeburn 14884: if ($errors) {
14885: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
14886: '<ul>'.$errors.'</ul></p>';
14887: }
1.3 raeburn 14888: return $resulttext;
1.1 raeburn 14889: }
14890:
1.216 raeburn 14891: sub process_textbook_image {
1.242 raeburn 14892: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 14893: my $filename = $env{'form.'.$caller.'.filename'};
14894: my ($error,$url);
14895: my ($width,$height) = (50,50);
14896: if ($configuserok eq 'ok') {
14897: if ($switchserver) {
14898: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
14899: $switchserver);
14900: } elsif ($author_ok eq 'ok') {
1.421 raeburn 14901: my $modified = [];
1.216 raeburn 14902: my ($result,$imageurl) =
1.421 raeburn 14903: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
14904: "$type/$cdom/$cnum/cover",$width,$height,
14905: '',$modified);
1.216 raeburn 14906: if ($result eq 'ok') {
14907: $url = $imageurl;
1.421 raeburn 14908: &update_modify_urls($r,$modified);
1.216 raeburn 14909: } else {
14910: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14911: }
14912: } else {
14913: $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);
14914: }
14915: } else {
14916: $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);
14917: }
14918: return ($url,$error);
14919: }
14920:
1.267 raeburn 14921: sub modify_ltitools {
14922: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.421 raeburn 14923: my (%currtoolsec,%secchanges,%newtoolsec,%newkeyset);
14924: &fetch_secrets($dom,'toolsec',\%domconfig,\%currtoolsec,\%secchanges,\%newtoolsec,\%newkeyset);
14925:
1.267 raeburn 14926: my $confname = $dom.'-domainconfig';
14927: my $servadm = $r->dir_config('lonAdmEMail');
14928: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.421 raeburn 14929:
14930: my ($resulttext,$ltitoolsoutput,$is_home,$errors,%ltitoolschg,%newtoolsenc,%newltitools);
14931: my $toolserror =
14932: &Apache::courseprefs::process_ltitools($r,$dom,$confname,$domconfig{'ltitools'},\%ltitoolschg,'domain',
14933: $lastactref,$configuserok,$switchserver,$author_ok);
14934:
14935: my $home = &Apache::lonnet::domain($dom,'primary');
14936: unless (($home eq 'no_host') || ($home eq '')) {
14937: my @ids=&Apache::lonnet::current_machine_ids();
14938: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; last; } }
14939: }
14940:
14941: if (keys(%ltitoolschg)) {
14942: foreach my $id (keys(%ltitoolschg)) {
14943: if (ref($ltitoolschg{$id}) eq 'HASH') {
14944: foreach my $inner (keys(%{$ltitoolschg{$id}})) {
14945: if (($inner eq 'secret') || ($inner eq 'key')) {
14946: if ($is_home) {
14947: $newtoolsenc{$id}{$inner} = $ltitoolschg{$id}{$inner};
14948: }
14949: }
14950: }
1.267 raeburn 14951: }
1.421 raeburn 14952: }
14953: $ltitoolsoutput = &Apache::courseprefs::store_ltitools($dom,'','domain',\%ltitoolschg,$domconfig{'ltitools'});
14954: if (keys(%ltitoolschg)) {
14955: %newltitools = %ltitoolschg;
14956: }
14957: }
14958: if (ref($domconfig{'ltitools'}) eq 'HASH') {
14959: foreach my $id (%{$domconfig{'ltitools'}}) {
14960: next if ($id !~ /^\d+$/);
14961: unless (exists($ltitoolschg{$id})) {
14962: if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
14963: foreach my $inner (keys(%{$domconfig{'ltitools'}{$id}})) {
14964: if (($inner eq 'secret') || ($inner eq 'key')) {
14965: if ($is_home) {
14966: $newtoolsenc{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14967: }
14968: } else {
14969: $newltitools{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14970: }
14971: }
14972: } else {
14973: $newltitools{$id} = $domconfig{'ltitools'}{$id};
1.322 raeburn 14974: }
1.421 raeburn 14975: }
14976: }
14977: }
14978: if ($toolserror) {
14979: $errors = '<li>'.$toolserror.'</li>';
14980: }
14981: if ((keys(%ltitoolschg) == 0) && (keys(%secchanges) == 0)) {
14982: $resulttext = &mt('No changes made.');
14983: if ($errors) {
14984: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
14985: $errors.'</ul>';
14986: }
14987: return $resulttext;
14988: }
14989: my %ltitoolshash = (
14990: $action => { %newltitools }
14991: );
14992: if (keys(%secchanges)) {
14993: $ltitoolshash{'toolsec'} = \%newtoolsec;
14994: }
14995: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,$dom);
14996: if ($putresult eq 'ok') {
14997: my %keystore;
14998: if ($is_home) {
14999: my %toolsenchash = (
15000: $action => { %newtoolsenc }
15001: );
15002: &Apache::lonnet::put_dom('encconfig',\%toolsenchash,$dom,undef,1);
1.423 raeburn 15003: my $cachetime = 24*60*60;
15004: &Apache::lonnet::do_cache_new('ltitoolsenc',$dom,\%newtoolsenc,$cachetime);
1.421 raeburn 15005: &store_security($dom,'ltitools',\%secchanges,\%newkeyset,\%keystore,$lastactref);
15006: }
15007: $resulttext = &mt('Changes made:').'<ul>';
15008: if (keys(%secchanges) > 0) {
1.423 raeburn 15009: $resulttext .= <i_security_results($dom,'ltitools',\%secchanges,\%newtoolsec,\%newkeyset,\%keystore);
1.421 raeburn 15010: }
15011: if (keys(%ltitoolschg) > 0) {
15012: $resulttext .= $ltitoolsoutput;
15013: }
1.423 raeburn 15014: my $cachetime = 24*60*60;
15015: &Apache::lonnet::do_cache_new('ltitools',$dom,\%newltitools,$cachetime);
15016: if (ref($lastactref) eq 'HASH') {
15017: $lastactref->{'ltitools'} = 1;
15018: }
1.421 raeburn 15019: } else {
15020: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15021: }
15022: if ($errors) {
15023: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
15024: $errors.'</ul></p>';
15025: }
15026: return $resulttext;
15027: }
15028:
15029: sub fetch_secrets {
15030: my ($dom,$context,$domconfig,$currsec,$secchanges,$newsec,$newkeyset) = @_;
15031: my %keyset;
15032: %{$currsec} = ();
15033: $newsec->{'private'}{'keys'} = [];
15034: $newsec->{'encrypt'} = {};
15035: $newsec->{'rules'} = {};
15036: if ($context eq 'ltisec') {
15037: $newsec->{'linkprot'} = {};
15038: }
15039: if (ref($domconfig->{$context}) eq 'HASH') {
15040: %{$currsec} = %{$domconfig->{$context}};
15041: if ($context eq 'ltisec') {
15042: if (ref($currsec->{'linkprot'}) eq 'HASH') {
15043: foreach my $id (keys(%{$currsec->{'linkprot'}})) {
15044: unless ($id =~ /^\d+$/) {
15045: delete($currsec->{'linkprot'}{$id});
1.297 raeburn 15046: }
1.267 raeburn 15047: }
15048: }
1.421 raeburn 15049: }
15050: if (ref($currsec->{'private'}) eq 'HASH') {
15051: if (ref($currsec->{'private'}{'keys'}) eq 'ARRAY') {
15052: $newsec->{'private'}{'keys'} = $currsec->{'private'}{'keys'};
15053: map { $keyset{$_} = 1; } @{$currsec->{'private'}{'keys'}};
1.267 raeburn 15054: }
1.421 raeburn 15055: }
15056: }
15057: my @items= ('crs','dom');
15058: if ($context eq 'ltisec') {
15059: push(@items,'consumers');
15060: }
15061: foreach my $item (@items) {
15062: my $formelement;
15063: if (($context eq 'toolsec') || ($item eq 'consumers')) {
15064: $formelement = 'form.'.$context.'_'.$item;
15065: } else {
15066: $formelement = 'form.'.$context.'_'.$item.'linkprot';
15067: }
15068: if ($env{$formelement}) {
15069: $newsec->{'encrypt'}{$item} = 1;
15070: if (ref($currsec->{'encrypt'}) eq 'HASH') {
15071: unless ($currsec->{'encrypt'}{$item}) {
15072: $secchanges->{'encrypt'} = 1;
15073: }
15074: } else {
15075: $secchanges->{'encrypt'} = 1;
1.267 raeburn 15076: }
1.421 raeburn 15077: } elsif (ref($currsec->{'encrypt'}) eq 'HASH') {
15078: if ($currsec->{'encrypt'}{$item}) {
15079: $secchanges->{'encrypt'} = 1;
1.323 raeburn 15080: }
1.421 raeburn 15081: }
15082: }
15083: my $secrets;
15084: if ($context eq 'ltisec') {
15085: $secrets = 'ltisecrets';
15086: } else {
15087: $secrets = 'toolsecrets';
15088: }
15089: unless (exists($currsec->{'rules'})) {
15090: $currsec->{'rules'} = {};
15091: }
15092: &password_rule_changes($secrets,$newsec->{'rules'},$currsec->{'rules'},$secchanges);
15093:
15094: my @ids=&Apache::lonnet::current_machine_ids();
15095: my %servers = &Apache::lonnet::get_servers($dom,'library');
15096:
15097: foreach my $hostid (keys(%servers)) {
15098: if (($hostid ne '') && (grep(/^\Q$hostid\E$/,@ids))) {
15099: my $keyitem = 'form.'.$context.'_privkey_'.$hostid;
15100: if (exists($env{$keyitem})) {
15101: $env{$keyitem} =~ s/(`)/'/g;
15102: if ($keyset{$hostid}) {
15103: if ($env{'form.'.$context.'_changeprivkey_'.$hostid}) {
15104: if ($env{$keyitem} ne '') {
15105: $secchanges->{'private'} = 1;
15106: $newkeyset->{$hostid} = $env{$keyitem};
15107: }
1.296 raeburn 15108: }
1.421 raeburn 15109: } elsif ($env{$keyitem} ne '') {
15110: unless (grep(/^\Q$hostid\E$/,@{$newsec->{'private'}{'keys'}})) {
15111: push(@{$newsec->{'private'}{'keys'}},$hostid);
1.296 raeburn 15112: }
1.421 raeburn 15113: $secchanges->{'private'} = 1;
15114: $newkeyset->{$hostid} = $env{$keyitem};
1.267 raeburn 15115: }
15116: }
1.421 raeburn 15117: }
15118: }
15119: }
15120:
15121: sub store_security {
1.424 raeburn 15122: my ($dom,$context,$secchanges,$newkeyset,$keystore) = @_;
1.421 raeburn 15123: return unless ((ref($secchanges) eq 'HASH') && (ref($newkeyset) eq 'HASH') &&
15124: (ref($keystore) eq 'HASH'));
15125: if (keys(%{$secchanges})) {
15126: if ($secchanges->{'private'}) {
15127: my $who = &escape($env{'user.name'}.':'.$env{'user.domain'});
15128: foreach my $hostid (keys(%{$newkeyset})) {
15129: my $storehash = {
15130: key => $newkeyset->{$hostid},
15131: who => $env{'user.name'}.':'.$env{'user.domain'},
15132: };
15133: $keystore->{$hostid} = &Apache::lonnet::store_dom($storehash,$context,'private',
15134: $dom,$hostid);
15135: }
15136: }
15137: }
15138: }
15139:
15140: sub lti_security_results {
1.423 raeburn 15141: my ($dom,$context,$secchanges,$newsec,$newkeyset,$keystore) = @_;
1.421 raeburn 15142: my $output;
1.423 raeburn 15143: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
15144: my $needs_update;
1.421 raeburn 15145: foreach my $item (keys(%{$secchanges})) {
15146: if ($item eq 'encrypt') {
1.423 raeburn 15147: $needs_update = 1;
1.421 raeburn 15148: my %encrypted;
15149: if ($context eq 'lti') {
15150: %encrypted = (
15151: crs => {
15152: on => &mt('Encryption of stored link protection secrets defined in courses enabled'),
15153: off => &mt('Encryption of stored link protection secrets defined in courses disabled'),
15154: },
15155: dom => {
15156: on => &mt('Encryption of stored link protection secrets defined in domain enabled'),
15157: off => &mt('Encryption of stored link protection secrets defined in domain disabled'),
15158: },
15159: consumers => {
15160: on => &mt('Encryption of stored consumer secrets defined in domain enabled'),
15161: off => &mt('Encryption of stored consumer secrets defined in domain disabled'),
15162: },
15163: );
1.267 raeburn 15164: } else {
1.421 raeburn 15165: %encrypted = (
15166: crs => {
15167: on => &mt('Encryption of stored external tool secrets defined in courses enabled'),
15168: off => &mt('Encryption of stored external tool secrets defined in courses disabled'),
15169: },
15170: dom => {
15171: on => &mt('Encryption of stored external tool secrets defined in domain enabled'),
15172: off => &mt('Encryption of stored external tool secrets defined in domain disabled'),
15173: },
15174: );
15175: }
15176: my @types= ('crs','dom');
15177: if ($context eq 'lti') {
1.423 raeburn 15178: foreach my $type (@types) {
15179: undef($domdefaults{'linkprotenc_'.$type});
15180: }
1.421 raeburn 15181: push(@types,'consumers');
1.423 raeburn 15182: undef($domdefaults{'ltienc_consumers'});
15183: } elsif ($context eq 'ltitools') {
15184: foreach my $type (@types) {
15185: undef($domdefaults{'toolenc_'.$type});
15186: }
1.267 raeburn 15187: }
1.421 raeburn 15188: foreach my $type (@types) {
15189: my $shown = $encrypted{$type}{'off'};
15190: if (ref($newsec->{$item}) eq 'HASH') {
15191: if ($newsec->{$item}{$type}) {
1.423 raeburn 15192: if ($context eq 'lti') {
15193: if ($type eq 'consumers') {
15194: $domdefaults{'ltienc_consumers'} = 1;
15195: } else {
15196: $domdefaults{'linkprotenc_'.$type} = 1;
15197: }
15198: } elsif ($context eq 'ltitools') {
15199: $domdefaults{'toolenc_'.$type} = 1;
15200: }
1.421 raeburn 15201: $shown = $encrypted{$type}{'on'};
1.319 raeburn 15202: }
1.267 raeburn 15203: }
1.421 raeburn 15204: $output .= '<li>'.$shown.'</li>';
1.267 raeburn 15205: }
1.421 raeburn 15206: } elsif ($item eq 'rules') {
15207: my %titles = &Apache::lonlocal::texthash(
15208: min => 'Minimum password length',
15209: max => 'Maximum password length',
15210: chars => 'Required characters',
15211: );
15212: foreach my $rule ('min','max') {
15213: if ($newsec->{rules}{$rule} eq '') {
15214: if ($rule eq 'min') {
15215: $output .= '<li>'.&mt('[_1] not set.',$titles{$rule});
15216: ' '.&mt('Default of [_1] will be used',
15217: $Apache::lonnet::passwdmin).'</li>';
15218: } else {
15219: $output .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
15220: }
15221: } else {
15222: $output .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$newsec->{rules}{$rule}).'</li>';
15223: }
15224: }
15225: if (ref($newsec->{'rules'}{'chars'}) eq 'ARRAY') {
15226: if (@{$newsec->{'rules'}{'chars'}} > 0) {
15227: my %rulenames = &Apache::lonlocal::texthash(
15228: uc => 'At least one upper case letter',
15229: lc => 'At least one lower case letter',
15230: num => 'At least one number',
15231: spec => 'At least one non-alphanumeric',
15232: );
15233: my $needed = '<ul><li>'.
15234: join('</li><li>',map {$rulenames{$_} } @{$newsec->{'rules'}{'chars'}}).
15235: '</li></ul>';
15236: $output .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
15237: } else {
15238: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 15239: }
1.421 raeburn 15240: } else {
15241: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 15242: }
1.421 raeburn 15243: } elsif ($item eq 'private') {
1.423 raeburn 15244: $needs_update = 1;
15245: if ($context eq 'lti') {
15246: undef($domdefaults{'ltiprivhosts'});
15247: } elsif ($context eq 'ltitools') {
15248: undef($domdefaults{'toolprivhosts'});
15249: }
1.421 raeburn 15250: if (keys(%{$newkeyset})) {
1.423 raeburn 15251: my @privhosts;
1.421 raeburn 15252: foreach my $hostid (sort(keys(%{$newkeyset}))) {
15253: if ($keystore->{$hostid} eq 'ok') {
15254: $output .= '<li>'.&mt('Encryption key for storage of shared secrets saved for [_1]',$hostid).'</li>';
1.423 raeburn 15255: unless (grep(/^\Q$hostid\E$/,@privhosts)) {
15256: push(@privhosts,$hostid);
15257: }
15258: }
15259: }
15260: if (@privhosts) {
15261: if ($context eq 'lti') {
15262: $domdefaults{'ltiprivhosts'} = \@privhosts;
15263: } elsif ($context eq 'ltitools') {
15264: $domdefaults{'toolprivhosts'} = \@privhosts;
1.267 raeburn 15265: }
15266: }
15267: }
1.421 raeburn 15268: } elsif ($item eq 'linkprot') {
15269: next;
1.434 raeburn 15270: } elsif ($item eq 'suggested') {
15271: if ((ref($secchanges->{'suggested'}) eq 'HASH') &&
15272: (ref($newsec->{'suggested'}) eq 'HASH')) {
15273: my $suggestions;
15274: foreach my $id (sort { $a <=> $b } keys(%{$secchanges->{'suggested'}})) {
15275: if (ref($newsec->{'suggested'}->{$id}) eq 'HASH') {
15276: my $name = $newsec->{'suggested'}->{$id}->{'name'};
15277: my $info = $newsec->{'suggested'}->{$id}->{'info'};
15278: $suggestions .= '<li>'.&mt('Launcher: [_1]',$name).'<br />'.
15279: &mt('Recommend: [_1]','<pre>'.$info.'</pre>').
15280: '</li>';
15281: } else {
15282: $suggestions .= '<li>'.&mt('Recommendations deleted for Launcher: [_1]',
15283: $newsec->{'suggested'}->{$id}).'</li>';
15284: }
15285: }
15286: if ($suggestions) {
15287: $output .= '<li>'.&mt('Hints in Courses for Link Protector Configuration').
15288: '<ul>'.$suggestions.'</ul>'.
15289: '</li>';
15290: }
15291: }
1.267 raeburn 15292: }
15293: }
1.423 raeburn 15294: if ($needs_update) {
15295: my $cachetime = 24*60*60;
15296: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15297: }
1.421 raeburn 15298: return $output;
15299: }
15300:
15301: sub modify_proctoring {
15302: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15303: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15304: my (@allpos,%changes,%confhash,%encconfhash,$errors,$resulttext,%imgdeletions);
15305: my $confname = $dom.'-domainconfig';
15306: my $servadm = $r->dir_config('lonAdmEMail');
1.372 raeburn 15307: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
15308: my %providernames = &proctoring_providernames();
15309: my $maxnum = scalar(keys(%providernames));
15310:
15311: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
15312: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
15313: if (ref($requref) eq 'HASH') {
15314: %requserfields = %{$requref};
15315: }
15316: if (ref($opturef) eq 'HASH') {
15317: %optuserfields = %{$opturef};
15318: }
15319: if (ref($defref) eq 'HASH') {
15320: %defaults = %{$defref};
15321: }
15322: if (ref($extref) eq 'HASH') {
15323: %extended = %{$extref};
15324: }
15325: if (ref($crsref) eq 'HASH') {
15326: %crsconf = %{$crsref};
15327: }
15328: if (ref($rolesref) eq 'ARRAY') {
15329: @courseroles = @{$rolesref};
15330: }
15331: if (ref($ltiref) eq 'ARRAY') {
15332: @ltiroles = @{$ltiref};
15333: }
15334:
15335: if (ref($domconfig{$action}) eq 'HASH') {
15336: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.proctoring_image_del');
15337: if (@todeleteimages) {
15338: map { $imgdeletions{$_} = 1; } @todeleteimages;
15339: }
15340: }
15341: my %customadds;
15342: my @newcustom = &Apache::loncommon::get_env_multiple('form.proctoring_customadd');
15343: if (@newcustom) {
15344: map { $customadds{$_} = 1; } @newcustom;
15345: }
15346: foreach my $provider (sort(keys(%providernames))) {
15347: $confhash{$provider} = {};
15348: my $pos = $env{'form.proctoring_pos_'.$provider};
15349: $pos =~ s/\D+//g;
15350: $allpos[$pos] = $provider;
15351: my (%current,%currentenc);
15352: my $showroles = 0;
15353: if (ref($domconfig{$action}) eq 'HASH') {
15354: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15355: %current = %{$domconfig{$action}{$provider}};
15356: foreach my $item ('key','secret') {
15357: $currentenc{$item} = $current{$item};
15358: delete($current{$item});
15359: }
15360: }
15361: }
15362: if ($env{'form.proctoring_available_'.$provider}) {
15363: $confhash{$provider}{'available'} = 1;
15364: unless ($current{'available'}) {
15365: $changes{$provider} = 1;
15366: }
15367: } else {
15368: %{$confhash{$provider}} = %current;
15369: %{$encconfhash{$provider}} = %currentenc;
15370: $confhash{$provider}{'available'} = 0;
15371: if ($current{'available'}) {
15372: $changes{$provider} = 1;
15373: }
15374: }
15375: if ($confhash{$provider}{'available'}) {
15376: foreach my $field ('lifetime','version','sigmethod','url','key','secret') {
15377: my $possval = $env{'form.proctoring_'.$provider.'_'.$field};
15378: if ($field eq 'lifetime') {
15379: if ($possval =~ /^\d+$/) {
15380: $confhash{$provider}{$field} = $possval;
15381: }
15382: } elsif ($field eq 'version') {
15383: if ($possval =~ /^\d+\.\d+$/) {
15384: $confhash{$provider}{$field} = $possval;
15385: }
15386: } elsif ($field eq 'sigmethod') {
15387: if ($possval =~ /^\QHMAC-SHA\E(1|256)$/) {
15388: $confhash{$provider}{$field} = $possval;
15389: }
15390: } elsif ($field eq 'url') {
15391: $confhash{$provider}{$field} = $possval;
15392: } elsif (($field eq 'key') || ($field eq 'secret')) {
15393: $encconfhash{$provider}{$field} = $possval;
15394: unless ($currentenc{$field} eq $possval) {
15395: $changes{$provider} = 1;
15396: }
15397: }
15398: unless (($field eq 'key') || ($field eq 'secret')) {
15399: unless ($current{$field} eq $confhash{$provider}{$field}) {
15400: $changes{$provider} = 1;
15401: }
15402: }
15403: }
15404: if ($imgdeletions{$provider}) {
15405: $changes{$provider} = 1;
15406: } elsif ($env{'form.proctoring_image_'.$provider.'.filename'} ne '') {
15407: my ($imageurl,$error) =
15408: &process_proctoring_image($r,$dom,$confname,'proctoring_image_'.$provider,$provider,
15409: $configuserok,$switchserver,$author_ok);
15410: if ($imageurl) {
15411: $confhash{$provider}{'image'} = $imageurl;
15412: $changes{$provider} = 1;
15413: }
15414: if ($error) {
15415: &Apache::lonnet::logthis($error);
15416: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15417: }
15418: } elsif (exists($current{'image'})) {
15419: $confhash{$provider}{'image'} = $current{'image'};
15420: }
15421: if (ref($requserfields{$provider}) eq 'ARRAY') {
15422: if (@{$requserfields{$provider}} > 0) {
15423: if (grep(/^user$/,@{$requserfields{$provider}})) {
15424: if ($env{'form.proctoring_userincdom_'.$provider}) {
15425: $confhash{$provider}{'incdom'} = 1;
15426: }
15427: unless ($current{'incdom'} eq $confhash{$provider}{'incdom'}) {
15428: $changes{$provider} = 1;
15429: }
15430: }
15431: if (grep(/^roles$/,@{$requserfields{$provider}})) {
15432: $showroles = 1;
15433: }
15434: }
15435: }
15436: $confhash{$provider}{'fields'} = [];
15437: if (ref($optuserfields{$provider}) eq 'ARRAY') {
15438: if (@{$optuserfields{$provider}} > 0) {
15439: my @optfields = &Apache::loncommon::get_env_multiple('form.proctoring_optional_'.$provider);
15440: foreach my $field (@{$optuserfields{$provider}}) {
15441: if (grep(/^\Q$field\E$/,@optfields)) {
15442: push(@{$confhash{$provider}{'fields'}},$field);
15443: }
15444: }
15445: }
15446: if (ref($current{'fields'}) eq 'ARRAY') {
15447: unless ($changes{$provider}) {
15448: my @new = sort(@{$confhash{$provider}{'fields'}});
15449: my @old = sort(@{$current{'fields'}});
15450: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15451: if (@diffs) {
15452: $changes{$provider} = 1;
15453: }
15454: }
15455: } elsif (@{$confhash{$provider}{'fields'}}) {
15456: $changes{$provider} = 1;
15457: }
15458: }
15459: if (ref($defaults{$provider}) eq 'ARRAY') {
15460: if (@{$defaults{$provider}} > 0) {
15461: my %options;
15462: if (ref($extended{$provider}) eq 'HASH') {
15463: %options = %{$extended{$provider}};
15464: }
15465: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_defaults_'.$provider);
15466: foreach my $field (@{$defaults{$provider}}) {
15467: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
15468: my $poss = $env{'form.proctoring_defaults_'.$field.'_'.$provider};
15469: if (grep(/^\Q$poss\E$/,@{$options{$field}})) {
15470: push(@{$confhash{$provider}{'defaults'}},$poss);
15471: }
15472: } elsif ((exists($options{$field})) && (ref($options{$field}) eq 'HASH')) {
15473: foreach my $inner (keys(%{$options{$field}})) {
15474: if (ref($options{$field}{$inner}) eq 'ARRAY') {
15475: my $poss = $env{'form.proctoring_'.$inner.'_'.$provider};
15476: if (grep(/^\Q$poss\E$/,@{$options{$field}{$inner}})) {
15477: $confhash{$provider}{'defaults'}{$inner} = $poss;
15478: }
15479: } else {
15480: $confhash{$provider}{'defaults'}{$inner} = $env{'form.proctoring_'.$inner.'_'.$provider};
15481: }
15482: }
15483: } else {
15484: if (grep(/^\Q$field\E$/,@checked)) {
15485: push(@{$confhash{$provider}{'defaults'}},$field);
15486: }
15487: }
15488: }
15489: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15490: if (ref($current{'defaults'}) eq 'ARRAY') {
15491: unless ($changes{$provider}) {
15492: my @new = sort(@{$confhash{$provider}{'defaults'}});
15493: my @old = sort(@{$current{'defaults'}});
15494: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15495: if (@diffs) {
15496: $changes{$provider} = 1;
15497: }
15498: }
15499: } elsif (ref($current{'defaults'}) eq 'ARRAY') {
15500: if (@{$current{'defaults'}}) {
15501: $changes{$provider} = 1;
15502: }
15503: }
15504: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15505: if (ref($current{'defaults'}) eq 'HASH') {
15506: unless ($changes{$provider}) {
15507: foreach my $key (keys(%{$confhash{$provider}{'defaults'}})) {
15508: unless ($confhash{$provider}{'defaults'}{$key} eq $current{'defaults'}{$key}) {
15509: $changes{$provider} = 1;
15510: last;
15511: }
15512: }
15513: }
15514: unless ($changes{$provider}) {
15515: foreach my $key (keys(%{$current{'defaults'}})) {
15516: unless ($current{'defaults'}{$key} eq $confhash{$provider}{'defaults'}{$key}) {
15517: $changes{$provider} = 1;
15518: last;
15519: }
15520: }
15521: }
15522: } elsif (keys(%{$confhash{$provider}{'defaults'}})) {
15523: $changes{$provider} = 1;
15524: }
15525: }
15526: }
15527: }
15528: if (ref($crsconf{$provider}) eq 'ARRAY') {
15529: if (@{$crsconf{$provider}} > 0) {
15530: $confhash{$provider}{'crsconf'} = [];
15531: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_crsconf_'.$provider);
15532: foreach my $crsfield (@{$crsconf{$provider}}) {
15533: if (grep(/^\Q$crsfield\E$/,@checked)) {
15534: push(@{$confhash{$provider}{'crsconf'}},$crsfield);
15535: }
15536: }
15537: if (ref($current{'crsconf'}) eq 'ARRAY') {
15538: unless ($changes{$provider}) {
15539: my @new = sort(@{$confhash{$provider}{'crsconf'}});
15540: my @old = sort(@{$current{'crsconf'}});
15541: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15542: if (@diffs) {
15543: $changes{$provider} = 1;
15544: }
15545: }
15546: } elsif (@{$confhash{$provider}{'crsconf'}}) {
15547: $changes{$provider} = 1;
15548: }
15549: }
15550: }
15551: if ($showroles) {
15552: $confhash{$provider}{'roles'} = {};
15553: foreach my $role (@courseroles) {
15554: my $poss = $env{'form.proctoring_roles_'.$role.'_'.$provider};
15555: if (grep(/^\Q$poss\E$/,@ltiroles)) {
15556: $confhash{$provider}{'roles'}{$role} = $poss;
15557: }
15558: }
15559: unless ($changes{$provider}) {
15560: if (ref($current{'roles'}) eq 'HASH') {
15561: foreach my $role (keys(%{$current{'roles'}})) {
15562: unless ($current{'roles'}{$role} eq $confhash{$provider}{'roles'}{$role}) {
15563: $changes{$provider} = 1;
15564: last
15565: }
15566: }
15567: unless ($changes{$provider}) {
15568: foreach my $role (keys(%{$confhash{$provider}{'roles'}})) {
15569: unless ($confhash{$provider}{'roles'}{$role} eq $current{'roles'}{$role}) {
15570: $changes{$provider} = 1;
15571: last;
15572: }
15573: }
15574: }
15575: } elsif (keys(%{$confhash{$provider}{'roles'}})) {
15576: $changes{$provider} = 1;
15577: }
15578: }
15579: }
15580: if (ref($current{'custom'}) eq 'HASH') {
15581: my @customdels = &Apache::loncommon::get_env_multiple('form.proctoring_customdel_'.$provider);
15582: foreach my $key (keys(%{$current{'custom'}})) {
15583: if (grep(/^\Q$key\E$/,@customdels)) {
15584: $changes{$provider} = 1;
15585: } else {
15586: $confhash{$provider}{'custom'}{$key} = $env{'form.proctoring_customval_'.$key.'_'.$provider};
15587: if ($confhash{$provider}{'custom'}{$key} ne $current{'custom'}{$key}) {
15588: $changes{$provider} = 1;
15589: }
15590: }
15591: }
15592: }
15593: if ($customadds{$provider}) {
15594: my $name = $env{'form.proctoring_custom_name_'.$provider};
15595: $name =~ s/(`)/'/g;
15596: $name =~ s/^\s+//;
15597: $name =~ s/\s+$//;
15598: my $value = $env{'form.proctoring_custom_value_'.$provider};
15599: $value =~ s/(`)/'/g;
15600: $value =~ s/^\s+//;
15601: $value =~ s/\s+$//;
15602: if ($name ne '') {
15603: $confhash{$provider}{'custom'}{$name} = $value;
15604: $changes{$provider} = 1;
15605: }
15606: }
15607: }
15608: }
15609: if (@allpos > 0) {
15610: my $idx = 0;
15611: foreach my $provider (@allpos) {
15612: if ($provider ne '') {
15613: $confhash{$provider}{'order'} = $idx;
15614: unless ($changes{$provider}) {
15615: if (ref($domconfig{$action}) eq 'HASH') {
15616: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15617: if ($domconfig{$action}{$provider}{'order'} ne $idx) {
15618: $changes{$provider} = 1;
15619: }
15620: }
15621: }
15622: }
15623: $idx ++;
15624: }
15625: }
15626: }
15627: my %proc_hash = (
15628: $action => { %confhash }
15629: );
15630: my $putresult = &Apache::lonnet::put_dom('configuration',\%proc_hash,
15631: $dom);
15632: if ($putresult eq 'ok') {
15633: my %proc_enchash = (
15634: $action => { %encconfhash }
15635: );
1.384 raeburn 15636: &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom,undef,1);
1.372 raeburn 15637: if (keys(%changes) > 0) {
15638: my $cachetime = 24*60*60;
15639: my %procall = %confhash;
15640: foreach my $provider (keys(%procall)) {
15641: if (ref($encconfhash{$provider}) eq 'HASH') {
15642: foreach my $key ('key','secret') {
15643: $procall{$provider}{$key} = $encconfhash{$provider}{$key};
15644: }
15645: }
15646: }
15647: &Apache::lonnet::do_cache_new('proctoring',$dom,\%procall,$cachetime);
15648: if (ref($lastactref) eq 'HASH') {
15649: $lastactref->{'proctoring'} = 1;
15650: }
15651: $resulttext = &mt('Configuration for Provider(s) with changes:').'<ul>';
15652: my %bynum;
15653: foreach my $provider (sort(keys(%changes))) {
15654: my $position = $confhash{$provider}{'order'};
15655: $bynum{$position} = $provider;
15656: }
15657: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
15658: my $provider = $bynum{$pos};
15659: my %lt = &proctoring_titles($provider);
15660: my %fieldtitles = &proctoring_fieldtitles($provider);
15661: if (!$confhash{$provider}{'available'}) {
15662: $resulttext .= '<li>'.&mt('Proctoring integration unavailable for: [_1]','<b>'.$providernames{$provider}.'</b>').'</li>';
15663: } else {
15664: $resulttext .= '<li>'.&mt('Proctoring integration available for: [_1]','<b>'.$providernames{$provider}.'</b>');
15665: if ($confhash{$provider}{'image'}) {
15666: $resulttext .= ' '.
15667: '<img src="'.$confhash{$provider}{'image'}.'"'.
15668: ' alt="'.&mt('Proctoring icon').'" />';
15669: }
15670: $resulttext .= '<ul>';
15671: my $position = $pos + 1;
15672: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
15673: foreach my $key ('version','sigmethod','url','lifetime') {
15674: if ($confhash{$provider}{$key} ne '') {
15675: $resulttext .= '<li>'.$lt{$key}.': '.$confhash{$provider}{$key}.'</li>';
15676: }
15677: }
15678: if ($encconfhash{$provider}{'key'} ne '') {
15679: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfhash{$provider}{'key'}.'</li>';
15680: }
15681: if ($encconfhash{$provider}{'secret'} ne '') {
15682: $resulttext .= '<li>'.$lt{'secret'}.': ';
15683: my $num = length($encconfhash{$provider}{'secret'});
15684: $resulttext .= ('*'x$num).'</li>';
15685: }
15686: my (@fields,$showroles);
15687: if (ref($requserfields{$provider}) eq 'ARRAY') {
15688: push(@fields,@{$requserfields{$provider}});
15689: }
15690: if (ref($confhash{$provider}{'fields'}) eq 'ARRAY') {
15691: push(@fields,@{$confhash{$provider}{'fields'}});
15692: } elsif (ref($confhash{$provider}{'fields'}) eq 'HASH') {
15693: push(@fields,(keys(%{$confhash{$provider}{'fields'}})));
15694: }
15695: if (@fields) {
15696: if (grep(/^roles$/,@fields)) {
15697: $showroles = 1;
15698: }
15699: $resulttext .= '<li>'.$lt{'udsl'}.': "'.
15700: join('", "', map { $lt{$_}; } @fields).'"</li>';
15701: }
15702: if (ref($requserfields{$provider}) eq 'ARRAY') {
15703: if (grep(/^user$/,@{$requserfields{$provider}})) {
15704: if ($confhash{$provider}{'incdom'}) {
15705: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'uname:dom'}).'</li>';
15706: } else {
15707: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'username'}).'</li>';
15708: }
15709: }
15710: }
15711: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15712: if (@{$confhash{$provider}{'defaults'}} > 0) {
15713: $resulttext .= '<li>'.$lt{'defa'};
15714: foreach my $field (@{$confhash{$provider}{'defaults'}}) {
15715: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15716: }
15717: $resulttext =~ s/,$//;
15718: $resulttext .= '</li>';
15719: }
15720: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15721: if (keys(%{$confhash{$provider}{'defaults'}})) {
15722: $resulttext .= '<li>'.$lt{'defa'}.': <ul>';
15723: foreach my $key (sort(keys(%{$confhash{$provider}{'defaults'}}))) {
15724: if ($confhash{$provider}{'defaults'}{$key} ne '') {
15725: $resulttext .= '<li>'.$fieldtitles{$key}.' = '.$confhash{$provider}{'defaults'}{$key}.'</li>';
15726: }
15727: }
15728: $resulttext .= '</ul></li>';
15729: }
15730: }
15731: if (ref($crsconf{$provider}) eq 'ARRAY') {
15732: if (@{$crsconf{$provider}} > 0) {
15733: $resulttext .= '<li>'.&mt('Configurable in course:');
15734: my $numconfig = 0;
15735: if (ref($confhash{$provider}{'crsconf'}) eq 'ARRAY') {
15736: if (@{$confhash{$provider}{'crsconf'}} > 0) {
15737: foreach my $field (@{$confhash{$provider}{'crsconf'}}) {
15738: $numconfig ++;
15739: if ($provider eq 'examity') {
15740: $resulttext .= ' "'.$lt{'crs'.$field}.'",';
15741: } else {
15742: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15743: }
15744: }
15745: $resulttext =~ s/,$//;
15746: }
15747: }
15748: if (!$numconfig) {
15749: $resulttext .= ' '.&mt('None');
15750: }
15751: $resulttext .= '</li>';
15752: }
15753: }
15754: if ($showroles) {
15755: if (ref($confhash{$provider}{'roles'}) eq 'HASH') {
15756: my $rolemaps;
15757: foreach my $role (@courseroles) {
15758: if ($confhash{$provider}{'roles'}{$role}) {
15759: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
15760: $confhash{$provider}{'roles'}{$role}.',';
15761: }
15762: }
15763: if ($rolemaps) {
15764: $rolemaps =~ s/,$//;
15765: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
15766: }
15767: }
15768: }
15769: if (ref($confhash{$provider}{'custom'}) eq 'HASH') {
15770: my $customlist;
15771: if (keys(%{$confhash{$provider}{'custom'}})) {
15772: foreach my $key (sort(keys(%{$confhash{$provider}{'custom'}}))) {
15773: $customlist .= $key.'='.$confhash{$provider}{'custom'}{$key}.', ';
15774: }
15775: $customlist =~ s/,$//;
15776: }
15777: if ($customlist) {
15778: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
15779: }
15780: }
15781: $resulttext .= '</ul></li>';
15782: }
15783: }
15784: $resulttext .= '</ul>';
15785: } else {
15786: $resulttext = &mt('No changes made.');
15787: }
15788: } else {
15789: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15790: }
15791: if ($errors) {
15792: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15793: $errors.'</ul>';
15794: }
15795: return $resulttext;
15796: }
15797:
15798: sub process_proctoring_image {
15799: my ($r,$dom,$confname,$caller,$provider,$configuserok,$switchserver,$author_ok) = @_;
15800: my $filename = $env{'form.'.$caller.'.filename'};
15801: my ($error,$url);
15802: my ($width,$height) = (21,21);
15803: if ($configuserok eq 'ok') {
15804: if ($switchserver) {
15805: $error = &mt('Upload of Remote Proctoring Provider icon is not permitted to this server: [_1]',
15806: $switchserver);
15807: } elsif ($author_ok eq 'ok') {
1.421 raeburn 15808: my $modified = [];
1.372 raeburn 15809: my ($result,$imageurl,$madethumb) =
1.421 raeburn 15810: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
15811: "proctoring/$provider/icon",$width,$height,
15812: '',$modified);
1.372 raeburn 15813: if ($result eq 'ok') {
15814: if ($madethumb) {
15815: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
15816: my $imagethumb = "$path/tn-".$imagefile;
15817: $url = $imagethumb;
15818: } else {
15819: $url = $imageurl;
15820: }
1.421 raeburn 15821: &update_modify_urls($r,$modified);
1.372 raeburn 15822: } else {
15823: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
15824: }
15825: } else {
15826: $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);
15827: }
15828: } else {
15829: $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);
15830: }
15831: return ($url,$error);
15832: }
15833:
1.320 raeburn 15834: sub modify_lti {
15835: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15836: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.424 raeburn 15837: my ($newid,@allpos,%changes,%confhash,%ltienc,$errors,$resulttext);
1.320 raeburn 15838: my (%posslti,%posslticrs,%posscrstype);
15839: my @courseroles = ('cc','in','ta','ep','st');
15840: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
15841: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
1.392 raeburn 15842: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 15843: my %coursetypetitles = &Apache::lonlocal::texthash (
15844: official => 'Official',
15845: unofficial => 'Unofficial',
15846: community => 'Community',
15847: textbook => 'Textbook',
15848: placement => 'Placement Test',
1.392 raeburn 15849: lti => 'LTI Provider',
1.320 raeburn 15850: );
1.325 raeburn 15851: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 15852: my %lt = <i_names();
15853: map { $posslti{$_} = 1; } @ltiroles;
15854: map { $posslticrs{$_} = 1; } @lticourseroles;
15855: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 15856:
1.326 raeburn 15857: my %menutitles = <imenu_titles();
1.421 raeburn 15858: my (%currltisec,%secchanges,%newltisec,%newltienc,%newkeyset);
1.326 raeburn 15859:
1.421 raeburn 15860: &fetch_secrets($dom,'ltisec',\%domconfig,\%currltisec,\%secchanges,\%newltisec,\%newkeyset);
1.405 raeburn 15861:
1.406 raeburn 15862: my (%linkprotchg,$linkprotoutput,$is_home);
15863: my $proterror = &Apache::courseprefs::process_linkprot($dom,'',$currltisec{'linkprot'},
15864: \%linkprotchg,'domain');
15865: my $home = &Apache::lonnet::domain($dom,'primary');
15866: unless (($home eq 'no_host') || ($home eq '')) {
15867: my @ids=&Apache::lonnet::current_machine_ids();
15868: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; } }
15869: }
15870:
15871: if (keys(%linkprotchg)) {
15872: $secchanges{'linkprot'} = 1;
15873: my %oldlinkprot;
15874: if (ref($currltisec{'linkprot'}) eq 'HASH') {
15875: %oldlinkprot = %{$currltisec{'linkprot'}};
15876: }
15877: foreach my $id (keys(%linkprotchg)) {
15878: if (ref($linkprotchg{$id}) eq 'HASH') {
15879: foreach my $inner (keys(%{$linkprotchg{$id}})) {
15880: if (($inner eq 'secret') || ($inner eq 'key')) {
15881: if ($is_home) {
15882: $newltienc{$id}{$inner} = $linkprotchg{$id}{$inner};
15883: }
15884: }
15885: }
15886: } else {
15887: $newltisec{'linkprot'}{$id} = $linkprotchg{$id};
15888: }
15889: }
15890: $linkprotoutput = &Apache::courseprefs::store_linkprot($dom,'','domain',\%linkprotchg,\%oldlinkprot);
15891: if (keys(%linkprotchg)) {
15892: %{$newltisec{'linkprot'}} = %linkprotchg;
15893: }
15894: }
15895: if (ref($currltisec{'linkprot'}) eq 'HASH') {
1.434 raeburn 15896: foreach my $id (keys(%{$currltisec{'linkprot'}})) {
1.406 raeburn 15897: next if ($id !~ /^\d+$/);
15898: unless (exists($linkprotchg{$id})) {
15899: if (ref($currltisec{'linkprot'}{$id}) eq 'HASH') {
15900: foreach my $inner (keys(%{$currltisec{'linkprot'}{$id}})) {
15901: if (($inner eq 'secret') || ($inner eq 'key')) {
15902: if ($is_home) {
15903: $newltienc{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15904: }
15905: } else {
15906: $newltisec{'linkprot'}{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15907: }
15908: }
15909: } else {
15910: $newltisec{'linkprot'}{$id} = $currltisec{'linkprot'}{$id};
15911: }
15912: }
15913: }
15914: }
15915: if ($proterror) {
15916: $errors .= '<li>'.$proterror.'</li>';
15917: }
1.434 raeburn 15918:
15919: my (%delsuggested,%suggids,@suggested);;
15920: if (ref($currltisec{'suggested'}) eq 'HASH') {
15921: my $maxnum = $env{'form.linkprot_suggested_maxnum'};
15922: my @todelete = &Apache::loncommon::get_env_multiple('form.linkprot_suggested_del');
15923: for (my $i=0; $i<$maxnum; $i++) {
15924: my $itemid = $env{'form.linkprot_suggested_id_'.$i};
15925: $itemid =~ s/\D+//g;
15926: if ($itemid) {
15927: if (ref($currltisec{'suggested'}->{$itemid}) eq 'HASH') {
15928: push(@suggested,$i);
15929: $suggids{$i} = $itemid;
15930: if ((@todelete > 0) && (grep(/^$i$/,@todelete))) {
15931: if (ref($currltisec{'suggested'}{$itemid}) eq 'HASH') {
15932: $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
15933: }
15934: } else {
15935: if ($env{'form.linkprot_suggested_name_'.$i} eq '') {
15936: $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
15937: } else {
15938: $env{'form.linkprot_suggested_name_'.$i} =~ s/(`)/'/g;
15939: $env{'form.linkprot_suggested_info_'.$i} =~ s/(`)/'/g;
15940: $newltisec{'suggested'}{$itemid}{'name'} = $env{'form.linkprot_suggested_name_'.$i};
15941: $newltisec{'suggested'}{$itemid}{'info'} = $env{'form.linkprot_suggested_info_'.$i};
15942: if (($currltisec{'suggested'}{$itemid}{'name'} ne $newltisec{'suggested'}{$itemid}{'name'}) ||
15943: ($currltisec{'suggested'}{$itemid}{'info'} ne $newltisec{'suggested'}{$itemid}{'info'})) {
15944: $secchanges{'suggested'}{$itemid} = 1;
15945: }
15946: }
15947: }
15948: }
15949: }
15950: }
15951: }
15952: foreach my $key (keys(%delsuggested)) {
15953: $newltisec{'suggested'}{$key} = $delsuggested{$key};
15954: $secchanges{'suggested'}{$key} = 1;
15955: }
15956: if (($env{'form.linkprot_suggested_add'}) &&
15957: ($env{'form.linkprot_suggested_name_add'} ne '')) {
15958: $env{'form.linkprot_suggested_name_add'} =~ s/(`)/'/g;
15959: $env{'form.linkprot_suggested_info_add'} =~ s/(`)/'/g;
15960: my ($newsuggid,$errormsg) = &get_lti_id($dom,$env{'form.linkprot_suggested_name_add'},'suggested');
15961: if ($newsuggid) {
15962: $newltisec{'suggested'}{$newsuggid}{'name'} = $env{'form.linkprot_suggested_name_add'};
15963: $newltisec{'suggested'}{$newsuggid}{'info'} = $env{'form.linkprot_suggested_info_add'};
15964: $secchanges{'suggested'}{$newsuggid} = 1;
15965: } else {
15966: my $error = &mt('Failed to acquire unique ID for new Link Protectors in Courses Suggestion');
15967: if ($errormsg) {
15968: $error .= ' ('.$errormsg.')';
15969: }
15970: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15971: }
15972: }
1.320 raeburn 15973: my (@items,%deletions,%itemids);
15974: if ($env{'form.lti_add'}) {
15975: my $consumer = $env{'form.lti_consumer_add'};
15976: $consumer =~ s/(`)/'/g;
1.434 raeburn 15977: ($newid,my $errormsg) = &get_lti_id($dom,$consumer,'lti');
1.320 raeburn 15978: if ($newid) {
15979: $itemids{'add'} = $newid;
15980: push(@items,'add');
15981: $changes{$newid} = 1;
15982: } else {
15983: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
1.434 raeburn 15984: if ($errormsg) {
15985: $error .= ' ('.$errormsg.')';
15986: }
1.320 raeburn 15987: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15988: }
15989: }
15990: if (ref($domconfig{$action}) eq 'HASH') {
15991: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
15992: if (@todelete) {
15993: map { $deletions{$_} = 1; } @todelete;
15994: }
15995: my $maxnum = $env{'form.lti_maxnum'};
1.390 raeburn 15996: for (my $i=0; $i<$maxnum; $i++) {
1.320 raeburn 15997: my $itemid = $env{'form.lti_id_'.$i};
15998: $itemid =~ s/\D+//g;
15999: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
16000: if ($deletions{$itemid}) {
16001: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
16002: } else {
1.390 raeburn 16003: push(@items,$i);
16004: $itemids{$i} = $itemid;
1.320 raeburn 16005: }
16006: }
16007: }
16008: }
1.424 raeburn 16009: my (%keystore,$secstored);
16010: if ($is_home) {
16011: &store_security($dom,'lti',\%secchanges,\%newkeyset,\%keystore);
16012: }
16013:
16014: my ($cipher,$privnum);
16015: if ((@items > 0) && ($is_home)) {
16016: ($cipher,$privnum) = &get_priv_creds($dom,$home,$secchanges{'encrypt'},
16017: $newltisec{'encrypt'},$keystore{$home});
16018: }
1.320 raeburn 16019: foreach my $idx (@items) {
16020: my $itemid = $itemids{$idx};
16021: next unless ($itemid);
1.424 raeburn 16022: my %currlti;
16023: unless ($idx eq 'add') {
16024: if (ref($domconfig{$action}) eq 'HASH') {
16025: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
16026: %currlti = %{$domconfig{$action}{$itemid}};
16027: }
16028: }
16029: }
1.390 raeburn 16030: my $position = $env{'form.lti_pos_'.$itemid};
1.320 raeburn 16031: $position =~ s/\D+//g;
16032: if ($position ne '') {
16033: $allpos[$position] = $itemid;
16034: }
1.424 raeburn 16035: foreach my $item ('consumer','lifetime','requser','crsinc') {
1.320 raeburn 16036: my $formitem = 'form.lti_'.$item.'_'.$idx;
16037: $env{$formitem} =~ s/(`)/'/g;
16038: if ($item eq 'lifetime') {
16039: $env{$formitem} =~ s/[^\d.]//g;
16040: }
16041: if ($env{$formitem} ne '') {
1.424 raeburn 16042: $confhash{$itemid}{$item} = $env{$formitem};
16043: unless (($idx eq 'add') || ($changes{$itemid})) {
16044: if ($currlti{$item} ne $confhash{$itemid}{$item}) {
16045: $changes{$itemid} = 1;
1.320 raeburn 16046: }
16047: }
16048: }
16049: }
16050: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
16051: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
16052: }
1.345 raeburn 16053: if ($confhash{$itemid}{'requser'}) {
16054: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
1.405 raeburn 16055: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
1.345 raeburn 16056: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
16057: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
16058: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
16059: my $mapuser = $env{'form.lti_customuser_'.$idx};
16060: $mapuser =~ s/(`)/'/g;
1.405 raeburn 16061: $mapuser =~ s/^\s+|\s+$//g;
16062: $confhash{$itemid}{'mapuser'} = $mapuser;
1.345 raeburn 16063: }
16064: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
16065: my @makeuser;
16066: foreach my $ltirole (sort(@possmakeuser)) {
16067: if ($posslti{$ltirole}) {
16068: push(@makeuser,$ltirole);
16069: }
16070: }
16071: $confhash{$itemid}{'makeuser'} = \@makeuser;
16072: if (@makeuser) {
16073: my $lcauth = $env{'form.lti_lcauth_'.$idx};
16074: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
16075: $confhash{$itemid}{'lcauth'} = $lcauth;
16076: if ($lcauth ne 'internal') {
16077: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
16078: $lcauthparm =~ s/^(\s+|\s+)$//g;
16079: $lcauthparm =~ s/`//g;
16080: if ($lcauthparm ne '') {
16081: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
16082: }
16083: }
16084: } else {
16085: $confhash{$itemid}{'lcauth'} = 'lti';
16086: }
1.320 raeburn 16087: }
1.345 raeburn 16088: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
16089: if (@possinstdata) {
16090: foreach my $field (@possinstdata) {
16091: if (exists($fieldtitles{$field})) {
16092: push(@{$confhash{$itemid}{'instdata'}});
1.325 raeburn 16093: }
16094: }
16095: }
1.363 raeburn 16096: if ($env{'form.lti_callback_'.$idx}) {
16097: if ($env{'form.lti_callbackparam_'.$idx}) {
16098: my $callback = $env{'form.lti_callbackparam_'.$idx};
16099: $callback =~ s/^\s+|\s+$//g;
16100: $confhash{$itemid}{'callback'} = $callback;
16101: }
16102: }
1.391 raeburn 16103: foreach my $field ('topmenu','inlinemenu') {
1.345 raeburn 16104: if ($env{'form.lti_'.$field.'_'.$idx}) {
16105: $confhash{$itemid}{$field} = 1;
16106: }
1.320 raeburn 16107: }
1.345 raeburn 16108: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
16109: $confhash{$itemid}{lcmenu} = [];
16110: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
16111: foreach my $field (@possmenu) {
16112: if (exists($menutitles{$field})) {
16113: if ($field eq 'grades') {
16114: next unless ($env{'form.lti_inlinemenu_'.$idx});
16115: }
16116: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 16117: }
16118: }
16119: }
1.391 raeburn 16120: if ($confhash{$itemid}{'crsinc'}) {
16121: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
16122: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
16123: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
16124: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
16125: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
16126: $mapcrs =~ s/(`)/'/g;
16127: $mapcrs =~ s/^\s+|\s+$//g;
16128: $confhash{$itemid}{'mapcrs'} = $mapcrs;
16129: }
16130: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
16131: my @crstypes;
16132: foreach my $type (sort(@posstypes)) {
16133: if ($posscrstype{$type}) {
16134: push(@crstypes,$type);
16135: }
16136: }
16137: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
1.392 raeburn 16138: if ($env{'form.lti_storecrs_'.$idx}) {
16139: $confhash{$itemid}{'storecrs'} = 1;
16140: }
1.391 raeburn 16141: if ($env{'form.lti_makecrs_'.$idx}) {
16142: $confhash{$itemid}{'makecrs'} = 1;
16143: }
16144: foreach my $ltirole (@lticourseroles) {
16145: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
16146: if (grep(/^\Q$possrole\E$/,@courseroles)) {
16147: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
16148: }
16149: }
16150: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
16151: my @selfenroll;
16152: foreach my $type (sort(@possenroll)) {
16153: if ($posslticrs{$type}) {
16154: push(@selfenroll,$type);
16155: }
16156: }
16157: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
16158: if ($env{'form.lti_crssec_'.$idx}) {
16159: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
16160: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
16161: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
16162: my $section = $env{'form.lti_customsection_'.$idx};
16163: $section =~ s/(`)/'/g;
16164: $section =~ s/^\s+|\s+$//g;
16165: if ($section ne '') {
16166: $confhash{$itemid}{'section'} = $section;
16167: }
16168: }
16169: }
16170: foreach my $field ('passback','roster') {
16171: if ($env{'form.lti_'.$field.'_'.$idx}) {
16172: $confhash{$itemid}{$field} = 1;
16173: }
16174: }
16175: if ($env{'form.lti_passback_'.$idx}) {
16176: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
16177: $confhash{$itemid}{'passbackformat'} = '1.0';
16178: } else {
16179: $confhash{$itemid}{'passbackformat'} = '1.1';
1.337 raeburn 16180: }
16181: }
1.391 raeburn 16182: }
16183: unless (($idx eq 'add') || ($changes{$itemid})) {
16184: if ($confhash{$itemid}{'crsinc'}) {
1.392 raeburn 16185: foreach my $field ('mapcrs','storecrs','makecrs','section','passback','roster') {
1.424 raeburn 16186: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.320 raeburn 16187: $changes{$itemid} = 1;
16188: }
1.345 raeburn 16189: }
16190: unless ($changes{$itemid}) {
1.424 raeburn 16191: if ($currlti{'passback'} eq $confhash{$itemid}{'passback'}) {
16192: if ($currlti{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 16193: $changes{$itemid} = 1;
16194: }
16195: }
1.345 raeburn 16196: }
1.391 raeburn 16197: foreach my $field ('mapcrstype','selfenroll') {
16198: unless ($changes{$itemid}) {
1.424 raeburn 16199: if (ref($currlti{$field}) eq 'ARRAY') {
1.391 raeburn 16200: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424 raeburn 16201: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391 raeburn 16202: $confhash{$itemid}{$field});
16203: if (@diffs) {
16204: $changes{$itemid} = 1;
16205: }
1.424 raeburn 16206: } elsif (@{$currlti{$field}} > 0) {
1.391 raeburn 16207: $changes{$itemid} = 1;
16208: }
16209: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
16210: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 16211: $changes{$itemid} = 1;
16212: }
16213: }
1.391 raeburn 16214: }
16215: }
16216: unless ($changes{$itemid}) {
1.424 raeburn 16217: if (ref($currlti{'maproles'}) eq 'HASH') {
1.391 raeburn 16218: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
1.424 raeburn 16219: foreach my $ltirole (keys(%{$currlti{'maproles'}})) {
16220: if ($currlti{'maproles'}{$ltirole} ne
1.391 raeburn 16221: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.345 raeburn 16222: $changes{$itemid} = 1;
16223: last;
16224: }
16225: }
1.391 raeburn 16226: unless ($changes{$itemid}) {
16227: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
16228: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
1.424 raeburn 16229: $currlti{'maproles'}{$ltirole}) {
1.391 raeburn 16230: $changes{$itemid} = 1;
16231: last;
16232: }
16233: }
16234: }
1.424 raeburn 16235: } elsif (keys(%{$currlti{'maproles'}}) > 0) {
1.391 raeburn 16236: $changes{$itemid} = 1;
1.345 raeburn 16237: }
1.391 raeburn 16238: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16239: unless ($changes{$itemid}) {
16240: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
16241: $changes{$itemid} = 1;
16242: }
16243: }
16244: }
16245: }
16246: }
16247: unless ($changes{$itemid}) {
16248: foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
1.424 raeburn 16249: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.345 raeburn 16250: $changes{$itemid} = 1;
1.320 raeburn 16251: }
1.391 raeburn 16252: }
16253: unless ($changes{$itemid}) {
16254: foreach my $field ('makeuser','lcmenu') {
1.424 raeburn 16255: if (ref($currlti{$field}) eq 'ARRAY') {
1.391 raeburn 16256: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424 raeburn 16257: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391 raeburn 16258: $confhash{$itemid}{$field});
16259: if (@diffs) {
16260: $changes{$itemid} = 1;
16261: }
1.424 raeburn 16262: } elsif (@{$currlti{$field}} > 0) {
1.391 raeburn 16263: $changes{$itemid} = 1;
16264: }
16265: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
16266: if (@{$confhash{$itemid}{$field}} > 0) {
16267: $changes{$itemid} = 1;
16268: }
1.345 raeburn 16269: }
1.320 raeburn 16270: }
16271: }
16272: }
16273: }
16274: }
1.424 raeburn 16275: if ($is_home) {
16276: my $keyitem = 'form.lti_key_'.$idx;
16277: $env{$keyitem} =~ s/(`)/'/g;
16278: if ($env{$keyitem} ne '') {
16279: $ltienc{$itemid}{'key'} = $env{$keyitem};
16280: unless ($changes{$itemid}) {
16281: if ($currlti{'key'} ne $env{$keyitem}) {
16282: $changes{$itemid} = 1;
16283: }
16284: }
16285: }
16286: my $secretitem = 'form.lti_secret_'.$idx;
16287: $env{$secretitem} =~ s/(`)/'/g;
16288: if ($currlti{'usable'}) {
16289: if ($env{'form.lti_changesecret_'.$idx}) {
16290: if ($env{$secretitem} ne '') {
16291: if ($privnum && $cipher) {
16292: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
16293: $confhash{$itemid}{'cipher'} = $privnum;
16294: } else {
16295: $ltienc{$itemid}{'secret'} = $env{$secretitem};
16296: }
16297: $changes{$itemid} = 1;
16298: }
16299: } else {
16300: $ltienc{$itemid}{'secret'} = $currlti{'secret'};
16301: $confhash{$itemid}{'cipher'} = $currlti{'cipher'};
16302: }
16303: if (ref($ltienc{$itemid}) eq 'HASH') {
16304: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'secret'} ne '')) {
16305: $confhash{$itemid}{'usable'} = 1;
16306: }
16307: }
16308: } elsif ($env{$secretitem} ne '') {
16309: if ($privnum && $cipher) {
16310: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
16311: $confhash{$itemid}{'cipher'} = $privnum;
16312: } else {
16313: $ltienc{$itemid}{'secret'} = $env{$secretitem};
16314: }
16315: if (ref($ltienc{$itemid}) eq 'HASH') {
16316: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'key'} ne '')) {
16317: $confhash{$itemid}{'usable'} = 1;
16318: }
16319: }
16320: $changes{$itemid} = 1;
16321: }
16322: }
16323: unless ($changes{$itemid}) {
16324: foreach my $key (keys(%currlti)) {
16325: if (ref($currlti{$key}) eq 'HASH') {
16326: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
16327: foreach my $innerkey (keys(%{$currlti{$key}})) {
16328: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
16329: $changes{$itemid} = 1;
16330: last;
16331: }
16332: }
16333: } elsif (keys(%{$currlti{$key}}) > 0) {
16334: $changes{$itemid} = 1;
16335: }
16336: }
16337: last if ($changes{$itemid});
16338: }
16339: }
1.320 raeburn 16340: }
16341: if (@allpos > 0) {
16342: my $idx = 0;
16343: foreach my $itemid (@allpos) {
16344: if ($itemid ne '') {
16345: $confhash{$itemid}{'order'} = $idx;
16346: if (ref($domconfig{$action}) eq 'HASH') {
16347: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
16348: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
16349: $changes{$itemid} = 1;
16350: }
16351: }
16352: }
16353: $idx ++;
16354: }
16355: }
16356: }
1.424 raeburn 16357:
16358: if ((keys(%changes) == 0) && (keys(%secchanges) == 0)) {
16359: return &mt('No changes made.');
16360: }
16361:
1.320 raeburn 16362: my %ltihash = (
1.405 raeburn 16363: $action => { %confhash }
16364: );
1.424 raeburn 16365: my %ltienchash;
16366:
16367: if ($is_home) {
16368: %ltienchash = (
16369: $action => { %ltienc }
16370: );
16371: }
1.405 raeburn 16372: if (keys(%secchanges)) {
16373: $ltihash{'ltisec'} = \%newltisec;
1.406 raeburn 16374: if ($secchanges{'linkprot'}) {
16375: if ($is_home) {
16376: $ltienchash{'linkprot'} = \%newltienc;
16377: }
16378: }
1.405 raeburn 16379: }
16380: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,$dom);
1.320 raeburn 16381: if ($putresult eq 'ok') {
1.424 raeburn 16382: if (keys(%ltienchash)) {
16383: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.405 raeburn 16384: }
16385: $resulttext = &mt('Changes made:').'<ul>';
16386: if (keys(%secchanges) > 0) {
1.423 raeburn 16387: $resulttext .= <i_security_results($dom,'lti',\%secchanges,\%newltisec,\%newkeyset,\%keystore);
1.421 raeburn 16388: if (exists($secchanges{'linkprot'})) {
16389: $resulttext .= $linkprotoutput;
1.405 raeburn 16390: }
16391: }
1.320 raeburn 16392: if (keys(%changes) > 0) {
16393: my $cachetime = 24*60*60;
1.424 raeburn 16394: &Apache::lonnet::do_cache_new('lti',$dom,\%confhash,$cachetime);
1.320 raeburn 16395: if (ref($lastactref) eq 'HASH') {
16396: $lastactref->{'lti'} = 1;
16397: }
16398: my %bynum;
16399: foreach my $itemid (sort(keys(%changes))) {
1.424 raeburn 16400: if (ref($confhash{$itemid}) eq 'HASH') {
16401: my $position = $confhash{$itemid}{'order'};
16402: $bynum{$position} = $itemid;
16403: }
1.320 raeburn 16404: }
16405: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
16406: my $itemid = $bynum{$pos};
1.424 raeburn 16407: if (ref($confhash{$itemid}) eq 'HASH') {
1.390 raeburn 16408: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1.320 raeburn 16409: my $position = $pos + 1;
16410: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
16411: foreach my $item ('version','lifetime') {
16412: if ($confhash{$itemid}{$item} ne '') {
16413: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
16414: }
16415: }
1.424 raeburn 16416: if ($ltienc{$itemid}{'key'} ne '') {
16417: $resulttext .= '<li>'.$lt{'key'}.': '.$ltienc{$itemid}{'key'}.'</li>';
1.320 raeburn 16418: }
1.424 raeburn 16419: if ($ltienc{$itemid}{'secret'} ne '') {
16420: $resulttext .= '<li>'.$lt{'secret'}.': ['.&mt('not shown').']</li>';
1.320 raeburn 16421: }
1.345 raeburn 16422: if ($confhash{$itemid}{'requser'}) {
1.391 raeburn 16423: if ($confhash{$itemid}{'callback'}) {
16424: $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
16425: } else {
1.392 raeburn 16426: $resulttext .= '<li>'.&mt('Callback to logout LON-CAPA on log out from Consumer').'</li>';
1.391 raeburn 16427: }
1.345 raeburn 16428: if ($confhash{$itemid}{'mapuser'}) {
16429: my $shownmapuser;
16430: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
16431: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
16432: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
16433: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
16434: } else {
16435: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 16436: }
1.345 raeburn 16437: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 16438: }
1.345 raeburn 16439: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
16440: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
16441: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
16442: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
16443: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
16444: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
16445: } else {
16446: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
16447: $confhash{$itemid}{'lcauth'});
16448: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
16449: $resulttext .= '; '.&mt('a randomly generated password will be created');
16450: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
16451: if ($confhash{$itemid}{'lcauthparm'} ne '') {
16452: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
16453: }
16454: } else {
16455: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
16456: }
16457: }
16458: $resulttext .= '</li>';
16459: } else {
16460: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
16461: }
1.320 raeburn 16462: }
1.345 raeburn 16463: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
16464: if (@{$confhash{$itemid}{'instdata'}} > 0) {
16465: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
16466: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 16467: } else {
1.345 raeburn 16468: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325 raeburn 16469: }
1.320 raeburn 16470: }
1.391 raeburn 16471: foreach my $item ('topmenu','inlinemenu') {
1.345 raeburn 16472: $resulttext .= '<li>'.$lt{$item}.': ';
16473: if ($confhash{$itemid}{$item}) {
16474: $resulttext .= &mt('Yes');
16475: } else {
16476: $resulttext .= &mt('No');
1.337 raeburn 16477: }
1.345 raeburn 16478: $resulttext .= '</li>';
1.320 raeburn 16479: }
1.345 raeburn 16480: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16481: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16482: $resulttext .= '<li>'.&mt('Menu items:').' '.
1.391 raeburn 16483: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16484: } else {
16485: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16486: }
16487: }
16488: if ($confhash{$itemid}{'crsinc'}) {
16489: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16490: my $rolemaps;
16491: foreach my $role (@ltiroles) {
16492: if ($confhash{$itemid}{'maproles'}{$role}) {
16493: $rolemaps .= (' 'x2).$role.'='.
16494: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
16495: 'Course').',';
16496: }
16497: }
16498: if ($rolemaps) {
16499: $rolemaps =~ s/,$//;
16500: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
16501: }
16502: }
16503: if ($confhash{$itemid}{'mapcrs'}) {
16504: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
16505: }
16506: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
16507: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
16508: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
16509: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
16510: '</li>';
16511: } else {
16512: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
16513: }
16514: }
1.392 raeburn 16515: if ($confhash{$itemid}{'storecrs'}) {
16516: $resulttext .= '<li>'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.$confhash{$itemid}{'storecrs'}.'</li>';
16517: }
1.391 raeburn 16518: if ($confhash{$itemid}{'makecrs'}) {
16519: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
16520: } else {
16521: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
16522: }
16523: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
16524: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
16525: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
16526: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
16527: '</li>';
16528: } else {
16529: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
16530: }
16531: }
16532: if ($confhash{$itemid}{'section'}) {
16533: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
16534: $resulttext .= '<li>'.&mt('User section from standard field:').
16535: ' (course_section_sourcedid)'.'</li>';
16536: } else {
16537: $resulttext .= '<li>'.&mt('User section from:').' '.
16538: $confhash{$itemid}{'section'}.'</li>';
16539: }
1.345 raeburn 16540: } else {
1.391 raeburn 16541: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
16542: }
16543: foreach my $item ('passback','roster','topmenu','inlinemenu') {
16544: $resulttext .= '<li>'.$lt{$item}.': ';
16545: if ($confhash{$itemid}{$item}) {
16546: $resulttext .= &mt('Yes');
16547: if ($item eq 'passback') {
16548: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
16549: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
16550: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
16551: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
16552: }
16553: }
16554: } else {
16555: $resulttext .= &mt('No');
16556: }
16557: $resulttext .= '</li>';
16558: }
16559: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16560: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16561: $resulttext .= '<li>'.&mt('Menu items:').' '.
16562: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16563: } else {
16564: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16565: }
1.345 raeburn 16566: }
1.326 raeburn 16567: }
16568: }
1.320 raeburn 16569: $resulttext .= '</ul></li>';
16570: }
16571: }
1.424 raeburn 16572: if (keys(%deletions)) {
16573: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
16574: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
16575: }
16576: }
1.320 raeburn 16577: }
1.405 raeburn 16578: $resulttext .= '</ul>';
1.424 raeburn 16579: if (ref($lastactref) eq 'HASH') {
1.434 raeburn 16580: if (($secchanges{'encrypt'}) || ($secchanges{'private'}) || (exists($secchanges{'suggested'}))) {
16581: &Apache::lonnet::get_domain_defaults($dom,1);
1.424 raeburn 16582: $lastactref->{'domdefaults'} = 1;
16583: }
16584: }
1.320 raeburn 16585: } else {
16586: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
16587: }
16588: if ($errors) {
16589: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
16590: $errors.'</ul>';
16591: }
16592: return $resulttext;
16593: }
16594:
1.424 raeburn 16595: sub get_priv_creds {
16596: my ($dom,$home,$encchg,$encrypt,$storedsec) = @_;
16597: my ($needenc,$cipher,$privnum);
16598: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
16599: if (($encchg) && (ref($encrypt) eq 'HASH')) {
16600: $needenc = $encrypt->{'consumers'}
16601: } else {
16602: $needenc = $domdefs{'ltienc_consumers'};
16603: }
16604: if ($needenc) {
16605: if (($storedsec eq 'ok') || ((ref($domdefs{'ltiprivhosts'}) eq 'ARRAY') &&
16606: (grep(/^\Q$home\E$/,@{$domdefs{'ltiprivhosts'}})))) {
16607: my %privhash = &Apache::lonnet::restore_dom('lti','private',$dom,$home,1);
16608: my $privkey = $privhash{'key'};
16609: $privnum = $privhash{'version'};
16610: if (($privnum) && ($privkey ne '')) {
16611: $cipher = Crypt::CBC->new({'key' => $privkey,
16612: 'cipher' => 'DES'});
16613: }
16614: }
16615: }
16616: return ($cipher,$privnum);
16617: }
16618:
1.320 raeburn 16619: sub get_lti_id {
1.434 raeburn 16620: my ($domain,$consumer,$dbname) = @_;
16621: unless (($dbname eq 'lti') || ($dbname eq 'suggested')) {
16622: return ('','invalid db');
16623: }
16624: # get lock on db
1.320 raeburn 16625: my $lockhash = {
16626: lock => $env{'user.name'}.
16627: ':'.$env{'user.domain'},
16628: };
16629: my $tries = 0;
1.434 raeburn 16630: my $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1.320 raeburn 16631: my ($id,$error);
16632:
16633: while (($gotlock ne 'ok') && ($tries<10)) {
16634: $tries ++;
16635: sleep (0.1);
1.434 raeburn 16636: $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1.320 raeburn 16637: }
16638: if ($gotlock eq 'ok') {
1.434 raeburn 16639: my %currids = &Apache::lonnet::dump_dom($dbname,$domain);
1.320 raeburn 16640: if ($currids{'lock'}) {
16641: delete($currids{'lock'});
16642: if (keys(%currids)) {
16643: my @curr = sort { $a <=> $b } keys(%currids);
16644: if ($curr[-1] =~ /^\d+$/) {
16645: $id = 1 + $curr[-1];
16646: }
16647: } else {
16648: $id = 1;
16649: }
16650: if ($id) {
1.434 raeburn 16651: unless (&Apache::lonnet::newput_dom($dbname,{ $id => $consumer },$domain) eq 'ok') {
1.320 raeburn 16652: $error = 'nostore';
16653: }
16654: } else {
16655: $error = 'nonumber';
16656: }
16657: }
1.434 raeburn 16658: my $dellockoutcome = &Apache::lonnet::del_dom($dbname,['lock'],$domain);
1.320 raeburn 16659: } else {
16660: $error = 'nolock';
16661: }
16662: return ($id,$error);
16663: }
16664:
1.3 raeburn 16665: sub modify_autoenroll {
1.205 raeburn 16666: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 16667: my ($resulttext,%changes);
16668: my %currautoenroll;
16669: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
16670: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
16671: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
16672: }
16673: }
16674: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
16675: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 16676: sender => 'Sender for notification messages',
1.274 raeburn 16677: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.399 raeburn 16678: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 16679: my @offon = ('off','on');
1.17 raeburn 16680: my $sender_uname = $env{'form.sender_uname'};
16681: my $sender_domain = $env{'form.sender_domain'};
16682: if ($sender_domain eq '') {
16683: $sender_uname = '';
16684: } elsif ($sender_uname eq '') {
16685: $sender_domain = '';
16686: }
1.129 raeburn 16687: my $coowners = $env{'form.autoassign_coowners'};
1.399 raeburn 16688: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
16689: $autofailsafe =~ s{^\s+|\s+$}{}g;
16690: if ($autofailsafe =~ /\D/) {
16691: undef($autofailsafe);
16692: }
1.274 raeburn 16693: my $failsafe = $env{'form.autoenroll_failsafe'};
1.399 raeburn 16694: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
16695: $failsafe = 'off';
1.400 raeburn 16696: undef($autofailsafe);
1.274 raeburn 16697: }
1.1 raeburn 16698: my %autoenrollhash = (
1.129 raeburn 16699: autoenroll => { 'run' => $env{'form.autoenroll_run'},
16700: 'sender_uname' => $sender_uname,
16701: 'sender_domain' => $sender_domain,
16702: 'co-owners' => $coowners,
1.399 raeburn 16703: 'autofailsafe' => $autofailsafe,
1.400 raeburn 16704: 'failsafe' => $failsafe,
1.1 raeburn 16705: }
16706: );
1.4 raeburn 16707: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
16708: $dom);
1.1 raeburn 16709: if ($putresult eq 'ok') {
16710: if (exists($currautoenroll{'run'})) {
16711: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
16712: $changes{'run'} = 1;
16713: }
16714: } elsif ($autorun) {
16715: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 16716: $changes{'run'} = 1;
1.1 raeburn 16717: }
16718: }
1.17 raeburn 16719: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 16720: $changes{'sender'} = 1;
16721: }
1.17 raeburn 16722: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 16723: $changes{'sender'} = 1;
16724: }
1.129 raeburn 16725: if ($currautoenroll{'co-owners'} ne '') {
16726: if ($currautoenroll{'co-owners'} ne $coowners) {
16727: $changes{'coowners'} = 1;
16728: }
16729: } elsif ($coowners) {
16730: $changes{'coowners'} = 1;
1.274 raeburn 16731: }
1.399 raeburn 16732: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.274 raeburn 16733: $changes{'autofailsafe'} = 1;
16734: }
1.399 raeburn 16735: if ($currautoenroll{'failsafe'} ne $failsafe) {
16736: $changes{'failsafe'} = 1;
16737: }
1.1 raeburn 16738: if (keys(%changes) > 0) {
16739: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 16740: if ($changes{'run'}) {
1.1 raeburn 16741: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
16742: }
16743: if ($changes{'sender'}) {
1.17 raeburn 16744: if ($sender_uname eq '' || $sender_domain eq '') {
16745: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
16746: } else {
16747: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
16748: }
1.1 raeburn 16749: }
1.129 raeburn 16750: if ($changes{'coowners'}) {
16751: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
16752: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 16753: if (ref($lastactref) eq 'HASH') {
16754: $lastactref->{'domainconfig'} = 1;
16755: }
1.129 raeburn 16756: }
1.274 raeburn 16757: if ($changes{'autofailsafe'}) {
1.399 raeburn 16758: if ($autofailsafe ne '') {
16759: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.274 raeburn 16760: } else {
1.399 raeburn 16761: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.274 raeburn 16762: }
1.399 raeburn 16763: }
16764: if ($changes{'failsafe'}) {
16765: if ($failsafe eq 'off') {
16766: unless ($changes{'autofailsafe'}) {
16767: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
16768: }
16769: } elsif ($failsafe eq 'zero') {
16770: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
16771: } else {
16772: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
16773: }
16774: }
16775: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.274 raeburn 16776: &Apache::lonnet::get_domain_defaults($dom,1);
16777: if (ref($lastactref) eq 'HASH') {
16778: $lastactref->{'domdefaults'} = 1;
16779: }
16780: }
1.1 raeburn 16781: $resulttext .= '</ul>';
16782: } else {
16783: $resulttext = &mt('No changes made to auto-enrollment settings');
16784: }
16785: } else {
1.11 albertel 16786: $resulttext = '<span class="LC_error">'.
16787: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16788: }
1.3 raeburn 16789: return $resulttext;
1.1 raeburn 16790: }
16791:
16792: sub modify_autoupdate {
1.3 raeburn 16793: my ($dom,%domconfig) = @_;
1.1 raeburn 16794: my ($resulttext,%currautoupdate,%fields,%changes);
16795: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
16796: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
16797: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
16798: }
16799: }
16800: my @offon = ('off','on');
16801: my %title = &Apache::lonlocal::texthash (
1.385 raeburn 16802: run => 'Auto-update:',
16803: classlists => 'Updates to user information in classlists?',
16804: unexpired => 'Skip updates for users without active or future roles?',
16805: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 16806: );
1.44 raeburn 16807: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 16808: my %fieldtitles = &Apache::lonlocal::texthash (
16809: id => 'Student/Employee ID',
1.20 raeburn 16810: permanentemail => 'E-mail address',
1.1 raeburn 16811: lastname => 'Last Name',
16812: firstname => 'First Name',
16813: middlename => 'Middle Name',
1.132 raeburn 16814: generation => 'Generation',
1.1 raeburn 16815: );
1.142 raeburn 16816: $othertitle = &mt('All users');
1.1 raeburn 16817: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 16818: $othertitle = &mt('Other users');
1.1 raeburn 16819: }
16820: foreach my $key (keys(%env)) {
16821: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 16822: my ($usertype,$item) = ($1,$2);
16823: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
16824: if ($usertype eq 'default') {
16825: push(@{$fields{$1}},$2);
16826: } elsif (ref($types) eq 'ARRAY') {
16827: if (grep(/^\Q$usertype\E$/,@{$types})) {
16828: push(@{$fields{$1}},$2);
16829: }
16830: }
16831: }
1.1 raeburn 16832: }
16833: }
1.131 raeburn 16834: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
16835: @lockablenames = sort(@lockablenames);
16836: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
16837: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16838: if (@changed) {
16839: $changes{'lockablenames'} = 1;
16840: }
16841: } else {
16842: if (@lockablenames) {
16843: $changes{'lockablenames'} = 1;
16844: }
16845: }
1.1 raeburn 16846: my %updatehash = (
16847: autoupdate => { run => $env{'form.autoupdate_run'},
16848: classlists => $env{'form.classlists'},
1.385 raeburn 16849: unexpired => $env{'form.unexpired'},
1.1 raeburn 16850: fields => {%fields},
1.131 raeburn 16851: lockablenames => \@lockablenames,
1.1 raeburn 16852: }
16853: );
1.385 raeburn 16854: my $lastactivedays;
16855: if ($env{'form.lastactive'}) {
16856: $lastactivedays = $env{'form.lastactivedays'};
16857: $lastactivedays =~ s/^\s+|\s+$//g;
16858: unless ($lastactivedays =~ /^\d+$/) {
16859: undef($lastactivedays);
16860: $env{'form.lastactive'} = 0;
16861: }
16862: }
16863: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 16864: foreach my $key (keys(%currautoupdate)) {
1.385 raeburn 16865: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 16866: if (exists($updatehash{autoupdate}{$key})) {
16867: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
16868: $changes{$key} = 1;
16869: }
16870: }
16871: } elsif ($key eq 'fields') {
16872: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 16873: foreach my $item (@{$types},'default') {
1.1 raeburn 16874: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
16875: my $change = 0;
16876: foreach my $type (@{$currautoupdate{$key}{$item}}) {
16877: if (!exists($fields{$item})) {
16878: $change = 1;
1.132 raeburn 16879: last;
1.1 raeburn 16880: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 16881: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 16882: $change = 1;
1.132 raeburn 16883: last;
1.1 raeburn 16884: }
16885: }
16886: }
16887: if ($change) {
16888: push(@{$changes{$key}},$item);
16889: }
1.26 raeburn 16890: }
1.1 raeburn 16891: }
16892: }
1.131 raeburn 16893: } elsif ($key eq 'lockablenames') {
16894: if (ref($currautoupdate{$key}) eq 'ARRAY') {
16895: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16896: if (@changed) {
16897: $changes{'lockablenames'} = 1;
16898: }
16899: } else {
16900: if (@lockablenames) {
16901: $changes{'lockablenames'} = 1;
16902: }
16903: }
16904: }
16905: }
16906: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
16907: if (@lockablenames) {
16908: $changes{'lockablenames'} = 1;
1.1 raeburn 16909: }
16910: }
1.385 raeburn 16911: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
16912: if ($updatehash{'autoupdate'}{'unexpired'}) {
16913: $changes{'unexpired'} = 1;
16914: }
16915: }
16916: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
16917: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
16918: $changes{'lastactive'} = 1;
16919: }
16920: }
1.26 raeburn 16921: foreach my $item (@{$types},'default') {
16922: if (defined($fields{$item})) {
16923: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 16924: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
16925: my $change = 0;
16926: if (ref($fields{$item}) eq 'ARRAY') {
16927: foreach my $type (@{$fields{$item}}) {
16928: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
16929: $change = 1;
16930: last;
16931: }
16932: }
16933: }
16934: if ($change) {
16935: push(@{$changes{'fields'}},$item);
16936: }
16937: } else {
1.26 raeburn 16938: push(@{$changes{'fields'}},$item);
16939: }
16940: } else {
16941: push(@{$changes{'fields'}},$item);
1.1 raeburn 16942: }
16943: }
16944: }
16945: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
16946: $dom);
16947: if ($putresult eq 'ok') {
16948: if (keys(%changes) > 0) {
16949: $resulttext = &mt('Changes made:').'<ul>';
16950: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 16951: if ($key eq 'lockablenames') {
16952: $resulttext .= '<li>';
16953: if (@lockablenames) {
16954: $usertypes->{'default'} = $othertitle;
16955: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
16956: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
16957: } else {
16958: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
16959: }
16960: $resulttext .= '</li>';
16961: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 16962: foreach my $item (@{$changes{$key}}) {
16963: my @newvalues;
16964: foreach my $type (@{$fields{$item}}) {
16965: push(@newvalues,$fieldtitles{$type});
16966: }
1.3 raeburn 16967: my $newvaluestr;
16968: if (@newvalues > 0) {
16969: $newvaluestr = join(', ',@newvalues);
16970: } else {
16971: $newvaluestr = &mt('none');
1.6 raeburn 16972: }
1.1 raeburn 16973: if ($item eq 'default') {
1.26 raeburn 16974: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 16975: } else {
1.26 raeburn 16976: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 16977: }
16978: }
16979: } else {
16980: my $newvalue;
16981: if ($key eq 'run') {
16982: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.385 raeburn 16983: } elsif ($key eq 'lastactive') {
16984: $newvalue = $offon[$env{'form.lastactive'}];
16985: unless ($lastactivedays eq '') {
16986: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
16987: }
1.1 raeburn 16988: } else {
16989: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 16990: }
1.1 raeburn 16991: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
16992: }
16993: }
16994: $resulttext .= '</ul>';
16995: } else {
1.3 raeburn 16996: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 16997: }
16998: } else {
1.11 albertel 16999: $resulttext = '<span class="LC_error">'.
17000: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 17001: }
1.3 raeburn 17002: return $resulttext;
1.1 raeburn 17003: }
17004:
1.125 raeburn 17005: sub modify_autocreate {
17006: my ($dom,%domconfig) = @_;
17007: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
17008: if (ref($domconfig{'autocreate'}) eq 'HASH') {
17009: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
17010: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
17011: }
17012: }
17013: my %title= ( xml => 'Auto-creation of courses in XML course description files',
17014: req => 'Auto-creation of validated requests for official courses',
17015: xmldc => 'Identity of course creator of courses from XML files',
17016: );
17017: my @types = ('xml','req');
17018: foreach my $item (@types) {
17019: $newvals{$item} = $env{'form.autocreate_'.$item};
17020: $newvals{$item} =~ s/\D//g;
17021: $newvals{$item} = 0 if ($newvals{$item} eq '');
17022: }
17023: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 17024: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 17025: unless (exists($domcoords{$newvals{'xmldc'}})) {
17026: $newvals{'xmldc'} = '';
17027: }
17028: %autocreatehash = (
17029: autocreate => { xml => $newvals{'xml'},
17030: req => $newvals{'req'},
17031: }
17032: );
17033: if ($newvals{'xmldc'} ne '') {
17034: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
17035: }
17036: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
17037: $dom);
17038: if ($putresult eq 'ok') {
17039: my @items = @types;
17040: if ($newvals{'xml'}) {
17041: push(@items,'xmldc');
17042: }
17043: foreach my $item (@items) {
17044: if (exists($currautocreate{$item})) {
17045: if ($currautocreate{$item} ne $newvals{$item}) {
17046: $changes{$item} = 1;
17047: }
17048: } elsif ($newvals{$item}) {
17049: $changes{$item} = 1;
17050: }
17051: }
17052: if (keys(%changes) > 0) {
17053: my @offon = ('off','on');
17054: $resulttext = &mt('Changes made:').'<ul>';
17055: foreach my $item (@types) {
17056: if ($changes{$item}) {
17057: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 17058: $resulttext .= '<li>'.
17059: &mt("$title{$item} set to [_1]$newtxt [_2]",
17060: '<b>','</b>').
17061: '</li>';
1.125 raeburn 17062: }
17063: }
17064: if ($changes{'xmldc'}) {
17065: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
17066: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 17067: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 17068: }
17069: $resulttext .= '</ul>';
17070: } else {
17071: $resulttext = &mt('No changes made to auto-creation settings');
17072: }
17073: } else {
17074: $resulttext = '<span class="LC_error">'.
17075: &mt('An error occurred: [_1]',$putresult).'</span>';
17076: }
17077: return $resulttext;
17078: }
17079:
1.23 raeburn 17080: sub modify_directorysrch {
1.295 raeburn 17081: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 17082: my ($resulttext,%changes);
17083: my %currdirsrch;
17084: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
17085: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
17086: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
17087: }
17088: }
1.277 raeburn 17089: my %title = ( available => 'Institutional directory search available',
17090: localonly => 'Other domains can search institution',
17091: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 17092: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 17093: searchby => 'Search types',
17094: searchtypes => 'Search latitude');
17095: my @offon = ('off','on');
1.24 raeburn 17096: my @otherdoms = ('Yes','No');
1.23 raeburn 17097:
1.25 raeburn 17098: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 17099: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
17100: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
17101:
1.44 raeburn 17102: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 17103: if (keys(%{$usertypes}) == 0) {
17104: @cansearch = ('default');
17105: } else {
17106: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
17107: foreach my $type (@{$currdirsrch{'cansearch'}}) {
17108: if (!grep(/^\Q$type\E$/,@cansearch)) {
17109: push(@{$changes{'cansearch'}},$type);
17110: }
1.23 raeburn 17111: }
1.26 raeburn 17112: foreach my $type (@cansearch) {
17113: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
17114: push(@{$changes{'cansearch'}},$type);
17115: }
1.23 raeburn 17116: }
1.26 raeburn 17117: } else {
17118: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 17119: }
17120: }
17121:
17122: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
17123: foreach my $by (@{$currdirsrch{'searchby'}}) {
17124: if (!grep(/^\Q$by\E$/,@searchby)) {
17125: push(@{$changes{'searchby'}},$by);
17126: }
17127: }
17128: foreach my $by (@searchby) {
17129: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
17130: push(@{$changes{'searchby'}},$by);
17131: }
17132: }
17133: } else {
17134: push(@{$changes{'searchby'}},@searchby);
17135: }
1.25 raeburn 17136:
17137: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
17138: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
17139: if (!grep(/^\Q$type\E$/,@searchtypes)) {
17140: push(@{$changes{'searchtypes'}},$type);
17141: }
17142: }
17143: foreach my $type (@searchtypes) {
17144: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
17145: push(@{$changes{'searchtypes'}},$type);
17146: }
17147: }
17148: } else {
17149: if (exists($currdirsrch{'searchtypes'})) {
17150: foreach my $type (@searchtypes) {
17151: if ($type ne $currdirsrch{'searchtypes'}) {
17152: push(@{$changes{'searchtypes'}},$type);
17153: }
17154: }
17155: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
17156: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
17157: }
17158: } else {
17159: push(@{$changes{'searchtypes'}},@searchtypes);
17160: }
17161: }
17162:
1.23 raeburn 17163: my %dirsrch_hash = (
17164: directorysrch => { available => $env{'form.dirsrch_available'},
17165: cansearch => \@cansearch,
1.277 raeburn 17166: localonly => $env{'form.dirsrch_instlocalonly'},
17167: lclocalonly => $env{'form.dirsrch_domlocalonly'},
17168: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 17169: searchby => \@searchby,
1.25 raeburn 17170: searchtypes => \@searchtypes,
1.23 raeburn 17171: }
17172: );
17173: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
17174: $dom);
17175: if ($putresult eq 'ok') {
17176: if (exists($currdirsrch{'available'})) {
17177: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
17178: $changes{'available'} = 1;
17179: }
17180: } else {
17181: if ($env{'form.dirsrch_available'} eq '1') {
17182: $changes{'available'} = 1;
17183: }
17184: }
1.277 raeburn 17185: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 17186: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
17187: $changes{'lcavailable'} = 1;
17188: }
1.277 raeburn 17189: } else {
17190: if ($env{'form.dirsrch_lcavailable'} eq '1') {
17191: $changes{'lcavailable'} = 1;
17192: }
17193: }
1.24 raeburn 17194: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 17195: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
17196: $changes{'localonly'} = 1;
17197: }
1.24 raeburn 17198: } else {
1.277 raeburn 17199: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 17200: $changes{'localonly'} = 1;
17201: }
17202: }
1.277 raeburn 17203: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 17204: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
17205: $changes{'lclocalonly'} = 1;
17206: }
1.277 raeburn 17207: } else {
17208: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
17209: $changes{'lclocalonly'} = 1;
17210: }
17211: }
1.23 raeburn 17212: if (keys(%changes) > 0) {
17213: $resulttext = &mt('Changes made:').'<ul>';
17214: if ($changes{'available'}) {
17215: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
17216: }
1.277 raeburn 17217: if ($changes{'lcavailable'}) {
17218: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
17219: }
1.24 raeburn 17220: if ($changes{'localonly'}) {
1.277 raeburn 17221: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 17222: }
1.277 raeburn 17223: if ($changes{'lclocalonly'}) {
17224: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 17225: }
1.23 raeburn 17226: if (ref($changes{'cansearch'}) eq 'ARRAY') {
17227: my $chgtext;
1.26 raeburn 17228: if (ref($usertypes) eq 'HASH') {
17229: if (keys(%{$usertypes}) > 0) {
17230: foreach my $type (@{$types}) {
17231: if (grep(/^\Q$type\E$/,@cansearch)) {
17232: $chgtext .= $usertypes->{$type}.'; ';
17233: }
17234: }
17235: if (grep(/^default$/,@cansearch)) {
17236: $chgtext .= $othertitle;
17237: } else {
17238: $chgtext =~ s/\; $//;
17239: }
1.210 raeburn 17240: $resulttext .=
1.178 raeburn 17241: '<li>'.
17242: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
17243: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
17244: '</li>';
1.23 raeburn 17245: }
17246: }
17247: }
17248: if (ref($changes{'searchby'}) eq 'ARRAY') {
17249: my ($searchtitles,$titleorder) = &sorted_searchtitles();
17250: my $chgtext;
17251: foreach my $type (@{$titleorder}) {
17252: if (grep(/^\Q$type\E$/,@searchby)) {
17253: if (defined($searchtitles->{$type})) {
17254: $chgtext .= $searchtitles->{$type}.'; ';
17255: }
17256: }
17257: }
17258: $chgtext =~ s/\; $//;
17259: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
17260: }
1.25 raeburn 17261: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
17262: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
17263: my $chgtext;
17264: foreach my $type (@{$srchtypeorder}) {
17265: if (grep(/^\Q$type\E$/,@searchtypes)) {
17266: if (defined($srchtypes_desc->{$type})) {
17267: $chgtext .= $srchtypes_desc->{$type}.'; ';
17268: }
17269: }
17270: }
17271: $chgtext =~ s/\; $//;
1.178 raeburn 17272: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 17273: }
17274: $resulttext .= '</ul>';
1.295 raeburn 17275: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
17276: if (ref($lastactref) eq 'HASH') {
17277: $lastactref->{'directorysrch'} = 1;
17278: }
1.23 raeburn 17279: } else {
1.277 raeburn 17280: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 17281: }
17282: } else {
17283: $resulttext = '<span class="LC_error">'.
1.27 raeburn 17284: &mt('An error occurred: [_1]',$putresult).'</span>';
17285: }
17286: return $resulttext;
17287: }
17288:
1.28 raeburn 17289: sub modify_contacts {
1.205 raeburn 17290: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 17291: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
17292: if (ref($domconfig{'contacts'}) eq 'HASH') {
17293: foreach my $key (keys(%{$domconfig{'contacts'}})) {
17294: $currsetting{$key} = $domconfig{'contacts'}{$key};
17295: }
17296: }
1.286 raeburn 17297: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 17298: my @contacts = ('supportemail','adminemail');
1.286 raeburn 17299: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350 raeburn 17300: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340 raeburn 17301: my @toggles = ('reporterrors','reportupdates','reportstatus');
17302: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 17303: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 17304: foreach my $type (@mailings) {
17305: @{$newsetting{$type}} =
17306: &Apache::loncommon::get_env_multiple('form.'.$type);
17307: foreach my $item (@contacts) {
17308: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
17309: $contacts_hash{contacts}{$type}{$item} = 1;
17310: } else {
17311: $contacts_hash{contacts}{$type}{$item} = 0;
17312: }
1.289 raeburn 17313: }
1.28 raeburn 17314: $others{$type} = $env{'form.'.$type.'_others'};
17315: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 17316: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17317: $bcc{$type} = $env{'form.'.$type.'_bcc'};
17318: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 17319: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
17320: $includestr{$type} = $env{'form.'.$type.'_includestr'};
17321: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
17322: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17323: }
1.134 raeburn 17324: }
1.28 raeburn 17325: }
17326: foreach my $item (@contacts) {
17327: $to{$item} = $env{'form.'.$item};
17328: $contacts_hash{'contacts'}{$item} = $to{$item};
17329: }
1.203 raeburn 17330: foreach my $item (@toggles) {
17331: if ($env{'form.'.$item} =~ /^(0|1)$/) {
17332: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
17333: }
17334: }
1.340 raeburn 17335: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
17336: foreach my $item (@lonstatus) {
17337: if ($item eq 'excluded') {
17338: my (%serverhomes,@excluded);
17339: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
17340: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
17341: if (@possexcluded) {
17342: foreach my $id (sort(@possexcluded)) {
17343: if ($serverhomes{$id}) {
17344: push(@excluded,$id);
17345: }
17346: }
17347: }
17348: if (@excluded) {
17349: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
17350: }
17351: } elsif ($item eq 'weights') {
1.377 raeburn 17352: foreach my $type ('E','W','N','U') {
1.340 raeburn 17353: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
17354: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
17355: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
17356: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
17357: $env{'form.error'.$item.'_'.$type};
17358: }
17359: }
17360: }
17361: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
17362: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
17363: if ($env{'form.error'.$item} =~ /^\d+$/) {
17364: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
17365: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
17366: }
17367: }
17368: }
17369: }
1.286 raeburn 17370: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
17371: foreach my $field (@{$fields}) {
17372: if (ref($possoptions->{$field}) eq 'ARRAY') {
17373: my $value = $env{'form.helpform_'.$field};
17374: $value =~ s/^\s+|\s+$//g;
17375: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 17376: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 17377: if ($field eq 'screenshot') {
17378: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
17379: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 17380: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 17381: }
17382: }
17383: }
17384: }
17385: }
17386: }
1.315 raeburn 17387: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17388: my (@statuses,%usertypeshash,@overrides);
17389: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
17390: @statuses = @{$types};
17391: if (ref($usertypes) eq 'HASH') {
17392: %usertypeshash = %{$usertypes};
17393: }
17394: }
17395: if (@statuses) {
17396: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
17397: foreach my $type (@possoverrides) {
17398: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
17399: push(@overrides,$type);
17400: }
17401: }
17402: if (@overrides) {
17403: foreach my $type (@overrides) {
17404: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
17405: foreach my $item (@contacts) {
17406: if (grep(/^\Q$item\E$/,@standard)) {
17407: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
17408: $newsetting{'override_'.$type}{$item} = 1;
17409: } else {
17410: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
17411: $newsetting{'override_'.$type}{$item} = 0;
17412: }
17413: }
17414: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
17415: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17416: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
17417: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17418: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
17419: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
17420: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
17421: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17422: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
17423: }
1.425 raeburn 17424: }
1.315 raeburn 17425: }
17426: }
1.28 raeburn 17427: if (keys(%currsetting) > 0) {
17428: foreach my $item (@contacts) {
17429: if ($to{$item} ne $currsetting{$item}) {
17430: $changes{$item} = 1;
17431: }
17432: }
17433: foreach my $type (@mailings) {
17434: foreach my $item (@contacts) {
17435: if (ref($currsetting{$type}) eq 'HASH') {
17436: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
17437: push(@{$changes{$type}},$item);
17438: }
17439: } else {
17440: push(@{$changes{$type}},@{$newsetting{$type}});
17441: }
17442: }
17443: if ($others{$type} ne $currsetting{$type}{'others'}) {
17444: push(@{$changes{$type}},'others');
17445: }
1.289 raeburn 17446: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17447: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
17448: push(@{$changes{$type}},'bcc');
17449: }
1.286 raeburn 17450: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
17451: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
17452: push(@{$changes{$type}},'include');
17453: }
17454: }
17455: }
17456: if (ref($fields) eq 'ARRAY') {
17457: if (ref($currsetting{'helpform'}) eq 'HASH') {
17458: foreach my $field (@{$fields}) {
17459: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
17460: push(@{$changes{'helpform'}},$field);
17461: }
17462: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17463: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
17464: push(@{$changes{'helpform'}},'maxsize');
17465: }
17466: }
17467: }
17468: } else {
17469: foreach my $field (@{$fields}) {
17470: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17471: push(@{$changes{'helpform'}},$field);
17472: }
17473: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17474: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17475: push(@{$changes{'helpform'}},'maxsize');
17476: }
17477: }
17478: }
1.134 raeburn 17479: }
1.28 raeburn 17480: }
1.315 raeburn 17481: if (@statuses) {
1.425 raeburn 17482: if (ref($currsetting{'overrides'}) eq 'HASH') {
1.315 raeburn 17483: foreach my $key (keys(%{$currsetting{'overrides'}})) {
17484: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
17485: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
17486: foreach my $item (@contacts,'bcc','others','include') {
1.425 raeburn 17487: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
1.315 raeburn 17488: push(@{$changes{'overrides'}},$key);
17489: last;
17490: }
17491: }
17492: } else {
17493: push(@{$changes{'overrides'}},$key);
17494: }
17495: }
17496: }
17497: foreach my $key (@overrides) {
17498: unless (exists($currsetting{'overrides'}{$key})) {
17499: push(@{$changes{'overrides'}},$key);
17500: }
17501: }
17502: } else {
17503: foreach my $key (@overrides) {
1.425 raeburn 17504: push(@{$changes{'overrides'}},$key);
1.315 raeburn 17505: }
17506: }
17507: }
1.340 raeburn 17508: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
17509: foreach my $key ('excluded','weights','threshold','sysmail') {
17510: if ($key eq 'excluded') {
17511: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17512: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
17513: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17514: (@{$currsetting{'lonstatus'}{$key}})) {
17515: my @diffs =
17516: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
17517: $currsetting{'lonstatus'}{$key});
17518: if (@diffs) {
17519: push(@{$changes{'lonstatus'}},$key);
17520: }
17521: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
17522: push(@{$changes{'lonstatus'}},$key);
17523: }
17524: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17525: (@{$currsetting{'lonstatus'}{$key}})) {
17526: push(@{$changes{'lonstatus'}},$key);
17527: }
17528: } elsif ($key eq 'weights') {
17529: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17530: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
17531: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17532: foreach my $type ('E','W','N','U') {
1.340 raeburn 17533: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
17534: $currsetting{'lonstatus'}{$key}{$type}) {
17535: push(@{$changes{'lonstatus'}},$key);
17536: last;
17537: }
17538: }
17539: } else {
1.341 raeburn 17540: foreach my $type ('E','W','N','U') {
1.340 raeburn 17541: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
17542: push(@{$changes{'lonstatus'}},$key);
17543: last;
17544: }
17545: }
17546: }
17547: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17548: foreach my $type ('E','W','N','U') {
1.340 raeburn 17549: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
17550: push(@{$changes{'lonstatus'}},$key);
17551: last;
17552: }
17553: }
17554: }
17555: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
17556: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17557: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17558: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
17559: push(@{$changes{'lonstatus'}},$key);
17560: }
17561: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
17562: push(@{$changes{'lonstatus'}},$key);
17563: }
17564: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17565: push(@{$changes{'lonstatus'}},$key);
17566: }
17567: }
17568: }
17569: } else {
17570: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17571: foreach my $key ('excluded','weights','threshold','sysmail') {
17572: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17573: push(@{$changes{'lonstatus'}},$key);
17574: }
17575: }
17576: }
17577: }
1.28 raeburn 17578: } else {
17579: my %default;
17580: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
17581: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
17582: $default{'errormail'} = 'adminemail';
17583: $default{'packagesmail'} = 'adminemail';
17584: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 17585: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 17586: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 17587: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 17588: $default{'updatesmail'} = 'adminemail';
1.350 raeburn 17589: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 17590: foreach my $item (@contacts) {
17591: if ($to{$item} ne $default{$item}) {
1.286 raeburn 17592: $changes{$item} = 1;
1.203 raeburn 17593: }
1.28 raeburn 17594: }
17595: foreach my $type (@mailings) {
17596: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
17597: push(@{$changes{$type}},@{$newsetting{$type}});
17598: }
17599: if ($others{$type} ne '') {
17600: push(@{$changes{$type}},'others');
1.134 raeburn 17601: }
1.286 raeburn 17602: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17603: if ($bcc{$type} ne '') {
17604: push(@{$changes{$type}},'bcc');
17605: }
1.286 raeburn 17606: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
17607: push(@{$changes{$type}},'include');
17608: }
1.134 raeburn 17609: }
1.28 raeburn 17610: }
1.286 raeburn 17611: if (ref($fields) eq 'ARRAY') {
17612: foreach my $field (@{$fields}) {
17613: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17614: push(@{$changes{'helpform'}},$field);
17615: }
17616: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17617: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17618: push(@{$changes{'helpform'}},'maxsize');
17619: }
17620: }
17621: }
1.289 raeburn 17622: }
1.340 raeburn 17623: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17624: foreach my $key ('excluded','weights','threshold','sysmail') {
17625: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17626: push(@{$changes{'lonstatus'}},$key);
17627: }
17628: }
17629: }
1.28 raeburn 17630: }
1.203 raeburn 17631: foreach my $item (@toggles) {
17632: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
17633: $changes{$item} = 1;
17634: } elsif ((!$env{'form.'.$item}) &&
17635: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
17636: $changes{$item} = 1;
17637: }
17638: }
1.28 raeburn 17639: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
17640: $dom);
17641: if ($putresult eq 'ok') {
17642: if (keys(%changes) > 0) {
1.205 raeburn 17643: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 17644: if (ref($lastactref) eq 'HASH') {
17645: $lastactref->{'domainconfig'} = 1;
17646: }
1.28 raeburn 17647: my ($titles,$short_titles) = &contact_titles();
17648: $resulttext = &mt('Changes made:').'<ul>';
17649: foreach my $item (@contacts) {
17650: if ($changes{$item}) {
17651: $resulttext .= '<li>'.$titles->{$item}.
17652: &mt(' set to: ').
17653: '<span class="LC_cusr_emph">'.
17654: $to{$item}.'</span></li>';
17655: }
17656: }
17657: foreach my $type (@mailings) {
17658: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 17659: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 17660: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 17661: } else {
17662: $resulttext .= '<li>'.$titles->{$type}.': ';
17663: }
1.28 raeburn 17664: my @text;
17665: foreach my $item (@{$newsetting{$type}}) {
17666: push(@text,$short_titles->{$item});
17667: }
17668: if ($others{$type} ne '') {
17669: push(@text,$others{$type});
17670: }
1.286 raeburn 17671: if (@text) {
17672: $resulttext .= '<span class="LC_cusr_emph">'.
17673: join(', ',@text).'</span>';
17674: }
17675: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17676: if ($bcc{$type} ne '') {
1.286 raeburn 17677: my $bcctext;
17678: if (@text) {
1.289 raeburn 17679: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 17680: } else {
17681: $bcctext = '(Bcc)';
17682: }
17683: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
17684: } elsif (!@text) {
17685: $resulttext .= &mt('No one');
1.425 raeburn 17686: }
1.289 raeburn 17687: if ($includestr{$type} ne '') {
1.286 raeburn 17688: if ($includeloc{$type} eq 'b') {
17689: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
17690: } elsif ($includeloc{$type} eq 's') {
17691: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
17692: }
1.134 raeburn 17693: }
1.286 raeburn 17694: } elsif (!@text) {
17695: $resulttext .= &mt('No recipients');
1.134 raeburn 17696: }
17697: $resulttext .= '</li>';
1.28 raeburn 17698: }
17699: }
1.315 raeburn 17700: if (ref($changes{'overrides'}) eq 'ARRAY') {
17701: my @deletions;
17702: foreach my $type (@{$changes{'overrides'}}) {
17703: if ($usertypeshash{$type}) {
17704: if (grep(/^\Q$type\E/,@overrides)) {
17705: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
17706: $usertypeshash{$type}).'<ul><li>';
17707: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
17708: my @text;
17709: foreach my $item (@contacts) {
1.425 raeburn 17710: if ($newsetting{'override_'.$type}{$item}) {
1.315 raeburn 17711: push(@text,$short_titles->{$item});
17712: }
17713: }
17714: if ($newsetting{'override_'.$type}{'others'} ne '') {
17715: push(@text,$newsetting{'override_'.$type}{'others'});
17716: }
1.425 raeburn 17717:
1.315 raeburn 17718: if (@text) {
17719: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
17720: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
17721: }
17722: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
17723: my $bcctext;
17724: if (@text) {
17725: $bcctext = ' '.&mt('with Bcc to');
17726: } else {
17727: $bcctext = '(Bcc)';
17728: }
17729: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
17730: } elsif (!@text) {
17731: $resulttext .= &mt('Helpdesk e-mail sent to no one');
17732: }
17733: $resulttext .= '</li>';
17734: if ($newsetting{'override_'.$type}{'include'} ne '') {
17735: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
17736: if ($loc eq 'b') {
17737: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
17738: } elsif ($loc eq 's') {
17739: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
17740: }
17741: }
17742: }
17743: $resulttext .= '</li></ul></li>';
17744: } else {
17745: push(@deletions,$usertypeshash{$type});
17746: }
17747: }
17748: }
17749: if (@deletions) {
17750: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
17751: join(', ',@deletions)).'</li>';
17752: }
17753: }
1.203 raeburn 17754: my @offon = ('off','on');
1.340 raeburn 17755: my $corelink = &core_link_msu();
1.203 raeburn 17756: if ($changes{'reporterrors'}) {
17757: $resulttext .= '<li>'.
17758: &mt('E-mail error reports to [_1] set to "'.
17759: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 17760: $corelink).
1.203 raeburn 17761: '</li>';
17762: }
17763: if ($changes{'reportupdates'}) {
17764: $resulttext .= '<li>'.
17765: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
17766: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 17767: $corelink).
1.203 raeburn 17768: '</li>';
17769: }
1.340 raeburn 17770: if ($changes{'reportstatus'}) {
17771: $resulttext .= '<li>'.
17772: &mt('E-mail status if errors above threshold to [_1] set to "'.
17773: $offon[$env{'form.reportstatus'}].'".',
17774: $corelink).
17775: '</li>';
17776: }
17777: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
17778: $resulttext .= '<li>'.
17779: &mt('Nightly status check e-mail settings').':<ul>';
17780: my (%defval,%use_def,%shown);
17781: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
17782: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
17783: $defval{'weights'} =
1.341 raeburn 17784: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 17785: $defval{'excluded'} = &mt('None');
17786: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
17787: foreach my $item ('threshold','sysmail','weights','excluded') {
17788: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
17789: if (($item eq 'threshold') || ($item eq 'sysmail')) {
17790: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
17791: } elsif ($item eq 'weights') {
17792: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 17793: foreach my $type ('E','W','N','U') {
1.340 raeburn 17794: $shown{$item} .= $lonstatus_names->{$type}.'=';
17795: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
17796: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
17797: } else {
17798: $shown{$item} .= $lonstatus_defs->{$type};
17799: }
17800: $shown{$item} .= ', ';
17801: }
17802: $shown{$item} =~ s/, $//;
17803: } else {
17804: $shown{$item} = $defval{$item};
17805: }
17806: } elsif ($item eq 'excluded') {
17807: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
17808: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
17809: } else {
17810: $shown{$item} = $defval{$item};
17811: }
17812: }
17813: } else {
17814: $shown{$item} = $defval{$item};
17815: }
17816: }
17817: } else {
17818: foreach my $item ('threshold','weights','excluded','sysmail') {
17819: $shown{$item} = $defval{$item};
17820: }
17821: }
17822: foreach my $item ('threshold','weights','excluded','sysmail') {
17823: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
17824: $shown{$item}).'</li>';
17825: }
17826: $resulttext .= '</ul></li>';
17827: }
1.286 raeburn 17828: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
17829: my (@optional,@required,@unused,$maxsizechg);
17830: foreach my $field (@{$changes{'helpform'}}) {
17831: if ($field eq 'maxsize') {
17832: $maxsizechg = 1;
17833: next;
17834: }
17835: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 17836: push(@optional,$field);
1.286 raeburn 17837: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
17838: push(@unused,$field);
17839: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 17840: push(@required,$field);
1.286 raeburn 17841: }
17842: }
17843: if (@optional) {
17844: $resulttext .= '<li>'.
17845: &mt('Help form fields changed to "Optional": [_1].',
17846: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
17847: '</li>';
17848: }
17849: if (@required) {
17850: $resulttext .= '<li>'.
17851: &mt('Help form fields changed to "Required": [_1].',
17852: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
17853: '</li>';
17854: }
17855: if (@unused) {
17856: $resulttext .= '<li>'.
17857: &mt('Help form fields changed to "Not shown": [_1].',
17858: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
17859: '</li>';
17860: }
17861: if ($maxsizechg) {
17862: $resulttext .= '<li>'.
17863: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
17864: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
17865: '</li>';
17866: }
17867: }
1.28 raeburn 17868: $resulttext .= '</ul>';
17869: } else {
1.288 raeburn 17870: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 17871: }
17872: } else {
17873: $resulttext = '<span class="LC_error">'.
17874: &mt('An error occurred: [_1].',$putresult).'</span>';
17875: }
17876: return $resulttext;
17877: }
17878:
1.357 raeburn 17879: sub modify_privacy {
1.427 raeburn 17880: my ($dom,$lastactref,%domconfig) = @_;
1.357 raeburn 17881: my ($resulttext,%current,%changes);
17882: if (ref($domconfig{'privacy'}) eq 'HASH') {
17883: %current = %{$domconfig{'privacy'}};
17884: }
17885: my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
17886: my @items = ('domain','author','course','community');
17887: my %names = &Apache::lonlocal::texthash (
17888: domain => 'Assigned domain role(s)',
17889: author => 'Assigned co-author role(s)',
17890: course => 'Assigned course role(s)',
1.416 raeburn 17891: community => 'Assigned community role(s)',
1.357 raeburn 17892: );
17893: my %roles = &Apache::lonlocal::texthash (
17894: domain => 'Domain role',
17895: author => 'Co-author role',
17896: course => 'Course role',
17897: community => 'Community role',
17898: );
17899: my %titles = &Apache::lonlocal::texthash (
17900: approval => 'Approval for role in different domain',
17901: othdom => 'User information available in other domain',
17902: priv => 'Information viewable by privileged user in same domain',
17903: unpriv => 'Information viewable by unprivileged user in same domain',
17904: instdom => 'Other domain shares institution/provider',
17905: extdom => 'Other domain has different institution/provider',
17906: none => 'Not allowed',
17907: user => 'User authorizes',
17908: domain => 'Domain Coordinator authorizes',
17909: auto => 'Unrestricted',
1.418 raeburn 17910: notify => 'Notify when role needs authorization',
1.357 raeburn 17911: );
17912: my %fieldnames = &Apache::lonlocal::texthash (
17913: id => 'Student/Employee ID',
17914: permanentemail => 'E-mail address',
17915: lastname => 'Last Name',
17916: firstname => 'First Name',
17917: middlename => 'Middle Name',
17918: generation => 'Generation',
17919: );
17920: my ($othertitle,$usertypes,$types) =
17921: &Apache::loncommon::sorted_inst_types($dom);
17922: my (%by_ip,%by_location,@intdoms,@instdoms);
17923: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
17924:
17925: my %privacyhash = (
17926: 'approval' => {
17927: instdom => {},
17928: extdom => {},
17929: },
17930: 'othdom' => {},
17931: 'priv' => {},
17932: 'unpriv' => {},
17933: );
17934: foreach my $item (@items) {
17935: if (@instdoms > 1) {
1.416 raeburn 17936: if ($env{'form.privacy_approval_instdom_'.$item} =~ /^(none|user|domain|auto)$/) {
1.357 raeburn 17937: $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
17938: }
17939: if (ref($current{'approval'}) eq 'HASH') {
17940: if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
17941: unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
17942: $changes{'approval'} = 1;
17943: }
17944: }
17945: } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
17946: $changes{'approval'} = 1;
17947: }
17948: }
17949: if (keys(%by_location) > 0) {
17950: if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
17951: $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
17952: }
17953: if (ref($current{'approval'}) eq 'HASH') {
17954: if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
17955: unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
17956: $changes{'approval'} = 1;
17957: }
17958: }
17959: } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
17960: $changes{'approval'} = 1;
17961: }
17962: }
17963: foreach my $status ('priv','unpriv') {
17964: my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
17965: my @newvalues;
17966: foreach my $field (@possibles) {
17967: if (grep(/^\Q$field\E$/,@fields)) {
17968: $privacyhash{$status}{$item}{$field} = 1;
17969: push(@newvalues,$field);
17970: }
17971: }
17972: @newvalues = sort(@newvalues);
17973: if (ref($current{$status}) eq 'HASH') {
17974: if (ref($current{$status}{$item}) eq 'HASH') {
17975: my @currvalues = sort(keys(%{$current{$status}{$item}}));
17976: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
17977: if (@diffs > 0) {
17978: $changes{$status} = 1;
17979: }
17980: }
17981: } else {
17982: my @stdfields;
17983: foreach my $field (@fields) {
17984: if ($field eq 'id') {
17985: next if ($status eq 'unpriv');
17986: next if (($status eq 'priv') && ($item eq 'community'));
17987: }
17988: push(@stdfields,$field);
17989: }
17990: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
17991: if (@diffs > 0) {
17992: $changes{$status} = 1;
17993: }
17994: }
17995: }
17996: }
17997: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
17998: my @statuses;
17999: if (ref($types) eq 'ARRAY') {
18000: @statuses = @{$types};
18001: }
18002: foreach my $type (@statuses,'default') {
18003: my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
18004: my @newvalues;
18005: foreach my $field (sort(@possfields)) {
18006: if (grep(/^\Q$field\E$/,@fields)) {
18007: $privacyhash{'othdom'}{$type}{$field} = 1;
18008: push(@newvalues,$field);
18009: }
18010: }
18011: @newvalues = sort(@newvalues);
18012: if (ref($current{'othdom'}) eq 'HASH') {
18013: if (ref($current{'othdom'}{$type}) eq 'HASH') {
18014: my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
18015: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
18016: if (@diffs > 0) {
18017: $changes{'othdom'} = 1;
18018: }
18019: }
18020: } else {
18021: my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
18022: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
18023: if (@diffs > 0) {
18024: $changes{'othdom'} = 1;
18025: }
18026: }
18027: }
1.417 raeburn 18028: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
18029: my %notify;
18030: foreach my $possdc (&Apache::loncommon::get_env_multiple('form.privacy_notify')) {
18031: if (exists($domcoords{$possdc})) {
18032: $notify{$possdc} = 1;
18033: }
18034: }
18035: my $notify = join(',',sort(keys(%notify)));
18036: if ($current{'notify'} ne $notify) {
18037: $changes{'notify'} = 1;
18038: }
18039: $privacyhash{'notify'} = $notify;
1.357 raeburn 18040: }
18041: my %confighash = (
18042: privacy => \%privacyhash,
18043: );
18044: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
18045: if ($putresult eq 'ok') {
18046: if (keys(%changes) > 0) {
18047: $resulttext = &mt('Changes made: ').'<ul>';
1.417 raeburn 18048: foreach my $key ('approval','notify','othdom','priv','unpriv') {
1.357 raeburn 18049: if ($changes{$key}) {
18050: $resulttext .= '<li>'.$titles{$key}.':<ul>';
18051: if ($key eq 'approval') {
18052: if (keys(%{$privacyhash{$key}{instdom}})) {
18053: $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
18054: foreach my $item (@items) {
18055: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
18056: }
18057: $resulttext .= '</ul></li>';
18058: }
18059: if (keys(%{$privacyhash{$key}{extdom}})) {
18060: $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
18061: foreach my $item (@items) {
18062: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
18063: }
18064: $resulttext .= '</ul></li>';
18065: }
1.417 raeburn 18066: } elsif ($key eq 'notify') {
18067: if ($privacyhash{$key}) {
18068: foreach my $dc (split(/,/,$privacyhash{$key})) {
18069: my ($dcname,$dcdom) = split(/:/,$dc);
18070: $resulttext .= '<li>'.&Apache::loncommon::plainname($dcname,$dcdom).'</li>';
18071: }
18072: } else {
18073: $resulttext .= '<li>'.&mt('No DCs to notify').'</li>';
18074: }
1.357 raeburn 18075: } elsif ($key eq 'othdom') {
18076: my @statuses;
18077: if (ref($types) eq 'ARRAY') {
18078: @statuses = @{$types};
18079: }
18080: if (ref($privacyhash{$key}) eq 'HASH') {
18081: foreach my $status (@statuses,'default') {
18082: if ($status eq 'default') {
18083: $resulttext .= '<li>'.$othertitle.': ';
18084: } elsif (ref($usertypes) eq 'HASH') {
18085: $resulttext .= '<li>'.$usertypes->{$status}.': ';
18086: } else {
18087: next;
18088: }
18089: if (ref($privacyhash{$key}{$status}) eq 'HASH') {
18090: if (keys(%{$privacyhash{$key}{$status}})) {
18091: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
18092: } else {
18093: $resulttext .= &mt('none');
18094: }
18095: }
18096: $resulttext .= '</li>';
18097: }
18098: }
18099: } else {
18100: foreach my $item (@items) {
18101: if (ref($privacyhash{$key}{$item}) eq 'HASH') {
18102: $resulttext .= '<li>'.$names{$item}.': ';
18103: if (keys(%{$privacyhash{$key}{$item}})) {
18104: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
18105: } else {
18106: $resulttext .= &mt('none');
18107: }
18108: $resulttext .= '</li>';
18109: }
18110: }
18111: }
18112: $resulttext .= '</ul></li>';
18113: }
18114: }
1.421 raeburn 18115: $resulttext .= '</ul>';
1.427 raeburn 18116: if ($changes{'approval'}) {
18117: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
18118: delete($domdefaults{'userapprovals'});
18119: if (ref($privacyhash{'approval'}) eq 'HASH') {
18120: foreach my $domtype ('instdom','extdom') {
18121: if (ref($privacyhash{'approval'}{$domtype}) eq 'HASH') {
18122: foreach my $roletype ('domain','author','course','community') {
18123: if ($privacyhash{'approval'}{$domtype}{$roletype} eq 'user') {
18124: $domdefaults{'userapprovals'} = 1;
18125: last;
18126: }
18127: }
18128: }
18129: last if ($domdefaults{'userapprovals'});
18130: }
18131: }
18132: my $cachetime = 24*60*60;
18133: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18134: if (ref($lastactref) eq 'HASH') {
18135: $lastactref->{'domdefaults'} = 1;
18136: }
18137: }
1.357 raeburn 18138: } else {
18139: $resulttext = &mt('No changes made to user information settings');
18140: }
18141: } else {
18142: $resulttext = '<span class="LC_error">'.
18143: &mt('An error occurred: [_1]',$putresult).'</span>';
18144: }
18145: return $resulttext;
18146: }
18147:
1.354 raeburn 18148: sub modify_passwords {
18149: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 raeburn 18150: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
18151: $updatedefaults,$updateconf);
1.354 raeburn 18152: my $customfn = 'resetpw.html';
18153: if (ref($domconfig{'passwords'}) eq 'HASH') {
18154: %current = %{$domconfig{'passwords'}};
18155: }
18156: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
18157: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
18158: if (ref($types) eq 'ARRAY') {
18159: @oktypes = @{$types};
18160: }
18161: push(@oktypes,'default');
18162:
18163: my %titles = &Apache::lonlocal::texthash (
18164: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
18165: intauth_check => 'Check bcrypt cost if authenticated',
18166: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
18167: permanent => 'Permanent e-mail address',
18168: critical => 'Critical notification address',
18169: notify => 'Notification address',
18170: min => 'Minimum password length',
18171: max => 'Maximum password length',
18172: chars => 'Required characters',
18173: expire => 'Password expiration (days)',
1.356 raeburn 18174: numsaved => 'Number of previous passwords to save',
1.354 raeburn 18175: reset => 'Resetting Forgotten Password',
18176: intauth => 'Encryption of Stored Passwords (Internal Auth)',
18177: rules => 'Rules for LON-CAPA Passwords',
18178: crsownerchg => 'Course Owner Changing Student Passwords',
18179: username => 'Username',
18180: email => 'E-mail address',
18181: );
18182:
18183: #
18184: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
18185: #
18186: my (%curr_defaults,%save_defaults);
18187: if (ref($domconfig{'defaults'}) eq 'HASH') {
18188: foreach my $key (keys(%{$domconfig{'defaults'}})) {
18189: if ($key =~ /^intauth_(cost|check|switch)$/) {
18190: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
18191: } else {
18192: $save_defaults{$key} = $domconfig{'defaults'}{$key};
18193: }
18194: }
18195: }
18196: my %staticdefaults = (
18197: 'resetlink' => 2,
18198: 'resetcase' => \@oktypes,
18199: 'resetprelink' => 'both',
18200: 'resetemail' => ['critical','notify','permanent'],
18201: 'intauth_cost' => 10,
18202: 'intauth_check' => 0,
18203: 'intauth_switch' => 0,
18204: );
1.365 raeburn 18205: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354 raeburn 18206: foreach my $type (@oktypes) {
18207: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
18208: }
18209: my $linklife = $env{'form.passwords_link'};
18210: $linklife =~ s/^\s+|\s+$//g;
18211: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
18212: $newvalues{'resetlink'} = $linklife;
18213: if ($current{'resetlink'}) {
18214: if ($current{'resetlink'} ne $linklife) {
18215: $changes{'reset'} = 1;
18216: }
1.368 raeburn 18217: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18218: if ($staticdefaults{'resetlink'} ne $linklife) {
18219: $changes{'reset'} = 1;
18220: }
18221: }
18222: } elsif ($current{'resetlink'}) {
18223: $changes{'reset'} = 1;
18224: }
18225: my @casesens;
18226: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
18227: foreach my $case (sort(@posscase)) {
18228: if (grep(/^\Q$case\E$/,@oktypes)) {
18229: push(@casesens,$case);
18230: }
18231: }
18232: $newvalues{'resetcase'} = \@casesens;
18233: if (ref($current{'resetcase'}) eq 'ARRAY') {
18234: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
18235: if (@diffs > 0) {
18236: $changes{'reset'} = 1;
18237: }
1.368 raeburn 18238: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18239: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
18240: if (@diffs > 0) {
18241: $changes{'reset'} = 1;
18242: }
18243: }
18244: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
18245: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
18246: if (exists($current{'resetprelink'})) {
18247: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
18248: $changes{'reset'} = 1;
18249: }
1.368 raeburn 18250: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18251: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
18252: $changes{'reset'} = 1;
18253: }
18254: }
18255: } elsif ($current{'resetprelink'}) {
18256: $changes{'reset'} = 1;
18257: }
18258: foreach my $type (@oktypes) {
18259: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
18260: my @postlink;
18261: foreach my $item (sort(@possplink)) {
18262: if ($item =~ /^(email|username)$/) {
18263: push(@postlink,$item);
18264: }
18265: }
18266: $newvalues{'resetpostlink'}{$type} = \@postlink;
18267: unless ($changes{'reset'}) {
18268: if (ref($current{'resetpostlink'}) eq 'HASH') {
18269: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
18270: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
18271: if (@diffs > 0) {
18272: $changes{'reset'} = 1;
18273: }
18274: } else {
18275: $changes{'reset'} = 1;
18276: }
1.368 raeburn 18277: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18278: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
18279: if (@diffs > 0) {
18280: $changes{'reset'} = 1;
18281: }
18282: }
18283: }
18284: }
18285: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
18286: my @resetemail;
18287: foreach my $item (sort(@possemailsrc)) {
18288: if ($item =~ /^(permanent|critical|notify)$/) {
18289: push(@resetemail,$item);
18290: }
18291: }
18292: $newvalues{'resetemail'} = \@resetemail;
18293: unless ($changes{'reset'}) {
18294: if (ref($current{'resetemail'}) eq 'ARRAY') {
18295: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
18296: if (@diffs > 0) {
18297: $changes{'reset'} = 1;
18298: }
1.368 raeburn 18299: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18300: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
18301: if (@diffs > 0) {
18302: $changes{'reset'} = 1;
18303: }
18304: }
18305: }
18306: if ($env{'form.passwords_stdtext'} == 0) {
18307: $newvalues{'resetremove'} = 1;
18308: unless ($current{'resetremove'}) {
18309: $changes{'reset'} = 1;
18310: }
18311: } elsif ($current{'resetremove'}) {
18312: $changes{'reset'} = 1;
18313: }
18314: if ($env{'form.passwords_customfile.filename'} ne '') {
18315: my $servadm = $r->dir_config('lonAdmEMail');
18316: my ($configuserok,$author_ok,$switchserver) =
18317: &config_check($dom,$confname,$servadm);
18318: my $error;
18319: if ($configuserok eq 'ok') {
18320: if ($switchserver) {
18321: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
18322: } else {
18323: if ($author_ok eq 'ok') {
1.421 raeburn 18324: my $modified = [];
1.354 raeburn 18325: my ($result,$customurl) =
1.421 raeburn 18326: &Apache::lonconfigsettings::publishlogo($r,'upload','passwords_customfile',$dom,
18327: $confname,'customtext/resetpw','','',$customfn,
18328: $modified);
1.354 raeburn 18329: if ($result eq 'ok') {
18330: $newvalues{'resetcustom'} = $customurl;
18331: $changes{'reset'} = 1;
1.421 raeburn 18332: &update_modify_urls($r,$modified);
1.354 raeburn 18333: } else {
18334: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
18335: }
18336: } else {
18337: $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);
18338: }
18339: }
18340: } else {
18341: $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);
18342: }
18343: if ($error) {
18344: &Apache::lonnet::logthis($error);
18345: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
18346: }
18347: } elsif ($current{'resetcustom'}) {
18348: if ($env{'form.passwords_custom_del'}) {
18349: $changes{'reset'} = 1;
18350: } else {
18351: $newvalues{'resetcustom'} = $current{'resetcustom'};
18352: }
18353: }
18354: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
18355: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
18356: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
18357: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
18358: $changes{'intauth'} = 1;
18359: }
18360: } else {
18361: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
18362: }
18363: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
18364: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
18365: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
18366: $changes{'intauth'} = 1;
18367: }
18368: } else {
18369: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18370: }
18371: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
18372: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
18373: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
18374: $changes{'intauth'} = 1;
18375: }
18376: } else {
18377: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18378: }
18379: foreach my $item ('cost','check','switch') {
18380: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
18381: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
18382: $updatedefaults = 1;
18383: }
18384: }
1.405 raeburn 18385: &password_rule_changes('passwords',\%newvalues,\%current,\%changes);
1.359 raeburn 18386: my %crsownerchg = (
18387: by => [],
18388: for => [],
18389: );
18390: foreach my $item ('by','for') {
18391: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
18392: foreach my $type (sort(@posstypes)) {
18393: if (grep(/^\Q$type\E$/,@oktypes)) {
18394: push(@{$crsownerchg{$item}},$type);
18395: }
18396: }
18397: }
18398: $newvalues{'crsownerchg'} = \%crsownerchg;
18399: if (ref($current{'crsownerchg'}) eq 'HASH') {
18400: foreach my $item ('by','for') {
18401: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
18402: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
18403: if (@diffs > 0) {
18404: $changes{'crsownerchg'} = 1;
18405: last;
18406: }
18407: }
18408: }
1.368 raeburn 18409: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359 raeburn 18410: foreach my $item ('by','for') {
18411: if (@{$crsownerchg{$item}} > 0) {
18412: $changes{'crsownerchg'} = 1;
18413: last;
18414: }
1.354 raeburn 18415: }
18416: }
18417:
18418: my %confighash = (
18419: defaults => \%save_defaults,
18420: passwords => \%newvalues,
18421: );
18422: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
18423:
18424: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
18425: if ($putresult eq 'ok') {
18426: if (keys(%changes) > 0) {
18427: $resulttext = &mt('Changes made: ').'<ul>';
18428: foreach my $key ('reset','intauth','rules','crsownerchg') {
18429: if ($changes{$key}) {
1.355 raeburn 18430: unless ($key eq 'intauth') {
18431: $updateconf = 1;
18432: }
1.354 raeburn 18433: $resulttext .= '<li>'.$titles{$key}.':<ul>';
18434: if ($key eq 'reset') {
18435: if ($confighash{'passwords'}{'captcha'} eq 'original') {
18436: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
18437: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
18438: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369 raeburn 18439: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
18440: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
18441: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
18442: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
18443: }
1.354 raeburn 18444: } else {
18445: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
18446: }
18447: if ($confighash{'passwords'}{'resetlink'}) {
18448: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
18449: } else {
18450: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
18451: &mt('Will default to 2 hours').'</li>';
18452: }
18453: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
18454: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
18455: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
18456: } else {
18457: my $casesens;
18458: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
18459: if ($type eq 'default') {
18460: $casesens .= $othertitle.', ';
18461: } elsif ($usertypes->{$type} ne '') {
18462: $casesens .= $usertypes->{$type}.', ';
18463: }
18464: }
18465: $casesens =~ s/\Q, \E$//;
18466: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
18467: }
18468: } else {
18469: $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>';
18470: }
18471: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
18472: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
18473: } else {
18474: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
18475: }
18476: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
18477: my $output;
18478: if (ref($types) eq 'ARRAY') {
18479: foreach my $type (@{$types}) {
18480: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
18481: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
18482: $output .= $usertypes->{$type}.' -- '.&mt('none');
18483: } else {
18484: $output .= $usertypes->{$type}.' -- '.
18485: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
18486: }
18487: }
18488: }
18489: }
18490: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
18491: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
18492: $output .= $othertitle.' -- '.&mt('none');
18493: } else {
18494: $output .= $othertitle.' -- '.
18495: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
18496: }
18497: }
18498: if ($output) {
18499: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
18500: } else {
18501: $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>';
18502: }
18503: } else {
18504: $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>';
18505: }
18506: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
18507: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
18508: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
18509: } else {
18510: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
18511: }
18512: } else {
1.379 raeburn 18513: $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 18514: }
18515: if ($confighash{'passwords'}{'resetremove'}) {
18516: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
18517: } else {
18518: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
18519: }
18520: if ($confighash{'passwords'}{'resetcustom'}) {
18521: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369 raeburn 18522: &mt('custom text'),600,500,undef,undef,
18523: undef,undef,'background-color:#ffffff');
18524: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354 raeburn 18525: } else {
18526: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
18527: }
18528: } elsif ($key eq 'intauth') {
18529: foreach my $item ('cost','switch','check') {
18530: my $value = $save_defaults{$key.'_'.$item};
18531: if ($item eq 'switch') {
18532: my %optiondesc = &Apache::lonlocal::texthash (
18533: 0 => 'No',
18534: 1 => 'Yes',
18535: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
18536: );
18537: if ($value =~ /^(0|1|2)$/) {
18538: $value = $optiondesc{$value};
18539: } else {
18540: $value = &mt('none -- defaults to No');
18541: }
18542: } elsif ($item eq 'check') {
18543: my %optiondesc = &Apache::lonlocal::texthash (
18544: 0 => 'No',
18545: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
18546: 2 => 'Yes, disallow login if stored cost is less than domain default',
18547: );
18548: if ($value =~ /^(0|1|2)$/) {
18549: $value = $optiondesc{$value};
18550: } else {
18551: $value = &mt('none -- defaults to No');
18552: }
18553: }
18554: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
18555: }
18556: } elsif ($key eq 'rules') {
1.356 raeburn 18557: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 18558: if ($confighash{'passwords'}{$rule} eq '') {
18559: if ($rule eq 'min') {
1.356 raeburn 18560: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365 raeburn 18561: ' '.&mt('Default of [_1] will be used',
18562: $Apache::lonnet::passwdmin).'</li>';
1.356 raeburn 18563: } else {
18564: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354 raeburn 18565: }
18566: } else {
18567: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
18568: }
18569: }
1.370 raeburn 18570: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
18571: if (@{$confighash{'passwords'}{'chars'}} > 0) {
18572: my %rulenames = &Apache::lonlocal::texthash(
18573: uc => 'At least one upper case letter',
18574: lc => 'At least one lower case letter',
18575: num => 'At least one number',
18576: spec => 'At least one non-alphanumeric',
18577: );
18578: my $needed = '<ul><li>'.
18579: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
1.425 raeburn 18580: '</li></ul>';
1.370 raeburn 18581: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
18582: } else {
18583: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18584: }
18585: } else {
18586: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18587: }
1.354 raeburn 18588: } elsif ($key eq 'crsownerchg') {
1.359 raeburn 18589: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
18590: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
18591: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
18592: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
18593: } else {
18594: my %crsownerstr;
18595: foreach my $item ('by','for') {
18596: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
18597: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
18598: if ($type eq 'default') {
18599: $crsownerstr{$item} .= $othertitle.', ';
18600: } elsif ($usertypes->{$type} ne '') {
18601: $crsownerstr{$item} .= $usertypes->{$type}.', ';
18602: }
18603: }
18604: $crsownerstr{$item} =~ s/\Q, \E$//;
18605: }
18606: }
18607: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
18608: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
18609: }
1.354 raeburn 18610: } else {
1.359 raeburn 18611: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354 raeburn 18612: }
18613: }
18614: $resulttext .= '</ul></li>';
18615: }
18616: }
18617: $resulttext .= '</ul>';
18618: } else {
18619: $resulttext = &mt('No changes made to password settings');
18620: }
1.355 raeburn 18621: my $cachetime = 24*60*60;
1.354 raeburn 18622: if ($updatedefaults) {
18623: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18624: if (ref($lastactref) eq 'HASH') {
18625: $lastactref->{'domdefaults'} = 1;
18626: }
18627: }
1.355 raeburn 18628: if ($updateconf) {
18629: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
18630: if (ref($lastactref) eq 'HASH') {
18631: $lastactref->{'passwdconf'} = 1;
18632: }
18633: }
1.354 raeburn 18634: } else {
18635: $resulttext = '<span class="LC_error">'.
18636: &mt('An error occurred: [_1]',$putresult).'</span>';
18637: }
18638: if ($errors) {
18639: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
18640: $errors.'</ul></p>';
18641: }
18642: return $resulttext;
18643: }
18644:
1.405 raeburn 18645: sub password_rule_changes {
18646: my ($prefix,$newvalues,$current,$changes) = @_;
18647: return unless ((ref($newvalues) eq 'HASH') &&
18648: (ref($current) eq 'HASH') &&
18649: (ref($changes) eq 'HASH'));
18650: my (@rules,%staticdefaults);
18651: if ($prefix eq 'passwords') {
18652: @rules = ('min','max','expire','numsaved');
1.421 raeburn 18653: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 18654: @rules = ('min','max');
18655: }
18656: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
18657: foreach my $rule (@rules) {
18658: $env{'form.'.$prefix.'_'.$rule} =~ s/^\s+|\s+$//g;
18659: my $ruleok;
18660: if ($rule eq 'expire') {
18661: if (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+(|\.\d*)$/) &&
18662: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18663: $ruleok = 1;
18664: }
18665: } elsif ($rule eq 'min') {
18666: if ($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) {
18667: if ($env{'form.'.$prefix.'_'.$rule} >= $staticdefaults{$rule}) {
18668: $ruleok = 1;
18669: }
18670: }
18671: } elsif (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) &&
18672: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18673: $ruleok = 1;
18674: }
18675: if ($ruleok) {
18676: $newvalues->{$rule} = $env{'form.'.$prefix.'_'.$rule};
18677: if (exists($current->{$rule})) {
18678: if ($newvalues->{$rule} ne $current->{$rule}) {
18679: $changes->{'rules'} = 1;
18680: }
18681: } elsif ($rule eq 'min') {
18682: if ($staticdefaults{$rule} ne $newvalues->{$rule}) {
18683: $changes->{'rules'} = 1;
18684: }
18685: } else {
18686: $changes->{'rules'} = 1;
18687: }
18688: } elsif (exists($current->{$rule})) {
18689: $changes->{'rules'} = 1;
18690: }
18691: }
18692: my @posschars = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_chars');
18693: my @chars;
18694: foreach my $item (sort(@posschars)) {
18695: if ($item =~ /^(uc|lc|num|spec)$/) {
18696: push(@chars,$item);
18697: }
18698: }
18699: $newvalues->{'chars'} = \@chars;
18700: unless ($changes->{'rules'}) {
18701: if (ref($current->{'chars'}) eq 'ARRAY') {
18702: my @diffs = &Apache::loncommon::compare_arrays($current->{'chars'},\@chars);
18703: if (@diffs > 0) {
18704: $changes->{'rules'} = 1;
18705: }
18706: } else {
18707: if (@chars > 0) {
18708: $changes->{'rules'} = 1;
18709: }
18710: }
18711: }
18712: return;
18713: }
18714:
1.28 raeburn 18715: sub modify_usercreation {
1.27 raeburn 18716: my ($dom,%domconfig) = @_;
1.224 raeburn 18717: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 18718: my $warningmsg;
1.27 raeburn 18719: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18720: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 18721: if ($key eq 'cancreate') {
18722: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18723: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 18724: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
18725: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18726: } else {
1.224 raeburn 18727: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18728: }
18729: }
18730: }
18731: } elsif ($key eq 'email_rule') {
18732: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18733: } else {
18734: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18735: }
1.27 raeburn 18736: }
18737: }
18738: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 18739: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 18740: my @contexts = ('author','course','requestcrs');
1.34 raeburn 18741: foreach my $item(@contexts) {
1.224 raeburn 18742: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 18743: }
1.34 raeburn 18744: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
18745: foreach my $item (@contexts) {
1.224 raeburn 18746: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
18747: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 18748: }
1.27 raeburn 18749: }
1.34 raeburn 18750: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
18751: foreach my $item (@contexts) {
1.43 raeburn 18752: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 18753: if ($cancreate{$item} ne 'any') {
18754: push(@{$changes{'cancreate'}},$item);
18755: }
18756: } else {
18757: if ($cancreate{$item} ne 'none') {
18758: push(@{$changes{'cancreate'}},$item);
18759: }
1.27 raeburn 18760: }
18761: }
18762: } else {
1.43 raeburn 18763: foreach my $item (@contexts) {
1.34 raeburn 18764: push(@{$changes{'cancreate'}},$item);
18765: }
1.27 raeburn 18766: }
1.34 raeburn 18767:
1.27 raeburn 18768: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
18769: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
18770: if (!grep(/^\Q$type\E$/,@username_rule)) {
18771: push(@{$changes{'username_rule'}},$type);
18772: }
18773: }
18774: foreach my $type (@username_rule) {
18775: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
18776: push(@{$changes{'username_rule'}},$type);
18777: }
18778: }
18779: } else {
18780: push(@{$changes{'username_rule'}},@username_rule);
18781: }
18782:
1.32 raeburn 18783: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
18784: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
18785: if (!grep(/^\Q$type\E$/,@id_rule)) {
18786: push(@{$changes{'id_rule'}},$type);
18787: }
18788: }
18789: foreach my $type (@id_rule) {
18790: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
18791: push(@{$changes{'id_rule'}},$type);
18792: }
18793: }
18794: } else {
18795: push(@{$changes{'id_rule'}},@id_rule);
18796: }
18797:
1.43 raeburn 18798: my @authen_contexts = ('author','course','domain');
1.325 raeburn 18799: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 18800: my %authhash;
1.43 raeburn 18801: foreach my $item (@authen_contexts) {
1.28 raeburn 18802: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
18803: foreach my $auth (@authtypes) {
18804: if (grep(/^\Q$auth\E$/,@authallowed)) {
18805: $authhash{$item}{$auth} = 1;
18806: } else {
18807: $authhash{$item}{$auth} = 0;
18808: }
18809: }
18810: }
18811: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 18812: foreach my $item (@authen_contexts) {
1.28 raeburn 18813: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
18814: foreach my $auth (@authtypes) {
18815: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
18816: push(@{$changes{'authtypes'}},$item);
18817: last;
18818: }
18819: }
18820: }
18821: }
18822: } else {
1.43 raeburn 18823: foreach my $item (@authen_contexts) {
1.28 raeburn 18824: push(@{$changes{'authtypes'}},$item);
18825: }
18826: }
18827:
1.224 raeburn 18828: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
18829: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
18830: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
18831: $save_usercreate{'id_rule'} = \@id_rule;
18832: $save_usercreate{'username_rule'} = \@username_rule,
18833: $save_usercreate{'authtypes'} = \%authhash;
18834:
1.27 raeburn 18835: my %usercreation_hash = (
1.224 raeburn 18836: usercreation => \%save_usercreate,
18837: );
1.27 raeburn 18838:
18839: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
18840: $dom);
1.50 raeburn 18841:
1.224 raeburn 18842: if ($putresult eq 'ok') {
18843: if (keys(%changes) > 0) {
18844: $resulttext = &mt('Changes made:').'<ul>';
18845: if (ref($changes{'cancreate'}) eq 'ARRAY') {
18846: my %lt = &usercreation_types();
18847: foreach my $type (@{$changes{'cancreate'}}) {
18848: my $chgtext = $lt{$type}.', ';
18849: if ($cancreate{$type} eq 'none') {
18850: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
18851: } elsif ($cancreate{$type} eq 'any') {
18852: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
18853: } elsif ($cancreate{$type} eq 'official') {
18854: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
18855: } elsif ($cancreate{$type} eq 'unofficial') {
18856: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
18857: }
18858: $resulttext .= '<li>'.$chgtext.'</li>';
18859: }
18860: }
18861: if (ref($changes{'username_rule'}) eq 'ARRAY') {
18862: my ($rules,$ruleorder) =
18863: &Apache::lonnet::inst_userrules($dom,'username');
18864: my $chgtext = '<ul>';
18865: foreach my $type (@username_rule) {
18866: if (ref($rules->{$type}) eq 'HASH') {
18867: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
18868: }
18869: }
18870: $chgtext .= '</ul>';
18871: if (@username_rule > 0) {
18872: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18873: } else {
18874: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
18875: }
18876: }
18877: if (ref($changes{'id_rule'}) eq 'ARRAY') {
18878: my ($idrules,$idruleorder) =
18879: &Apache::lonnet::inst_userrules($dom,'id');
18880: my $chgtext = '<ul>';
18881: foreach my $type (@id_rule) {
18882: if (ref($idrules->{$type}) eq 'HASH') {
18883: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
18884: }
18885: }
18886: $chgtext .= '</ul>';
18887: if (@id_rule > 0) {
18888: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18889: } else {
18890: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
18891: }
18892: }
18893: my %authname = &authtype_names();
18894: my %context_title = &context_names();
18895: if (ref($changes{'authtypes'}) eq 'ARRAY') {
18896: my $chgtext = '<ul>';
18897: foreach my $type (@{$changes{'authtypes'}}) {
18898: my @allowed;
18899: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
18900: foreach my $auth (@authtypes) {
18901: if ($authhash{$type}{$auth}) {
18902: push(@allowed,$authname{$auth});
18903: }
18904: }
18905: if (@allowed > 0) {
18906: $chgtext .= join(', ',@allowed).'</li>';
18907: } else {
18908: $chgtext .= &mt('none').'</li>';
18909: }
18910: }
18911: $chgtext .= '</ul>';
18912: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
18913: $resulttext .= '</li>';
18914: }
18915: $resulttext .= '</ul>';
18916: } else {
18917: $resulttext = &mt('No changes made to user creation settings');
18918: }
18919: } else {
18920: $resulttext = '<span class="LC_error">'.
18921: &mt('An error occurred: [_1]',$putresult).'</span>';
18922: }
18923: if ($warningmsg ne '') {
18924: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
18925: }
18926: return $resulttext;
18927: }
18928:
18929: sub modify_selfcreation {
1.305 raeburn 18930: my ($dom,$lastactref,%domconfig) = @_;
18931: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
18932: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
18933: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 18934: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
18935: if (ref($typesref) eq 'ARRAY') {
18936: @types = @{$typesref};
18937: }
18938: if (ref($usertypesref) eq 'HASH') {
18939: %usertypes = %{$usertypesref};
1.228 raeburn 18940: }
1.303 raeburn 18941: $usertypes{'default'} = $othertitle;
1.224 raeburn 18942: #
18943: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
18944: #
18945: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18946: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
18947: if ($key eq 'cancreate') {
18948: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18949: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
18950: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 18951: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
18952: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
18953: ($item eq 'emailusername') || ($item eq 'shibenv') ||
18954: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 18955: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 18956: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18957: } else {
18958: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18959: }
18960: }
18961: }
18962: } elsif ($key eq 'email_rule') {
18963: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18964: } else {
18965: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18966: }
18967: }
18968: }
18969: #
18970: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
18971: #
18972: if (ref($domconfig{'usermodification'}) eq 'HASH') {
18973: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
18974: if ($key eq 'selfcreate') {
18975: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
18976: } else {
18977: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
18978: }
18979: }
18980: }
1.305 raeburn 18981: #
18982: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
18983: #
18984: if (ref($domconfig{'inststatus'}) eq 'HASH') {
18985: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
18986: if ($key eq 'inststatusguest') {
18987: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
18988: } else {
18989: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
18990: }
18991: }
18992: }
1.224 raeburn 18993:
18994: my @contexts = ('selfcreate');
18995: @{$cancreate{'selfcreate'}} = ();
18996: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 18997: if (@types) {
18998: @{$cancreate{'statustocreate'}} = ();
18999: }
1.236 raeburn 19000: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 19001: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 19002: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 19003: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 19004: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 19005: my %selfcreatetypes = (
19006: sso => 'users authenticated by institutional single sign on',
19007: login => 'users authenticated by institutional log-in',
1.303 raeburn 19008: email => 'users verified by e-mail',
1.50 raeburn 19009: );
1.224 raeburn 19010: #
19011: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
19012: # is permitted.
19013: #
1.305 raeburn 19014: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 19015:
1.305 raeburn 19016: my (@statuses,%email_rule);
1.228 raeburn 19017: foreach my $item ('login','sso','email') {
1.224 raeburn 19018: if ($item eq 'email') {
1.236 raeburn 19019: if ($env{'form.cancreate_email'}) {
1.305 raeburn 19020: if (@types) {
19021: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
19022: foreach my $status (@poss_statuses) {
19023: if (grep(/^\Q$status\E$/,(@types,'default'))) {
19024: push(@statuses,$status);
19025: }
19026: }
19027: $save_inststatus{'inststatusguest'} = \@statuses;
19028: } else {
19029: push(@statuses,'default');
19030: }
19031: if (@statuses) {
19032: my %curr_rule;
19033: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
19034: foreach my $type (@statuses) {
19035: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 19036: }
1.305 raeburn 19037: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
19038: foreach my $type (@statuses) {
19039: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
19040: }
19041: }
19042: push(@{$cancreate{'selfcreate'}},'email');
19043: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
19044: my %curremaildom;
19045: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
19046: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
19047: }
19048: foreach my $type (@statuses) {
19049: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
19050: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
19051: }
19052: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
19053: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
19054: }
19055: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
19056: #
19057: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
19058: #
19059: my $chosen = $1;
19060: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
19061: my $emaildom;
19062: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
1.425 raeburn 19063: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
1.305 raeburn 19064: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
19065: if (ref($curremaildom{$type}) eq 'HASH') {
19066: if (exists($curremaildom{$type}{$chosen})) {
19067: if ($curremaildom{$type}{$chosen} ne $emaildom) {
19068: push(@{$changes{'cancreate'}},'emaildomain');
19069: }
19070: } elsif ($emaildom ne '') {
19071: push(@{$changes{'cancreate'}},'emaildomain');
19072: }
19073: } elsif ($emaildom ne '') {
19074: push(@{$changes{'cancreate'}},'emaildomain');
1.425 raeburn 19075: }
1.305 raeburn 19076: }
19077: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
19078: } elsif ($chosen eq 'custom') {
19079: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
19080: $email_rule{$type} = [];
19081: if (ref($emailrules) eq 'HASH') {
19082: foreach my $rule (@possemail_rules) {
19083: if (exists($emailrules->{$rule})) {
19084: push(@{$email_rule{$type}},$rule);
19085: }
19086: }
19087: }
19088: if (@{$email_rule{$type}}) {
19089: $cancreate{'emailoptions'}{$type} = 'custom';
19090: if (ref($curr_rule{$type}) eq 'ARRAY') {
19091: if (@{$curr_rule{$type}} > 0) {
19092: foreach my $rule (@{$curr_rule{$type}}) {
19093: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
19094: push(@{$changes{'email_rule'}},$type);
19095: }
19096: }
19097: }
19098: foreach my $type (@{$email_rule{$type}}) {
19099: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
19100: push(@{$changes{'email_rule'}},$type);
19101: }
19102: }
19103: } else {
19104: push(@{$changes{'email_rule'}},$type);
19105: }
19106: }
19107: } else {
19108: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
19109: }
19110: }
19111: }
19112: if (@types) {
19113: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19114: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
19115: if (@changed) {
19116: push(@{$changes{'inststatus'}},'inststatusguest');
19117: }
19118: } else {
19119: push(@{$changes{'inststatus'}},'inststatusguest');
19120: }
19121: }
19122: } else {
19123: delete($env{'form.cancreate_email'});
19124: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19125: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
19126: push(@{$changes{'inststatus'}},'inststatusguest');
19127: }
19128: }
19129: }
19130: } else {
19131: $save_inststatus{'inststatusguest'} = [];
19132: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19133: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
19134: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 19135: }
19136: }
1.224 raeburn 19137: }
19138: } else {
19139: if ($env{'form.cancreate_'.$item}) {
19140: push(@{$cancreate{'selfcreate'}},$item);
19141: }
19142: }
19143: }
1.305 raeburn 19144: my (%userinfo,%savecaptcha);
1.224 raeburn 19145: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
19146: #
1.228 raeburn 19147: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
19148: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 19149: #
1.236 raeburn 19150:
1.244 raeburn 19151: if ($env{'form.cancreate_email'}) {
1.228 raeburn 19152: push(@contexts,'emailusername');
1.305 raeburn 19153: if (@statuses) {
19154: foreach my $type (@statuses) {
1.228 raeburn 19155: if (ref($infofields) eq 'ARRAY') {
19156: foreach my $field (@{$infofields}) {
19157: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
19158: $cancreate{'emailusername'}{$type}{$field} = $1;
19159: }
19160: }
1.224 raeburn 19161: }
19162: }
19163: }
19164: #
19165: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 19166: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 19167: #
19168:
19169: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
19170: @approvalnotify = sort(@approvalnotify);
19171: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
19172: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
19173: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
19174: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
19175: push(@{$changes{'cancreate'}},'notify');
19176: }
19177: } else {
19178: if ($cancreate{'notify'}{'approval'}) {
19179: push(@{$changes{'cancreate'}},'notify');
19180: }
19181: }
19182: } elsif ($cancreate{'notify'}{'approval'}) {
19183: push(@{$changes{'cancreate'}},'notify');
19184: }
19185:
19186: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
19187: }
19188: #
1.236 raeburn 19189: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 19190: # institutional log-in.
19191: #
19192: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
19193: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
19194: ($domdefaults{'auth_def'} eq 'localauth'))) {
19195: $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.').' '.
19196: &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.');
19197: }
19198: }
19199: my @fields = ('lastname','firstname','middlename','generation',
19200: 'permanentemail','id');
1.240 raeburn 19201: my @shibfields = (@fields,'inststatus');
1.224 raeburn 19202: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19203: #
19204: # Where usernames may created for institutional log-in and/or institutional single sign on:
19205: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
19206: # may self-create accounts
19207: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
19208: # which the user may supply, if institutional data is unavailable.
19209: #
19210: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 19211: if (@types) {
1.305 raeburn 19212: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
19213: push(@contexts,'statustocreate');
1.303 raeburn 19214: foreach my $type (@types) {
1.224 raeburn 19215: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
19216: foreach my $field (@fields) {
19217: if (grep(/^\Q$field\E$/,@modifiable)) {
19218: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
19219: } else {
19220: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
19221: }
19222: }
19223: }
19224: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 19225: foreach my $type (@types) {
1.224 raeburn 19226: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
19227: foreach my $field (@fields) {
19228: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
19229: $curr_usermodify{'selfcreate'}{$type}{$field}) {
19230: push(@{$changes{'selfcreate'}},$type);
19231: last;
19232: }
19233: }
19234: }
19235: }
19236: } else {
1.303 raeburn 19237: foreach my $type (@types) {
1.224 raeburn 19238: push(@{$changes{'selfcreate'}},$type);
19239: }
19240: }
19241: }
1.240 raeburn 19242: foreach my $field (@shibfields) {
19243: if ($env{'form.shibenv_'.$field} ne '') {
19244: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
19245: }
19246: }
19247: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
19248: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
19249: foreach my $field (@shibfields) {
19250: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
19251: push(@{$changes{'cancreate'}},'shibenv');
19252: }
19253: }
19254: } else {
19255: foreach my $field (@shibfields) {
19256: if ($env{'form.shibenv_'.$field}) {
19257: push(@{$changes{'cancreate'}},'shibenv');
19258: last;
19259: }
19260: }
19261: }
19262: }
1.224 raeburn 19263: }
19264: foreach my $item (@contexts) {
19265: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
19266: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
19267: if (ref($cancreate{$item}) eq 'ARRAY') {
19268: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
19269: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19270: push(@{$changes{'cancreate'}},$item);
19271: }
19272: }
19273: }
19274: }
19275: if (ref($cancreate{$item}) eq 'ARRAY') {
19276: foreach my $type (@{$cancreate{$item}}) {
19277: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
19278: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19279: push(@{$changes{'cancreate'}},$item);
19280: }
19281: }
19282: }
19283: }
19284: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
19285: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 19286: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
19287: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19288: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
19289: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19290: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19291: push(@{$changes{'cancreate'}},$item);
19292: }
19293: }
19294: }
1.305 raeburn 19295: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19296: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19297: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19298: push(@{$changes{'cancreate'}},$item);
19299: }
1.224 raeburn 19300: }
19301: }
19302: }
1.305 raeburn 19303: foreach my $type (keys(%{$cancreate{$item}})) {
19304: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19305: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19306: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19307: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19308: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19309: push(@{$changes{'cancreate'}},$item);
19310: }
19311: }
19312: } else {
19313: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19314: push(@{$changes{'cancreate'}},$item);
19315: }
19316: }
19317: }
1.305 raeburn 19318: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19319: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19320: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19321: push(@{$changes{'cancreate'}},$item);
19322: }
1.224 raeburn 19323: }
19324: }
19325: }
19326: }
19327: } elsif ($curr_usercreation{'cancreate'}{$item}) {
19328: if (ref($cancreate{$item}) eq 'ARRAY') {
19329: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
19330: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19331: push(@{$changes{'cancreate'}},$item);
19332: }
19333: }
1.305 raeburn 19334: }
19335: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19336: if (ref($cancreate{$item}) eq 'HASH') {
19337: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19338: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 19339: }
19340: }
19341: } elsif ($item eq 'emailusername') {
1.228 raeburn 19342: if (ref($cancreate{$item}) eq 'HASH') {
19343: foreach my $type (keys(%{$cancreate{$item}})) {
19344: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19345: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19346: if ($cancreate{$item}{$type}{$field}) {
19347: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19348: push(@{$changes{'cancreate'}},$item);
19349: }
19350: last;
19351: }
19352: }
19353: }
19354: }
1.224 raeburn 19355: }
19356: }
19357: }
19358: #
19359: # Populate %save_usercreate hash with updates to self-creation configuration.
19360: #
19361: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
19362: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 19363: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 19364: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
19365: if (ref($cancreate{'notify'}) eq 'HASH') {
19366: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
19367: }
1.236 raeburn 19368: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
19369: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
19370: }
1.303 raeburn 19371: if (ref($cancreate{'emailverified'}) eq 'HASH') {
19372: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
19373: }
1.305 raeburn 19374: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
19375: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
19376: }
1.303 raeburn 19377: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
19378: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
19379: }
1.224 raeburn 19380: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19381: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
19382: }
1.240 raeburn 19383: if (ref($cancreate{'shibenv'}) eq 'HASH') {
19384: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
19385: }
1.224 raeburn 19386: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 19387: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 19388:
19389: my %userconfig_hash = (
19390: usercreation => \%save_usercreate,
19391: usermodification => \%save_usermodify,
1.305 raeburn 19392: inststatus => \%save_inststatus,
1.224 raeburn 19393: );
1.305 raeburn 19394:
1.224 raeburn 19395: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
19396: $dom);
19397: #
1.305 raeburn 19398: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 19399: #
1.27 raeburn 19400: if ($putresult eq 'ok') {
19401: if (keys(%changes) > 0) {
19402: $resulttext = &mt('Changes made:').'<ul>';
19403: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 19404: my %lt = &selfcreation_types();
1.34 raeburn 19405: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 19406: my $chgtext = '';
1.45 raeburn 19407: if ($type eq 'selfcreate') {
1.50 raeburn 19408: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 19409: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 19410: } else {
1.224 raeburn 19411: $chgtext .= &mt('Self-creation of a new account is permitted for:').
19412: '<ul>';
1.50 raeburn 19413: foreach my $case (@{$cancreate{$type}}) {
19414: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
19415: }
19416: $chgtext .= '</ul>';
1.100 raeburn 19417: if (ref($cancreate{$type}) eq 'ARRAY') {
19418: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
19419: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19420: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 19421: $chgtext .= '<span class="LC_warning">'.
19422: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
19423: '</span><br />';
19424: }
19425: }
19426: }
19427: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 19428: if (!@statuses) {
19429: $chgtext .= '<span class="LC_warning">'.
19430: &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.").
19431: '</span><br />';
1.303 raeburn 19432:
1.100 raeburn 19433: }
19434: }
19435: }
1.43 raeburn 19436: }
1.240 raeburn 19437: } elsif ($type eq 'shibenv') {
19438: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 19439: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 19440: } else {
19441: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
19442: '<ul>';
19443: foreach my $field (@shibfields) {
19444: next if ($cancreate{$type}{$field} eq '');
19445: if ($field eq 'inststatus') {
19446: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
19447: } else {
19448: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
19449: }
19450: }
19451: $chgtext .= '</ul>';
1.303 raeburn 19452: }
1.93 raeburn 19453: } elsif ($type eq 'statustocreate') {
1.96 raeburn 19454: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
19455: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
19456: if (@{$cancreate{'selfcreate'}} > 0) {
19457: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 19458: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 19459: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 19460: $chgtext .= '<br />'.
19461: '<span class="LC_warning">'.
19462: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
19463: '</span>';
19464: }
1.303 raeburn 19465: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 19466: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 19467: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
19468: } else {
19469: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
19470: }
19471: $chgtext .= '<ul>';
19472: foreach my $case (@{$cancreate{$type}}) {
19473: if ($case eq 'default') {
19474: $chgtext .= '<li>'.$othertitle.'</li>';
19475: } else {
1.303 raeburn 19476: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 19477: }
19478: }
1.100 raeburn 19479: $chgtext .= '</ul>';
19480: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 19481: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 19482: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
19483: '</span>';
1.100 raeburn 19484: }
19485: }
19486: } else {
19487: if (@{$cancreate{$type}} == 0) {
19488: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
19489: } else {
19490: $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 19491: }
19492: }
1.303 raeburn 19493: $chgtext .= '<br />';
1.93 raeburn 19494: }
1.236 raeburn 19495: } elsif ($type eq 'selfcreateprocessing') {
19496: my %choices = &Apache::lonlocal::texthash (
19497: automatic => 'Automatic approval',
19498: approval => 'Queued for approval',
19499: );
1.305 raeburn 19500: if (@types) {
19501: if (@statuses) {
1.425 raeburn 19502: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 19503: '<ul>';
1.305 raeburn 19504: foreach my $status (@statuses) {
19505: if ($status eq 'default') {
19506: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19507: } else {
1.305 raeburn 19508: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19509: }
19510: }
19511: $chgtext .= '</ul>';
19512: }
19513: } else {
19514: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
19515: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
19516: }
19517: } elsif ($type eq 'emailverified') {
19518: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 19519: all => 'Same as e-mail',
19520: first => 'Omit @domain',
19521: free => 'Free to choose',
1.303 raeburn 19522: );
1.305 raeburn 19523: if (@types) {
19524: if (@statuses) {
1.303 raeburn 19525: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
19526: '<ul>';
1.305 raeburn 19527: foreach my $status (@statuses) {
1.362 raeburn 19528: if ($status eq 'default') {
1.305 raeburn 19529: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19530: } else {
1.305 raeburn 19531: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19532: }
19533: }
19534: $chgtext .= '</ul>';
19535: }
19536: } else {
1.305 raeburn 19537: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 19538: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 19539: }
1.305 raeburn 19540: } elsif ($type eq 'emailoptions') {
19541: my %options = &Apache::lonlocal::texthash (
19542: any => 'Any e-mail',
19543: inst => 'Institutional only',
19544: noninst => 'Non-institutional only',
19545: custom => 'Custom restrictions',
19546: );
19547: if (@types) {
19548: if (@statuses) {
19549: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
19550: '<ul>';
19551: foreach my $status (@statuses) {
19552: if ($type eq 'default') {
19553: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
19554: } else {
19555: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 19556: }
19557: }
1.305 raeburn 19558: $chgtext .= '</ul>';
19559: }
19560: } else {
19561: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
19562: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
19563: } else {
19564: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
19565: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 19566: }
1.305 raeburn 19567: }
19568: } elsif ($type eq 'emaildomain') {
19569: my $output;
19570: if (@statuses) {
19571: foreach my $type (@statuses) {
19572: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
19573: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
19574: if ($type eq 'default') {
19575: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19576: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19577: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19578: } else {
19579: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
19580: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
19581: }
1.303 raeburn 19582: } else {
1.305 raeburn 19583: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19584: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19585: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19586: } else {
19587: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
1.421 raeburn 19588: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
1.305 raeburn 19589: }
1.303 raeburn 19590: }
1.305 raeburn 19591: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
19592: if ($type eq 'default') {
19593: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19594: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19595: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19596: } else {
19597: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
19598: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
19599: }
1.303 raeburn 19600: } else {
1.305 raeburn 19601: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19602: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19603: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19604: } else {
19605: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
1.421 raeburn 19606: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
1.305 raeburn 19607: }
1.303 raeburn 19608: }
19609: }
19610: }
19611: }
1.305 raeburn 19612: }
19613: if ($output ne '') {
19614: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
19615: '<ul>'.$output.'</ul>';
1.236 raeburn 19616: }
1.165 raeburn 19617: } elsif ($type eq 'captcha') {
1.224 raeburn 19618: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 19619: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
19620: } else {
19621: my %captchas = &captcha_phrases();
1.224 raeburn 19622: if ($captchas{$savecaptcha{$type}}) {
19623: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 19624: } else {
1.210 raeburn 19625: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 19626: }
19627: }
19628: } elsif ($type eq 'recaptchakeys') {
19629: my ($privkey,$pubkey);
1.224 raeburn 19630: if (ref($savecaptcha{$type}) eq 'HASH') {
19631: $pubkey = $savecaptcha{$type}{'public'};
19632: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 19633: }
19634: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
19635: if (!$pubkey) {
19636: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
19637: } else {
19638: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
19639: }
19640: if (!$privkey) {
19641: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
19642: } else {
19643: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
19644: }
19645: $chgtext .= '</ul>';
1.269 raeburn 19646: } elsif ($type eq 'recaptchaversion') {
19647: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 19648: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 19649: }
1.224 raeburn 19650: } elsif ($type eq 'emailusername') {
19651: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 19652: if (@statuses) {
19653: foreach my $type (@statuses) {
1.228 raeburn 19654: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
19655: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 19656: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 19657: '<ul>';
19658: foreach my $field (@{$infofields}) {
19659: if ($cancreate{'emailusername'}{$type}{$field}) {
19660: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
19661: }
19662: }
1.245 raeburn 19663: $chgtext .= '</ul>';
19664: } else {
1.303 raeburn 19665: $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 19666: }
19667: } else {
1.303 raeburn 19668: $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 19669: }
19670: }
19671: }
19672: }
19673: } elsif ($type eq 'notify') {
1.303 raeburn 19674: my $numapprove = 0;
1.224 raeburn 19675: if (ref($changes{'cancreate'}) eq 'ARRAY') {
19676: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
19677: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 19678: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
19679: $numapprove ++;
1.224 raeburn 19680: }
19681: }
1.43 raeburn 19682: }
1.303 raeburn 19683: unless ($numapprove) {
19684: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
19685: }
1.34 raeburn 19686: }
1.224 raeburn 19687: if ($chgtext) {
19688: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 19689: }
19690: }
19691: }
1.305 raeburn 19692: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 19693: my ($emailrules,$emailruleorder) =
19694: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 19695: foreach my $type (@{$changes{'email_rule'}}) {
19696: if (ref($email_rule{$type}) eq 'ARRAY') {
19697: my $chgtext = '<ul>';
19698: foreach my $rule (@{$email_rule{$type}}) {
19699: if (ref($emailrules->{$rule}) eq 'HASH') {
19700: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
19701: }
19702: }
19703: $chgtext .= '</ul>';
1.310 raeburn 19704: my $typename;
1.305 raeburn 19705: if (@types) {
19706: if ($type eq 'default') {
19707: $typename = $othertitle;
19708: } else {
19709: $typename = $usertypes{$type};
1.425 raeburn 19710: }
1.305 raeburn 19711: $chgtext .= &mt('(Affiliation: [_1])',$typename);
19712: }
19713: if (@{$email_rule{$type}} > 0) {
19714: $resulttext .= '<li>'.
19715: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
19716: $usertypes{$type}).
19717: $chgtext.
19718: '</li>';
19719: } else {
19720: $resulttext .= '<li>'.
1.310 raeburn 19721: &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 19722: '</li>'.
1.310 raeburn 19723: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 19724: }
1.43 raeburn 19725: }
19726: }
1.305 raeburn 19727: }
19728: if (ref($changes{'inststatus'}) eq 'ARRAY') {
19729: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
19730: if (@{$save_inststatus{'inststatusguest'}} > 0) {
19731: my $chgtext = '<ul>';
19732: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
19733: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
19734: }
19735: $chgtext .= '</ul>';
19736: $resulttext .= '<li>'.
19737: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
19738: $chgtext.
19739: '</li>';
19740: } else {
19741: $resulttext .= '<li>'.
19742: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
19743: '</li>';
19744: }
1.43 raeburn 19745: }
19746: }
1.224 raeburn 19747: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
19748: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
19749: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19750: foreach my $type (@{$changes{'selfcreate'}}) {
19751: my $typename = $type;
1.303 raeburn 19752: if (keys(%usertypes) > 0) {
19753: if ($usertypes{$type} ne '') {
19754: $typename = $usertypes{$type};
1.224 raeburn 19755: }
19756: }
19757: my @modifiable;
19758: $resulttext .= '<li>'.
19759: &mt('Self-creation of account by users with status: [_1]',
19760: '<span class="LC_cusr_emph">'.$typename.'</span>').
19761: ' - '.&mt('modifiable fields (if institutional data blank): ');
19762: foreach my $field (@fields) {
19763: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
19764: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 19765: }
19766: }
1.224 raeburn 19767: if (@modifiable > 0) {
19768: $resulttext .= join(', ',@modifiable);
1.43 raeburn 19769: } else {
1.224 raeburn 19770: $resulttext .= &mt('none');
1.43 raeburn 19771: }
1.224 raeburn 19772: $resulttext .= '</li>';
1.28 raeburn 19773: }
1.224 raeburn 19774: $resulttext .= '</ul></li>';
1.28 raeburn 19775: }
1.27 raeburn 19776: $resulttext .= '</ul>';
1.305 raeburn 19777: my $cachetime = 24*60*60;
19778: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
19779: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19780: if (ref($lastactref) eq 'HASH') {
19781: $lastactref->{'domdefaults'} = 1;
19782: }
1.27 raeburn 19783: } else {
1.224 raeburn 19784: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 19785: }
19786: } else {
19787: $resulttext = '<span class="LC_error">'.
1.23 raeburn 19788: &mt('An error occurred: [_1]',$putresult).'</span>';
19789: }
1.43 raeburn 19790: if ($warningmsg ne '') {
19791: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
19792: }
1.23 raeburn 19793: return $resulttext;
19794: }
19795:
1.165 raeburn 19796: sub process_captcha {
1.369 raeburn 19797: my ($container,$changes,$newsettings,$currsettings) = @_;
19798: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165 raeburn 19799: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
19800: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
19801: $newsettings->{'captcha'} = 'original';
19802: }
1.369 raeburn 19803: my %current;
19804: if (ref($currsettings) eq 'HASH') {
19805: %current = %{$currsettings};
19806: }
19807: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 19808: if ($container eq 'cancreate') {
1.169 raeburn 19809: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19810: push(@{$changes->{'cancreate'}},'captcha');
19811: } elsif (!defined($changes->{'cancreate'})) {
19812: $changes->{'cancreate'} = ['captcha'];
19813: }
1.368 raeburn 19814: } elsif ($container eq 'passwords') {
19815: $changes->{'reset'} = 1;
1.169 raeburn 19816: } else {
19817: $changes->{'captcha'} = 1;
1.165 raeburn 19818: }
19819: }
1.269 raeburn 19820: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 19821: if ($newsettings->{'captcha'} eq 'recaptcha') {
19822: $newpub = $env{'form.'.$container.'_recaptchapub'};
19823: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 19824: $newpub =~ s/[^\w\-]//g;
19825: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 19826: $newsettings->{'recaptchakeys'} = {
19827: public => $newpub,
19828: private => $newpriv,
19829: };
1.269 raeburn 19830: $newversion = $env{'form.'.$container.'_recaptchaversion'};
19831: $newversion =~ s/\D//g;
19832: if ($newversion ne '2') {
19833: $newversion = 1;
19834: }
19835: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 19836: }
1.369 raeburn 19837: if (ref($current{'recaptchakeys'}) eq 'HASH') {
19838: $currpub = $current{'recaptchakeys'}{'public'};
19839: $currpriv = $current{'recaptchakeys'}{'private'};
1.179 raeburn 19840: unless ($newsettings->{'captcha'} eq 'recaptcha') {
19841: $newsettings->{'recaptchakeys'} = {
19842: public => '',
19843: private => '',
19844: }
19845: }
1.165 raeburn 19846: }
1.369 raeburn 19847: if ($current{'captcha'} eq 'recaptcha') {
19848: $currversion = $current{'recaptchaversion'};
1.269 raeburn 19849: if ($currversion ne '2') {
19850: $currversion = 1;
19851: }
19852: }
19853: if ($currversion ne $newversion) {
19854: if ($container eq 'cancreate') {
19855: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19856: push(@{$changes->{'cancreate'}},'recaptchaversion');
19857: } elsif (!defined($changes->{'cancreate'})) {
19858: $changes->{'cancreate'} = ['recaptchaversion'];
19859: }
1.368 raeburn 19860: } elsif ($container eq 'passwords') {
19861: $changes->{'reset'} = 1;
1.269 raeburn 19862: } else {
19863: $changes->{'recaptchaversion'} = 1;
19864: }
19865: }
1.165 raeburn 19866: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 19867: if ($container eq 'cancreate') {
19868: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19869: push(@{$changes->{'cancreate'}},'recaptchakeys');
19870: } elsif (!defined($changes->{'cancreate'})) {
19871: $changes->{'cancreate'} = ['recaptchakeys'];
19872: }
1.368 raeburn 19873: } elsif ($container eq 'passwords') {
19874: $changes->{'reset'} = 1;
1.169 raeburn 19875: } else {
1.210 raeburn 19876: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 19877: }
19878: }
19879: return;
19880: }
19881:
1.33 raeburn 19882: sub modify_usermodification {
19883: my ($dom,%domconfig) = @_;
1.224 raeburn 19884: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 19885: if (ref($domconfig{'usermodification'}) eq 'HASH') {
19886: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 19887: if ($key eq 'selfcreate') {
19888: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
19889: } else {
19890: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
19891: }
1.33 raeburn 19892: }
19893: }
1.443 raeburn 19894: my @contexts = ('author','coauthor','course');
1.33 raeburn 19895: my %context_title = (
19896: author => 'In author context',
1.443 raeburn 19897: coauthor => 'As co-author manager',
1.33 raeburn 19898: course => 'In course context',
19899: );
19900: my @fields = ('lastname','firstname','middlename','generation',
19901: 'permanentemail','id');
19902: my %roles = (
19903: author => ['ca','aa'],
1.443 raeburn 19904: coauthor => ['ca','aa'],
1.33 raeburn 19905: course => ['st','ep','ta','in','cr'],
19906: );
19907: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19908: foreach my $context (@contexts) {
1.443 raeburn 19909: my $prefix = 'canmodify';
19910: if ($context eq 'coauthor') {
19911: $prefix = 'cacanmodify';
19912: }
1.33 raeburn 19913: foreach my $role (@{$roles{$context}}) {
1.443 raeburn 19914: my @modifiable = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$role);
1.33 raeburn 19915: foreach my $item (@fields) {
19916: if (grep(/^\Q$item\E$/,@modifiable)) {
19917: $modifyhash{$context}{$role}{$item} = 1;
19918: } else {
19919: $modifyhash{$context}{$role}{$item} = 0;
19920: }
19921: }
19922: }
19923: if (ref($curr_usermodification{$context}) eq 'HASH') {
19924: foreach my $role (@{$roles{$context}}) {
19925: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
19926: foreach my $field (@fields) {
19927: if ($modifyhash{$context}{$role}{$field} ne
19928: $curr_usermodification{$context}{$role}{$field}) {
19929: push(@{$changes{$context}},$role);
19930: last;
19931: }
19932: }
19933: }
19934: }
19935: } else {
19936: foreach my $context (@contexts) {
19937: foreach my $role (@{$roles{$context}}) {
19938: push(@{$changes{$context}},$role);
19939: }
19940: }
19941: }
19942: }
19943: my %usermodification_hash = (
19944: usermodification => \%modifyhash,
19945: );
19946: my $putresult = &Apache::lonnet::put_dom('configuration',
19947: \%usermodification_hash,$dom);
19948: if ($putresult eq 'ok') {
19949: if (keys(%changes) > 0) {
19950: $resulttext = &mt('Changes made: ').'<ul>';
19951: foreach my $context (@contexts) {
19952: if (ref($changes{$context}) eq 'ARRAY') {
19953: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
19954: if (ref($changes{$context}) eq 'ARRAY') {
19955: foreach my $role (@{$changes{$context}}) {
19956: my $rolename;
1.224 raeburn 19957: if ($role eq 'cr') {
19958: $rolename = &mt('Custom');
1.33 raeburn 19959: } else {
1.224 raeburn 19960: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 19961: }
19962: my @modifiable;
1.224 raeburn 19963: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 19964: foreach my $field (@fields) {
19965: if ($modifyhash{$context}{$role}{$field}) {
19966: push(@modifiable,$fieldtitles{$field});
19967: }
19968: }
19969: if (@modifiable > 0) {
19970: $resulttext .= join(', ',@modifiable);
19971: } else {
19972: $resulttext .= &mt('none');
19973: }
19974: $resulttext .= '</li>';
19975: }
19976: $resulttext .= '</ul></li>';
19977: }
19978: }
19979: }
19980: $resulttext .= '</ul>';
19981: } else {
19982: $resulttext = &mt('No changes made to user modification settings');
19983: }
19984: } else {
19985: $resulttext = '<span class="LC_error">'.
19986: &mt('An error occurred: [_1]',$putresult).'</span>';
19987: }
19988: return $resulttext;
19989: }
19990:
1.43 raeburn 19991: sub modify_defaults {
1.212 raeburn 19992: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 19993: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 19994: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 19995: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 19996: 'portal_def');
1.325 raeburn 19997: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 19998: foreach my $item (@items) {
19999: $newvalues{$item} = $env{'form.'.$item};
20000: if ($item eq 'auth_def') {
20001: if ($newvalues{$item} ne '') {
20002: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
20003: push(@errors,$item);
20004: }
20005: }
20006: } elsif ($item eq 'lang_def') {
20007: if ($newvalues{$item} ne '') {
20008: if ($newvalues{$item} =~ /^(\w+)/) {
20009: my $langcode = $1;
1.103 raeburn 20010: if ($langcode ne 'x_chef') {
20011: if (code2language($langcode) eq '') {
20012: push(@errors,$item);
20013: }
1.43 raeburn 20014: }
20015: } else {
20016: push(@errors,$item);
20017: }
20018: }
1.54 raeburn 20019: } elsif ($item eq 'timezone_def') {
20020: if ($newvalues{$item} ne '') {
1.62 raeburn 20021: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 20022: push(@errors,$item);
20023: }
20024: }
1.68 raeburn 20025: } elsif ($item eq 'datelocale_def') {
20026: if ($newvalues{$item} ne '') {
20027: my @datelocale_ids = DateTime::Locale->ids();
20028: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
20029: push(@errors,$item);
20030: }
20031: }
1.141 raeburn 20032: } elsif ($item eq 'portal_def') {
20033: if ($newvalues{$item} ne '') {
1.414 raeburn 20034: 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])\/?$/) {
20035: foreach my $field ('email','web') {
20036: if ($env{'form.'.$item.'_'.$field}) {
20037: $newvalues{$item.'_'.$field} = $env{'form.'.$item.'_'.$field};
20038: }
20039: }
20040: } else {
1.141 raeburn 20041: push(@errors,$item);
20042: }
20043: }
1.43 raeburn 20044: }
20045: if (grep(/^\Q$item\E$/,@errors)) {
20046: $newvalues{$item} = $domdefaults{$item};
1.414 raeburn 20047: if ($item eq 'portal_def') {
20048: if ($domdefaults{$item}) {
20049: foreach my $field ('email','web') {
20050: if (exists($domdefaults{$item.'_'.$field})) {
20051: $newvalues{$item.'_'.$field} = $domdefaults{$item.'_'.$field};
20052: }
20053: }
20054: }
20055: }
1.43 raeburn 20056: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
20057: $changes{$item} = 1;
20058: }
1.414 raeburn 20059: if ($item eq 'portal_def') {
20060: unless (grep(/^\Q$item\E$/,@errors)) {
1.425 raeburn 20061: if ($newvalues{$item} eq '') {
1.414 raeburn 20062: foreach my $field ('email','web') {
20063: if (exists($domdefaults{$item.'_'.$field})) {
20064: delete($domdefaults{$item.'_'.$field});
20065: }
20066: }
20067: } else {
20068: unless ($changes{$item}) {
20069: foreach my $field ('email','web') {
20070: if ($domdefaults{$item.'_'.$field} ne $newvalues{$item.'_'.$field}) {
20071: $changes{$item} = 1;
20072: last;
20073: }
20074: }
20075: }
20076: foreach my $field ('email','web') {
20077: if ($newvalues{$item.'_'.$field}) {
20078: $domdefaults{$item.'_'.$field} = $newvalues{$item.'_'.$field};
20079: } elsif (exists($domdefaults{$item.'_'.$field})) {
20080: delete($domdefaults{$item.'_'.$field});
20081: }
20082: }
20083: }
20084: }
20085: }
1.72 raeburn 20086: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 20087: }
1.354 raeburn 20088: my %staticdefaults = (
20089: 'intauth_cost' => 10,
20090: 'intauth_check' => 0,
20091: 'intauth_switch' => 0,
20092: );
20093: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
20094: if (exists($domdefaults{$item})) {
20095: $newvalues{$item} = $domdefaults{$item};
20096: } else {
20097: $newvalues{$item} = $staticdefaults{$item};
20098: }
20099: }
1.409 raeburn 20100: my ($unamemaprules,$ruleorder);
20101: my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
20102: if (@possunamemaprules) {
20103: ($unamemaprules,$ruleorder) =
20104: &Apache::lonnet::inst_userrules($dom,'unamemap');
20105: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
20106: if (@{$ruleorder} > 0) {
20107: my %possrules;
20108: map { $possrules{$_} = 1; } @possunamemaprules;
20109: foreach my $rule (@{$ruleorder}) {
20110: if ($possrules{$rule}) {
20111: push(@{$newvalues{'unamemap_rule'}},$rule);
20112: }
20113: }
20114: }
20115: }
20116: }
20117: if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
20118: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20119: my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
20120: $newvalues{'unamemap_rule'});
20121: if (@rulediffs) {
20122: $changes{'unamemap_rule'} = 1;
20123: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
20124: }
20125: } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
20126: $changes{'unamemap_rule'} = 1;
20127: delete($domdefaults{'unamemap_rule'});
20128: }
20129: } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20130: if (@{$newvalues{'unamemap_rule'}} > 0) {
20131: $changes{'unamemap_rule'} = 1;
20132: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
20133: }
20134: }
1.43 raeburn 20135: my %defaults_hash = (
1.72 raeburn 20136: defaults => \%newvalues,
20137: );
1.43 raeburn 20138: my $title = &defaults_titles();
1.236 raeburn 20139:
20140: my $currinststatus;
20141: if (ref($domconfig{'inststatus'}) eq 'HASH') {
20142: $currinststatus = $domconfig{'inststatus'};
20143: } else {
20144: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
20145: $currinststatus = {
20146: inststatustypes => $usertypes,
20147: inststatusorder => $types,
20148: inststatusguest => [],
20149: };
20150: }
20151: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
20152: my @allpos;
20153: my %alltypes;
1.305 raeburn 20154: my @inststatusguest;
20155: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
20156: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
20157: unless (grep(/^\Q$type\E$/,@todelete)) {
20158: push(@inststatusguest,$type);
20159: }
20160: }
20161: }
20162: my ($currtitles,$currorder);
1.236 raeburn 20163: if (ref($currinststatus) eq 'HASH') {
20164: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
20165: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
20166: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
20167: if ($currinststatus->{inststatustypes}->{$type} ne '') {
20168: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
20169: }
20170: }
20171: unless (grep(/^\Q$type\E$/,@todelete)) {
20172: my $position = $env{'form.inststatus_pos_'.$type};
20173: $position =~ s/\D+//g;
20174: $allpos[$position] = $type;
20175: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
20176: $alltypes{$type} =~ s/`//g;
20177: }
20178: }
20179: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
20180: $currtitles =~ s/,$//;
20181: }
20182: }
20183: if ($env{'form.addinststatus'}) {
20184: my $newtype = $env{'form.addinststatus'};
20185: $newtype =~ s/\W//g;
20186: unless (exists($alltypes{$newtype})) {
20187: $alltypes{$newtype} = $env{'form.addinststatus_title'};
20188: $alltypes{$newtype} =~ s/`//g;
20189: my $position = $env{'form.addinststatus_pos'};
20190: $position =~ s/\D+//g;
20191: if ($position ne '') {
20192: $allpos[$position] = $newtype;
20193: }
20194: }
20195: }
1.305 raeburn 20196: my @orderedstatus;
1.236 raeburn 20197: foreach my $type (@allpos) {
20198: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
20199: push(@orderedstatus,$type);
20200: }
20201: }
20202: foreach my $type (keys(%alltypes)) {
20203: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
20204: delete($alltypes{$type});
20205: }
20206: }
20207: $defaults_hash{'inststatus'} = {
20208: inststatustypes => \%alltypes,
20209: inststatusorder => \@orderedstatus,
1.305 raeburn 20210: inststatusguest => \@inststatusguest,
1.236 raeburn 20211: };
20212: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
20213: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
20214: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
20215: }
20216: }
20217: if ($currorder ne join(',',@orderedstatus)) {
20218: $changes{'inststatus'}{'inststatusorder'} = 1;
20219: }
20220: my $newtitles;
20221: foreach my $item (@orderedstatus) {
20222: $newtitles .= $alltypes{$item}.',';
20223: }
20224: $newtitles =~ s/,$//;
20225: if ($currtitles ne $newtitles) {
20226: $changes{'inststatus'}{'inststatustypes'} = 1;
20227: }
1.43 raeburn 20228: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
20229: $dom);
20230: if ($putresult eq 'ok') {
20231: if (keys(%changes) > 0) {
20232: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 20233: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 20234: 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";
20235: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 20236: if ($item eq 'inststatus') {
20237: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 20238: if (@orderedstatus) {
1.236 raeburn 20239: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
20240: foreach my $type (@orderedstatus) {
20241: $resulttext .= $alltypes{$type}.', ';
20242: }
20243: $resulttext =~ s/, $//;
20244: $resulttext .= '</li>';
1.305 raeburn 20245: } else {
1.425 raeburn 20246: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 20247: }
20248: }
1.409 raeburn 20249: } elsif ($item eq 'unamemap_rule') {
20250: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20251: my @rulenames;
20252: if (ref($unamemaprules) eq 'HASH') {
20253: foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
20254: if (ref($unamemaprules->{$rule}) eq 'HASH') {
20255: push(@rulenames,$unamemaprules->{$rule}->{'name'});
20256: }
20257: }
20258: }
20259: if (@rulenames) {
20260: $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
20261: '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
20262: '</li>';
20263: } else {
20264: $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
20265: }
20266: } else {
20267: $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
20268: }
1.236 raeburn 20269: } else {
20270: my $value = $env{'form.'.$item};
20271: if ($value eq '') {
20272: $value = &mt('none');
20273: } elsif ($item eq 'auth_def') {
20274: my %authnames = &authtype_names();
20275: my %shortauth = (
20276: internal => 'int',
20277: krb4 => 'krb4',
20278: krb5 => 'krb5',
20279: localauth => 'loc',
1.325 raeburn 20280: lti => 'lti',
1.236 raeburn 20281: );
20282: $value = $authnames{$shortauth{$value}};
20283: }
20284: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
1.414 raeburn 20285: $mailmsgtext .= "$title->{$item} set to $value\n";
20286: if ($item eq 'portal_def') {
20287: if ($env{'form.'.$item} ne '') {
20288: foreach my $field ('email','web') {
20289: $value = $env{'form.'.$item.'_'.$field};
20290: if ($value) {
20291: $value = &mt('Yes');
20292: } else {
20293: $value = &mt('No');
20294: }
20295: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$field},$value).'</li>';
20296: }
20297: }
20298: }
1.43 raeburn 20299: }
20300: }
20301: $resulttext .= '</ul>';
20302: $mailmsgtext .= "\n";
20303: my $cachetime = 24*60*60;
1.72 raeburn 20304: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 20305: if (ref($lastactref) eq 'HASH') {
20306: $lastactref->{'domdefaults'} = 1;
20307: }
1.68 raeburn 20308: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 20309: my $notify = 1;
20310: if (ref($domconfig{'contacts'}) eq 'HASH') {
20311: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
20312: $notify = 0;
20313: }
20314: }
20315: if ($notify) {
20316: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
20317: "LON-CAPA Domain Settings Change - $dom",
20318: $mailmsgtext);
20319: }
1.54 raeburn 20320: }
1.43 raeburn 20321: } else {
1.54 raeburn 20322: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 20323: }
20324: } else {
20325: $resulttext = '<span class="LC_error">'.
20326: &mt('An error occurred: [_1]',$putresult).'</span>';
20327: }
20328: if (@errors > 0) {
20329: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
20330: foreach my $item (@errors) {
20331: $resulttext .= ' "'.$title->{$item}.'",';
20332: }
20333: $resulttext =~ s/,$//;
20334: }
20335: return $resulttext;
20336: }
20337:
1.46 raeburn 20338: sub modify_scantron {
1.205 raeburn 20339: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 20340: my ($resulttext,%confhash,%changes,$errors);
20341: my $custom = 'custom.tab';
20342: my $default = 'default.tab';
20343: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 20344: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 20345: &config_check($dom,$confname,$servadm);
20346: if ($env{'form.scantronformat.filename'} ne '') {
20347: my $error;
20348: if ($configuserok eq 'ok') {
20349: if ($switchserver) {
1.130 raeburn 20350: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 20351: } else {
20352: if ($author_ok eq 'ok') {
1.421 raeburn 20353: my $modified = [];
1.46 raeburn 20354: my ($result,$scantronurl) =
1.421 raeburn 20355: &Apache::lonconfigsettings::publishlogo($r,'upload','scantronformat',$dom,
20356: $confname,'scantron','','',$custom,
20357: $modified);
1.46 raeburn 20358: if ($result eq 'ok') {
20359: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 20360: $changes{'scantronformat'} = 1;
1.421 raeburn 20361: &update_modify_urls($r,$modified);
1.46 raeburn 20362: } else {
20363: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
20364: }
20365: } else {
20366: $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);
20367: }
20368: }
20369: } else {
20370: $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);
20371: }
20372: if ($error) {
20373: &Apache::lonnet::logthis($error);
20374: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
20375: }
20376: }
1.48 raeburn 20377: if (ref($domconfig{'scantron'}) eq 'HASH') {
20378: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
20379: if ($env{'form.scantronformat_del'}) {
20380: $confhash{'scantron'}{'scantronformat'} = '';
20381: $changes{'scantronformat'} = 1;
1.347 raeburn 20382: } else {
20383: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 20384: }
20385: }
20386: }
1.347 raeburn 20387: my @options = ('hdr','pad','rem');
1.346 raeburn 20388: my @fields = &scantroncsv_fields();
20389: my %titles = &scantronconfig_titles();
1.347 raeburn 20390: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 20391: my ($newdat,$currdat,%newcol,%currcol);
20392: if (grep(/^dat$/,@formats)) {
20393: $confhash{'scantron'}{config}{dat} = 1;
20394: $newdat = 1;
20395: } else {
20396: $newdat = 0;
20397: }
20398: if (grep(/^csv$/,@formats)) {
20399: my %bynum;
20400: foreach my $field (@fields) {
20401: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
20402: my $posscol = $1;
20403: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 20404: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 20405: $bynum{$posscol} = $field;
20406: $newcol{$field} = $posscol;
20407: }
20408: }
20409: }
1.347 raeburn 20410: if (keys(%newcol)) {
20411: foreach my $option (@options) {
20412: if ($env{'form.scantroncsv_'.$option}) {
20413: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
20414: }
20415: }
20416: }
1.346 raeburn 20417: }
20418: $currdat = 1;
20419: if (ref($domconfig{'scantron'}) eq 'HASH') {
20420: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 20421: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 20422: $currdat = 0;
20423: }
20424: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20425: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20426: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
20427: }
1.346 raeburn 20428: }
20429: }
20430: }
20431: if ($currdat != $newdat) {
20432: $changes{'config'} = 1;
20433: } else {
20434: foreach my $field (@fields) {
20435: if ($currcol{$field} ne '') {
20436: if ($currcol{$field} ne $newcol{$field}) {
20437: $changes{'config'} = 1;
20438: last;
1.347 raeburn 20439: }
1.346 raeburn 20440: } elsif ($newcol{$field} ne '') {
20441: $changes{'config'} = 1;
20442: last;
20443: }
20444: }
20445: }
1.46 raeburn 20446: if (keys(%confhash) > 0) {
20447: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
20448: $dom);
20449: if ($putresult eq 'ok') {
20450: if (keys(%changes) > 0) {
1.48 raeburn 20451: if (ref($confhash{'scantron'}) eq 'HASH') {
20452: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 20453: if ($changes{'scantronformat'}) {
20454: if ($confhash{'scantron'}{'scantronformat'} eq '') {
20455: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
20456: } else {
20457: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
20458: }
20459: }
1.347 raeburn 20460: if ($changes{'config'}) {
1.346 raeburn 20461: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
20462: if ($confhash{'scantron'}{'config'}{'dat'}) {
20463: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
20464: }
20465: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20466: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20467: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
20468: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
20469: foreach my $field (@fields) {
20470: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
20471: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
20472: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
20473: }
20474: }
20475: $resulttext .= '</ul></li>';
20476: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
20477: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
20478: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
20479: foreach my $option (@options) {
20480: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
20481: $resulttext .= '<li>'.$titles{$option}.'</li>';
20482: }
20483: }
20484: $resulttext .= '</ul></li>';
20485: }
1.346 raeburn 20486: }
20487: }
20488: }
20489: }
20490: } else {
20491: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
20492: }
1.46 raeburn 20493: }
1.48 raeburn 20494: $resulttext .= '</ul>';
20495: } else {
1.130 raeburn 20496: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 20497: }
20498: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 20499: if (ref($lastactref) eq 'HASH') {
20500: $lastactref->{'domainconfig'} = 1;
20501: }
1.46 raeburn 20502: } else {
1.346 raeburn 20503: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 20504: }
20505: } else {
20506: $resulttext = '<span class="LC_error">'.
20507: &mt('An error occurred: [_1]',$putresult).'</span>';
20508: }
20509: } else {
1.130 raeburn 20510: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 20511: }
20512: if ($errors) {
1.353 raeburn 20513: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
20514: $errors.'</ul></p>';
1.46 raeburn 20515: }
20516: return $resulttext;
20517: }
20518:
1.48 raeburn 20519: sub modify_coursecategories {
1.239 raeburn 20520: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 20521: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
20522: $cathash);
1.48 raeburn 20523: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 20524: my @catitems = ('unauth','auth');
20525: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 20526: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 20527: $cathash = $domconfig{'coursecategories'}{'cats'};
20528: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
20529: $changes{'togglecats'} = 1;
20530: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
20531: }
20532: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
20533: $changes{'categorize'} = 1;
20534: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
20535: }
1.120 raeburn 20536: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
20537: $changes{'togglecatscomm'} = 1;
20538: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
20539: }
20540: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
20541: $changes{'categorizecomm'} = 1;
20542: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 20543:
20544: }
20545: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
20546: $changes{'togglecatsplace'} = 1;
20547: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
20548: }
20549: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
20550: $changes{'categorizeplace'} = 1;
20551: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 20552: }
1.238 raeburn 20553: foreach my $item (@catitems) {
20554: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20555: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
20556: $changes{$item} = 1;
20557: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20558: }
20559: }
20560: }
1.57 raeburn 20561: } else {
20562: $changes{'togglecats'} = 1;
20563: $changes{'categorize'} = 1;
1.124 raeburn 20564: $changes{'togglecatscomm'} = 1;
20565: $changes{'categorizecomm'} = 1;
1.272 raeburn 20566: $changes{'togglecatsplace'} = 1;
20567: $changes{'categorizeplace'} = 1;
1.87 raeburn 20568: $domconfig{'coursecategories'} = {
20569: togglecats => $env{'form.togglecats'},
20570: categorize => $env{'form.categorize'},
1.124 raeburn 20571: togglecatscomm => $env{'form.togglecatscomm'},
20572: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 20573: togglecatsplace => $env{'form.togglecatsplace'},
20574: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 20575: };
1.238 raeburn 20576: foreach my $item (@catitems) {
20577: if ($env{'form.coursecat_'.$item} ne 'std') {
20578: $changes{$item} = 1;
20579: }
20580: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20581: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20582: }
20583: }
1.57 raeburn 20584: }
20585: if (ref($cathash) eq 'HASH') {
20586: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 20587: push (@deletecategory,'instcode::0');
20588: }
1.120 raeburn 20589: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
20590: push(@deletecategory,'communities::0');
20591: }
1.272 raeburn 20592: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
20593: push(@deletecategory,'placement::0');
20594: }
1.48 raeburn 20595: }
1.57 raeburn 20596: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
20597: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20598: if (@deletecategory > 0) {
20599: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 20600: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 20601: foreach my $item (@deletecategory) {
1.57 raeburn 20602: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
20603: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 20604: $deletions{$item} = 1;
1.57 raeburn 20605: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 20606: }
20607: }
20608: }
1.57 raeburn 20609: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 20610: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 20611: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 20612: $reorderings{$item} = 1;
1.57 raeburn 20613: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 20614: }
20615: if ($env{'form.addcategory_name_'.$item} ne '') {
20616: my $newcat = $env{'form.addcategory_name_'.$item};
20617: my $newdepth = $depth+1;
20618: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20619: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 20620: $adds{$newitem} = 1;
20621: }
20622: if ($env{'form.subcat_'.$item} ne '') {
20623: my $newcat = $env{'form.subcat_'.$item};
20624: my $newdepth = $depth+1;
20625: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20626: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 20627: $adds{$newitem} = 1;
20628: }
20629: }
20630: }
20631: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 20632: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20633: my $newitem = 'instcode::0';
1.57 raeburn 20634: if ($cathash->{$newitem} eq '') {
20635: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20636: $adds{$newitem} = 1;
20637: }
20638: } else {
20639: my $newitem = 'instcode::0';
1.57 raeburn 20640: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20641: $adds{$newitem} = 1;
20642: }
20643: }
1.120 raeburn 20644: if ($env{'form.communities'} eq '1') {
20645: if (ref($cathash) eq 'HASH') {
20646: my $newitem = 'communities::0';
20647: if ($cathash->{$newitem} eq '') {
20648: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20649: $adds{$newitem} = 1;
20650: }
20651: } else {
20652: my $newitem = 'communities::0';
20653: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20654: $adds{$newitem} = 1;
20655: }
20656: }
1.272 raeburn 20657: if ($env{'form.placement'} eq '1') {
20658: if (ref($cathash) eq 'HASH') {
20659: my $newitem = 'placement::0';
20660: if ($cathash->{$newitem} eq '') {
20661: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20662: $adds{$newitem} = 1;
20663: }
20664: } else {
20665: my $newitem = 'placement::0';
20666: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20667: $adds{$newitem} = 1;
20668: }
20669: }
1.48 raeburn 20670: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 20671: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 20672: ($env{'form.addcategory_name'} ne 'communities') &&
20673: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 20674: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
20675: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
20676: $adds{$newitem} = 1;
20677: }
1.48 raeburn 20678: }
1.57 raeburn 20679: my $putresult;
1.48 raeburn 20680: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20681: if (keys(%deletions) > 0) {
20682: foreach my $key (keys(%deletions)) {
20683: if ($predelallitems{$key} ne '') {
20684: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
20685: }
20686: }
20687: }
20688: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 20689: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 20690: if (ref($chkcats[0]) eq 'ARRAY') {
20691: my $depth = 0;
20692: my $chg = 0;
20693: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
20694: my $name = $chkcats[0][$i];
20695: my $item;
20696: if ($name eq '') {
20697: $chg ++;
20698: } else {
20699: $item = &escape($name).'::0';
20700: if ($chg) {
1.57 raeburn 20701: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 20702: }
20703: $depth ++;
1.57 raeburn 20704: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 20705: $depth --;
20706: }
20707: }
20708: }
1.57 raeburn 20709: }
20710: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20711: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 20712: if ($putresult eq 'ok') {
1.57 raeburn 20713: my %title = (
1.120 raeburn 20714: togglecats => 'Show/Hide a course in catalog',
20715: categorize => 'Assign a category to a course',
20716: togglecatscomm => 'Show/Hide a community in catalog',
20717: categorizecomm => 'Assign a category to a community',
1.57 raeburn 20718: );
20719: my %level = (
1.120 raeburn 20720: dom => 'set in Domain ("Modify Course/Community")',
20721: crs => 'set in Course ("Course Configuration")',
20722: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 20723: none => 'No catalog',
20724: std => 'Standard catalog',
20725: domonly => 'Domain-only catalog',
20726: codesrch => 'Code search form',
1.57 raeburn 20727: );
1.48 raeburn 20728: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 20729: if ($changes{'togglecats'}) {
20730: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
20731: }
20732: if ($changes{'categorize'}) {
20733: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 20734: }
1.120 raeburn 20735: if ($changes{'togglecatscomm'}) {
20736: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
20737: }
20738: if ($changes{'categorizecomm'}) {
20739: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
20740: }
1.238 raeburn 20741: if ($changes{'unauth'}) {
20742: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
20743: }
20744: if ($changes{'auth'}) {
20745: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
20746: }
1.57 raeburn 20747: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20748: my $cathash;
20749: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
20750: $cathash = $domconfig{'coursecategories'}{'cats'};
20751: } else {
20752: $cathash = {};
20753: }
20754: my (@cats,@trails,%allitems);
20755: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
20756: if (keys(%deletions) > 0) {
20757: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
20758: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
20759: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
20760: }
20761: $resulttext .= '</ul></li>';
20762: }
20763: if (keys(%reorderings) > 0) {
20764: my %sort_by_trail;
20765: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
20766: foreach my $key (keys(%reorderings)) {
20767: if ($allitems{$key} ne '') {
20768: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20769: }
1.48 raeburn 20770: }
1.57 raeburn 20771: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20772: $resulttext .= '<li>'.$trails[$trail].'</li>';
20773: }
20774: $resulttext .= '</ul></li>';
1.48 raeburn 20775: }
1.57 raeburn 20776: if (keys(%adds) > 0) {
20777: my %sort_by_trail;
20778: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
20779: foreach my $key (keys(%adds)) {
20780: if ($allitems{$key} ne '') {
20781: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20782: }
20783: }
20784: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20785: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 20786: }
1.57 raeburn 20787: $resulttext .= '</ul></li>';
1.48 raeburn 20788: }
1.364 raeburn 20789: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
20790: if (ref($lastactref) eq 'HASH') {
20791: $lastactref->{'cats'} = 1;
20792: }
1.48 raeburn 20793: }
20794: $resulttext .= '</ul>';
1.239 raeburn 20795: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 20796: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
20797: if ($changes{'auth'}) {
20798: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
20799: }
20800: if ($changes{'unauth'}) {
20801: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
20802: }
20803: my $cachetime = 24*60*60;
20804: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 20805: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 20806: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 20807: }
20808: }
1.48 raeburn 20809: } else {
20810: $resulttext = '<span class="LC_error">'.
1.57 raeburn 20811: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 20812: }
20813: } else {
1.120 raeburn 20814: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 20815: }
20816: return $resulttext;
20817: }
20818:
1.69 raeburn 20819: sub modify_serverstatuses {
20820: my ($dom,%domconfig) = @_;
20821: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
20822: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
20823: %currserverstatus = %{$domconfig{'serverstatuses'}};
20824: }
20825: my @pages = &serverstatus_pages();
20826: foreach my $type (@pages) {
20827: $newserverstatus{$type}{'namedusers'} = '';
20828: $newserverstatus{$type}{'machines'} = '';
20829: if (defined($env{'form.'.$type.'_namedusers'})) {
20830: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
20831: my @okusers;
20832: foreach my $user (@users) {
20833: my ($uname,$udom) = split(/:/,$user);
20834: if (($udom =~ /^$match_domain$/) &&
20835: (&Apache::lonnet::domain($udom)) &&
20836: ($uname =~ /^$match_username$/)) {
20837: if (!grep(/^\Q$user\E/,@okusers)) {
20838: push(@okusers,$user);
20839: }
20840: }
20841: }
20842: if (@okusers > 0) {
20843: @okusers = sort(@okusers);
20844: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
20845: }
20846: }
20847: if (defined($env{'form.'.$type.'_machines'})) {
20848: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
20849: my @okmachines;
20850: foreach my $ip (@machines) {
20851: my @parts = split(/\./,$ip);
20852: next if (@parts < 4);
20853: my $badip = 0;
20854: for (my $i=0; $i<4; $i++) {
20855: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
20856: $badip = 1;
20857: last;
20858: }
20859: }
20860: if (!$badip) {
20861: push(@okmachines,$ip);
20862: }
20863: }
20864: @okmachines = sort(@okmachines);
20865: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
20866: }
20867: }
20868: my %serverstatushash = (
20869: serverstatuses => \%newserverstatus,
20870: );
20871: foreach my $type (@pages) {
1.83 raeburn 20872: foreach my $setting ('namedusers','machines') {
1.84 raeburn 20873: my (@current,@new);
1.83 raeburn 20874: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 20875: if ($currserverstatus{$type}{$setting} ne '') {
20876: @current = split(/,/,$currserverstatus{$type}{$setting});
20877: }
20878: }
20879: if ($newserverstatus{$type}{$setting} ne '') {
20880: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 20881: }
20882: if (@current > 0) {
20883: if (@new > 0) {
20884: foreach my $item (@current) {
20885: if (!grep(/^\Q$item\E$/,@new)) {
20886: $changes{$type}{$setting} = 1;
1.82 raeburn 20887: last;
20888: }
20889: }
1.84 raeburn 20890: foreach my $item (@new) {
20891: if (!grep(/^\Q$item\E$/,@current)) {
20892: $changes{$type}{$setting} = 1;
20893: last;
1.82 raeburn 20894: }
20895: }
20896: } else {
1.83 raeburn 20897: $changes{$type}{$setting} = 1;
1.69 raeburn 20898: }
1.83 raeburn 20899: } elsif (@new > 0) {
20900: $changes{$type}{$setting} = 1;
1.69 raeburn 20901: }
20902: }
20903: }
20904: if (keys(%changes) > 0) {
1.81 raeburn 20905: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 20906: my $putresult = &Apache::lonnet::put_dom('configuration',
20907: \%serverstatushash,$dom);
20908: if ($putresult eq 'ok') {
20909: $resulttext .= &mt('Changes made:').'<ul>';
20910: foreach my $type (@pages) {
1.84 raeburn 20911: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 20912: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 20913: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 20914: if ($newserverstatus{$type}{'namedusers'} eq '') {
20915: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
20916: } else {
20917: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
20918: }
1.84 raeburn 20919: }
20920: if ($changes{$type}{'machines'}) {
1.69 raeburn 20921: if ($newserverstatus{$type}{'machines'} eq '') {
20922: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
20923: } else {
20924: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
20925: }
20926:
20927: }
20928: $resulttext .= '</ul></li>';
20929: }
20930: }
20931: $resulttext .= '</ul>';
20932: } else {
20933: $resulttext = '<span class="LC_error">'.
20934: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
20935:
20936: }
20937: } else {
20938: $resulttext = &mt('No changes made to access to server status pages');
20939: }
20940: return $resulttext;
20941: }
20942:
1.118 jms 20943: sub modify_helpsettings {
1.285 raeburn 20944: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 20945: my ($resulttext,$errors,%changes,%helphash);
20946: my %defaultchecked = ('submitbugs' => 'on');
20947: my @offon = ('off','on');
1.118 jms 20948: my @toggles = ('submitbugs');
1.285 raeburn 20949: my %current = ('submitbugs' => '',
20950: 'adhoc' => {},
20951: );
1.118 jms 20952: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 20953: %current = %{$domconfig{'helpsettings'}};
20954: }
1.285 raeburn 20955: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 20956: foreach my $item (@toggles) {
20957: if ($defaultchecked{$item} eq 'on') {
20958: if ($current{$item} eq '') {
20959: if ($env{'form.'.$item} eq '0') {
20960: $changes{$item} = 1;
20961: }
20962: } elsif ($current{$item} ne $env{'form.'.$item}) {
20963: $changes{$item} = 1;
20964: }
20965: } elsif ($defaultchecked{$item} eq 'off') {
20966: if ($current{$item} eq '') {
20967: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 20968: $changes{$item} = 1;
20969: }
1.282 raeburn 20970: } elsif ($current{$item} ne $env{'form.'.$item}) {
20971: $changes{$item} = 1;
20972: }
20973: }
20974: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
20975: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
20976: }
20977: }
1.285 raeburn 20978: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 20979: my $confname = $dom.'-domainconfig';
20980: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 20981: my (@allpos,%newsettings,%changedprivs,$newrole);
20982: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 20983: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 20984: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 20985: my %lt = &Apache::lonlocal::texthash(
20986: s => 'system',
20987: d => 'domain',
20988: order => 'Display order',
20989: access => 'Role usage',
1.291 raeburn 20990: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 20991: dh => 'All with domain helpdesk role',
20992: da => 'All with domain helpdesk assistant role',
1.285 raeburn 20993: none => 'None',
20994: status => 'Determined based on institutional status',
20995: inc => 'Include all, but exclude specific personnel',
20996: exc => 'Exclude all, but include specific personnel',
20997: );
20998: for (my $num=0; $num<=$maxnum; $num++) {
20999: my ($prefix,$identifier,$rolename,%curr);
21000: if ($num == $maxnum) {
21001: next unless ($env{'form.newcusthelp'} == $maxnum);
21002: $identifier = 'custhelp'.$num;
21003: $prefix = 'helproles_'.$num;
21004: $rolename = $env{'form.custhelpname'.$num};
21005: $rolename=~s/[^A-Za-z0-9]//gs;
21006: next if ($rolename eq '');
21007: next if (exists($existing{'rolesdef_'.$rolename}));
21008: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
21009: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
21010: $newprivs{'c'},$confname,$dom);
21011: if ($result ne 'ok') {
21012: $errors .= '<li><span class="LC_error">'.
21013: &mt('An error occurred storing the new custom role: [_1]',
21014: $result).'</span></li>';
21015: next;
21016: } else {
21017: $changedprivs{$rolename} = \%newprivs;
21018: $newrole = $rolename;
21019: }
21020: } else {
21021: $prefix = 'helproles_'.$num;
21022: $rolename = $env{'form.'.$prefix};
21023: next if ($rolename eq '');
21024: next unless (exists($existing{'rolesdef_'.$rolename}));
21025: $identifier = 'custhelp'.$num;
21026: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
21027: my %currprivs;
1.289 raeburn 21028: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 21029: split(/\_/,$existing{'rolesdef_'.$rolename});
21030: foreach my $level ('c','d','s') {
21031: if ($newprivs{$level} ne $currprivs{$level}) {
21032: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
21033: $newprivs{'c'},$confname,$dom);
21034: if ($result ne 'ok') {
21035: $errors .= '<li><span class="LC_error">'.
21036: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
21037: $rolename,$result).'</span></li>';
21038: } else {
21039: $changedprivs{$rolename} = \%newprivs;
21040: }
21041: last;
21042: }
21043: }
21044: if (ref($current{'adhoc'}) eq 'HASH') {
21045: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
21046: %curr = %{$current{'adhoc'}{$rolename}};
21047: }
21048: }
21049: }
21050: my $newpos = $env{'form.'.$prefix.'_pos'};
21051: $newpos =~ s/\D+//g;
21052: $allpos[$newpos] = $rolename;
21053: my $newdesc = $env{'form.'.$prefix.'_desc'};
21054: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
21055: if ($curr{'desc'}) {
21056: if ($curr{'desc'} ne $newdesc) {
21057: $changes{'customrole'}{$rolename}{'desc'} = 1;
21058: $newsettings{$rolename}{'desc'} = $newdesc;
21059: }
21060: } elsif ($newdesc ne '') {
21061: $changes{'customrole'}{$rolename}{'desc'} = 1;
21062: $newsettings{$rolename}{'desc'} = $newdesc;
21063: }
21064: my $access = $env{'form.'.$prefix.'_access'};
21065: if (grep(/^\Q$access\E$/,@accesstypes)) {
21066: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
21067: if ($access eq 'status') {
21068: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
21069: if (scalar(@statuses) == 0) {
1.289 raeburn 21070: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 21071: } else {
21072: my (@shownstatus,$numtypes);
21073: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
21074: if (ref($types) eq 'ARRAY') {
21075: $numtypes = scalar(@{$types});
21076: foreach my $type (sort(@statuses)) {
21077: if ($type eq 'default') {
21078: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
21079: } elsif (grep(/^\Q$type\E$/,@{$types})) {
21080: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
21081: push(@shownstatus,$usertypes->{$type});
21082: }
21083: }
21084: }
21085: if (grep(/^default$/,@statuses)) {
21086: push(@shownstatus,$othertitle);
21087: }
21088: if (scalar(@shownstatus) == 1+$numtypes) {
21089: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
21090: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
21091: } else {
21092: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
21093: if (ref($curr{'status'}) eq 'ARRAY') {
21094: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
21095: if (@diffs) {
21096: $changes{'customrole'}{$rolename}{$access} = 1;
21097: }
21098: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21099: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 21100: }
1.166 raeburn 21101: }
21102: }
1.285 raeburn 21103: } elsif (($access eq 'inc') || ($access eq 'exc')) {
21104: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
21105: my @newspecstaff;
21106: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
21107: foreach my $person (sort(@personnel)) {
21108: if ($domhelpdesk{$person}) {
21109: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
21110: }
21111: }
21112: if (ref($curr{$access}) eq 'ARRAY') {
21113: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
21114: if (@diffs) {
21115: $changes{'customrole'}{$rolename}{$access} = 1;
21116: }
21117: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21118: $changes{'customrole'}{$rolename}{$access} = 1;
21119: }
21120: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21121: my ($uname,$udom) = split(/:/,$person);
21122: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
21123: }
21124: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 21125: }
1.285 raeburn 21126: } else {
21127: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
21128: }
21129: unless ($curr{'access'} eq $access) {
21130: $changes{'customrole'}{$rolename}{'access'} = 1;
21131: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 21132: }
21133: }
1.285 raeburn 21134: if (@allpos > 0) {
21135: my $idx = 0;
21136: foreach my $rolename (@allpos) {
21137: if ($rolename ne '') {
21138: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
21139: if (ref($current{'adhoc'}) eq 'HASH') {
21140: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
21141: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
21142: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 21143: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 21144: }
21145: }
1.282 raeburn 21146: }
1.285 raeburn 21147: $idx ++;
1.166 raeburn 21148: }
21149: }
1.118 jms 21150: }
1.123 jms 21151: my $putresult;
21152: if (keys(%changes) > 0) {
1.166 raeburn 21153: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 21154: if ($putresult eq 'ok') {
1.285 raeburn 21155: if (ref($helphash{'helpsettings'}) eq 'HASH') {
21156: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
21157: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
21158: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
21159: }
21160: }
21161: my $cachetime = 24*60*60;
21162: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21163: if (ref($lastactref) eq 'HASH') {
21164: $lastactref->{'domdefaults'} = 1;
21165: }
21166: } else {
21167: $errors .= '<li><span class="LC_error">'.
21168: &mt('An error occurred storing the settings: [_1]',
21169: $putresult).'</span></li>';
21170: }
21171: }
21172: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
21173: $resulttext = &mt('Changes made:').'<ul>';
21174: my (%shownprivs,@levelorder);
21175: @levelorder = ('c','d','s');
21176: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 21177: foreach my $item (sort(keys(%changes))) {
21178: if ($item eq 'submitbugs') {
21179: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
21180: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
21181: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 21182: } elsif ($item eq 'customrole') {
21183: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 21184: my @keyorder = ('order','desc','access','status','exc','inc');
21185: my %keytext = &Apache::lonlocal::texthash(
21186: order => 'Order',
21187: desc => 'Role description',
21188: access => 'Role usage',
1.300 droeschl 21189: status => 'Allowed institutional types',
1.285 raeburn 21190: exc => 'Allowed personnel',
21191: inc => 'Disallowed personnel',
21192: );
1.282 raeburn 21193: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 21194: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
21195: if ($role eq $newrole) {
21196: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
21197: $role).'<ul>';
21198: } else {
21199: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
21200: $role).'<ul>';
21201: }
21202: foreach my $key (@keyorder) {
21203: if ($changes{'customrole'}{$role}{$key}) {
21204: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
21205: $keytext{$key},$newsettings{$role}{$key}).
21206: '</li>';
21207: }
21208: }
21209: if (ref($changedprivs{$role}) eq 'HASH') {
21210: $shownprivs{$role} = 1;
21211: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
21212: foreach my $level (@levelorder) {
21213: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
21214: next if ($item eq '');
21215: my ($priv) = split(/\&/,$item,2);
21216: if (&Apache::lonnet::plaintext($priv)) {
21217: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
21218: unless ($level eq 'c') {
21219: $resulttext .= ' ('.$lt{$level}.')';
21220: }
21221: $resulttext .= '</li>';
21222: }
21223: }
21224: }
21225: $resulttext .= '</ul>';
21226: }
21227: $resulttext .= '</ul></li>';
21228: }
21229: }
21230: }
21231: }
21232: }
21233: }
21234: if (keys(%changedprivs)) {
21235: foreach my $role (sort(keys(%changedprivs))) {
21236: unless ($shownprivs{$role}) {
21237: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
21238: $role).'<ul>'.
21239: '<li>'.&mt('Privileges set to :').'<ul>';
21240: foreach my $level (@levelorder) {
21241: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
21242: next if ($item eq '');
21243: my ($priv) = split(/\&/,$item,2);
21244: if (&Apache::lonnet::plaintext($priv)) {
21245: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
21246: unless ($level eq 'c') {
21247: $resulttext .= ' ('.$lt{$level}.')';
21248: }
21249: $resulttext .= '</li>';
21250: }
1.282 raeburn 21251: }
21252: }
1.285 raeburn 21253: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 21254: }
21255: }
21256: }
1.285 raeburn 21257: $resulttext .= '</ul>';
21258: } else {
21259: $resulttext = &mt('No changes made to help settings');
1.118 jms 21260: }
21261: if ($errors) {
1.168 raeburn 21262: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 21263: $errors.'</ul>';
1.118 jms 21264: }
21265: return $resulttext;
21266: }
21267:
1.121 raeburn 21268: sub modify_coursedefaults {
1.212 raeburn 21269: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 21270: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 21271: my %defaultchecked = (
21272: 'canuse_pdfforms' => 'off',
21273: 'uselcmath' => 'on',
1.398 raeburn 21274: 'usejsme' => 'on',
21275: 'inline_chem' => 'on',
1.404 raeburn 21276: 'ltiauth' => 'off',
1.257 raeburn 21277: );
1.404 raeburn 21278: my @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem','ltiauth');
1.198 raeburn 21279: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 21280: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
1.428 raeburn 21281: 'coursequota_official','coursequota_unofficial','coursequota_community',
21282: 'coursequota_textbook','coursequota_placement','mysqltables_official',
21283: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook',
21284: 'mysqltables_placement');
1.271 raeburn 21285: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 21286: my %staticdefaults = (
21287: anonsurvey_threshold => 10,
21288: uploadquota => 500,
1.428 raeburn 21289: coursequota => 20,
1.257 raeburn 21290: postsubmit => 60,
1.276 raeburn 21291: mysqltables => 172800,
1.422 raeburn 21292: domexttool => 1,
1.432 raeburn 21293: crsauthor => 1,
1.438 raeburn 21294: crseditors => ['edit','xml'],
1.198 raeburn 21295: );
1.314 raeburn 21296: my %texoptions = (
21297: MathJax => 'MathJax',
21298: mimetex => &mt('Convert to Images'),
21299: tth => &mt('TeX to HTML'),
21300: );
1.438 raeburn 21301:
21302: my @editors = ('edit','xml','daxe');
21303: my %editornames = &crseditor_titles();
21304:
1.121 raeburn 21305: $defaultshash{'coursedefaults'} = {};
21306:
21307: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
21308: if ($domconfig{'coursedefaults'} eq '') {
21309: $domconfig{'coursedefaults'} = {};
21310: }
21311: }
21312:
21313: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
21314: foreach my $item (@toggles) {
21315: if ($defaultchecked{$item} eq 'on') {
21316: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21317: ($env{'form.'.$item} eq '0')) {
21318: $changes{$item} = 1;
1.192 raeburn 21319: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 21320: $changes{$item} = 1;
21321: }
21322: } elsif ($defaultchecked{$item} eq 'off') {
21323: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21324: ($env{'form.'.$item} eq '1')) {
21325: $changes{$item} = 1;
21326: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
21327: $changes{$item} = 1;
21328: }
21329: }
21330: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
21331: }
1.198 raeburn 21332: foreach my $item (@numbers) {
21333: my ($currdef,$newdef);
1.208 raeburn 21334: $newdef = $env{'form.'.$item};
1.198 raeburn 21335: if ($item eq 'anonsurvey_threshold') {
21336: $currdef = $domconfig{'coursedefaults'}{$item};
21337: $newdef =~ s/\D//g;
21338: if ($newdef eq '' || $newdef < 1) {
21339: $newdef = 1;
21340: }
21341: $defaultshash{'coursedefaults'}{$item} = $newdef;
21342: } else {
1.428 raeburn 21343: my ($setting,$type) = ($item =~ /^(uploadquota|coursequota|mysqltables)_(\w+)$/);
1.276 raeburn 21344: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
21345: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 21346: }
21347: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 21348: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 21349: }
21350: if ($currdef ne $newdef) {
21351: if ($item eq 'anonsurvey_threshold') {
21352: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
21353: $changes{$item} = 1;
21354: }
1.428 raeburn 21355: } elsif ($item =~ /^(uploadquota|coursequota|mysqltables)_/) {
1.289 raeburn 21356: my $setting = $1;
1.276 raeburn 21357: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
21358: $changes{$setting} = 1;
1.198 raeburn 21359: }
21360: }
1.139 raeburn 21361: }
21362: }
1.314 raeburn 21363: my $texengine;
21364: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
21365: $texengine = $env{'form.texengine'};
1.349 raeburn 21366: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
21367: if ($currdef eq '') {
21368: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 21369: $changes{'texengine'} = 1;
21370: }
1.349 raeburn 21371: } elsif ($currdef ne $texengine) {
1.314 raeburn 21372: $changes{'texengine'} = 1;
21373: }
21374: }
21375: if ($texengine ne '') {
21376: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
21377: }
1.264 raeburn 21378: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
21379: my @currclonecode;
21380: if (ref($currclone) eq 'HASH') {
21381: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
21382: @currclonecode = @{$currclone->{'instcode'}};
21383: }
21384: }
21385: my $newclone;
1.289 raeburn 21386: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 21387: $newclone = $env{'form.canclone'};
21388: }
21389: if ($newclone eq 'instcode') {
21390: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
21391: my (%codedefaults,@code_order,@clonecode);
21392: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
21393: \@code_order);
21394: foreach my $item (@code_order) {
21395: if (grep(/^\Q$item\E$/,@newcodes)) {
21396: push(@clonecode,$item);
21397: }
21398: }
21399: if (@clonecode) {
21400: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
21401: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
21402: if (@diffs) {
21403: $changes{'canclone'} = 1;
21404: }
21405: } else {
21406: $newclone eq '';
21407: }
21408: } elsif ($newclone ne '') {
1.289 raeburn 21409: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
21410: }
1.264 raeburn 21411: if ($newclone ne $currclone) {
21412: $changes{'canclone'} = 1;
21413: }
1.257 raeburn 21414: my %credits;
21415: foreach my $type (@types) {
21416: unless ($type eq 'community') {
21417: $credits{$type} = $env{'form.'.$type.'_credits'};
21418: $credits{$type} =~ s/[^\d.]+//g;
21419: }
21420: }
21421: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
21422: ($env{'form.coursecredits'} eq '1')) {
21423: $changes{'coursecredits'} = 1;
21424: foreach my $type (keys(%credits)) {
21425: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21426: }
21427: } else {
1.289 raeburn 21428: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 21429: foreach my $type (@types) {
21430: unless ($type eq 'community') {
1.289 raeburn 21431: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 21432: $changes{'coursecredits'} = 1;
21433: }
21434: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21435: }
21436: }
21437: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21438: foreach my $type (@types) {
21439: unless ($type eq 'community') {
21440: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
21441: $changes{'coursecredits'} = 1;
21442: last;
21443: }
21444: }
21445: }
21446: }
21447: }
21448: if ($env{'form.postsubmit'} eq '1') {
21449: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
21450: my %currtimeout;
21451: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21452: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
21453: $changes{'postsubmit'} = 1;
21454: }
21455: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21456: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
21457: }
21458: } else {
21459: $changes{'postsubmit'} = 1;
21460: }
21461: foreach my $type (@types) {
21462: my $timeout = $env{'form.'.$type.'_timeout'};
21463: $timeout =~ s/\D//g;
21464: if ($timeout == $staticdefaults{'postsubmit'}) {
21465: $timeout = '';
21466: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
21467: $timeout = '0';
21468: }
21469: unless ($timeout eq '') {
21470: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
21471: }
21472: if (exists($currtimeout{$type})) {
21473: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 21474: $changes{'postsubmit'} = 1;
1.257 raeburn 21475: }
21476: } elsif ($timeout ne '') {
21477: $changes{'postsubmit'} = 1;
21478: }
21479: }
21480: } else {
21481: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
21482: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21483: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
21484: $changes{'postsubmit'} = 1;
21485: }
21486: } else {
21487: $changes{'postsubmit'} = 1;
21488: }
1.192 raeburn 21489: }
1.438 raeburn 21490: my (%newdomexttool,%newexttool,%newcrsauthor,%olddomexttool,%oldexttool,%oldcrsauthor,
21491: %posscrseditors);
1.422 raeburn 21492: map { $newdomexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.domexttool');
1.425 raeburn 21493: map { $newexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.exttool');
1.432 raeburn 21494: map { $newcrsauthor{$_} = 1; } &Apache::loncommon::get_env_multiple('form.crsauthor');
1.438 raeburn 21495: map { $posscrseditors{$_} = 1; } &Apache::loncommon::get_env_multiple('form.crseditors');
1.422 raeburn 21496: if (ref($domconfig{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21497: %olddomexttool = %{$domconfig{'coursedefaults'}{'domexttool'}};
21498: } else {
21499: foreach my $type (@types) {
21500: if ($staticdefaults{'domexttool'}) {
21501: $olddomexttool{$type} = 1;
21502: } else {
21503: $olddomexttool{$type} = 0;
21504: }
21505: }
21506: }
21507: if (ref($domconfig{'coursedefaults'}{'exttool'}) eq 'HASH') {
1.425 raeburn 21508: %oldexttool = %{$domconfig{'coursedefaults'}{'exttool'}};
1.422 raeburn 21509: } else {
21510: foreach my $type (@types) {
21511: if ($staticdefaults{'exttool'}) {
21512: $oldexttool{$type} = 1;
21513: } else {
21514: $oldexttool{$type} = 0;
21515: }
21516: }
21517: }
1.432 raeburn 21518: if (ref($domconfig{'coursedefaults'}{'crsauthor'}) eq 'HASH') {
21519: %oldcrsauthor = %{$domconfig{'coursedefaults'}{'crsauthor'}};
21520: } else {
21521: foreach my $type (@types) {
21522: if ($staticdefaults{'crsauthor'}) {
21523: $oldcrsauthor{$type} = 1;
21524: } else {
21525: $oldcrsauthor{$type} = 0;
21526: }
21527: }
21528: }
1.438 raeburn 21529: my @newcrseditors = ();
21530: foreach my $editor (@editors) {
21531: if ($posscrseditors{$editor}) {
21532: push(@newcrseditors,$editor);
21533: }
21534: }
21535: if (ref($domconfig{'coursedefaults'}{'crseditors'}) eq 'ARRAY') {
21536: my @diffs =
21537: &Apache::loncommon::compare_arrays($domconfig{'coursedefaults'}{'crseditors'},
21538: \@newcrseditors);
21539: if (@diffs) {
21540: $changes{'crseditors'} = 1;
21541: }
21542: } else {
21543: my @diffs =
21544: &Apache::loncommon::compare_arrays($staticdefaults{'crseditors'},
21545: \@newcrseditors);
21546: unless (@diffs == 0) {
21547: $changes{'crseditors'} = 1;
21548: }
21549: }
1.422 raeburn 21550: foreach my $type (@types) {
21551: unless ($newdomexttool{$type}) {
21552: $newdomexttool{$type} = 0;
21553: }
21554: unless ($newexttool{$type}) {
21555: $newexttool{$type} = 0;
21556: }
1.432 raeburn 21557: unless ($newcrsauthor{$type}) {
21558: $newcrsauthor{$type} = 0;
21559: }
1.422 raeburn 21560: if ($newdomexttool{$type} != $olddomexttool{$type}) {
21561: $changes{'domexttool'} = 1;
21562: }
21563: if ($newexttool{$type} != $oldexttool{$type}) {
21564: $changes{'exttool'} = 1;
21565: }
1.432 raeburn 21566: if ($newcrsauthor{$type} != $oldcrsauthor{$type}) {
21567: $changes{'crsauthor'} = 1;
21568: }
1.422 raeburn 21569: }
21570: $defaultshash{'coursedefaults'}{'domexttool'} = \%newdomexttool;
21571: $defaultshash{'coursedefaults'}{'exttool'} = \%newexttool;
1.432 raeburn 21572: $defaultshash{'coursedefaults'}{'crsauthor'} = \%newcrsauthor;
1.438 raeburn 21573: $defaultshash{'coursedefaults'}{'crseditors'} = \@newcrseditors;
1.121 raeburn 21574: }
21575: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21576: $dom);
21577: if ($putresult eq 'ok') {
21578: if (keys(%changes) > 0) {
1.213 raeburn 21579: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 21580: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 21581: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.398 raeburn 21582: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
1.422 raeburn 21583: ($changes{'inline_chem'}) || ($changes{'ltiauth'}) || ($changes{'domexttool'}) ||
1.432 raeburn 21584: ($changes{'exttool'}) || ($changes{'coursequota'}) || ($changes{'crsauthor'})) {
1.422 raeburn 21585: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','inline_chem','texengine',
21586: 'ltiauth') {
1.257 raeburn 21587: if ($changes{$item}) {
21588: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
21589: }
1.289 raeburn 21590: }
1.192 raeburn 21591: if ($changes{'coursecredits'}) {
21592: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 21593: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
21594: $domdefaults{$type.'credits'} =
21595: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
21596: }
21597: }
21598: }
21599: if ($changes{'postsubmit'}) {
21600: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21601: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
21602: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21603: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
21604: $domdefaults{$type.'postsubtimeout'} =
21605: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21606: }
21607: }
1.192 raeburn 21608: }
21609: }
1.198 raeburn 21610: if ($changes{'uploadquota'}) {
21611: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21612: foreach my $type (@types) {
21613: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
21614: }
21615: }
21616: }
1.428 raeburn 21617: if ($changes{'coursequota'}) {
21618: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
21619: foreach my $type (@types) {
21620: $domdefaults{$type.'coursequota'}=$defaultshash{'coursedefaults'}{'coursequota'}{$type};
21621: }
21622: }
21623: }
1.264 raeburn 21624: if ($changes{'canclone'}) {
21625: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21626: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21627: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
21628: if (@clonecodes) {
21629: $domdefaults{'canclone'} = join('+',@clonecodes);
21630: }
21631: }
21632: } else {
21633: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
21634: }
21635: }
1.422 raeburn 21636: if ($changes{'domexttool'}) {
21637: if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21638: foreach my $type (@types) {
21639: $domdefaults{$type.'domexttool'}=$defaultshash{'coursedefaults'}{'domexttool'}{$type};
21640: }
21641: }
21642: }
21643: if ($changes{'exttool'}) {
21644: if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
21645: foreach my $type (@types) {
21646: $domdefaults{$type.'exttool'}=$defaultshash{'coursedefaults'}{'exttool'}{$type};
21647: }
21648: }
21649: }
1.432 raeburn 21650: if ($changes{'crsauthor'}) {
21651: if (ref($defaultshash{'coursedefaults'}{'crsauthor'}) eq 'HASH') {
21652: foreach my $type (@types) {
21653: $domdefaults{$type.'crsauthor'}=$defaultshash{'coursedefaults'}{'crsauthor'}{$type};
21654: }
21655: }
21656: }
1.438 raeburn 21657: if ($changes{'crseditors'}) {
21658: if (ref($defaultshash{'coursedefaults'}{'crseditors'}) eq 'ARRAY') {
21659: $domdefaults{'crseditors'}=join(',',@{$defaultshash{'coursedefaults'}{'crseditors'}});
21660: }
21661: }
1.121 raeburn 21662: my $cachetime = 24*60*60;
21663: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 21664: if (ref($lastactref) eq 'HASH') {
21665: $lastactref->{'domdefaults'} = 1;
21666: }
1.121 raeburn 21667: }
21668: $resulttext = &mt('Changes made:').'<ul>';
21669: foreach my $item (sort(keys(%changes))) {
21670: if ($item eq 'canuse_pdfforms') {
21671: if ($env{'form.'.$item} eq '1') {
21672: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
21673: } else {
21674: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
21675: }
1.257 raeburn 21676: } elsif ($item eq 'uselcmath') {
21677: if ($env{'form.'.$item} eq '1') {
21678: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
21679: } else {
21680: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
21681: }
21682: } elsif ($item eq 'usejsme') {
21683: if ($env{'form.'.$item} eq '1') {
21684: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
21685: } else {
1.289 raeburn 21686: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 21687: }
1.398 raeburn 21688: } elsif ($item eq 'inline_chem') {
21689: if ($env{'form.'.$item} eq '1') {
21690: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
21691: } else {
21692: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
21693: }
1.314 raeburn 21694: } elsif ($item eq 'texengine') {
21695: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
21696: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
21697: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
21698: }
1.139 raeburn 21699: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 21700: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 21701: } elsif ($item eq 'uploadquota') {
21702: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21703: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
21704: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
21705: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 21706: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 21707: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 21708: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
21709: '</ul>'.
21710: '</li>';
21711: } else {
21712: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
21713: }
1.428 raeburn 21714: } elsif ($item eq 'coursequota') {
21715: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
21716: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course set as follows:').'<ul>'.
21717: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'official'}.'</b>').'</li>'.
21718: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'unofficial'}.'</b>').'</li>'.
21719: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'textbook'}.'</b>').'</li>'.
21720: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'placement'}.'</b>').'</li>'.
21721: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'community'}.'</b>').'</li>'.
21722: '</ul>'.
21723: '</li>';
21724: } else {
21725: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course remains default: [_1] MB',$staticdefaults{'coursequota'}).'</li>';
21726: }
1.276 raeburn 21727: } elsif ($item eq 'mysqltables') {
21728: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
21729: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
21730: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
21731: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
21732: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
21733: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
21734: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
21735: '</ul>'.
21736: '</li>';
21737: } else {
21738: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
21739: }
1.257 raeburn 21740: } elsif ($item eq 'postsubmit') {
21741: if ($domdefaults{'postsubmit'} eq 'off') {
21742: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
21743: } else {
21744: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 21745: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 21746: $resulttext .= &mt('durations:').'<ul>';
21747: foreach my $type (@types) {
21748: $resulttext .= '<li>';
21749: my $timeout;
21750: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21751: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21752: }
21753: my $display;
21754: if ($timeout eq '0') {
21755: $display = &mt('unlimited');
21756: } elsif ($timeout eq '') {
21757: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
21758: } else {
21759: $display = &mt('[quant,_1,second]',$timeout);
21760: }
21761: if ($type eq 'community') {
21762: $resulttext .= &mt('Communities');
21763: } elsif ($type eq 'official') {
21764: $resulttext .= &mt('Official courses');
21765: } elsif ($type eq 'unofficial') {
21766: $resulttext .= &mt('Unofficial courses');
21767: } elsif ($type eq 'textbook') {
21768: $resulttext .= &mt('Textbook courses');
1.271 raeburn 21769: } elsif ($type eq 'placement') {
21770: $resulttext .= &mt('Placement tests');
1.257 raeburn 21771: }
21772: $resulttext .= ' -- '.$display.'</li>';
21773: }
21774: $resulttext .= '</ul>';
21775: }
1.289 raeburn 21776: $resulttext .= '</li>';
1.257 raeburn 21777: }
1.192 raeburn 21778: } elsif ($item eq 'coursecredits') {
21779: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21780: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 21781: ($domdefaults{'unofficialcredits'} eq '') &&
21782: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 21783: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21784: } else {
21785: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
21786: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
21787: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 21788: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 21789: '</ul>'.
21790: '</li>';
21791: }
21792: } else {
21793: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21794: }
1.264 raeburn 21795: } elsif ($item eq 'canclone') {
21796: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21797: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21798: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
21799: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
21800: }
21801: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
21802: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
21803: } else {
1.289 raeburn 21804: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 21805: }
1.404 raeburn 21806: } elsif ($item eq 'ltiauth') {
21807: if ($env{'form.'.$item} eq '1') {
21808: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
21809: } else {
21810: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
21811: }
1.432 raeburn 21812: } elsif (($item eq 'domexttool') || ($item eq 'exttool') || ($item eq 'crsauthor')) {
1.422 raeburn 21813: my @noyes = (&mt('no'),&mt('yes'));
1.432 raeburn 21814: my %status = (
21815: domexttool => {
21816: ishash => &mt('External Tools defined in the domain may be used as follows:'),
21817: default => &mt('External Tools defined in the domain may be used in all course types, by default'),
21818: },
21819: exttool => {
21820: ishash => &mt('External Tools can be defined and configured in course containers as follows:'),
21821: default => &mt('External Tools can not be defined in any course types, by default'),
21822: },
21823: crsauthor => {
21824: ishash => &mt('Standard Problems can be created within course containers as follows:'),
21825: default => &mt('Standard Problems can be created within any course type, by default'),
21826: },
21827: );
21828:
21829: if (ref($defaultshash{'coursedefaults'}{$item}) eq 'HASH') {
21830: $resulttext .= '<li>'.$status{$item}{'ishash'}.'<ul>'.
21831: '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'official'}].'</b>').'</li>'.
21832: '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'unofficial'}].'</b>').'</li>'.
21833: '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'textbook'}].'</b>').'</li>'.
21834: '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'placement'}].'</b>').'</li>'.
21835: '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'community'}].'</b>').'</li>'.
1.422 raeburn 21836: '</ul>'.
21837: '</li>';
21838: } else {
1.432 raeburn 21839: $resulttext .= '<li>'.$status{$item}{'default'}.'</li>';
1.422 raeburn 21840: }
1.438 raeburn 21841: } elsif ($item eq 'crseditors') {
21842: if (ref($defaultshash{'coursedefaults'}{$item}) eq 'ARRAY') {
21843: my $shown;
21844: if (@{$defaultshash{'coursedefaults'}{$item}}) {
21845: $shown = join(', ', map { $editornames{$_} } @{$defaultshash{'coursedefaults'}{$item}});
21846: } else {
21847: $shown = &mt('None');
21848: }
21849: $resulttext .= '<li>'.&mt('Available editors for course/community resources: [_1]',$shown).'</li>';
21850: }
1.140 raeburn 21851: }
1.121 raeburn 21852: }
21853: $resulttext .= '</ul>';
21854: } else {
21855: $resulttext = &mt('No changes made to course defaults');
21856: }
21857: } else {
21858: $resulttext = '<span class="LC_error">'.
21859: &mt('An error occurred: [_1]',$putresult).'</span>';
21860: }
21861: return $resulttext;
21862: }
21863:
1.231 raeburn 21864: sub modify_selfenrollment {
21865: my ($dom,$lastactref,%domconfig) = @_;
21866: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 21867: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 21868: my %titles = &tool_titles();
1.232 raeburn 21869: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
21870: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 21871: $ordered{'default'} = ['types','registered','approval','limit'];
21872:
21873: my (%roles,%shown,%toplevel);
21874: $roles{'0'} = &Apache::lonnet::plaintext('dc');
21875:
21876: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
21877: if ($domconfig{'selfenrollment'} eq '') {
21878: $domconfig{'selfenrollment'} = {};
21879: }
21880: }
21881: %toplevel = (
21882: admin => 'Configuration Rights',
21883: default => 'Default settings',
21884: validation => 'Validation of self-enrollment requests',
21885: );
1.233 raeburn 21886: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 21887:
21888: if (ref($ordered{'admin'}) eq 'ARRAY') {
21889: foreach my $item (@{$ordered{'admin'}}) {
21890: foreach my $type (@types) {
21891: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
21892: $selfenrollhash{'admin'}{$type}{$item} = 1;
21893: } else {
21894: $selfenrollhash{'admin'}{$type}{$item} = 0;
21895: }
21896: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
21897: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
21898: if ($selfenrollhash{'admin'}{$type}{$item} ne
21899: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
21900: push(@{$changes{'admin'}{$type}},$item);
21901: }
21902: } else {
21903: if (!$selfenrollhash{'admin'}{$type}{$item}) {
21904: push(@{$changes{'admin'}{$type}},$item);
21905: }
21906: }
21907: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
21908: push(@{$changes{'admin'}{$type}},$item);
21909: }
21910: }
21911: }
21912: }
21913:
21914: foreach my $item (@{$ordered{'default'}}) {
21915: foreach my $type (@types) {
21916: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
21917: if ($item eq 'types') {
21918: unless (($value eq 'all') || ($value eq 'dom')) {
21919: $value = '';
21920: }
21921: } elsif ($item eq 'registered') {
21922: unless ($value eq '1') {
21923: $value = 0;
21924: }
21925: } elsif ($item eq 'approval') {
21926: unless ($value =~ /^[012]$/) {
21927: $value = 0;
21928: }
21929: } else {
21930: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21931: $value = 'none';
21932: }
21933: }
21934: $selfenrollhash{'default'}{$type}{$item} = $value;
21935: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
21936: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21937: if ($selfenrollhash{'default'}{$type}{$item} ne
21938: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
21939: push(@{$changes{'default'}{$type}},$item);
21940: }
21941: } else {
21942: push(@{$changes{'default'}{$type}},$item);
21943: }
21944: } else {
21945: push(@{$changes{'default'}{$type}},$item);
21946: }
21947: if ($item eq 'limit') {
21948: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21949: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
21950: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
21951: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
21952: }
21953: } else {
21954: $selfenrollhash{'default'}{$type}{'cap'} = '';
21955: }
21956: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21957: if ($selfenrollhash{'default'}{$type}{'cap'} ne
21958: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
21959: push(@{$changes{'default'}{$type}},'cap');
21960: }
21961: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
21962: push(@{$changes{'default'}{$type}},'cap');
21963: }
21964: }
21965: }
21966: }
21967:
21968: foreach my $item (@{$itemsref}) {
21969: if ($item eq 'fields') {
21970: my @changed;
21971: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
21972: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
21973: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
21974: }
21975: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21976: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
21977: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
21978: $domconfig{'selfenrollment'}{'validation'}{$item});
21979: } else {
21980: @changed = @{$selfenrollhash{'validation'}{$item}};
21981: }
21982: } else {
21983: @changed = @{$selfenrollhash{'validation'}{$item}};
21984: }
21985: if (@changed) {
21986: if ($selfenrollhash{'validation'}{$item}) {
21987: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
21988: } else {
21989: $changes{'validation'}{$item} = &mt('None');
21990: }
21991: }
21992: } else {
21993: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
21994: if ($item eq 'markup') {
21995: if ($env{'form.selfenroll_validation_'.$item}) {
21996: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
21997: }
21998: }
21999: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
22000: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
22001: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
22002: }
22003: }
22004: }
22005: }
22006:
22007: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
22008: $dom);
22009: if ($putresult eq 'ok') {
22010: if (keys(%changes) > 0) {
22011: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22012: $resulttext = &mt('Changes made:').'<ul>';
22013: foreach my $key ('admin','default','validation') {
22014: if (ref($changes{$key}) eq 'HASH') {
22015: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
22016: if ($key eq 'validation') {
22017: foreach my $item (@{$itemsref}) {
22018: if (exists($changes{$key}{$item})) {
22019: if ($item eq 'markup') {
22020: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
22021: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
22022: } else {
22023: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
22024: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
22025: }
22026: }
22027: }
22028: } else {
22029: foreach my $type (@types) {
22030: if ($type eq 'community') {
22031: $roles{'1'} = &mt('Community personnel');
22032: } else {
22033: $roles{'1'} = &mt('Course personnel');
22034: }
22035: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 22036: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
22037: if ($key eq 'admin') {
22038: my @mgrdc = ();
22039: if (ref($ordered{$key}) eq 'ARRAY') {
22040: foreach my $item (@{$ordered{'admin'}}) {
22041: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
22042: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
22043: push(@mgrdc,$item);
22044: }
22045: }
22046: }
22047: if (@mgrdc) {
22048: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
22049: } else {
22050: delete($domdefaults{$type.'selfenrolladmdc'});
22051: }
22052: }
22053: } else {
22054: if (ref($ordered{$key}) eq 'ARRAY') {
22055: foreach my $item (@{$ordered{$key}}) {
22056: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
22057: $domdefaults{$type.'selfenroll'.$item} =
22058: $selfenrollhash{$key}{$type}{$item};
22059: }
22060: }
22061: }
22062: }
22063: }
1.231 raeburn 22064: $resulttext .= '<li>'.$titles{$type}.'<ul>';
22065: foreach my $item (@{$ordered{$key}}) {
22066: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
22067: $resulttext .= '<li>';
22068: if ($key eq 'admin') {
22069: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
22070: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
22071: } else {
22072: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
22073: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
22074: }
22075: $resulttext .= '</li>';
22076: }
22077: }
22078: $resulttext .= '</ul></li>';
22079: }
22080: }
22081: $resulttext .= '</ul></li>';
22082: }
22083: }
1.305 raeburn 22084: }
22085: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
22086: my $cachetime = 24*60*60;
22087: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22088: if (ref($lastactref) eq 'HASH') {
22089: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 22090: }
1.231 raeburn 22091: }
22092: $resulttext .= '</ul>';
22093: } else {
22094: $resulttext = &mt('No changes made to self-enrollment settings');
22095: }
22096: } else {
22097: $resulttext = '<span class="LC_error">'.
22098: &mt('An error occurred: [_1]',$putresult).'</span>';
22099: }
22100: return $resulttext;
22101: }
22102:
1.373 raeburn 22103: sub modify_wafproxy {
22104: my ($dom,$action,$lastactref,%domconfig) = @_;
22105: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 22106: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
22107: %wafproxy,%changes,%expirecache,%expiresaml);
1.373 raeburn 22108: foreach my $server (sort(keys(%servers))) {
22109: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
22110: if ($serverhome eq $server) {
22111: my $serverdom = &Apache::lonnet::host_domain($server);
22112: if ($serverdom eq $dom) {
22113: $canset{$server} = 1;
22114: }
22115: }
22116: }
1.381 raeburn 22117: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
22118: %{$values{$dom}} = ();
22119: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
22120: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
22121: }
1.388 raeburn 22122: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
22123: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
22124: }
1.382 raeburn 22125: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.381 raeburn 22126: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
22127: }
22128: }
1.373 raeburn 22129: my $output;
22130: if (keys(%canset)) {
22131: %{$wafproxy{'alias'}} = ();
1.388 raeburn 22132: %{$wafproxy{'saml'}} = ();
1.373 raeburn 22133: foreach my $key (sort(keys(%canset))) {
1.381 raeburn 22134: if ($env{'form.wafproxy_'.$dom}) {
22135: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
22136: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
22137: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
22138: $changes{'alias'} = 1;
22139: }
1.388 raeburn 22140: if ($env{'form.wafproxy_alias_saml_'.$key}) {
22141: $wafproxy{'saml'}{$key} = 1;
22142: }
22143: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
22144: $changes{'saml'} = 1;
22145: }
1.381 raeburn 22146: } else {
22147: $wafproxy{'alias'}{$key} = '';
1.388 raeburn 22148: $wafproxy{'saml'}{$key} = '';
1.381 raeburn 22149: if ($curralias{$key}) {
22150: $changes{'alias'} = 1;
22151: }
1.388 raeburn 22152: if ($currsaml{$key}) {
22153: $changes{'saml'} = 1;
22154: }
1.373 raeburn 22155: }
22156: if ($wafproxy{'alias'}{$key} eq '') {
22157: if ($curralias{$key}) {
22158: $expirecache{$key} = 1;
22159: }
22160: delete($wafproxy{'alias'}{$key});
22161: }
1.388 raeburn 22162: if ($wafproxy{'saml'}{$key} eq '') {
22163: if ($currsaml{$key}) {
22164: $expiresaml{$key} = 1;
22165: }
22166: delete($wafproxy{'saml'}{$key});
22167: }
1.373 raeburn 22168: }
22169: unless (keys(%{$wafproxy{'alias'}})) {
22170: delete($wafproxy{'alias'});
22171: }
1.388 raeburn 22172: unless (keys(%{$wafproxy{'saml'}})) {
22173: delete($wafproxy{'saml'});
22174: }
22175: # Localization for values in %warn occurs in &mt() calls separately.
1.373 raeburn 22176: my %warn = (
22177: trusted => 'trusted IP range(s)',
1.381 raeburn 22178: vpnint => 'internal IP range(s) for VPN sessions(s)',
22179: vpnext => 'IP range(s) for backend WAF connections',
1.373 raeburn 22180: );
1.382 raeburn 22181: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22182: my $possible = $env{'form.wafproxy_'.$item};
22183: $possible =~ s/^\s+|\s+$//g;
22184: if ($possible ne '') {
1.381 raeburn 22185: if ($item eq 'remoteip') {
22186: if ($possible =~ /^[mhn]$/) {
22187: $wafproxy{$item} = $possible;
22188: }
22189: } elsif ($item eq 'ipheader') {
22190: if ($wafproxy{'remoteip'} eq 'h') {
22191: $wafproxy{$item} = $possible;
22192: }
1.382 raeburn 22193: } elsif ($item eq 'sslopt') {
22194: if ($possible =~ /^0|1$/) {
22195: $wafproxy{$item} = $possible;
22196: }
1.373 raeburn 22197: } else {
22198: my (@ok,$count);
1.381 raeburn 22199: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
22200: unless ($env{'form.wafproxy_vpnaccess'}) {
22201: $possible = '';
22202: }
22203: } elsif ($item eq 'trusted') {
22204: unless ($wafproxy{'remoteip'} eq 'h') {
22205: $possible = '';
22206: }
22207: }
22208: unless ($possible eq '') {
22209: $possible =~ s/[\r\n]+/\s/g;
22210: $possible =~ s/\s*-\s*/-/g;
22211: $possible =~ s/\s+/,/g;
1.393 raeburn 22212: $possible =~ s/,+/,/g;
1.381 raeburn 22213: }
1.373 raeburn 22214: $count = 0;
1.381 raeburn 22215: if ($possible ne '') {
1.373 raeburn 22216: foreach my $poss (split(/\,/,$possible)) {
22217: $count ++;
1.393 raeburn 22218: $poss = &validate_ip_pattern($poss);
22219: if ($poss ne '') {
1.373 raeburn 22220: push(@ok,$poss);
22221: }
22222: }
22223: my $diff = $count - scalar(@ok);
22224: if ($diff) {
22225: push(@warnings,'<li>'.
22226: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
22227: $diff,$warn{$item}).
22228: '</li>');
22229: }
1.393 raeburn 22230: if (@ok) {
22231: my @cidr_list;
22232: foreach my $item (@ok) {
22233: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
22234: }
22235: $wafproxy{$item} = join(',',@cidr_list);
22236: }
1.373 raeburn 22237: }
22238: }
1.381 raeburn 22239: if ($wafproxy{$item} ne $currvalue{$item}) {
1.373 raeburn 22240: $changes{$item} = 1;
22241: }
1.381 raeburn 22242: } elsif ($currvalue{$item}) {
22243: $changes{$item} = 1;
1.425 raeburn 22244: }
1.381 raeburn 22245: }
22246: } else {
22247: if (keys(%curralias)) {
22248: $changes{'alias'} = 1;
1.388 raeburn 22249: }
22250: if (keys(%currsaml)) {
22251: $changes{'saml'} = 1;
1.425 raeburn 22252: }
1.381 raeburn 22253: if (keys(%currvalue)) {
22254: foreach my $key (keys(%currvalue)) {
22255: $changes{$key} = 1;
1.373 raeburn 22256: }
22257: }
22258: }
22259: if (keys(%changes)) {
22260: my %defaultshash = (
22261: wafproxy => \%wafproxy,
1.425 raeburn 22262: );
1.373 raeburn 22263: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22264: $dom);
22265: if ($putresult eq 'ok') {
22266: my $cachetime = 24*60*60;
22267: my (%domdefaults,$updatedomdefs);
1.382 raeburn 22268: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22269: if ($changes{$item}) {
22270: unless ($updatedomdefs) {
22271: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
22272: $updatedomdefs = 1;
22273: }
22274: if ($wafproxy{$item}) {
22275: $domdefaults{'waf_'.$item} = $wafproxy{$item};
22276: } elsif (exists($domdefaults{'waf_'.$item})) {
22277: delete($domdefaults{'waf_'.$item});
1.425 raeburn 22278: }
1.373 raeburn 22279: }
22280: }
22281: if ($updatedomdefs) {
22282: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22283: if (ref($lastactref) eq 'HASH') {
22284: $lastactref->{'domdefaults'} = 1;
22285: }
22286: }
22287: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
22288: my %updates = %expirecache;
22289: foreach my $key (keys(%expirecache)) {
22290: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
22291: }
22292: if (ref($wafproxy{'alias'}) eq 'HASH') {
22293: my $cachetime = 24*60*60;
22294: foreach my $key (keys(%{$wafproxy{'alias'}})) {
22295: $updates{$key} = 1;
22296: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
22297: $cachetime);
22298: }
22299: }
22300: if (ref($lastactref) eq 'HASH') {
22301: $lastactref->{'proxyalias'} = \%updates;
22302: }
22303: }
1.388 raeburn 22304: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
22305: my %samlupdates = %expiresaml;
22306: foreach my $key (keys(%expiresaml)) {
22307: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
22308: }
22309: if (ref($wafproxy{'saml'}) eq 'HASH') {
22310: my $cachetime = 24*60*60;
22311: foreach my $key (keys(%{$wafproxy{'saml'}})) {
22312: $samlupdates{$key} = 1;
22313: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
22314: $cachetime);
22315: }
22316: }
22317: if (ref($lastactref) eq 'HASH') {
22318: $lastactref->{'proxysaml'} = \%samlupdates;
22319: }
22320: }
1.373 raeburn 22321: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.401 raeburn 22322: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22323: if ($changes{$item}) {
22324: if ($item eq 'alias') {
22325: my $numaliased = 0;
22326: if (ref($wafproxy{'alias'}) eq 'HASH') {
22327: my $shown;
22328: if (keys(%{$wafproxy{'alias'}})) {
22329: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
22330: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
22331: &Apache::lonnet::hostname($server),
22332: $wafproxy{'alias'}{$server}).'</li>';
22333: $numaliased ++;
22334: }
22335: if ($numaliased) {
22336: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
22337: '<ul>'.$shown.'</ul>').'</li>';
22338: }
22339: }
22340: }
22341: unless ($numaliased) {
22342: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
22343: }
1.388 raeburn 22344: } elsif ($item eq 'saml') {
1.425 raeburn 22345: my $shown;
1.388 raeburn 22346: if (ref($wafproxy{'saml'}) eq 'HASH') {
22347: if (keys(%{$wafproxy{'saml'}})) {
22348: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
22349: }
22350: }
22351: if ($shown) {
1.396 raeburn 22352: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
1.388 raeburn 22353: $shown).'</li>';
22354: } else {
1.396 raeburn 22355: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
1.388 raeburn 22356: }
1.373 raeburn 22357: } else {
1.381 raeburn 22358: if ($item eq 'remoteip') {
22359: my %ip_methods = &remoteip_methods();
22360: if ($wafproxy{$item} =~ /^[mh]$/) {
22361: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
22362: $ip_methods{$wafproxy{$item}}).'</li>';
22363: } else {
22364: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
22365: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
22366: '</li>';
22367: } else {
22368: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
22369: }
22370: }
22371: } elsif ($item eq 'ipheader') {
1.373 raeburn 22372: if ($wafproxy{$item}) {
1.381 raeburn 22373: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
1.373 raeburn 22374: $wafproxy{$item}).'</li>';
22375: } else {
1.381 raeburn 22376: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
1.373 raeburn 22377: }
22378: } elsif ($item eq 'trusted') {
22379: if ($wafproxy{$item}) {
1.381 raeburn 22380: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
1.373 raeburn 22381: $wafproxy{$item}).'</li>';
22382: } else {
22383: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
22384: }
1.381 raeburn 22385: } elsif ($item eq 'vpnint') {
22386: if ($wafproxy{$item}) {
22387: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
22388: $wafproxy{$item}).'</li>';
22389: } else {
22390: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
22391: }
22392: } elsif ($item eq 'vpnext') {
1.373 raeburn 22393: if ($wafproxy{$item}) {
1.381 raeburn 22394: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
1.373 raeburn 22395: $wafproxy{$item}).'</li>';
22396: } else {
1.381 raeburn 22397: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
1.373 raeburn 22398: }
1.382 raeburn 22399: } elsif ($item eq 'sslopt') {
22400: if ($wafproxy{$item}) {
22401: $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>';
22402: } else {
22403: $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>';
22404: }
1.373 raeburn 22405: }
22406: }
22407: }
22408: }
1.420 raeburn 22409: $output .= '</ul>';
1.373 raeburn 22410: } else {
22411: $output = '<span class="LC_error">'.
22412: &mt('An error occurred: [_1]',$putresult).'</span>';
22413: }
22414: } elsif (keys(%canset)) {
22415: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
22416: }
22417: if (@warnings) {
22418: $output .= '<br />'.&mt('Warnings:').'<ul>'.
22419: join("\n",@warnings).'</ul>';
22420: }
22421: return $output;
22422: }
22423:
22424: sub validate_ip_pattern {
22425: my ($pattern) = @_;
22426: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
22427: my ($start,$end) = ($1,$2);
22428: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
1.393 raeburn 22429: if (($start !~ m{/}) && ($end !~ m{/})) {
22430: return $start.'-'.$end;
22431: }
22432: }
22433: } elsif ($pattern ne '') {
22434: $pattern = &Net::CIDR::cidrvalidate($pattern);
22435: if ($pattern ne '') {
22436: return $pattern;
1.373 raeburn 22437: }
22438: }
1.393 raeburn 22439: return;
1.373 raeburn 22440: }
22441:
1.137 raeburn 22442: sub modify_usersessions {
1.212 raeburn 22443: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 22444: my @hostingtypes = ('version','excludedomain','includedomain');
22445: my @offloadtypes = ('primary','default');
22446: my %types = (
22447: remote => \@hostingtypes,
22448: hosted => \@hostingtypes,
22449: spares => \@offloadtypes,
22450: );
22451: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 22452: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 22453: my (%by_ip,%by_location,@intdoms,@instdoms);
22454: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 22455: my @locations = sort(keys(%by_location));
1.137 raeburn 22456: my (%defaultshash,%changes);
22457: foreach my $prefix (@prefixes) {
22458: $defaultshash{'usersessions'}{$prefix} = {};
22459: }
1.212 raeburn 22460: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 22461: my $resulttext;
1.138 raeburn 22462: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 22463: foreach my $prefix (@prefixes) {
1.145 raeburn 22464: next if ($prefix eq 'spares');
22465: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 22466: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22467: if ($type eq 'version') {
22468: my $value = $env{'form.'.$prefix.'_'.$type};
22469: my $okvalue;
22470: if ($value ne '') {
22471: if (grep(/^\Q$value\E$/,@lcversions)) {
22472: $okvalue = $value;
22473: }
22474: }
22475: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22476: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22477: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
22478: if ($inuse == 0) {
22479: $changes{$prefix}{$type} = 1;
22480: } else {
22481: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
22482: $changes{$prefix}{$type} = 1;
22483: }
22484: if ($okvalue ne '') {
22485: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22486: }
22487: }
22488: } else {
22489: if (($inuse == 1) && ($okvalue ne '')) {
22490: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22491: $changes{$prefix}{$type} = 1;
22492: }
22493: }
22494: } else {
22495: if (($inuse == 1) && ($okvalue ne '')) {
22496: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22497: $changes{$prefix}{$type} = 1;
22498: }
22499: }
22500: } else {
22501: if (($inuse == 1) && ($okvalue ne '')) {
22502: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22503: $changes{$prefix}{$type} = 1;
22504: }
22505: }
22506: } else {
22507: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22508: my @okvals;
22509: foreach my $val (@vals) {
1.138 raeburn 22510: if ($val =~ /:/) {
22511: my @items = split(/:/,$val);
22512: foreach my $item (@items) {
22513: if (ref($by_location{$item}) eq 'ARRAY') {
22514: push(@okvals,$item);
22515: }
22516: }
22517: } else {
22518: if (ref($by_location{$val}) eq 'ARRAY') {
22519: push(@okvals,$val);
22520: }
1.137 raeburn 22521: }
22522: }
22523: @okvals = sort(@okvals);
22524: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22525: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22526: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22527: if ($inuse == 0) {
22528: $changes{$prefix}{$type} = 1;
22529: } else {
22530: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22531: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
22532: if (@changed > 0) {
22533: $changes{$prefix}{$type} = 1;
22534: }
22535: }
22536: } else {
22537: if ($inuse == 1) {
22538: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22539: $changes{$prefix}{$type} = 1;
22540: }
22541: }
22542: } else {
22543: if ($inuse == 1) {
22544: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22545: $changes{$prefix}{$type} = 1;
22546: }
22547: }
22548: } else {
22549: if ($inuse == 1) {
22550: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22551: $changes{$prefix}{$type} = 1;
22552: }
22553: }
22554: }
22555: }
22556: }
1.145 raeburn 22557:
22558: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 22559: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 22560: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
22561: my $savespares;
22562:
22563: foreach my $lonhost (sort(keys(%servers))) {
22564: my $serverhomeID =
22565: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 22566: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 22567: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
22568: my %spareschg;
22569: foreach my $type (@{$types{'spares'}}) {
22570: my @okspares;
22571: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
22572: foreach my $server (@checked) {
1.152 raeburn 22573: if (&Apache::lonnet::hostname($server) ne '') {
22574: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
22575: unless (grep(/^\Q$server\E$/,@okspares)) {
22576: push(@okspares,$server);
22577: }
1.145 raeburn 22578: }
22579: }
22580: }
22581: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
22582: my $newspare;
1.152 raeburn 22583: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
22584: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 22585: $newspare = $new;
22586: }
22587: }
1.152 raeburn 22588: my @spares;
22589: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
22590: @spares = sort(@okspares,$newspare);
22591: } else {
22592: @spares = sort(@okspares);
22593: }
22594: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 22595: if (ref($spareid{$lonhost}) eq 'HASH') {
22596: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 22597: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 22598: if (@diffs > 0) {
22599: $spareschg{$type} = 1;
22600: }
22601: }
22602: }
22603: }
22604: if (keys(%spareschg) > 0) {
22605: $changes{'spares'}{$lonhost} = \%spareschg;
22606: }
22607: }
1.261 raeburn 22608: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371 raeburn 22609: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261 raeburn 22610: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
22611: my @okoffload;
22612: if (@offloadnow) {
22613: foreach my $server (@offloadnow) {
22614: if (&Apache::lonnet::hostname($server) ne '') {
22615: unless (grep(/^\Q$server\E$/,@okoffload)) {
22616: push(@okoffload,$server);
22617: }
22618: }
22619: }
22620: if (@okoffload) {
22621: foreach my $lonhost (@okoffload) {
22622: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
22623: }
22624: }
22625: }
1.371 raeburn 22626: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
22627: my @okoffloadoth;
22628: if (@offloadoth) {
22629: foreach my $server (@offloadoth) {
22630: if (&Apache::lonnet::hostname($server) ne '') {
22631: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
22632: push(@okoffloadoth,$server);
22633: }
22634: }
22635: }
22636: if (@okoffloadoth) {
22637: foreach my $lonhost (@okoffloadoth) {
22638: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
22639: }
22640: }
22641: }
1.145 raeburn 22642: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22643: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
22644: if (ref($changes{'spares'}) eq 'HASH') {
22645: if (keys(%{$changes{'spares'}}) > 0) {
22646: $savespares = 1;
22647: }
22648: }
22649: } else {
22650: $savespares = 1;
22651: }
1.371 raeburn 22652: foreach my $offload ('offloadnow','offloadoth') {
22653: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
22654: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
22655: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
22656: $changes{$offload} = 1;
22657: last;
22658: }
1.261 raeburn 22659: }
1.371 raeburn 22660: unless ($changes{$offload}) {
22661: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
22662: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
22663: $changes{$offload} = 1;
22664: last;
22665: }
1.261 raeburn 22666: }
22667: }
1.371 raeburn 22668: } else {
22669: if (($offload eq 'offloadnow') && (@okoffload)) {
22670: $changes{'offloadnow'} = 1;
22671: }
22672: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
22673: $changes{'offloadoth'} = 1;
22674: }
1.425 raeburn 22675: }
1.371 raeburn 22676: }
22677: } else {
22678: if (@okoffload) {
1.261 raeburn 22679: $changes{'offloadnow'} = 1;
22680: }
1.371 raeburn 22681: if (@okoffloadoth) {
22682: $changes{'offloadoth'} = 1;
22683: }
1.145 raeburn 22684: }
1.147 raeburn 22685: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
22686: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 22687: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22688: $dom);
22689: if ($putresult eq 'ok') {
22690: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22691: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
22692: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
22693: }
22694: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
22695: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
22696: }
1.261 raeburn 22697: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22698: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
22699: }
1.371 raeburn 22700: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22701: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
22702: }
1.137 raeburn 22703: }
22704: my $cachetime = 24*60*60;
22705: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 22706: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 22707: if (ref($lastactref) eq 'HASH') {
22708: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 22709: $lastactref->{'usersessions'} = 1;
1.212 raeburn 22710: }
1.147 raeburn 22711: if (keys(%changes) > 0) {
22712: my %lt = &usersession_titles();
22713: $resulttext = &mt('Changes made:').'<ul>';
22714: foreach my $prefix (@prefixes) {
22715: if (ref($changes{$prefix}) eq 'HASH') {
22716: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
22717: if ($prefix eq 'spares') {
22718: if (ref($changes{$prefix}) eq 'HASH') {
22719: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
22720: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 22721: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 22722: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
22723: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 22724: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
22725: foreach my $type (@{$types{$prefix}}) {
22726: if ($changes{$prefix}{$lonhost}{$type}) {
22727: my $offloadto = &mt('None');
22728: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
22729: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
22730: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
22731: }
1.145 raeburn 22732: }
1.147 raeburn 22733: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 22734: }
1.137 raeburn 22735: }
22736: }
1.147 raeburn 22737: $resulttext .= '</li>';
1.137 raeburn 22738: }
22739: }
1.147 raeburn 22740: } else {
22741: foreach my $type (@{$types{$prefix}}) {
22742: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22743: my ($newvalue,$notinuse);
1.147 raeburn 22744: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22745: if (ref($defaultshash{'usersessions'}{$prefix})) {
22746: if ($type eq 'version') {
22747: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 22748: } else {
22749: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22750: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
22751: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
22752: }
22753: } else {
22754: $notinuse = 1;
1.147 raeburn 22755: }
1.145 raeburn 22756: }
22757: }
22758: }
1.147 raeburn 22759: if ($newvalue eq '') {
22760: if ($type eq 'version') {
22761: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 22762: } elsif ($notinuse) {
22763: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 22764: } else {
22765: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
22766: }
1.145 raeburn 22767: } else {
1.147 raeburn 22768: if ($type eq 'version') {
1.344 raeburn 22769: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 22770: }
22771: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 22772: }
1.137 raeburn 22773: }
22774: }
22775: }
1.147 raeburn 22776: $resulttext .= '</ul>';
1.137 raeburn 22777: }
22778: }
1.261 raeburn 22779: if ($changes{'offloadnow'}) {
22780: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22781: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371 raeburn 22782: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261 raeburn 22783: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
22784: $resulttext .= '<li>'.$lonhost.'</li>';
22785: }
22786: $resulttext .= '</ul>';
22787: } else {
1.371 raeburn 22788: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
22789: }
22790: } else {
22791: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
22792: }
22793: }
22794: if ($changes{'offloadoth'}) {
22795: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22796: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
22797: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
22798: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
22799: $resulttext .= '<li>'.$lonhost.'</li>';
22800: }
22801: $resulttext .= '</ul>';
22802: } else {
22803: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261 raeburn 22804: }
22805: } else {
1.371 raeburn 22806: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261 raeburn 22807: }
22808: }
1.147 raeburn 22809: $resulttext .= '</ul>';
22810: } else {
22811: $resulttext = $nochgmsg;
1.137 raeburn 22812: }
22813: } else {
22814: $resulttext = '<span class="LC_error">'.
22815: &mt('An error occurred: [_1]',$putresult).'</span>';
22816: }
22817: } else {
1.147 raeburn 22818: $resulttext = $nochgmsg;
1.137 raeburn 22819: }
22820: return $resulttext;
22821: }
22822:
1.275 raeburn 22823: sub modify_ssl {
22824: my ($dom,$lastactref,%domconfig) = @_;
22825: my (%by_ip,%by_location,@intdoms,@instdoms);
22826: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
22827: my @locations = sort(keys(%by_location));
22828: my %servers = &Apache::lonnet::internet_dom_servers($dom);
22829: my (%defaultshash,%changes);
22830: my $action = 'ssl';
1.293 raeburn 22831: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 22832: foreach my $prefix (@prefixes) {
22833: $defaultshash{$action}{$prefix} = {};
22834: }
22835: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22836: my $resulttext;
22837: my %iphost = &Apache::lonnet::get_iphost();
22838: my @reptypes = ('certreq','nocertreq');
22839: my @connecttypes = ('dom','intdom','other');
22840: my %types = (
1.293 raeburn 22841: connto => \@connecttypes,
22842: connfrom => \@connecttypes,
22843: replication => \@reptypes,
1.275 raeburn 22844: );
22845: foreach my $prefix (sort(keys(%types))) {
22846: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 22847: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22848: my $value = 'yes';
22849: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
22850: $value = $env{'form.'.$prefix.'_'.$type};
22851: }
1.335 raeburn 22852: if (ref($domconfig{$action}) eq 'HASH') {
22853: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22854: if ($domconfig{$action}{$prefix}{$type} ne '') {
22855: if ($value ne $domconfig{$action}{$prefix}{$type}) {
22856: $changes{$prefix}{$type} = 1;
22857: }
22858: $defaultshash{$action}{$prefix}{$type} = $value;
22859: } else {
22860: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 22861: $changes{$prefix}{$type} = 1;
22862: }
22863: } else {
22864: $defaultshash{$action}{$prefix}{$type} = $value;
22865: $changes{$prefix}{$type} = 1;
22866: }
22867: } else {
22868: $defaultshash{$action}{$prefix}{$type} = $value;
22869: $changes{$prefix}{$type} = 1;
22870: }
22871: if (($type eq 'dom') && (keys(%servers) == 1)) {
22872: delete($changes{$prefix}{$type});
22873: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
22874: delete($changes{$prefix}{$type});
22875: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
22876: delete($changes{$prefix}{$type});
22877: }
22878: } elsif ($prefix eq 'replication') {
22879: if (@locations > 0) {
22880: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22881: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22882: my @okvals;
22883: foreach my $val (@vals) {
22884: if ($val =~ /:/) {
22885: my @items = split(/:/,$val);
22886: foreach my $item (@items) {
22887: if (ref($by_location{$item}) eq 'ARRAY') {
22888: push(@okvals,$item);
22889: }
22890: }
22891: } else {
22892: if (ref($by_location{$val}) eq 'ARRAY') {
22893: push(@okvals,$val);
22894: }
22895: }
22896: }
22897: @okvals = sort(@okvals);
22898: if (ref($domconfig{$action}) eq 'HASH') {
22899: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22900: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
22901: if ($inuse == 0) {
22902: $changes{$prefix}{$type} = 1;
22903: } else {
22904: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22905: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
22906: if (@changed > 0) {
22907: $changes{$prefix}{$type} = 1;
22908: }
22909: }
22910: } else {
22911: if ($inuse == 1) {
22912: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22913: $changes{$prefix}{$type} = 1;
22914: }
22915: }
22916: } else {
22917: if ($inuse == 1) {
22918: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22919: $changes{$prefix}{$type} = 1;
22920: }
22921: }
22922: } else {
22923: if ($inuse == 1) {
22924: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22925: $changes{$prefix}{$type} = 1;
22926: }
22927: }
22928: }
22929: }
22930: }
22931: }
1.336 raeburn 22932: if (keys(%changes)) {
22933: foreach my $prefix (keys(%changes)) {
22934: if (ref($changes{$prefix}) eq 'HASH') {
22935: if (scalar(keys(%{$changes{$prefix}})) == 0) {
22936: delete($changes{$prefix});
22937: }
22938: } else {
22939: delete($changes{$prefix});
22940: }
22941: }
22942: }
1.275 raeburn 22943: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
22944: if (keys(%changes) > 0) {
22945: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22946: $dom);
22947: if ($putresult eq 'ok') {
22948: if (ref($defaultshash{$action}) eq 'HASH') {
22949: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
22950: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
22951: }
1.293 raeburn 22952: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 22953: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 22954: }
22955: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 22956: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 22957: }
22958: }
22959: my $cachetime = 24*60*60;
22960: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22961: if (ref($lastactref) eq 'HASH') {
22962: $lastactref->{'domdefaults'} = 1;
22963: }
22964: if (keys(%changes) > 0) {
22965: my %titles = &ssl_titles();
22966: $resulttext = &mt('Changes made:').'<ul>';
22967: foreach my $prefix (@prefixes) {
22968: if (ref($changes{$prefix}) eq 'HASH') {
22969: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
22970: foreach my $type (@{$types{$prefix}}) {
22971: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22972: my ($newvalue,$notinuse);
1.275 raeburn 22973: if (ref($defaultshash{$action}) eq 'HASH') {
22974: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 22975: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22976: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 22977: } else {
22978: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
22979: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
22980: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
22981: }
22982: } else {
22983: $notinuse = 1;
1.275 raeburn 22984: }
22985: }
22986: }
1.344 raeburn 22987: if ($notinuse) {
22988: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
22989: } elsif ($newvalue eq '') {
1.275 raeburn 22990: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
22991: } else {
22992: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
22993: }
22994: }
22995: }
22996: }
22997: $resulttext .= '</ul>';
22998: }
22999: }
23000: } else {
23001: $resulttext = $nochgmsg;
23002: }
23003: } else {
23004: $resulttext = '<span class="LC_error">'.
23005: &mt('An error occurred: [_1]',$putresult).'</span>';
23006: }
23007: } else {
23008: $resulttext = $nochgmsg;
23009: }
23010: return $resulttext;
23011: }
23012:
1.279 raeburn 23013: sub modify_trust {
23014: my ($dom,$lastactref,%domconfig) = @_;
23015: my (%by_ip,%by_location,@intdoms,@instdoms);
23016: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
23017: my @locations = sort(keys(%by_location));
23018: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
23019: my @types = ('exc','inc');
23020: my (%defaultshash,%changes);
23021: foreach my $prefix (@prefixes) {
23022: $defaultshash{'trust'}{$prefix} = {};
23023: }
23024: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
23025: my $resulttext;
23026: foreach my $prefix (@prefixes) {
23027: foreach my $type (@types) {
23028: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
23029: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
23030: my @okvals;
23031: foreach my $val (@vals) {
23032: if ($val =~ /:/) {
23033: my @items = split(/:/,$val);
23034: foreach my $item (@items) {
23035: if (ref($by_location{$item}) eq 'ARRAY') {
23036: push(@okvals,$item);
23037: }
23038: }
23039: } else {
23040: if (ref($by_location{$val}) eq 'ARRAY') {
23041: push(@okvals,$val);
23042: }
23043: }
23044: }
23045: @okvals = sort(@okvals);
23046: if (ref($domconfig{'trust'}) eq 'HASH') {
23047: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
23048: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
23049: if ($inuse == 0) {
23050: $changes{$prefix}{$type} = 1;
23051: } else {
23052: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23053: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
23054: if (@changed > 0) {
23055: $changes{$prefix}{$type} = 1;
23056: }
23057: }
23058: } else {
23059: if ($inuse == 1) {
23060: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23061: $changes{$prefix}{$type} = 1;
23062: }
23063: }
23064: } else {
23065: if ($inuse == 1) {
23066: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23067: $changes{$prefix}{$type} = 1;
23068: }
23069: }
23070: } else {
23071: if ($inuse == 1) {
23072: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23073: $changes{$prefix}{$type} = 1;
23074: }
23075: }
23076: }
23077: }
23078: my $nochgmsg = &mt('No changes made to trust settings.');
23079: if (keys(%changes) > 0) {
23080: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
23081: $dom);
23082: if ($putresult eq 'ok') {
23083: if (ref($defaultshash{'trust'}) eq 'HASH') {
23084: foreach my $prefix (@prefixes) {
23085: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
23086: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
23087: }
23088: }
23089: }
23090: my $cachetime = 24*60*60;
23091: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.410 raeburn 23092: &Apache::lonnet::do_cache_new('trust',$dom,$defaultshash{'trust'},3600);
1.279 raeburn 23093: if (ref($lastactref) eq 'HASH') {
23094: $lastactref->{'domdefaults'} = 1;
1.410 raeburn 23095: $lastactref->{'trust'} = 1;
1.279 raeburn 23096: }
23097: if (keys(%changes) > 0) {
23098: my %lt = &trust_titles();
23099: $resulttext = &mt('Changes made:').'<ul>';
23100: foreach my $prefix (@prefixes) {
23101: if (ref($changes{$prefix}) eq 'HASH') {
23102: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
23103: foreach my $type (@types) {
23104: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 23105: my ($newvalue,$notinuse);
1.279 raeburn 23106: if (ref($defaultshash{'trust'}) eq 'HASH') {
23107: if (ref($defaultshash{'trust'}{$prefix})) {
23108: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
23109: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
23110: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
23111: }
1.344 raeburn 23112: } else {
23113: $notinuse = 1;
1.279 raeburn 23114: }
23115: }
23116: }
1.344 raeburn 23117: if ($notinuse) {
23118: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
23119: } elsif ($newvalue eq '') {
1.279 raeburn 23120: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
23121: } else {
23122: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
23123: }
23124: }
23125: }
23126: $resulttext .= '</ul>';
23127: }
23128: }
23129: $resulttext .= '</ul>';
23130: } else {
23131: $resulttext = $nochgmsg;
23132: }
23133: } else {
23134: $resulttext = '<span class="LC_error">'.
23135: &mt('An error occurred: [_1]',$putresult).'</span>';
23136: }
23137: } else {
23138: $resulttext = $nochgmsg;
23139: }
23140: return $resulttext;
23141: }
23142:
1.150 raeburn 23143: sub modify_loadbalancing {
23144: my ($dom,%domconfig) = @_;
23145: my $primary_id = &Apache::lonnet::domain($dom,'primary');
23146: my $intdom = &Apache::lonnet::internet_dom($primary_id);
23147: my ($othertitle,$usertypes,$types) =
23148: &Apache::loncommon::sorted_inst_types($dom);
23149: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 23150: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 23151: my @sparestypes = ('primary','default');
23152: my %typetitles = &sparestype_titles();
23153: my $resulttext;
1.342 raeburn 23154: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 23155: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
23156: %existing = %{$domconfig{'loadbalancing'}};
23157: }
23158: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 23159: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 23160: my ($saveloadbalancing,%defaultshash,%changes);
23161: my ($alltypes,$othertypes,$titles) =
23162: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
23163: my %ruletitles = &offloadtype_text();
23164: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
23165: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
23166: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
23167: if ($balancer eq '') {
23168: next;
23169: }
1.210 raeburn 23170: if (!exists($servers{$balancer})) {
1.171 raeburn 23171: if (exists($currbalancer{$balancer})) {
23172: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 23173: }
1.171 raeburn 23174: next;
23175: }
23176: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
23177: push(@{$changes{'delete'}},$balancer);
23178: next;
23179: }
23180: if (!exists($currbalancer{$balancer})) {
23181: push(@{$changes{'add'}},$balancer);
23182: }
23183: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
23184: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
23185: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
23186: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
23187: $saveloadbalancing = 1;
23188: }
23189: foreach my $sparetype (@sparestypes) {
23190: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
23191: my @offloadto;
23192: foreach my $target (@targets) {
23193: if (($servers{$target}) && ($target ne $balancer)) {
23194: if ($sparetype eq 'default') {
23195: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
23196: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 23197: }
23198: }
1.171 raeburn 23199: unless(grep(/^\Q$target\E$/,@offloadto)) {
23200: push(@offloadto,$target);
23201: }
1.150 raeburn 23202: }
23203: }
1.284 raeburn 23204: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
23205: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
23206: push(@offloadto,$balancer);
23207: }
23208: }
23209: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 23210: }
1.342 raeburn 23211: if ($env{'form.loadbalancing_cookie_'.$i}) {
23212: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
1.425 raeburn 23213: if (exists($currbalancer{$balancer})) {
1.342 raeburn 23214: unless ($currcookies{$balancer}) {
23215: $changes{'curr'}{$balancer}{'cookie'} = 1;
23216: }
23217: }
23218: } elsif (exists($currbalancer{$balancer})) {
23219: if ($currcookies{$balancer}) {
23220: $changes{'curr'}{$balancer}{'cookie'} = 1;
23221: }
23222: }
1.171 raeburn 23223: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 23224: foreach my $sparetype (@sparestypes) {
1.171 raeburn 23225: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
23226: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 23227: if (@targetdiffs > 0) {
1.171 raeburn 23228: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 23229: }
1.171 raeburn 23230: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23231: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23232: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 23233: }
23234: }
23235: }
23236: } else {
1.171 raeburn 23237: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 23238: foreach my $sparetype (@sparestypes) {
1.171 raeburn 23239: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23240: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23241: $changes{'curr'}{$balancer}{'targets'} = 1;
23242: }
1.150 raeburn 23243: }
23244: }
1.210 raeburn 23245: }
1.150 raeburn 23246: }
23247: my $ishomedom;
1.171 raeburn 23248: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
23249: $ishomedom = 1;
1.150 raeburn 23250: }
23251: if (ref($alltypes) eq 'ARRAY') {
23252: foreach my $type (@{$alltypes}) {
23253: my $rule;
1.210 raeburn 23254: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 23255: (!$ishomedom)) {
1.171 raeburn 23256: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
23257: }
23258: if ($rule eq 'specific') {
1.255 raeburn 23259: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 23260: if (exists($servers{$specifiedhost})) {
1.255 raeburn 23261: $rule = $specifiedhost;
23262: }
1.150 raeburn 23263: }
1.171 raeburn 23264: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
23265: if (ref($currrules{$balancer}) eq 'HASH') {
23266: if ($rule ne $currrules{$balancer}{$type}) {
23267: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 23268: }
23269: } elsif ($rule ne '') {
1.171 raeburn 23270: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 23271: }
23272: }
23273: }
1.171 raeburn 23274: }
23275: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
23276: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
23277: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
23278: $defaultshash{'loadbalancing'} = {};
23279: }
23280: my $putresult = &Apache::lonnet::put_dom('configuration',
23281: \%defaultshash,$dom);
23282: if ($putresult eq 'ok') {
23283: if (keys(%changes) > 0) {
1.252 raeburn 23284: my %toupdate;
1.171 raeburn 23285: if (ref($changes{'delete'}) eq 'ARRAY') {
23286: foreach my $balancer (sort(@{$changes{'delete'}})) {
23287: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 23288: $toupdate{$balancer} = 1;
1.150 raeburn 23289: }
1.171 raeburn 23290: }
23291: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 23292: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 23293: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 23294: $toupdate{$balancer} = 1;
1.171 raeburn 23295: }
23296: }
23297: if (ref($changes{'curr'}) eq 'HASH') {
23298: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 23299: $toupdate{$balancer} = 1;
1.171 raeburn 23300: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
23301: if ($changes{'curr'}{$balancer}{'targets'}) {
23302: my %offloadstr;
23303: foreach my $sparetype (@sparestypes) {
23304: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23305: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23306: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
23307: }
23308: }
1.150 raeburn 23309: }
1.171 raeburn 23310: if (keys(%offloadstr) == 0) {
23311: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 23312: } else {
1.171 raeburn 23313: my $showoffload;
23314: foreach my $sparetype (@sparestypes) {
23315: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
23316: if (defined($offloadstr{$sparetype})) {
23317: $showoffload .= $offloadstr{$sparetype};
23318: } else {
23319: $showoffload .= &mt('None');
23320: }
23321: $showoffload .= (' 'x3);
23322: }
23323: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 23324: }
23325: }
23326: }
1.171 raeburn 23327: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
23328: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
23329: foreach my $type (@{$alltypes}) {
23330: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
23331: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23332: my $balancetext;
23333: if ($rule eq '') {
23334: $balancetext = $ruletitles{'default'};
1.209 raeburn 23335: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 23336: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 23337: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 23338: foreach my $sparetype (@sparestypes) {
23339: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23340: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
23341: }
23342: }
1.253 raeburn 23343: foreach my $item (@{$alltypes}) {
23344: next if ($item =~ /^_LC_ipchange/);
23345: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
23346: if ($hasrule eq 'homeserver') {
23347: map { $toupdate{$_} = 1; } (keys(%libraryservers));
23348: } else {
23349: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
23350: if ($servers{$hasrule}) {
23351: $toupdate{$hasrule} = 1;
23352: }
23353: }
23354: }
23355: }
1.254 raeburn 23356: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
23357: $balancetext = $ruletitles{$rule};
23358: } else {
23359: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23360: $balancetext = $ruletitles{'particular'}.' '.$receiver;
23361: if ($receiver) {
23362: $toupdate{$receiver};
23363: }
23364: }
23365: } else {
23366: $balancetext = $ruletitles{$rule};
1.252 raeburn 23367: }
1.171 raeburn 23368: } else {
23369: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
23370: }
1.210 raeburn 23371: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 23372: }
23373: }
23374: }
23375: }
1.342 raeburn 23376: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.389 raeburn 23377: if ($currcookies{$balancer}) {
23378: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
23379: $balancer).'</li>';
23380: } else {
23381: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
23382: $balancer).'</li>';
23383: }
1.342 raeburn 23384: }
1.375 raeburn 23385: }
23386: }
23387: if (keys(%toupdate)) {
23388: my %thismachine;
23389: my $updatedhere;
23390: my $cachetime = 60*60*24;
23391: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
23392: foreach my $lonhost (keys(%toupdate)) {
23393: if ($thismachine{$lonhost}) {
23394: unless ($updatedhere) {
23395: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
23396: $defaultshash{'loadbalancing'},
23397: $cachetime);
23398: $updatedhere = 1;
1.252 raeburn 23399: }
1.375 raeburn 23400: } else {
23401: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
23402: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.252 raeburn 23403: }
1.150 raeburn 23404: }
1.171 raeburn 23405: }
23406: if ($resulttext ne '') {
23407: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 23408: } else {
23409: $resulttext = $nochgmsg;
23410: }
23411: } else {
1.171 raeburn 23412: $resulttext = $nochgmsg;
1.150 raeburn 23413: }
23414: } else {
1.171 raeburn 23415: $resulttext = '<span class="LC_error">'.
23416: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 23417: }
23418: } else {
1.171 raeburn 23419: $resulttext = $nochgmsg;
1.150 raeburn 23420: }
23421: return $resulttext;
23422: }
23423:
1.48 raeburn 23424: sub recurse_check {
23425: my ($chkcats,$categories,$depth,$name) = @_;
23426: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
23427: my $chg = 0;
23428: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
23429: my $category = $chkcats->[$depth]{$name}[$j];
23430: my $item;
23431: if ($category eq '') {
23432: $chg ++;
23433: } else {
23434: my $deeper = $depth + 1;
23435: $item = &escape($category).':'.&escape($name).':'.$depth;
23436: if ($chg) {
23437: $categories->{$item} -= $chg;
23438: }
23439: &recurse_check($chkcats,$categories,$deeper,$category);
23440: $deeper --;
23441: }
23442: }
23443: }
23444: return;
23445: }
23446:
23447: sub recurse_cat_deletes {
23448: my ($item,$coursecategories,$deletions) = @_;
23449: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
23450: my $subdepth = $depth + 1;
23451: if (ref($coursecategories) eq 'HASH') {
23452: foreach my $subitem (keys(%{$coursecategories})) {
23453: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
23454: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
23455: delete($coursecategories->{$subitem});
23456: $deletions->{$subitem} = 1;
23457: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 23458: }
1.48 raeburn 23459: }
23460: }
23461: return;
23462: }
23463:
1.125 raeburn 23464: sub active_dc_picker {
1.191 raeburn 23465: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 23466: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 23467: my @domcoord = keys(%domcoords);
23468: if (keys(%currhash)) {
23469: foreach my $dc (keys(%currhash)) {
23470: unless (exists($domcoords{$dc})) {
23471: push(@domcoord,$dc);
23472: }
23473: }
23474: }
23475: @domcoord = sort(@domcoord);
1.210 raeburn 23476: my $numdcs = scalar(@domcoord);
1.191 raeburn 23477: my $rows = 0;
23478: my $table;
1.125 raeburn 23479: if ($numdcs > 1) {
1.191 raeburn 23480: $table = '<table>';
23481: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 23482: my $rem = $i%($numinrow);
23483: if ($rem == 0) {
23484: if ($i > 0) {
1.191 raeburn 23485: $table .= '</tr>';
1.125 raeburn 23486: }
1.191 raeburn 23487: $table .= '<tr>';
23488: $rows ++;
1.125 raeburn 23489: }
1.191 raeburn 23490: my $check = '';
23491: if ($inputtype eq 'radio') {
23492: if (keys(%currhash) == 0) {
23493: if (!$i) {
23494: $check = ' checked="checked"';
23495: }
23496: } elsif (exists($currhash{$domcoord[$i]})) {
23497: $check = ' checked="checked"';
23498: }
23499: } else {
23500: if (exists($currhash{$domcoord[$i]})) {
23501: $check = ' checked="checked"';
1.125 raeburn 23502: }
23503: }
1.191 raeburn 23504: if ($i == @domcoord - 1) {
1.125 raeburn 23505: my $colsleft = $numinrow - $rem;
23506: if ($colsleft > 1) {
1.191 raeburn 23507: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 23508: } else {
1.191 raeburn 23509: $table .= '<td class="LC_left_item">';
1.125 raeburn 23510: }
23511: } else {
1.191 raeburn 23512: $table .= '<td class="LC_left_item">';
23513: }
23514: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
23515: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
23516: $table .= '<span class="LC_nobreak"><label>'.
23517: '<input type="'.$inputtype.'" name="'.$name.'"'.
23518: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
23519: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 23520: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 23521: }
1.219 raeburn 23522: $table .= '</label></span></td>';
1.191 raeburn 23523: }
23524: $table .= '</tr></table>';
23525: } elsif ($numdcs == 1) {
1.219 raeburn 23526: my ($dcname,$dcdom) = split(':',$domcoord[0]);
23527: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 23528: if ($inputtype eq 'radio') {
1.247 raeburn 23529: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 23530: if ($user ne $dcname.':'.$dcdom) {
23531: $table .= ' ('.$dcname.':'.$dcdom.')';
23532: }
1.191 raeburn 23533: } else {
23534: my $check;
23535: if (exists($currhash{$domcoord[0]})) {
23536: $check = ' checked="checked"';
1.125 raeburn 23537: }
1.247 raeburn 23538: $table = '<span class="LC_nobreak"><label>'.
23539: '<input type="checkbox" name="'.$name.'" '.
23540: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 23541: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 23542: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 23543: }
1.220 raeburn 23544: $table .= '</label></span>';
1.191 raeburn 23545: $rows ++;
1.125 raeburn 23546: }
23547: }
1.191 raeburn 23548: return ($numdcs,$table,$rows);
1.125 raeburn 23549: }
23550:
1.137 raeburn 23551: sub usersession_titles {
23552: return &Apache::lonlocal::texthash(
23553: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
23554: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 23555: spares => 'Servers offloaded to, when busy',
1.137 raeburn 23556: version => 'LON-CAPA version requirement',
1.138 raeburn 23557: excludedomain => 'Allow all, but exclude specific domains',
23558: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 23559: primary => 'Primary (checked first)',
1.154 raeburn 23560: default => 'Default',
1.137 raeburn 23561: );
23562: }
23563:
1.152 raeburn 23564: sub id_for_thisdom {
23565: my (%servers) = @_;
23566: my %altids;
23567: foreach my $server (keys(%servers)) {
23568: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
23569: if ($serverhome ne $server) {
23570: $altids{$serverhome} = $server;
23571: }
23572: }
23573: return %altids;
23574: }
23575:
1.150 raeburn 23576: sub count_servers {
23577: my ($currbalancer,%servers) = @_;
23578: my (@spares,$numspares);
23579: foreach my $lonhost (sort(keys(%servers))) {
23580: next if ($currbalancer eq $lonhost);
23581: push(@spares,$lonhost);
23582: }
23583: if ($currbalancer) {
23584: $numspares = scalar(@spares);
23585: } else {
23586: $numspares = scalar(@spares) - 1;
23587: }
23588: return ($numspares,@spares);
23589: }
23590:
23591: sub lonbalance_targets_js {
1.171 raeburn 23592: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 23593: my $select = &mt('Select');
23594: my ($alltargets,$allishome,$allinsttypes,@alltypes);
23595: if (ref($servers) eq 'HASH') {
23596: $alltargets = join("','",sort(keys(%{$servers})));
23597: my @homedoms;
23598: foreach my $server (sort(keys(%{$servers}))) {
23599: if (&Apache::lonnet::host_domain($server) eq $dom) {
23600: push(@homedoms,'1');
23601: } else {
23602: push(@homedoms,'0');
23603: }
23604: }
23605: $allishome = join("','",@homedoms);
23606: }
23607: if (ref($types) eq 'ARRAY') {
23608: if (@{$types} > 0) {
23609: @alltypes = @{$types};
23610: }
23611: }
23612: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
23613: $allinsttypes = join("','",@alltypes);
1.342 raeburn 23614: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 23615: if (ref($settings) eq 'HASH') {
23616: %existing = %{$settings};
23617: }
23618: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 23619: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 23620: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 23621: return <<"END";
23622:
23623: <script type="text/javascript">
23624: // <![CDATA[
23625:
1.171 raeburn 23626: currBalancers = new Array('$balancers');
23627:
23628: function toggleTargets(balnum) {
23629: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23630: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
23631: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
23632: var prevbalancer = prevhostitem.value;
23633: var baltotal = document.getElementById('loadbalancing_total').value;
23634: prevhostitem.value = balancer;
23635: if (prevbalancer != '') {
23636: var prevIdx = currBalancers.indexOf(prevbalancer);
23637: if (prevIdx != -1) {
23638: currBalancers.splice(prevIdx,1);
23639: }
23640: }
1.150 raeburn 23641: if (balancer == '') {
1.171 raeburn 23642: hideSpares(balnum);
1.150 raeburn 23643: } else {
1.171 raeburn 23644: var currIdx = currBalancers.indexOf(balancer);
23645: if (currIdx == -1) {
23646: currBalancers.push(balancer);
23647: }
1.150 raeburn 23648: var homedoms = new Array('$allishome');
1.171 raeburn 23649: var ishomedom = homedoms[lonhostitem.selectedIndex];
23650: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 23651: }
1.171 raeburn 23652: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 23653: return;
23654: }
23655:
1.171 raeburn 23656: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 23657: var alltargets = new Array('$alltargets');
23658: var insttypes = new Array('$allinsttypes');
1.151 raeburn 23659: var offloadtypes = new Array('primary','default');
23660:
1.171 raeburn 23661: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
23662: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 23663:
1.151 raeburn 23664: for (var i=0; i<offloadtypes.length; i++) {
23665: var count = 0;
23666: for (var j=0; j<alltargets.length; j++) {
23667: if (alltargets[j] != balancer) {
1.171 raeburn 23668: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
23669: item.value = alltargets[j];
23670: item.style.textAlign='left';
23671: item.style.textFace='normal';
23672: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
23673: if (currBalancers.indexOf(alltargets[j]) == -1) {
23674: item.disabled = '';
23675: } else {
23676: item.disabled = 'disabled';
23677: item.checked = false;
23678: }
1.151 raeburn 23679: count ++;
23680: }
1.150 raeburn 23681: }
23682: }
1.151 raeburn 23683: for (var k=0; k<insttypes.length; k++) {
23684: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 23685: if (ishomedom == 1) {
1.171 raeburn 23686: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23687: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23688: } else {
1.171 raeburn 23689: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23690: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 23691: }
23692: } else {
1.171 raeburn 23693: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23694: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23695: }
1.151 raeburn 23696: if ((insttypes[k] != '_LC_external') &&
23697: ((insttypes[k] != '_LC_internetdom') ||
23698: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 23699: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
23700: item.options.length = 0;
23701: item.options[0] = new Option("","",true,true);
1.210 raeburn 23702: var idx = 0;
1.151 raeburn 23703: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 23704: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
23705: idx ++;
23706: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 23707: }
23708: }
23709: }
23710: }
23711: return;
23712: }
23713:
1.171 raeburn 23714: function hideSpares(balnum) {
1.150 raeburn 23715: var alltargets = new Array('$alltargets');
23716: var insttypes = new Array('$allinsttypes');
23717: var offloadtypes = new Array('primary','default');
23718:
1.171 raeburn 23719: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
23720: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 23721:
23722: var total = alltargets.length - 1;
23723: for (var i=0; i<offloadtypes; i++) {
23724: for (var j=0; j<total; j++) {
1.171 raeburn 23725: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
23726: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
23727: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 23728: }
1.150 raeburn 23729: }
23730: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 23731: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23732: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 23733: if (insttypes[k] != '_LC_external') {
1.171 raeburn 23734: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
23735: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 23736: }
23737: }
23738: return;
23739: }
23740:
1.171 raeburn 23741: function checkOffloads(item,balnum,type) {
1.150 raeburn 23742: var alltargets = new Array('$alltargets');
23743: var offloadtypes = new Array('primary','default');
23744: if (item.checked) {
23745: var total = alltargets.length - 1;
23746: var other;
23747: if (type == offloadtypes[0]) {
1.151 raeburn 23748: other = offloadtypes[1];
1.150 raeburn 23749: } else {
1.151 raeburn 23750: other = offloadtypes[0];
1.150 raeburn 23751: }
23752: for (var i=0; i<total; i++) {
1.171 raeburn 23753: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 23754: if (server == item.value) {
1.171 raeburn 23755: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
23756: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 23757: }
23758: }
23759: }
23760: }
23761: return;
23762: }
23763:
1.171 raeburn 23764: function singleServerToggle(balnum,type) {
23765: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 23766: if (offloadtoSelIdx == 0) {
1.171 raeburn 23767: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
23768: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23769:
23770: } else {
1.171 raeburn 23771: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
23772: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 23773: }
23774: return;
23775: }
23776:
1.171 raeburn 23777: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 23778: if (type == '_LC_external') {
1.171 raeburn 23779: return;
1.150 raeburn 23780: }
1.171 raeburn 23781: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 23782: for (var i=0; i<typesRules.length; i++) {
23783: if (formname.elements[typesRules[i]].checked) {
23784: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 23785: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
23786: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23787: } else {
1.171 raeburn 23788: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
23789: }
23790: }
23791: }
23792: return;
23793: }
23794:
23795: function balancerDeleteChange(balnum) {
23796: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23797: var baltotal = document.getElementById('loadbalancing_total').value;
23798: var addtarget;
23799: var removetarget;
23800: var action = 'delete';
23801: if (document.getElementById('loadbalancing_delete_'+balnum)) {
23802: var lonhost = hostitem.value;
23803: var currIdx = currBalancers.indexOf(lonhost);
23804: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
23805: if (currIdx != -1) {
23806: currBalancers.splice(currIdx,1);
23807: }
23808: addtarget = lonhost;
23809: } else {
23810: if (currIdx == -1) {
23811: currBalancers.push(lonhost);
23812: }
23813: removetarget = lonhost;
23814: action = 'undelete';
23815: }
23816: balancerChange(balnum,baltotal,action,addtarget,removetarget);
23817: }
23818: return;
23819: }
23820:
23821: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
23822: if (baltotal > 1) {
23823: var offloadtypes = new Array('primary','default');
23824: var alltargets = new Array('$alltargets');
23825: var insttypes = new Array('$allinsttypes');
23826: for (var i=0; i<baltotal; i++) {
23827: if (i != balnum) {
23828: for (var j=0; j<offloadtypes.length; j++) {
23829: var total = alltargets.length - 1;
23830: for (var k=0; k<total; k++) {
23831: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
23832: var server = serveritem.value;
23833: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23834: if (server == addtarget) {
23835: serveritem.disabled = '';
23836: }
23837: }
23838: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23839: if (server == removetarget) {
23840: serveritem.disabled = 'disabled';
23841: serveritem.checked = false;
23842: }
23843: }
23844: }
23845: }
23846: for (var j=0; j<insttypes.length; j++) {
23847: if (insttypes[j] != '_LC_external') {
23848: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
23849: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
23850: var currSel = singleserver.selectedIndex;
23851: var currVal = singleserver.options[currSel].value;
23852: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23853: var numoptions = singleserver.options.length;
23854: var needsnew = 1;
23855: for (var k=0; k<numoptions; k++) {
23856: if (singleserver.options[k] == addtarget) {
23857: needsnew = 0;
23858: break;
23859: }
23860: }
23861: if (needsnew == 1) {
23862: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
23863: }
23864: }
23865: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23866: singleserver.options.length = 0;
23867: if ((currVal) && (currVal != removetarget)) {
23868: singleserver.options[0] = new Option("","",false,false);
23869: } else {
23870: singleserver.options[0] = new Option("","",true,true);
23871: }
23872: var idx = 0;
23873: for (var m=0; m<alltargets.length; m++) {
23874: if (currBalancers.indexOf(alltargets[m]) == -1) {
23875: idx ++;
23876: if (currVal == alltargets[m]) {
23877: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
23878: } else {
23879: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
23880: }
23881: }
23882: }
23883: }
23884: }
23885: }
23886: }
1.150 raeburn 23887: }
23888: }
23889: }
23890: return;
23891: }
23892:
1.152 raeburn 23893: // ]]>
23894: </script>
23895:
23896: END
23897: }
23898:
23899: sub new_spares_js {
23900: my @sparestypes = ('primary','default');
23901: my $types = join("','",@sparestypes);
23902: my $select = &mt('Select');
23903: return <<"END";
23904:
23905: <script type="text/javascript">
23906: // <![CDATA[
23907:
23908: function updateNewSpares(formname,lonhost) {
23909: var types = new Array('$types');
23910: var include = new Array();
23911: var exclude = new Array();
23912: for (var i=0; i<types.length; i++) {
23913: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
23914: for (var j=0; j<spareboxes.length; j++) {
23915: if (formname.elements[spareboxes[j]].checked) {
23916: exclude.push(formname.elements[spareboxes[j]].value);
23917: } else {
23918: include.push(formname.elements[spareboxes[j]].value);
23919: }
23920: }
23921: }
23922: for (var i=0; i<types.length; i++) {
23923: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
23924: var selIdx = newSpare.selectedIndex;
23925: var currnew = newSpare.options[selIdx].value;
23926: var okSpares = new Array();
23927: for (var j=0; j<newSpare.options.length; j++) {
23928: var possible = newSpare.options[j].value;
23929: if (possible != '') {
23930: if (exclude.indexOf(possible) == -1) {
23931: okSpares.push(possible);
23932: } else {
23933: if (currnew == possible) {
23934: selIdx = 0;
23935: }
23936: }
23937: }
23938: }
23939: for (var k=0; k<include.length; k++) {
23940: if (okSpares.indexOf(include[k]) == -1) {
23941: okSpares.push(include[k]);
23942: }
23943: }
23944: okSpares.sort();
23945: newSpare.options.length = 0;
23946: if (selIdx == 0) {
23947: newSpare.options[0] = new Option("$select","",true,true);
23948: } else {
23949: newSpare.options[0] = new Option("$select","",false,false);
23950: }
23951: for (var m=0; m<okSpares.length; m++) {
23952: var idx = m+1;
23953: var selThis = 0;
23954: if (selIdx != 0) {
23955: if (okSpares[m] == currnew) {
23956: selThis = 1;
23957: }
23958: }
23959: if (selThis == 1) {
23960: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
23961: } else {
23962: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
23963: }
23964: }
23965: }
23966: return;
23967: }
23968:
23969: function checkNewSpares(lonhost,type) {
23970: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
23971: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.372 raeburn 23972: if (chosen != '') {
1.152 raeburn 23973: var othertype;
23974: var othernewSpare;
23975: if (type == 'primary') {
23976: othernewSpare = document.getElementById('newspare_default_'+lonhost);
23977: }
23978: if (type == 'default') {
23979: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
23980: }
23981: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
23982: othernewSpare.selectedIndex = 0;
23983: }
23984: }
23985: return;
23986: }
23987:
23988: // ]]>
23989: </script>
23990:
23991: END
23992:
23993: }
23994:
23995: sub common_domprefs_js {
23996: return <<"END";
23997:
23998: <script type="text/javascript">
23999: // <![CDATA[
24000:
1.150 raeburn 24001: function getIndicesByName(formname,item) {
1.152 raeburn 24002: var group = new Array();
1.150 raeburn 24003: for (var i=0;i<formname.elements.length;i++) {
24004: if (formname.elements[i].name == item) {
1.152 raeburn 24005: group.push(formname.elements[i].id);
1.150 raeburn 24006: }
24007: }
1.152 raeburn 24008: return group;
1.150 raeburn 24009: }
24010:
24011: // ]]>
24012: </script>
24013:
24014: END
1.152 raeburn 24015:
1.150 raeburn 24016: }
24017:
1.165 raeburn 24018: sub recaptcha_js {
24019: my %lt = &captcha_phrases();
24020: return <<"END";
24021:
24022: <script type="text/javascript">
24023: // <![CDATA[
24024:
24025: function updateCaptcha(caller,context) {
24026: var privitem;
24027: var pubitem;
24028: var privtext;
24029: var pubtext;
1.269 raeburn 24030: var versionitem;
24031: var versiontext;
1.165 raeburn 24032: if (document.getElementById(context+'_recaptchapub')) {
24033: pubitem = document.getElementById(context+'_recaptchapub');
24034: } else {
24035: return;
24036: }
24037: if (document.getElementById(context+'_recaptchapriv')) {
24038: privitem = document.getElementById(context+'_recaptchapriv');
24039: } else {
24040: return;
24041: }
24042: if (document.getElementById(context+'_recaptchapubtxt')) {
24043: pubtext = document.getElementById(context+'_recaptchapubtxt');
24044: } else {
24045: return;
24046: }
24047: if (document.getElementById(context+'_recaptchaprivtxt')) {
24048: privtext = document.getElementById(context+'_recaptchaprivtxt');
24049: } else {
24050: return;
24051: }
1.269 raeburn 24052: if (document.getElementById(context+'_recaptchaversion')) {
24053: versionitem = document.getElementById(context+'_recaptchaversion');
24054: } else {
24055: return;
24056: }
24057: if (document.getElementById(context+'_recaptchavertxt')) {
24058: versiontext = document.getElementById(context+'_recaptchavertxt');
24059: } else {
24060: return;
24061: }
1.165 raeburn 24062: if (caller.checked) {
24063: if (caller.value == 'recaptcha') {
24064: pubitem.type = 'text';
24065: privitem.type = 'text';
24066: pubitem.size = '40';
24067: privitem.size = '40';
24068: pubtext.innerHTML = "$lt{'pub'}";
24069: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 24070: versionitem.type = 'text';
24071: versionitem.size = '3';
1.289 raeburn 24072: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 24073: } else {
24074: pubitem.type = 'hidden';
24075: privitem.type = 'hidden';
1.269 raeburn 24076: versionitem.type = 'hidden';
1.165 raeburn 24077: pubtext.innerHTML = '';
24078: privtext.innerHTML = '';
1.269 raeburn 24079: versiontext.innerHTML = '';
1.165 raeburn 24080: }
24081: }
24082: return;
24083: }
24084:
24085: // ]]>
24086: </script>
24087:
24088: END
24089:
24090: }
24091:
1.236 raeburn 24092: sub toggle_display_js {
1.192 raeburn 24093: return <<"END";
24094:
24095: <script type="text/javascript">
24096: // <![CDATA[
24097:
1.236 raeburn 24098: function toggleDisplay(domForm,caller) {
24099: if (document.getElementById(caller)) {
24100: var divitem = document.getElementById(caller);
24101: var optionsElement = domForm.coursecredits;
1.264 raeburn 24102: var checkval = 1;
24103: var dispval = 'block';
1.303 raeburn 24104: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 24105: if (caller == 'emailoptions') {
1.372 raeburn 24106: optionsElement = domForm.cancreate_email;
1.236 raeburn 24107: }
1.257 raeburn 24108: if (caller == 'studentsubmission') {
24109: optionsElement = domForm.postsubmit;
24110: }
1.264 raeburn 24111: if (caller == 'cloneinstcode') {
24112: optionsElement = domForm.canclone;
24113: checkval = 'instcode';
24114: }
1.303 raeburn 24115: if (selfcreateRegExp.test(caller)) {
24116: optionsElement = domForm.elements[caller];
24117: checkval = 'other';
24118: dispval = 'inline'
24119: }
1.236 raeburn 24120: if (optionsElement.length) {
1.192 raeburn 24121: var currval;
1.236 raeburn 24122: for (var i=0; i<optionsElement.length; i++) {
24123: if (optionsElement[i].checked) {
24124: currval = optionsElement[i].value;
1.192 raeburn 24125: }
24126: }
1.264 raeburn 24127: if (currval == checkval) {
24128: divitem.style.display = dispval;
1.192 raeburn 24129: } else {
1.236 raeburn 24130: divitem.style.display = 'none';
1.192 raeburn 24131: }
24132: }
24133: }
24134: return;
24135: }
24136:
24137: // ]]>
24138: </script>
24139:
24140: END
24141:
24142: }
24143:
1.165 raeburn 24144: sub captcha_phrases {
24145: return &Apache::lonlocal::texthash (
24146: priv => 'Private key',
24147: pub => 'Public key',
24148: original => 'original (CAPTCHA)',
24149: recaptcha => 'successor (ReCAPTCHA)',
24150: notused => 'unused',
1.289 raeburn 24151: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 24152: );
24153: }
24154:
1.205 raeburn 24155: sub devalidate_remote_domconfs {
1.212 raeburn 24156: my ($dom,$cachekeys) = @_;
24157: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 24158: my %servers = &Apache::lonnet::internet_dom_servers($dom);
24159: my %thismachine;
24160: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 raeburn 24161: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.394 raeburn 24162: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
1.410 raeburn 24163: 'ipaccess','trust');
1.386 raeburn 24164: my %cache_by_lonhost;
24165: if (exists($cachekeys->{'samllanding'})) {
24166: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
24167: my %landing = %{$cachekeys->{'samllanding'}};
24168: my %domservers = &Apache::lonnet::get_servers($dom);
24169: if (keys(%domservers)) {
24170: foreach my $server (keys(%domservers)) {
24171: my @cached;
24172: next if ($thismachine{$server});
24173: if ($landing{$server}) {
24174: push(@cached,&escape('samllanding').':'.&escape($server));
24175: }
24176: if (@cached) {
24177: $cache_by_lonhost{$server} = \@cached;
24178: }
24179: }
24180: }
24181: }
24182: }
1.260 raeburn 24183: if (keys(%servers)) {
1.205 raeburn 24184: foreach my $server (keys(%servers)) {
24185: next if ($thismachine{$server});
1.212 raeburn 24186: my @cached;
24187: foreach my $name (@posscached) {
24188: if ($cachekeys->{$name}) {
1.388 raeburn 24189: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
1.386 raeburn 24190: if (ref($cachekeys->{$name}) eq 'HASH') {
1.373 raeburn 24191: foreach my $key (keys(%{$cachekeys->{$name}})) {
24192: push(@cached,&escape($name).':'.&escape($key));
24193: }
24194: }
24195: } else {
24196: push(@cached,&escape($name).':'.&escape($dom));
24197: }
1.212 raeburn 24198: }
24199: }
1.386 raeburn 24200: if ((exists($cache_by_lonhost{$server})) &&
24201: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
24202: push(@cached,@{$cache_by_lonhost{$server}});
24203: }
1.212 raeburn 24204: if (@cached) {
24205: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
24206: }
1.205 raeburn 24207: }
24208: }
24209: return;
24210: }
24211:
1.3 raeburn 24212: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>