Annotation of loncom/interface/domainprefs.pm, revision 1.445
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.445 ! raeburn 4: # $Id: domainprefs.pm,v 1.444 2024/10/11 23:29:34 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
1.286 raeburn 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
1.1 raeburn 24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: ###############################################################
1.297 raeburn 30: ###############################################################
1.1 raeburn 31:
1.101 raeburn 32: =pod
33:
34: =head1 NAME
35:
36: Apache::domainprefs.pm
37:
38: =head1 SYNOPSIS
39:
40: Handles configuration of a LON-CAPA domain.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
45:
46: =head1 OVERVIEW
47:
48: Each institution using LON-CAPA will typically have a single domain designated
1.183 bisitz 49: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 50: may define a default set of logos and a color scheme which can be used to "brand"
51: the LON-CAPA instance. In addition, an institution will typically have a language
52: and timezone which are used for the majority of courses.
53:
54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
55: host of other domain-wide settings which determine the types of functionality
56: available to users and courses in the domain.
57:
58: There is also a mechanism to configure cataloging of courses in the domain, and
59: controls on the operation of automated processes which govern such things as
60: roster updates, user directory updates and processing of course requests.
61:
62: The domain coordination manual which is built dynamically on install/update of
63: LON-CAPA from the relevant help items provides more information about domain
64: configuration.
65:
66: Most of the domain settings are stored in the configuration.db GDBM file which is
67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
68: where $dom is the domain. The configuration.db stores settings in a number of
69: frozen hashes of hashes. In a few cases, domain information must be uploaded to
70: the domain as files (e.g., image files for logos etc., or plain text files for
71: bubblesheet formats). In this case the domainprefs.pm must be running in a user
72: session hosted on the primary library server in the domain, as these files are
73: stored in author space belonging to a special $dom-domainconfig user.
74:
75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
76: the current settings, and provides an interface to make modifications.
77:
78: =head1 SUBROUTINES
79:
80: =over
81:
82: =item print_quotas()
83:
84: Inputs: 4
85:
86: $dom,$settings,$rowtotal,$action.
87:
88: $dom is the domain, $settings is a reference to a hash of current settings for
89: the current context, $rowtotal is a reference to the scalar used to record the
1.210 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.163 raeburn 91: requestcourses or requestauthor).
1.101 raeburn 92:
93: The print_quotas routine was orginally created to display/store information
94: about default quota sizes for portfolio spaces for the different types of
95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
96: but is now also used to manage availability of user tools:
97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.429 raeburn 98: used by course owners to request creation of a course.
1.101 raeburn 99:
100: Outputs: 1
101:
102: $datatable - HTML containing form elements which allow settings to be changed.
103:
104: In the case of course requests, radio buttons are displayed for each institutional
105: affiliate type (and also default, and _LC_adv) for each of the course types
1.325 raeburn 106: (official, unofficial, community, textbook, placement, and lti).
1.425 raeburn 107: In each case the radio buttons allow the selection of one of four values:
1.101 raeburn 108:
1.104 raeburn 109: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 110: which have the following effects:
111:
112: 0
113:
114: =over
115:
116: - course requests are not allowed for this course types/affiliation
117:
118: =back
119:
1.104 raeburn 120: approval
1.101 raeburn 121:
122: =over
123:
124: - course requests must be approved by a Doman Coordinator in the
125: course's domain
126:
127: =back
128:
129: validate
130:
131: =over
132:
133: - an institutional validation (e.g., check requestor is instructor
134: of record) needs to be passed before the course will be created. The required
135: validation is in localenroll.pm on the primary library server for the course
136: domain.
137:
138: =back
139:
140: autolimit
141:
142: =over
143:
1.143 raeburn 144: - course requests will be processed automatically up to a limit of
1.101 raeburn 145: N requests for the course type for the particular requestor.
146: If N is undefined, there is no limit to the number of course requests
147: which a course owner may submit and have processed automatically.
148:
149: =back
150:
151: =item modify_quotas()
152:
153: =back
154:
155: =cut
156:
1.1 raeburn 157: package Apache::domainprefs;
158:
159: use strict;
160: use Apache::Constants qw(:common :http);
161: use Apache::lonnet;
162: use Apache::loncommon();
163: use Apache::lonhtmlcommon();
164: use Apache::lonlocal;
1.43 raeburn 165: use Apache::lonmsg();
1.91 raeburn 166: use Apache::lonconfigsettings;
1.232 raeburn 167: use Apache::lonuserutils();
1.235 raeburn 168: use Apache::loncoursequeueadmin();
1.419 raeburn 169: use Apache::courseprefs();
1.69 raeburn 170: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 171: use LONCAPA::Enrollment;
1.81 raeburn 172: use LONCAPA::lonauthcgi();
1.275 raeburn 173: use LONCAPA::SSL;
1.9 raeburn 174: use File::Copy;
1.43 raeburn 175: use Locale::Language;
1.62 raeburn 176: use DateTime::TimeZone;
1.68 raeburn 177: use DateTime::Locale;
1.267 raeburn 178: use Time::HiRes qw( sleep );
1.373 raeburn 179: use Net::CIDR;
1.424 raeburn 180: use Crypt::CBC;
1.1 raeburn 181:
1.155 raeburn 182: my $registered_cleanup;
183: my $modified_urls;
184:
1.1 raeburn 185: sub handler {
186: my $r=shift;
187: if ($r->header_only) {
188: &Apache::loncommon::content_type($r,'text/html');
189: $r->send_http_header;
190: return OK;
191: }
192:
1.91 raeburn 193: my $context = 'domain';
1.1 raeburn 194: my $dom = $env{'request.role.domain'};
1.5 albertel 195: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 196: if (&Apache::lonnet::allowed('mau',$dom)) {
197: &Apache::loncommon::content_type($r,'text/html');
198: $r->send_http_header;
199: } else {
200: $env{'user.error.msg'}=
201: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
202: return HTTP_NOT_ACCEPTABLE;
203: }
1.155 raeburn 204:
205: $registered_cleanup=0;
206: @{$modified_urls}=();
207:
1.1 raeburn 208: &Apache::lonhtmlcommon::clear_breadcrumbs();
209: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 210: ['phase','actions']);
1.30 raeburn 211: my $phase = 'pickactions';
1.3 raeburn 212: if ( exists($env{'form.phase'}) ) {
213: $phase = $env{'form.phase'};
214: }
1.150 raeburn 215: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 216: my %domconfig =
1.6 raeburn 217: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 218: 'quotas','autoenroll','autoupdate','autocreate',
219: 'directorysrch','usercreation','usermodification',
220: 'contacts','defaults','scantron','coursecategories',
221: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 222: 'coursedefaults','usersessions','loadbalancing',
1.267 raeburn 223: 'requestauthor','selfenrollment','inststatus',
1.421 raeburn 224: 'ltitools','toolsec','ssl','trust','lti','ltisec',
1.429 raeburn 225: 'privacy','passwords','proctoring','wafproxy',
226: 'ipaccess','authordefaults'],$dom);
1.320 raeburn 227: my %encconfig =
1.405 raeburn 228: &Apache::lonnet::get_dom('encconfig',['ltitools','lti','proctoring','linkprot'],$dom,undef,1);
1.424 raeburn 229: my ($checked_is_home,$is_home);
1.297 raeburn 230: if (ref($domconfig{'ltitools'}) eq 'HASH') {
231: if (ref($encconfig{'ltitools'}) eq 'HASH') {
1.423 raeburn 232: my $home = &Apache::lonnet::domain($dom,'primary');
233: unless (($home eq 'no_host') || ($home eq '')) {
234: my @ids=&Apache::lonnet::current_machine_ids();
235: if (grep(/^\Q$home\E$/,@ids)) {
236: $is_home = 1;
237: }
238: }
1.425 raeburn 239: $checked_is_home = 1;
1.297 raeburn 240: foreach my $id (keys(%{$domconfig{'ltitools'}})) {
1.320 raeburn 241: if ((ref($domconfig{'ltitools'}{$id}) eq 'HASH') &&
242: (ref($encconfig{'ltitools'}{$id}) eq 'HASH')) {
1.421 raeburn 243: $domconfig{'ltitools'}{$id}{'key'} = $encconfig{'ltitools'}{$id}{'key'};
1.423 raeburn 244: if (($is_home) && ($phase eq 'process')) {
245: $domconfig{'ltitools'}{$id}{'secret'} = $encconfig{'ltitools'}{$id}{'secret'};
246: }
1.297 raeburn 247: }
248: }
249: }
250: }
1.320 raeburn 251: if (ref($domconfig{'lti'}) eq 'HASH') {
252: if (ref($encconfig{'lti'}) eq 'HASH') {
1.424 raeburn 253: unless ($checked_is_home) {
254: my $home = &Apache::lonnet::domain($dom,'primary');
255: unless (($home eq 'no_host') || ($home eq '')) {
256: my @ids=&Apache::lonnet::current_machine_ids();
257: if (grep(/^\Q$home\E$/,@ids)) {
258: $is_home = 1;
259: }
260: }
261: $checked_is_home = 1;
262: }
1.320 raeburn 263: foreach my $id (keys(%{$domconfig{'lti'}})) {
264: if ((ref($domconfig{'lti'}{$id}) eq 'HASH') &&
265: (ref($encconfig{'lti'}{$id}) eq 'HASH')) {
1.424 raeburn 266: $domconfig{'lti'}{$id}{'key'} = $encconfig{'lti'}{$id}{'key'};
267: if (($is_home) && ($phase eq 'process')) {
268: $domconfig{'lti'}{$id}{'secret'} = $encconfig{'lti'}{$id}{'secret'};
1.320 raeburn 269: }
270: }
271: }
272: }
273: }
1.405 raeburn 274: if (ref($domconfig{'ltisec'}) eq 'HASH') {
1.406 raeburn 275: if (ref($domconfig{'ltisec'}{'linkprot'}) eq 'HASH') {
1.405 raeburn 276: if (ref($encconfig{'linkprot'}) eq 'HASH') {
1.406 raeburn 277: foreach my $id (keys(%{$domconfig{'ltisec'}{'linkprot'}})) {
278: unless ($id =~ /^\d+$/) {
279: delete($domconfig{'ltisec'}{'linkprot'}{$id});
280: }
281: if ((ref($domconfig{'ltisec'}{'linkprot'}{$id}) eq 'HASH') &&
1.405 raeburn 282: (ref($encconfig{'linkprot'}{$id}) eq 'HASH')) {
283: foreach my $item ('key','secret') {
1.406 raeburn 284: $domconfig{'ltisec'}{'linkprot'}{$id}{$item} = $encconfig{'linkprot'}{$id}{$item};
1.405 raeburn 285: }
286: }
287: }
288: }
289: }
290: }
1.372 raeburn 291: if (ref($domconfig{'proctoring'}) eq 'HASH') {
292: if (ref($encconfig{'proctoring'}) eq 'HASH') {
293: foreach my $provider (keys(%{$domconfig{'proctoring'}})) {
294: if ((ref($domconfig{'proctoring'}{$provider}) eq 'HASH') &&
295: (ref($encconfig{'proctoring'}{$provider}) eq 'HASH')) {
296: foreach my $item ('key','secret') {
297: $domconfig{'proctoring'}{$provider}{$item} = $encconfig{'proctoring'}{$provider}{$item};
298: }
299: }
300: }
301: }
302: }
1.394 raeburn 303: my @prefs_order = ('rolecolors','login','ipaccess','defaults','wafproxy','passwords',
304: 'quotas','autoenroll','autoupdate','autocreate','directorysrch',
1.373 raeburn 305: 'contacts','privacy','usercreation','selfcreation',
1.374 raeburn 306: 'usermodification','scantron','requestcourses','requestauthor',
1.373 raeburn 307: 'coursecategories','serverstatuses','helpsettings','coursedefaults',
1.429 raeburn 308: 'authordefaults','ltitools','proctoring','selfenrollment',
309: 'usersessions','ssl','trust','lti');
1.171 raeburn 310: my %existing;
311: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
312: %existing = %{$domconfig{'loadbalancing'}};
313: }
314: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 315: push(@prefs_order,'loadbalancing');
316: }
1.30 raeburn 317: my %prefs = (
318: 'rolecolors' =>
319: { text => 'Default color schemes',
1.67 raeburn 320: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 321: header => [{col1 => 'Student Settings',
322: col2 => '',},
323: {col1 => 'Coordinator Settings',
324: col2 => '',},
325: {col1 => 'Author Settings',
326: col2 => '',},
327: {col1 => 'Administrator Settings',
328: col2 => '',}],
1.230 raeburn 329: print => \&print_rolecolors,
330: modify => \&modify_rolecolors,
1.30 raeburn 331: },
1.110 raeburn 332: 'login' =>
1.30 raeburn 333: { text => 'Log-in page options',
1.67 raeburn 334: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 335: header => [{col1 => 'Log-in Page Items',
336: col2 => '',},
337: {col1 => 'Log-in Help',
1.256 raeburn 338: col2 => 'Value'},
339: {col1 => 'Custom HTML in document head',
1.386 raeburn 340: col2 => 'Value'},
341: {col1 => 'SSO',
342: col2 => 'Dual login: SSO and non-SSO options'},
343: ],
1.230 raeburn 344: print => \&print_login,
345: modify => \&modify_login,
1.30 raeburn 346: },
1.43 raeburn 347: 'defaults' =>
1.236 raeburn 348: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 349: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 350: header => [{col1 => 'Setting',
1.236 raeburn 351: col2 => 'Value'},
352: {col1 => 'Institutional user types',
1.409 raeburn 353: col2 => 'Name displayed'},
354: {col1 => 'Mapping for missing usernames via standard log-in',
355: col2 => 'Rules in use'}],
1.230 raeburn 356: print => \&print_defaults,
357: modify => \&modify_defaults,
1.43 raeburn 358: },
1.381 raeburn 359: 'wafproxy' =>
360: { text => 'Web Application Firewall/Reverse Proxy',
1.373 raeburn 361: help => 'Domain_Configuration_WAF_Proxy',
1.381 raeburn 362: header => [{col1 => 'Domain(s)',
363: col2 => 'Servers and WAF/Reverse Proxy alias(es)',
1.373 raeburn 364: },
1.381 raeburn 365: {col1 => 'Domain(s)',
366: col2 => 'WAF Configuration',}],
1.373 raeburn 367: print => \&print_wafproxy,
1.381 raeburn 368: modify => \&modify_wafproxy,
1.373 raeburn 369: },
1.354 raeburn 370: 'passwords' =>
371: { text => 'Passwords (Internal authentication)',
372: help => 'Domain_Configuration_Passwords',
373: header => [{col1 => 'Resetting Forgotten Password',
374: col2 => 'Settings'},
375: {col1 => 'Encryption of Stored Passwords (Internal Auth)',
376: col2 => 'Settings'},
377: {col1 => 'Rules for LON-CAPA Passwords',
378: col2 => 'Settings'},
379: {col1 => 'Course Owner Changing Student Passwords',
380: col2 => 'Settings'}],
381: print => \&print_passwords,
382: modify => \&modify_passwords,
383: },
1.30 raeburn 384: 'quotas' =>
1.429 raeburn 385: { text => 'Blogs, personal pages/timezones, portfolio/quotas',
1.67 raeburn 386: help => 'Domain_Configuration_Quotas',
1.77 raeburn 387: header => [{col1 => 'User affiliation',
1.72 raeburn 388: col2 => 'Available tools',
1.435 raeburn 389: col3 => 'Portfolio quota (MB)',}],
1.230 raeburn 390: print => \&print_quotas,
391: modify => \&modify_quotas,
1.30 raeburn 392: },
393: 'autoenroll' =>
394: { text => 'Auto-enrollment settings',
1.67 raeburn 395: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 396: header => [{col1 => 'Configuration setting',
397: col2 => 'Value(s)'}],
1.230 raeburn 398: print => \&print_autoenroll,
399: modify => \&modify_autoenroll,
1.30 raeburn 400: },
401: 'autoupdate' =>
402: { text => 'Auto-update settings',
1.67 raeburn 403: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 404: header => [{col1 => 'Setting',
405: col2 => 'Value',},
1.131 raeburn 406: {col1 => 'Setting',
407: col2 => 'Affiliation'},
1.43 raeburn 408: {col1 => 'User population',
1.227 bisitz 409: col2 => 'Updatable user data'}],
1.230 raeburn 410: print => \&print_autoupdate,
411: modify => \&modify_autoupdate,
1.30 raeburn 412: },
1.125 raeburn 413: 'autocreate' =>
414: { text => 'Auto-course creation settings',
415: help => 'Domain_Configuration_Auto_Creation',
416: header => [{col1 => 'Configuration Setting',
417: col2 => 'Value',}],
1.230 raeburn 418: print => \&print_autocreate,
419: modify => \&modify_autocreate,
1.125 raeburn 420: },
1.30 raeburn 421: 'directorysrch' =>
1.277 raeburn 422: { text => 'Directory searches',
1.67 raeburn 423: help => 'Domain_Configuration_InstDirectory_Search',
1.277 raeburn 424: header => [{col1 => 'Institutional Directory Setting',
425: col2 => 'Value',},
426: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 427: col2 => 'Value',}],
1.230 raeburn 428: print => \&print_directorysrch,
429: modify => \&modify_directorysrch,
1.30 raeburn 430: },
431: 'contacts' =>
1.286 raeburn 432: { text => 'E-mail addresses and helpform',
1.67 raeburn 433: help => 'Domain_Configuration_Contact_Info',
1.286 raeburn 434: header => [{col1 => 'Default e-mail addresses',
435: col2 => 'Value',},
436: {col1 => 'Recipient(s) for notifications',
437: col2 => 'Value',},
1.340 raeburn 438: {col1 => 'Nightly status check e-mail',
439: col2 => 'Settings',},
1.286 raeburn 440: {col1 => 'Ask helpdesk form settings',
441: col2 => 'Value',},],
1.230 raeburn 442: print => \&print_contacts,
443: modify => \&modify_contacts,
1.30 raeburn 444: },
445: 'usercreation' =>
446: { text => 'User creation',
1.67 raeburn 447: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 448: header => [{col1 => 'Format rule type',
449: col2 => 'Format rules in force'},
1.34 raeburn 450: {col1 => 'User account creation',
451: col2 => 'Usernames which may be created',},
1.30 raeburn 452: {col1 => 'Context',
1.43 raeburn 453: col2 => 'Assignable authentication types'}],
1.230 raeburn 454: print => \&print_usercreation,
455: modify => \&modify_usercreation,
1.30 raeburn 456: },
1.224 raeburn 457: 'selfcreation' =>
458: { text => 'Users self-creating accounts',
459: help => 'Domain_Configuration_Self_Creation',
460: header => [{col1 => 'Self-creation with institutional username',
461: col2 => 'Enabled?'},
462: {col1 => 'Institutional user type (login/SSO self-creation)',
463: col2 => 'Information user can enter'},
1.303 raeburn 464: {col1 => 'Self-creation with e-mail verification',
1.224 raeburn 465: col2 => 'Settings'}],
1.230 raeburn 466: print => \&print_selfcreation,
467: modify => \&modify_selfcreation,
1.224 raeburn 468: },
1.69 raeburn 469: 'usermodification' =>
1.33 raeburn 470: { text => 'User modification',
1.67 raeburn 471: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 472: header => [{col1 => 'Target user has role',
1.227 bisitz 473: col2 => 'User information updatable in author context'},
1.33 raeburn 474: {col1 => 'Target user has role',
1.443 raeburn 475: col2 => 'User information updatable by co-author manager'},
476: {col1 => 'Target user has role',
1.227 bisitz 477: col2 => 'User information updatable in course context'}],
1.230 raeburn 478: print => \&print_usermodification,
479: modify => \&modify_usermodification,
1.33 raeburn 480: },
1.69 raeburn 481: 'scantron' =>
1.346 raeburn 482: { text => 'Bubblesheet format',
1.67 raeburn 483: help => 'Domain_Configuration_Scantron_Format',
1.346 raeburn 484: header => [ {col1 => 'Bubblesheet format file',
485: col2 => ''},
486: {col1 => 'Bubblesheet data upload formats',
487: col2 => 'Settings'}],
1.230 raeburn 488: print => \&print_scantron,
489: modify => \&modify_scantron,
1.46 raeburn 490: },
1.86 raeburn 491: 'requestcourses' =>
492: {text => 'Request creation of courses',
493: help => 'Domain_Configuration_Request_Courses',
494: header => [{col1 => 'User affiliation',
1.102 raeburn 495: col2 => 'Availability/Processing of requests',},
496: {col1 => 'Setting',
1.216 raeburn 497: col2 => 'Value'},
498: {col1 => 'Available textbooks',
1.235 raeburn 499: col2 => ''},
1.242 raeburn 500: {col1 => 'Available templates',
501: col2 => ''},
1.235 raeburn 502: {col1 => 'Validation (not official courses)',
503: col2 => 'Value'},],
1.230 raeburn 504: print => \&print_quotas,
505: modify => \&modify_quotas,
1.86 raeburn 506: },
1.163 raeburn 507: 'requestauthor' =>
1.223 bisitz 508: {text => 'Request Authoring Space',
1.163 raeburn 509: help => 'Domain_Configuration_Request_Author',
510: header => [{col1 => 'User affiliation',
511: col2 => 'Availability/Processing of requests',},
512: {col1 => 'Setting',
513: col2 => 'Value'}],
1.230 raeburn 514: print => \&print_quotas,
515: modify => \&modify_quotas,
1.163 raeburn 516: },
1.69 raeburn 517: 'coursecategories' =>
1.120 raeburn 518: { text => 'Cataloging of courses/communities',
1.67 raeburn 519: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 520: header => [{col1 => 'Catalog type/availability',
521: col2 => '',},
522: {col1 => 'Category settings for standard catalog',
1.57 raeburn 523: col2 => '',},
524: {col1 => 'Categories',
525: col2 => '',
526: }],
1.230 raeburn 527: print => \&print_coursecategories,
528: modify => \&modify_coursecategories,
1.69 raeburn 529: },
530: 'serverstatuses' =>
1.77 raeburn 531: {text => 'Access to server status pages',
1.69 raeburn 532: help => 'Domain_Configuration_Server_Status',
533: header => [{col1 => 'Status Page',
534: col2 => 'Other named users',
535: col3 => 'Specific IPs',
536: }],
1.230 raeburn 537: print => \&print_serverstatuses,
538: modify => \&modify_serverstatuses,
1.69 raeburn 539: },
1.118 jms 540: 'helpsettings' =>
1.282 raeburn 541: {text => 'Support settings',
1.118 jms 542: help => 'Domain_Configuration_Help_Settings',
1.282 raeburn 543: header => [{col1 => 'Help Page Settings (logged-in users)',
544: col2 => 'Value'},
545: {col1 => 'Helpdesk Roles',
546: col2 => 'Settings'},],
1.230 raeburn 547: print => \&print_helpsettings,
548: modify => \&modify_helpsettings,
1.118 jms 549: },
1.121 raeburn 550: 'coursedefaults' =>
551: {text => 'Course/Community defaults',
552: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 553: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
554: col2 => 'Value',},
555: {col1 => 'Defaults which can be overridden for each course by a DC',
556: col2 => 'Value',},],
1.230 raeburn 557: print => \&print_coursedefaults,
558: modify => \&modify_coursedefaults,
1.121 raeburn 559: },
1.231 raeburn 560: 'selfenrollment' =>
561: {text => 'Self-enrollment in Course/Community',
562: help => 'Domain_Configuration_Selfenrollment',
563: header => [{col1 => 'Configuration Rights',
564: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
565: {col1 => 'Defaults',
566: col2 => 'Value'},
567: {col1 => 'Self-enrollment validation (optional)',
568: col2 => 'Value'},],
569: print => \&print_selfenrollment,
570: modify => \&modify_selfenrollment,
571: },
1.120 raeburn 572: 'privacy' =>
1.427 raeburn 573: {text => 'Role assignments and user privacy',
1.120 raeburn 574: help => 'Domain_Configuration_User_Privacy',
1.357 raeburn 575: header => [{col1 => 'Role assigned in different domain',
576: col2 => 'Approval options'},
577: {col1 => 'Role assigned in different domain to user of type',
578: col2 => 'User information available in that domain'},
579: {col1 => "Role assigned in user's domain",
580: col2 => 'Information viewable by privileged user'},
581: {col1 => "Role assigned in user's domain",
582: col2 => 'Information viewable by unprivileged user'}],
1.230 raeburn 583: print => \&print_privacy,
584: modify => \&modify_privacy,
1.120 raeburn 585: },
1.141 raeburn 586: 'usersessions' =>
1.145 raeburn 587: {text => 'User session hosting/offloading',
1.137 raeburn 588: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 589: header => [{col1 => 'Domain server',
590: col2 => 'Servers to offload sessions to when busy'},
591: {col1 => 'Hosting of users from other domains',
1.137 raeburn 592: col2 => 'Rules'},
593: {col1 => "Hosting domain's own users elsewhere",
594: col2 => 'Rules'}],
1.230 raeburn 595: print => \&print_usersessions,
596: modify => \&modify_usersessions,
1.137 raeburn 597: },
1.279 raeburn 598: 'loadbalancing' =>
1.185 raeburn 599: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 600: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 601: header => [{col1 => 'Balancers',
1.150 raeburn 602: col2 => 'Default destinations',
1.183 bisitz 603: col3 => 'User affiliation',
1.150 raeburn 604: col4 => 'Overrides'},
605: ],
1.230 raeburn 606: print => \&print_loadbalancing,
607: modify => \&modify_loadbalancing,
1.150 raeburn 608: },
1.425 raeburn 609: 'ltitools' =>
1.267 raeburn 610: {text => 'External Tools (LTI)',
1.296 raeburn 611: help => 'Domain_Configuration_LTI_Tools',
1.421 raeburn 612: header => [{col1 => 'Encryption of shared secrets',
613: col2 => 'Settings'},
614: {col1 => 'Rules for shared secrets',
615: col2 => 'Settings'},
616: {col1 => 'Providers',
617: col2 => 'Settings',}],
1.267 raeburn 618: print => \&print_ltitools,
619: modify => \&modify_ltitools,
620: },
1.372 raeburn 621: 'proctoring' =>
622: {text => 'Remote Proctoring Integration',
623: help => 'Domain_Configuration_Proctoring',
624: header => [{col1 => 'Name',
625: col2 => 'Configuration'}],
626: print => \&print_proctoring,
627: modify => \&modify_proctoring,
628: },
1.279 raeburn 629: 'ssl' =>
1.275 raeburn 630: {text => 'LON-CAPA Network (SSL)',
631: help => 'Domain_Configuration_Network_SSL',
632: header => [{col1 => 'Server',
633: col2 => 'Certificate Status'},
634: {col1 => 'Connections to other servers',
635: col2 => 'Rules'},
1.293 raeburn 636: {col1 => 'Connections from other servers',
637: col2 => 'Rules'},
1.275 raeburn 638: {col1 => "Replicating domain's published content",
639: col2 => 'Rules'}],
640: print => \&print_ssl,
641: modify => \&modify_ssl,
642: },
1.279 raeburn 643: 'trust' =>
644: {text => 'Trust Settings',
645: help => 'Domain_Configuration_Trust',
646: header => [{col1 => "Access to this domain's content by others",
647: col2 => 'Rules'},
648: {col1 => "Access to other domain's content by this domain",
649: col2 => 'Rules'},
650: {col1 => "Enrollment in this domain's courses by others",
651: col2 => 'Rules',},
652: {col1 => "Co-author roles in this domain for others",
653: col2 => 'Rules',},
654: {col1 => "Co-author roles for this domain's users elsewhere",
655: col2 => 'Rules',},
656: {col1 => "Domain roles in this domain assignable to others",
657: col2 => 'Rules'},
658: {col1 => "Course catalog for this domain displayed elsewhere",
659: col2 => 'Rules'},
660: {col1 => "Requests for creation of courses in this domain by others",
661: col2 => 'Rules'},
662: {col1 => "Users in other domains can send messages to this domain",
663: col2 => 'Rules'},],
664: print => \&print_trust,
665: modify => \&modify_trust,
666: },
1.425 raeburn 667: 'lti' =>
1.405 raeburn 668: {text => 'LTI Link Protection and LTI Consumers',
1.320 raeburn 669: help => 'Domain_Configuration_LTI_Provider',
1.405 raeburn 670: header => [{col1 => 'Encryption of shared secrets',
671: col2 => 'Settings'},
1.425 raeburn 672: {col1 => 'Rules for shared secrets',
1.405 raeburn 673: col2 => 'Settings'},
1.434 raeburn 674: {col1 => 'Link Protectors in Courses',
1.436 raeburn 675: col2 => 'Values'},
1.406 raeburn 676: {col1 => 'Link Protectors',
1.405 raeburn 677: col2 => 'Settings'},
678: {col1 => 'Consumers',
679: col2 => 'Settings'},],
1.320 raeburn 680: print => \&print_lti,
681: modify => \&modify_lti,
682: },
1.425 raeburn 683: 'ipaccess' =>
1.394 raeburn 684: {text => 'IP-based access control',
685: help => 'Domain_Configuration_IP_Access',
686: header => [{col1 => 'Setting',
687: col2 => 'Value'},],
688: print => \&print_ipaccess,
689: modify => \&modify_ipaccess,
690: },
1.436 raeburn 691: 'authordefaults' =>
1.429 raeburn 692: {text => 'Authoring Space defaults',
693: help => 'Domain_Configuration_Author_Defaults',
694: header => [{col1 => 'Defaults which can be overridden by Author',
695: col2 => 'Settings',},
696: {col1 => 'Defaults which can be overridden by a Dom. Coord.',
697: col2 => 'Settings',},],
698: print => \&print_authordefaults,
699: modify => \&modify_authordefaults,
700: },
1.3 raeburn 701: );
1.110 raeburn 702: if (keys(%servers) > 1) {
703: $prefs{'login'} = { text => 'Log-in page options',
704: help => 'Domain_Configuration_Login_Page',
705: header => [{col1 => 'Log-in Service',
706: col2 => 'Server Setting',},
707: {col1 => 'Log-in Page Items',
1.405 raeburn 708: col2 => 'Settings'},
1.168 raeburn 709: {col1 => 'Log-in Help',
1.256 raeburn 710: col2 => 'Value'},
711: {col1 => 'Custom HTML in document head',
1.386 raeburn 712: col2 => 'Value'},
713: {col1 => 'SSO',
714: col2 => 'Dual login: SSO and non-SSO options'},
715: ],
1.230 raeburn 716: print => \&print_login,
717: modify => \&modify_login,
1.110 raeburn 718: };
719: }
1.174 foxr 720:
1.6 raeburn 721: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 722: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 723: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 724: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 725: text=>"Settings to display/modify"});
1.9 raeburn 726: my $confname = $dom.'-domainconfig';
1.174 foxr 727:
1.3 raeburn 728: if ($phase eq 'process') {
1.212 raeburn 729: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
730: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 731: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 732: $r->rflush();
1.212 raeburn 733: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 734: }
1.30 raeburn 735: } elsif ($phase eq 'display') {
1.192 raeburn 736: my $js = &recaptcha_js().
1.236 raeburn 737: &toggle_display_js();
1.171 raeburn 738: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 739: my ($othertitle,$usertypes,$types) =
740: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 741: $js .= &lonbalance_targets_js($dom,$types,\%servers,
742: $domconfig{'loadbalancing'}).
1.170 raeburn 743: &new_spares_js().
744: &common_domprefs_js().
745: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 746: }
1.216 raeburn 747: if (grep(/^requestcourses$/,@actions)) {
748: my $javascript_validations;
749: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
750: $js .= <<END;
751: <script type="text/javascript">
752: $javascript_validations
753: </script>
754: $coursebrowserjs
755: END
1.394 raeburn 756: } elsif (grep(/^ipaccess$/,@actions)) {
757: $js .= &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
1.216 raeburn 758: }
1.305 raeburn 759: if (grep(/^selfcreation$/,@actions)) {
760: $js .= &selfcreate_javascript();
761: }
1.286 raeburn 762: if (grep(/^contacts$/,@actions)) {
763: $js .= &contacts_javascript();
764: }
1.346 raeburn 765: if (grep(/^scantron$/,@actions)) {
766: $js .= &scantron_javascript();
767: }
1.150 raeburn 768: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 769: } else {
1.180 raeburn 770: # check if domconfig user exists for the domain.
771: my $servadm = $r->dir_config('lonAdmEMail');
772: my ($configuserok,$author_ok,$switchserver) =
773: &config_check($dom,$confname,$servadm);
774: unless ($configuserok eq 'ok') {
1.181 raeburn 775: &Apache::lonconfigsettings::print_header($r,$phase,$context);
776: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 777: $confname).
1.181 raeburn 778: '<br />'
779: );
1.180 raeburn 780: if ($switchserver) {
1.181 raeburn 781: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
782: '<br />'.
783: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
784: '<br />'.
785: &mt('The "[_1]" user can be created automatically when a Domain Coordinator visits the web-based "Set domain configuration" screen, in a session hosted on the primary library server.',$confname).
786: '<br />'.
787: &mt('To do that now, use the following link: [_1]',$switchserver)
788: );
789: } else {
790: $r->print(&mt('To create that user from the command line run the ./UPDATE script found in the top level directory of the extracted LON-CAPA tarball.').
791: '<br />'.
792: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
793: );
1.180 raeburn 794: }
795: $r->print(&Apache::loncommon::end_page());
796: return OK;
797: }
1.21 raeburn 798: if (keys(%domconfig) == 0) {
799: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 800: my @ids=&Apache::lonnet::current_machine_ids();
801: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 802: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 803: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 804: my $custom_img_count = 0;
805: foreach my $img (@loginimages) {
806: if ($designhash{$dom.'.login.'.$img} ne '') {
807: $custom_img_count ++;
808: }
809: }
810: foreach my $role (@roles) {
811: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
812: $custom_img_count ++;
813: }
814: }
815: if ($custom_img_count > 0) {
1.94 raeburn 816: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 817: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 818: $r->print(
819: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
820: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
821: &mt("Thereafter, (with a Domain Coordinator role selected in the domain) you will be able to update settings when logged in to any server in the LON-CAPA network.").'<br />'.
822: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
823: if ($switch_server) {
1.30 raeburn 824: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 825: }
1.91 raeburn 826: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 827: return OK;
828: }
829: }
830: }
1.91 raeburn 831: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 832: }
833: return OK;
834: }
835:
836: sub process_changes {
1.205 raeburn 837: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 838: my %domconfig;
839: if (ref($values) eq 'HASH') {
840: %domconfig = %{$values};
841: }
1.3 raeburn 842: my $output;
843: if ($action eq 'login') {
1.205 raeburn 844: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 845: } elsif ($action eq 'rolecolors') {
1.9 raeburn 846: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 847: $lastactref,%domconfig);
1.3 raeburn 848: } elsif ($action eq 'quotas') {
1.216 raeburn 849: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 850: } elsif ($action eq 'autoenroll') {
1.205 raeburn 851: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 852: } elsif ($action eq 'autoupdate') {
853: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 854: } elsif ($action eq 'autocreate') {
855: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 856: } elsif ($action eq 'directorysrch') {
1.295 raeburn 857: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 858: } elsif ($action eq 'usercreation') {
1.28 raeburn 859: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 860: } elsif ($action eq 'selfcreation') {
1.305 raeburn 861: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 862: } elsif ($action eq 'usermodification') {
863: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 864: } elsif ($action eq 'contacts') {
1.205 raeburn 865: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 866: } elsif ($action eq 'defaults') {
1.212 raeburn 867: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 868: } elsif ($action eq 'scantron') {
1.205 raeburn 869: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 870: } elsif ($action eq 'coursecategories') {
1.239 raeburn 871: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 872: } elsif ($action eq 'serverstatuses') {
873: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 874: } elsif ($action eq 'requestcourses') {
1.216 raeburn 875: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 876: } elsif ($action eq 'requestauthor') {
1.216 raeburn 877: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 878: } elsif ($action eq 'helpsettings') {
1.285 raeburn 879: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 880: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 881: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 882: } elsif ($action eq 'selfenrollment') {
883: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 884: } elsif ($action eq 'usersessions') {
1.212 raeburn 885: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 886: } elsif ($action eq 'loadbalancing') {
887: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 888: } elsif ($action eq 'ltitools') {
889: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.372 raeburn 890: } elsif ($action eq 'proctoring') {
891: $output = &modify_proctoring($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 892: } elsif ($action eq 'ssl') {
893: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 894: } elsif ($action eq 'trust') {
895: $output = &modify_trust($dom,$lastactref,%domconfig);
1.320 raeburn 896: } elsif ($action eq 'lti') {
897: $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.357 raeburn 898: } elsif ($action eq 'privacy') {
1.427 raeburn 899: $output = &modify_privacy($dom,$lastactref,%domconfig);
1.354 raeburn 900: } elsif ($action eq 'passwords') {
901: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.373 raeburn 902: } elsif ($action eq 'wafproxy') {
903: $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
1.394 raeburn 904: } elsif ($action eq 'ipaccess') {
905: $output = &modify_ipaccess($dom,$lastactref,%domconfig);
1.429 raeburn 906: } elsif ($action eq 'authordefaults') {
907: $output = &modify_authordefaults($dom,$lastactref,%domconfig);
1.3 raeburn 908: }
909: return $output;
910: }
911:
912: sub print_config_box {
1.9 raeburn 913: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 914: my $rowtotal = 0;
1.49 raeburn 915: my $output;
916: if ($action eq 'coursecategories') {
917: $output = &coursecategories_javascript($settings);
1.236 raeburn 918: } elsif ($action eq 'defaults') {
919: $output = &defaults_javascript($settings);
1.354 raeburn 920: } elsif ($action eq 'passwords') {
1.405 raeburn 921: $output = &passwords_javascript($action);
1.282 raeburn 922: } elsif ($action eq 'helpsettings') {
923: my (%privs,%levelscurrent);
924: my %full=();
925: my %levels=(
926: course => {},
927: domain => {},
928: system => {},
929: );
930: my $context = 'domain';
931: my $crstype = 'Course';
932: my $formname = 'display';
933: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
934: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
935: $output =
1.425 raeburn 936: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
1.282 raeburn 937: \@templateroles);
1.334 raeburn 938: } elsif ($action eq 'ltitools') {
1.421 raeburn 939: $output .= &Apache::lonconfigsettings::ltitools_javascript($settings);
1.334 raeburn 940: } elsif ($action eq 'lti') {
1.421 raeburn 941: $output .= &passwords_javascript('ltisecrets')."\n".
1.405 raeburn 942: <i_javascript($dom,$settings);
1.372 raeburn 943: } elsif ($action eq 'proctoring') {
944: $output .= &proctoring_javascript($settings);
1.381 raeburn 945: } elsif ($action eq 'wafproxy') {
946: $output .= &wafproxy_javascript($dom);
1.385 raeburn 947: } elsif ($action eq 'autoupdate') {
948: $output .= &autoupdate_javascript();
1.399 raeburn 949: } elsif ($action eq 'autoenroll') {
950: $output .= &autoenroll_javascript();
1.386 raeburn 951: } elsif ($action eq 'login') {
952: $output .= &saml_javascript();
1.394 raeburn 953: } elsif ($action eq 'ipaccess') {
954: $output .= &ipaccess_javascript($settings);
1.429 raeburn 955: } elsif ($action eq 'authordefaults') {
956: $output .= &authordefaults_javascript();
1.91 raeburn 957: }
1.236 raeburn 958: $output .=
1.30 raeburn 959: '<table class="LC_nested_outer">
1.3 raeburn 960: <tr>
1.306 raeburn 961: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 962: &mt($item->{text}).' '.
963: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
964: '</tr>';
1.30 raeburn 965: $rowtotal ++;
1.110 raeburn 966: my $numheaders = 1;
967: if (ref($item->{'header'}) eq 'ARRAY') {
968: $numheaders = scalar(@{$item->{'header'}});
969: }
970: if ($numheaders > 1) {
1.64 raeburn 971: my $colspan = '';
1.145 raeburn 972: my $rightcolspan = '';
1.369 raeburn 973: my $leftnobr = '';
1.238 raeburn 974: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 975: ($action eq 'directorysrch') ||
1.386 raeburn 976: (($action eq 'login') && ($numheaders < 5))) {
1.64 raeburn 977: $colspan = ' colspan="2"';
978: }
1.145 raeburn 979: if ($action eq 'usersessions') {
980: $rightcolspan = ' colspan="3"';
981: }
1.369 raeburn 982: if ($action eq 'passwords') {
983: $leftnobr = ' LC_nobreak';
984: }
1.30 raeburn 985: $output .= '
1.3 raeburn 986: <tr>
987: <td>
988: <table class="LC_nested">
989: <tr class="LC_info_row">
1.369 raeburn 990: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 991: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 992: </tr>';
1.69 raeburn 993: $rowtotal ++;
1.230 raeburn 994: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 995: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 996: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 997: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
1.421 raeburn 998: ($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'wafproxy') ||
1.429 raeburn 999: ($action eq 'lti') || ($action eq 'ltitools') || ($action eq 'authordefaults')) {
1.230 raeburn 1000: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.354 raeburn 1001: } elsif ($action eq 'passwords') {
1002: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 1003: } elsif ($action eq 'coursecategories') {
1.230 raeburn 1004: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.346 raeburn 1005: } elsif ($action eq 'scantron') {
1006: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 1007: } elsif ($action eq 'login') {
1.386 raeburn 1008: if ($numheaders == 5) {
1.168 raeburn 1009: $colspan = ' colspan="2"';
1010: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
1011: } else {
1012: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
1013: }
1.230 raeburn 1014: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 1015: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 1016: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1017: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 1018: }
1.30 raeburn 1019: $output .= '
1.6 raeburn 1020: </table>
1021: </td>
1022: </tr>
1023: <tr>
1024: <td>
1025: <table class="LC_nested">
1026: <tr class="LC_info_row">
1.230 raeburn 1027: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 1028: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 1029: </tr>';
1030: $rowtotal ++;
1.230 raeburn 1031: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
1032: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 1033: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.409 raeburn 1034: ($action eq 'trust') || ($action eq 'contacts') || ($action eq 'defaults') ||
1.421 raeburn 1035: ($action eq 'privacy') || ($action eq 'passwords') || ($action eq 'lti') ||
1.443 raeburn 1036: ($action eq 'ltitools') || ($action eq 'usermodification')) {
1.238 raeburn 1037: if ($action eq 'coursecategories') {
1038: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
1039: $colspan = ' colspan="2"';
1.279 raeburn 1040: } elsif ($action eq 'trust') {
1041: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.354 raeburn 1042: } elsif ($action eq 'passwords') {
1043: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.434 raeburn 1044: } elsif ($action eq 'lti') {
1045: $output .= $item->{'print'}->('upper',$dom,$settings,\$rowtotal).'
1046: </table>
1047: </td>
1048: </tr>
1049: <tr>
1050: <td>
1051: <table class="LC_nested">
1052: <tr class="LC_info_row">
1053: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1054: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1055: </tr>'."\n".
1056: $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
1.238 raeburn 1057: } else {
1058: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
1059: }
1.279 raeburn 1060: if ($action eq 'trust') {
1061: $output .= '
1062: </table>
1063: </td>
1064: </tr>';
1065: my @trusthdrs = qw(2 3 4 5 6 7);
1066: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
1067: for (my $i=0; $i<@trusthdrs; $i++) {
1068: $output .= '
1069: <tr>
1070: <td>
1071: <table class="LC_nested">
1072: <tr class="LC_info_row">
1073: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
1074: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
1075: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
1076: </table>
1077: </td>
1078: </tr>';
1079: }
1080: $output .= '
1081: <tr>
1082: <td>
1083: <table class="LC_nested">
1084: <tr class="LC_info_row">
1085: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
1086: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
1087: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1088: } else {
1.434 raeburn 1089: my $hdridx = 2;
1090: if ($action eq 'lti') {
1091: $hdridx = 3;
1092: }
1.279 raeburn 1093: $output .= '
1.63 raeburn 1094: </table>
1095: </td>
1096: </tr>
1097: <tr>
1098: <td>
1099: <table class="LC_nested">
1100: <tr class="LC_info_row">
1.434 raeburn 1101: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col1'}).'</td>
1102: <td class="LC_right_item">'.&mt($item->{'header'}->[$hdridx]->{'col2'}).'</td>
1.238 raeburn 1103: </tr>'."\n";
1.279 raeburn 1104: if ($action eq 'coursecategories') {
1105: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.405 raeburn 1106: } elsif (($action eq 'contacts') || ($action eq 'privacy') ||
1107: ($action eq 'passwords') || ($action eq 'lti')) {
1.354 raeburn 1108: if ($action eq 'passwords') {
1109: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
1110: } else {
1111: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
1112: }
1.434 raeburn 1113: $hdridx ++;
1.354 raeburn 1114: $output .= '
1.340 raeburn 1115: </tr>
1116: </table>
1117: </td>
1118: </tr>
1119: <tr>
1120: <td>
1121: <table class="LC_nested">
1122: <tr class="LC_info_row">
1.434 raeburn 1123: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col1'}).'</td>
1124: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col2'}).'</td></tr>'."\n";
1.354 raeburn 1125: if ($action eq 'passwords') {
1126: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
1127: } else {
1128: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1129: }
1130: $output .= '
1.340 raeburn 1131: </table>
1132: </td>
1133: </tr>
1134: <tr>';
1.279 raeburn 1135: } else {
1136: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1137: }
1.238 raeburn 1138: }
1.63 raeburn 1139: $rowtotal ++;
1.443 raeburn 1140: } elsif (($action eq 'coursedefaults') || ($action eq 'authordefaults') ||
1.409 raeburn 1141: ($action eq 'directorysrch') || ($action eq 'helpsettings') ||
1.443 raeburn 1142: ($action eq 'wafproxy')) {
1.230 raeburn 1143: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.346 raeburn 1144: } elsif ($action eq 'scantron') {
1145: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.293 raeburn 1146: } elsif ($action eq 'ssl') {
1147: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
1148: </table>
1149: </td>
1150: </tr>
1151: <tr>
1152: <td>
1153: <table class="LC_nested">
1154: <tr class="LC_info_row">
1155: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1156: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1157: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
1158: </table>
1159: </td>
1160: </tr>
1161: <tr>
1162: <td>
1163: <table class="LC_nested">
1164: <tr class="LC_info_row">
1165: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1166: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
1167: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 1168: } elsif ($action eq 'login') {
1.386 raeburn 1169: if ($numheaders == 5) {
1.168 raeburn 1170: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
1171: </table>
1172: </td>
1173: </tr>
1174: <tr>
1175: <td>
1176: <table class="LC_nested">
1177: <tr class="LC_info_row">
1178: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 1179: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 1180: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1181: $rowtotal ++;
1182: } else {
1183: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1184: }
1.256 raeburn 1185: $output .= '
1186: </table>
1187: </td>
1188: </tr>
1189: <tr>
1190: <td>
1191: <table class="LC_nested">
1192: <tr class="LC_info_row">';
1.386 raeburn 1193: if ($numheaders == 5) {
1.256 raeburn 1194: $output .= '
1195: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1196: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1197: </tr>';
1198: } else {
1199: $output .= '
1200: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1201: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1202: </tr>';
1203: }
1204: $rowtotal ++;
1.386 raeburn 1205: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
1206: </table>
1207: </td>
1208: </tr>
1209: <tr>
1210: <td>
1211: <table class="LC_nested">
1212: <tr class="LC_info_row">';
1213: if ($numheaders == 5) {
1214: $output .= '
1215: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1216: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1217: </tr>';
1218: } else {
1219: $output .= '
1220: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1221: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1222: </tr>';
1223: }
1224: $rowtotal ++;
1225: $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 1226: } elsif ($action eq 'requestcourses') {
1.247 raeburn 1227: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1228: $rowtotal ++;
1229: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 1230: </table>
1231: </td>
1232: </tr>
1233: <tr>
1234: <td>
1235: <table class="LC_nested">
1236: <tr class="LC_info_row">
1237: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1238: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 1239: &textbookcourses_javascript($settings).
1240: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
1241: </table>
1242: </td>
1243: </tr>
1244: <tr>
1245: <td>
1246: <table class="LC_nested">
1247: <tr class="LC_info_row">
1248: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1249: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1250: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 1251: </table>
1252: </td>
1253: </tr>
1254: <tr>
1255: <td>
1256: <table class="LC_nested">
1257: <tr class="LC_info_row">
1.306 raeburn 1258: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1259: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 1260: </tr>'.
1261: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 1262: } elsif ($action eq 'requestauthor') {
1263: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 1264: $rowtotal ++;
1.122 jms 1265: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1266: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1267: </table>
1268: </td>
1269: </tr>
1270: <tr>
1271: <td>
1272: <table class="LC_nested">
1273: <tr class="LC_info_row">
1.306 raeburn 1274: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69 raeburn 1275: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306 raeburn 1276: <td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1277: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1278: </tr>'.
1.30 raeburn 1279: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1280: </table>
1281: </td>
1282: </tr>
1283: <tr>
1284: <td>
1285: <table class="LC_nested">
1286: <tr class="LC_info_row">
1.59 bisitz 1287: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1288: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1289: </tr>'.
1.30 raeburn 1290: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1291: $rowtotal += 2;
1.6 raeburn 1292: }
1.3 raeburn 1293: } else {
1.30 raeburn 1294: $output .= '
1.3 raeburn 1295: <tr>
1296: <td>
1297: <table class="LC_nested">
1.30 raeburn 1298: <tr class="LC_info_row">';
1.277 raeburn 1299: if ($action eq 'login') {
1.30 raeburn 1300: $output .= '
1.59 bisitz 1301: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1302: } elsif ($action eq 'serverstatuses') {
1303: $output .= '
1.306 raeburn 1304: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69 raeburn 1305: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1306:
1.6 raeburn 1307: } else {
1.30 raeburn 1308: $output .= '
1.306 raeburn 1309: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1310: }
1.72 raeburn 1311: if (defined($item->{'header'}->[0]->{'col3'})) {
1.306 raeburn 1312: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72 raeburn 1313: &mt($item->{'header'}->[0]->{'col2'});
1314: if ($action eq 'serverstatuses') {
1315: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1316: }
1.69 raeburn 1317: } else {
1.306 raeburn 1318: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1319: &mt($item->{'header'}->[0]->{'col2'});
1320: }
1321: $output .= '</td>';
1322: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1323: if (defined($item->{'header'}->[0]->{'col4'})) {
1.306 raeburn 1324: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150 raeburn 1325: &mt($item->{'header'}->[0]->{'col3'});
1326: } else {
1.306 raeburn 1327: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1328: &mt($item->{'header'}->[0]->{'col3'});
1329: }
1.69 raeburn 1330: if ($action eq 'serverstatuses') {
1331: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1332: }
1333: $output .= '</td>';
1.6 raeburn 1334: }
1.150 raeburn 1335: if ($item->{'header'}->[0]->{'col4'}) {
1.306 raeburn 1336: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1337: &mt($item->{'header'}->[0]->{'col4'});
1338: }
1.69 raeburn 1339: $output .= '</tr>';
1.48 raeburn 1340: $rowtotal ++;
1.168 raeburn 1341: if ($action eq 'quotas') {
1.86 raeburn 1342: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1343: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1344: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.421 raeburn 1345: ($action eq 'proctoring') || ($action eq 'ipaccess')) {
1.230 raeburn 1346: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1347: }
1.3 raeburn 1348: }
1.30 raeburn 1349: $output .= '
1.3 raeburn 1350: </table>
1351: </td>
1352: </tr>
1.30 raeburn 1353: </table><br />';
1354: return ($output,$rowtotal);
1.1 raeburn 1355: }
1356:
1.3 raeburn 1357: sub print_login {
1.168 raeburn 1358: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.386 raeburn 1359: my ($css_class,$datatable,$switchserver,%lt);
1.6 raeburn 1360: my %choices = &login_choices();
1.386 raeburn 1361: if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
1362: %lt = &login_file_options();
1363: $switchserver = &check_switchserver($dom,$confname);
1364: }
1.168 raeburn 1365: if ($caller eq 'service') {
1.149 raeburn 1366: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1367: my $choice = $choices{'disallowlogin'};
1368: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1369: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306 raeburn 1370: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1371: '<th>'.$choices{'server'}.'</th>'.
1372: '<th>'.$choices{'serverpath'}.'</th>'.
1373: '<th>'.$choices{'custompath'}.'</th>'.
1374: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1375: my %disallowed;
1376: if (ref($settings) eq 'HASH') {
1377: if (ref($settings->{'loginvia'}) eq 'HASH') {
1378: %disallowed = %{$settings->{'loginvia'}};
1379: }
1380: }
1381: foreach my $lonhost (sort(keys(%servers))) {
1382: my $direct = 'selected="selected"';
1.128 raeburn 1383: if (ref($disallowed{$lonhost}) eq 'HASH') {
1384: if ($disallowed{$lonhost}{'server'} ne '') {
1385: $direct = '';
1386: }
1.110 raeburn 1387: }
1.115 raeburn 1388: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1389: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1390: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1391: '</option>';
1.184 raeburn 1392: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1393: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1394: my $selected = '';
1.128 raeburn 1395: if (ref($disallowed{$lonhost}) eq 'HASH') {
1396: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1397: $selected = 'selected="selected"';
1398: }
1.110 raeburn 1399: }
1400: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1401: $servers{$hostid}.'</option>';
1402: }
1.128 raeburn 1403: $datatable .= '</select></td>'.
1404: '<td><select name="'.$lonhost.'_serverpath">';
1405: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1406: my $pathname = $path;
1407: if ($path eq 'custom') {
1408: $pathname = &mt('Custom Path').' ->';
1409: }
1410: my $selected = '';
1411: if (ref($disallowed{$lonhost}) eq 'HASH') {
1412: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1413: $selected = 'selected="selected"';
1414: }
1415: } elsif ($path eq '') {
1416: $selected = 'selected="selected"';
1417: }
1418: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1419: }
1420: $datatable .= '</select></td>';
1421: my ($custom,$exempt);
1422: if (ref($disallowed{$lonhost}) eq 'HASH') {
1423: $custom = $disallowed{$lonhost}{'custompath'};
1424: $exempt = $disallowed{$lonhost}{'exempt'};
1425: }
1426: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1427: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1428: '</tr>';
1.110 raeburn 1429: }
1430: $datatable .= '</table></td></tr>';
1431: return $datatable;
1.168 raeburn 1432: } elsif ($caller eq 'page') {
1433: my %defaultchecked = (
1434: 'coursecatalog' => 'on',
1.188 raeburn 1435: 'helpdesk' => 'on',
1.168 raeburn 1436: 'adminmail' => 'off',
1437: 'newuser' => 'off',
1438: );
1.188 raeburn 1439: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1440: my (%checkedon,%checkedoff);
1.42 raeburn 1441: foreach my $item (@toggles) {
1.168 raeburn 1442: if ($defaultchecked{$item} eq 'on') {
1443: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1444: $checkedoff{$item} = ' ';
1.168 raeburn 1445: } elsif ($defaultchecked{$item} eq 'off') {
1446: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1447: $checkedon{$item} = ' ';
1448: }
1.1 raeburn 1449: }
1.168 raeburn 1450: my @images = ('img','logo','domlogo','login');
1.402 raeburn 1451: my @alttext = ('img','logo','domlogo');
1.168 raeburn 1452: my @logintext = ('textcol','bgcol');
1453: my @bgs = ('pgbg','mainbg','sidebg');
1454: my @links = ('link','alink','vlink');
1455: my %designhash = &Apache::loncommon::get_domainconf($dom);
1456: my %defaultdesign = %Apache::loncommon::defaultdesign;
1457: my (%is_custom,%designs);
1458: my %defaults = (
1459: font => $defaultdesign{'login.font'},
1460: );
1.6 raeburn 1461: foreach my $item (@images) {
1.168 raeburn 1462: $defaults{$item} = $defaultdesign{'login.'.$item};
1463: $defaults{'showlogo'}{$item} = 1;
1464: }
1465: foreach my $item (@bgs) {
1466: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1467: }
1.41 raeburn 1468: foreach my $item (@logintext) {
1.168 raeburn 1469: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1470: }
1.168 raeburn 1471: foreach my $item (@links) {
1472: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1473: }
1.168 raeburn 1474: if (ref($settings) eq 'HASH') {
1475: foreach my $item (@toggles) {
1476: if ($settings->{$item} eq '1') {
1477: $checkedon{$item} = ' checked="checked" ';
1478: $checkedoff{$item} = ' ';
1479: } elsif ($settings->{$item} eq '0') {
1480: $checkedoff{$item} = ' checked="checked" ';
1481: $checkedon{$item} = ' ';
1482: }
1483: }
1484: foreach my $item (@images) {
1485: if (defined($settings->{$item})) {
1486: $designs{$item} = $settings->{$item};
1487: $is_custom{$item} = 1;
1488: }
1489: if (defined($settings->{'showlogo'}{$item})) {
1490: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1491: }
1492: }
1.402 raeburn 1493: foreach my $item (@alttext) {
1494: if (ref($settings->{'alttext'}) eq 'HASH') {
1495: if ($settings->{'alttext'}->{$item} ne '') {
1496: $designs{'alttext'}{$item} = $settings->{'alttext'}{$item};
1497: }
1498: }
1499: }
1.168 raeburn 1500: foreach my $item (@logintext) {
1501: if ($settings->{$item} ne '') {
1502: $designs{'logintext'}{$item} = $settings->{$item};
1503: $is_custom{$item} = 1;
1504: }
1505: }
1506: if ($settings->{'font'} ne '') {
1507: $designs{'font'} = $settings->{'font'};
1508: $is_custom{'font'} = 1;
1509: }
1510: foreach my $item (@bgs) {
1511: if ($settings->{$item} ne '') {
1512: $designs{'bgs'}{$item} = $settings->{$item};
1513: $is_custom{$item} = 1;
1514: }
1515: }
1516: foreach my $item (@links) {
1517: if ($settings->{$item} ne '') {
1518: $designs{'links'}{$item} = $settings->{$item};
1519: $is_custom{$item} = 1;
1520: }
1521: }
1522: } else {
1523: if ($designhash{$dom.'.login.font'} ne '') {
1524: $designs{'font'} = $designhash{$dom.'.login.font'};
1525: $is_custom{'font'} = 1;
1526: }
1527: foreach my $item (@images) {
1528: if ($designhash{$dom.'.login.'.$item} ne '') {
1529: $designs{$item} = $designhash{$dom.'.login.'.$item};
1530: $is_custom{$item} = 1;
1531: }
1532: }
1533: foreach my $item (@bgs) {
1534: if ($designhash{$dom.'.login.'.$item} ne '') {
1535: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1536: $is_custom{$item} = 1;
1537: }
1.6 raeburn 1538: }
1.168 raeburn 1539: foreach my $item (@links) {
1540: if ($designhash{$dom.'.login.'.$item} ne '') {
1541: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1542: $is_custom{$item} = 1;
1543: }
1.6 raeburn 1544: }
1545: }
1.168 raeburn 1546: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1547: logo => 'Institution Logo',
1548: domlogo => 'Domain Logo',
1549: login => 'Login box');
1550: my $itemcount = 1;
1551: foreach my $item (@toggles) {
1552: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1553: $datatable .=
1554: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1555: '</td><td>'.
1556: '<span class="LC_nobreak"><label><input type="radio" name="'.
1557: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1558: '</label> <label><input type="radio" name="'.$item.'"'.
1559: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1560: '</tr>';
1561: $itemcount ++;
1.6 raeburn 1562: }
1.168 raeburn 1563: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1564: $datatable .= '</tr></table></td></tr>';
1565: } elsif ($caller eq 'help') {
1.386 raeburn 1566: my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1.168 raeburn 1567: my $itemcount = 1;
1568: $defaulturl = '/adm/loginproblems.html';
1569: $defaulttype = 'default';
1570: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1571: my @currlangs;
1572: if (ref($settings) eq 'HASH') {
1573: if (ref($settings->{'helpurl'}) eq 'HASH') {
1574: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1575: next if ($settings->{'helpurl'}{$key} eq '');
1576: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1577: $type{$key} = 'custom';
1578: unless ($key eq 'nolang') {
1579: push(@currlangs,$key);
1580: }
1581: }
1582: } elsif ($settings->{'helpurl'} ne '') {
1583: $type{'nolang'} = 'custom';
1584: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1585: }
1586: }
1.168 raeburn 1587: foreach my $lang ('nolang',sort(@currlangs)) {
1588: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1589: $datatable .= '<tr'.$css_class.'>';
1590: if ($url{$lang} eq '') {
1591: $url{$lang} = $defaulturl;
1592: }
1593: if ($type{$lang} eq '') {
1594: $type{$lang} = $defaulttype;
1595: }
1596: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1597: if ($lang eq 'nolang') {
1598: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1599: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1600: } else {
1601: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1602: $langchoices{$lang},
1603: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1604: }
1605: $datatable .= '</span></td>'."\n".
1606: '<td class="LC_left_item">';
1607: if ($type{$lang} eq 'custom') {
1608: $datatable .= '<span class="LC_nobreak"><label>'.
1609: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1610: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1611: } else {
1612: $datatable .= $lt{'upl'};
1613: }
1614: $datatable .='<br />';
1615: if ($switchserver) {
1616: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1617: } else {
1618: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1619: }
1.168 raeburn 1620: $datatable .= '</td></tr>';
1621: $itemcount ++;
1.6 raeburn 1622: }
1.168 raeburn 1623: my @addlangs;
1624: foreach my $lang (sort(keys(%langchoices))) {
1625: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1626: push(@addlangs,$lang);
1627: }
1628: if (@addlangs > 0) {
1629: my %toadd;
1630: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1631: $toadd{''} = &mt('Select');
1632: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1633: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1634: &mt('Add log-in help page for a specific language:').' '.
1635: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1636: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1637: if ($switchserver) {
1638: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1639: } else {
1640: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1641: }
1.168 raeburn 1642: $datatable .= '</td></tr>';
1.169 raeburn 1643: $itemcount ++;
1.6 raeburn 1644: }
1.169 raeburn 1645: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1646: } elsif ($caller eq 'headtag') {
1647: my %domservers = &Apache::lonnet::get_servers($dom);
1648: my $choice = $choices{'headtag'};
1649: $css_class = ' class="LC_odd_row"';
1650: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306 raeburn 1651: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256 raeburn 1652: '<th>'.$choices{'current'}.'</th>'.
1653: '<th>'.$choices{'action'}.'</th>'.
1654: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1655: my (%currurls,%currexempt);
1656: if (ref($settings) eq 'HASH') {
1657: if (ref($settings->{'headtag'}) eq 'HASH') {
1658: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1659: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1660: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1661: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1662: }
1663: }
1664: }
1665: }
1666: foreach my $lonhost (sort(keys(%domservers))) {
1667: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1668: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1669: if ($currurls{$lonhost}) {
1670: $datatable .= '<td class="LC_right_item"><a href="'.
1671: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1672: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1673: '">'.$lt{'curr'}.'</a></td>'.
1674: '<td><span class="LC_nobreak"><label>'.
1675: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1676: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1677: } else {
1678: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1679: }
1680: $datatable .='<br />';
1681: if ($switchserver) {
1682: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1683: } else {
1684: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1685: }
1.330 raeburn 1686: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256 raeburn 1687: }
1688: $datatable .= '</table></td></tr>';
1.386 raeburn 1689: } elsif ($caller eq 'saml') {
1690: my %domservers = &Apache::lonnet::get_servers($dom);
1691: $datatable .= '<tr><td colspan="3" style="text-align: left">'.
1692: '<table><tr><th>'.$choices{'hostid'}.'</th>'.
1693: '<th>'.$choices{'samllanding'}.'</th>'.
1694: '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
1.412 raeburn 1695: my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso,%styleon,%styleoff);
1.386 raeburn 1696: foreach my $lonhost (keys(%domservers)) {
1697: $samlurl{$lonhost} = '/adm/sso';
1698: $styleon{$lonhost} = 'display:none';
1699: $styleoff{$lonhost} = '';
1700: }
1.411 raeburn 1701: if ((ref($settings) eq 'HASH') && (ref($settings->{'saml'}) eq 'HASH')) {
1.386 raeburn 1702: foreach my $lonhost (keys(%{$settings->{'saml'}})) {
1703: if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
1704: $saml{$lonhost} = 1;
1705: $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
1706: $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
1707: $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
1708: $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
1709: $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
1.412 raeburn 1710: $samlwindow{$lonhost} = $settings->{'saml'}{$lonhost}{'window'};
1.386 raeburn 1711: $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
1712: $styleon{$lonhost} = '';
1713: $styleoff{$lonhost} = 'display:none';
1714: } else {
1715: $styleon{$lonhost} = 'display:none';
1716: $styleoff{$lonhost} = '';
1717: }
1718: }
1719: }
1720: my $itemcount = 1;
1721: foreach my $lonhost (sort(keys(%domservers))) {
1722: my $samlon = ' ';
1723: my $samloff = ' checked="checked" ';
1724: if ($saml{$lonhost}) {
1725: $samlon = $samloff;
1726: $samloff = ' ';
1727: }
1.412 raeburn 1728: my $samlwinon = '';
1729: my $samlwinoff = ' checked="checked"';
1730: if ($samlwindow{$lonhost}) {
1731: $samlwinon = $samlwinoff;
1732: $samlwinoff = '';
1733: }
1.386 raeburn 1734: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1735: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
1736: '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
1737: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
1738: &mt('No').'</label>'.(' 'x2).
1739: '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
1740: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
1741: &mt('Yes').'</label></span></td>'.
1742: '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
1.412 raeburn 1743: '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th></tr>'.
1.386 raeburn 1744: '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
1.412 raeburn 1745: '<th>'.&mt('Alt Text').'</th></tr>'.
1746: '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="20" value="'.
1.386 raeburn 1747: $samltext{$lonhost}.'" /></td><td>';
1748: if ($samlimg{$lonhost}) {
1749: $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
1750: '<span class="LC_nobreak"><label>'.
1751: '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
1752: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1753: } else {
1754: $datatable .= $lt{'upl'};
1755: }
1756: $datatable .='<br />';
1757: if ($switchserver) {
1758: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1759: } else {
1760: $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
1761: }
1762: $datatable .= '</td>'.
1.412 raeburn 1763: '<td><input type="text" name="saml_alt_'.$lonhost.'" size="25" '.
1764: 'value="'.$samlalt{$lonhost}.'" /></td></tr></table><br />'.
1765: '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th><th align="center">'.
1766: '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
1767: '<tr><th>'.&mt('URL').'</th><th>'.&mt('Tool Tip').'</th>'.
1768: '<th>'.&mt('Pop-up if iframe').'</th><th>'.&mt('Text').'</th></tr>'.
1769: '<tr'.$css_class.'>'.
1770: '<td><input type="text" name="saml_url_'.$lonhost.'" size="30" '.
1.386 raeburn 1771: 'value="'.$samlurl{$lonhost}.'" /></td>'.
1.412 raeburn 1772: '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="20">'.
1.386 raeburn 1773: $samltitle{$lonhost}.'</textarea></td>'.
1.412 raeburn 1774: '<td><label><input type="radio" name="saml_window_'.$lonhost.'" value=""'.$samlwinoff.'>'.
1775: &mt('No').'</label>'.(' 'x2).'<label><input type="radio" '.
1776: 'name="saml_window_'.$lonhost.'" value="1"'.$samlwinon.'>'.&mt('Yes').'</label></td>'.
1777: '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="12" '.
1.386 raeburn 1778: 'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
1779: '</table></td>'.
1780: '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%"> </td></tr>';
1781: $itemcount ++;
1782: }
1783: $datatable .= '</table></td></tr>';
1.1 raeburn 1784: }
1.6 raeburn 1785: return $datatable;
1786: }
1787:
1788: sub login_choices {
1789: my %choices =
1790: &Apache::lonlocal::texthash (
1.116 bisitz 1791: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1792: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1793: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1794: disallowlogin => "Login page requests redirected",
1795: hostid => "Server",
1.128 raeburn 1796: server => "Redirect to:",
1797: serverpath => "Path",
1798: custompath => "Custom",
1799: exempt => "Exempt IP(s)",
1.110 raeburn 1800: directlogin => "No redirect",
1801: newuser => "Link to create a user account",
1802: img => "Header",
1803: logo => "Main Logo",
1804: domlogo => "Domain Logo",
1805: login => "Log-in Header",
1806: textcol => "Text color",
1807: bgcol => "Box color",
1808: bgs => "Background colors",
1809: links => "Link colors",
1810: font => "Font color",
1811: pgbg => "Header",
1812: mainbg => "Page",
1813: sidebg => "Login box",
1814: link => "Link",
1815: alink => "Active link",
1816: vlink => "Visited link",
1.256 raeburn 1817: headtag => "Custom markup",
1818: action => "Action",
1819: current => "Current",
1.386 raeburn 1820: samllanding => "Dual login?",
1821: samloptions => "Options",
1.402 raeburn 1822: alttext => "Alt text",
1.6 raeburn 1823: );
1824: return %choices;
1825: }
1826:
1.386 raeburn 1827: sub login_file_options {
1828: return &Apache::lonlocal::texthash(
1829: del => 'Delete?',
1830: rep => 'Replace:',
1831: upl => 'Upload:',
1832: curr => 'View contents',
1833: default => 'Default',
1834: custom => 'Custom',
1835: none => 'None',
1836: );
1837: }
1838:
1.394 raeburn 1839: sub print_ipaccess {
1840: my ($dom,$settings,$rowtotal) = @_;
1841: my $css_class;
1842: my $itemcount = 0;
1843: my $datatable;
1844: my %ordered;
1845: if (ref($settings) eq 'HASH') {
1846: foreach my $item (keys(%{$settings})) {
1847: if (ref($settings->{$item}) eq 'HASH') {
1848: my $num = $settings->{$item}{'order'};
1849: if ($num eq '') {
1850: $num = scalar(keys(%{$settings}));
1851: }
1852: $ordered{$num} = $item;
1853: }
1854: }
1855: }
1856: my $maxnum = scalar(keys(%ordered));
1857: if (keys(%ordered)) {
1858: my @items = sort { $a <=> $b } keys(%ordered);
1859: for (my $i=0; $i<@items; $i++) {
1860: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1861: my $item = $ordered{$items[$i]};
1862: my ($name,$ipranges,%commblocks,%courses);
1863: if (ref($settings->{$item}) eq 'HASH') {
1864: $name = $settings->{$item}->{'name'};
1865: $ipranges = $settings->{$item}->{'ip'};
1866: if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
1867: %commblocks = %{$settings->{$item}->{'commblocks'}};
1868: }
1869: if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
1870: %courses = %{$settings->{$item}->{'courses'}};
1871: }
1872: }
1873: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
1874: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1875: .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
1876: for (my $k=0; $k<=$maxnum; $k++) {
1877: my $vpos = $k+1;
1878: my $selstr;
1879: if ($k == $i) {
1880: $selstr = ' selected="selected" ';
1881: }
1882: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1883: }
1884: $datatable .= '</select>'.(' 'x2).
1885: '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
1886: &mt('Delete?').'</label></span></td>'.
1887: '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
1888: &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
1889: '</td></tr>';
1890: $itemcount ++;
1891: }
1892: }
1893: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1894: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
1895: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1896: '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
1897: '<select name="ipaccess_pos_add"'.$chgstr.'>';
1898: for (my $k=0; $k<$maxnum+1; $k++) {
1899: my $vpos = $k+1;
1900: my $selstr;
1901: if ($k == $maxnum) {
1902: $selstr = ' selected="selected" ';
1903: }
1904: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1905: }
1906: $datatable .= '</select> '."\n".
1907: '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1908: '<td colspan="2">'.
1909: &ipaccess_options('add',$itemcount,$dom).
1910: '</td>'."\n".
1911: '</tr>'."\n";
1912: $$rowtotal ++;
1913: return $datatable;
1914: }
1915:
1916: sub ipaccess_options {
1917: my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
1918: my (%currblocks,%currcourses,$output);
1919: if (ref($blocksref) eq 'HASH') {
1920: %currblocks = %{$blocksref};
1921: }
1922: if (ref($coursesref) eq 'HASH') {
1923: %currcourses = %{$coursesref};
1924: }
1925: $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
1926: '<span class="LC_nobreak">'.&mt('Name').': '.
1927: '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
1928: '</span></fieldset>'.
1929: '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
1930: &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
1931: &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
1932: '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
1933: $ipranges.'</textarea></fieldset>'.
1934: '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
1935: &blocker_checkboxes($num,$blocksref).'</fieldset>'.
1936: '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
1937: '<table>';
1938: foreach my $cid (sort(keys(%currcourses))) {
1939: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1940: $output .= '<tr><td><span class="LC_nobreak">'.
1941: '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
1942: &mt('Delete?').' <span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
1943: ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
1944: }
1945: $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').': '.
1946: '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
1947: &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
1948: '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
1949: '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
1950: '</span></td></tr></table>'."\n".
1951: '</fieldset>';
1952: return $output;
1953: }
1954:
1955: sub blocker_checkboxes {
1956: my ($num,$blocks) = @_;
1957: my ($typeorder,$types) = &commblocktype_text();
1958: my $numinrow = 6;
1959: my $output = '<table>';
1960: for (my $i=0; $i<@{$typeorder}; $i++) {
1961: my $block = $typeorder->[$i];
1962: my $blockstatus;
1963: if (ref($blocks) eq 'HASH') {
1964: if ($blocks->{$block} eq 'on') {
1965: $blockstatus = 'checked="checked"';
1966: }
1967: }
1968: my $rem = $i%($numinrow);
1969: if ($rem == 0) {
1970: if ($i > 0) {
1971: $output .= '</tr>';
1972: }
1973: $output .= '<tr>';
1974: }
1975: if ($i == scalar(@{$typeorder})-1) {
1976: my $colsleft = $numinrow-$rem;
1977: if ($colsleft > 1) {
1978: $output .= '<td colspan="'.$colsleft.'">';
1979: } else {
1980: $output .= '<td>';
1981: }
1982: } else {
1983: $output .= '<td>';
1984: }
1985: my $item = 'ipaccess_block_'.$num;
1986: if ($blockstatus) {
1987: $blockstatus = ' '.$blockstatus;
1988: }
1989: $output .= '<span class="LC_nobreak"><label>'."\n".
1990: '<input type="checkbox" name="'.$item.'"'.
1991: $blockstatus.' value="'.$block.'"'.' />'.
1992: $types->{$block}.'</label></span>'."\n".
1993: '<br /></td>';
1994: }
1995: $output .= '</tr></table>';
1996: return $output;
1997: }
1998:
1999: sub commblocktype_text {
2000: my %types = &Apache::lonlocal::texthash(
2001: 'com' => 'Messaging',
2002: 'chat' => 'Chat Room',
2003: 'boards' => 'Discussion',
2004: 'port' => 'Portfolio',
2005: 'groups' => 'Groups',
2006: 'blogs' => 'Blogs',
2007: 'about' => 'User Information',
2008: 'printout' => 'Printouts',
2009: 'passwd' => 'Change Password',
2010: 'grades' => 'Gradebook',
1.397 raeburn 2011: 'search' => 'Course search',
2012: 'wishlist' => 'Stored links',
2013: 'annotate' => 'Annotations',
1.394 raeburn 2014: );
1.397 raeburn 2015: my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','annotate','passwd'];
1.394 raeburn 2016: return ($typeorder,\%types);
2017: }
2018:
1.6 raeburn 2019: sub print_rolecolors {
1.30 raeburn 2020: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 2021: my %choices = &color_font_choices();
2022: my @bgs = ('pgbg','tabbg','sidebg');
2023: my @links = ('link','alink','vlink');
1.445 ! raeburn 2024: my @images = ();
1.6 raeburn 2025: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 2026: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 2027: my %defaultdesign = %Apache::loncommon::defaultdesign;
2028: my (%is_custom,%designs);
1.200 raeburn 2029: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 2030: if (ref($settings) eq 'HASH') {
2031: if (ref($settings->{$role}) eq 'HASH') {
2032: if ($settings->{$role}->{'font'} ne '') {
2033: $designs{'font'} = $settings->{$role}->{'font'};
2034: $is_custom{'font'} = 1;
2035: }
1.97 tempelho 2036: if ($settings->{$role}->{'fontmenu'} ne '') {
2037: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
2038: $is_custom{'fontmenu'} = 1;
2039: }
1.6 raeburn 2040: foreach my $item (@bgs) {
2041: if ($settings->{$role}->{$item} ne '') {
2042: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
2043: $is_custom{$item} = 1;
2044: }
2045: }
2046: foreach my $item (@links) {
2047: if ($settings->{$role}->{$item} ne '') {
2048: $designs{'links'}{$item} = $settings->{$role}->{$item};
2049: $is_custom{$item} = 1;
2050: }
2051: }
2052: }
2053: } else {
1.97 tempelho 2054: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
2055: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
2056: $is_custom{'fontmenu'} = 1;
2057: }
1.6 raeburn 2058: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
2059: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
2060: $is_custom{'font'} = 1;
2061: }
2062: foreach my $item (@bgs) {
2063: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
2064: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
2065: $is_custom{$item} = 1;
2066:
2067: }
2068: }
2069: foreach my $item (@links) {
2070: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
2071: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
2072: $is_custom{$item} = 1;
2073: }
2074: }
2075: }
2076: my $itemcount = 1;
1.30 raeburn 2077: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 2078: $datatable .= '</tr></table></td></tr>';
2079: return $datatable;
2080: }
2081:
1.200 raeburn 2082: sub role_defaults {
2083: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 2084: my %defaults;
2085: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 2086: return %defaults;
2087: }
2088: my %defaultdesign = %Apache::loncommon::defaultdesign;
2089: if ($role eq 'login') {
2090: %defaults = (
2091: font => $defaultdesign{$role.'.font'},
2092: );
2093: if (ref($logintext) eq 'ARRAY') {
2094: foreach my $item (@{$logintext}) {
2095: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
2096: }
2097: }
2098: foreach my $item (@{$images}) {
2099: $defaults{'showlogo'}{$item} = 1;
2100: }
2101: } else {
2102: %defaults = (
2103: font => $defaultdesign{$role.'.font'},
2104: fontmenu => $defaultdesign{$role.'.fontmenu'},
2105: );
2106: }
2107: foreach my $item (@{$bgs}) {
2108: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
2109: }
2110: foreach my $item (@{$links}) {
2111: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
2112: }
2113: foreach my $item (@{$images}) {
2114: $defaults{$item} = $defaultdesign{$role.'.'.$item};
2115: }
2116: return %defaults;
2117: }
2118:
1.6 raeburn 2119: sub display_color_options {
1.9 raeburn 2120: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 2121: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 2122: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 2123: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 2124: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 2125: '<td>'.$choices->{'font'}.'</td>';
2126: if (!$is_custom->{'font'}) {
1.329 raeburn 2127: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 2128: } else {
2129: $datatable .= '<td> </td>';
2130: }
1.174 foxr 2131: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
2132:
1.8 raeburn 2133: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2134: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 2135: ' value="'.$current_color.'" /> '.
1.329 raeburn 2136: ' </span></td></tr>';
1.107 raeburn 2137: unless ($role eq 'login') {
2138: $datatable .= '<tr'.$css_class.'>'.
2139: '<td>'.$choices->{'fontmenu'}.'</td>';
2140: if (!$is_custom->{'fontmenu'}) {
1.329 raeburn 2141: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 2142: } else {
2143: $datatable .= '<td> </td>';
2144: }
1.202 raeburn 2145: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 2146: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 2147: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2148: '<input class="colorchooser" type="text" size="10" name="'
2149: .$role.'_fontmenu"'.
2150: ' value="'.$current_color.'" /> '.
1.329 raeburn 2151: ' </span></td></tr>';
1.97 tempelho 2152: }
1.9 raeburn 2153: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 2154: foreach my $img (@{$images}) {
1.18 albertel 2155: $itemcount ++;
1.6 raeburn 2156: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 2157: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 2158: '<td>'.$choices->{$img};
1.402 raeburn 2159: my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext);
1.70 raeburn 2160: if ($role eq 'login') {
2161: if ($img eq 'login') {
2162: $login_hdr_pick =
1.135 bisitz 2163: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 2164: $logincolors =
2165: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 2166: $designs,$defaults);
1.402 raeburn 2167: } else {
2168: if ($img ne 'domlogo') {
2169: $datatable.= &logo_display_options($img,$defaults,$designs);
2170: }
2171: if (ref($designs->{'alttext'}) eq 'HASH') {
2172: $alttext = $designs->{'alttext'}{$img};
2173: }
1.70 raeburn 2174: }
2175: }
2176: $datatable .= '</td>';
1.6 raeburn 2177: if ($designs->{$img} ne '') {
2178: $imgfile = $designs->{$img};
1.18 albertel 2179: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 2180: } else {
2181: $imgfile = $defaults->{$img};
2182: }
2183: if ($imgfile) {
1.9 raeburn 2184: my ($showfile,$fullsize);
2185: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 2186: my $urldir = $1;
2187: my $filename = $2;
2188: my @info = &Apache::lonnet::stat_file($designs->{$img});
2189: if (@info) {
2190: my $thumbfile = 'tn-'.$filename;
2191: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
2192: if (@thumb) {
2193: $showfile = $urldir.'/'.$thumbfile;
2194: } else {
2195: $showfile = $imgfile;
2196: }
2197: } else {
2198: $showfile = '';
2199: }
2200: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 2201: $showfile = $imgfile;
1.6 raeburn 2202: my $imgdir = $1;
2203: my $filename = $2;
1.159 raeburn 2204: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 2205: $showfile = "/$imgdir/tn-".$filename;
2206: } else {
1.159 raeburn 2207: my $input = $londocroot.$imgfile;
2208: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 2209: if (!-e $output) {
1.9 raeburn 2210: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 2211: my ($fullwidth,$fullheight) = &check_dimensions($input);
2212: if ($fullwidth ne '' && $fullheight ne '') {
2213: if ($fullwidth > $width && $fullheight > $height) {
2214: my $size = $width.'x'.$height;
1.316 raeburn 2215: my @args = ('convert','-sample',$size,$input,$output);
2216: system({$args[0]} @args);
1.159 raeburn 2217: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 2218: }
2219: }
1.6 raeburn 2220: }
2221: }
1.16 raeburn 2222: }
1.6 raeburn 2223: if ($showfile) {
1.40 raeburn 2224: if ($showfile =~ m{^/(adm|res)/}) {
2225: if ($showfile =~ m{^/res/}) {
2226: my $local_showfile =
2227: &Apache::lonnet::filelocation('',$showfile);
2228: &Apache::lonnet::repcopy($local_showfile);
2229: }
2230: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
2231: }
2232: if ($imgfile) {
2233: if ($imgfile =~ m{^/(adm|res)/}) {
2234: if ($imgfile =~ m{^/res/}) {
2235: my $local_imgfile =
2236: &Apache::lonnet::filelocation('',$imgfile);
2237: &Apache::lonnet::repcopy($local_imgfile);
2238: }
2239: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
2240: } else {
2241: $fullsize = $imgfile;
2242: }
2243: }
1.41 raeburn 2244: $datatable .= '<td>';
2245: if ($img eq 'login') {
1.135 bisitz 2246: $datatable .= $login_hdr_pick;
2247: }
1.41 raeburn 2248: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
2249: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 2250: } else {
1.201 raeburn 2251: $datatable .= '<td> </td><td class="LC_left_item">'.
2252: &mt('Upload:').'<br />';
1.6 raeburn 2253: }
2254: } else {
1.201 raeburn 2255: $datatable .= '<td> </td><td class="LC_left_item">'.
2256: &mt('Upload:').'<br />';
1.6 raeburn 2257: }
1.9 raeburn 2258: if ($switchserver) {
2259: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2260: } else {
1.135 bisitz 2261: if ($img ne 'login') { # suppress file selection for Log-in header
2262: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
2263: }
1.9 raeburn 2264: }
1.402 raeburn 2265: if (($role eq 'login') && ($img ne 'login')) {
2266: $datatable .= (' ' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'.
2267: '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'.
2268: '</label></span>';
2269: }
1.9 raeburn 2270: $datatable .= '</td></tr>';
1.6 raeburn 2271: }
2272: $itemcount ++;
2273: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2274: $datatable .= '<tr'.$css_class.'>'.
2275: '<td>'.$choices->{'bgs'}.'</td>';
2276: my $bgs_def;
2277: foreach my $item (@{$bgs}) {
2278: if (!$is_custom->{$item}) {
1.329 raeburn 2279: $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 2280: }
2281: }
2282: if ($bgs_def) {
1.8 raeburn 2283: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 2284: } else {
2285: $datatable .= '<td> </td>';
2286: }
2287: $datatable .= '<td class="LC_right_item">'.
2288: '<table border="0"><tr>';
1.174 foxr 2289:
1.6 raeburn 2290: foreach my $item (@{$bgs}) {
1.306 raeburn 2291: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 2292: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 2293: if ($designs->{'bgs'}{$item}) {
1.174 foxr 2294: $datatable .= ' ';
1.6 raeburn 2295: }
1.174 foxr 2296: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 2297: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 2298: }
2299: $datatable .= '</tr></table></td></tr>';
2300: $itemcount ++;
2301: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2302: $datatable .= '<tr'.$css_class.'>'.
2303: '<td>'.$choices->{'links'}.'</td>';
2304: my $links_def;
2305: foreach my $item (@{$links}) {
2306: if (!$is_custom->{$item}) {
1.329 raeburn 2307: $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 2308: }
2309: }
2310: if ($links_def) {
1.8 raeburn 2311: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 2312: } else {
2313: $datatable .= '<td> </td>';
2314: }
2315: $datatable .= '<td class="LC_right_item">'.
2316: '<table border="0"><tr>';
2317: foreach my $item (@{$links}) {
1.234 raeburn 2318: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 2319: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 2320: if ($designs->{'links'}{$item}) {
1.174 foxr 2321: $datatable.=' ';
1.6 raeburn 2322: }
1.174 foxr 2323: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 2324: '" /></td>';
2325: }
1.30 raeburn 2326: $$rowtotal += $itemcount;
1.3 raeburn 2327: return $datatable;
2328: }
2329:
1.70 raeburn 2330: sub logo_display_options {
2331: my ($img,$defaults,$designs) = @_;
2332: my $checkedon;
2333: if (ref($defaults) eq 'HASH') {
2334: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2335: if ($defaults->{'showlogo'}{$img}) {
2336: $checkedon = 'checked="checked" ';
2337: }
2338: }
2339: }
2340: if (ref($designs) eq 'HASH') {
2341: if (ref($designs->{'showlogo'}) eq 'HASH') {
2342: if (defined($designs->{'showlogo'}{$img})) {
2343: if ($designs->{'showlogo'}{$img} == 0) {
2344: $checkedon = '';
2345: } elsif ($designs->{'showlogo'}{$img} == 1) {
2346: $checkedon = 'checked="checked" ';
2347: }
2348: }
2349: }
2350: }
2351: return '<br /><label> <input type="checkbox" name="'.
2352: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2353: &mt('show').'</label>'."\n";
2354: }
2355:
1.41 raeburn 2356: sub login_header_options {
1.135 bisitz 2357: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2358: my $output = '';
1.41 raeburn 2359: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 2360: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 2361: if (!$is_custom->{'textcol'}) {
2362: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2363: ' ';
2364: }
2365: if (!$is_custom->{'bgcol'}) {
2366: $output .= $choices->{'bgcol'}.': '.
2367: '<span id="css_'.$role.'_font" style="background-color: '.
2368: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2369: }
2370: $output .= '<br />';
2371: }
2372: $output .='<br />';
2373: return $output;
2374: }
2375:
2376: sub login_text_colors {
1.201 raeburn 2377: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 2378: my $color_menu = '<table border="0"><tr>';
2379: foreach my $item (@{$logintext}) {
1.306 raeburn 2380: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 2381: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2382: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2383: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 2384: }
2385: $color_menu .= '</tr></table><br />';
2386: return $color_menu;
2387: }
2388:
2389: sub image_changes {
2390: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2391: my $output;
1.135 bisitz 2392: if ($img eq 'login') {
1.331 raeburn 2393: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 2394: } elsif (!$is_custom) {
1.70 raeburn 2395: if ($img ne 'domlogo') {
1.331 raeburn 2396: $output = &mt('Default image:').'<br />';
1.41 raeburn 2397: } else {
1.331 raeburn 2398: $output = &mt('Default in use:').'<br />';
1.41 raeburn 2399: }
2400: }
1.331 raeburn 2401: if ($img ne 'login') {
1.135 bisitz 2402: if ($img_import) {
2403: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2404: }
2405: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2406: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2407: if ($is_custom) {
2408: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2409: '<input type="checkbox" name="'.
2410: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2411: '</label> '.&mt('Replace:').'</span><br />';
2412: } else {
1.306 raeburn 2413: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 2414: }
1.41 raeburn 2415: }
2416: return $output;
2417: }
2418:
1.3 raeburn 2419: sub print_quotas {
1.86 raeburn 2420: my ($dom,$settings,$rowtotal,$action) = @_;
2421: my $context;
2422: if ($action eq 'quotas') {
2423: $context = 'tools';
2424: } else {
2425: $context = $action;
2426: }
1.429 raeburn 2427: my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44 raeburn 2428: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2429: my $typecount = 0;
1.101 raeburn 2430: my ($css_class,%titles);
1.86 raeburn 2431: if ($context eq 'requestcourses') {
1.325 raeburn 2432: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 2433: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2434: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2435: %titles = &courserequest_titles();
1.163 raeburn 2436: } elsif ($context eq 'requestauthor') {
2437: @usertools = ('author');
2438: @options = ('norequest','approval','automatic');
1.210 raeburn 2439: %titles = &authorrequest_titles();
1.86 raeburn 2440: } else {
1.430 raeburn 2441: @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.101 raeburn 2442: %titles = &tool_titles();
1.86 raeburn 2443: }
1.26 raeburn 2444: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2445: foreach my $type (@{$types}) {
1.429 raeburn 2446: my $currdefquota;
1.163 raeburn 2447: unless (($context eq 'requestcourses') ||
2448: ($context eq 'requestauthor')) {
1.86 raeburn 2449: if (ref($settings) eq 'HASH') {
2450: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 2451: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2452: } else {
2453: $currdefquota = $settings->{$type};
2454: }
1.78 raeburn 2455: }
1.72 raeburn 2456: }
1.3 raeburn 2457: if (defined($usertypes->{$type})) {
2458: $typecount ++;
2459: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2460: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2461: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2462: '<td class="LC_left_item">';
1.101 raeburn 2463: if ($context eq 'requestcourses') {
2464: $datatable .= '<table><tr>';
2465: }
2466: my %cell;
1.72 raeburn 2467: foreach my $item (@usertools) {
1.101 raeburn 2468: if ($context eq 'requestcourses') {
2469: my ($curroption,$currlimit);
2470: if (ref($settings) eq 'HASH') {
2471: if (ref($settings->{$item}) eq 'HASH') {
2472: $curroption = $settings->{$item}->{$type};
2473: if ($curroption =~ /^autolimit=(\d*)$/) {
2474: $currlimit = $1;
2475: }
2476: }
2477: }
2478: if (!$curroption) {
2479: $curroption = 'norequest';
2480: }
2481: $datatable .= '<th>'.$titles{$item}.'</th>';
2482: foreach my $option (@options) {
2483: my $val = $option;
2484: if ($option eq 'norequest') {
2485: $val = 0;
2486: }
2487: if ($option eq 'validate') {
2488: my $canvalidate = 0;
2489: if (ref($validations{$item}) eq 'HASH') {
2490: if ($validations{$item}{$type}) {
2491: $canvalidate = 1;
2492: }
2493: }
2494: next if (!$canvalidate);
2495: }
2496: my $checked = '';
2497: if ($option eq $curroption) {
2498: $checked = ' checked="checked"';
2499: } elsif ($option eq 'autolimit') {
2500: if ($curroption =~ /^autolimit/) {
2501: $checked = ' checked="checked"';
2502: }
2503: }
2504: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2505: '<input type="radio" name="crsreq_'.$item.
2506: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2507: $titles{$option}.'</label>';
1.101 raeburn 2508: if ($option eq 'autolimit') {
1.127 raeburn 2509: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2510: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2511: 'value="'.$currlimit.'" />';
1.101 raeburn 2512: }
1.127 raeburn 2513: $cell{$item} .= '</span> ';
1.103 raeburn 2514: if ($option eq 'autolimit') {
1.127 raeburn 2515: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2516: }
1.101 raeburn 2517: }
1.163 raeburn 2518: } elsif ($context eq 'requestauthor') {
2519: my $curroption;
2520: if (ref($settings) eq 'HASH') {
2521: $curroption = $settings->{$type};
2522: }
2523: if (!$curroption) {
2524: $curroption = 'norequest';
2525: }
2526: foreach my $option (@options) {
2527: my $val = $option;
2528: if ($option eq 'norequest') {
2529: $val = 0;
2530: }
2531: my $checked = '';
2532: if ($option eq $curroption) {
2533: $checked = ' checked="checked"';
2534: }
2535: $datatable .= '<span class="LC_nobreak"><label>'.
2536: '<input type="radio" name="authorreq_'.$type.
2537: '" value="'.$val.'"'.$checked.' />'.
2538: $titles{$option}.'</label></span> ';
2539: }
1.101 raeburn 2540: } else {
2541: my $checked = 'checked="checked" ';
1.413 raeburn 2542: if ($item eq 'timezone') {
2543: $checked = '';
2544: }
1.101 raeburn 2545: if (ref($settings) eq 'HASH') {
2546: if (ref($settings->{$item}) eq 'HASH') {
1.413 raeburn 2547: if (!$settings->{$item}->{$type}) {
1.101 raeburn 2548: $checked = '';
2549: } elsif ($settings->{$item}->{$type} == 1) {
2550: $checked = 'checked="checked" ';
2551: }
1.78 raeburn 2552: }
1.72 raeburn 2553: }
1.101 raeburn 2554: $datatable .= '<span class="LC_nobreak"><label>'.
2555: '<input type="checkbox" name="'.$context.'_'.$item.
2556: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2557: '</label></span> ';
1.72 raeburn 2558: }
1.101 raeburn 2559: }
2560: if ($context eq 'requestcourses') {
2561: $datatable .= '</tr><tr>';
2562: foreach my $item (@usertools) {
1.106 raeburn 2563: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2564: }
2565: $datatable .= '</tr></table>';
1.72 raeburn 2566: }
1.86 raeburn 2567: $datatable .= '</td>';
1.163 raeburn 2568: unless (($context eq 'requestcourses') ||
2569: ($context eq 'requestauthor')) {
1.86 raeburn 2570: $datatable .=
1.197 raeburn 2571: '<td class="LC_right_item">'.
1.429 raeburn 2572: '<span class="LC_nobreak">'.
1.3 raeburn 2573: '<input type="text" name="quota_'.$type.
1.72 raeburn 2574: '" value="'.$currdefquota.
1.197 raeburn 2575: '" size="5" /></span></td>';
1.86 raeburn 2576: }
2577: $datatable .= '</tr>';
1.3 raeburn 2578: }
2579: }
2580: }
1.163 raeburn 2581: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2582: $defaultquota = '20';
2583: if (ref($settings) eq 'HASH') {
2584: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2585: $defaultquota = $settings->{'defaultquota'}->{'default'};
2586: } elsif (defined($settings->{'default'})) {
2587: $defaultquota = $settings->{'default'};
2588: }
1.3 raeburn 2589: }
2590: }
2591: $typecount ++;
2592: $css_class = $typecount%2?' class="LC_odd_row"':'';
2593: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2594: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2595: '<td class="LC_left_item">';
1.101 raeburn 2596: if ($context eq 'requestcourses') {
2597: $datatable .= '<table><tr>';
2598: }
2599: my %defcell;
1.72 raeburn 2600: foreach my $item (@usertools) {
1.101 raeburn 2601: if ($context eq 'requestcourses') {
2602: my ($curroption,$currlimit);
2603: if (ref($settings) eq 'HASH') {
2604: if (ref($settings->{$item}) eq 'HASH') {
2605: $curroption = $settings->{$item}->{'default'};
2606: if ($curroption =~ /^autolimit=(\d*)$/) {
2607: $currlimit = $1;
2608: }
2609: }
2610: }
2611: if (!$curroption) {
2612: $curroption = 'norequest';
2613: }
2614: $datatable .= '<th>'.$titles{$item}.'</th>';
2615: foreach my $option (@options) {
2616: my $val = $option;
2617: if ($option eq 'norequest') {
2618: $val = 0;
2619: }
2620: if ($option eq 'validate') {
2621: my $canvalidate = 0;
2622: if (ref($validations{$item}) eq 'HASH') {
2623: if ($validations{$item}{'default'}) {
2624: $canvalidate = 1;
2625: }
2626: }
2627: next if (!$canvalidate);
2628: }
2629: my $checked = '';
2630: if ($option eq $curroption) {
2631: $checked = ' checked="checked"';
2632: } elsif ($option eq 'autolimit') {
2633: if ($curroption =~ /^autolimit/) {
2634: $checked = ' checked="checked"';
2635: }
2636: }
2637: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2638: '<input type="radio" name="crsreq_'.$item.
2639: '_default" value="'.$val.'"'.$checked.' />'.
2640: $titles{$option}.'</label>';
2641: if ($option eq 'autolimit') {
1.127 raeburn 2642: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2643: $item.'_limit_default" size="1" '.
2644: 'value="'.$currlimit.'" />';
2645: }
1.127 raeburn 2646: $defcell{$item} .= '</span> ';
1.104 raeburn 2647: if ($option eq 'autolimit') {
1.127 raeburn 2648: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2649: }
1.101 raeburn 2650: }
1.163 raeburn 2651: } elsif ($context eq 'requestauthor') {
2652: my $curroption;
2653: if (ref($settings) eq 'HASH') {
1.172 raeburn 2654: $curroption = $settings->{'default'};
1.163 raeburn 2655: }
2656: if (!$curroption) {
2657: $curroption = 'norequest';
2658: }
2659: foreach my $option (@options) {
2660: my $val = $option;
2661: if ($option eq 'norequest') {
2662: $val = 0;
2663: }
2664: my $checked = '';
2665: if ($option eq $curroption) {
2666: $checked = ' checked="checked"';
2667: }
2668: $datatable .= '<span class="LC_nobreak"><label>'.
2669: '<input type="radio" name="authorreq_default"'.
2670: ' value="'.$val.'"'.$checked.' />'.
2671: $titles{$option}.'</label></span> ';
2672: }
1.101 raeburn 2673: } else {
2674: my $checked = 'checked="checked" ';
2675: if (ref($settings) eq 'HASH') {
2676: if (ref($settings->{$item}) eq 'HASH') {
2677: if ($settings->{$item}->{'default'} == 0) {
2678: $checked = '';
2679: } elsif ($settings->{$item}->{'default'} == 1) {
2680: $checked = 'checked="checked" ';
2681: }
1.78 raeburn 2682: }
1.72 raeburn 2683: }
1.101 raeburn 2684: $datatable .= '<span class="LC_nobreak"><label>'.
2685: '<input type="checkbox" name="'.$context.'_'.$item.
2686: '" value="default" '.$checked.'/>'.$titles{$item}.
2687: '</label></span> ';
2688: }
2689: }
2690: if ($context eq 'requestcourses') {
2691: $datatable .= '</tr><tr>';
2692: foreach my $item (@usertools) {
1.106 raeburn 2693: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2694: }
1.101 raeburn 2695: $datatable .= '</tr></table>';
1.72 raeburn 2696: }
1.86 raeburn 2697: $datatable .= '</td>';
1.163 raeburn 2698: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2699: $datatable .= '<td class="LC_right_item">'.
1.429 raeburn 2700: '<span class="LC_nobreak">'.
1.86 raeburn 2701: '<input type="text" name="defaultquota" value="'.
1.429 raeburn 2702: $defaultquota.'" size="5" /></span></td>';
1.86 raeburn 2703: }
2704: $datatable .= '</tr>';
1.72 raeburn 2705: $typecount ++;
2706: $css_class = $typecount%2?' class="LC_odd_row"':'';
2707: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2708: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2709: if ($context eq 'requestcourses') {
1.109 raeburn 2710: $datatable .= &mt('(overrides affiliation, if set)').
2711: '</td>'.
2712: '<td class="LC_left_item">'.
2713: '<table><tr>';
1.101 raeburn 2714: } else {
1.109 raeburn 2715: $datatable .= &mt('(overrides affiliation, if checked)').
2716: '</td>'.
2717: '<td class="LC_left_item" colspan="2">'.
2718: '<br />';
1.101 raeburn 2719: }
2720: my %advcell;
1.72 raeburn 2721: foreach my $item (@usertools) {
1.101 raeburn 2722: if ($context eq 'requestcourses') {
2723: my ($curroption,$currlimit);
2724: if (ref($settings) eq 'HASH') {
2725: if (ref($settings->{$item}) eq 'HASH') {
2726: $curroption = $settings->{$item}->{'_LC_adv'};
2727: if ($curroption =~ /^autolimit=(\d*)$/) {
2728: $currlimit = $1;
2729: }
2730: }
2731: }
2732: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2733: my $checked = '';
2734: if ($curroption eq '') {
2735: $checked = ' checked="checked"';
2736: }
2737: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2738: '<input type="radio" name="crsreq_'.$item.
2739: '__LC_adv" value=""'.$checked.' />'.
2740: &mt('No override set').'</label></span> ';
1.101 raeburn 2741: foreach my $option (@options) {
2742: my $val = $option;
2743: if ($option eq 'norequest') {
2744: $val = 0;
2745: }
2746: if ($option eq 'validate') {
2747: my $canvalidate = 0;
2748: if (ref($validations{$item}) eq 'HASH') {
2749: if ($validations{$item}{'_LC_adv'}) {
2750: $canvalidate = 1;
2751: }
2752: }
2753: next if (!$canvalidate);
2754: }
2755: my $checked = '';
1.104 raeburn 2756: if ($val eq $curroption) {
1.101 raeburn 2757: $checked = ' checked="checked"';
2758: } elsif ($option eq 'autolimit') {
2759: if ($curroption =~ /^autolimit/) {
2760: $checked = ' checked="checked"';
2761: }
2762: }
2763: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2764: '<input type="radio" name="crsreq_'.$item.
2765: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2766: $titles{$option}.'</label>';
2767: if ($option eq 'autolimit') {
1.127 raeburn 2768: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2769: $item.'_limit__LC_adv" size="1" '.
2770: 'value="'.$currlimit.'" />';
2771: }
1.127 raeburn 2772: $advcell{$item} .= '</span> ';
1.104 raeburn 2773: if ($option eq 'autolimit') {
1.127 raeburn 2774: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2775: }
1.101 raeburn 2776: }
1.163 raeburn 2777: } elsif ($context eq 'requestauthor') {
2778: my $curroption;
2779: if (ref($settings) eq 'HASH') {
2780: $curroption = $settings->{'_LC_adv'};
2781: }
2782: my $checked = '';
2783: if ($curroption eq '') {
2784: $checked = ' checked="checked"';
2785: }
2786: $datatable .= '<span class="LC_nobreak"><label>'.
2787: '<input type="radio" name="authorreq__LC_adv"'.
2788: ' value=""'.$checked.' />'.
2789: &mt('No override set').'</label></span> ';
2790: foreach my $option (@options) {
2791: my $val = $option;
2792: if ($option eq 'norequest') {
2793: $val = 0;
2794: }
2795: my $checked = '';
2796: if ($val eq $curroption) {
2797: $checked = ' checked="checked"';
2798: }
2799: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2800: '<input type="radio" name="authorreq__LC_adv"'.
2801: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2802: $titles{$option}.'</label></span> ';
2803: }
1.101 raeburn 2804: } else {
2805: my $checked = 'checked="checked" ';
2806: if (ref($settings) eq 'HASH') {
2807: if (ref($settings->{$item}) eq 'HASH') {
2808: if ($settings->{$item}->{'_LC_adv'} == 0) {
2809: $checked = '';
2810: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2811: $checked = 'checked="checked" ';
2812: }
1.79 raeburn 2813: }
1.72 raeburn 2814: }
1.101 raeburn 2815: $datatable .= '<span class="LC_nobreak"><label>'.
2816: '<input type="checkbox" name="'.$context.'_'.$item.
2817: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2818: '</label></span> ';
2819: }
2820: }
2821: if ($context eq 'requestcourses') {
2822: $datatable .= '</tr><tr>';
2823: foreach my $item (@usertools) {
1.106 raeburn 2824: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2825: }
1.101 raeburn 2826: $datatable .= '</tr></table>';
1.72 raeburn 2827: }
1.98 raeburn 2828: $datatable .= '</td></tr>';
1.30 raeburn 2829: $$rowtotal += $typecount;
1.3 raeburn 2830: return $datatable;
2831: }
2832:
1.163 raeburn 2833: sub print_requestmail {
1.305 raeburn 2834: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2835: my ($now,$datatable,%currapp);
1.102 raeburn 2836: $now = time;
2837: if (ref($settings) eq 'HASH') {
2838: if (ref($settings->{'notify'}) eq 'HASH') {
2839: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2840: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2841: }
2842: }
2843: }
1.191 raeburn 2844: my $numinrow = 2;
1.224 raeburn 2845: my $css_class;
1.305 raeburn 2846: if ($$rowtotal%2) {
2847: $css_class = 'LC_odd_row';
2848: }
2849: if ($customcss) {
2850: $css_class .= " $customcss";
2851: }
2852: $css_class =~ s/^\s+//;
2853: if ($css_class) {
2854: $css_class = ' class="'.$css_class.'"';
2855: }
2856: if ($rowstyle) {
2857: $css_class .= ' style="'.$rowstyle.'"';
2858: }
1.163 raeburn 2859: my $text;
2860: if ($action eq 'requestcourses') {
2861: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2862: } elsif ($action eq 'requestauthor') {
2863: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2864: } else {
1.224 raeburn 2865: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2866: }
1.224 raeburn 2867: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2868: ' <td>'.$text.'</td>'.
1.102 raeburn 2869: ' <td class="LC_left_item">';
1.191 raeburn 2870: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2871: $action.'notifyapproval',%currapp);
1.191 raeburn 2872: if ($numdc > 0) {
2873: $datatable .= $table;
1.102 raeburn 2874: } else {
2875: $datatable .= &mt('There are no active Domain Coordinators');
2876: }
2877: $datatable .='</td></tr>';
2878: return $datatable;
2879: }
2880:
1.216 raeburn 2881: sub print_studentcode {
2882: my ($settings,$rowtotal) = @_;
2883: my $rownum = 0;
1.218 raeburn 2884: my ($output,%current);
1.325 raeburn 2885: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248 raeburn 2886: if (ref($settings) eq 'HASH') {
2887: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2888: foreach my $type (@crstypes) {
2889: $current{$type} = $settings->{'uniquecode'}{$type};
2890: }
1.218 raeburn 2891: }
2892: }
2893: $output .= '<tr>'.
2894: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2895: '<td class="LC_left_item">';
2896: foreach my $type (@crstypes) {
2897: my $check = ' ';
2898: if ($current{$type}) {
2899: $check = ' checked="checked" ';
2900: }
2901: $output .= '<span class="LC_nobreak"><label>'.
2902: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2903: &mt($type).'</label></span>'.(' 'x2).' ';
2904: }
2905: $output .= '</td></tr>';
2906: $$rowtotal ++;
2907: return $output;
1.216 raeburn 2908: }
2909:
2910: sub print_textbookcourses {
1.242 raeburn 2911: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2912: my $rownum = 0;
2913: my $css_class;
2914: my $itemcount = 1;
2915: my $maxnum = 0;
2916: my $bookshash;
2917: if (ref($settings) eq 'HASH') {
1.242 raeburn 2918: $bookshash = $settings->{$type};
1.216 raeburn 2919: }
2920: my %ordered;
2921: if (ref($bookshash) eq 'HASH') {
2922: foreach my $item (keys(%{$bookshash})) {
2923: if (ref($bookshash->{$item}) eq 'HASH') {
2924: my $num = $bookshash->{$item}{'order'};
2925: $ordered{$num} = $item;
2926: }
2927: }
2928: }
2929: my $confname = $dom.'-domainconfig';
2930: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2931: my $maxnum = scalar(keys(%ordered));
2932: my $datatable;
1.216 raeburn 2933: if (keys(%ordered)) {
2934: my @items = sort { $a <=> $b } keys(%ordered);
2935: for (my $i=0; $i<@items; $i++) {
2936: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2937: my $key = $ordered{$items[$i]};
2938: my %coursehash=&Apache::lonnet::coursedescription($key);
2939: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2940: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2941: if (ref($bookshash->{$key}) eq 'HASH') {
2942: $subject = $bookshash->{$key}->{'subject'};
2943: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2944: if ($type eq 'textbooks') {
1.243 raeburn 2945: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2946: $author = $bookshash->{$key}->{'author'};
2947: $image = $bookshash->{$key}->{'image'};
2948: if ($image ne '') {
2949: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2950: my $imagethumb = "$path/tn-".$imagefile;
2951: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2952: }
1.216 raeburn 2953: }
2954: }
1.242 raeburn 2955: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2956: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2957: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2958: for (my $k=0; $k<=$maxnum; $k++) {
2959: my $vpos = $k+1;
2960: my $selstr;
2961: if ($k == $i) {
2962: $selstr = ' selected="selected" ';
2963: }
2964: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2965: }
2966: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2967: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2968: &mt('Delete?').'</label></span></td>'.
2969: '<td colspan="2">'.
1.242 raeburn 2970: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2971: (' 'x2).
1.242 raeburn 2972: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2973: if ($type eq 'textbooks') {
2974: $datatable .= (' 'x2).
1.243 raeburn 2975: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2976: (' 'x2).
1.242 raeburn 2977: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2978: (' 'x2).
2979: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2980: if ($image) {
1.267 raeburn 2981: $datatable .= $imgsrc.
1.242 raeburn 2982: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2983: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2984: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2985: }
2986: if ($switchserver) {
2987: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2988: } else {
2989: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2990: }
1.216 raeburn 2991: }
1.242 raeburn 2992: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2993: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2994: $coursetitle.'</span></td></tr>'."\n";
2995: $itemcount ++;
2996: }
2997: }
2998: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2999: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 3000: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 3001: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
3002: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 3003: for (my $k=0; $k<$maxnum+1; $k++) {
3004: my $vpos = $k+1;
3005: my $selstr;
3006: if ($k == $maxnum) {
3007: $selstr = ' selected="selected" ';
3008: }
3009: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3010: }
3011: $datatable .= '</select> '."\n".
1.334 raeburn 3012: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216 raeburn 3013: '<td colspan="2">'.
1.242 raeburn 3014: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 3015: (' 'x2).
1.242 raeburn 3016: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
3017: (' 'x2);
3018: if ($type eq 'textbooks') {
1.243 raeburn 3019: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
3020: (' 'x2).
3021: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 3022: (' 'x2).
3023: '<span class="LC_nobreak">'.&mt('Image:').' ';
3024: if ($switchserver) {
3025: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3026: } else {
3027: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
3028: }
1.334 raeburn 3029: $datatable .= '</span>'."\n";
1.216 raeburn 3030: }
1.334 raeburn 3031: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 3032: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
3033: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 3034: &Apache::loncommon::selectcourse_link
1.334 raeburn 3035: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216 raeburn 3036: '</span></td>'."\n".
3037: '</tr>'."\n";
3038: $itemcount ++;
3039: return $datatable;
3040: }
3041:
1.217 raeburn 3042: sub textbookcourses_javascript {
1.242 raeburn 3043: my ($settings) = @_;
3044: return unless(ref($settings) eq 'HASH');
3045: my (%ordered,%total,%jstext);
3046: foreach my $type ('textbooks','templates') {
3047: $total{$type} = 0;
3048: if (ref($settings->{$type}) eq 'HASH') {
3049: foreach my $item (keys(%{$settings->{$type}})) {
3050: if (ref($settings->{$type}->{$item}) eq 'HASH') {
3051: my $num = $settings->{$type}->{$item}{'order'};
3052: $ordered{$type}{$num} = $item;
3053: }
3054: }
3055: $total{$type} = scalar(keys(%{$settings->{$type}}));
3056: }
3057: my @jsarray = ();
3058: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
3059: push(@jsarray,$ordered{$type}{$item});
3060: }
3061: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 3062: }
3063: return <<"ENDSCRIPT";
3064: <script type="text/javascript">
3065: // <![CDATA[
1.242 raeburn 3066: function reorderBooks(form,item,caller) {
1.217 raeburn 3067: var changedVal;
1.242 raeburn 3068: $jstext{'textbooks'};
3069: $jstext{'templates'};
3070: var newpos;
3071: var maxh;
3072: if (caller == 'textbooks') {
3073: newpos = 'textbooks_addbook_pos';
3074: maxh = 1 + $total{'textbooks'};
3075: } else {
3076: newpos = 'templates_addbook_pos';
3077: maxh = 1 + $total{'templates'};
3078: }
1.217 raeburn 3079: var current = new Array;
3080: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3081: if (item == newpos) {
3082: changedVal = newitemVal;
3083: } else {
3084: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3085: current[newitemVal] = newpos;
3086: }
1.242 raeburn 3087: if (caller == 'textbooks') {
3088: for (var i=0; i<textbooks.length; i++) {
3089: var elementName = 'textbooks_'+textbooks[i];
3090: if (elementName != item) {
3091: if (form.elements[elementName]) {
3092: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3093: current[currVal] = elementName;
3094: }
3095: }
3096: }
3097: }
3098: if (caller == 'templates') {
3099: for (var i=0; i<templates.length; i++) {
3100: var elementName = 'templates_'+templates[i];
3101: if (elementName != item) {
3102: if (form.elements[elementName]) {
3103: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3104: current[currVal] = elementName;
3105: }
1.217 raeburn 3106: }
3107: }
3108: }
3109: var oldVal;
3110: for (var j=0; j<maxh; j++) {
3111: if (current[j] == undefined) {
3112: oldVal = j;
3113: }
3114: }
3115: if (oldVal < changedVal) {
3116: for (var k=oldVal+1; k<=changedVal ; k++) {
3117: var elementName = current[k];
3118: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3119: }
3120: } else {
3121: for (var k=changedVal; k<oldVal; k++) {
3122: var elementName = current[k];
3123: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3124: }
3125: }
3126: return;
3127: }
3128:
3129: // ]]>
3130: </script>
3131:
3132: ENDSCRIPT
3133: }
3134:
1.267 raeburn 3135: sub ltitools_javascript {
3136: my ($settings) = @_;
1.319 raeburn 3137: my $togglejs = <itools_toggle_js();
3138: unless (ref($settings) eq 'HASH') {
3139: return $togglejs;
3140: }
1.267 raeburn 3141: my (%ordered,$total,%jstext);
3142: $total = 0;
3143: foreach my $item (keys(%{$settings})) {
3144: if (ref($settings->{$item}) eq 'HASH') {
3145: my $num = $settings->{$item}{'order'};
3146: $ordered{$num} = $item;
3147: }
3148: }
3149: $total = scalar(keys(%{$settings}));
3150: my @jsarray = ();
3151: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3152: push(@jsarray,$ordered{$item});
3153: }
3154: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
3155: return <<"ENDSCRIPT";
3156: <script type="text/javascript">
3157: // <![CDATA[
1.319 raeburn 3158: function reorderLTITools(form,item) {
1.267 raeburn 3159: var changedVal;
3160: $jstext
3161: var newpos = 'ltitools_add_pos';
3162: var maxh = 1 + $total;
3163: var current = new Array;
3164: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3165: if (item == newpos) {
3166: changedVal = newitemVal;
3167: } else {
3168: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3169: current[newitemVal] = newpos;
3170: }
3171: for (var i=0; i<ltitools.length; i++) {
3172: var elementName = 'ltitools_'+ltitools[i];
3173: if (elementName != item) {
3174: if (form.elements[elementName]) {
3175: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3176: current[currVal] = elementName;
3177: }
3178: }
3179: }
3180: var oldVal;
3181: for (var j=0; j<maxh; j++) {
3182: if (current[j] == undefined) {
3183: oldVal = j;
3184: }
3185: }
3186: if (oldVal < changedVal) {
3187: for (var k=oldVal+1; k<=changedVal ; k++) {
3188: var elementName = current[k];
3189: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3190: }
3191: } else {
3192: for (var k=changedVal; k<oldVal; k++) {
3193: var elementName = current[k];
3194: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3195: }
3196: }
3197: return;
3198: }
3199:
3200: // ]]>
3201: </script>
3202:
1.319 raeburn 3203: $togglejs
3204:
3205: ENDSCRIPT
3206: }
3207:
3208: sub ltitools_toggle_js {
3209: return <<"ENDSCRIPT";
3210: <script type="text/javascript">
3211: // <![CDATA[
3212:
3213: function toggleLTITools(form,setting,item) {
3214: var radioname = '';
3215: var divid = '';
3216: if ((setting == 'passback') || (setting == 'roster')) {
3217: radioname = 'ltitools_'+setting+'_'+item;
3218: divid = 'ltitools_'+setting+'time_'+item;
3219: var num = form.elements[radioname].length;
3220: if (num) {
3221: var setvis = '';
3222: for (var i=0; i<num; i++) {
3223: if (form.elements[radioname][i].checked) {
3224: if (form.elements[radioname][i].value == '1') {
3225: if (document.getElementById(divid)) {
3226: document.getElementById(divid).style.display = 'inline-block';
3227: }
3228: setvis = 1;
3229: }
3230: break;
3231: }
3232: }
3233: }
3234: if (!setvis) {
3235: if (document.getElementById(divid)) {
3236: document.getElementById(divid).style.display = 'none';
3237: }
3238: }
3239: }
1.324 raeburn 3240: if (setting == 'user') {
3241: divid = 'ltitools_'+setting+'_div_'+item;
3242: var checkid = 'ltitools_'+setting+'_field_'+item;
3243: if (document.getElementById(divid)) {
3244: if (document.getElementById(checkid)) {
3245: if (document.getElementById(checkid).checked) {
3246: document.getElementById(divid).style.display = 'inline-block';
3247: } else {
3248: document.getElementById(divid).style.display = 'none';
3249: }
3250: }
3251: }
3252: }
1.319 raeburn 3253: return;
3254: }
3255: // ]]>
3256: </script>
3257:
1.267 raeburn 3258: ENDSCRIPT
3259: }
3260:
1.381 raeburn 3261: sub wafproxy_javascript {
3262: my ($dom) = @_;
3263: return <<"ENDSCRIPT";
3264: <script type="text/javascript">
3265: // <![CDATA[
3266: function updateWAF() {
3267: if (document.getElementById('wafproxy_remoteip')) {
3268: var wafremote = 0;
3269: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
3270: wafremote = 1;
3271: }
3272: var fields = new Array('header','trust');
3273: for (var i=0; i<fields.length; i++) {
3274: if (document.getElementById('wafproxy_'+fields[i])) {
3275: if (wafremote == 1) {
3276: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
3277: }
3278: else {
3279: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
3280: }
3281: }
3282: }
3283: if (document.getElementById('wafproxyranges_$dom')) {
3284: if (wafremote == 1) {
3285: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3286: } else {
3287: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3288: if (document.display.wafproxy_vpnaccess[i].checked) {
3289: if (document.display.wafproxy_vpnaccess[i].value == 0) {
3290: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3291: }
3292: }
3293: }
3294: }
3295: }
3296: }
3297: return;
3298: }
3299:
3300: function checkWAF() {
3301: if (document.getElementById('wafproxy_remoteip')) {
3302: var wafvpn = 0;
3303: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3304: if (document.display.wafproxy_vpnaccess[i].checked) {
3305: if (document.display.wafproxy_vpnaccess[i].value == 1) {
3306: wafvpn = 1;
3307: }
3308: break;
3309: }
3310: }
3311: var vpn = new Array('vpnint','vpnext');
3312: for (var i=0; i<vpn.length; i++) {
3313: if (document.getElementById('wafproxy_show_'+vpn[i])) {
3314: if (wafvpn == 1) {
3315: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
3316: }
3317: else {
3318: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
3319: }
3320: }
3321: }
3322: if (document.getElementById('wafproxyranges_$dom')) {
3323: if (wafvpn == 1) {
3324: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3325: }
3326: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
3327: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3328: }
3329: }
3330: }
3331: return;
3332: }
3333:
3334: function toggleWAF() {
3335: if (document.getElementById('wafproxy_table')) {
3336: var wafproxy = 0;
3337: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
3338: if (document.display.wafproxy_${dom}[i].checked) {
3339: if (document.display.wafproxy_${dom}[i].value == 1) {
3340: wafproxy = 1;
3341: break;
3342: }
3343: }
3344: }
3345: if (wafproxy == 1) {
3346: document.getElementById('wafproxy_table').style.display='inline';
3347: }
3348: else {
3349: document.getElementById('wafproxy_table').style.display='none';
3350: }
3351: if (document.getElementById('wafproxyrow_${dom}')) {
3352: if (wafproxy == 1) {
3353: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
3354: }
3355: else {
3356: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
3357: }
3358: }
3359: if (document.getElementById('nowafproxyrow_$dom')) {
3360: if (wafproxy == 1) {
3361: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
3362: }
3363: else {
3364: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
3365: }
3366: }
3367: }
3368: return;
3369: }
3370: // ]]>
3371: </script>
3372:
3373: ENDSCRIPT
3374: }
3375:
1.372 raeburn 3376: sub proctoring_javascript {
3377: my ($settings) = @_;
3378: my (%ordered,$total,%jstext);
3379: $total = 0;
3380: if (ref($settings) eq 'HASH') {
3381: foreach my $item (keys(%{$settings})) {
3382: if (ref($settings->{$item}) eq 'HASH') {
3383: my $num = $settings->{$item}{'order'};
3384: $ordered{$num} = $item;
3385: }
3386: }
3387: $total = scalar(keys(%{$settings}));
3388: } else {
3389: %ordered = (
3390: 0 => 'proctorio',
3391: 1 => 'examity',
3392: );
3393: $total = 2;
3394: }
3395: my @jsarray = ();
3396: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3397: push(@jsarray,$ordered{$item});
3398: }
3399: my $jstext = ' var proctors = Array('."'".join("','",@jsarray)."'".');'."\n";
3400: return <<"ENDSCRIPT";
3401: <script type="text/javascript">
3402: // <![CDATA[
3403: function reorderProctoring(form,item) {
3404: var changedVal;
3405: $jstext
3406: var maxh = $total;
3407: var current = new Array;
3408: var changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3409: for (var i=0; i<proctors.length; i++) {
3410: var elementName = 'proctoring_pos_'+proctors[i];
3411: if (elementName != item) {
3412: if (form.elements[elementName]) {
3413: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3414: current[currVal] = elementName;
3415: }
3416: }
3417: }
3418: var oldVal;
3419: for (var j=0; j<maxh; j++) {
3420: if (current[j] == undefined) {
3421: oldVal = j;
3422: }
3423: }
3424: if (oldVal < changedVal) {
3425: for (var k=oldVal+1; k<=changedVal ; k++) {
3426: var elementName = current[k];
3427: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3428: }
3429: } else {
3430: for (var k=changedVal; k<oldVal; k++) {
3431: var elementName = current[k];
3432: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3433: }
3434: }
3435: return;
3436: }
3437:
3438: function toggleProctoring(form,item) {
3439: var fieldsets = document.getElementsByClassName('proctoring_'+item);
3440: if (fieldsets.length) {
3441: var radioname = 'proctoring_available_'+item;
3442: var num = form.elements[radioname].length;
3443: if (num) {
3444: var setvis = '';
3445: for (var i=0; i<num; i++) {
3446: if (form.elements[radioname][i].checked) {
3447: if (form.elements[radioname][i].value == '1') {
3448: setvis = 1;
3449: break;
3450: }
3451: }
3452: }
3453: for (var j=0; j<fieldsets.length; j++) {
3454: if (setvis) {
3455: fieldsets[j].style.display = 'block';
3456: } else {
3457: fieldsets[j].style.display = 'none';
3458: }
3459: }
3460: }
3461: }
3462: return;
3463: }
3464:
3465: // ]]>
3466: </script>
3467:
3468: ENDSCRIPT
3469: }
3470:
3471:
1.320 raeburn 3472: sub lti_javascript {
1.405 raeburn 3473: my ($dom,$settings) = @_;
3474: my $togglejs = <i_toggle_js($dom);
1.419 raeburn 3475: my $linkprot_js = &Apache::courseprefs::linkprot_javascript();
1.320 raeburn 3476: unless (ref($settings) eq 'HASH') {
1.419 raeburn 3477: return $togglejs.'
3478: <script type="text/javascript">
3479: // <![CDATA[
3480:
3481: '.$linkprot_js.'
3482:
3483: // ]]>
3484: </script>
3485: ';
1.320 raeburn 3486: }
3487: my (%ordered,$total,%jstext);
1.390 raeburn 3488: $total = scalar(keys(%{$settings}));
1.320 raeburn 3489: foreach my $item (keys(%{$settings})) {
3490: if (ref($settings->{$item}) eq 'HASH') {
3491: my $num = $settings->{$item}{'order'};
1.390 raeburn 3492: if ($num eq '') {
3493: $num = $total - 1;
3494: }
1.320 raeburn 3495: $ordered{$num} = $item;
3496: }
3497: }
3498: my @jsarray = ();
3499: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3500: push(@jsarray,$ordered{$item});
3501: }
3502: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
3503: return <<"ENDSCRIPT";
3504: <script type="text/javascript">
3505: // <![CDATA[
3506: function reorderLTI(form,item) {
3507: var changedVal;
3508: $jstext
3509: var newpos = 'lti_pos_add';
3510: var maxh = 1 + $total;
3511: var current = new Array;
3512: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3513: if (item == newpos) {
3514: changedVal = newitemVal;
3515: } else {
3516: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3517: current[newitemVal] = newpos;
3518: }
3519: for (var i=0; i<lti.length; i++) {
3520: var elementName = 'lti_pos_'+lti[i];
3521: if (elementName != item) {
3522: if (form.elements[elementName]) {
3523: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3524: current[currVal] = elementName;
3525: }
3526: }
3527: }
3528: var oldVal;
3529: for (var j=0; j<maxh; j++) {
3530: if (current[j] == undefined) {
3531: oldVal = j;
3532: }
3533: }
3534: if (oldVal < changedVal) {
3535: for (var k=oldVal+1; k<=changedVal ; k++) {
3536: var elementName = current[k];
3537: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3538: }
3539: } else {
3540: for (var k=changedVal; k<oldVal; k++) {
3541: var elementName = current[k];
3542: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3543: }
3544: }
3545: return;
3546: }
1.406 raeburn 3547:
3548: $linkprot_js
3549:
1.320 raeburn 3550: // ]]>
3551: </script>
3552:
3553: $togglejs
3554:
3555: ENDSCRIPT
3556: }
3557:
3558: sub lti_toggle_js {
1.405 raeburn 3559: my ($dom) = @_;
1.325 raeburn 3560: my %lcauthparmtext = &Apache::lonlocal::texthash (
3561: localauth => 'Local auth argument',
3562: krb => 'Kerberos domain',
3563: );
1.391 raeburn 3564: my $crsincalert = &mt('"User\'s identity sent" needs to be set to "Yes" first,[_1] before setting "Course\'s identity sent" to "Yes"',"\n");
3565: &js_escape(\$crsincalert);
1.405 raeburn 3566: my %servers = &Apache::lonnet::get_servers($dom,'library');
3567: my $primary = &Apache::lonnet::domain($dom,'primary');
3568: my $course_servers = "'".join("','",keys(%servers))."'";
1.320 raeburn 3569: return <<"ENDSCRIPT";
3570: <script type="text/javascript">
3571: // <![CDATA[
3572:
3573: function toggleLTI(form,setting,item) {
1.391 raeburn 3574: if ((setting == 'requser') || (setting == 'crsinc')) {
3575: var usrfieldsets = document.getElementsByClassName('ltioption_usr_'+item);
3576: var setvis = '';
3577: var radioname = 'lti_requser_'+item;
3578: var num = form.elements[radioname].length;
3579: if (num) {
3580: for (var i=0; i<num; i++) {
3581: if (form.elements[radioname][i].checked) {
3582: if (form.elements[radioname][i].value == '1') {
3583: setvis = 1;
3584: break;
3585: }
3586: }
3587: }
3588: }
3589: if (usrfieldsets.length) {
3590: for (var j=0; j<usrfieldsets.length; j++) {
3591: if (setvis) {
3592: usrfieldsets[j].style.display = 'block';
3593: } else {
3594: usrfieldsets[j].style.display = 'none';
3595: }
3596: }
3597: }
3598: var crsfieldsets = document.getElementsByClassName('ltioption_crs_'+item);
3599: if (crsfieldsets.length) {
3600: radioname = 'lti_crsinc_'+item;
1.345 raeburn 3601: var num = form.elements[radioname].length;
3602: if (num) {
1.391 raeburn 3603: var crsvis = '';
1.345 raeburn 3604: for (var i=0; i<num; i++) {
3605: if (form.elements[radioname][i].checked) {
3606: if (form.elements[radioname][i].value == '1') {
1.391 raeburn 3607: if (setvis == '') {
3608: if (setting == 'crsinc'){
3609: alert("$crsincalert");
3610: form.elements[radioname][0].checked = true;
3611: }
3612: } else {
3613: crsvis = 1;
3614: }
3615: break;
1.345 raeburn 3616: }
3617: }
3618: }
1.391 raeburn 3619: setvis = crsvis;
3620: }
3621: for (var j=0; j<crsfieldsets.length; j++) {
3622: if (setvis) {
3623: crsfieldsets[j].style.display = 'block';
3624: } else {
3625: crsfieldsets[j].style.display = 'none';
1.345 raeburn 3626: }
3627: }
3628: }
1.363 raeburn 3629: } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
1.320 raeburn 3630: var radioname = '';
3631: var divid = '';
3632: if (setting == 'user') {
3633: radioname = 'lti_mapuser_'+item;
3634: divid = 'lti_userfield_'+item;
1.343 raeburn 3635: } else if (setting == 'crs') {
1.320 raeburn 3636: radioname = 'lti_mapcrs_'+item;
3637: divid = 'lti_crsfield_'+item;
1.363 raeburn 3638: } else if (setting == 'callback') {
3639: radioname = 'lti_callback_'+item;
3640: divid = 'lti_callbackfield_'+item;
1.337 raeburn 3641: } else {
1.351 raeburn 3642: radioname = 'lti_passback_'+item;
1.337 raeburn 3643: divid = 'lti_passback_'+item;
1.320 raeburn 3644: }
3645: var num = form.elements[radioname].length;
3646: if (num) {
3647: var setvis = '';
3648: for (var i=0; i<num; i++) {
3649: if (form.elements[radioname][i].checked) {
1.363 raeburn 3650: if ((setting == 'passback') || (setting == 'callback')) {
1.337 raeburn 3651: if (form.elements[radioname][i].value == '1') {
3652: if (document.getElementById(divid)) {
3653: document.getElementById(divid).style.display = 'inline-block';
3654: }
3655: setvis = 1;
3656: break;
3657: }
3658: } else {
3659: if (form.elements[radioname][i].value == 'other') {
3660: if (document.getElementById(divid)) {
3661: document.getElementById(divid).style.display = 'inline-block';
3662: }
3663: setvis = 1;
3664: break;
1.320 raeburn 3665: }
3666: }
1.425 raeburn 3667: }
1.320 raeburn 3668: }
3669: if (!setvis) {
3670: if (document.getElementById(divid)) {
3671: document.getElementById(divid).style.display = 'none';
3672: }
3673: }
3674: }
3675: } else if ((setting == 'sec') || (setting == 'secsrc')) {
3676: var numsec = form.elements['lti_crssec_'+item].length;
3677: if (numsec) {
3678: var setvis = '';
3679: for (var i=0; i<numsec; i++) {
3680: if (form.elements['lti_crssec_'+item][i].checked) {
3681: if (form.elements['lti_crssec_'+item][i].value == '1') {
3682: if (document.getElementById('lti_crssecfield_'+item)) {
3683: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
3684: setvis = 1;
3685: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
3686: if (numsrcsec) {
3687: var setsrcvis = '';
3688: for (var j=0; j<numsrcsec; j++) {
3689: if (form.elements['lti_crssecsrc_'+item][j].checked) {
3690: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
3691: if (document.getElementById('lti_secsrcfield_'+item)) {
3692: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
3693: setsrcvis = 1;
3694: }
3695: }
3696: }
3697: }
3698: if (!setsrcvis) {
3699: if (document.getElementById('lti_secsrcfield_'+item)) {
3700: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3701: }
3702: }
3703: }
3704: }
3705: }
3706: }
3707: }
3708: if (!setvis) {
3709: if (document.getElementById('lti_crssecfield_'+item)) {
3710: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
3711: }
3712: if (document.getElementById('lti_secsrcfield_'+item)) {
3713: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3714: }
3715: }
3716: }
1.325 raeburn 3717: } else if (setting == 'lcauth') {
3718: var numauth = form.elements['lti_lcauth_'+item].length;
3719: if (numauth) {
3720: for (var i=0; i<numauth; i++) {
3721: if (form.elements['lti_lcauth_'+item][i].checked) {
3722: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
3723: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
3724: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
3725: } else {
3726: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
3727: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
3728: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
3729: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
3730: } else {
3731: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
3732: }
3733: }
3734: }
3735: }
3736: }
3737: }
3738: }
1.326 raeburn 3739: } else if (setting == 'lcmenu') {
3740: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3741: var divid = 'lti_menufield_'+item;
3742: var setvis = '';
3743: for (var i=0; i<menus.length; i++) {
1.425 raeburn 3744: var radioname = menus[i];
1.326 raeburn 3745: var num = form.elements[radioname].length;
3746: if (num) {
3747: for (var j=0; j<num; j++) {
3748: if (form.elements[radioname][j].checked) {
3749: if (form.elements[radioname][j].value == '1') {
3750: if (document.getElementById(divid)) {
3751: document.getElementById(divid).style.display = 'inline-block';
3752: }
3753: setvis = 1;
3754: break;
3755: }
3756: }
3757: }
3758: }
3759: if (setvis == 1) {
3760: break;
3761: }
3762: }
3763: if (!setvis) {
3764: if (document.getElementById(divid)) {
3765: document.getElementById(divid).style.display = 'none';
3766: }
3767: }
1.320 raeburn 3768: }
3769: return;
3770: }
1.405 raeburn 3771:
1.320 raeburn 3772: // ]]>
3773: </script>
3774:
3775: ENDSCRIPT
3776: }
3777:
1.385 raeburn 3778: sub autoupdate_javascript {
3779: return <<"ENDSCRIPT";
3780: <script type="text/javascript">
3781: // <![CDATA[
3782: function toggleLastActiveDays(form) {
3783: var radioname = 'lastactive';
3784: var divid = 'lastactive_div';
3785: var num = form.elements[radioname].length;
3786: if (num) {
3787: var setvis = '';
3788: for (var i=0; i<num; i++) {
3789: if (form.elements[radioname][i].checked) {
3790: if (form.elements[radioname][i].value == '1') {
3791: if (document.getElementById(divid)) {
3792: document.getElementById(divid).style.display = 'inline-block';
3793: }
3794: setvis = 1;
3795: }
3796: break;
3797: }
3798: }
3799: if (!setvis) {
3800: if (document.getElementById(divid)) {
3801: document.getElementById(divid).style.display = 'none';
3802: }
3803: }
3804: }
3805: return;
3806: }
3807: // ]]>
3808: </script>
3809:
3810: ENDSCRIPT
3811: }
3812:
1.399 raeburn 3813: sub autoenroll_javascript {
3814: return <<"ENDSCRIPT";
3815: <script type="text/javascript">
3816: // <![CDATA[
3817: function toggleFailsafe(form) {
3818: var radioname = 'autoenroll_failsafe';
3819: var divid = 'autoenroll_failsafe_div';
3820: var num = form.elements[radioname].length;
3821: if (num) {
3822: var setvis = '';
3823: for (var i=0; i<num; i++) {
3824: if (form.elements[radioname][i].checked) {
3825: if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
3826: if (document.getElementById(divid)) {
3827: document.getElementById(divid).style.display = 'inline-block';
3828: }
3829: setvis = 1;
3830: }
3831: break;
3832: }
3833: }
3834: if (!setvis) {
3835: if (document.getElementById(divid)) {
3836: document.getElementById(divid).style.display = 'none';
3837: }
3838: }
3839: }
3840: return;
3841: }
3842: // ]]>
3843: </script>
3844:
3845: ENDSCRIPT
3846: }
3847:
1.386 raeburn 3848: sub saml_javascript {
3849: return <<"ENDSCRIPT";
3850: <script type="text/javascript">
3851: // <![CDATA[
1.425 raeburn 3852: function toggleSamlOptions(form,hostid) {
1.386 raeburn 3853: var radioname = 'saml_'+hostid;
3854: var tablecellon = 'samloptionson_'+hostid;
3855: var tablecelloff = 'samloptionsoff_'+hostid;
3856: var num = form.elements[radioname].length;
3857: if (num) {
1.425 raeburn 3858: var setvis = '';
1.386 raeburn 3859: for (var i=0; i<num; i++) {
3860: if (form.elements[radioname][i].checked) {
1.425 raeburn 3861: if (form.elements[radioname][i].value == '1') {
1.386 raeburn 3862: if (document.getElementById(tablecellon)) {
3863: document.getElementById(tablecellon).style.display='';
3864: }
3865: if (document.getElementById(tablecelloff)) {
3866: document.getElementById(tablecelloff).style.display='none';
3867: }
3868: setvis = 1;
3869: }
3870: break;
3871: }
3872: }
3873: if (!setvis) {
3874: if (document.getElementById(tablecellon)) {
3875: document.getElementById(tablecellon).style.display='none';
3876: }
3877: if (document.getElementById(tablecelloff)) {
3878: document.getElementById(tablecelloff).style.display='';
3879: }
3880: }
3881: }
3882: return;
3883: }
3884: // ]]>
3885: </script>
3886:
3887: ENDSCRIPT
3888: }
3889:
1.394 raeburn 3890: sub ipaccess_javascript {
3891: my ($settings) = @_;
3892: my (%ordered,$total,%jstext);
3893: $total = 0;
3894: if (ref($settings) eq 'HASH') {
3895: foreach my $item (keys(%{$settings})) {
3896: if (ref($settings->{$item}) eq 'HASH') {
3897: my $num = $settings->{$item}{'order'};
3898: $ordered{$num} = $item;
3899: }
3900: }
3901: $total = scalar(keys(%{$settings}));
3902: }
3903: my @jsarray = ();
3904: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3905: push(@jsarray,$ordered{$item});
3906: }
3907: my $jstext = ' var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
3908: return <<"ENDSCRIPT";
3909: <script type="text/javascript">
3910: // <![CDATA[
3911: function reorderIPaccess(form,item) {
3912: var changedVal;
3913: $jstext
3914: var newpos = 'ipaccess_pos_add';
3915: var maxh = 1 + $total;
3916: var current = new Array;
3917: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3918: if (item == newpos) {
3919: changedVal = newitemVal;
3920: } else {
3921: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3922: current[newitemVal] = newpos;
3923: }
3924: for (var i=0; i<ipaccess.length; i++) {
3925: var elementName = 'ipaccess_pos_'+ipaccess[i];
3926: if (elementName != item) {
3927: if (form.elements[elementName]) {
3928: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3929: current[currVal] = elementName;
3930: }
3931: }
3932: }
3933: var oldVal;
3934: for (var j=0; j<maxh; j++) {
3935: if (current[j] == undefined) {
3936: oldVal = j;
3937: }
3938: }
3939: if (oldVal < changedVal) {
3940: for (var k=oldVal+1; k<=changedVal ; k++) {
3941: var elementName = current[k];
3942: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3943: }
3944: } else {
3945: for (var k=changedVal; k<oldVal; k++) {
3946: var elementName = current[k];
3947: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3948: }
3949: }
3950: return;
3951: }
3952: // ]]>
3953: </script>
3954:
3955: ENDSCRIPT
3956: }
3957:
1.429 raeburn 3958: sub authordefaults_javascript {
3959: my %alert = &Apache::lonlocal::texthash (
3960: reqd => 'Warning: at least one editor needs to be available.',
3961: rest => 'Unchecking this editor disallowed while others unchecked.',
3962: );
3963: &js_escape(\%alert);
3964: return <<"ENDSCRIPT";
3965: <script type="text/javascript">
3966: // <![CDATA[
3967:
3968: function checkEditors(form,checkbox,current) {
3969: if (form.elements[checkbox].length != undefined) {
3970: var count = 0;
3971: for (var i=0; i<form.elements[checkbox].length; i++) {
3972: if (form.elements[checkbox][i].checked) {
3973: count ++;
3974: }
3975: }
3976: if (count == 0) {
3977: if (current.type =='radio') {
3978: current.checked = true;
3979: alert('$alert{reqd}\\n$alert{rest}');
3980: }
3981: }
3982: }
3983: return;
3984: }
3985: // ]]>
3986: </script>
3987:
3988: ENDSCRIPT
3989: }
3990:
1.3 raeburn 3991: sub print_autoenroll {
1.30 raeburn 3992: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3993: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.399 raeburn 3994: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
3995: $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
3996: $failsafesty = 'none';
3997: %failsafechecked = (
3998: off => ' checked="checked"',
3999: );
1.3 raeburn 4000: if (ref($settings) eq 'HASH') {
4001: if (exists($settings->{'run'})) {
4002: if ($settings->{'run'} eq '0') {
4003: $runoff = ' checked="checked" ';
4004: $runon = ' ';
4005: } else {
4006: $runon = ' checked="checked" ';
4007: $runoff = ' ';
4008: }
4009: } else {
4010: if ($autorun) {
4011: $runon = ' checked="checked" ';
4012: $runoff = ' ';
4013: } else {
4014: $runoff = ' checked="checked" ';
4015: $runon = ' ';
4016: }
4017: }
1.129 raeburn 4018: if (exists($settings->{'co-owners'})) {
4019: if ($settings->{'co-owners'} eq '0') {
4020: $coownersoff = ' checked="checked" ';
4021: $coownerson = ' ';
4022: } else {
4023: $coownerson = ' checked="checked" ';
4024: $coownersoff = ' ';
4025: }
4026: } else {
4027: $coownersoff = ' checked="checked" ';
4028: $coownerson = ' ';
4029: }
1.3 raeburn 4030: if (exists($settings->{'sender_domain'})) {
4031: $defdom = $settings->{'sender_domain'};
4032: }
1.399 raeburn 4033: if (exists($settings->{'failsafe'})) {
4034: $failsafe = $settings->{'failsafe'};
4035: if ($failsafe eq 'zero') {
1.400 raeburn 4036: $failsafechecked{'zero'} = ' checked="checked"';
1.399 raeburn 4037: $failsafechecked{'off'} = '';
4038: $failsafesty = 'inline-block';
4039: } elsif ($failsafe eq 'any') {
4040: $failsafechecked{'any'} = ' checked="checked"';
4041: $failsafechecked{'off'} = '';
4042: }
4043: $autofailsafe = $settings->{'autofailsafe'};
4044: } elsif (exists($settings->{'autofailsafe'})) {
4045: $autofailsafe = $settings->{'autofailsafe'};
4046: if ($autofailsafe ne '') {
4047: $failsafechecked{'zero'} = ' checked="checked"';
4048: $failsafe = 'zero';
1.400 raeburn 4049: $failsafechecked{'off'} = '';
1.399 raeburn 4050: }
1.274 raeburn 4051: }
1.14 raeburn 4052: } else {
4053: if ($autorun) {
4054: $runon = ' checked="checked" ';
4055: $runoff = ' ';
4056: } else {
4057: $runoff = ' checked="checked" ';
4058: $runon = ' ';
4059: }
1.3 raeburn 4060: }
4061: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 4062: my $notif_sender;
4063: if (ref($settings) eq 'HASH') {
4064: $notif_sender = $settings->{'sender_uname'};
4065: }
1.3 raeburn 4066: my $datatable='<tr class="LC_odd_row">'.
4067: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 4068: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 4069: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 4070: $runon.' value="1" />'.&mt('Yes').'</label> '.
4071: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 4072: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 4073: '</tr><tr>'.
4074: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 4075: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 4076: &mt('username').': '.
4077: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 4078: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 4079: ': '.$domform.'</span></td></tr>'.
4080: '<tr class="LC_odd_row">'.
4081: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
4082: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4083: '<input type="radio" name="autoassign_coowners"'.
4084: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
4085: '<label><input type="radio" name="autoassign_coowners"'.
4086: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 4087: '</tr><tr>'.
4088: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
1.400 raeburn 4089: '<td class="LC_left_item"><span class="LC_nobreak">'.
4090: '<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> '.
4091: '<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 />'.
4092: '<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 4093: '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
4094: '<span class="LC_nobreak">'.
4095: &mt('Threshold for number of students in section to drop: [_1]',
4096: '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
4097: '</span></div></td></tr>';
1.274 raeburn 4098: $$rowtotal += 4;
1.3 raeburn 4099: return $datatable;
4100: }
4101:
4102: sub print_autoupdate {
1.30 raeburn 4103: my ($position,$dom,$settings,$rowtotal) = @_;
1.385 raeburn 4104: my ($enable,$datatable);
1.3 raeburn 4105: if ($position eq 'top') {
1.385 raeburn 4106: my %choices = &Apache::lonlocal::texthash (
4107: run => 'Auto-update active?',
4108: classlists => 'Update information in classlists?',
4109: unexpired => 'Skip updates for users without active or future roles?',
4110: lastactive => 'Skip updates for inactive users?',
4111: );
4112: my $itemcount = 0;
1.3 raeburn 4113: my $updateon = ' ';
4114: my $updateoff = ' checked="checked" ';
4115: if (ref($settings) eq 'HASH') {
4116: if ($settings->{'run'} eq '1') {
4117: $updateon = $updateoff;
4118: $updateoff = ' ';
4119: }
4120: }
1.385 raeburn 4121: $enable = '<tr class="LC_odd_row">'.
4122: '<td>'.$choices{'run'}.'</td>'.
4123: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 4124: '<input type="radio" name="autoupdate_run"'.
1.397 raeburn 4125: $updateoff.'value="0" />'.&mt('No').'</label> '.
1.8 raeburn 4126: '<label><input type="radio" name="autoupdate_run"'.
1.385 raeburn 4127: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 4128: '</tr>';
1.385 raeburn 4129: my @toggles = ('classlists','unexpired');
4130: my %defaultchecked = ('classlists' => 'off',
4131: 'unexpired' => 'off'
4132: );
4133: $$rowtotal ++;
4134: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4135: \%choices,$itemcount,'','','left','no');
4136: $datatable = $enable.$datatable;
4137: $$rowtotal += $itemcount;
4138: my $lastactiveon = ' ';
4139: my $lastactiveoff = ' checked="checked" ';
4140: my $lastactivestyle = 'none';
4141: my $lastactivedays;
4142: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
4143: if (ref($settings) eq 'HASH') {
4144: if ($settings->{'lastactive'} =~ /^\d+$/) {
4145: $lastactiveon = $lastactiveoff;
4146: $lastactiveoff = ' ';
4147: $lastactivestyle = 'inline-block';
4148: $lastactivedays = $settings->{'lastactive'};
4149: }
4150: }
4151: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4152: $datatable .= '<tr'.$css_class.'>'.
4153: '<td>'.$choices{'lastactive'}.'</td>'.
4154: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
4155: '<input type="radio" name="lastactive"'.
4156: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
4157: ' <label>'.
4158: '<input type="radio" name="lastactive"'.
4159: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
4160: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
4161: ': '.&mt('inactive = no activity in last [_1] days',
4162: '<input type="text" size="5" name="lastactivedays" value="'.
4163: $lastactivedays.'" />').
4164: '</span></td>'.
4165: '</tr>';
4166: $$rowtotal ++;
1.131 raeburn 4167: } elsif ($position eq 'middle') {
4168: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4169: my $numinrow = 3;
4170: my $locknamesettings;
4171: $datatable .= &insttypes_row($settings,$types,$usertypes,
4172: $dom,$numinrow,$othertitle,
1.305 raeburn 4173: 'lockablenames',$rowtotal);
1.131 raeburn 4174: $$rowtotal ++;
1.3 raeburn 4175: } else {
1.44 raeburn 4176: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 4177: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 4178: 'permanentemail','id');
1.33 raeburn 4179: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 4180: my $numrows = 0;
1.26 raeburn 4181: if (ref($types) eq 'ARRAY') {
4182: if (@{$types} > 0) {
4183: $datatable =
4184: &usertype_update_row($settings,$usertypes,\%fieldtitles,
4185: \@fields,$types,\$numrows);
1.30 raeburn 4186: $$rowtotal += @{$types};
1.26 raeburn 4187: }
1.3 raeburn 4188: }
4189: $datatable .=
4190: &usertype_update_row($settings,{'default' => $othertitle},
4191: \%fieldtitles,\@fields,['default'],
4192: \$numrows);
1.30 raeburn 4193: $$rowtotal ++;
1.3 raeburn 4194: }
4195: return $datatable;
4196: }
4197:
1.125 raeburn 4198: sub print_autocreate {
4199: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 4200: my (%createon,%createoff,%currhash);
1.125 raeburn 4201: my @types = ('xml','req');
4202: if (ref($settings) eq 'HASH') {
4203: foreach my $item (@types) {
4204: $createoff{$item} = ' checked="checked" ';
4205: $createon{$item} = ' ';
4206: if (exists($settings->{$item})) {
4207: if ($settings->{$item}) {
4208: $createon{$item} = ' checked="checked" ';
4209: $createoff{$item} = ' ';
4210: }
4211: }
4212: }
1.210 raeburn 4213: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 4214: $currhash{$settings->{'xmldc'}} = 1;
4215: }
1.125 raeburn 4216: } else {
4217: foreach my $item (@types) {
4218: $createoff{$item} = ' checked="checked" ';
4219: $createon{$item} = ' ';
4220: }
4221: }
4222: $$rowtotal += 2;
1.191 raeburn 4223: my $numinrow = 2;
1.125 raeburn 4224: my $datatable='<tr class="LC_odd_row">'.
4225: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
4226: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4227: '<input type="radio" name="autocreate_xml"'.
4228: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
4229: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 4230: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
4231: '</td></tr><tr>'.
4232: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
4233: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4234: '<input type="radio" name="autocreate_req"'.
4235: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
4236: '<label><input type="radio" name="autocreate_req"'.
4237: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 4238: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4239: 'autocreate_xmldc',%currhash);
1.247 raeburn 4240: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 4241: if ($numdc > 1) {
1.247 raeburn 4242: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
4243: '</td><td class="LC_left_item">';
1.125 raeburn 4244: } else {
1.247 raeburn 4245: $datatable .= &mt('Course creation processed as:').
4246: '</td><td class="LC_right_item">';
1.125 raeburn 4247: }
1.247 raeburn 4248: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 4249: $$rowtotal += $rows;
1.125 raeburn 4250: return $datatable;
4251: }
4252:
1.23 raeburn 4253: sub print_directorysrch {
1.277 raeburn 4254: my ($position,$dom,$settings,$rowtotal) = @_;
4255: my $datatable;
4256: if ($position eq 'top') {
4257: my $instsrchon = ' ';
4258: my $instsrchoff = ' checked="checked" ';
4259: my ($exacton,$containson,$beginson);
4260: my $instlocalon = ' ';
4261: my $instlocaloff = ' checked="checked" ';
4262: if (ref($settings) eq 'HASH') {
4263: if ($settings->{'available'} eq '1') {
4264: $instsrchon = $instsrchoff;
4265: $instsrchoff = ' ';
4266: }
4267: if ($settings->{'localonly'} eq '1') {
4268: $instlocalon = $instlocaloff;
4269: $instlocaloff = ' ';
4270: }
4271: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
4272: foreach my $type (@{$settings->{'searchtypes'}}) {
4273: if ($type eq 'exact') {
4274: $exacton = ' checked="checked" ';
4275: } elsif ($type eq 'contains') {
4276: $containson = ' checked="checked" ';
4277: } elsif ($type eq 'begins') {
4278: $beginson = ' checked="checked" ';
4279: }
4280: }
4281: } else {
4282: if ($settings->{'searchtypes'} eq 'exact') {
4283: $exacton = ' checked="checked" ';
4284: } elsif ($settings->{'searchtypes'} eq 'contains') {
4285: $containson = ' checked="checked" ';
4286: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 4287: $exacton = ' checked="checked" ';
4288: $containson = ' checked="checked" ';
4289: }
4290: }
1.277 raeburn 4291: }
4292: my ($searchtitles,$titleorder) = &sorted_searchtitles();
4293: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4294:
4295: my $numinrow = 4;
4296: my $cansrchrow = 0;
4297: $datatable='<tr class="LC_odd_row">'.
4298: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
4299: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4300: '<input type="radio" name="dirsrch_available"'.
4301: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
4302: '<label><input type="radio" name="dirsrch_available"'.
4303: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4304: '</tr><tr>'.
4305: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
4306: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4307: '<input type="radio" name="dirsrch_instlocalonly"'.
4308: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4309: '<label><input type="radio" name="dirsrch_instlocalonly"'.
4310: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4311: '</tr>';
4312: $$rowtotal += 2;
4313: if (ref($usertypes) eq 'HASH') {
4314: if (keys(%{$usertypes}) > 0) {
4315: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 4316: $numinrow,$othertitle,'cansearch',
4317: $rowtotal);
1.277 raeburn 4318: $cansrchrow = 1;
1.25 raeburn 4319: }
1.23 raeburn 4320: }
1.277 raeburn 4321: if ($cansrchrow) {
4322: $$rowtotal ++;
4323: $datatable .= '<tr>';
4324: } else {
4325: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 4326: }
1.277 raeburn 4327: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
4328: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
4329: foreach my $title (@{$titleorder}) {
4330: if (defined($searchtitles->{$title})) {
4331: my $check = ' ';
4332: if (ref($settings) eq 'HASH') {
4333: if (ref($settings->{'searchby'}) eq 'ARRAY') {
4334: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
4335: $check = ' checked="checked" ';
4336: }
1.39 raeburn 4337: }
1.25 raeburn 4338: }
1.277 raeburn 4339: $datatable .= '<td class="LC_left_item">'.
4340: '<span class="LC_nobreak"><label>'.
4341: '<input type="checkbox" name="searchby" '.
4342: 'value="'.$title.'"'.$check.'/>'.
4343: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 4344: }
4345: }
1.277 raeburn 4346: $datatable .= '</tr></table></td></tr>';
4347: $$rowtotal ++;
4348: if ($cansrchrow) {
4349: $datatable .= '<tr class="LC_odd_row">';
4350: } else {
4351: $datatable .= '<tr>';
4352: }
4353: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
4354: '<td class="LC_left_item" colspan="2">'.
4355: '<span class="LC_nobreak"><label>'.
4356: '<input type="checkbox" name="searchtypes" '.
4357: $exacton.' value="exact" />'.&mt('Exact match').
4358: '</label> '.
4359: '<label><input type="checkbox" name="searchtypes" '.
4360: $beginson.' value="begins" />'.&mt('Begins with').
4361: '</label> '.
4362: '<label><input type="checkbox" name="searchtypes" '.
4363: $containson.' value="contains" />'.&mt('Contains').
4364: '</label></span></td></tr>';
4365: $$rowtotal ++;
1.26 raeburn 4366: } else {
1.277 raeburn 4367: my $domsrchon = ' checked="checked" ';
4368: my $domsrchoff = ' ';
4369: my $domlocalon = ' ';
4370: my $domlocaloff = ' checked="checked" ';
4371: if (ref($settings) eq 'HASH') {
4372: if ($settings->{'lclocalonly'} eq '1') {
4373: $domlocalon = $domlocaloff;
4374: $domlocaloff = ' ';
4375: }
4376: if ($settings->{'lcavailable'} eq '0') {
4377: $domsrchoff = $domsrchon;
4378: $domsrchon = ' ';
4379: }
4380: }
4381: $datatable='<tr class="LC_odd_row">'.
4382: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
4383: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4384: '<input type="radio" name="dirsrch_domavailable"'.
4385: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
4386: '<label><input type="radio" name="dirsrch_domavailable"'.
4387: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4388: '</tr><tr>'.
4389: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
4390: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4391: '<input type="radio" name="dirsrch_domlocalonly"'.
4392: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4393: '<label><input type="radio" name="dirsrch_domlocalonly"'.
4394: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4395: '</tr>';
4396: $$rowtotal += 2;
1.26 raeburn 4397: }
1.25 raeburn 4398: return $datatable;
4399: }
4400:
1.28 raeburn 4401: sub print_contacts {
1.286 raeburn 4402: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 4403: my $datatable;
4404: my @contacts = ('adminemail','supportemail');
1.286 raeburn 4405: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340 raeburn 4406: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286 raeburn 4407: if ($position eq 'top') {
4408: if (ref($settings) eq 'HASH') {
4409: foreach my $item (@contacts) {
4410: if (exists($settings->{$item})) {
4411: $to{$item} = $settings->{$item};
4412: }
4413: }
4414: }
4415: } elsif ($position eq 'middle') {
4416: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350 raeburn 4417: 'updatesmail','idconflictsmail','hostipmail');
1.288 raeburn 4418: foreach my $type (@mailings) {
4419: $otheremails{$type} = '';
4420: }
1.340 raeburn 4421: } elsif ($position eq 'lower') {
4422: if (ref($settings) eq 'HASH') {
4423: if (ref($settings->{'lonstatus'}) eq 'HASH') {
4424: %lonstatus = %{$settings->{'lonstatus'}};
4425: }
4426: }
1.286 raeburn 4427: } else {
4428: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 4429: foreach my $type (@mailings) {
4430: $otheremails{$type} = '';
4431: }
1.286 raeburn 4432: $bccemails{'helpdeskmail'} = '';
4433: $bccemails{'otherdomsmail'} = '';
4434: $includestr{'helpdeskmail'} = '';
4435: $includestr{'otherdomsmail'} = '';
4436: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
4437: }
1.28 raeburn 4438: if (ref($settings) eq 'HASH') {
1.340 raeburn 4439: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4440: foreach my $type (@mailings) {
4441: if (exists($settings->{$type})) {
4442: if (ref($settings->{$type}) eq 'HASH') {
4443: foreach my $item (@contacts) {
4444: if ($settings->{$type}{$item}) {
4445: $checked{$type}{$item} = ' checked="checked" ';
4446: }
4447: }
4448: $otheremails{$type} = $settings->{$type}{'others'};
4449: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4450: $bccemails{$type} = $settings->{$type}{'bcc'};
4451: if ($settings->{$type}{'include'} ne '') {
4452: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4453: $includestr{$type} = &unescape($includestr{$type});
4454: }
4455: }
4456: }
4457: } elsif ($type eq 'lonstatusmail') {
4458: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
4459: }
1.28 raeburn 4460: }
4461: }
1.286 raeburn 4462: if ($position eq 'bottom') {
4463: foreach my $type (@mailings) {
4464: $bccemails{$type} = $settings->{$type}{'bcc'};
4465: if ($settings->{$type}{'include'} ne '') {
4466: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4467: $includestr{$type} = &unescape($includestr{$type});
4468: }
4469: }
4470: if (ref($settings->{'helpform'}) eq 'HASH') {
4471: if (ref($fields) eq 'ARRAY') {
4472: foreach my $field (@{$fields}) {
4473: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 4474: }
1.286 raeburn 4475: }
4476: if (exists($settings->{'helpform'}{'maxsize'})) {
4477: $maxsize = $settings->{'helpform'}{'maxsize'};
4478: } else {
1.289 raeburn 4479: $maxsize = '1.0';
1.286 raeburn 4480: }
4481: } else {
4482: if (ref($fields) eq 'ARRAY') {
4483: foreach my $field (@{$fields}) {
4484: $currfield{$field} = 'yes';
1.134 raeburn 4485: }
1.28 raeburn 4486: }
1.286 raeburn 4487: $maxsize = '1.0';
1.28 raeburn 4488: }
4489: }
4490: } else {
1.286 raeburn 4491: if ($position eq 'top') {
4492: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
4493: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
4494: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
4495: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 4496: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4497: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
4498: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
4499: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350 raeburn 4500: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4501: } elsif ($position eq 'bottom') {
4502: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
4503: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
4504: if (ref($fields) eq 'ARRAY') {
4505: foreach my $field (@{$fields}) {
4506: $currfield{$field} = 'yes';
4507: }
4508: }
4509: $maxsize = '1.0';
4510: }
1.28 raeburn 4511: }
4512: my ($titles,$short_titles) = &contact_titles();
4513: my $rownum = 0;
4514: my $css_class;
1.286 raeburn 4515: if ($position eq 'top') {
4516: foreach my $item (@contacts) {
4517: $css_class = $rownum%2?' class="LC_odd_row"':'';
4518: $datatable .= '<tr'.$css_class.'>'.
4519: '<td><span class="LC_nobreak">'.$titles->{$item}.
4520: '</span></td><td class="LC_right_item">'.
4521: '<input type="text" name="'.$item.'" value="'.
4522: $to{$item}.'" /></td></tr>';
4523: $rownum ++;
4524: }
1.315 raeburn 4525: } elsif ($position eq 'bottom') {
4526: $css_class = $rownum%2?' class="LC_odd_row"':'';
4527: $datatable .= '<tr'.$css_class.'>'.
4528: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
4529: &mt('(e-mail, subject, and description always shown)').
4530: '</td><td class="LC_left_item">';
4531: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
4532: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
4533: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
4534: foreach my $field (@{$fields}) {
4535: $datatable .= '<tr><td>'.$fieldtitles->{$field};
4536: if (($field eq 'screenshot') || ($field eq 'cc')) {
4537: $datatable .= ' '.&mt('(logged-in users)');
4538: }
4539: $datatable .='</td><td>';
4540: my $clickaction;
4541: if ($field eq 'screenshot') {
4542: $clickaction = ' onclick="screenshotSize(this);"';
4543: }
4544: if (ref($possoptions->{$field}) eq 'ARRAY') {
4545: foreach my $option (@{$possoptions->{$field}}) {
4546: my $checked;
4547: if ($currfield{$field} eq $option) {
4548: $checked = ' checked="checked"';
4549: }
4550: $datatable .= '<span class="LC_nobreak"><label>'.
4551: '<input type="radio" name="helpform_'.$field.'" '.
4552: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
4553: '</label></span>'.(' 'x2);
4554: }
4555: }
4556: if ($field eq 'screenshot') {
4557: my $display;
4558: if ($currfield{$field} eq 'no') {
4559: $display = ' style="display:none"';
4560: }
1.334 raeburn 4561: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315 raeburn 4562: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
4563: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
4564: }
4565: $datatable .= '</td></tr>';
4566: }
4567: $datatable .= '</table>';
4568: }
4569: $datatable .= '</td></tr>'."\n";
4570: $rownum ++;
4571: }
1.340 raeburn 4572: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4573: foreach my $type (@mailings) {
4574: $css_class = $rownum%2?' class="LC_odd_row"':'';
4575: $datatable .= '<tr'.$css_class.'>'.
4576: '<td><span class="LC_nobreak">'.
4577: $titles->{$type}.': </span></td>'.
4578: '<td class="LC_left_item">';
4579: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4580: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
4581: }
4582: $datatable .= '<span class="LC_nobreak">';
4583: foreach my $item (@contacts) {
4584: $datatable .= '<label>'.
4585: '<input type="checkbox" name="'.$type.'"'.
4586: $checked{$type}{$item}.
4587: ' value="'.$item.'" />'.$short_titles->{$item}.
4588: '</label> ';
4589: }
4590: $datatable .= '</span><br />'.&mt('Others').': '.
4591: '<input type="text" name="'.$type.'_others" '.
4592: 'value="'.$otheremails{$type}.'" />';
4593: my %locchecked;
4594: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4595: foreach my $loc ('s','b') {
4596: if ($includeloc{$type} eq $loc) {
4597: $locchecked{$loc} = ' checked="checked"';
4598: last;
4599: }
4600: }
4601: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
4602: '<input type="text" name="'.$type.'_bcc" '.
4603: 'value="'.$bccemails{$type}.'" /></fieldset>'.
4604: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4605: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4606: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286 raeburn 4607: '<span class="LC_nobreak">'.&mt('Location:').' '.
4608: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4609: (' 'x2).
4610: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4611: '</span></fieldset>';
4612: }
4613: $datatable .= '</td></tr>'."\n";
4614: $rownum ++;
4615: }
1.28 raeburn 4616: }
1.286 raeburn 4617: if ($position eq 'middle') {
4618: my %choices;
1.340 raeburn 4619: my $corelink = &core_link_msu();
4620: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286 raeburn 4621: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340 raeburn 4622: $corelink);
4623: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
4624: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286 raeburn 4625: my %defaultchecked = ('reporterrors' => 'on',
1.340 raeburn 4626: 'reportupdates' => 'on',
4627: 'reportstatus' => 'on');
1.286 raeburn 4628: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4629: \%choices,$rownum);
4630: $datatable .= $reports;
1.340 raeburn 4631: } elsif ($position eq 'lower') {
1.378 raeburn 4632: my (%current,%excluded,%weights);
1.340 raeburn 4633: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
4634: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.378 raeburn 4635: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.340 raeburn 4636: } else {
1.378 raeburn 4637: $current{'errorthreshold'} = $defaults->{'threshold'};
1.340 raeburn 4638: }
4639: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.378 raeburn 4640: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.340 raeburn 4641: } else {
1.378 raeburn 4642: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.340 raeburn 4643: }
4644: if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341 raeburn 4645: foreach my $type ('E','W','N','U') {
1.340 raeburn 4646: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
4647: $weights{$type} = $lonstatus{'weights'}{$type};
4648: } else {
4649: $weights{$type} = $defaults->{$type};
4650: }
4651: }
4652: } else {
1.341 raeburn 4653: foreach my $type ('E','W','N','U') {
1.340 raeburn 4654: $weights{$type} = $defaults->{$type};
4655: }
4656: }
4657: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
4658: if (@{$lonstatus{'excluded'}} > 0) {
4659: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
4660: }
4661: }
1.425 raeburn 4662: foreach my $item ('errorthreshold','errorsysmail') {
1.378 raeburn 4663: $css_class = $rownum%2?' class="LC_odd_row"':'';
4664: $datatable .= '<tr'.$css_class.'>'.
4665: '<td class="LC_left_item"><span class="LC_nobreak">'.
4666: $titles->{$item}.
4667: '</span></td><td class="LC_left_item">'.
4668: '<input type="text" name="'.$item.'" value="'.
4669: $current{$item}.'" size="5" /></td></tr>';
4670: $rownum ++;
4671: }
1.340 raeburn 4672: $css_class = $rownum%2?' class="LC_odd_row"':'';
4673: $datatable .= '<tr'.$css_class.'>'.
4674: '<td class="LC_left_item">'.
4675: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
4676: '</span></td><td class="LC_left_item"><table><tr>';
1.341 raeburn 4677: foreach my $type ('E','W','N','U') {
1.340 raeburn 4678: $datatable .= '<td>'.$names->{$type}.'<br />'.
4679: '<input type="text" name="errorweights_'.$type.'" value="'.
4680: $weights{$type}.'" size="5" /></td>';
4681: }
4682: $datatable .= '</tr></table></tr>';
4683: $rownum ++;
4684: $css_class = $rownum%2?' class="LC_odd_row"':'';
4685: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
4686: $titles->{'errorexcluded'}.'</td>'.
4687: '<td class="LC_left_item"><table>';
4688: my $numinrow = 4;
4689: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
4690: for (my $i=0; $i<@ids; $i++) {
4691: my $rem = $i%($numinrow);
4692: if ($rem == 0) {
4693: if ($i > 0) {
4694: $datatable .= '</tr>';
4695: }
4696: $datatable .= '<tr>';
4697: }
4698: my $check;
4699: if ($excluded{$ids[$i]}) {
4700: $check = ' checked="checked" ';
4701: }
4702: $datatable .= '<td class="LC_left_item">'.
4703: '<span class="LC_nobreak"><label>'.
4704: '<input type="checkbox" name="errorexcluded" '.
4705: 'value="'.$ids[$i].'"'.$check.' />'.
4706: $ids[$i].'</label></span></td>';
4707: }
4708: my $colsleft = $numinrow - @ids%($numinrow);
4709: if ($colsleft > 1 ) {
4710: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4711: ' </td>';
4712: } elsif ($colsleft == 1) {
4713: $datatable .= '<td class="LC_left_item"> </td>';
4714: }
4715: $datatable .= '</tr></table></td></tr>';
4716: $rownum ++;
1.286 raeburn 4717: } elsif ($position eq 'bottom') {
1.315 raeburn 4718: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4719: my (@posstypes,%usertypeshash);
4720: if (ref($types) eq 'ARRAY') {
4721: @posstypes = @{$types};
4722: }
4723: if (@posstypes) {
4724: if (ref($usertypes) eq 'HASH') {
4725: %usertypeshash = %{$usertypes};
4726: }
4727: my @overridden;
4728: my $numinrow = 4;
4729: if (ref($settings) eq 'HASH') {
4730: if (ref($settings->{'overrides'}) eq 'HASH') {
4731: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
4732: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
4733: push(@overridden,$key);
4734: foreach my $item (@contacts) {
4735: if ($settings->{'overrides'}{$key}{$item}) {
4736: $checked{'override_'.$key}{$item} = ' checked="checked" ';
4737: }
4738: }
4739: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
4740: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
4741: $includeloc{'override_'.$key} = '';
4742: $includestr{'override_'.$key} = '';
4743: if ($settings->{'overrides'}{$key}{'include'} ne '') {
1.425 raeburn 4744: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
1.315 raeburn 4745: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
4746: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
4747: }
1.286 raeburn 4748: }
4749: }
4750: }
1.315 raeburn 4751: }
4752: my $customclass = 'LC_helpdesk_override';
4753: my $optionsprefix = 'LC_options_helpdesk_';
4754:
4755: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
4756: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
4757: $numinrow,$othertitle,'overrides',
4758: \$rownum,$onclicktypes,$customclass);
4759: $rownum ++;
4760: $usertypeshash{'default'} = $othertitle;
4761: foreach my $status (@posstypes) {
4762: my $css_class;
4763: if ($rownum%2) {
4764: $css_class = 'LC_odd_row ';
4765: }
4766: $css_class .= $customclass;
4767: my $rowid = $optionsprefix.$status;
4768: my $hidden = 1;
4769: my $currstyle = 'display:none';
4770: if (grep(/^\Q$status\E$/,@overridden)) {
4771: $currstyle = 'display:table-row';
4772: $hidden = 0;
4773: }
4774: my $key = 'override_'.$status;
4775: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
4776: $includeloc{$key},$includestr{$key},$status,$rowid,
4777: $usertypeshash{$status},$css_class,$currstyle,
4778: \@contacts,$short_titles);
4779: unless ($hidden) {
4780: $rownum ++;
1.286 raeburn 4781: }
4782: }
1.134 raeburn 4783: }
1.28 raeburn 4784: }
1.30 raeburn 4785: $$rowtotal += $rownum;
1.28 raeburn 4786: return $datatable;
4787: }
4788:
1.340 raeburn 4789: sub core_link_msu {
4790: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
4791: &mt('LON-CAPA core group - MSU'),600,500);
4792: }
4793:
1.315 raeburn 4794: sub overridden_helpdesk {
4795: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
4796: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
4797: my $class = 'LC_left_item';
4798: if ($css_class) {
4799: $css_class = ' class="'.$css_class.'"';
4800: }
4801: if ($rowid) {
4802: $rowid = ' id="'.$rowid.'"';
4803: }
4804: if ($rowstyle) {
4805: $rowstyle = ' style="'.$rowstyle.'"';
4806: }
4807: my ($output,$description);
4808: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
4809: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
4810: "<td>$description</td>\n".
4811: '<td class="'.$class.'" colspan="2">'.
4812: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
4813: '<span class="LC_nobreak">';
4814: if (ref($contacts) eq 'ARRAY') {
4815: foreach my $item (@{$contacts}) {
4816: my $check;
4817: if (ref($checked) eq 'HASH') {
4818: $check = $checked->{$item};
4819: }
4820: my $title;
4821: if (ref($short_titles) eq 'HASH') {
1.425 raeburn 4822: $title = $short_titles->{$item};
1.315 raeburn 4823: }
4824: $output .= '<label>'.
4825: '<input type="checkbox" name="override_'.$type.'"'.$check.
4826: ' value="'.$item.'" />'.$title.'</label> ';
4827: }
4828: }
4829: $output .= '</span><br />'.&mt('Others').': '.
4830: '<input type="text" name="override_'.$type.'_others" '.
4831: 'value="'.$otheremails.'" />';
4832: my %locchecked;
4833: foreach my $loc ('s','b') {
4834: if ($includeloc eq $loc) {
4835: $locchecked{$loc} = ' checked="checked"';
4836: last;
4837: }
4838: }
4839: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4840: '<input type="text" name="override_'.$type.'_bcc" '.
4841: 'value="'.$bccemails.'" /></fieldset>'.
4842: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4843: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4844: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315 raeburn 4845: '<span class="LC_nobreak">'.&mt('Location:').' '.
4846: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4847: (' 'x2).
4848: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4849: '</span></fieldset>'.
4850: '</td></tr>'."\n";
4851: return $output;
4852: }
4853:
1.286 raeburn 4854: sub contacts_javascript {
4855: return <<"ENDSCRIPT";
4856:
4857: <script type="text/javascript">
4858: // <![CDATA[
4859:
4860: function screenshotSize(field) {
4861: if (document.getElementById('help_screenshotsize')) {
4862: if (field.value == 'no') {
1.289 raeburn 4863: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 4864: } else {
4865: document.getElementById('help_screenshotsize').style.display="";
4866: }
4867: }
4868: return;
4869: }
4870:
1.315 raeburn 4871: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4872: if (form.elements[checkbox].length != undefined) {
4873: var count = 0;
4874: if (docount) {
4875: for (var i=0; i<form.elements[checkbox].length; i++) {
4876: if (form.elements[checkbox][i].checked) {
4877: count ++;
4878: }
4879: }
4880: }
4881: for (var i=0; i<form.elements[checkbox].length; i++) {
4882: var type = form.elements[checkbox][i].value;
4883: if (document.getElementById(prefix+type)) {
4884: if (form.elements[checkbox][i].checked) {
4885: document.getElementById(prefix+type).style.display = 'table-row';
4886: if (count % 2 == 1) {
4887: document.getElementById(prefix+type).className = target+' LC_odd_row';
4888: } else {
4889: document.getElementById(prefix+type).className = target;
4890: }
4891: count ++;
4892: } else {
4893: document.getElementById(prefix+type).style.display = 'none';
4894: }
4895: }
4896: }
4897: }
4898: return;
4899: }
4900:
1.286 raeburn 4901: // ]]>
4902: </script>
4903:
4904: ENDSCRIPT
4905: }
4906:
1.118 jms 4907: sub print_helpsettings {
1.282 raeburn 4908: my ($position,$dom,$settings,$rowtotal) = @_;
4909: my $confname = $dom.'-domainconfig';
1.285 raeburn 4910: my $formname = 'display';
1.168 raeburn 4911: my ($datatable,$itemcount);
1.282 raeburn 4912: if ($position eq 'top') {
4913: $itemcount = 1;
4914: my (%choices,%defaultchecked,@toggles);
4915: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4916: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4917: &mt('LON-CAPA bug tracker'),600,500));
4918: %defaultchecked = ('submitbugs' => 'on');
4919: @toggles = ('submitbugs');
4920: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4921: \%choices,$itemcount);
4922: $$rowtotal ++;
4923: } else {
4924: my $css_class;
4925: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 4926: my (%customroles,%ordered,%current);
1.301 raeburn 4927: if (ref($settings) eq 'HASH') {
4928: if (ref($settings->{'adhoc'}) eq 'HASH') {
4929: %current = %{$settings->{'adhoc'}};
4930: }
1.285 raeburn 4931: }
4932: my $count = 0;
4933: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 4934: if ($key=~/^rolesdef\_(\w+)$/) {
4935: my $rolename = $1;
1.285 raeburn 4936: my (%privs,$order);
1.282 raeburn 4937: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4938: $customroles{$rolename} = \%privs;
1.285 raeburn 4939: if (ref($current{$rolename}) eq 'HASH') {
4940: $order = $current{$rolename}{'order'};
4941: }
4942: if ($order eq '') {
4943: $order = $count;
4944: }
4945: $ordered{$order} = $rolename;
4946: $count++;
4947: }
4948: }
4949: my $maxnum = scalar(keys(%ordered));
4950: my @roles_by_num = ();
4951: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4952: push(@roles_by_num,$item);
4953: }
4954: my $context = 'domprefs';
4955: my $crstype = 'Course';
4956: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 4957: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 4958: my ($numstatustypes,@jsarray);
4959: if (ref($types) eq 'ARRAY') {
4960: if (@{$types} > 0) {
4961: $numstatustypes = scalar(@{$types});
4962: push(@accesstypes,'status');
4963: @jsarray = ('bystatus');
1.282 raeburn 4964: }
4965: }
1.290 raeburn 4966: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 4967: if (keys(%domhelpdesk)) {
4968: push(@accesstypes,('inc','exc'));
4969: push(@jsarray,('notinc','notexc'));
4970: }
4971: my $hiddenstr = join("','",@jsarray);
1.282 raeburn 4972: my $context = 'domprefs';
4973: my $crstype = 'Course';
1.285 raeburn 4974: my $prefix = 'helproles_';
4975: my $add_class = 'LC_hidden';
4976: foreach my $num (@roles_by_num) {
4977: my $role = $ordered{$num};
4978: my ($desc,$access,@statuses);
4979: if (ref($current{$role}) eq 'HASH') {
4980: $desc = $current{$role}{'desc'};
4981: $access = $current{$role}{'access'};
4982: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4983: @statuses = @{$current{$role}{'insttypes'}};
4984: }
4985: }
4986: if ($desc eq '') {
4987: $desc = $role;
4988: }
4989: my $identifier = 'custhelp'.$num;
1.282 raeburn 4990: my %full=();
4991: my %levels= (
4992: course => {},
4993: domain => {},
4994: system => {},
4995: );
4996: my %levelscurrent=(
4997: course => {},
4998: domain => {},
4999: system => {},
5000: );
5001: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
5002: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
5003: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 5004: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 5005: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 5006: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
5007: for (my $k=0; $k<=$maxnum; $k++) {
5008: my $vpos = $k+1;
5009: my $selstr;
5010: if ($k == $num) {
5011: $selstr = ' selected="selected" ';
5012: }
5013: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5014: }
5015: $datatable .= '</select>'.(' 'x2).
5016: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
5017: '</td>'.
5018: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
5019: &mt('Name shown to users:').
5020: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
5021: '</fieldset>'.
5022: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
5023: $othertitle,$usertypes,$types,\%domhelpdesk).
5024: '<fieldset>'.
5025: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 5026: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 5027: \%levelscurrent,$identifier,
5028: 'LC_hidden',$prefix.$num.'_privs').
5029: '</fieldset></td>';
1.282 raeburn 5030: $itemcount ++;
5031: }
5032: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5033: my $newcust = 'custhelp'.$count;
5034: my (%privs,%levelscurrent);
5035: my %full=();
5036: my %levels= (
5037: course => {},
5038: domain => {},
5039: system => {},
5040: );
5041: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
5042: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 5043: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 5044: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 5045: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
5046: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
5047: for (my $k=0; $k<$maxnum+1; $k++) {
5048: my $vpos = $k+1;
5049: my $selstr;
5050: if ($k == $maxnum) {
5051: $selstr = ' selected="selected" ';
5052: }
5053: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5054: }
5055: $datatable .= '</select> '."\n".
1.282 raeburn 5056: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
5057: '</label></span></td>'.
1.285 raeburn 5058: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
5059: '<span class="LC_nobreak">'.
5060: &mt('Internal name:').
5061: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
5062: '</span>'.(' 'x4).
5063: '<span class="LC_nobreak">'.
5064: &mt('Name shown to users:').
5065: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
5066: '</span></fieldset>'.
5067: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
5068: $usertypes,$types,\%domhelpdesk).
5069: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 5070: &Apache::lonuserutils::custom_role_header($context,$crstype,
5071: \@templateroles,$newcust).
5072: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
5073: \%levelscurrent,$newcust).
1.334 raeburn 5074: '</fieldset>'.
5075: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
5076: '</td></tr>';
1.282 raeburn 5077: $count ++;
5078: $$rowtotal += $count;
5079: }
1.166 raeburn 5080: return $datatable;
1.121 raeburn 5081: }
5082:
1.285 raeburn 5083: sub adhocbutton {
5084: my ($prefix,$num,$field,$visibility) = @_;
5085: my %lt = &Apache::lonlocal::texthash(
5086: show => 'Show details',
5087: hide => 'Hide details',
5088: );
5089: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
5090: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
5091: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
5092: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
5093: }
5094:
5095: sub helpsettings_javascript {
5096: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
5097: return unless(ref($roles_by_num) eq 'ARRAY');
5098: my %html_js_lt = &Apache::lonlocal::texthash(
5099: show => 'Show details',
5100: hide => 'Hide details',
5101: );
5102: &html_escape(\%html_js_lt);
5103: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
5104: return <<"ENDSCRIPT";
5105: <script type="text/javascript">
5106: // <![CDATA[
5107:
5108: function reorderHelpRoles(form,item) {
5109: var changedVal;
5110: $jstext
5111: var newpos = 'helproles_${total}_pos';
5112: var maxh = 1 + $total;
5113: var current = new Array();
5114: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5115: if (item == newpos) {
5116: changedVal = newitemVal;
5117: } else {
5118: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5119: current[newitemVal] = newpos;
5120: }
5121: for (var i=0; i<helproles.length; i++) {
5122: var elementName = 'helproles_'+helproles[i]+'_pos';
5123: if (elementName != item) {
5124: if (form.elements[elementName]) {
5125: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5126: current[currVal] = elementName;
5127: }
5128: }
5129: }
5130: var oldVal;
5131: for (var j=0; j<maxh; j++) {
5132: if (current[j] == undefined) {
5133: oldVal = j;
5134: }
5135: }
5136: if (oldVal < changedVal) {
5137: for (var k=oldVal+1; k<=changedVal ; k++) {
5138: var elementName = current[k];
5139: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5140: }
5141: } else {
5142: for (var k=changedVal; k<oldVal; k++) {
5143: var elementName = current[k];
5144: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5145: }
5146: }
5147: return;
5148: }
5149:
5150: function helpdeskAccess(num) {
5151: var curraccess = null;
5152: if (document.$formname.elements['helproles_'+num+'_access'].length) {
5153: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
5154: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
5155: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
5156: }
5157: }
5158: }
5159: var shown = Array();
5160: var hidden = Array();
5161: if (curraccess == 'none') {
5162: hidden = Array('$hiddenstr');
5163: } else {
5164: if (curraccess == 'status') {
5165: shown = Array('bystatus');
5166: hidden = Array('notinc','notexc');
5167: } else {
5168: if (curraccess == 'exc') {
5169: shown = Array('notexc');
5170: hidden = Array('notinc','bystatus');
5171: }
5172: if (curraccess == 'inc') {
5173: shown = Array('notinc');
5174: hidden = Array('notexc','bystatus');
5175: }
1.293 raeburn 5176: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 5177: hidden = Array('notinc','notexc','bystatus');
5178: }
5179: }
5180: }
5181: if (hidden.length > 0) {
5182: for (var i=0; i<hidden.length; i++) {
5183: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
5184: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
5185: }
5186: }
5187: }
5188: if (shown.length > 0) {
5189: for (var i=0; i<shown.length; i++) {
5190: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
5191: if (shown[i] == 'privs') {
5192: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
5193: } else {
5194: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
5195: }
5196: }
5197: }
5198: }
5199: return;
5200: }
5201:
5202: function toggleHelpdeskItem(num,field) {
5203: if (document.getElementById('helproles_'+num+'_'+field)) {
5204: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 5205: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 5206: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
5207: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5208: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
5209: }
5210: } else {
5211: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
5212: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5213: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
5214: }
5215: }
5216: }
5217: return;
5218: }
5219:
5220: // ]]>
5221: </script>
5222:
5223: ENDSCRIPT
5224: }
5225:
5226: sub helpdeskroles_access {
5227: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
5228: $usertypes,$types,$domhelpdesk) = @_;
5229: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
5230: my %lt = &Apache::lonlocal::texthash(
5231: 'rou' => 'Role usage',
5232: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 5233: 'all' => 'All with domain helpdesk or helpdesk assistant role',
5234: 'dh' => 'All with domain helpdesk role',
5235: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 5236: 'none' => 'None',
5237: 'status' => 'Determined based on institutional status',
5238: 'inc' => 'Include all, but exclude specific personnel',
5239: 'exc' => 'Exclude all, but include specific personnel',
5240: );
5241: my %usecheck = (
5242: all => ' checked="checked"',
5243: );
5244: my %displaydiv = (
5245: status => 'none',
5246: inc => 'none',
5247: exc => 'none',
5248: priv => 'block',
5249: );
5250: my $output;
5251: if (ref($current) eq 'HASH') {
5252: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
5253: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
5254: $usecheck{$current->{access}} = $usecheck{'all'};
5255: delete($usecheck{'all'});
5256: if ($current->{access} =~ /^(status|inc|exc)$/) {
5257: my $access = $1;
5258: $displaydiv{$access} = 'inline';
5259: } elsif ($current->{access} eq 'none') {
5260: $displaydiv{'priv'} = 'none';
5261: }
5262: }
5263: }
5264: }
5265: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
5266: '<p>'.$lt{'whi'}.'</p>';
5267: foreach my $access (@{$accesstypes}) {
5268: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
5269: ' onclick="helpdeskAccess('."'$num'".');" />'.
5270: $lt{$access}.'</label>';
5271: if ($access eq 'status') {
5272: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
5273: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
5274: $othertitle,$usertypes,$types).
5275: '</div>';
5276: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
5277: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
5278: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5279: '</div>';
5280: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
5281: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
5282: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5283: '</div>';
5284: }
5285: $output .= '</p>';
5286: }
5287: $output .= '</fieldset>';
5288: return $output;
5289: }
5290:
1.121 raeburn 5291: sub radiobutton_prefs {
1.192 raeburn 5292: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.385 raeburn 5293: $additional,$align,$firstval) = @_;
1.121 raeburn 5294: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
5295: (ref($choices) eq 'HASH'));
5296:
1.170 raeburn 5297: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 5298:
5299: foreach my $item (@{$toggles}) {
5300: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 5301: $checkedon{$item} = ' checked="checked" ';
5302: $checkedoff{$item} = ' ';
1.121 raeburn 5303: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 5304: $checkedoff{$item} = ' checked="checked" ';
5305: $checkedon{$item} = ' ';
5306: }
5307: }
5308: if (ref($settings) eq 'HASH') {
1.121 raeburn 5309: foreach my $item (@{$toggles}) {
1.118 jms 5310: if ($settings->{$item} eq '1') {
5311: $checkedon{$item} = ' checked="checked" ';
5312: $checkedoff{$item} = ' ';
5313: } elsif ($settings->{$item} eq '0') {
5314: $checkedoff{$item} = ' checked="checked" ';
5315: $checkedon{$item} = ' ';
5316: }
5317: }
1.121 raeburn 5318: }
1.192 raeburn 5319: if ($onclick) {
5320: $onclick = ' onclick="'.$onclick.'"';
5321: }
1.121 raeburn 5322: foreach my $item (@{$toggles}) {
1.118 jms 5323: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 5324: $datatable .=
1.306 raeburn 5325: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 5326: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 5327: '</span></td>';
5328: if ($align eq 'left') {
5329: $datatable .= '<td class="LC_left_item">';
5330: } else {
5331: $datatable .= '<td class="LC_right_item">';
5332: }
1.385 raeburn 5333: $datatable .= '<span class="LC_nobreak">';
5334: if ($firstval eq 'no') {
5335: $datatable .=
5336: '<label><input type="radio" name="'.
5337: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
5338: '</label> <label><input type="radio" name="'.$item.'" '.
5339: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
5340: } else {
5341: $datatable .=
5342: '<label><input type="radio" name="'.
5343: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
5344: '</label> <label><input type="radio" name="'.$item.'" '.
5345: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
5346: }
5347: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 5348: $itemcount ++;
1.121 raeburn 5349: }
5350: return ($datatable,$itemcount);
5351: }
5352:
1.267 raeburn 5353: sub print_ltitools {
1.421 raeburn 5354: my ($position,$dom,$settings,$rowtotal) = @_;
5355: my (%rules,%encrypt,%privkeys,%linkprot);
1.267 raeburn 5356: if (ref($settings) eq 'HASH') {
1.421 raeburn 5357: if ($position eq 'top') {
5358: if (exists($settings->{'encrypt'})) {
5359: if (ref($settings->{'encrypt'}) eq 'HASH') {
5360: foreach my $key (keys(%{$settings->{'encrypt'}})) {
5361: $encrypt{'toolsec_'.$key} = $settings->{'encrypt'}{$key};
1.324 raeburn 5362: }
5363: }
1.267 raeburn 5364: }
1.421 raeburn 5365: if (exists($settings->{'private'})) {
5366: if (ref($settings->{'private'}) eq 'HASH') {
5367: if (ref($settings->{'private'}) eq 'HASH') {
5368: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
5369: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
1.267 raeburn 5370: }
5371: }
5372: }
5373: }
1.421 raeburn 5374: } elsif ($position eq 'middle') {
5375: if (exists($settings->{'rules'})) {
5376: if (ref($settings->{'rules'}) eq 'HASH') {
5377: %rules = %{$settings->{'rules'}};
1.273 raeburn 5378: }
5379: }
1.421 raeburn 5380: } else {
5381: foreach my $key ('encrypt','private','rules') {
5382: if (exists($settings->{$key})) {
5383: delete($settings->{$key});
1.267 raeburn 5384: }
5385: }
5386: }
5387: }
1.421 raeburn 5388: my $datatable;
5389: my $itemcount = 1;
5390: if ($position eq 'top') {
5391: $datatable = &secrets_form($dom,'toolsec',\%encrypt,\%privkeys,$rowtotal);
5392: } elsif ($position eq 'middle') {
5393: $datatable = &password_rules('toolsecrets',\$itemcount,\%rules);
5394: $$rowtotal += $itemcount;
5395: } else {
5396: $datatable = &Apache::courseprefs::print_ltitools($dom,'',$settings,\$rowtotal,'','','domain');
1.267 raeburn 5397: }
5398: return $datatable;
5399: }
5400:
5401: sub ltitools_names {
5402: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 5403: 'title' => 'Title',
5404: 'version' => 'Version',
5405: 'msgtype' => 'Message Type',
1.323 raeburn 5406: 'sigmethod' => 'Signature Method',
1.296 raeburn 5407: 'url' => 'URL',
5408: 'key' => 'Key',
1.322 raeburn 5409: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 5410: 'secret' => 'Secret',
1.425 raeburn 5411: 'icon' => 'Icon',
1.324 raeburn 5412: 'user' => 'User',
1.296 raeburn 5413: 'fullname' => 'Full Name',
5414: 'firstname' => 'First Name',
5415: 'lastname' => 'Last Name',
5416: 'email' => 'E-mail',
5417: 'roles' => 'Role',
1.298 raeburn 5418: 'window' => 'Window',
5419: 'tab' => 'Tab',
1.296 raeburn 5420: 'iframe' => 'iFrame',
5421: 'height' => 'Height',
5422: 'width' => 'Width',
5423: 'linktext' => 'Default Link Text',
5424: 'explanation' => 'Default Explanation',
5425: 'passback' => 'Tool can return grades:',
5426: 'roster' => 'Tool can retrieve roster:',
5427: 'crstarget' => 'Display target',
5428: 'crslabel' => 'Course label',
1.425 raeburn 5429: 'crstitle' => 'Course title',
1.296 raeburn 5430: 'crslinktext' => 'Link Text',
5431: 'crsexplanation' => 'Explanation',
1.318 raeburn 5432: 'crsappend' => 'Provider URL',
1.267 raeburn 5433: );
5434: return %lt;
5435: }
5436:
1.421 raeburn 5437: sub secrets_form {
5438: my ($dom,$context,$encrypt,$privkeys,$rowtotal) = @_;
5439: my @ids=&Apache::lonnet::current_machine_ids();
5440: my %servers = &Apache::lonnet::get_servers($dom,'library');
5441: my $primary = &Apache::lonnet::domain($dom,'primary');
5442: my ($css_class,$extra,$numshown,$itemcount,$output);
5443: $itemcount = 0;
5444: foreach my $hostid (sort(keys(%servers))) {
5445: my ($showextra,$divsty,$switch);
5446: if ($hostid eq $primary) {
5447: if ($context eq 'ltisec') {
5448: if (($encrypt->{'ltisec_consumers'}) || ($encrypt->{'ltisec_domlinkprot'})) {
5449: $showextra = 1;
5450: }
5451: if ($encrypt->{'ltisec_crslinkprot'}) {
5452: $showextra = 1;
5453: }
5454: } else {
5455: if (($encrypt->{'toolsec_crs'}) || ($encrypt->{'toolsec_dom'})) {
5456: $showextra = 1;
5457: }
5458: }
5459: unless (grep(/^\Q$hostid\E$/,@ids)) {
5460: $switch = 1;
5461: }
5462: if ($showextra) {
5463: $numshown ++;
5464: $divsty = 'display:inline-block';
5465: } else {
5466: $divsty = 'display:none';
5467: }
5468: $extra .= '<fieldset id="'.$context.'_info_'.$hostid.'" style="'.$divsty.'">'.
5469: '<legend>'.$hostid.'</legend>';
5470: if ($switch) {
5471: my $switchserver = '<a href="/adm/switchserver?otherserver='.$hostid.'&role='.
5472: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
5473: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
5474: if (exists($privkeys->{$hostid})) {
5475: $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" />'.
5476: '<span class="LC_nobreak">'.
5477: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5478: '<span class="LC_nobreak">'.&mt('Change?').
5479: '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5480: (' 'x2).
5481: '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5482: '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5483: '<span class="LC_nobreak"> - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5484: '</span></div>';
5485: } else {
5486: $extra .= '<span class="LC_nobreak">'.
5487: &mt('Key required').' - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5488: '</span>'."\n";
5489: }
5490: } elsif (exists($privkeys->{$hostid})) {
5491: $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" /><span class="LC_nobreak">'.
5492: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5493: '<span class="LC_nobreak">'.&mt('Change?').
5494: '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5495: (' 'x2).
5496: '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5497: '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5498: '<span class="LC_nobreak">'.&mt('New Key').':'.
5499: '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5500: '<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>'.
5501: '</span></div>';
5502: } else {
5503: $extra .= '<span class="LC_nobreak">'.&mt('Encryption Key').':'.
5504: '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5505: '<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>';
5506: }
5507: $extra .= '</fieldset>';
5508: }
5509: }
5510: my (%choices,@toggles,%defaultchecked);
5511: if ($context eq 'ltisec') {
5512: %choices = &Apache::lonlocal::texthash (
5513: ltisec_crslinkprot => 'Encrypt stored link protection secrets defined in courses',
5514: ltisec_domlinkprot => 'Encrypt stored link protection secrets defined in domain',
5515: ltisec_consumers => 'Encrypt stored consumer secrets defined in domain',
5516: );
5517: @toggles = qw(ltisec_crslinkprot ltisec_domlinkprot ltisec_consumers);
5518: %defaultchecked = (
5519: 'ltisec_crslinkprot' => 'off',
5520: 'ltisec_domlinkprot' => 'off',
5521: 'ltisec_consumers' => 'off',
5522: );
5523: } else {
5524: %choices = &Apache::lonlocal::texthash (
5525: toolsec_crs => 'Encrypt stored external tool secrets defined in courses',
5526: toolsec_dom => 'Encrypt stored external tool secrets defined in domain',
5527: );
5528: @toggles = qw(toolsec_crs toolsec_dom);
5529: %defaultchecked = (
5530: 'toolsec_crs' => 'off',
5531: 'toolsec_dom' => 'off',
5532: );
5533: }
5534: my ($onclick,$itemcount);
5535: $onclick = 'javascript:toggleLTIEncKey(this.form,'."'$context'".');';
5536: ($output,$itemcount) = &radiobutton_prefs($encrypt,\@toggles,\%defaultchecked,
5537: \%choices,$itemcount,$onclick,'','left','no');
5538:
5539: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5540: my $noprivkeysty = 'display:inline-block';
5541: if ($numshown) {
5542: $noprivkeysty = 'display:none';
5543: }
5544: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.&mt('Encryption Key(s)').'</td>'.
5545: '<td><div id="'.$context.'_noprivkey" style="'.$noprivkeysty.'" >'.
5546: '<span class="LC_nobreak">'.&mt('Not in use').'</span></div>'.
5547: $extra.
5548: '</td></tr>';
5549: $itemcount ++;
5550: $$rowtotal += $itemcount;
5551: return $output;
5552: }
5553:
1.372 raeburn 5554: sub print_proctoring {
5555: my ($dom,$settings,$rowtotal) = @_;
5556: my $itemcount = 1;
5557: my (%ordered,%providernames,%current,%currentdef);
5558: my $confname = $dom.'-domainconfig';
5559: my $switchserver = &check_switchserver($dom,$confname);
5560: if (ref($settings) eq 'HASH') {
5561: foreach my $item (keys(%{$settings})) {
5562: if (ref($settings->{$item}) eq 'HASH') {
5563: my $num = $settings->{$item}{'order'};
5564: $ordered{$num} = $item;
5565: }
5566: }
5567: } else {
5568: %ordered = (
5569: 1 => 'proctorio',
5570: 2 => 'examity',
5571: );
5572: }
5573: %providernames = &proctoring_providernames();
5574: my $maxnum = scalar(keys(%ordered));
5575: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
5576: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
5577: if (ref($requref) eq 'HASH') {
5578: %requserfields = %{$requref};
5579: }
5580: if (ref($opturef) eq 'HASH') {
5581: %optuserfields = %{$opturef};
5582: }
5583: if (ref($defref) eq 'HASH') {
5584: %defaults = %{$defref};
5585: }
5586: if (ref($extref) eq 'HASH') {
5587: %extended = %{$extref};
5588: }
5589: if (ref($crsref) eq 'HASH') {
5590: %crsconf = %{$crsref};
5591: }
5592: if (ref($rolesref) eq 'ARRAY') {
5593: @courseroles = @{$rolesref};
5594: }
5595: if (ref($ltiref) eq 'ARRAY') {
5596: @ltiroles = @{$ltiref};
5597: }
5598: my $datatable;
5599: my $css_class;
5600: if (keys(%ordered)) {
5601: my @items = sort { $a <=> $b } keys(%ordered);
5602: for (my $i=0; $i<@items; $i++) {
5603: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5604: my $provider = $ordered{$items[$i]};
5605: my $optionsty = 'none';
5606: my ($available,$version,$lifetime,$imgsrc,$userincdom,$showroles,
5607: %checkedfields,%rolemaps,%inuse,%crsconfig,%current);
5608: if (ref($settings) eq 'HASH') {
5609: if (ref($settings->{$provider}) eq 'HASH') {
5610: %current = %{$settings->{$provider}};
5611: if ($current{'available'}) {
5612: $optionsty = 'block';
5613: $available = 1;
5614: }
5615: if ($current{'lifetime'} =~ /^\d+$/) {
5616: $lifetime = $current{'lifetime'};
5617: }
5618: if ($current{'version'} =~ /^\d+\.\d+$/) {
5619: $version = $current{'version'};
5620: }
5621: if ($current{'image'} ne '') {
5622: $imgsrc = '<img src="'.$current{'image'}.'" alt="'.&mt('Proctoring service icon').'" />';
5623: }
5624: if (ref($current{'fields'}) eq 'ARRAY') {
5625: map { $checkedfields{$_} = 1; } @{$current{'fields'}};
5626: }
5627: $userincdom = $current{'incdom'};
5628: if (ref($current{'roles'}) eq 'HASH') {
5629: %rolemaps = %{$current{'roles'}};
5630: $checkedfields{'roles'} = 1;
5631: }
5632: if (ref($current{'defaults'}) eq 'ARRAY') {
5633: foreach my $val (@{$current{'defaults'}}) {
5634: if (grep(/^\Q$val\E$/,@{$defaults{$provider}})) {
5635: $inuse{$val} = 1;
5636: } else {
5637: foreach my $poss (keys(%{$extended{$provider}})) {
5638: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5639: if (grep(/^\Q$val\E$/,@{$extended{$provider}{$poss}})) {
5640: $inuse{$poss} = $val;
5641: last;
5642: }
5643: }
5644: }
5645: }
5646: }
5647: } elsif (ref($current{'defaults'}) eq 'HASH') {
5648: foreach my $key (keys(%{$current{'defaults'}})) {
5649: my $currval = $current{'defaults'}{$key};
5650: if (grep(/^\Q$key\E$/,@{$defaults{$provider}})) {
5651: $inuse{$key} = 1;
5652: } else {
5653: my $match;
5654: foreach my $poss (keys(%{$extended{$provider}})) {
5655: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5656: if (grep(/^\Q$key\E$/,@{$extended{$provider}{$poss}})) {
5657: $inuse{$poss} = $key;
5658: last;
5659: }
5660: } elsif (ref($extended{$provider}{$poss}) eq 'HASH') {
5661: foreach my $inner (sort(keys(%{$extended{$provider}{$poss}}))) {
5662: if (ref($extended{$provider}{$poss}{$inner}) eq 'ARRAY') {
5663: if (grep(/^\Q$currval\E$/,@{$extended{$provider}{$poss}{$inner}})) {
5664: $currentdef{$inner} = $currval;
5665: $match = 1;
5666: last;
5667: }
5668: } elsif ($inner eq $key) {
5669: $currentdef{$key} = $currval;
5670: $match = 1;
5671: last;
5672: }
5673: }
5674: }
5675: last if ($match);
5676: }
5677: }
5678: }
5679: }
5680: if (ref($current{'crsconf'}) eq 'ARRAY') {
5681: map { $crsconfig{$_} = 1; } @{$current{'crsconf'}};
5682: }
5683: }
5684: }
5685: my %lt = &proctoring_titles($provider);
5686: my %fieldtitles = &proctoring_fieldtitles($provider);
5687: my $onclickavailable = ' onclick="toggleProctoring(this.form,'."'$provider'".');"';
5688: my %checkedavailable = (
5689: yes => '',
5690: no => ' checked="checked"',
5691: );
5692: if ($available) {
5693: $checkedavailable{'yes'} = $checkedavailable{'no'};
5694: $checkedavailable{'no'} = '';
5695: }
5696: my $chgstr = ' onchange="javascript:reorderProctoring(this.form,'."'proctoring_pos_".$provider."'".');"';
5697: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5698: .'<select name="proctoring_pos_'.$provider.'"'.$chgstr.'>';
5699: for (my $k=0; $k<$maxnum; $k++) {
5700: my $vpos = $k+1;
5701: my $selstr;
5702: if ($k == $i) {
5703: $selstr = ' selected="selected" ';
5704: }
5705: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5706: }
5707: if ($version eq '') {
5708: if ($provider eq 'proctorio') {
5709: $version = '1.0';
5710: } elsif ($provider eq 'examity') {
5711: $version = '1.1';
5712: }
5713: }
5714: if ($lifetime eq '') {
5715: $lifetime = '300';
5716: }
5717: $datatable .=
5718: '</select>'.(' 'x2).'<b>'.$providernames{$provider}.'</b></span><br />'.
5719: '<span class="LC_nobreak">'.$lt{'avai'}.' '.
5720: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="1"'.$onclickavailable.$checkedavailable{yes}.' />'.&mt('Yes').'</label> '."\n".
5721: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="0"'.$onclickavailable.$checkedavailable{no}.' />'.&mt('No').'</label></span>'."\n".
5722: '</td>'.
5723: '<td colspan="2">'.
5724: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'base'}.'</legend>'.
5725: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="proctoring_'.$provider.'_version">'.
5726: '<option value="'.$version.'" selected="selected">'.$version.'</option></select></span> '."\n".
5727: (' 'x2).
5728: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="proctoring_'.$provider.'_sigmethod">'.
5729: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5730: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
5731: (' 'x2).
5732: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="proctoring_'.$provider.'_lifetime" value="'.$lifetime.'" /></span> '."\n".
5733: '<br />'.
5734: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="proctoring_'.$provider.'_url" value="'.$current{'url'}.'" /></span> '."\n".
5735: '<br />'.
5736: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="proctoring_'.$provider.'_key" value="'.$current{'key'}.'" /></span> '."\n".
5737: (' 'x2).
5738: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="proctoring_'.$provider.'_secret" value="'.$current{'secret'}.'" />'.
5739: '<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";
5740: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
5741: if ($imgsrc) {
5742: $datatable .= $imgsrc.
5743: '<label><input type="checkbox" name="proctoring_image_del"'.
5744: ' value="'.$provider.'" />'.&mt('Delete?').'</label></span> '.
5745: '<span class="LC_nobreak"> '.&mt('Replace:');
5746: }
5747: $datatable .= ' ';
5748: if ($switchserver) {
5749: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5750: } else {
5751: $datatable .= '<input type="file" name="proctoring_image_'.$provider.'" value="" />';
5752: }
5753: unless ($imgsrc) {
5754: $datatable .= '<br />('.&mt('if larger than 21x21 pixels, image will be scaled').')';
5755: }
5756: $datatable .= '</fieldset>'."\n";
5757: if (ref($requserfields{$provider}) eq 'ARRAY') {
5758: if (@{$requserfields{$provider}} > 0) {
5759: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'requ'}.'</legend>';
5760: foreach my $field (@{$requserfields{$provider}}) {
5761: $datatable .= '<span class="LC_nobreak">'.
5762: '<label><input type="checkbox" name="proctoring_reqd_'.$provider.'" value="'.$field.'" checked="checked" disabled="disabled" />'.
5763: $lt{$field}.'</label>';
5764: if ($field eq 'user') {
5765: my $seluserdom = '';
5766: my $unseluserdom = ' selected="selected"';
5767: if ($userincdom) {
5768: $seluserdom = $unseluserdom;
5769: $unseluserdom = '';
5770: }
5771: $datatable .= ': '.
5772: '<select name="proctoring_userincdom_'.$provider.'">'.
5773: '<option value="0"'.$unseluserdom.'>'.$lt{'username'}.'</option>'.
5774: '<option value="1"'.$seluserdom.'>'.$lt{'uname:dom'}.'</option>'.
5775: '</select> ';
5776: } else {
5777: $datatable .= ' ';
5778: if ($field eq 'roles') {
5779: $showroles = 1;
5780: }
5781: }
5782: $datatable .= '</span> ';
5783: }
5784: }
5785: $datatable .= '</fieldset>'."\n";
5786: }
5787: if (ref($optuserfields{$provider}) eq 'ARRAY') {
5788: if (@{$optuserfields{$provider}} > 0) {
5789: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'optu'}.'</legend>';
5790: foreach my $field (@{$optuserfields{$provider}}) {
5791: my $checked;
5792: if ($checkedfields{$field}) {
5793: $checked = ' checked="checked"';
5794: }
5795: $datatable .= '<span class="LC_nobreak">'.
5796: '<label><input type="checkbox" name="proctoring_optional_'.$provider.'" value="'.$field.'"'.$checked.' />'.$lt{$field}.'</label></span> ';
5797: }
5798: $datatable .= '</fieldset>'."\n";
5799: }
5800: }
5801: if (ref($defaults{$provider}) eq 'ARRAY') {
5802: if (@{$defaults{$provider}}) {
5803: my (%options,@selectboxes);
5804: if (ref($extended{$provider}) eq 'HASH') {
5805: %options = %{$extended{$provider}};
5806: }
5807: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'defa'}.'</legend>';
5808: my ($rem,$numinrow,$dropdowns);
5809: if ($provider eq 'proctorio') {
5810: $datatable .= '<table>';
5811: $numinrow = 4;
5812: }
5813: my $i = 0;
5814: foreach my $field (@{$defaults{$provider}}) {
5815: my $checked;
5816: if ($inuse{$field}) {
5817: $checked = ' checked="checked"';
5818: }
5819: if ($provider eq 'examity') {
5820: if ($field eq 'display') {
5821: $datatable .= '<span class="LC_nobreak">'.&mt('Display target:');
5822: foreach my $option ('iframe','tab','window') {
5823: my $checkdisp;
5824: if ($currentdef{'target'} eq $option) {
5825: $checkdisp = ' checked="checked"';
5826: }
5827: $datatable .= '<label><input type="radio" name="proctoring_target_'.$provider.'" value="'.$option.'"'.$checkdisp.' />'.
5828: $fieldtitles{$option}.'</label>'.(' 'x2);
5829: }
5830: $datatable .= (' 'x4);
5831: foreach my $dimen ('width','height') {
5832: $datatable .= '<label>'.$fieldtitles{$dimen}.' '.
5833: '<input type="text" name="proctoring_'.$dimen.'_'.$provider.'" size="5" '.
5834: 'value="'.$currentdef{$dimen}.'" /></label>'.
5835: (' 'x2);
5836: }
5837: $datatable .= '</span><br />'.
5838: '<div class="LC_left_float">'.$fieldtitles{'linktext'}.'<br />'.
5839: '<input type="text" name="proctoring_linktext_'.$provider.'" '.
5840: 'size="25" value="'.$currentdef{'linktext'}.'" /></div>'.
5841: '<div class="LC_left_float">'.$fieldtitles{'explanation'}.'<br />'.
5842: '<textarea name="proctoring_explanation_'.$provider.'" rows="5" cols="40">'.
5843: $currentdef{'explanation'}.
5844: '</textarea></div><div style=""></div><br />';
5845: }
5846: } else {
5847: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
5848: my ($output,$selnone);
5849: unless ($checked) {
5850: $selnone = ' selected="selected"';
5851: }
5852: $output .= '<span class="LC_nobreak">'.$fieldtitles{$field}.': '.
5853: '<select name="proctoring_defaults_'.$field.'_'.$provider.'">'.
5854: '<option value=""'.$selnone.'>'.&mt('Not in use').'</option>';
5855: foreach my $option (@{$options{$field}}) {
5856: my $sel;
5857: if ($inuse{$field} eq $option) {
5858: $sel = ' selected="selected"';
5859: }
5860: $output .= '<option value="'.$option.'"'.$sel.'>'.$fieldtitles{$option}.'</option>';
5861: }
5862: $output .= '</select></span>';
5863: push(@selectboxes,$output);
5864: } else {
5865: $rem = $i%($numinrow);
5866: if ($rem == 0) {
5867: if ($i > 0) {
5868: $datatable .= '</tr>';
5869: }
5870: $datatable .= '<tr>';
5871: }
5872: $datatable .= '<td class="LC_left_item">'.
5873: '<span class="LC_nobreak">'.
5874: '<label><input type="checkbox" name="proctoring_defaults_'.$provider.'" value="'.$field.'"'.$checked.' />'.
5875: $fieldtitles{$field}.'</label></span></td>';
5876: $i++;
5877: }
5878: }
5879: }
5880: if ($provider eq 'proctorio') {
5881: if ($numinrow) {
5882: $rem = $i%$numinrow;
5883: }
5884: my $colsleft = $numinrow - $rem;
5885: if ($colsleft > 1) {
5886: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5887: } else {
5888: $datatable .= '<td class="LC_left_item">';
5889: }
5890: $datatable .= ' '.
5891: '</td></tr></table>';
5892: if (@selectboxes) {
5893: $datatable .= '<hr /><table>';
5894: $numinrow = 2;
5895: for (my $i=0; $i<@selectboxes; $i++) {
5896: $rem = $i%($numinrow);
5897: if ($rem == 0) {
5898: if ($i > 0) {
5899: $datatable .= '</tr>';
5900: }
5901: $datatable .= '<tr>';
5902: }
5903: $datatable .= '<td class="LC_left_item">'.
5904: $selectboxes[$i].'</td>';
5905: }
5906: if ($numinrow) {
5907: $rem = $i%$numinrow;
5908: }
5909: $colsleft = $numinrow - $rem;
5910: if ($colsleft > 1) {
5911: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5912: } else {
5913: $datatable .= '<td class="LC_left_item">';
5914: }
5915: $datatable .= ' '.
5916: '</td></tr></table>';
5917: }
5918: }
5919: $datatable .= '</fieldset>';
5920: }
5921: if (ref($crsconf{$provider}) eq 'ARRAY') {
5922: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5923: '<legend>'.&mt('Configurable in course').'</legend>';
5924: my ($rem,$numinrow);
5925: if ($provider eq 'proctorio') {
5926: $datatable .= '<table>';
5927: $numinrow = 4;
5928: }
5929: my $i = 0;
5930: foreach my $item (@{$crsconf{$provider}}) {
5931: my $name;
5932: if ($provider eq 'examity') {
5933: $name = $lt{'crs'.$item};
5934: } elsif ($provider eq 'proctorio') {
5935: $name = $fieldtitles{$item};
5936: $rem = $i%($numinrow);
5937: if ($rem == 0) {
5938: if ($i > 0) {
5939: $datatable .= '</tr>';
5940: }
5941: $datatable .= '<tr>';
5942: }
5943: $datatable .= '<td class="LC_left_item>';
5944: }
5945: my $checked;
5946: if ($crsconfig{$item}) {
5947: $checked = ' checked="checked"';
5948: }
5949: $datatable .= '<span class="LC_nobreak"><label>'.
5950: '<input type="checkbox" name="proctoring_crsconf_'.$provider.'" value="'.$item.'"'.$checked.' />'.
5951: $name.'</label></span>';
5952: if ($provider eq 'examity') {
5953: $datatable .= ' ';
5954: }
5955: $datatable .= "\n";
5956: $i++;
5957: }
5958: if ($provider eq 'proctorio') {
5959: if ($numinrow) {
5960: $rem = $i%$numinrow;
5961: }
5962: my $colsleft = $numinrow - $rem;
5963: if ($colsleft > 1) {
5964: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5965: } else {
5966: $datatable .= '<td class="LC_left_item">';
5967: }
5968: $datatable .= ' '.
5969: '</td></tr></table>';
5970: }
5971: $datatable .= '</fieldset>';
5972: }
5973: if ($showroles) {
5974: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5975: '<legend>'.&mt('Role mapping').'</legend><table><tr>';
5976: foreach my $role (@courseroles) {
5977: my ($selected,$selectnone);
5978: if (!$rolemaps{$role}) {
5979: $selectnone = ' selected="selected"';
5980: }
5981: $datatable .= '<td style="text-align: center">'.
5982: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5983: '<select name="proctoring_roles_'.$role.'_'.$provider.'">'.
5984: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5985: foreach my $ltirole (@ltiroles) {
5986: unless ($selectnone) {
5987: if ($rolemaps{$role} eq $ltirole) {
5988: $selected = ' selected="selected"';
5989: } else {
5990: $selected = '';
5991: }
5992: }
5993: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
5994: }
5995: $datatable .= '</select></td>';
5996: }
5997: $datatable .= '</tr></table></fieldset>'.
5998: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5999: '<legend>'.&mt('Custom items sent on launch').'</legend>'.
6000: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
6001: '<tr><td></td><td>lms</td>'.
6002: '<td><input type="text" name="proctoring_customval_lms_'.$provider.'"'.
6003: ' value="Loncapa" disabled="disabled"/></td></tr>';
6004: if ((ref($settings) eq 'HASH') && (ref($settings->{$provider}) eq 'HASH') &&
6005: (ref($settings->{$provider}->{'custom'}) eq 'HASH')) {
6006: my %custom = %{$settings->{$provider}->{'custom'}};
6007: if (keys(%custom) > 0) {
6008: foreach my $key (sort(keys(%custom))) {
6009: next if ($key eq 'lms');
6010: $datatable .= '<tr><td><span class="LC_nobreak">'.
6011: '<label><input type="checkbox" name="proctoring_customdel_'.$provider.'" value="'.
6012: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
6013: '<td><input type="text" name="proctoring_customval_'.$key.'_'.$provider.'"'.
6014: ' value="'.$custom{$key}.'" /></td></tr>';
6015: }
6016: }
6017: }
6018: $datatable .= '<tr><td><span class="LC_nobreak">'.
6019: '<label><input type="checkbox" name="proctoring_customadd" value="'.$provider.'" />'.
6020: &mt('Add more').'</label></span></td><td><input type="text" name="proctoring_custom_name_'.$provider.'" />'.
6021: '</td><td><input type="text" name="proctoring_custom_value_'.$provider.'" /></td></tr>'.
6022: '</table></fieldset></td></tr>'."\n";
6023: }
6024: $datatable .= '</td></tr>';
6025: }
6026: $itemcount ++;
6027: }
6028: }
6029: return $datatable;
6030: }
6031:
6032: sub proctoring_data {
6033: my $requserfields = {
6034: proctorio => ['user'],
6035: examity => ['roles','user'],
6036: };
6037: my $optuserfields = {
6038: proctorio => ['fullname'],
6039: examity => ['fullname','firstname','lastname','email'],
6040: };
6041: my $defaults = {
6042: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6043: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6044: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6045: 'closetabs','onescreen','print','downloads','cache','rightclick',
6046: 'reentry','calculator','whiteboard'],
6047: examity => ['display'],
6048: };
6049: my $extended = {
6050: proctorio => {
6051: verifyid => ['verifyidauto','verifyidlive'],
6052: fullscreen => ['fullscreenlenient','fullscreenmoderate','fullscreensever'],
6053: tabslinks => ['notabs','linksonly'],
6054: reentry => ['noreentry','agentreentry'],
6055: calculator => ['calculatorbasic','calculatorsci'],
6056: },
6057: examity => {
6058: display => {
6059: target => ['iframe','tab','window'],
6060: width => '',
6061: height => '',
6062: linktext => '',
6063: explanation => '',
6064: },
6065: },
6066: };
6067: my $crsconf = {
6068: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6069: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6070: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6071: 'closetabs','onescreen','print','downloads','cache','rightclick',
6072: 'reentry','calculator','whiteboard'],
6073: examity => ['label','title','target','linktext','explanation','append'],
6074: };
6075: my $courseroles = ['cc','in','ta','ep','st'];
6076: my $ltiroles = ['Instructor','ContentDeveloper','TeachingAssistant','Learner'];
6077: return ($requserfields,$optuserfields,$defaults,$extended,$crsconf,$courseroles,$ltiroles);
6078: }
6079:
6080: sub proctoring_titles {
6081: my ($item) = @_;
6082: my (%common_lt,%custom_lt);
6083: %common_lt = &Apache::lonlocal::texthash (
6084: 'avai' => 'Available?',
6085: 'base' => 'Basic Settings',
6086: 'requ' => 'User data required to be sent on launch',
6087: 'optu' => 'User data optionally sent on launch',
6088: 'udsl' => 'User data sent on launch',
6089: 'defa' => 'Defaults for items configurable in course',
6090: 'sigmethod' => 'Signature Method',
6091: 'key' => 'Key',
6092: 'lifetime' => 'Nonce lifetime (s)',
6093: 'secret' => 'Secret',
6094: 'icon' => 'Icon',
6095: 'fullname' => 'Full Name',
6096: 'visible' => 'Visible input',
6097: 'username' => 'username',
6098: 'user' => 'User',
6099: );
6100: if ($item eq 'proctorio') {
6101: %custom_lt = &Apache::lonlocal::texthash (
6102: 'version' => 'OAuth version',
6103: 'url' => 'API URL',
6104: 'uname:dom' => 'username-domain',
6105: );
6106: } elsif ($item eq 'examity') {
6107: %custom_lt = &Apache::lonlocal::texthash (
6108: 'version' => 'LTI Version',
6109: 'url' => 'URL',
6110: 'uname:dom' => 'username:domain',
6111: 'msgtype' => 'Message Type',
6112: 'firstname' => 'First Name',
6113: 'lastname' => 'Last Name',
6114: 'email' => 'E-mail',
6115: 'roles' => 'Role',
6116: 'crstarget' => 'Display target',
6117: 'crslabel' => 'Course label',
6118: 'crstitle' => 'Course title',
6119: 'crslinktext' => 'Link Text',
6120: 'crsexplanation' => 'Explanation',
6121: 'crsappend' => 'Provider URL',
6122: );
6123: }
6124: my %lt = (%common_lt,%custom_lt);
6125: return %lt;
6126: }
6127:
6128: sub proctoring_fieldtitles {
6129: my ($item) = @_;
6130: if ($item eq 'proctorio') {
6131: return &Apache::lonlocal::texthash (
6132: 'recordvideo' => 'Record video',
6133: 'recordaudio' => 'Record audio',
6134: 'recordscreen' => 'Record screen',
6135: 'recordwebtraffic' => 'Record web traffic',
6136: 'recordroomstart' => 'Record room scan',
6137: 'verifyvideo' => 'Verify webcam',
6138: 'verifyaudio' => 'Verify microphone',
6139: 'verifydesktop' => 'Verify desktop recording',
6140: 'verifyid' => 'Photo ID verification',
6141: 'verifysignature' => 'Require signature',
6142: 'fullscreen' => 'Fullscreen',
6143: 'clipboard' => 'Disable copy/paste',
6144: 'tabslinks' => 'New tabs/windows',
6145: 'closetabs' => 'Close other tabs',
6146: 'onescreen' => 'Limit to single screen',
6147: 'print' => 'Disable Printing',
6148: 'downloads' => 'Disable Downloads',
6149: 'cache' => 'Empty cache after exam',
6150: 'rightclick' => 'Disable right click',
6151: 'reentry' => 'Re-entry to exam',
6152: 'calculator' => 'Onscreen calculator',
6153: 'whiteboard' => 'Onscreen whiteboard',
6154: 'verifyidauto' => 'Automated verification',
6155: 'verifyidlive' => 'Live agent verification',
6156: 'fullscreenlenient' => 'Forced, but can navigate away for up to 30s',
6157: 'fullscreenmoderate' => 'Forced, but can navigate away for up to 15s',
6158: 'fullscreensever' => 'Forced, navigation away ends exam',
6159: 'notabs' => 'Disaallowed',
6160: 'linksonly' => 'Allowed from links in exam',
6161: 'noreentry' => 'Disallowed',
6162: 'agentreentry' => 'Agent required for re-entry',
6163: 'calculatorbasic' => 'Basic',
6164: 'calculatorsci' => 'Scientific',
6165: );
6166: } elsif ($item eq 'examity') {
6167: return &Apache::lonlocal::texthash (
6168: 'target' => 'Display target',
6169: 'window' => 'Window',
6170: 'tab' => 'Tab',
6171: 'iframe' => 'iFrame',
6172: 'height' => 'Height (pixels)',
6173: 'width' => 'Width (pixels)',
6174: 'linktext' => 'Default Link Text',
6175: 'explanation' => 'Default Explanation',
6176: 'append' => 'Provider URL',
6177: );
6178: }
6179: }
6180:
6181: sub proctoring_providernames {
6182: return (
6183: proctorio => 'Proctorio',
6184: examity => 'Examity',
6185: );
6186: }
6187:
1.320 raeburn 6188: sub print_lti {
1.405 raeburn 6189: my ($position,$dom,$settings,$rowtotal) = @_;
1.320 raeburn 6190: my $itemcount = 1;
1.405 raeburn 6191: my ($datatable,$css_class);
1.434 raeburn 6192: my (%rules,%encrypt,%privkeys,%linkprot,%suggestions);
1.320 raeburn 6193: if (ref($settings) eq 'HASH') {
1.405 raeburn 6194: if ($position eq 'top') {
6195: if (exists($settings->{'encrypt'})) {
6196: if (ref($settings->{'encrypt'}) eq 'HASH') {
6197: foreach my $key (keys(%{$settings->{'encrypt'}})) {
6198: if ($key eq 'consumers') {
6199: $encrypt{'ltisec_'.$key} = $settings->{'encrypt'}{$key};
6200: } else {
6201: $encrypt{'ltisec_'.$key.'linkprot'} = $settings->{'encrypt'}{$key};
6202: }
6203: }
6204: }
6205: }
6206: if (exists($settings->{'private'})) {
6207: if (ref($settings->{'private'}) eq 'HASH') {
6208: if (ref($settings->{'private'}) eq 'HASH') {
6209: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
6210: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
6211: }
6212: }
6213: }
6214: }
1.434 raeburn 6215: } elsif ($position eq 'upper') {
1.405 raeburn 6216: if (exists($settings->{'rules'})) {
6217: if (ref($settings->{'rules'}) eq 'HASH') {
6218: %rules = %{$settings->{'rules'}};
6219: }
6220: }
1.434 raeburn 6221: } elsif ($position eq 'middle') {
6222: if (exists($settings->{'suggested'})) {
6223: if (ref($settings->{'suggested'}) eq 'HASH') {
6224: %suggestions = %{$settings->{'suggested'}};
6225: }
6226: }
1.405 raeburn 6227: } elsif ($position eq 'lower') {
6228: if (exists($settings->{'linkprot'})) {
6229: if (ref($settings->{'linkprot'}) eq 'HASH') {
6230: %linkprot = %{$settings->{'linkprot'}};
1.406 raeburn 6231: if ($linkprot{'lock'}) {
6232: delete($linkprot{'lock'});
6233: }
1.405 raeburn 6234: }
6235: }
6236: } else {
1.434 raeburn 6237: foreach my $key ('encrypt','private','rules','linkprot','suggestions') {
1.405 raeburn 6238: if (exists($settings->{$key})) {
6239: delete($settings->{$key});
1.390 raeburn 6240: }
1.320 raeburn 6241: }
6242: }
6243: }
1.405 raeburn 6244: if ($position eq 'top') {
1.421 raeburn 6245: $datatable = &secrets_form($dom,'ltisec',\%encrypt,\%privkeys,$rowtotal);
1.434 raeburn 6246: } elsif ($position eq 'upper') {
6247: $datatable = &password_rules('ltisecrets',\$itemcount,\%rules);
6248: $$rowtotal += $itemcount;
1.421 raeburn 6249: } elsif ($position eq 'middle') {
1.434 raeburn 6250: $datatable = &linkprot_suggestions(\%suggestions,\$itemcount);
1.421 raeburn 6251: $$rowtotal += $itemcount;
6252: } elsif ($position eq 'lower') {
1.434 raeburn 6253: $datatable .= &Apache::courseprefs::print_linkprotection($dom,'',$settings,$rowtotal,'','','domain');
1.421 raeburn 6254: } else {
1.424 raeburn 6255: my ($switchserver,$switchmessage);
6256: $switchserver = &check_switchserver($dom);
6257: $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
1.421 raeburn 6258: my $maxnum = 0;
6259: my %ordered;
6260: if (ref($settings) eq 'HASH') {
6261: foreach my $item (keys(%{$settings})) {
6262: if (ref($settings->{$item}) eq 'HASH') {
6263: my $num = $settings->{$item}{'order'};
6264: if ($num eq '') {
6265: $num = scalar(keys(%{$settings}));
6266: }
6267: $ordered{$num} = $item;
1.405 raeburn 6268: }
1.352 raeburn 6269: }
1.405 raeburn 6270: }
6271: $maxnum = scalar(keys(%ordered));
6272: my %lt = <i_names();
6273: if (keys(%ordered)) {
6274: my @items = sort { $a <=> $b } keys(%ordered);
6275: for (my $i=0; $i<@items; $i++) {
6276: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6277: my $item = $ordered{$items[$i]};
1.424 raeburn 6278: my ($key,$secret,$usable,$lifetime,$consumer,$requser,$crsinc,$current);
1.405 raeburn 6279: if (ref($settings->{$item}) eq 'HASH') {
6280: $key = $settings->{$item}->{'key'};
1.424 raeburn 6281: $usable = $settings->{$item}->{'usable'};
1.405 raeburn 6282: $lifetime = $settings->{$item}->{'lifetime'};
6283: $consumer = $settings->{$item}->{'consumer'};
6284: $requser = $settings->{$item}->{'requser'};
6285: $crsinc = $settings->{$item}->{'crsinc'};
6286: $current = $settings->{$item};
6287: }
6288: my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
6289: my %checkedrequser = (
6290: yes => ' checked="checked"',
6291: no => '',
6292: );
6293: if (!$requser) {
6294: $checkedrequser{'no'} = $checkedrequser{'yes'};
6295: $checkedrequser{'yes'} = '';
6296: }
6297: my $onclickcrsinc = ' onclick="toggleLTI(this.form,'."'crsinc','$i'".');"';
6298: my %checkedcrsinc = (
1.391 raeburn 6299: yes => ' checked="checked"',
6300: no => '',
1.405 raeburn 6301: );
6302: if (!$crsinc) {
6303: $checkedcrsinc{'no'} = $checkedcrsinc{'yes'};
6304: $checkedcrsinc{'yes'} = '';
6305: }
6306: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
6307: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6308: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
6309: for (my $k=0; $k<=$maxnum; $k++) {
6310: my $vpos = $k+1;
6311: my $selstr;
6312: if ($k == $i) {
6313: $selstr = ' selected="selected" ';
6314: }
6315: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320 raeburn 6316: }
1.405 raeburn 6317: $datatable .= '</select>'.(' 'x2).
6318: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
6319: &mt('Delete?').'</label></span></td>'.
6320: '<td colspan="2">'.
6321: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6322: '<span class="LC_nobreak">'.$lt{'consumer'}.
6323: ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
6324: (' 'x2).
6325: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
6326: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
6327: (' 'x2).
6328: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
1.424 raeburn 6329: 'value="'.$lifetime.'" size="3" /></span><br /><br />';
6330: if ($key ne '') {
6331: $datatable .= '<span class="LC_nobreak">'.$lt{'key'};
6332: if ($switchserver) {
6333: $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
6334: } else {
6335: $datatable .= ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />';
6336: }
6337: $datatable .= '</span> '.(' 'x2);
6338: } elsif (!$switchserver) {
6339: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':'.
6340: '<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />'.
6341: '</span> '.(' 'x2);
6342: }
6343: if ($switchserver) {
6344: if ($usable ne '') {
6345: $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6346: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6347: '<span class="LC_nobreak">'.&mt('Change secret?').
6348: '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
6349: (' 'x2).
6350: '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').'</label>'.(' 'x2).
6351: '</span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
6352: '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
6353: '</div>';
6354: } elsif ($key eq '') {
6355: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6356: } else {
6357: $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
6358: }
6359: } else {
6360: if ($usable ne '') {
6361: $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6362: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6363: '<span class="LC_nobreak">'.&mt('Change?').
6364: '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
6365: (' 'x2).
6366: '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').
6367: '</label> </span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
6368: '<span class="LC_nobreak">'.&mt('New Secret').':'.
6369: '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
6370: '<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>';
6371: } else {
6372: $datatable .=
6373: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
6374: '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
6375: '<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>';
6376: }
6377: }
1.425 raeburn 6378: $datatable .= '<br /><br />'.
1.405 raeburn 6379: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6380: '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
6381: '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
6382: '<br /><br />'.
6383: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6384: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="1"'.$onclickcrsinc.$checkedcrsinc{yes}.' />'.&mt('Yes').'</label> '."\n".
6385: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="0"'.$onclickcrsinc.$checkedcrsinc{no}.' />'.&mt('No').'</label></span>'."\n".
6386: (' 'x4).
6387: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
6388: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
6389: $itemcount ++;
1.320 raeburn 6390: }
6391: }
1.405 raeburn 6392: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6393: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
6394: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6395: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
6396: '<select name="lti_pos_add"'.$chgstr.'>';
6397: for (my $k=0; $k<$maxnum+1; $k++) {
6398: my $vpos = $k+1;
6399: my $selstr;
6400: if ($k == $maxnum) {
6401: $selstr = ' selected="selected" ';
6402: }
6403: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320 raeburn 6404: }
1.405 raeburn 6405: $datatable .= '</select> '."\n".
6406: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6407: '<td colspan="2">'.
6408: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6409: '<span class="LC_nobreak">'.$lt{'consumer'}.
6410: ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
6411: (' 'x2).
6412: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
6413: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
6414: (' 'x2).
1.424 raeburn 6415: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span><br /><br />'."\n";
6416: if ($switchserver) {
6417: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6418: } else {
6419: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" autocomplete="off" /></span> '."\n".
6420: (' 'x2).
6421: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" autocomplete="new-password" />'.
6422: '<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";
6423: }
6424: $datatable .= '<br /><br />'.
1.405 raeburn 6425: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6426: '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6427: '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
6428: '<br /><br />'.
6429: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6430: '<label><input type="radio" name="lti_crsinc_add" value="1" onclick="toggleLTI(this.form,'."'crsinc','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6431: '<label><input type="radio" name="lti_crsinc_add" value="0" onclick="toggleLTI(this.form,'."'crsinc','add'".');" />'.&mt('No').'</label></span>'."\n".
6432: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
6433: '</td>'."\n".
6434: '</tr>'."\n";
6435: $itemcount ++;
1.320 raeburn 6436: }
1.405 raeburn 6437: $$rowtotal += $itemcount;
6438: return $datatable;
1.320 raeburn 6439: }
6440:
6441: sub lti_names {
6442: my %lt = &Apache::lonlocal::texthash(
6443: 'version' => 'LTI Version',
6444: 'url' => 'URL',
6445: 'key' => 'Key',
1.322 raeburn 6446: 'lifetime' => 'Nonce lifetime (s)',
1.345 raeburn 6447: 'consumer' => 'Consumer',
1.320 raeburn 6448: 'secret' => 'Secret',
1.345 raeburn 6449: 'requser' => "User's identity sent",
1.391 raeburn 6450: 'crsinc' => "Course's identity sent",
1.320 raeburn 6451: 'email' => 'Email address',
6452: 'sourcedid' => 'User ID',
6453: 'other' => 'Other',
6454: 'passback' => 'Can return grades to Consumer:',
6455: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 6456: 'topmenu' => 'Display LON-CAPA page header',
1.345 raeburn 6457: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 6458: );
6459: return %lt;
6460: }
6461:
6462: sub lti_options {
1.325 raeburn 6463: my ($num,$current,$itemcount,%lt) = @_;
1.363 raeburn 6464: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
1.320 raeburn 6465: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
6466: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
1.392 raeburn 6467: $checked{'storecrs'}{'Y'} = ' checked="checked"';
6468: $checked{'makecrs'}{'N'} = ' checked="checked"';
1.320 raeburn 6469: $checked{'mapcrstype'} = {};
6470: $checked{'makeuser'} = {};
6471: $checked{'selfenroll'} = {};
6472: $checked{'crssec'} = {};
6473: $checked{'crssecsrc'} = {};
1.325 raeburn 6474: $checked{'lcauth'} = {};
1.326 raeburn 6475: $checked{'menuitem'} = {};
1.325 raeburn 6476: if ($num eq 'add') {
6477: $checked{'lcauth'}{'lti'} = ' checked="checked"';
6478: }
1.320 raeburn 6479: my $userfieldsty = 'none';
6480: my $crsfieldsty = 'none';
6481: my $crssecfieldsty = 'none';
6482: my $secsrcfieldsty = 'none';
1.363 raeburn 6483: my $callbacksty = 'none';
1.337 raeburn 6484: my $passbacksty = 'none';
1.345 raeburn 6485: my $optionsty = 'block';
1.391 raeburn 6486: my $crssty = 'block';
1.325 raeburn 6487: my $lcauthparm;
6488: my $lcauthparmstyle = 'display:none';
6489: my $lcauthparmtext;
1.326 raeburn 6490: my $menusty;
1.325 raeburn 6491: my $numinrow = 4;
1.326 raeburn 6492: my %menutitles = <imenu_titles();
1.320 raeburn 6493:
6494: if (ref($current) eq 'HASH') {
1.345 raeburn 6495: if (!$current->{'requser'}) {
6496: $optionsty = 'none';
1.391 raeburn 6497: $crssty = 'none';
6498: } elsif (!$current->{'crsinc'}) {
6499: $crssty = 'none';
1.345 raeburn 6500: }
1.320 raeburn 6501: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
6502: $checked{'mapuser'}{'sourcedid'} = '';
6503: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
1.425 raeburn 6504: $checked{'mapuser'}{'email'} = ' checked="checked"';
1.320 raeburn 6505: } else {
6506: $checked{'mapuser'}{'other'} = ' checked="checked"';
6507: $userfield = $current->{'mapuser'};
6508: $userfieldsty = 'inline-block';
6509: }
6510: }
6511: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
6512: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
6513: if ($current->{'mapcrs'} eq 'context_id') {
1.425 raeburn 6514: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
1.320 raeburn 6515: } else {
6516: $checked{'mapcrs'}{'other'} = ' checked="checked"';
6517: $cidfield = $current->{'mapcrs'};
6518: $crsfieldsty = 'inline-block';
6519: }
6520: }
6521: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
6522: foreach my $type (@{$current->{'mapcrstype'}}) {
6523: $checked{'mapcrstype'}{$type} = ' checked="checked"';
6524: }
6525: }
1.392 raeburn 6526: if (!$current->{'storecrs'}) {
6527: $checked{'storecrs'}{'N'} = $checked{'storecrs'}{'Y'};
6528: $checked{'storecrs'}{'Y'} = '';
6529: }
1.345 raeburn 6530: if ($current->{'makecrs'}) {
1.320 raeburn 6531: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 6532: }
1.320 raeburn 6533: if (ref($current->{'makeuser'}) eq 'ARRAY') {
6534: foreach my $role (@{$current->{'makeuser'}}) {
6535: $checked{'makeuser'}{$role} = ' checked="checked"';
6536: }
6537: }
1.325 raeburn 6538: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
6539: $checked{'lcauth'}{$1} = ' checked="checked"';
6540: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
6541: $lcauthparm = $current->{'lcauthparm'};
1.425 raeburn 6542: $lcauthparmstyle = 'display:table-row';
1.325 raeburn 6543: if ($current->{'lcauth'} eq 'localauth') {
6544: $lcauthparmtext = &mt('Local auth argument');
6545: } else {
6546: $lcauthparmtext = &mt('Kerberos domain');
6547: }
6548: }
6549: }
1.320 raeburn 6550: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
6551: foreach my $role (@{$current->{'selfenroll'}}) {
6552: $checked{'selfenroll'}{$role} = ' checked="checked"';
6553: }
6554: }
6555: if (ref($current->{'maproles'}) eq 'HASH') {
6556: %rolemaps = %{$current->{'maproles'}};
6557: }
6558: if ($current->{'section'} ne '') {
1.425 raeburn 6559: $checked{'crssec'}{'Y'} = ' checked="checked"';
1.320 raeburn 6560: $crssecfieldsty = 'inline-block';
6561: if ($current->{'section'} eq 'course_section_sourcedid') {
6562: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
6563: } else {
6564: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
6565: $crssecsrc = $current->{'section'};
6566: $secsrcfieldsty = 'inline-block';
6567: }
6568: } else {
6569: $checked{'crssec'}{'N'} = ' checked="checked"';
6570: }
1.363 raeburn 6571: if ($current->{'callback'} ne '') {
6572: $callback = $current->{'callback'};
6573: $checked{'callback'}{'Y'} = ' checked="checked"';
6574: $callbacksty = 'inline-block';
6575: } else {
6576: $checked{'callback'}{'N'} = ' checked="checked"';
6577: }
1.326 raeburn 6578: if ($current->{'topmenu'}) {
6579: $checked{'topmenu'}{'Y'} = ' checked="checked"';
6580: } else {
6581: $checked{'topmenu'}{'N'} = ' checked="checked"';
6582: }
6583: if ($current->{'inlinemenu'}) {
6584: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
6585: } else {
6586: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
6587: }
6588: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
6589: $menusty = 'inline-block';
6590: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
6591: foreach my $item (@{$current->{'lcmenu'}}) {
6592: if (exists($menutitles{$item})) {
6593: $checked{'menuitem'}{$item} = ' checked="checked"';
6594: }
6595: }
6596: }
6597: } else {
6598: $menusty = 'none';
6599: }
1.320 raeburn 6600: } else {
6601: $checked{'makecrs'}{'N'} = ' checked="checked"';
6602: $checked{'crssec'}{'N'} = ' checked="checked"';
1.363 raeburn 6603: $checked{'callback'}{'N'} = ' checked="checked"';
1.326 raeburn 6604: $checked{'topmenu'}{'N'} = ' checked="checked"';
1.425 raeburn 6605: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
1.326 raeburn 6606: $checked{'menuitem'}{'grades'} = ' checked="checked"';
1.425 raeburn 6607: $menusty = 'inline-block';
1.320 raeburn 6608: }
1.325 raeburn 6609: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 6610: my %coursetypetitles = &Apache::lonlocal::texthash (
6611: official => 'Official',
6612: unofficial => 'Unofficial',
6613: community => 'Community',
6614: textbook => 'Textbook',
6615: placement => 'Placement Test',
1.325 raeburn 6616: lti => 'LTI Provider',
1.320 raeburn 6617: );
1.325 raeburn 6618: my @authtypes = ('internal','krb4','krb5','localauth');
6619: my %shortauth = (
6620: internal => 'int',
6621: krb4 => 'krb4',
6622: krb5 => 'krb5',
6623: localauth => 'loc'
6624: );
6625: my %authnames = &authtype_names();
1.320 raeburn 6626: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
6627: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
6628: my @courseroles = ('cc','in','ta','ep','st');
6629: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
6630: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
6631: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
1.363 raeburn 6632: my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
1.320 raeburn 6633: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 6634: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 6635: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.391 raeburn 6636: my $output = '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Logout options').'</legend>'.
1.392 raeburn 6637: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback to logout LON-CAPA on log out from Consumer').': '.
1.391 raeburn 6638: '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
6639: $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.(' 'x2).
6640: '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
6641: $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
6642: '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
6643: '<span class="LC_nobreak">'.&mt('Parameter').': '.
6644: '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
6645: '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
6646: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320 raeburn 6647: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
6648: foreach my $option ('sourcedid','email','other') {
6649: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
6650: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
6651: ($option eq 'other' ? '' : (' 'x2) );
6652: }
6653: $output .= '</span></div>'.
6654: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
6655: '<input type="text" name="lti_customuser_'.$num.'" '.
1.372 raeburn 6656: 'value="'.$userfield.'" /></div></fieldset>'.
1.391 raeburn 6657: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320 raeburn 6658: foreach my $ltirole (@ltiroles) {
6659: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
1.425 raeburn 6660: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
1.320 raeburn 6661: }
6662: $output .= '</fieldset>'.
1.391 raeburn 6663: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325 raeburn 6664: '<table>'.
6665: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
6666: '</table>'.
6667: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
6668: '<td class="LC_left_item">';
6669: foreach my $auth ('lti',@authtypes) {
6670: my $authtext;
6671: if ($auth eq 'lti') {
6672: $authtext = &mt('None');
6673: } else {
6674: $authtext = $authnames{$shortauth{$auth}};
6675: }
6676: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
6677: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
6678: $authtext.'</label></span> ';
6679: }
6680: $output .= '</td></tr>'.
6681: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
6682: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
6683: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
6684: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
6685: '</table></fieldset>'.
1.391 raeburn 6686: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.
6687: &mt('LON-CAPA menu items (Course Coordinator can override)').'</legend>'.
6688: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
6689: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
6690: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6691: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
6692: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
6693: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6694: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
6695: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
6696: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6697: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
6698: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
6699: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6700: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
6701: '<span class="LC_nobreak">'.&mt('Menu items').': ';
6702: foreach my $type ('fullname','coursetitle','role','logout','grades') {
6703: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
6704: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
6705: (' 'x2);
6706: }
6707: $output .= '</span></div></fieldset>'.
6708: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320 raeburn 6709: '<div class="LC_floatleft"><span class="LC_nobreak">'.
6710: &mt('Unique course identifier').': ';
6711: foreach my $option ('course_offering_sourcedid','context_id','other') {
6712: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
6713: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
6714: ($option eq 'other' ? '' : (' 'x2) );
6715: }
1.334 raeburn 6716: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320 raeburn 6717: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
6718: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
6719: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
6720: foreach my $type (@coursetypes) {
6721: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
6722: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
6723: (' 'x2);
6724: }
1.392 raeburn 6725: $output .= '</span><br /><br />'.
6726: '<span class="LC_nobreak">'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.
6727: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="0"'.
6728: $checked{'storecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6729: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="1"'.
6730: $checked{'storecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6731: '</fieldset>'.
1.391 raeburn 6732: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
6733: foreach my $ltirole (@lticourseroles) {
6734: my ($selected,$selectnone);
6735: if ($rolemaps{$ltirole} eq '') {
6736: $selectnone = ' selected="selected"';
6737: }
6738: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
6739: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
6740: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
6741: foreach my $role (@courseroles) {
6742: unless ($selectnone) {
6743: if ($rolemaps{$ltirole} eq $role) {
6744: $selected = ' selected="selected"';
6745: } else {
6746: $selected = '';
6747: }
6748: }
6749: $output .= '<option value="'.$role.'"'.$selected.'>'.
6750: &Apache::lonnet::plaintext($role,'Course').
6751: '</option>';
6752: }
6753: $output .= '</select></td>';
6754: }
6755: $output .= '</tr></table></fieldset>'.
6756: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320 raeburn 6757: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
6758: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
6759: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6760: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
6761: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6762: '</fieldset>'.
1.391 raeburn 6763: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320 raeburn 6764: foreach my $lticrsrole (@lticourseroles) {
6765: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
6766: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
6767: }
6768: $output .= '</fieldset>'.
1.391 raeburn 6769: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Course options').'</legend>'.
1.320 raeburn 6770: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
6771: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
6772: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
6773: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334 raeburn 6774: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320 raeburn 6775: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
6776: '<span class="LC_nobreak">'.&mt('From').':<label>'.
6777: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
6778: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
6779: &mt('Standard field').'</label>'.(' 'x2).
6780: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
6781: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334 raeburn 6782: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320 raeburn 6783: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337 raeburn 6784: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6785: my ($pb1p1chk,$pb1p0chk,$onclickpb);
6786: foreach my $extra ('roster','passback') {
1.320 raeburn 6787: my $checkedon = '';
6788: my $checkedoff = ' checked="checked"';
1.337 raeburn 6789: if ($extra eq 'passback') {
6790: $pb1p1chk = ' checked="checked"';
6791: $pb1p0chk = '';
1.425 raeburn 6792: $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
1.337 raeburn 6793: } else {
1.425 raeburn 6794: $onclickpb = '';
1.337 raeburn 6795: }
1.320 raeburn 6796: if (ref($current) eq 'HASH') {
6797: if (($current->{$extra})) {
6798: $checkedon = $checkedoff;
6799: $checkedoff = '';
1.337 raeburn 6800: if ($extra eq 'passback') {
6801: $passbacksty = 'inline-block';
6802: }
6803: if ($current->{'passbackformat'} eq '1.0') {
6804: $pb1p0chk = ' checked="checked"';
6805: $pb1p1chk = '';
6806: }
1.320 raeburn 6807: }
6808: }
6809: $output .= $lt{$extra}.' '.
1.337 raeburn 6810: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320 raeburn 6811: &mt('No').'</label>'.(' 'x2).
1.339 raeburn 6812: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320 raeburn 6813: &mt('Yes').'</label><br />';
6814: }
1.337 raeburn 6815: $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
6816: '<span class="LC_nobreak">'.&mt('Grade format').
6817: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
6818: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
6819: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
1.363 raeburn 6820: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
1.391 raeburn 6821: '<div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>';
1.334 raeburn 6822: $output .= '</span></div></fieldset>';
1.320 raeburn 6823: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
6824: #
6825: # $output .= '</fieldset>'.
6826: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
6827: return $output;
6828: }
6829:
1.326 raeburn 6830: sub ltimenu_titles {
6831: return &Apache::lonlocal::texthash(
6832: fullname => 'Full name',
6833: coursetitle => 'Course title',
6834: role => 'Role',
6835: logout => 'Logout',
6836: grades => 'Grades',
6837: );
6838: }
6839:
1.434 raeburn 6840: sub linkprot_suggestions {
6841: my ($suggested,$itemcount) = @_;
6842: my $count = 0;
6843: my $next = 1;
6844: my %lt = &Apache::lonlocal::texthash(
6845: 'name' => 'Suggested Launcher',
6846: 'info' => 'Recommendations',
6847: );
6848: my ($datatable,$css_class,$dest);
6849: if (ref($suggested) eq 'HASH') {
6850: my @current = sort { $a <=> $b } keys(%{$suggested});
6851: $next += $current[-1];
6852: for (my $i=0; $i<@current; $i++) {
6853: my $num = $current[$i];
6854: my %values;
6855: if (ref($suggested->{$num}) eq 'HASH') {
6856: %values = %{$suggested->{$num}};
6857: } else {
6858: next;
6859: }
6860: $css_class = $$itemcount%2?' class="LC_odd_row"':'';
6861: $datatable .=
6862: '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6863: '<label><input type="checkbox" name="linkprot_suggested_del" value="'.$i.'" />'."\n".
6864: &mt('Delete?').'</label></span></td><td>'."\n".
6865: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'name'}.'</legend>'."\n".
6866: '<input type="text" size="15" name="linkprot_suggested_name_'.$i.'" value="'.$values{'name'}.'" autocomplete="off" />'."\n".
6867: '</fieldset></div>'.
6868: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'info'}.'</legend>'."\n".
6869: '<textarea cols="55" rows="5" name="linkprot_suggested_info_'.$i.'">'.$values{'info'}.'</textarea>'.
6870: '</fieldset></div>'.
6871: '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
6872: '<input type="hidden" name="linkprot_suggested_id_'.$i.'" value="'.$num.'" /></td></tr>'."\n";
6873: $$itemcount ++;
6874: }
6875: }
6876: $css_class = $$itemcount%2?' class="LC_odd_row"':'';
6877: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6878: '<input type="hidden" name="linkprot_suggested_maxnum" value="'.$next.'" />'."\n".
6879: '<input type="checkbox" name="linkprot_suggested_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6880: '<td>'."\n".
6881: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'name'}.'</legend>'."\n".
6882: '<input type="text" size="15" name="linkprot_suggested_name_add" value="" autocomplete="off" />'."\n".
6883: '</fieldset></div>'.
6884: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'info'}.'</legend>'."\n".
6885: '<textarea cols="55" rows="5" name="linkprot_suggested_info_add"></textarea>'.
6886: '</fieldset></div>'.
6887: '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
6888: '</td></tr>'."\n";
6889: return $datatable;
6890: }
6891:
1.121 raeburn 6892: sub print_coursedefaults {
1.139 raeburn 6893: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 6894: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 6895: my $itemcount = 1;
1.192 raeburn 6896: my %choices = &Apache::lonlocal::texthash (
6897: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 6898: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.432 raeburn 6899: coursequota => 'Default cumulative quota for all group portfolio spaces in course (MB)',
1.192 raeburn 6900: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
6901: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 6902: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
6903: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.398 raeburn 6904: inline_chem => 'Use inline previewer for chemical reaction response in place of pop-up',
1.314 raeburn 6905: texengine => 'Default method to display mathematics',
1.257 raeburn 6906: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 6907: canclone => "People who may clone a course (besides course's owner and coordinators)",
6908: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.405 raeburn 6909: ltiauth => 'Student username in LTI launch of deep-linked URL can be accepted without re-authentication',
1.422 raeburn 6910: domexttool => 'External Tools defined in the domain may be used in courses/communities (by type)',
6911: exttool => 'External Tools can be defined and configured in courses/communities (by type)',
1.432 raeburn 6912: crsauthor => 'Standard LON-CAPA problems can be created within a course/community (by type)',
1.438 raeburn 6913: crseditors => 'Available editors for web pages and/or problems created in a course/community',
1.192 raeburn 6914: );
1.198 raeburn 6915: my %staticdefaults = (
6916: anonsurvey_threshold => 10,
6917: uploadquota => 500,
1.428 raeburn 6918: coursequota => 20,
1.257 raeburn 6919: postsubmit => 60,
1.276 raeburn 6920: mysqltables => 172800,
1.422 raeburn 6921: domexttool => 1,
6922: exttool => 0,
1.432 raeburn 6923: crsauthor => 1,
1.438 raeburn 6924: crseditors => ['edit','xml'],
1.198 raeburn 6925: );
1.139 raeburn 6926: if ($position eq 'top') {
1.257 raeburn 6927: %defaultchecked = (
6928: 'canuse_pdfforms' => 'off',
6929: 'uselcmath' => 'on',
6930: 'usejsme' => 'on',
1.398 raeburn 6931: 'inline_chem' => 'on',
1.289 raeburn 6932: 'canclone' => 'none',
1.257 raeburn 6933: );
1.398 raeburn 6934: @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem');
1.349 raeburn 6935: my $deftex = $Apache::lonnet::deftex;
1.314 raeburn 6936: if (ref($settings) eq 'HASH') {
6937: if ($settings->{'texengine'}) {
6938: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
6939: $deftex = $settings->{'texengine'};
6940: }
6941: }
6942: }
6943: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6944: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
6945: '<span class="LC_nobreak">'.$choices{'texengine'}.
6946: '</span></td><td class="LC_right_item">'.
6947: '<select name="texengine">'."\n";
6948: my %texoptions = (
6949: MathJax => 'MathJax',
6950: mimetex => &mt('Convert to Images'),
6951: tth => &mt('TeX to HTML'),
6952: );
6953: foreach my $renderer ('MathJax','mimetex','tth') {
6954: my $selected = '';
6955: if ($renderer eq $deftex) {
6956: $selected = ' selected="selected"';
6957: }
6958: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
6959: }
6960: $mathdisp .= '</select></td></tr>'."\n";
6961: $itemcount ++;
1.139 raeburn 6962: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 6963: \%choices,$itemcount);
1.314 raeburn 6964: $datatable = $mathdisp.$datatable;
1.264 raeburn 6965: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6966: $datatable .=
1.306 raeburn 6967: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 6968: '<span class="LC_nobreak">'.$choices{'canclone'}.
6969: '</span></td><td class="LC_left_item">';
6970: my $currcanclone = 'none';
6971: my $onclick;
6972: my @cloneoptions = ('none','domain');
1.380 raeburn 6973: my %clonetitles = &Apache::lonlocal::texthash (
1.264 raeburn 6974: none => 'No additional course requesters',
6975: domain => "Any course requester in course's domain",
6976: instcode => 'Course requests for official courses ...',
6977: );
6978: my (%codedefaults,@code_order,@posscodes);
6979: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
6980: \@code_order) eq 'ok') {
6981: if (@code_order > 0) {
6982: push(@cloneoptions,'instcode');
6983: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
6984: }
6985: }
6986: if (ref($settings) eq 'HASH') {
6987: if ($settings->{'canclone'}) {
6988: if (ref($settings->{'canclone'}) eq 'HASH') {
6989: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
6990: if (@code_order > 0) {
6991: $currcanclone = 'instcode';
6992: @posscodes = @{$settings->{'canclone'}{'instcode'}};
6993: }
6994: }
6995: } elsif ($settings->{'canclone'} eq 'domain') {
6996: $currcanclone = $settings->{'canclone'};
6997: }
6998: }
1.289 raeburn 6999: }
1.264 raeburn 7000: foreach my $option (@cloneoptions) {
7001: my ($checked,$additional);
7002: if ($currcanclone eq $option) {
7003: $checked = ' checked="checked"';
7004: }
7005: if ($option eq 'instcode') {
7006: if (@code_order) {
7007: my $show = 'none';
7008: if ($checked) {
7009: $show = 'block';
7010: }
1.317 raeburn 7011: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 7012: &mt('Institutional codes for new and cloned course have identical:').
7013: '<br />';
7014: foreach my $item (@code_order) {
7015: my $codechk;
7016: if ($checked) {
7017: if (grep(/^\Q$item\E$/,@posscodes)) {
7018: $codechk = ' checked="checked"';
7019: }
7020: }
7021: $additional .= '<label>'.
7022: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
7023: $item.'</label>';
7024: }
7025: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
7026: }
7027: }
7028: $datatable .=
7029: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
7030: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
7031: '</label> '.$additional.'</span><br />';
7032: }
7033: $datatable .= '</td>'.
7034: '</tr>';
7035: $itemcount ++;
1.139 raeburn 7036: } else {
7037: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.428 raeburn 7038: my ($currdefresponder,%defcredits,%curruploadquota,%currcoursequota,
7039: %deftimeout,%currmysql);
1.192 raeburn 7040: my $currusecredits = 0;
1.257 raeburn 7041: my $postsubmitclient = 1;
1.405 raeburn 7042: my $ltiauth = 0;
1.422 raeburn 7043: my %domexttool;
7044: my %exttool;
1.432 raeburn 7045: my %crsauthor;
1.438 raeburn 7046: my %crseditors;
1.271 raeburn 7047: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 7048: if (ref($settings) eq 'HASH') {
1.404 raeburn 7049: if ($settings->{'ltiauth'}) {
7050: $ltiauth = 1;
1.405 raeburn 7051: }
1.422 raeburn 7052: if (ref($settings->{'domexttool'}) eq 'HASH') {
7053: foreach my $type (@types) {
7054: if ($settings->{'domexttool'}->{$type}) {
7055: $domexttool{$type} = ' checked="checked"';
7056: }
7057: }
7058: } else {
7059: foreach my $type (@types) {
7060: if ($staticdefaults{'domexttool'}) {
7061: $domexttool{$type} = ' checked="checked"';
7062: }
7063: }
7064: }
7065: if (ref($settings->{'exttool'}) eq 'HASH') {
7066: foreach my $type (@types) {
7067: if ($settings->{'exttool'}->{$type}) {
7068: $exttool{$type} = ' checked="checked"';
7069: }
7070: }
7071: }
1.432 raeburn 7072: if (ref($settings->{'crsauthor'}) eq 'HASH') {
7073: foreach my $type (@types) {
7074: if ($settings->{'crsauthor'}->{$type}) {
7075: $crsauthor{$type} = ' checked="checked"';
7076: }
7077: }
7078: } else {
7079: foreach my $type (@types) {
7080: if ($staticdefaults{'crsauthor'}) {
7081: $crsauthor{$type} = ' checked="checked"';
7082: }
7083: }
7084: }
1.438 raeburn 7085: if (ref($settings->{'crseditors'}) eq 'ARRAY') {
7086: foreach my $editor (@{$settings->{'crseditors'}}) {
7087: $crseditors{$editor} = ' checked="checked"';
7088: }
7089: } else {
7090: foreach my $editor (@{$staticdefaults{'crseditors'}}) {
7091: $crseditors{$editor} = ' checked="checked"';
7092: }
7093: }
1.139 raeburn 7094: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 7095: if (ref($settings->{'uploadquota'}) eq 'HASH') {
7096: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
7097: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
7098: }
7099: }
1.428 raeburn 7100: if (ref($settings->{'coursequota'}) eq 'HASH') {
7101: foreach my $type (keys(%{$settings->{'coursequota'}})) {
7102: $currcoursequota{$type} = $settings->{'coursequota'}{$type};
7103: }
7104: }
1.192 raeburn 7105: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 7106: foreach my $type (@types) {
7107: next if ($type eq 'community');
7108: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
7109: if ($defcredits{$type} ne '') {
7110: $currusecredits = 1;
7111: }
7112: }
7113: }
7114: if (ref($settings->{'postsubmit'}) eq 'HASH') {
7115: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
7116: $postsubmitclient = 0;
7117: foreach my $type (@types) {
7118: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7119: }
7120: } else {
7121: foreach my $type (@types) {
7122: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
7123: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 7124: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 7125: } else {
7126: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7127: }
7128: } else {
7129: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7130: }
7131: }
7132: }
7133: } else {
7134: foreach my $type (@types) {
7135: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 7136: }
7137: }
1.276 raeburn 7138: if (ref($settings->{'mysqltables'}) eq 'HASH') {
7139: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
7140: $currmysql{$type} = $settings->{'mysqltables'}{$type};
7141: }
7142: } else {
7143: foreach my $type (@types) {
7144: $currmysql{$type} = $staticdefaults{'mysqltables'};
7145: }
7146: }
1.258 raeburn 7147: } else {
7148: foreach my $type (@types) {
7149: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.422 raeburn 7150: if ($staticdefaults{'domexttool'}) {
7151: $domexttool{$type} = ' checked="checked"';
7152: }
1.432 raeburn 7153: if ($staticdefaults{'crsauthor'}) {
7154: $crsauthor{$type} = ' checked="checked"';
7155: }
1.258 raeburn 7156: }
1.438 raeburn 7157: foreach my $editor (@{$staticdefaults{'crseditors'}}) {
7158: $crseditors{$editor} = ' checked="checked"';
7159: }
1.139 raeburn 7160: }
7161: if (!$currdefresponder) {
1.198 raeburn 7162: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 7163: } elsif ($currdefresponder < 1) {
7164: $currdefresponder = 1;
7165: }
1.198 raeburn 7166: foreach my $type (@types) {
7167: if ($curruploadquota{$type} eq '') {
7168: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
7169: }
1.428 raeburn 7170: if ($currcoursequota{$type} eq '') {
7171: $currcoursequota{$type} = $staticdefaults{'coursequota'};
7172: }
1.198 raeburn 7173: }
1.139 raeburn 7174: $datatable .=
1.192 raeburn 7175: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7176: $choices{'anonsurvey_threshold'}.
1.139 raeburn 7177: '</span></td>'.
7178: '<td class="LC_right_item"><span class="LC_nobreak">'.
7179: '<input type="text" name="anonsurvey_threshold"'.
7180: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 7181: '</td></tr>'."\n";
7182: $itemcount ++;
7183: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7184: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7185: $choices{'uploadquota'}.
7186: '</span></td>'.
1.306 raeburn 7187: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 7188: '<table><tr>';
1.198 raeburn 7189: foreach my $type (@types) {
1.306 raeburn 7190: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 7191: '<input type="text" name="uploadquota_'.$type.'"'.
7192: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
7193: }
7194: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 7195: $itemcount ++;
1.428 raeburn 7196: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7197: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7198: $choices{'coursequota'}.
7199: '</span></td>'.
7200: '<td style="text-align: right" class="LC_right_item">'.
7201: '<table><tr>';
7202: foreach my $type (@types) {
7203: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
7204: '<input type="text" name="coursequota_'.$type.'"'.
7205: ' value="'.$currcoursequota{$type}.'" size="5" /></td>';
7206: }
7207: $datatable .= '</tr></table></td></tr>'."\n";
7208: $itemcount ++;
1.236 raeburn 7209: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 7210: my $display = 'none';
1.192 raeburn 7211: if ($currusecredits) {
7212: $display = 'block';
7213: }
7214: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 7215: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
7216: foreach my $type (@types) {
7217: next if ($type eq 'community');
1.306 raeburn 7218: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7219: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 7220: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 7221: }
7222: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 7223: %defaultchecked = ('coursecredits' => 'off');
7224: @toggles = ('coursecredits');
7225: my $current = {
7226: 'coursecredits' => $currusecredits,
7227: };
7228: (my $table,$itemcount) =
7229: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 7230: \%choices,$itemcount,$onclick,$additional,'left');
7231: $datatable .= $table;
7232: $onclick = "toggleDisplay(this.form,'studentsubmission');";
7233: my $display = 'none';
7234: if ($postsubmitclient) {
7235: $display = 'block';
7236: }
7237: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 7238: &mt('Number of seconds submit is disabled').'<br />'.
7239: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
7240: '<table><tr>';
1.257 raeburn 7241: foreach my $type (@types) {
1.306 raeburn 7242: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7243: '<input type="text" name="'.$type.'_timeout" value="'.
7244: $deftimeout{$type}.'" size="5" /></td>';
7245: }
7246: $additional .= '</tr></table></div>'."\n";
7247: %defaultchecked = ('postsubmit' => 'on');
7248: @toggles = ('postsubmit');
1.280 raeburn 7249: $current = {
7250: 'postsubmit' => $postsubmitclient,
7251: };
1.257 raeburn 7252: ($table,$itemcount) =
7253: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7254: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 7255: $datatable .= $table;
1.276 raeburn 7256: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7257: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7258: $choices{'mysqltables'}.
7259: '</span></td>'.
1.306 raeburn 7260: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 7261: '<table><tr>';
7262: foreach my $type (@types) {
1.306 raeburn 7263: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 7264: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 7265: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 7266: }
7267: $datatable .= '</tr></table></td></tr>'."\n";
7268: $itemcount ++;
1.404 raeburn 7269: %defaultchecked = ('ltiauth' => 'off');
7270: @toggles = ('ltiauth');
7271: $current = {
7272: 'ltiauth' => $ltiauth,
7273: };
7274: ($table,$itemcount) =
7275: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7276: \%choices,$itemcount,undef,undef,'left');
7277: $datatable .= $table;
1.422 raeburn 7278: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7279: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7280: $choices{'domexttool'}.
7281: '</span></td>'.
7282: '<td style="text-align: right" class="LC_right_item">'.
7283: '<table><tr>';
7284: foreach my $type (@types) {
7285: $datatable .= '<td style="text-align: left">'.
7286: '<span class="LC_nobreak">'.
1.438 raeburn 7287: '<label><input type="checkbox" name="domexttool"'.
1.422 raeburn 7288: ' value="'.$type.'"'.$domexttool{$type}.' />'.
1.438 raeburn 7289: &mt($type).'</label></span></td>'."\n";
1.422 raeburn 7290: }
7291: $datatable .= '</tr></table></td></tr>'."\n";
1.404 raeburn 7292: $itemcount ++;
1.422 raeburn 7293: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7294: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7295: $choices{'exttool'}.
7296: '</span></td>'.
7297: '<td style="text-align: right" class="LC_right_item">'.
7298: '<table><tr>';
7299: foreach my $type (@types) {
7300: $datatable .= '<td style="text-align: left">'.
7301: '<span class="LC_nobreak">'.
1.438 raeburn 7302: '<label><input type="checkbox" name="exttool"'.
1.422 raeburn 7303: ' value="'.$type.'"'.$exttool{$type}.' />'.
1.438 raeburn 7304: &mt($type).'</label></span></td>'."\n";
1.422 raeburn 7305: }
7306: $datatable .= '</tr></table></td></tr>'."\n";
1.432 raeburn 7307: $itemcount ++;
7308: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7309: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7310: $choices{'crsauthor'}.
7311: '</span></td>'.
7312: '<td style="text-align: right" class="LC_right_item">'.
7313: '<table><tr>';
7314: foreach my $type (@types) {
7315: $datatable .= '<td style="text-align: left">'.
7316: '<span class="LC_nobreak">'.
1.438 raeburn 7317: '<label><input type="checkbox" name="crsauthor"'.
1.432 raeburn 7318: ' value="'.$type.'"'.$crsauthor{$type}.' />'.
1.438 raeburn 7319: &mt($type).'</label></span></td>'."\n";
7320: }
7321: $datatable .= '</tr></table></td></tr>'."\n";
7322: $itemcount ++;
7323: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7324: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7325: $choices{'crseditors'}.
7326: '</span></td>'.
7327: '<td style="text-align: right" class="LC_right_item">'.
7328: '<table><tr>';
7329: my @editors = ('edit','xml','daxe');
7330: my %editornames = &crseditor_titles();
7331: foreach my $editor (@editors) {
7332: $datatable .= '<td style="text-align: left">'.
7333: '<span class="LC_nobreak">'.
7334: '<label><input type="checkbox" name="crseditors"'.
7335: ' value="'.$editor.'"'.$crseditors{$editor}.' />'.
7336: $editornames{$editor}.'</label></span></td>'."\n";
1.432 raeburn 7337: }
7338: $datatable .= '</tr></table></td></tr>'."\n";
1.139 raeburn 7339: }
1.192 raeburn 7340: $$rowtotal += $itemcount;
1.121 raeburn 7341: return $datatable;
1.118 jms 7342: }
7343:
1.438 raeburn 7344: sub crseditor_titles {
7345: return &Apache::lonlocal::texthash(
7346: edit => 'Standard editor (Edit)',
7347: xml => 'Text editor (EditXML)',
7348: daxe => 'Daxe editor (Daxe)',
7349: );
7350: }
7351:
1.429 raeburn 7352: sub print_authordefaults {
7353: my ($position,$dom,$settings,$rowtotal) = @_;
7354: my ($css_class,$datatable,%checkedon,%checkedoff);
7355: my $itemcount = 1;
7356: my %titles = &authordefaults_titles();
7357: if ($position eq 'top') {
7358: my %defaultchecked = (
7359: 'nocodemirror' => 'off',
1.437 raeburn 7360: 'daxecollapse' => 'off',
1.429 raeburn 7361: 'domcoordacc' => 'on',
7362: );
1.437 raeburn 7363: my @toggles = ('nocodemirror','daxecollapse','domcoordacc');
1.429 raeburn 7364: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
7365: \%titles,$itemcount);
7366: my %staticdefaults = (
7367: 'copyright' => 'default',
7368: 'sourceavail' => 'closed',
7369: );
7370: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7371: my %currrights;
7372: foreach my $item ('copyright','sourceavail') {
7373: $currrights{$item} = $staticdefaults{$item};
7374: if (ref($settings) eq 'HASH') {
7375: if (exists($settings->{$item})) {
7376: $currrights{$item} = $settings->{$item};
7377: }
7378: }
7379: }
7380: $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
7381: '<span class="LC_nobreak">'.$titles{'copyright'}.
7382: '</span></td><td class="LC_right_item">'.
7383: &selectbox('copyright',$currrights{'copyright'},'',
7384: \&Apache::loncommon::copyrightdescription,
7385: (grep !/^priv|custom$/,(&Apache::loncommon::copyrightids))).
7386: '</td></tr>'."\n";
7387: $itemcount ++;
7388: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7389: $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
7390: '<span class="LC_nobreak">'.$titles{'sourceavail'}.
7391: '</span></td><td class="LC_right_item">'.
7392: &selectbox('sourceavail',$currrights{'sourceavail'},'',
7393: \&Apache::loncommon::source_copyrightdescription,
7394: (&Apache::loncommon::source_copyrightids)).
7395: '</td></tr>'."\n";
7396: } else {
7397: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7398: my $curreditors;
7399: my %staticdefaults = (
7400: editors => ['edit','xml'],
7401: authorquota => 500,
7402: webdav => 0,
7403: );
7404: my $curreditors = $staticdefaults{'editors'};
7405: if ((ref($settings) eq 'HASH') &&
7406: (ref($settings->{'editors'}) eq 'ARRAY')) {
7407: $curreditors = $settings->{'editors'};
7408: } else {
7409: $curreditors = $staticdefaults{'editors'};
7410: }
7411: my @editors = ('edit','xml','daxe');
7412: $datatable = '<tr'.$css_class.'>'."\n".
7413: '<td>'.$titles{'editors'}.'</td>'."\n".
7414: '<td class="LC_left_item">'."\n".
7415: '<span class="LC_nobreak">';
7416: foreach my $editor (@editors) {
7417: my $checked;
7418: if (grep(/^\Q$editor\E$/,@{$curreditors})) {
7419: $checked = ' checked="checked"';
7420: }
7421: $datatable .= '<label>'.
7422: '<input type="checkbox" name="author_editors" '.
7423: $checked.' value="'.$editor.'" '.
7424: 'onclick="javascript:checkEditors(this.form,'."'author_editors'".',this);" />'.
7425: $titles{$editor}.'</label> ';
7426: }
7427: $datatable .= '</span>'."\n".'</td>'."\n".'</tr>'."\n";
7428: $itemcount ++;
7429: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7430: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7431: my @insttypes;
7432: if (ref($types) eq 'ARRAY') {
7433: @insttypes = @{$types};
7434: }
7435: my $typecount = 0;
7436: my %domconf = &Apache::lonnet::get_dom('configuration',['quotas'],$dom);
7437: my @items = ('webdav','authorquota');
7438: my %quotas;
7439: if (ref($domconf{'quotas'}) eq 'HASH') {
7440: %quotas = %{$domconf{'quotas'}};
7441: foreach my $item (@items) {
7442: if (ref($quotas{$item}) eq 'HASH') {
7443: foreach my $type (@insttypes,'default') {
7444: if ($item eq 'authorquota') {
7445: if ($quotas{$item}{$type} !~ /^\d+$/) {
7446: $quotas{$item}{$type} = $staticdefaults{$item};
7447: }
7448: } elsif ($item eq 'webdav') {
7449: if ($quotas{$item}{$type} !~ /^(0|1)$/) {
7450: $quotas{$item}{$type} = $staticdefaults{$item};
7451: }
7452: }
7453: }
7454: } else {
7455: foreach my $type (@insttypes,'default') {
7456: $quotas{$item}{$type} = $staticdefaults{$item};
7457: }
7458: }
7459: }
7460: } else {
7461: foreach my $item (@items) {
7462: foreach my $type (@insttypes,'default') {
7463: $quotas{$item}{$type} = $staticdefaults{$item};
7464: }
7465: }
7466: }
7467: if (ref($usertypes) eq 'HASH') {
7468: my $numinrow = 4;
7469: my $onclick = '';
7470: $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
7471: $numinrow,$othertitle,'authorquota',
7472: \$itemcount,$onclick);
7473: $itemcount ++;
7474: $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
7475: $numinrow,$othertitle,'webdav',
7476: \$itemcount);
7477: $itemcount ++;
7478: }
7479: my $checkedno = ' checked="checked"';
7480: my ($checkedon,$checkedoff);
7481: if (ref($quotas{'webdav'}) eq 'HASH') {
1.436 raeburn 7482: if ($quotas{'webdav'}{'_LC_adv'} =~ /^0|1$/) {
1.429 raeburn 7483: if ($quotas{'webdav'}{'_LC_adv'}) {
7484: $checkedon = $checkedno;
7485: } else {
7486: $checkedoff = $checkedno;
7487: }
7488: undef($checkedno);
7489: }
7490: }
7491: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7492: $datatable .= '<tr'.$css_class.'>'.
7493: '<td>'.$titles{'webdav_LC_adv'}.'<br />'.
7494: $titles{'webdav_LC_adv_over'}.
7495: '</td>'.
7496: '<td class="LC_left_item">';
7497: foreach my $option ('none','off','on') {
7498: my ($text,$val,$checked);
7499: if ($option eq 'none') {
7500: $text = $titles{'none'};
7501: $val = '';
7502: $checked = $checkedno;
7503: } elsif ($option eq 'off') {
7504: $text = $titles{'overoff'};
7505: $val = 0;
7506: $checked = $checkedoff;
7507: } elsif ($option eq 'on') {
7508: $text = $titles{'overon'};
7509: $val = 1;
7510: $checked = $checkedon;
1.436 raeburn 7511: }
1.429 raeburn 7512: $datatable .= '<span class="LC_nobreak"><label>'.
7513: '<input type="radio" name="webdav_LC_adv"'.
7514: ' value="'.$val.'"'.$checked.' />'.
7515: $text.'</label></span> ';
7516: }
7517: $datatable .= '</td></tr>';
7518: $itemcount ++;
1.440 raeburn 7519: my %defchecked = (
7520: 'archive' => 'off',
7521: );
7522: my @toggles = ('archive');
7523: (my $archive,$itemcount) = &radiobutton_prefs($settings,['archive'],
7524: {'archive' => 'off'},
7525: \%titles,$itemcount);
7526: $datatable .= $archive."\n";
7527: $itemcount ++;
1.429 raeburn 7528: }
7529: $$rowtotal += $itemcount;
7530: return $datatable;
7531: }
7532:
7533: sub authordefaults_titles {
7534: return &Apache::lonlocal::texthash(
7535: copyright => 'Copyright/Distribution',
7536: sourceavail => ' Source Available',
7537: editors => 'Available Editors',
7538: webdav => 'WebDAV',
7539: authorquota => 'Authoring Space quotas (MB)',
7540: nocodemirror => 'Deactivate CodeMirror for EditXML editor',
1.437 raeburn 7541: daxecollapse => 'Daxe editor: LON-CAPA standard menus start collapsed',
1.429 raeburn 7542: domcoordacc => 'Dom. Coords. can enter Authoring Spaces in domain',
7543: edit => 'Standard editor (Edit)',
7544: xml => 'Text editor (EditXML)',
7545: daxe => 'Daxe editor (Daxe)',
7546: webdav_LC_adv => 'WebDAV access for LON-CAPA "advanced" users',
7547: webdav_LC_adv_over => '(overrides access based on affiliation, if set)',
7548: none => 'No override set',
7549: overon => 'Override -- webDAV on',
1.436 raeburn 7550: overoff => 'Override -- webDAV off',
1.440 raeburn 7551: archive => 'Authors can download tar.gz file of Authoring Space',
1.429 raeburn 7552: );
7553: }
7554:
7555: sub selectbox {
7556: my ($name,$value,$readonly,$functionref,@idlist)=@_;
7557: my $selout = '<select name="'.$name.'">';
7558: foreach my $id (@idlist) {
7559: $selout.='<option value="'.$id.'"';
7560: if ($id eq $value) {
7561: $selout.=' selected="selected"';
7562: }
7563: if ($readonly) {
7564: $selout .= ' disabled="disabled"';
7565: }
7566: $selout.='>'.&{$functionref}($id).'</option>';
7567: }
7568: $selout.='</select>';
7569: return $selout;
7570: }
7571:
1.231 raeburn 7572: sub print_selfenrollment {
7573: my ($position,$dom,$settings,$rowtotal) = @_;
7574: my ($css_class,$datatable);
7575: my $itemcount = 1;
1.271 raeburn 7576: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 7577: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 7578: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
7579: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 7580: my @rows;
7581: my $key;
7582: if ($position eq 'top') {
7583: $key = 'admin';
7584: if (ref($rowsref) eq 'ARRAY') {
7585: @rows = @{$rowsref};
7586: }
7587: } elsif ($position eq 'middle') {
7588: $key = 'default';
7589: @rows = ('types','registered','approval','limit');
7590: }
7591: foreach my $row (@rows) {
7592: if (defined($titlesref->{$row})) {
7593: $itemcount ++;
7594: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7595: $datatable .= '<tr'.$css_class.'>'.
7596: '<td>'.$titlesref->{$row}.'</td>'.
7597: '<td class="LC_left_item">'.
7598: '<table><tr>';
7599: my (%current,%currentcap);
7600: if (ref($settings) eq 'HASH') {
7601: if (ref($settings->{$key}) eq 'HASH') {
7602: foreach my $type (@types) {
7603: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7604: $current{$type} = $settings->{$key}->{$type}->{$row};
7605: }
7606: if (($row eq 'limit') && ($key eq 'default')) {
7607: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7608: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
7609: }
7610: }
7611: }
7612: }
7613: }
7614: my %roles = (
7615: '0' => &Apache::lonnet::plaintext('dc'),
7616: );
7617:
7618: foreach my $type (@types) {
7619: unless (($row eq 'registered') && ($key eq 'default')) {
7620: $datatable .= '<th>'.&mt($type).'</th>';
7621: }
7622: }
7623: unless (($row eq 'registered') && ($key eq 'default')) {
7624: $datatable .= '</tr><tr>';
7625: }
7626: foreach my $type (@types) {
7627: if ($type eq 'community') {
7628: $roles{'1'} = &mt('Community personnel');
7629: } else {
7630: $roles{'1'} = &mt('Course personnel');
7631: }
7632: $datatable .= '<td style="vertical-align: top">';
7633: if ($position eq 'top') {
7634: my %checked;
7635: if ($current{$type} eq '0') {
7636: $checked{'0'} = ' checked="checked"';
7637: } else {
7638: $checked{'1'} = ' checked="checked"';
7639: }
7640: foreach my $role ('1','0') {
7641: $datatable .= '<span class="LC_nobreak"><label>'.
7642: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
7643: 'value="'.$role.'"'.$checked{$role}.' />'.
7644: $roles{$role}.'</label></span> ';
7645: }
7646: } else {
7647: if ($row eq 'types') {
7648: my %checked;
7649: if ($current{$type} =~ /^(all|dom)$/) {
7650: $checked{$1} = ' checked="checked"';
7651: } else {
7652: $checked{''} = ' checked="checked"';
7653: }
7654: foreach my $val ('','dom','all') {
7655: $datatable .= '<span class="LC_nobreak"><label>'.
7656: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7657: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7658: }
7659: } elsif ($row eq 'registered') {
7660: my %checked;
7661: if ($current{$type} eq '1') {
7662: $checked{'1'} = ' checked="checked"';
7663: } else {
7664: $checked{'0'} = ' checked="checked"';
7665: }
7666: foreach my $val ('0','1') {
7667: $datatable .= '<span class="LC_nobreak"><label>'.
7668: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7669: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7670: }
7671: } elsif ($row eq 'approval') {
7672: my %checked;
7673: if ($current{$type} =~ /^([12])$/) {
7674: $checked{$1} = ' checked="checked"';
7675: } else {
7676: $checked{'0'} = ' checked="checked"';
7677: }
7678: for my $val (0..2) {
7679: $datatable .= '<span class="LC_nobreak"><label>'.
7680: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7681: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7682: }
7683: } elsif ($row eq 'limit') {
7684: my %checked;
7685: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
7686: $checked{$1} = ' checked="checked"';
7687: } else {
7688: $checked{'none'} = ' checked="checked"';
7689: }
7690: my $cap;
7691: if ($currentcap{$type} =~ /^\d+$/) {
7692: $cap = $currentcap{$type};
7693: }
7694: foreach my $val ('none','allstudents','selfenrolled') {
7695: $datatable .= '<span class="LC_nobreak"><label>'.
7696: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7697: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7698: }
7699: $datatable .= '<br />'.
7700: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
7701: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
7702: '</span>';
7703: }
7704: }
7705: $datatable .= '</td>';
7706: }
7707: $datatable .= '</tr>';
7708: }
7709: $datatable .= '</table></td></tr>';
7710: }
7711: } elsif ($position eq 'bottom') {
1.235 raeburn 7712: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
7713: }
7714: $$rowtotal += $itemcount;
7715: return $datatable;
7716: }
7717:
7718: sub print_validation_rows {
7719: my ($caller,$dom,$settings,$rowtotal) = @_;
7720: my ($itemsref,$namesref,$fieldsref);
7721: if ($caller eq 'selfenroll') {
7722: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
7723: } elsif ($caller eq 'requestcourses') {
7724: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
7725: }
7726: my %currvalidation;
7727: if (ref($settings) eq 'HASH') {
7728: if (ref($settings->{'validation'}) eq 'HASH') {
7729: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 7730: }
1.235 raeburn 7731: }
7732: my $datatable;
7733: my $itemcount = 0;
7734: foreach my $item (@{$itemsref}) {
7735: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7736: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7737: $namesref->{$item}.
7738: '</span></td>'.
7739: '<td class="LC_left_item">';
7740: if (($item eq 'url') || ($item eq 'button')) {
7741: $datatable .= '<span class="LC_nobreak">'.
7742: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
7743: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
7744: } elsif ($item eq 'fields') {
7745: my @currfields;
7746: if (ref($currvalidation{$item}) eq 'ARRAY') {
7747: @currfields = @{$currvalidation{$item}};
7748: }
7749: foreach my $field (@{$fieldsref}) {
7750: my $check = '';
7751: if (grep(/^\Q$field\E$/,@currfields)) {
7752: $check = ' checked="checked"';
7753: }
7754: $datatable .= '<span class="LC_nobreak"><label>'.
7755: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
7756: ' value="'.$field.'"'.$check.' />'.$field.
7757: '</label></span> ';
7758: }
7759: } elsif ($item eq 'markup') {
1.334 raeburn 7760: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 7761: $currvalidation{$item}.
1.231 raeburn 7762: '</textarea>';
1.235 raeburn 7763: }
7764: $datatable .= '</td></tr>'."\n";
7765: if (ref($rowtotal)) {
1.231 raeburn 7766: $itemcount ++;
7767: }
7768: }
1.235 raeburn 7769: if ($caller eq 'requestcourses') {
7770: my %currhash;
1.248 raeburn 7771: if (ref($settings) eq 'HASH') {
7772: if (ref($settings->{'validation'}) eq 'HASH') {
7773: if ($settings->{'validation'}{'dc'} ne '') {
7774: $currhash{$settings->{'validation'}{'dc'}} = 1;
7775: }
1.235 raeburn 7776: }
7777: }
7778: my $numinrow = 2;
7779: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
7780: 'validationdc',%currhash);
1.247 raeburn 7781: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 7782: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 7783: if ($numdc > 1) {
1.247 raeburn 7784: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 7785: } else {
1.247 raeburn 7786: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 7787: }
1.247 raeburn 7788: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 7789: $itemcount ++;
7790: }
7791: if (ref($rowtotal)) {
7792: $$rowtotal += $itemcount;
7793: }
1.231 raeburn 7794: return $datatable;
7795: }
7796:
1.357 raeburn 7797: sub print_privacy {
7798: my ($position,$dom,$settings,$rowtotal) = @_;
7799: my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
7800: my $itemcount = 0;
1.417 raeburn 7801: if ($position eq 'top') {
7802: $numinrow = 2;
7803: } else {
1.357 raeburn 7804: @items = ('domain','author','course','community');
7805: %names = &Apache::lonlocal::texthash (
7806: domain => 'Assigned domain role(s)',
7807: author => 'Assigned co-author role(s)',
7808: course => 'Assigned course role(s)',
1.416 raeburn 7809: community => 'Assigned community role(s)',
1.357 raeburn 7810: );
7811: $numinrow = 4;
7812: ($othertitle,$usertypes,$types) =
7813: &Apache::loncommon::sorted_inst_types($dom);
7814: }
7815: if (($position eq 'top') || ($position eq 'middle')) {
7816: my (%by_ip,%by_location,@intdoms,@instdoms);
7817: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
7818: if ($position eq 'top') {
7819: my %curr;
7820: my @options = ('none','user','domain','auto');
7821: my %titles = &Apache::lonlocal::texthash (
7822: none => 'Not allowed',
7823: user => 'User authorizes',
7824: domain => 'DC authorizes',
7825: auto => 'Unrestricted',
7826: instdom => 'Other domain shares institution/provider',
7827: extdom => 'Other domain has different institution/provider',
1.418 raeburn 7828: notify => 'Notify when role needs authorization',
1.357 raeburn 7829: );
7830: my %names = &Apache::lonlocal::texthash (
7831: domain => 'Domain role',
7832: author => 'Co-author role',
7833: course => 'Course role',
7834: community => 'Community role',
7835: );
7836: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7837: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7838: foreach my $domtype ('instdom','extdom') {
7839: my (%checked,$skip);
7840: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7841: $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
7842: '<td class="LC_left_item">';
7843: if ($domtype eq 'instdom') {
7844: unless (@instdoms > 1) {
7845: $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
7846: $skip = 1;
7847: }
7848: } elsif ($domtype eq 'extdom') {
7849: if (keys(%by_location) == 0) {
7850: $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
7851: $skip = 1;
7852: }
7853: }
7854: unless ($skip) {
7855: foreach my $roletype ('domain','author','course','community') {
7856: $checked{'auto'} = ' checked="checked"';
7857: if (ref($settings) eq 'HASH') {
7858: if (ref($settings->{approval}) eq 'HASH') {
7859: if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
7860: if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
7861: $checked{$1} = ' checked="checked"';
7862: $checked{'auto'} = '';
7863: }
7864: }
7865: }
7866: }
7867: $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
7868: foreach my $option (@options) {
7869: $datatable .= '<span class="LC_nobreak"><label>'.
7870: '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
7871: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
7872: '</label></span> ';
7873: }
7874: $datatable .= '</fieldset>';
7875: }
7876: }
7877: $datatable .= '</td></tr>';
7878: $itemcount ++;
7879: }
1.417 raeburn 7880: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7881: $datatable .= '<tr'.$css_class.'><td>'.$titles{'notify'}.'</td>'.
7882: '<td class="LC_left_item">';
7883: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7884: my %curr;
7885: if (ref($settings) eq 'HASH') {
7886: if ($settings->{'notify'} ne '') {
7887: map {$curr{$_}=1;} split(/,/,$settings->{'notify'});
7888: }
7889: }
7890: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7891: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
7892: 'privacy_notify',%curr);
7893: if ($numdc > 0) {
7894: $datatable .= $table;
7895: } else {
7896: $datatable .= &mt('There are no active Domain Coordinators');
7897: }
7898: } else {
7899: $datatable .= &mt('Nothing to set here, as there are no other domains');
7900: }
7901: $datatable .='</td></tr>';
1.357 raeburn 7902: } elsif ($position eq 'middle') {
7903: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7904: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7905: foreach my $item (@{$types}) {
7906: $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
7907: $numinrow,$itemcount,'','','','','',
7908: '',$usertypes->{$item});
7909: $itemcount ++;
7910: }
7911: }
7912: $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
7913: $numinrow,$itemcount,'','','','','',
7914: '',$othertitle);
7915: $itemcount ++;
7916: } else {
1.360 raeburn 7917: my (@insttypes,%insttitles);
7918: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7919: @insttypes = @{$types};
7920: %insttitles = %{$usertypes};
7921: }
7922: foreach my $item (@insttypes,'default') {
7923: my $title;
7924: if ($item eq 'default') {
7925: $title = $othertitle;
7926: } else {
7927: $title = $insttitles{$item};
7928: }
7929: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7930: $datatable .= '<tr'.$css_class.'>'.
7931: '<td class="LC_left_item">'.$title.'</td>'.
7932: '<td class="LC_left_item">'.
7933: &mt('Nothing to set here, as there are no other domains').
7934: '</td></tr>';
7935: $itemcount ++;
7936: }
1.357 raeburn 7937: }
7938: }
7939: } else {
7940: my $prefix;
7941: if ($position eq 'lower') {
7942: $prefix = 'priv';
7943: } else {
7944: $prefix = 'unpriv';
7945: }
7946: foreach my $item (@items) {
7947: $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
7948: $numinrow,$itemcount,'','','','','',
7949: '',$names{$item});
7950: $itemcount ++;
7951: }
7952: }
7953: if (ref($rowtotal)) {
7954: $$rowtotal += $itemcount;
7955: }
7956: return $datatable;
7957: }
7958:
1.354 raeburn 7959: sub print_passwords {
7960: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
7961: my ($datatable,$css_class);
7962: my $itemcount = 0;
7963: my %titles = &Apache::lonlocal::texthash (
7964: captcha => '"Forgot Password" CAPTCHA validation',
7965: link => 'Reset link expiration (hours)',
7966: case => 'Case-sensitive usernames/e-mail',
7967: prelink => 'Information required (form 1)',
7968: postlink => 'Information required (form 2)',
7969: emailsrc => 'LON-CAPA e-mail address type(s)',
7970: customtext => 'Domain specific text (HTML)',
7971: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
7972: intauth_check => 'Check bcrypt cost if authenticated',
7973: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
7974: permanent => 'Permanent e-mail address',
7975: critical => 'Critical notification address',
7976: notify => 'Notification address',
7977: min => 'Minimum password length',
7978: max => 'Maximum password length',
7979: chars => 'Required characters',
7980: expire => 'Password expiration (days)',
1.356 raeburn 7981: numsaved => 'Number of previous passwords to save and disallow reuse',
1.354 raeburn 7982: );
7983: if ($position eq 'top') {
7984: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7985: my $shownlinklife = 2;
7986: my $prelink = 'both';
7987: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
7988: if (ref($settings) eq 'HASH') {
7989: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
7990: $shownlinklife = $settings->{resetlink};
7991: }
7992: if (ref($settings->{resetcase}) eq 'ARRAY') {
7993: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
7994: }
7995: if ($settings->{resetprelink} =~ /^(both|either)$/) {
7996: $prelink = $settings->{resetprelink};
7997: }
7998: if (ref($settings->{resetpostlink}) eq 'HASH') {
7999: %postlink = %{$settings->{resetpostlink}};
8000: }
8001: if (ref($settings->{resetemail}) eq 'ARRAY') {
8002: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
8003: }
8004: if ($settings->{resetremove}) {
8005: $nostdtext = 1;
8006: }
8007: if ($settings->{resetcustom}) {
8008: $customurl = $settings->{resetcustom};
8009: }
8010: } else {
8011: if (ref($types) eq 'ARRAY') {
8012: foreach my $item (@{$types}) {
8013: $casesens{$item} = 1;
8014: $postlink{$item} = ['username','email'];
8015: }
8016: }
8017: $casesens{'default'} = 1;
8018: $postlink{'default'} = ['username','email'];
8019: $prelink = 'both';
8020: %emailsrc = (
8021: permanent => 1,
8022: critical => 1,
8023: notify => 1,
8024: );
8025: }
8026: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
8027: $itemcount ++;
8028: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8029: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
8030: '<td class="LC_left_item">'.
8031: '<input type="textbox" value="'.$shownlinklife.'" '.
8032: 'name="passwords_link" size="3" /></td></tr>';
8033: $itemcount ++;
8034: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8035: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
8036: '<td class="LC_left_item">';
8037: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8038: foreach my $item (@{$types}) {
8039: my $checkedcase;
8040: if ($casesens{$item}) {
8041: $checkedcase = ' checked="checked"';
8042: }
8043: $datatable .= '<span class="LC_nobreak"><label>'.
8044: '<input type="checkbox" name="passwords_case_sensitive" value="'.
8045: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369 raeburn 8046: '</span> ';
1.354 raeburn 8047: }
8048: }
8049: my $checkedcase;
8050: if ($casesens{'default'}) {
8051: $checkedcase = ' checked="checked"';
8052: }
8053: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
8054: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
8055: $othertitle.'</label></span></td>';
8056: $itemcount ++;
8057: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8058: my %checkedpre = (
8059: both => ' checked="checked"',
8060: either => '',
8061: );
8062: if ($prelink eq 'either') {
8063: $checkedpre{either} = ' checked="checked"';
8064: $checkedpre{both} = '';
8065: }
8066: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
8067: '<td class="LC_left_item"><span class="LC_nobreak">'.
8068: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
8069: &mt('Both username and e-mail address').'</label></span> '.
8070: '<span class="LC_nobreak"><label>'.
8071: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
8072: &mt('Either username or e-mail address').'</label></span></td></tr>';
8073: $itemcount ++;
8074: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8075: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
8076: '<td class="LC_left_item">';
8077: my %postlinked;
8078: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8079: foreach my $item (@{$types}) {
8080: undef(%postlinked);
8081: $datatable .= '<fieldset style="display: inline-block;">'.
8082: '<legend>'.$usertypes->{$item}.'</legend>';
8083: if (ref($postlink{$item}) eq 'ARRAY') {
8084: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
8085: }
8086: foreach my $field ('email','username') {
8087: my $checked;
8088: if ($postlinked{$field}) {
8089: $checked = ' checked="checked"';
8090: }
8091: $datatable .= '<span class="LC_nobreak"><label>'.
8092: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
8093: $field.'"'.$checked.' />'.$field.'</label>'.
8094: '<span> ';
8095: }
8096: $datatable .= '</fieldset>';
8097: }
8098: }
8099: if (ref($postlink{'default'}) eq 'ARRAY') {
8100: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
8101: }
8102: $datatable .= '<fieldset style="display: inline-block;">'.
8103: '<legend>'.$othertitle.'</legend>';
8104: foreach my $field ('email','username') {
8105: my $checked;
8106: if ($postlinked{$field}) {
8107: $checked = ' checked="checked"';
8108: }
8109: $datatable .= '<span class="LC_nobreak"><label>'.
8110: '<input type="checkbox" name="passwords_postlink_default" value="'.
8111: $field.'"'.$checked.' />'.$field.'</label>'.
8112: '<span> ';
8113: }
8114: $datatable .= '</fieldset></td></tr>';
8115: $itemcount ++;
8116: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8117: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
8118: '<td class="LC_left_item">';
8119: foreach my $type ('permanent','critical','notify') {
8120: my $checkedemail;
8121: if ($emailsrc{$type}) {
8122: $checkedemail = ' checked="checked"';
8123: }
8124: $datatable .= '<span class="LC_nobreak"><label>'.
8125: '<input type="checkbox" name="passwords_emailsrc" value="'.
8126: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
8127: '<span> ';
8128: }
8129: $datatable .= '</td></tr>';
8130: $itemcount ++;
8131: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8132: my $switchserver = &check_switchserver($dom,$confname);
8133: my ($showstd,$noshowstd);
8134: if ($nostdtext) {
8135: $noshowstd = ' checked="checked"';
8136: } else {
8137: $showstd = ' checked="checked"';
8138: }
8139: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
8140: '<td class="LC_left_item"><span class="LC_nobreak">'.
8141: &mt('Retain standard text:').
8142: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
8143: &mt('Yes').'</label>'.' '.
8144: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
8145: &mt('No').'</label></span><br />'.
8146: '<span class="LC_fontsize_small">'.
8147: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
8148: &mt('Include custom text:');
8149: if ($customurl) {
1.369 raeburn 8150: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354 raeburn 8151: undef,undef,undef,undef,'background-color:#ffffff');
8152: $datatable .= '<span class="LC_nobreak"> '.$link.
8153: '<label><input type="checkbox" name="passwords_custom_del"'.
8154: ' value="1" />'.&mt('Delete?').'</label></span>'.
8155: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
8156: }
8157: if ($switchserver) {
8158: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
8159: } else {
8160: $datatable .='<span class="LC_nobreak"> '.
8161: '<input type="file" name="passwords_customfile" /></span>';
8162: }
8163: $datatable .= '</td></tr>';
8164: } elsif ($position eq 'middle') {
8165: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
8166: my @items = ('intauth_cost','intauth_check','intauth_switch');
8167: my %defaults;
8168: if (ref($domconf{'defaults'}) eq 'HASH') {
8169: %defaults = %{$domconf{'defaults'}};
8170: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
8171: $defaults{'intauth_cost'} = 10;
8172: }
8173: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
8174: $defaults{'intauth_check'} = 0;
8175: }
8176: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
8177: $defaults{'intauth_switch'} = 0;
8178: }
8179: } else {
8180: %defaults = (
8181: 'intauth_cost' => 10,
8182: 'intauth_check' => 0,
8183: 'intauth_switch' => 0,
8184: );
8185: }
8186: foreach my $item (@items) {
8187: if ($itemcount%2) {
8188: $css_class = '';
8189: } else {
8190: $css_class = ' class="LC_odd_row" ';
8191: }
8192: $datatable .= '<tr'.$css_class.'>'.
8193: '<td><span class="LC_nobreak">'.$titles{$item}.
8194: '</span></td><td class="LC_left_item" colspan="3">';
8195: if ($item eq 'intauth_switch') {
8196: my @options = (0,1,2);
8197: my %optiondesc = &Apache::lonlocal::texthash (
8198: 0 => 'No',
8199: 1 => 'Yes',
8200: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
8201: );
8202: $datatable .= '<table width="100%">';
8203: foreach my $option (@options) {
8204: my $checked = ' ';
8205: if ($defaults{$item} eq $option) {
8206: $checked = ' checked="checked"';
8207: }
8208: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8209: '<label><input type="radio" name="'.$item.
8210: '" value="'.$option.'"'.$checked.' />'.
8211: $optiondesc{$option}.'</label></span></td></tr>';
8212: }
8213: $datatable .= '</table>';
8214: } elsif ($item eq 'intauth_check') {
8215: my @options = (0,1,2);
8216: my %optiondesc = &Apache::lonlocal::texthash (
8217: 0 => 'No',
8218: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
8219: 2 => 'Yes, disallow login if stored cost is less than domain default',
8220: );
8221: $datatable .= '<table width="100%">';
8222: foreach my $option (@options) {
8223: my $checked = ' ';
8224: my $onclick;
8225: if ($defaults{$item} eq $option) {
8226: $checked = ' checked="checked"';
8227: }
8228: if ($option == 2) {
8229: $onclick = ' onclick="javascript:warnIntAuth(this);"';
8230: }
8231: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8232: '<label><input type="radio" name="'.$item.
8233: '" value="'.$option.'"'.$checked.$onclick.' />'.
8234: $optiondesc{$option}.'</label></span></td></tr>';
8235: }
8236: $datatable .= '</table>';
8237: } else {
8238: $datatable .= '<input type="text" name="'.$item.'" value="'.
8239: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
8240: }
8241: $datatable .= '</td></tr>';
8242: $itemcount ++;
8243: }
8244: } elsif ($position eq 'lower') {
1.405 raeburn 8245: $datatable .= &password_rules('passwords',\$itemcount,$settings);
1.354 raeburn 8246: } else {
1.359 raeburn 8247: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8248: my %ownerchg = (
8249: by => {},
8250: for => {},
8251: );
8252: my %ownertitles = &Apache::lonlocal::texthash (
8253: by => 'Course owner status(es) allowed',
8254: for => 'Student status(es) allowed',
8255: );
1.354 raeburn 8256: if (ref($settings) eq 'HASH') {
1.359 raeburn 8257: if (ref($settings->{crsownerchg}) eq 'HASH') {
8258: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
8259: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
8260: }
8261: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
8262: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
8263: }
1.354 raeburn 8264: }
8265: }
8266: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8267: $datatable .= '<tr '.$css_class.'>'.
8268: '<td>'.
8269: &mt('Requirements').'<ul>'.
1.359 raeburn 8270: '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354 raeburn 8271: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
8272: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359 raeburn 8273: '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354 raeburn 8274: '</ul>'.
8275: '</td>'.
1.359 raeburn 8276: '<td class="LC_left_item">';
8277: foreach my $item ('by','for') {
8278: $datatable .= '<fieldset style="display: inline-block;">'.
8279: '<legend>'.$ownertitles{$item}.'</legend>';
8280: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8281: foreach my $type (@{$types}) {
8282: my $checked;
8283: if ($ownerchg{$item}{$type}) {
8284: $checked = ' checked="checked"';
8285: }
8286: $datatable .= '<span class="LC_nobreak"><label>'.
8287: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
8288: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369 raeburn 8289: '</span> ';
1.359 raeburn 8290: }
8291: }
8292: my $checked;
8293: if ($ownerchg{$item}{'default'}) {
8294: $checked = ' checked="checked"';
8295: }
8296: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
8297: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
8298: $othertitle.'</label></span></fieldset>';
8299: }
8300: $datatable .= '</td></tr>';
1.354 raeburn 8301: }
8302: return $datatable;
8303: }
8304:
1.405 raeburn 8305: sub password_rules {
8306: my ($prefix,$itemcountref,$settings) = @_;
8307: my ($min,$max,%chars,$expire,$numsaved,$numinrow);
8308: my %titles;
8309: if ($prefix eq 'passwords') {
8310: %titles = &Apache::lonlocal::texthash (
8311: min => 'Minimum password length',
8312: max => 'Maximum password length',
8313: chars => 'Required characters',
8314: );
1.421 raeburn 8315: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 8316: %titles = &Apache::lonlocal::texthash (
8317: min => 'Minimum secret length',
8318: max => 'Maximum secret length',
8319: chars => 'Required characters',
8320: );
8321: }
8322: $min = $Apache::lonnet::passwdmin;
8323: my $datatable;
8324: my $itemcount;
8325: if (ref($itemcountref)) {
8326: $itemcount = $$itemcountref;
8327: }
8328: if (ref($settings) eq 'HASH') {
8329: if ($settings->{min}) {
8330: $min = $settings->{min};
8331: }
8332: if ($settings->{max}) {
8333: $max = $settings->{max};
8334: }
8335: if (ref($settings->{chars}) eq 'ARRAY') {
8336: map { $chars{$_} = 1; } (@{$settings->{chars}});
8337: }
1.425 raeburn 8338: if ($prefix eq 'passwords') {
1.405 raeburn 8339: if ($settings->{expire}) {
8340: $expire = $settings->{expire};
8341: }
8342: if ($settings->{numsaved}) {
8343: $numsaved = $settings->{numsaved};
8344: }
8345: }
8346: }
8347: my %rulenames = &Apache::lonlocal::texthash(
8348: uc => 'At least one upper case letter',
8349: lc => 'At least one lower case letter',
8350: num => 'At least one number',
8351: spec => 'At least one non-alphanumeric',
8352: );
8353: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
8354: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
8355: '<td class="LC_left_item"><span class="LC_nobreak">'.
8356: '<input type="text" name="'.$prefix.'_min" value="'.$min.'" size="3" '.
8357: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8358: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
8359: '</span></td></tr>';
8360: $itemcount ++;
8361: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8362: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
8363: '<td class="LC_left_item"><span class="LC_nobreak">'.
8364: '<input type="text" name="'.$prefix.'_max" value="'.$max.'" size="3" '.
8365: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8366: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
8367: '</span></td></tr>';
8368: $itemcount ++;
8369: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8370: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
8371: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
8372: '</span></td>';
8373: my $numinrow = 2;
8374: my @possrules = ('uc','lc','num','spec');
8375: $datatable .= '<td class="LC_left_item"><table>';
8376: for (my $i=0; $i<@possrules; $i++) {
8377: my ($rem,$checked);
8378: if ($chars{$possrules[$i]}) {
8379: $checked = ' checked="checked"';
8380: }
8381: $rem = $i%($numinrow);
8382: if ($rem == 0) {
8383: if ($i > 0) {
8384: $datatable .= '</tr>';
8385: }
8386: $datatable .= '<tr>';
8387: }
8388: $datatable .= '<td><span class="LC_nobreak"><label>'.
8389: '<input type="checkbox" name="'.$prefix.'_chars" value="'.$possrules[$i].'"'.$checked.' />'.
8390: $rulenames{$possrules[$i]}.'</label></span></td>';
8391: }
8392: my $rem = @possrules%($numinrow);
8393: my $colsleft = $numinrow - $rem;
8394: if ($colsleft > 1 ) {
8395: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8396: ' </td>';
8397: } elsif ($colsleft == 1) {
8398: $datatable .= '<td class="LC_left_item"> </td>';
8399: }
8400: $datatable .='</table></td></tr>';
8401: $itemcount ++;
8402: if ($prefix eq 'passwords') {
8403: $titles{'expire'} = &mt('Password expiration (days)');
8404: $titles{'numsaved'} = &mt('Number of previous passwords to save and disallow reuse');
8405: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8406: $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
8407: '<td class="LC_left_item"><span class="LC_nobreak">'.
8408: '<input type="text" name="'.$prefix.'_expire" value="'.$expire.'" size="4" '.
8409: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8410: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
8411: '</span></td></tr>';
8412: $itemcount ++;
8413: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8414: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
8415: '<td class="LC_left_item"><span class="LC_nobreak">'.
8416: '<input type="text" name="'.$prefix.'_numsaved" value="'.$numsaved.'" size="3" '.
8417: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8418: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
8419: '</span></td></tr>';
8420: $itemcount ++;
8421: }
8422: if (ref($itemcountref)) {
8423: $$itemcountref += $itemcount;
8424: }
8425: return $datatable;
8426: }
8427:
1.373 raeburn 8428: sub print_wafproxy {
8429: my ($position,$dom,$settings,$rowtotal) = @_;
8430: my $css_class;
8431: my $itemcount = 0;
8432: my $datatable;
8433: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 8434: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
1.374 raeburn 8435: my %lt = &wafproxy_titles();
1.373 raeburn 8436: foreach my $server (sort(keys(%servers))) {
8437: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
1.381 raeburn 8438: next if ($serverhome eq '');
1.373 raeburn 8439: my $serverdom;
8440: if ($serverhome ne $server) {
8441: $serverdom = &Apache::lonnet::host_domain($serverhome);
1.381 raeburn 8442: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
8443: $othercontrol{$server} = $serverdom;
8444: }
1.373 raeburn 8445: } else {
8446: $serverdom = &Apache::lonnet::host_domain($server);
1.381 raeburn 8447: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
1.373 raeburn 8448: if ($serverdom ne $dom) {
8449: $othercontrol{$server} = $serverdom;
8450: } else {
8451: $setdom = 1;
8452: if (ref($settings) eq 'HASH') {
8453: if (ref($settings->{'alias'}) eq 'HASH') {
8454: $aliases{$dom} = $settings->{'alias'};
1.381 raeburn 8455: if ($aliases{$dom} ne '') {
8456: $showdom = 1;
8457: }
1.373 raeburn 8458: }
1.388 raeburn 8459: if (ref($settings->{'saml'}) eq 'HASH') {
8460: $saml{$dom} = $settings->{'saml'};
8461: }
1.373 raeburn 8462: }
8463: }
8464: }
8465: }
1.381 raeburn 8466: if ($setdom) {
8467: %{$values{$dom}} = ();
8468: if (ref($settings) eq 'HASH') {
8469: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8470: $values{$dom}{$item} = $settings->{$item};
8471: }
8472: }
8473: }
1.373 raeburn 8474: if (keys(%othercontrol)) {
8475: %otherdoms = reverse(%othercontrol);
8476: foreach my $domain (keys(%otherdoms)) {
8477: %{$values{$domain}} = ();
8478: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
1.383 raeburn 8479: if (ref($config{'wafproxy'}) eq 'HASH') {
8480: $aliases{$domain} = $config{'wafproxy'}{'alias'};
1.425 raeburn 8481: if (exists($config{'wafproxy'}{'saml'})) {
1.388 raeburn 8482: $saml{$domain} = $config{'wafproxy'}{'saml'};
8483: }
1.383 raeburn 8484: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8485: $values{$domain}{$item} = $config{'wafproxy'}{$item};
1.373 raeburn 8486: }
8487: }
8488: }
8489: }
8490: if ($position eq 'top') {
8491: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.381 raeburn 8492: my %aliasinfo;
1.373 raeburn 8493: foreach my $server (sort(keys(%servers))) {
1.381 raeburn 8494: $itemcount ++;
8495: my $dom_in_effect;
8496: my $aliasrows = '<tr>'.
1.383 raeburn 8497: '<td class="LC_left_item" style="vertical-align: baseline;">'.
1.433 raeburn 8498: &mt('Hostname').': '.
8499: '<span class="LC_nobreak LC_cusr_emph">'.
8500: &Apache::lonnet::hostname($server).
8501: '</span></td><td> </td>';
1.373 raeburn 8502: if ($othercontrol{$server}) {
1.381 raeburn 8503: $dom_in_effect = $othercontrol{$server};
1.388 raeburn 8504: my ($current,$forsaml);
1.383 raeburn 8505: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
8506: $current = $aliases{$dom_in_effect}{$server};
1.373 raeburn 8507: }
1.388 raeburn 8508: if (ref($saml{$dom_in_effect}) eq 'HASH') {
8509: if ($saml{$dom_in_effect}{$server}) {
8510: $forsaml = 1;
8511: }
8512: }
1.383 raeburn 8513: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8514: &mt('Alias').': ';
1.373 raeburn 8515: if ($current) {
1.381 raeburn 8516: $aliasrows .= $current;
1.388 raeburn 8517: if ($forsaml) {
1.396 raeburn 8518: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
1.388 raeburn 8519: }
1.373 raeburn 8520: } else {
1.383 raeburn 8521: $aliasrows .= &mt('None');
1.373 raeburn 8522: }
1.383 raeburn 8523: $aliasrows .= ' <span class="LC_small">('.
8524: &mt('controlled by domain: [_1]',
8525: '<b>'.$dom_in_effect.'</b>').')</span></td>';
1.373 raeburn 8526: } else {
1.381 raeburn 8527: $dom_in_effect = $dom;
1.388 raeburn 8528: my ($current,$samlon,$samloff);
8529: $samloff = ' checked="checked"';
1.373 raeburn 8530: if (ref($aliases{$dom}) eq 'HASH') {
8531: if ($aliases{$dom}{$server}) {
8532: $current = $aliases{$dom}{$server};
8533: }
8534: }
1.388 raeburn 8535: if (ref($saml{$dom}) eq 'HASH') {
8536: if ($saml{$dom}{$server}) {
8537: $samlon = $samloff;
8538: undef($samloff);
8539: }
8540: }
1.383 raeburn 8541: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8542: &mt('Alias').': '.
1.381 raeburn 8543: '<input type="text" name="wafproxy_alias_'.$server.'" '.
1.388 raeburn 8544: 'value="'.$current.'" size="30" />'.
8545: (' 'x2).'<span class="LC_nobreak">'.
1.396 raeburn 8546: &mt('Alias used for SSO Auth').': <label>'.
1.388 raeburn 8547: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
1.425 raeburn 8548: &mt('No').'</label> <label>'.
1.388 raeburn 8549: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
8550: &mt('Yes').'</label></span>'.
1.425 raeburn 8551: '</td>';
1.381 raeburn 8552: }
8553: $aliasrows .= '</tr>';
8554: $aliasinfo{$dom_in_effect} .= $aliasrows;
8555: }
8556: if ($aliasinfo{$dom}) {
8557: my ($onclick,$wafon,$wafoff,$showtable);
8558: $onclick = ' onclick="javascript:toggleWAF();"';
8559: $wafoff = ' checked="checked"';
8560: $showtable = ' style="display:none";';
8561: if ($showdom) {
8562: $wafon = $wafoff;
8563: $wafoff = '';
8564: $showtable = ' style="display:inline;"';
8565: }
8566: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8567: $datatable = '<tr'.$css_class.'>'.
8568: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
8569: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
8570: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
8571: &mt('Yes').'</label>'.(' 'x2).'<label>'.
8572: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
8573: &mt('No').'</label></span></td>'.
8574: '<td class="LC_left_item">'.
8575: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
8576: '</table></td></tr>';
8577: $itemcount++;
8578: }
1.383 raeburn 8579: if (keys(%otherdoms)) {
8580: foreach my $key (sort(keys(%otherdoms))) {
1.381 raeburn 8581: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.383 raeburn 8582: $datatable .= '<tr'.$css_class.'>'.
8583: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
8584: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
8585: '</table></td></tr>';
1.381 raeburn 8586: $itemcount++;
1.373 raeburn 8587: }
8588: }
8589: } else {
1.383 raeburn 8590: my %ip_methods = &remoteip_methods();
1.373 raeburn 8591: if ($setdom) {
8592: $itemcount ++;
8593: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.381 raeburn 8594: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
1.382 raeburn 8595: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
1.381 raeburn 8596: $wafstyle = ' style="display:none;"';
8597: $nowafstyle = ' style="display:table-row;"';
8598: $currwafdisplay = ' style="display: none"';
8599: $wafrangestyle = ' style="display: none"';
8600: $curr_remotip = 'n';
1.382 raeburn 8601: $ssltossl = ' checked="checked"';
1.381 raeburn 8602: if ($showdom) {
8603: $wafstyle = ' style="display:table-row;"';
8604: $nowafstyle = ' style="display:none;"';
8605: if (keys(%{$values{$dom}})) {
8606: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
8607: $curr_remotip = $values{$dom}{remoteip};
8608: }
8609: if ($curr_remotip eq 'h') {
8610: $currwafdisplay = ' style="display:table-row"';
8611: $wafrangestyle = ' style="display:inline-block;"';
8612: }
1.382 raeburn 8613: if ($values{$dom}{'sslopt'}) {
8614: $alltossl = ' checked="checked"';
8615: $ssltossl = '';
8616: }
1.381 raeburn 8617: }
8618: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
8619: $vpndircheck = ' checked="checked"';
8620: $currwafvpn = ' style="display:table-row;"';
8621: $wafrangestyle = ' style="display:inline-block;"';
8622: } else {
8623: $vpnaliascheck = ' checked="checked"';
8624: $currwafvpn = ' style="display:none;"';
8625: }
8626: }
8627: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
8628: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
8629: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
8630: '</tr>'.
8631: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
1.374 raeburn 8632: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
1.381 raeburn 8633: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
1.393 raeburn 8634: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
8635: &mt('Range(s) stored in CIDR notation').'</div></td>'.
1.381 raeburn 8636: '<td class="LC_left_item"><table>'.
8637: '<tr>'.
8638: '<td valign="top">'.$lt{'remoteip'}.': '.
8639: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
8640: foreach my $option ('m','h','n') {
8641: my $sel;
8642: if ($option eq $curr_remotip) {
8643: $sel = ' selected="selected"';
8644: }
8645: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
8646: $ip_methods{$option}.'</option>';
8647: }
8648: $datatable .= '</select></td></tr>'."\n".
8649: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
8650: $lt{'ipheader'}.': '.
8651: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
8652: 'name="wafproxy_ipheader" />'.
8653: '</td></tr>'."\n".
8654: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
1.382 raeburn 8655: $lt{'trusted'}.':<br />'.
1.381 raeburn 8656: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
8657: $values{$dom}{'trusted'}.'</textarea>'.
8658: '</td></tr>'."\n".
8659: '<tr><td><hr /></td></tr>'."\n".
8660: '<tr>'.
8661: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
8662: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
8663: $lt{'vpndirect'}.'</label>'.(' 'x2).
8664: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
8665: $lt{'vpnaliased'}.'</label></span></td></tr>';
8666: foreach my $item ('vpnint','vpnext') {
8667: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
1.382 raeburn 8668: '<td valign="top">'.$lt{$item}.':<br />'.
1.381 raeburn 8669: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
8670: $values{$dom}{$item}.'</textarea>'.
8671: '</td></tr>'."\n";
1.373 raeburn 8672: }
1.382 raeburn 8673: $datatable .= '<tr><td><hr /></td></tr>'."\n".
8674: '<tr>'.
8675: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
8676: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
8677: $lt{'alltossl'}.'</label>'.(' 'x2).
8678: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
8679: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
8680: '</table></td></tr>';
1.373 raeburn 8681: }
8682: if (keys(%otherdoms)) {
8683: foreach my $domain (sort(keys(%otherdoms))) {
8684: $itemcount ++;
8685: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8686: $datatable .= '<tr'.$css_class.'>'.
1.383 raeburn 8687: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
1.374 raeburn 8688: '<td class="LC_left_item"><table>';
1.382 raeburn 8689: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 8690: my $showval = &mt('None');
1.382 raeburn 8691: if ($item eq 'ssl') {
8692: $showval = $lt{'ssltossl'};
8693: }
1.373 raeburn 8694: if ($values{$domain}{$item}) {
1.381 raeburn 8695: $showval = $values{$domain}{$item};
1.382 raeburn 8696: if ($item eq 'ssl') {
8697: $showval = $lt{'alltossl'};
1.383 raeburn 8698: } elsif ($item eq 'remoteip') {
8699: $showval = $ip_methods{$values{$domain}{$item}};
1.382 raeburn 8700: }
1.373 raeburn 8701: }
8702: $datatable .= '<tr>'.
8703: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
8704: }
1.381 raeburn 8705: $datatable .= '</table></td></tr>';
1.373 raeburn 8706: }
8707: }
8708: }
8709: $$rowtotal += $itemcount;
8710: return $datatable;
8711: }
8712:
8713: sub wafproxy_titles {
8714: return &Apache::lonlocal::texthash(
1.381 raeburn 8715: remoteip => "Method for determining user's IP",
8716: ipheader => 'Request header containing remote IP',
8717: trusted => 'Trusted IP range(s)',
8718: vpnaccess => 'Access from institutional VPN',
8719: vpndirect => 'via regular hostname (no WAF)',
8720: vpnaliased => 'via aliased hostname (WAF)',
8721: vpnint => 'Internal IP Range(s) for VPN sessions',
8722: vpnext => 'IP Range(s) for backend WAF connections',
1.382 raeburn 8723: sslopt => 'Forwarding http/https',
1.381 raeburn 8724: alltossl => 'WAF forwards both http and https requests to https',
8725: ssltossl => 'WAF forwards http requests to http and https to https',
8726: );
8727: }
8728:
8729: sub remoteip_methods {
8730: return &Apache::lonlocal::texthash(
8731: m => 'Use Apache mod_remoteip',
8732: h => 'Use headers parsed by LON-CAPA',
8733: n => 'Not in use',
1.373 raeburn 8734: );
8735: }
8736:
1.137 raeburn 8737: sub print_usersessions {
8738: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 8739: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 8740: my (%by_ip,%by_location,@intdoms,@instdoms);
8741: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 8742:
8743: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 8744: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 8745: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 8746: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 8747: if ($position eq 'top') {
1.152 raeburn 8748: if (keys(%serverhomes) > 1) {
1.145 raeburn 8749: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.371 raeburn 8750: my ($curroffloadnow,$curroffloadoth);
1.261 raeburn 8751: if (ref($settings) eq 'HASH') {
8752: if (ref($settings->{'offloadnow'}) eq 'HASH') {
8753: $curroffloadnow = $settings->{'offloadnow'};
8754: }
1.371 raeburn 8755: if (ref($settings->{'offloadoth'}) eq 'HASH') {
8756: $curroffloadoth = $settings->{'offloadoth'};
8757: }
1.261 raeburn 8758: }
1.371 raeburn 8759: my $other_insts = scalar(keys(%by_location));
8760: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
8761: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 8762: } else {
1.140 raeburn 8763: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 8764: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
8765: '</td></tr>';
1.140 raeburn 8766: }
1.137 raeburn 8767: } else {
1.279 raeburn 8768: my %titles = &usersession_titles();
8769: my ($prefix,@types);
8770: if ($position eq 'bottom') {
8771: $prefix = 'remote';
8772: @types = ('version','excludedomain','includedomain');
1.145 raeburn 8773: } else {
1.279 raeburn 8774: $prefix = 'hosted';
8775: @types = ('excludedomain','includedomain');
8776: }
8777: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8778: }
8779: $$rowtotal += $itemcount;
8780: return $datatable;
8781: }
8782:
8783: sub rules_by_location {
8784: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
8785: my ($datatable,$itemcount,$css_class);
8786: if (keys(%{$by_location}) == 0) {
8787: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8788: $datatable = '<tr'.$css_class.'><td colspan="2">'.
8789: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
8790: '</td></tr>';
8791: $itemcount = 1;
8792: } else {
8793: $itemcount = 0;
8794: my $numinrow = 5;
8795: my (%current,%checkedon,%checkedoff);
8796: my @locations = sort(keys(%{$by_location}));
8797: foreach my $type (@{$types}) {
8798: $checkedon{$type} = '';
8799: $checkedoff{$type} = ' checked="checked"';
8800: }
8801: if (ref($settings) eq 'HASH') {
8802: if (ref($settings->{$prefix}) eq 'HASH') {
8803: foreach my $key (keys(%{$settings->{$prefix}})) {
8804: $current{$key} = $settings->{$prefix}{$key};
8805: if ($key eq 'version') {
8806: if ($current{$key} ne '') {
1.145 raeburn 8807: $checkedon{$key} = ' checked="checked"';
8808: $checkedoff{$key} = '';
8809: }
1.279 raeburn 8810: } elsif (ref($current{$key}) eq 'ARRAY') {
8811: $checkedon{$key} = ' checked="checked"';
8812: $checkedoff{$key} = '';
1.137 raeburn 8813: }
8814: }
8815: }
1.279 raeburn 8816: }
8817: foreach my $type (@{$types}) {
8818: next if ($type ne 'version' && !@locations);
8819: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8820: $datatable .= '<tr'.$css_class.'>
8821: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
8822: <span class="LC_nobreak">
8823: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
8824: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
8825: if ($type eq 'version') {
8826: my @lcversions = &Apache::lonnet::all_loncaparevs();
8827: my $selector = '<select name="'.$prefix.'_version">';
8828: foreach my $version (@lcversions) {
8829: my $selected = '';
8830: if ($current{'version'} eq $version) {
8831: $selected = ' selected="selected"';
1.145 raeburn 8832: }
1.279 raeburn 8833: $selector .= ' <option value="'.$version.'"'.
8834: $selected.'>'.$version.'</option>';
8835: }
8836: $selector .= '</select> ';
8837: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
8838: } else {
8839: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
8840: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
8841: ' />'.(' 'x2).
8842: '<input type="button" value="'.&mt('uncheck all').'" '.
8843: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
8844: "\n".
8845: '</div><div><table>';
8846: my $rem;
8847: for (my $i=0; $i<@locations; $i++) {
8848: my ($showloc,$value,$checkedtype);
8849: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
8850: my $ip = $by_location->{$locations[$i]}->[0];
8851: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8852: $value = join(':',@{$by_ip->{$ip}});
8853: $showloc = join(', ',@{$by_ip->{$ip}});
8854: if (ref($current{$type}) eq 'ARRAY') {
8855: foreach my $loc (@{$by_ip->{$ip}}) {
8856: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
8857: $checkedtype = ' checked="checked"';
8858: last;
1.145 raeburn 8859: }
1.138 raeburn 8860: }
8861: }
8862: }
1.137 raeburn 8863: }
1.279 raeburn 8864: $rem = $i%($numinrow);
8865: if ($rem == 0) {
8866: if ($i > 0) {
8867: $datatable .= '</tr>';
8868: }
8869: $datatable .= '<tr>';
8870: }
8871: $datatable .= '<td class="LC_left_item">'.
8872: '<span class="LC_nobreak"><label>'.
8873: '<input type="checkbox" name="'.$prefix.'_'.$type.
8874: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
8875: '</label></span></td>';
8876: }
8877: $rem = @locations%($numinrow);
8878: my $colsleft = $numinrow - $rem;
8879: if ($colsleft > 1 ) {
8880: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8881: ' </td>';
8882: } elsif ($colsleft == 1) {
8883: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 8884: }
1.279 raeburn 8885: $datatable .= '</tr></table>';
1.137 raeburn 8886: }
1.279 raeburn 8887: $datatable .= '</td></tr>';
8888: $itemcount ++;
1.137 raeburn 8889: }
8890: }
1.279 raeburn 8891: return ($datatable,$itemcount);
1.137 raeburn 8892: }
8893:
1.275 raeburn 8894: sub print_ssl {
8895: my ($position,$dom,$settings,$rowtotal) = @_;
8896: my ($css_class,$datatable);
8897: my $itemcount = 1;
8898: if ($position eq 'top') {
1.281 raeburn 8899: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8900: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8901: my $same_institution;
8902: if ($intdom ne '') {
8903: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
8904: if (ref($internet_names) eq 'ARRAY') {
8905: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
8906: $same_institution = 1;
8907: }
8908: }
8909: }
1.275 raeburn 8910: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 8911: $datatable = '<tr'.$css_class.'><td colspan="2">';
8912: if ($same_institution) {
8913: my %domservers = &Apache::lonnet::get_servers($dom);
8914: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
8915: } else {
8916: $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.");
8917: }
8918: $datatable .= '</td></tr>';
1.275 raeburn 8919: $itemcount ++;
8920: } else {
8921: my %titles = &ssl_titles();
8922: my (%by_ip,%by_location,@intdoms,@instdoms);
8923: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8924: my @alldoms = &Apache::lonnet::all_domains();
8925: my %serverhomes = %Apache::lonnet::serverhomeIDs;
8926: my @domservers = &Apache::lonnet::get_servers($dom);
8927: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8928: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 8929: if (($position eq 'connto') || ($position eq 'connfrom')) {
8930: my $legacy;
8931: unless (ref($settings) eq 'HASH') {
8932: my $name;
8933: if ($position eq 'connto') {
8934: $name = 'loncAllowInsecure';
8935: } else {
8936: $name = 'londAllowInsecure';
8937: }
8938: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
8939: my @ids=&Apache::lonnet::current_machine_ids();
8940: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
8941: my %what = (
8942: $name => 1,
8943: );
8944: my ($result,$returnhash) =
8945: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
8946: if ($result eq 'ok') {
8947: if (ref($returnhash) eq 'HASH') {
8948: $legacy = $returnhash->{$name};
8949: }
8950: }
8951: } else {
8952: $legacy = $Apache::lonnet::perlvar{$name};
8953: }
8954: }
1.275 raeburn 8955: foreach my $type ('dom','intdom','other') {
8956: my %checked;
8957: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8958: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
8959: '<td class="LC_right_item">';
8960: my $skip;
8961: if ($type eq 'dom') {
8962: unless (keys(%servers) > 1) {
8963: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
8964: $skip = 1;
8965: }
8966: }
8967: if ($type eq 'intdom') {
8968: unless (@instdoms > 1) {
8969: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
8970: $skip = 1;
8971: }
8972: } elsif ($type eq 'other') {
8973: if (keys(%by_location) == 0) {
8974: $datatable .= &mt('Nothing to set here, as there are no other institutions');
8975: $skip = 1;
8976: }
8977: }
8978: unless ($skip) {
8979: $checked{'yes'} = ' checked="checked"';
8980: if (ref($settings) eq 'HASH') {
1.293 raeburn 8981: if (ref($settings->{$position}) eq 'HASH') {
8982: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 8983: $checked{$1} = $checked{'yes'};
8984: delete($checked{'yes'});
8985: }
8986: }
1.293 raeburn 8987: } else {
8988: if ($legacy == 0) {
8989: $checked{'req'} = $checked{'yes'};
8990: delete($checked{'yes'});
8991: }
1.275 raeburn 8992: }
8993: foreach my $option ('no','yes','req') {
8994: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 8995: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 8996: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
8997: '</label></span>'.(' 'x2);
8998: }
8999: }
9000: $datatable .= '</td></tr>';
9001: $itemcount ++;
9002: }
9003: } else {
9004: my $prefix = 'replication';
9005: my @types = ('certreq','nocertreq');
1.279 raeburn 9006: if (keys(%by_location) == 0) {
9007: $datatable .= '<tr'.$css_class.'><td>'.
9008: &mt('Nothing to set here, as there are no other institutions').
9009: '</td></tr>';
9010: $itemcount ++;
1.275 raeburn 9011: } else {
1.279 raeburn 9012: ($datatable,$itemcount) =
9013: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 9014: }
9015: }
9016: }
9017: $$rowtotal += $itemcount;
9018: return $datatable;
9019: }
9020:
9021: sub ssl_titles {
9022: return &Apache::lonlocal::texthash (
9023: dom => 'LON-CAPA servers/VMs from same domain',
9024: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
9025: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 9026: connto => 'Connections to other servers',
9027: connfrom => 'Connections from other servers',
1.275 raeburn 9028: replication => 'Replicating content to other institutions',
9029: certreq => 'Client certificate required, but specific domains exempt',
9030: nocertreq => 'No client certificate required, except for specific domains',
9031: no => 'SSL not used',
9032: yes => 'SSL Optional (used if available)',
9033: req => 'SSL Required',
9034: );
1.279 raeburn 9035: }
9036:
9037: sub print_trust {
9038: my ($prefix,$dom,$settings,$rowtotal) = @_;
9039: my ($css_class,$datatable,%checked,%choices);
9040: my (%by_ip,%by_location,@intdoms,@instdoms);
9041: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
9042: my $itemcount = 1;
9043: my %titles = &trust_titles();
9044: my @types = ('exc','inc');
9045: if ($prefix eq 'top') {
9046: $prefix = 'content';
9047: } elsif ($prefix eq 'bottom') {
9048: $prefix = 'msg';
9049: }
9050: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
9051: $$rowtotal += $itemcount;
9052: return $datatable;
9053: }
9054:
9055: sub trust_titles {
9056: return &Apache::lonlocal::texthash(
9057: content => "Access to this domain's content by others",
9058: shared => "Access to other domain's content by this domain",
9059: enroll => "Enrollment in this domain's courses by others",
9060: othcoau => "Co-author roles in this domain for others",
9061: coaurem => "Co-author roles for this domain's users elsewhere",
9062: domroles => "Domain roles in this domain assignable to others",
9063: catalog => "Course Catalog for this domain displayed elsewhere",
9064: reqcrs => "Requests for creation of courses in this domain by others",
9065: msg => "Users in other domains can send messages to this domain",
9066: exc => "Allow all, but exclude specific domains",
9067: inc => "Deny all, but include specific domains",
9068: );
1.275 raeburn 9069: }
9070:
1.138 raeburn 9071: sub build_location_hashes {
1.275 raeburn 9072: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 9073: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 9074: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 9075: my %iphost = &Apache::lonnet::get_iphost();
9076: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
9077: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
9078: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
9079: foreach my $id (@{$iphost{$primary_ip}}) {
9080: my $intdom = &Apache::lonnet::internet_dom($id);
9081: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
9082: push(@{$intdoms},$intdom);
9083: }
9084: }
9085: }
9086: foreach my $ip (keys(%iphost)) {
9087: if (ref($iphost{$ip}) eq 'ARRAY') {
9088: foreach my $id (@{$iphost{$ip}}) {
9089: my $location = &Apache::lonnet::internet_dom($id);
9090: if ($location) {
1.275 raeburn 9091: if (grep(/^\Q$location\E$/,@{$intdoms})) {
9092: my $dom = &Apache::lonnet::host_domain($id);
9093: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
9094: push(@{$instdoms},$dom);
9095: }
9096: next;
9097: }
1.138 raeburn 9098: if (ref($by_ip->{$ip}) eq 'ARRAY') {
9099: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
9100: push(@{$by_ip->{$ip}},$location);
9101: }
9102: } else {
9103: $by_ip->{$ip} = [$location];
9104: }
9105: }
9106: }
9107: }
9108: }
9109: foreach my $ip (sort(keys(%{$by_ip}))) {
9110: if (ref($by_ip->{$ip}) eq 'ARRAY') {
9111: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
9112: my $first = $by_ip->{$ip}->[0];
9113: if (ref($by_location->{$first}) eq 'ARRAY') {
9114: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
9115: push(@{$by_location->{$first}},$ip);
9116: }
9117: } else {
9118: $by_location->{$first} = [$ip];
9119: }
9120: }
9121: }
9122: return;
9123: }
9124:
1.145 raeburn 9125: sub current_offloads_to {
9126: my ($dom,$settings,$servers) = @_;
9127: my (%spareid,%otherdomconfigs);
1.152 raeburn 9128: if (ref($servers) eq 'HASH') {
1.145 raeburn 9129: foreach my $lonhost (sort(keys(%{$servers}))) {
9130: my $gotspares;
1.152 raeburn 9131: if (ref($settings) eq 'HASH') {
9132: if (ref($settings->{'spares'}) eq 'HASH') {
9133: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
9134: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
9135: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
9136: $gotspares = 1;
9137: }
1.145 raeburn 9138: }
9139: }
9140: unless ($gotspares) {
9141: my $gotspares;
9142: my $serverhomeID =
9143: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
9144: my $serverhomedom =
9145: &Apache::lonnet::host_domain($serverhomeID);
9146: if ($serverhomedom ne $dom) {
9147: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
9148: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
9149: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
9150: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
9151: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
9152: $gotspares = 1;
9153: }
9154: }
9155: } else {
9156: $otherdomconfigs{$serverhomedom} =
9157: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
9158: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
9159: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
9160: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
9161: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
9162: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
9163: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
9164: $gotspares = 1;
9165: }
9166: }
9167: }
9168: }
9169: }
9170: }
9171: }
9172: unless ($gotspares) {
9173: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
9174: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9175: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9176: } else {
9177: my $server_hostname = &Apache::lonnet::hostname($lonhost);
9178: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
9179: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
9180: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9181: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9182: } else {
1.150 raeburn 9183: my %what = (
9184: spareid => 1,
9185: );
9186: my ($result,$returnhash) =
9187: &Apache::lonnet::get_remote_globals($lonhost,\%what);
9188: if ($result eq 'ok') {
9189: if (ref($returnhash) eq 'HASH') {
9190: if (ref($returnhash->{'spareid'}) eq 'HASH') {
9191: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
9192: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
9193: }
9194: }
1.145 raeburn 9195: }
9196: }
9197: }
9198: }
9199: }
9200: }
9201: return %spareid;
9202: }
9203:
9204: sub spares_row {
1.371 raeburn 9205: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
9206: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 9207: my $css_class;
9208: my $numinrow = 4;
9209: my $itemcount = 1;
9210: my $datatable;
1.152 raeburn 9211: my %typetitles = &sparestype_titles();
9212: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 9213: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 9214: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
9215: my ($othercontrol,$serverdom);
9216: if ($serverhome ne $server) {
9217: $serverdom = &Apache::lonnet::host_domain($serverhome);
9218: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9219: } else {
9220: $serverdom = &Apache::lonnet::host_domain($server);
9221: if ($serverdom ne $dom) {
9222: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9223: }
9224: }
9225: next unless (ref($spareid->{$server}) eq 'HASH');
1.371 raeburn 9226: my ($checkednow,$checkedoth);
1.261 raeburn 9227: if (ref($curroffloadnow) eq 'HASH') {
9228: if ($curroffloadnow->{$server}) {
9229: $checkednow = ' checked="checked"';
9230: }
9231: }
1.371 raeburn 9232: if (ref($curroffloadoth) eq 'HASH') {
9233: if ($curroffloadoth->{$server}) {
9234: $checkedoth = ' checked="checked"';
9235: }
9236: }
1.145 raeburn 9237: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
9238: $datatable .= '<tr'.$css_class.'>
9239: <td rowspan="2">
1.183 bisitz 9240: <span class="LC_nobreak">'.
9241: &mt('[_1] when busy, offloads to:'
1.261 raeburn 9242: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 9243: '<span class="LC_nobreak">'."\n".
1.261 raeburn 9244: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.371 raeburn 9245: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.183 bisitz 9246: "\n";
1.371 raeburn 9247: if ($other_insts) {
9248: $datatable .= '<br />'.
9249: '<span class="LC_nobreak">'."\n".
9250: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
9251: ' '.&mt('Switch other institutions on next access').'</label></span>'.
9252: "\n";
9253: }
1.145 raeburn 9254: my (%current,%canselect);
1.152 raeburn 9255: my @choices =
9256: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
9257: foreach my $type ('primary','default') {
9258: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 9259: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
9260: my @spares = @{$spareid->{$server}{$type}};
9261: if (@spares > 0) {
1.152 raeburn 9262: if ($othercontrol) {
9263: $current{$type} = join(', ',@spares);
9264: } else {
9265: $current{$type} .= '<table>';
9266: my $numspares = scalar(@spares);
9267: for (my $i=0; $i<@spares; $i++) {
9268: my $rem = $i%($numinrow);
9269: if ($rem == 0) {
9270: if ($i > 0) {
9271: $current{$type} .= '</tr>';
9272: }
9273: $current{$type} .= '<tr>';
1.145 raeburn 9274: }
1.152 raeburn 9275: $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'".');" /> '.
9276: $spareid->{$server}{$type}[$i].
9277: '</label></td>'."\n";
9278: }
9279: my $rem = @spares%($numinrow);
9280: my $colsleft = $numinrow - $rem;
9281: if ($colsleft > 1 ) {
9282: $current{$type} .= '<td colspan="'.$colsleft.
9283: '" class="LC_left_item">'.
9284: ' </td>';
9285: } elsif ($colsleft == 1) {
9286: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 9287: }
1.152 raeburn 9288: $current{$type} .= '</tr></table>';
1.150 raeburn 9289: }
1.145 raeburn 9290: }
9291: }
9292: if ($current{$type} eq '') {
9293: $current{$type} = &mt('None specified');
9294: }
1.152 raeburn 9295: if ($othercontrol) {
9296: if ($type eq 'primary') {
9297: $canselect{$type} = $othercontrol;
9298: }
9299: } else {
9300: $canselect{$type} =
9301: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
9302: '<select name="newspare_'.$type.'_'.$server.'" '.
9303: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
9304: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
9305: if (@choices > 0) {
9306: foreach my $lonhost (@choices) {
9307: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
9308: }
9309: }
9310: $canselect{$type} .= '</select>'."\n";
9311: }
9312: } else {
9313: $current{$type} = &mt('Could not be determined');
9314: if ($type eq 'primary') {
9315: $canselect{$type} = $othercontrol;
9316: }
1.145 raeburn 9317: }
1.152 raeburn 9318: if ($type eq 'default') {
9319: $datatable .= '<tr'.$css_class.'>';
9320: }
9321: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
9322: '<td>'.$current{$type}.'</td>'."\n".
9323: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 9324: }
9325: $itemcount ++;
9326: }
9327: }
9328: $$rowtotal += $itemcount;
9329: return $datatable;
9330: }
9331:
1.152 raeburn 9332: sub possible_newspares {
9333: my ($server,$currspares,$serverhomes,$altids) = @_;
9334: my $serverhostname = &Apache::lonnet::hostname($server);
9335: my %excluded;
9336: if ($serverhostname ne '') {
9337: %excluded = (
9338: $serverhostname => 1,
9339: );
9340: }
9341: if (ref($currspares) eq 'HASH') {
9342: foreach my $type (keys(%{$currspares})) {
9343: if (ref($currspares->{$type}) eq 'ARRAY') {
9344: if (@{$currspares->{$type}} > 0) {
9345: foreach my $curr (@{$currspares->{$type}}) {
9346: my $hostname = &Apache::lonnet::hostname($curr);
9347: $excluded{$hostname} = 1;
9348: }
9349: }
9350: }
9351: }
9352: }
9353: my @choices;
9354: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
9355: if (keys(%{$serverhomes}) > 1) {
9356: foreach my $name (sort(keys(%{$serverhomes}))) {
9357: unless ($excluded{$name}) {
9358: if (exists($altids->{$serverhomes->{$name}})) {
9359: push(@choices,$altids->{$serverhomes->{$name}});
9360: } else {
9361: push(@choices,$serverhomes->{$name});
1.145 raeburn 9362: }
9363: }
9364: }
9365: }
9366: }
1.152 raeburn 9367: return sort(@choices);
1.145 raeburn 9368: }
9369:
1.150 raeburn 9370: sub print_loadbalancing {
9371: my ($dom,$settings,$rowtotal) = @_;
9372: my $primary_id = &Apache::lonnet::domain($dom,'primary');
9373: my $intdom = &Apache::lonnet::internet_dom($primary_id);
9374: my $numinrow = 1;
9375: my $datatable;
9376: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 9377: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 9378: if (ref($settings) eq 'HASH') {
9379: %existing = %{$settings};
9380: }
9381: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
9382: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 9383: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 9384: } else {
9385: return;
9386: }
9387: my ($othertitle,$usertypes,$types) =
9388: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 9389: my $rownum = 8;
1.150 raeburn 9390: if (ref($types) eq 'ARRAY') {
9391: $rownum += scalar(@{$types});
9392: }
1.171 raeburn 9393: my @css_class = ('LC_odd_row','LC_even_row');
9394: my $balnum = 0;
9395: my $islast;
9396: my (@toshow,$disabledtext);
9397: if (keys(%currbalancer) > 0) {
9398: @toshow = sort(keys(%currbalancer));
9399: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
9400: push(@toshow,'');
9401: }
9402: } else {
9403: @toshow = ('');
9404: $disabledtext = &mt('No existing load balancer');
9405: }
9406: foreach my $lonhost (@toshow) {
9407: if ($balnum == scalar(@toshow)-1) {
9408: $islast = 1;
9409: } else {
9410: $islast = 0;
9411: }
9412: my $cssidx = $balnum%2;
9413: my $targets_div_style = 'display: none';
9414: my $disabled_div_style = 'display: block';
9415: my $homedom_div_style = 'display: none';
9416: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 9417: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9418: '<p>';
9419: if ($lonhost eq '') {
1.210 raeburn 9420: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 9421: if (keys(%currbalancer) > 0) {
9422: $datatable .= &mt('Add balancer:');
9423: } else {
9424: $datatable .= &mt('Enable balancer:');
9425: }
9426: $datatable .= ' '.
9427: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
9428: ' id="loadbalancing_lonhost_'.$balnum.'"'.
9429: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
9430: '<option value="" selected="selected">'.&mt('None').
9431: '</option>'."\n";
9432: foreach my $server (sort(keys(%servers))) {
9433: next if ($currbalancer{$server});
9434: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
9435: }
1.210 raeburn 9436: $datatable .=
1.171 raeburn 9437: '</select>'."\n".
9438: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
9439: } else {
9440: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
9441: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
9442: &mt('Stop balancing').'</label>'.
9443: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
9444: $targets_div_style = 'display: block';
9445: $disabled_div_style = 'display: none';
9446: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
9447: $homedom_div_style = 'display: block';
9448: }
9449: }
1.306 raeburn 9450: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9451: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
9452: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
9453: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
9454: my ($numspares,@spares) = &count_servers($lonhost,%servers);
9455: my @sparestypes = ('primary','default');
9456: my %typetitles = &sparestype_titles();
1.284 raeburn 9457: my %hostherechecked = (
9458: no => ' checked="checked"',
9459: );
1.342 raeburn 9460: my %balcookiechecked = (
1.425 raeburn 9461: no => ' checked="checked"',
1.342 raeburn 9462: );
1.171 raeburn 9463: foreach my $sparetype (@sparestypes) {
9464: my $targettable;
9465: for (my $i=0; $i<$numspares; $i++) {
9466: my $checked;
9467: if (ref($currtargets{$lonhost}) eq 'HASH') {
9468: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9469: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9470: $checked = ' checked="checked"';
9471: }
9472: }
9473: }
9474: my ($chkboxval,$disabled);
9475: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
9476: $chkboxval = $spares[$i];
9477: }
9478: if (exists($currbalancer{$spares[$i]})) {
9479: $disabled = ' disabled="disabled"';
9480: }
1.210 raeburn 9481: $targettable .=
1.253 raeburn 9482: '<td><span class="LC_nobreak"><label>'.
9483: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 9484: $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 9485: '</span></label></span></td>';
1.171 raeburn 9486: my $rem = $i%($numinrow);
9487: if ($rem == 0) {
9488: if (($i > 0) && ($i < $numspares-1)) {
9489: $targettable .= '</tr>';
9490: }
9491: if ($i < $numspares-1) {
9492: $targettable .= '<tr>';
1.150 raeburn 9493: }
9494: }
9495: }
1.171 raeburn 9496: if ($targettable ne '') {
9497: my $rem = $numspares%($numinrow);
9498: my $colsleft = $numinrow - $rem;
9499: if ($colsleft > 1 ) {
9500: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9501: ' </td>';
9502: } elsif ($colsleft == 1) {
9503: $targettable .= '<td class="LC_left_item"> </td>';
9504: }
9505: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
9506: '<table><tr>'.$targettable.'</tr></table><br />';
9507: }
1.284 raeburn 9508: $hostherechecked{$sparetype} = '';
9509: if (ref($currtargets{$lonhost}) eq 'HASH') {
9510: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9511: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9512: $hostherechecked{$sparetype} = ' checked="checked"';
9513: $hostherechecked{'no'} = '';
9514: }
9515: }
9516: }
9517: }
1.342 raeburn 9518: if ($currcookies{$lonhost}) {
9519: %balcookiechecked = (
9520: yes => ' checked="checked"',
9521: );
9522: }
1.284 raeburn 9523: $datatable .= &mt('Hosting on balancer itself').'<br />'.
9524: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
9525: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
9526: foreach my $sparetype (@sparestypes) {
9527: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
9528: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
9529: '</i></label><br />';
1.171 raeburn 9530: }
1.342 raeburn 9531: $datatable .= &mt('Use balancer cookie').'<br />'.
9532: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
9533: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
9534: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
9535: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
9536: '</div></td></tr>'.
1.171 raeburn 9537: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
9538: $othertitle,$usertypes,$types,\%servers,
9539: \%currbalancer,$lonhost,
9540: $targets_div_style,$homedom_div_style,
9541: $css_class[$cssidx],$balnum,$islast);
9542: $$rowtotal += $rownum;
9543: $balnum ++;
9544: }
9545: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
9546: return $datatable;
9547: }
9548:
9549: sub get_loadbalancers_config {
1.342 raeburn 9550: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 9551: return unless ((ref($servers) eq 'HASH') &&
9552: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 9553: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
9554: (ref($currcookies) eq 'HASH'));
1.171 raeburn 9555: if (keys(%{$existing}) > 0) {
9556: my $oldlonhost;
9557: foreach my $key (sort(keys(%{$existing}))) {
9558: if ($key eq 'lonhost') {
9559: $oldlonhost = $existing->{'lonhost'};
9560: $currbalancer->{$oldlonhost} = 1;
9561: } elsif ($key eq 'targets') {
9562: if ($oldlonhost) {
9563: $currtargets->{$oldlonhost} = $existing->{'targets'};
9564: }
9565: } elsif ($key eq 'rules') {
9566: if ($oldlonhost) {
9567: $currrules->{$oldlonhost} = $existing->{'rules'};
9568: }
9569: } elsif (ref($existing->{$key}) eq 'HASH') {
9570: $currbalancer->{$key} = 1;
9571: $currtargets->{$key} = $existing->{$key}{'targets'};
9572: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 9573: if ($existing->{$key}{'cookie'}) {
9574: $currcookies->{$key} = 1;
9575: }
1.150 raeburn 9576: }
9577: }
1.171 raeburn 9578: } else {
9579: my ($balancerref,$targetsref) =
9580: &Apache::lonnet::get_lonbalancer_config($servers);
9581: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
9582: foreach my $server (sort(keys(%{$balancerref}))) {
9583: $currbalancer->{$server} = 1;
9584: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 9585: }
9586: }
9587: }
1.171 raeburn 9588: return;
1.150 raeburn 9589: }
9590:
9591: sub loadbalancing_rules {
9592: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 9593: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
9594: $css_class,$balnum,$islast) = @_;
1.150 raeburn 9595: my $output;
1.171 raeburn 9596: my $num = 0;
1.210 raeburn 9597: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 9598: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
9599: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
9600: foreach my $type (@{$alltypes}) {
1.171 raeburn 9601: $num ++;
1.150 raeburn 9602: my $current;
9603: if (ref($currrules) eq 'HASH') {
9604: $current = $currrules->{$type};
9605: }
1.253 raeburn 9606: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 9607: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 9608: $current = '';
9609: }
9610: }
9611: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 9612: $servers,$currbalancer,$lonhost,$dom,
9613: $targets_div_style,$homedom_div_style,
9614: $css_class,$balnum,$num,$islast);
1.150 raeburn 9615: }
9616: }
9617: return $output;
9618: }
9619:
9620: sub loadbalancing_titles {
9621: my ($dom,$intdom,$usertypes,$types) = @_;
9622: my %othertypes = (
9623: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
9624: '_LC_author' => &mt('Users from [_1] with author role',$dom),
9625: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
9626: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 9627: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
9628: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 9629: );
1.209 raeburn 9630: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 9631: my @available;
1.150 raeburn 9632: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9633: @available = @{$types};
1.150 raeburn 9634: }
1.302 raeburn 9635: unless (grep(/^default$/,@available)) {
9636: push(@available,'default');
9637: }
9638: unshift(@alltypes,@available);
1.150 raeburn 9639: my %titles;
9640: foreach my $type (@alltypes) {
9641: if ($type =~ /^_LC_/) {
9642: $titles{$type} = $othertypes{$type};
9643: } elsif ($type eq 'default') {
9644: $titles{$type} = &mt('All users from [_1]',$dom);
9645: if (ref($types) eq 'ARRAY') {
9646: if (@{$types} > 0) {
9647: $titles{$type} = &mt('Other users from [_1]',$dom);
9648: }
9649: }
9650: } elsif (ref($usertypes) eq 'HASH') {
9651: $titles{$type} = $usertypes->{$type};
9652: }
9653: }
9654: return (\@alltypes,\%othertypes,\%titles);
9655: }
9656:
9657: sub loadbalance_rule_row {
1.171 raeburn 9658: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
9659: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 9660: my @rulenames;
1.150 raeburn 9661: my %ruletitles = &offloadtype_text();
1.209 raeburn 9662: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 9663: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 9664: } else {
1.209 raeburn 9665: @rulenames = ('default','homeserver');
9666: if ($type eq '_LC_external') {
9667: push(@rulenames,'externalbalancer');
9668: } else {
9669: push(@rulenames,'specific');
9670: }
9671: push(@rulenames,'none');
1.150 raeburn 9672: }
9673: my $style = $targets_div_style;
1.253 raeburn 9674: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 9675: $style = $homedom_div_style;
9676: }
1.171 raeburn 9677: my $space;
9678: if ($islast && $num == 1) {
1.317 raeburn 9679: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 9680: }
1.210 raeburn 9681: my $output =
1.306 raeburn 9682: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 9683: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
9684: '<td valaign="top">'.$space.
9685: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 9686: for (my $i=0; $i<@rulenames; $i++) {
9687: my $rule = $rulenames[$i];
9688: my ($checked,$extra);
9689: if ($rulenames[$i] eq 'default') {
9690: $rule = '';
9691: }
9692: if ($rulenames[$i] eq 'specific') {
9693: if (ref($servers) eq 'HASH') {
9694: my $default;
9695: if (($current ne '') && (exists($servers->{$current}))) {
9696: $checked = ' checked="checked"';
9697: }
9698: unless ($checked) {
9699: $default = ' selected="selected"';
9700: }
1.210 raeburn 9701: $extra =
1.171 raeburn 9702: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
9703: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
9704: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
9705: '<option value=""'.$default.'></option>'."\n";
9706: foreach my $server (sort(keys(%{$servers}))) {
9707: if (ref($currbalancer) eq 'HASH') {
9708: next if (exists($currbalancer->{$server}));
9709: }
1.150 raeburn 9710: my $selected;
1.171 raeburn 9711: if ($server eq $current) {
1.150 raeburn 9712: $selected = ' selected="selected"';
9713: }
1.171 raeburn 9714: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 9715: }
9716: $extra .= '</select>';
9717: }
9718: } elsif ($rule eq $current) {
9719: $checked = ' checked="checked"';
9720: }
9721: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 9722: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
9723: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
9724: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 9725: ')"'.$checked.' /> ';
9726: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
9727: $output .= $ruletitles{'particular'};
9728: } else {
9729: $output .= $ruletitles{$rulenames[$i]};
9730: }
9731: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 9732: }
9733: $output .= '</div></td></tr>'."\n";
9734: return $output;
9735: }
9736:
9737: sub offloadtype_text {
9738: my %ruletitles = &Apache::lonlocal::texthash (
9739: 'default' => 'Offloads to default destinations',
9740: 'homeserver' => "Offloads to user's home server",
9741: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
9742: 'specific' => 'Offloads to specific server',
1.161 raeburn 9743: 'none' => 'No offload',
1.209 raeburn 9744: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
9745: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 9746: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 9747: );
9748: return %ruletitles;
9749: }
9750:
9751: sub sparestype_titles {
9752: my %typestitles = &Apache::lonlocal::texthash (
9753: 'primary' => 'primary',
9754: 'default' => 'default',
9755: );
9756: return %typestitles;
9757: }
9758:
1.28 raeburn 9759: sub contact_titles {
9760: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 9761: 'supportemail' => 'Support E-mail address',
9762: 'adminemail' => 'Default Server Admin E-mail address',
9763: 'errormail' => 'Error reports to be e-mailed to',
9764: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 9765: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
9766: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 9767: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
9768: 'requestsmail' => 'E-mail from course requests requiring approval',
9769: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 9770: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350 raeburn 9771: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.378 raeburn 9772: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
9773: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.340 raeburn 9774: 'errorweights' => 'Weights used to compute error count',
9775: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 9776: );
9777: my %short_titles = &Apache::lonlocal::texthash (
9778: adminemail => 'Admin E-mail address',
9779: supportemail => 'Support E-mail',
9780: );
9781: return (\%titles,\%short_titles);
9782: }
9783:
1.286 raeburn 9784: sub helpform_fields {
9785: my %titles = &Apache::lonlocal::texthash (
9786: 'username' => 'Name',
9787: 'user' => 'Username/domain',
9788: 'phone' => 'Phone',
9789: 'cc' => 'Cc e-mail',
9790: 'course' => 'Course Details',
9791: 'section' => 'Sections',
1.289 raeburn 9792: 'screenshot' => 'File upload',
1.286 raeburn 9793: );
9794: my @fields = ('username','phone','user','course','section','cc','screenshot');
9795: my %possoptions = (
9796: username => ['yes','no','req'],
1.289 raeburn 9797: phone => ['yes','no','req'],
1.286 raeburn 9798: user => ['yes','no'],
1.289 raeburn 9799: cc => ['yes','no'],
1.286 raeburn 9800: course => ['yes','no'],
9801: section => ['yes','no'],
9802: screenshot => ['yes','no'],
9803: );
9804: my %fieldoptions = &Apache::lonlocal::texthash (
9805: 'yes' => 'Optional',
9806: 'req' => 'Required',
9807: 'no' => "Not shown",
9808: );
9809: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
9810: }
9811:
1.72 raeburn 9812: sub tool_titles {
9813: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 9814: aboutme => 'Personal web page',
1.86 raeburn 9815: blog => 'Blog',
9816: portfolio => 'Portfolio',
1.430 raeburn 9817: portaccess => 'Share portfolio files',
1.413 raeburn 9818: timezone => 'Can set time zone',
1.88 bisitz 9819: official => 'Official courses (with institutional codes)',
9820: unofficial => 'Unofficial courses',
1.98 raeburn 9821: community => 'Communities',
1.216 raeburn 9822: textbook => 'Textbook courses',
1.271 raeburn 9823: placement => 'Placement tests',
1.86 raeburn 9824: );
1.72 raeburn 9825: return %titles;
9826: }
9827:
1.101 raeburn 9828: sub courserequest_titles {
9829: my %titles = &Apache::lonlocal::texthash (
9830: official => 'Official',
9831: unofficial => 'Unofficial',
9832: community => 'Communities',
1.216 raeburn 9833: textbook => 'Textbook',
1.271 raeburn 9834: placement => 'Placement tests',
1.325 raeburn 9835: lti => 'LTI Provider',
1.101 raeburn 9836: norequest => 'Not allowed',
1.325 raeburn 9837: approval => 'Approval by DC',
1.101 raeburn 9838: validate => 'With validation',
9839: autolimit => 'Numerical limit',
1.103 raeburn 9840: unlimited => '(blank for unlimited)',
1.101 raeburn 9841: );
9842: return %titles;
9843: }
9844:
1.163 raeburn 9845: sub authorrequest_titles {
9846: my %titles = &Apache::lonlocal::texthash (
9847: norequest => 'Not allowed',
9848: approval => 'Approval by Dom. Coord.',
9849: automatic => 'Automatic approval',
9850: );
9851: return %titles;
1.210 raeburn 9852: }
1.163 raeburn 9853:
1.101 raeburn 9854: sub courserequest_conditions {
9855: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 9856: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 9857: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 9858: );
9859: return %conditions;
9860: }
9861:
9862:
1.27 raeburn 9863: sub print_usercreation {
1.30 raeburn 9864: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 9865: my $numinrow = 4;
1.28 raeburn 9866: my $datatable;
9867: if ($position eq 'top') {
1.30 raeburn 9868: $$rowtotal ++;
1.34 raeburn 9869: my $rowcount = 0;
1.32 raeburn 9870: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 9871: if (ref($rules) eq 'HASH') {
9872: if (keys(%{$rules}) > 0) {
1.32 raeburn 9873: $datatable .= &user_formats_row('username',$settings,$rules,
9874: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 9875: $$rowtotal ++;
1.32 raeburn 9876: $rowcount ++;
9877: }
9878: }
9879: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
9880: if (ref($idrules) eq 'HASH') {
9881: if (keys(%{$idrules}) > 0) {
9882: $datatable .= &user_formats_row('id',$settings,$idrules,
9883: $idruleorder,$numinrow,$rowcount);
9884: $$rowtotal ++;
9885: $rowcount ++;
1.28 raeburn 9886: }
9887: }
1.39 raeburn 9888: if ($rowcount == 0) {
9889: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
9890: $$rowtotal ++;
9891: $rowcount ++;
9892: }
1.34 raeburn 9893: } elsif ($position eq 'middle') {
1.224 raeburn 9894: my @creators = ('author','course','requestcrs');
1.37 raeburn 9895: my ($rules,$ruleorder) =
9896: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 9897: my %lt = &usercreation_types();
9898: my %checked;
9899: if (ref($settings) eq 'HASH') {
9900: if (ref($settings->{'cancreate'}) eq 'HASH') {
9901: foreach my $item (@creators) {
9902: $checked{$item} = $settings->{'cancreate'}{$item};
9903: }
9904: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
9905: foreach my $item (@creators) {
9906: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
9907: $checked{$item} = 'none';
9908: }
9909: }
9910: }
9911: }
9912: my $rownum = 0;
9913: foreach my $item (@creators) {
9914: $rownum ++;
1.224 raeburn 9915: if ($checked{$item} eq '') {
9916: $checked{$item} = 'any';
1.34 raeburn 9917: }
9918: my $css_class;
9919: if ($rownum%2) {
9920: $css_class = '';
9921: } else {
9922: $css_class = ' class="LC_odd_row" ';
9923: }
9924: $datatable .= '<tr'.$css_class.'>'.
9925: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 9926: '</span></td><td style="text-align: right">';
1.224 raeburn 9927: my @options = ('any');
9928: if (ref($rules) eq 'HASH') {
9929: if (keys(%{$rules}) > 0) {
9930: push(@options,('official','unofficial'));
1.37 raeburn 9931: }
9932: }
1.224 raeburn 9933: push(@options,'none');
1.37 raeburn 9934: foreach my $option (@options) {
1.50 raeburn 9935: my $type = 'radio';
1.34 raeburn 9936: my $check = ' ';
1.224 raeburn 9937: if ($checked{$item} eq $option) {
9938: $check = ' checked="checked" ';
1.34 raeburn 9939: }
9940: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 9941: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 9942: $item.'" value="'.$option.'"'.$check.'/> '.
9943: $lt{$option}.'</label> </span>';
9944: }
9945: $datatable .= '</td></tr>';
9946: }
1.28 raeburn 9947: } else {
9948: my @contexts = ('author','course','domain');
1.325 raeburn 9949: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 9950: my %checked;
9951: if (ref($settings) eq 'HASH') {
9952: if (ref($settings->{'authtypes'}) eq 'HASH') {
9953: foreach my $item (@contexts) {
9954: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
9955: foreach my $auth (@authtypes) {
9956: if ($settings->{'authtypes'}{$item}{$auth}) {
9957: $checked{$item}{$auth} = ' checked="checked" ';
9958: }
9959: }
9960: }
9961: }
1.27 raeburn 9962: }
1.35 raeburn 9963: } else {
9964: foreach my $item (@contexts) {
1.36 raeburn 9965: foreach my $auth (@authtypes) {
1.35 raeburn 9966: $checked{$item}{$auth} = ' checked="checked" ';
9967: }
9968: }
1.27 raeburn 9969: }
1.28 raeburn 9970: my %title = &context_names();
9971: my %authname = &authtype_names();
9972: my $rownum = 0;
9973: my $css_class;
9974: foreach my $item (@contexts) {
9975: if ($rownum%2) {
9976: $css_class = '';
9977: } else {
9978: $css_class = ' class="LC_odd_row" ';
9979: }
1.30 raeburn 9980: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 9981: '<td>'.$title{$item}.
9982: '</td><td class="LC_left_item">'.
9983: '<span class="LC_nobreak">';
9984: foreach my $auth (@authtypes) {
9985: $datatable .= '<label>'.
9986: '<input type="checkbox" name="'.$item.'_auth" '.
9987: $checked{$item}{$auth}.' value="'.$auth.'" />'.
9988: $authname{$auth}.'</label> ';
9989: }
9990: $datatable .= '</span></td></tr>';
9991: $rownum ++;
1.27 raeburn 9992: }
1.30 raeburn 9993: $$rowtotal += $rownum;
1.27 raeburn 9994: }
9995: return $datatable;
9996: }
9997:
1.224 raeburn 9998: sub print_selfcreation {
9999: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 10000: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
10001: $emaildomain,$datatable);
1.224 raeburn 10002: if (ref($settings) eq 'HASH') {
10003: if (ref($settings->{'cancreate'}) eq 'HASH') {
10004: $createsettings = $settings->{'cancreate'};
1.236 raeburn 10005: if (ref($createsettings) eq 'HASH') {
10006: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
10007: @selfcreate = @{$createsettings->{'selfcreate'}};
10008: } elsif ($createsettings->{'selfcreate'} ne '') {
10009: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
10010: @selfcreate = ('email','login','sso');
10011: } elsif ($createsettings->{'selfcreate'} ne 'none') {
10012: @selfcreate = ($createsettings->{'selfcreate'});
10013: }
10014: }
10015: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
10016: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 10017: }
1.305 raeburn 10018: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
10019: $emailoptions = $createsettings->{'emailoptions'};
10020: }
1.303 raeburn 10021: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
10022: $emailverified = $createsettings->{'emailverified'};
10023: }
10024: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
10025: $emaildomain = $createsettings->{'emaildomain'};
10026: }
1.224 raeburn 10027: }
10028: }
10029: }
10030: my %radiohash;
10031: my $numinrow = 4;
10032: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 10033: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 10034: if ($position eq 'top') {
10035: my %choices = &Apache::lonlocal::texthash (
10036: cancreate_login => 'Institutional Login',
10037: cancreate_sso => 'Institutional Single Sign On',
10038: );
10039: my @toggles = sort(keys(%choices));
10040: my %defaultchecked = (
10041: 'cancreate_login' => 'off',
10042: 'cancreate_sso' => 'off',
10043: );
1.228 raeburn 10044: my ($onclick,$itemcount);
1.224 raeburn 10045: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
10046: \%choices,$itemcount,$onclick);
1.228 raeburn 10047: $$rowtotal += $itemcount;
1.425 raeburn 10048:
1.224 raeburn 10049: if (ref($usertypes) eq 'HASH') {
10050: if (keys(%{$usertypes}) > 0) {
10051: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
10052: $dom,$numinrow,$othertitle,
1.305 raeburn 10053: 'statustocreate',$rowtotal);
1.224 raeburn 10054: $$rowtotal ++;
10055: }
10056: }
1.240 raeburn 10057: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
10058: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10059: $fieldtitles{'inststatus'} = &mt('Institutional status');
10060: my $rem;
10061: my $numperrow = 2;
10062: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
10063: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 10064: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 10065: '<td class="LC_left_item">'."\n".
1.334 raeburn 10066: '<table>'."\n";
1.240 raeburn 10067: for (my $i=0; $i<@fields; $i++) {
10068: $rem = $i%($numperrow);
10069: if ($rem == 0) {
10070: if ($i > 0) {
10071: $datatable .= '</tr>';
10072: }
10073: $datatable .= '<tr>';
10074: }
10075: my $currval;
1.248 raeburn 10076: if (ref($createsettings) eq 'HASH') {
10077: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
10078: $currval = $createsettings->{'shibenv'}{$fields[$i]};
10079: }
1.240 raeburn 10080: }
10081: $datatable .= '<td class="LC_left_item">'.
10082: '<span class="LC_nobreak">'.
10083: '<input type="text" name="shibenv_'.$fields[$i].'" '.
10084: 'value="'.$currval.'" size="10" /> '.
10085: $fieldtitles{$fields[$i]}.'</span></td>';
10086: }
10087: my $colsleft = $numperrow - $rem;
10088: if ($colsleft > 1 ) {
10089: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10090: ' </td>';
10091: } elsif ($colsleft == 1) {
10092: $datatable .= '<td class="LC_left_item"> </td>';
10093: }
10094: $datatable .= '</tr></table></td></tr>';
10095: $$rowtotal ++;
1.224 raeburn 10096: } elsif ($position eq 'middle') {
10097: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 10098: my @posstypes;
1.224 raeburn 10099: if (ref($types) eq 'ARRAY') {
1.302 raeburn 10100: @posstypes = @{$types};
10101: }
10102: unless (grep(/^default$/,@posstypes)) {
10103: push(@posstypes,'default');
10104: }
10105: my %usertypeshash;
10106: if (ref($usertypes) eq 'HASH') {
10107: %usertypeshash = %{$usertypes};
10108: }
10109: $usertypeshash{'default'} = $othertitle;
10110: foreach my $status (@posstypes) {
10111: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
10112: $numinrow,$$rowtotal,\%usertypeshash);
10113: $$rowtotal ++;
1.224 raeburn 10114: }
10115: } else {
1.236 raeburn 10116: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 10117: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 10118: );
10119: my @toggles = sort(keys(%choices));
10120: my %defaultchecked = (
10121: 'cancreate_email' => 'off',
10122: );
1.305 raeburn 10123: my $customclass = 'LC_selfcreate_email';
10124: my $classprefix = 'LC_canmodify_emailusername_';
10125: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 10126: my $display = 'none';
1.305 raeburn 10127: my $rowstyle = 'display:none';
1.236 raeburn 10128: if (grep(/^\Qemail\E$/,@selfcreate)) {
10129: $display = 'block';
1.305 raeburn 10130: $rowstyle = 'display:table-row';
1.236 raeburn 10131: }
1.305 raeburn 10132: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
10133: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
10134: \%choices,$$rowtotal,$onclick);
10135: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
10136: $rowstyle);
10137: $$rowtotal ++;
10138: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
10139: $rowstyle);
10140: $$rowtotal ++;
10141: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 10142: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 10143: my ($emailrules,$emailruleorder) =
10144: &Apache::lonnet::inst_userrules($dom,'email');
10145: my $primary_id = &Apache::lonnet::domain($dom,'primary');
10146: my $intdom = &Apache::lonnet::internet_dom($primary_id);
10147: if (ref($types) eq 'ARRAY') {
10148: @posstypes = @{$types};
10149: }
10150: if (@posstypes) {
10151: unless (grep(/^default$/,@posstypes)) {
10152: push(@posstypes,'default');
1.302 raeburn 10153: }
10154: if (ref($usertypes) eq 'HASH') {
10155: %usertypeshash = %{$usertypes};
10156: }
1.305 raeburn 10157: my $currassign;
10158: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
10159: $currassign = {
10160: selfassign => $domdefaults{'inststatusguest'},
10161: };
10162: @ordered = @{$domdefaults{'inststatusguest'}};
10163: } else {
10164: $currassign = { selfassign => [] };
10165: }
10166: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
10167: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
10168: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
10169: $numinrow,$othertitle,'selfassign',
10170: $rowtotal,$onclicktypes,$customclass,
10171: $rowstyle);
10172: $$rowtotal ++;
1.302 raeburn 10173: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10174: foreach my $status (@posstypes) {
10175: my $css_class;
10176: if ($$rowtotal%2) {
10177: $css_class = 'LC_odd_row ';
10178: }
10179: $css_class .= $customclass;
10180: my $rowid = $optionsprefix.$status;
10181: my $hidden = 1;
10182: my $currstyle = 'display:none';
10183: if (grep(/^\Q$status\E$/,@ordered)) {
10184: $currstyle = $rowstyle;
1.425 raeburn 10185: $hidden = 0;
1.305 raeburn 10186: }
10187: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10188: $emailrules,$emailruleorder,$settings,$status,$rowid,
10189: $usertypeshash{$status},$css_class,$currstyle,$intdom);
10190: unless ($hidden) {
10191: $$rowtotal ++;
10192: }
1.224 raeburn 10193: }
1.302 raeburn 10194: } else {
1.305 raeburn 10195: my $css_class;
10196: if ($$rowtotal%2) {
10197: $css_class = 'LC_odd_row ';
10198: }
10199: $css_class .= $customclass;
1.302 raeburn 10200: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10201: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10202: $emailrules,$emailruleorder,$settings,'default','',
10203: $othertitle,$css_class,$rowstyle,$intdom);
10204: $$rowtotal ++;
1.224 raeburn 10205: }
10206: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 10207: $numinrow = 1;
1.305 raeburn 10208: if (@posstypes) {
10209: foreach my $status (@posstypes) {
10210: my $rowid = $classprefix.$status;
10211: my $datarowstyle = 'display:none';
1.425 raeburn 10212: if (grep(/^\Q$status\E$/,@ordered)) {
10213: $datarowstyle = $rowstyle;
1.305 raeburn 10214: }
10215: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
10216: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10217: $infotitles,$rowid,$customclass,$datarowstyle);
10218: unless ($datarowstyle eq 'display:none') {
10219: $$rowtotal ++;
10220: }
1.224 raeburn 10221: }
1.305 raeburn 10222: } else {
10223: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
10224: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10225: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 10226: }
10227: }
10228: return $datatable;
10229: }
10230:
1.305 raeburn 10231: sub selfcreate_javascript {
10232: return <<"ENDSCRIPT";
10233:
10234: <script type="text/javascript">
10235: // <![CDATA[
10236:
10237: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
10238: var x = document.getElementsByClassName(target);
10239: var insttypes = 0;
10240: var insttypeRegExp = new RegExp(prefix);
10241: if ((x.length != undefined) && (x.length > 0)) {
10242: if (form.elements[radio].length != undefined) {
10243: for (var i=0; i<form.elements[radio].length; i++) {
10244: if (form.elements[radio][i].checked) {
10245: if (form.elements[radio][i].value == 1) {
10246: for (var j=0; j<x.length; j++) {
10247: if (x[j].id == 'undefined') {
10248: x[j].style.display = 'table-row';
10249: } else if (insttypeRegExp.test(x[j].id)) {
10250: insttypes ++;
10251: } else {
10252: x[j].style.display = 'table-row';
10253: }
10254: }
10255: } else {
10256: for (var j=0; j<x.length; j++) {
10257: x[j].style.display = 'none';
10258: }
1.236 raeburn 10259: }
1.305 raeburn 10260: break;
10261: }
10262: }
10263: if (insttypes > 0) {
10264: toggleDataRow(form,checkbox,target,altprefix);
10265: toggleDataRow(form,checkbox,target,prefix,1);
10266: }
10267: }
10268: }
10269: return;
10270: }
10271:
10272: function toggleDataRow(form,checkbox,target,prefix,docount) {
10273: if (form.elements[checkbox].length != undefined) {
10274: var count = 0;
10275: if (docount) {
10276: for (var i=0; i<form.elements[checkbox].length; i++) {
10277: if (form.elements[checkbox][i].checked) {
10278: count ++;
1.236 raeburn 10279: }
1.305 raeburn 10280: }
10281: }
10282: for (var i=0; i<form.elements[checkbox].length; i++) {
10283: var type = form.elements[checkbox][i].value;
10284: if (document.getElementById(prefix+type)) {
10285: if (form.elements[checkbox][i].checked) {
10286: document.getElementById(prefix+type).style.display = 'table-row';
10287: if (count % 2 == 1) {
10288: document.getElementById(prefix+type).className = target+' LC_odd_row';
10289: } else {
10290: document.getElementById(prefix+type).className = target;
1.236 raeburn 10291: }
1.305 raeburn 10292: count ++;
1.236 raeburn 10293: } else {
1.305 raeburn 10294: document.getElementById(prefix+type).style.display = 'none';
10295: }
10296: }
10297: }
10298: }
10299: return;
10300: }
10301:
10302: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
10303: var caller = radio+'_'+status;
10304: if (form.elements[caller].length != undefined) {
10305: for (var i=0; i<form.elements[caller].length; i++) {
10306: if (form.elements[caller][i].checked) {
10307: if (document.getElementById(altprefix+'_inst_'+status)) {
10308: var curr = form.elements[caller][i].value;
10309: if (prefix) {
10310: document.getElementById(prefix+'_'+status).style.display = 'none';
10311: }
10312: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
10313: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
10314: if (curr == 'custom') {
1.425 raeburn 10315: if (prefix) {
1.305 raeburn 10316: document.getElementById(prefix+'_'+status).style.display = 'inline';
10317: }
10318: } else if (curr == 'inst') {
10319: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
10320: } else if (curr == 'noninst') {
10321: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 10322: }
1.305 raeburn 10323: break;
1.236 raeburn 10324: }
10325: }
10326: }
10327: }
10328: }
10329:
1.305 raeburn 10330: // ]]>
10331: </script>
10332:
10333: ENDSCRIPT
10334: }
10335:
10336: sub noninst_users {
10337: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
1.425 raeburn 10338: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
1.305 raeburn 10339: my $class = 'LC_left_item';
10340: if ($css_class) {
1.425 raeburn 10341: $css_class = ' class="'.$css_class.'"';
1.305 raeburn 10342: }
10343: if ($rowid) {
10344: $rowid = ' id="'.$rowid.'"';
10345: }
10346: if ($rowstyle) {
10347: $rowstyle = ' style="'.$rowstyle.'"';
10348: }
10349: my ($output,$description);
10350: if ($type eq 'default') {
10351: $description = &mt('Requests for: [_1]',$typetitle);
10352: } else {
10353: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
10354: }
10355: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
1.425 raeburn 10356: "<td>$description</td>\n".
1.305 raeburn 10357: '<td class="'.$class.'" colspan="2">'.
10358: '<table><tr>';
1.425 raeburn 10359: my %headers = &Apache::lonlocal::texthash(
1.305 raeburn 10360: approve => 'Processing',
10361: email => 'E-mail',
10362: username => 'Username',
10363: );
10364: foreach my $item ('approve','email','username') {
10365: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 10366: }
1.305 raeburn 10367: $output .= '</tr><tr>';
10368: foreach my $item ('approve','email','username') {
1.306 raeburn 10369: $output .= '<td style="vertical-align: top">';
1.305 raeburn 10370: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
10371: if ($item eq 'approve') {
10372: %choices = &Apache::lonlocal::texthash (
10373: automatic => 'Automatically approved',
10374: approval => 'Queued for approval',
10375: );
10376: @options = ('automatic','approval');
10377: $hashref = $processing;
10378: $defoption = 'automatic';
10379: $name = 'cancreate_emailprocess_'.$type;
10380: } elsif ($item eq 'email') {
10381: %choices = &Apache::lonlocal::texthash (
10382: any => 'Any e-mail',
10383: inst => 'Institutional only',
10384: noninst => 'Non-institutional only',
10385: custom => 'Custom restrictions',
10386: );
10387: @options = ('any','inst','noninst');
10388: my $showcustom;
10389: if (ref($emailrules) eq 'HASH') {
10390: if (keys(%{$emailrules}) > 0) {
10391: push(@options,'custom');
10392: $showcustom = 'cancreate_emailrule';
10393: if (ref($settings) eq 'HASH') {
10394: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
10395: foreach my $rule (@{$settings->{'email_rule'}}) {
10396: if (exists($emailrules->{$rule})) {
10397: $hascustom ++;
10398: }
10399: }
10400: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
10401: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
10402: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
10403: if (exists($emailrules->{$rule})) {
10404: $hascustom ++;
10405: }
10406: }
10407: }
10408: }
10409: }
10410: }
10411: }
10412: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
10413: "'cancreate_emaildomain','$type'".');"';
10414: $hashref = $emailoptions;
10415: $defoption = 'any';
10416: $name = 'cancreate_emailoptions_'.$type;
10417: } elsif ($item eq 'username') {
10418: %choices = &Apache::lonlocal::texthash (
10419: all => 'Same as e-mail',
10420: first => 'Omit @domain',
10421: free => 'Free to choose',
10422: );
10423: @options = ('all','first','free');
10424: $hashref = $emailverified;
10425: $defoption = 'all';
10426: $name = 'cancreate_usernameoptions_'.$type;
10427: }
10428: foreach my $option (@options) {
10429: my $checked;
10430: if (ref($hashref) eq 'HASH') {
10431: if ($type eq '') {
10432: if (!exists($hashref->{'default'})) {
10433: if ($option eq $defoption) {
10434: $checked = ' checked="checked"';
10435: }
10436: } else {
10437: if ($hashref->{'default'} eq $option) {
10438: $checked = ' checked="checked"';
10439: }
1.303 raeburn 10440: }
10441: } else {
1.305 raeburn 10442: if (!exists($hashref->{$type})) {
10443: if ($option eq $defoption) {
10444: $checked = ' checked="checked"';
10445: }
10446: } else {
10447: if ($hashref->{$type} eq $option) {
10448: $checked = ' checked="checked"';
10449: }
1.303 raeburn 10450: }
10451: }
1.305 raeburn 10452: } elsif (($item eq 'email') && ($hascustom)) {
10453: if ($option eq 'custom') {
10454: $checked = ' checked="checked"';
10455: }
10456: } elsif ($option eq $defoption) {
10457: $checked = ' checked="checked"';
10458: }
10459: $output .= '<span class="LC_nobreak"><label>'.
10460: '<input type="radio" name="'.$name.'"'.
10461: $checked.' value="'.$option.'"'.$onclick.' />'.
10462: $choices{$option}.'</label></span><br />';
10463: if ($item eq 'email') {
10464: if ($option eq 'custom') {
10465: my $id = 'cancreate_emailrule_'.$type;
10466: my $display = 'none';
10467: if ($checked) {
10468: $display = 'inline';
1.303 raeburn 10469: }
1.305 raeburn 10470: my $numinrow = 2;
10471: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
10472: '<legend>'.&mt('Disallow').'</legend><table>'.
10473: &user_formats_row('email',$settings,$emailrules,
10474: $emailruleorder,$numinrow,'',$type);
10475: '</table></fieldset>';
10476: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
10477: my %text = &Apache::lonlocal::texthash (
10478: inst => 'must end:',
10479: noninst => 'cannot end:',
10480: );
10481: my $value;
10482: if (ref($emaildomain) eq 'HASH') {
10483: if (ref($emaildomain->{$type}) eq 'HASH') {
1.425 raeburn 10484: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 10485: }
10486: }
1.305 raeburn 10487: if ($value eq '') {
10488: $value = '@'.$intdom;
10489: }
10490: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
10491: my $display = 'none';
10492: if ($checked) {
10493: $display = 'inline';
10494: }
10495: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
10496: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
10497: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
10498: '</div>';
1.303 raeburn 10499: }
10500: }
10501: }
1.305 raeburn 10502: $output .= '</td>'."\n";
1.303 raeburn 10503: }
1.305 raeburn 10504: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 10505: return $output;
10506: }
10507:
1.165 raeburn 10508: sub captcha_choice {
1.305 raeburn 10509: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 10510: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
10511: $vertext,$currver);
1.165 raeburn 10512: my %lt = &captcha_phrases();
10513: $keyentry = 'hidden';
1.354 raeburn 10514: my $colspan=2;
1.165 raeburn 10515: if ($context eq 'cancreate') {
1.224 raeburn 10516: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 10517: } elsif ($context eq 'login') {
10518: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.354 raeburn 10519: } elsif ($context eq 'passwords') {
10520: $rowname = &mt('"Forgot Password" CAPTCHA validation');
10521: $colspan=1;
1.165 raeburn 10522: }
10523: if (ref($settings) eq 'HASH') {
10524: if ($settings->{'captcha'}) {
10525: $checked{$settings->{'captcha'}} = ' checked="checked"';
10526: } else {
10527: $checked{'original'} = ' checked="checked"';
10528: }
10529: if ($settings->{'captcha'} eq 'recaptcha') {
10530: $pubtext = $lt{'pub'};
10531: $privtext = $lt{'priv'};
10532: $keyentry = 'text';
1.269 raeburn 10533: $vertext = $lt{'ver'};
10534: $currver = $settings->{'recaptchaversion'};
10535: if ($currver ne '2') {
10536: $currver = 1;
10537: }
1.165 raeburn 10538: }
10539: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
10540: $currpub = $settings->{'recaptchakeys'}{'public'};
10541: $currpriv = $settings->{'recaptchakeys'}{'private'};
10542: }
10543: } else {
10544: $checked{'original'} = ' checked="checked"';
10545: }
1.305 raeburn 10546: my $css_class;
10547: if ($itemcount%2) {
10548: $css_class = 'LC_odd_row';
10549: }
10550: if ($customcss) {
10551: $css_class .= " $customcss";
10552: }
10553: $css_class =~ s/^\s+//;
10554: if ($css_class) {
10555: $css_class = ' class="'.$css_class.'"';
10556: }
10557: if ($rowstyle) {
10558: $css_class .= ' style="'.$rowstyle.'"';
10559: }
1.169 raeburn 10560: my $output = '<tr'.$css_class.'>'.
1.354 raeburn 10561: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165 raeburn 10562: '<table><tr><td>'."\n";
10563: foreach my $option ('original','recaptcha','notused') {
10564: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
10565: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
10566: $lt{$option}.'</label></span>';
10567: unless ($option eq 'notused') {
10568: $output .= (' 'x2)."\n";
10569: }
10570: }
10571: #
10572: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
10573: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 10574: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 10575: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 10576: #
1.165 raeburn 10577: $output .= '</td></tr>'."\n".
1.305 raeburn 10578: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 10579: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
10580: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
10581: $currpub.'" size="40" /></span><br />'."\n".
10582: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
10583: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 10584: $currpriv.'" size="40" /></span><br />'.
10585: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
10586: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
10587: $currver.'" size="3" /></span><br />'.
10588: '</td></tr></table>'."\n".
1.165 raeburn 10589: '</td></tr>';
10590: return $output;
10591: }
10592:
1.32 raeburn 10593: sub user_formats_row {
1.305 raeburn 10594: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 10595: my $output;
10596: my %text = (
10597: 'username' => 'new usernames',
10598: 'id' => 'IDs',
10599: );
1.409 raeburn 10600: unless (($type eq 'email') || ($type eq 'unamemap')) {
1.305 raeburn 10601: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
10602: $output = '<tr '.$css_class.'>'.
10603: '<td><span class="LC_nobreak">'.
10604: &mt("Format rules to check for $text{$type}: ").
10605: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 10606: }
1.27 raeburn 10607: my $rem;
10608: if (ref($ruleorder) eq 'ARRAY') {
10609: for (my $i=0; $i<@{$ruleorder}; $i++) {
10610: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
10611: my $rem = $i%($numinrow);
10612: if ($rem == 0) {
10613: if ($i > 0) {
10614: $output .= '</tr>';
10615: }
10616: $output .= '<tr>';
10617: }
10618: my $check = ' ';
1.39 raeburn 10619: if (ref($settings) eq 'HASH') {
10620: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
10621: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
10622: $check = ' checked="checked" ';
10623: }
1.305 raeburn 10624: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
10625: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
10626: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
10627: $check = ' checked="checked" ';
10628: }
10629: }
1.27 raeburn 10630: }
10631: }
1.305 raeburn 10632: my $name = $type.'_rule';
10633: if ($type eq 'email') {
10634: $name .= '_'.$status;
10635: }
1.27 raeburn 10636: $output .= '<td class="LC_left_item">'.
10637: '<span class="LC_nobreak"><label>'.
1.311 raeburn 10638: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 10639: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
10640: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
10641: }
10642: }
10643: $rem = @{$ruleorder}%($numinrow);
10644: }
1.305 raeburn 10645: my $colsleft;
10646: if ($rem) {
10647: $colsleft = $numinrow - $rem;
10648: }
1.27 raeburn 10649: if ($colsleft > 1 ) {
10650: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10651: ' </td>';
10652: } elsif ($colsleft == 1) {
10653: $output .= '<td class="LC_left_item"> </td>';
10654: }
1.409 raeburn 10655: $output .= '</tr>';
10656: unless (($type eq 'email') || ($type eq 'unamemap')) {
10657: $output .= '</table></td></tr>';
1.305 raeburn 10658: }
1.27 raeburn 10659: return $output;
10660: }
10661:
1.34 raeburn 10662: sub usercreation_types {
10663: my %lt = &Apache::lonlocal::texthash (
10664: author => 'When adding a co-author',
10665: course => 'When adding a user to a course',
1.100 raeburn 10666: requestcrs => 'When requesting a course',
1.34 raeburn 10667: any => 'Any',
10668: official => 'Institutional only ',
10669: unofficial => 'Non-institutional only',
10670: none => 'None',
10671: );
10672: return %lt;
1.48 raeburn 10673: }
1.34 raeburn 10674:
1.224 raeburn 10675: sub selfcreation_types {
10676: my %lt = &Apache::lonlocal::texthash (
10677: selfcreate => 'User creates own account',
10678: any => 'Any',
10679: official => 'Institutional only ',
10680: unofficial => 'Non-institutional only',
10681: email => 'E-mail address',
10682: login => 'Institutional Login',
10683: sso => 'SSO',
10684: );
10685: }
10686:
1.28 raeburn 10687: sub authtype_names {
10688: my %lt = &Apache::lonlocal::texthash(
10689: int => 'Internal',
10690: krb4 => 'Kerberos 4',
10691: krb5 => 'Kerberos 5',
10692: loc => 'Local',
1.325 raeburn 10693: lti => 'LTI',
1.28 raeburn 10694: );
10695: return %lt;
10696: }
10697:
10698: sub context_names {
10699: my %context_title = &Apache::lonlocal::texthash(
10700: author => 'Creating users when an Author',
10701: course => 'Creating users when in a course',
10702: domain => 'Creating users when a Domain Coordinator',
10703: );
10704: return %context_title;
10705: }
10706:
1.33 raeburn 10707: sub print_usermodification {
10708: my ($position,$dom,$settings,$rowtotal) = @_;
10709: my $numinrow = 4;
10710: my ($context,$datatable,$rowcount);
10711: if ($position eq 'top') {
10712: $rowcount = 0;
10713: $context = 'author';
10714: foreach my $role ('ca','aa') {
10715: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10716: $numinrow,$rowcount);
10717: $$rowtotal ++;
10718: $rowcount ++;
10719: }
1.443 raeburn 10720: } elsif ($position eq 'middle') {
10721: $rowcount = 0;
10722: $context = 'coauthor';
10723: foreach my $role ('ca','aa') {
10724: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10725: $numinrow,$rowcount);
10726: $$rowtotal ++;
10727: $rowcount ++;
10728: }
1.230 raeburn 10729: } elsif ($position eq 'bottom') {
1.33 raeburn 10730: $context = 'course';
10731: $rowcount = 0;
10732: foreach my $role ('st','ep','ta','in','cr') {
10733: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10734: $numinrow,$rowcount);
10735: $$rowtotal ++;
10736: $rowcount ++;
10737: }
10738: }
10739: return $datatable;
10740: }
10741:
1.43 raeburn 10742: sub print_defaults {
1.236 raeburn 10743: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 10744: my $rownum = 0;
1.294 raeburn 10745: my ($datatable,$css_class,$titles);
10746: unless ($position eq 'bottom') {
10747: $titles = &defaults_titles($dom);
10748: }
1.236 raeburn 10749: if ($position eq 'top') {
10750: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
10751: 'datelocale_def','portal_def');
10752: my %defaults;
10753: if (ref($settings) eq 'HASH') {
10754: %defaults = %{$settings};
1.43 raeburn 10755: } else {
1.236 raeburn 10756: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10757: foreach my $item (@items) {
10758: $defaults{$item} = $domdefaults{$item};
10759: }
1.43 raeburn 10760: }
1.236 raeburn 10761: foreach my $item (@items) {
10762: if ($rownum%2) {
10763: $css_class = '';
10764: } else {
10765: $css_class = ' class="LC_odd_row" ';
10766: }
10767: $datatable .= '<tr'.$css_class.'>'.
10768: '<td><span class="LC_nobreak">'.$titles->{$item}.
10769: '</span></td><td class="LC_right_item" colspan="3">';
10770: if ($item eq 'auth_def') {
1.325 raeburn 10771: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 10772: my %shortauth = (
10773: internal => 'int',
10774: krb4 => 'krb4',
10775: krb5 => 'krb5',
1.325 raeburn 10776: localauth => 'loc',
10777: lti => 'lti',
1.236 raeburn 10778: );
10779: my %authnames = &authtype_names();
10780: foreach my $auth (@authtypes) {
10781: my $checked = ' ';
10782: if ($defaults{$item} eq $auth) {
10783: $checked = ' checked="checked" ';
10784: }
10785: $datatable .= '<label><input type="radio" name="'.$item.
10786: '" value="'.$auth.'"'.$checked.'/>'.
10787: $authnames{$shortauth{$auth}}.'</label> ';
10788: }
10789: } elsif ($item eq 'timezone_def') {
10790: my $includeempty = 1;
10791: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
10792: } elsif ($item eq 'datelocale_def') {
10793: my $includeempty = 1;
10794: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
10795: } elsif ($item eq 'lang_def') {
1.263 raeburn 10796: my $includeempty = 1;
10797: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.414 raeburn 10798: } elsif ($item eq 'portal_def') {
10799: $datatable .= '<input type="text" name="'.$item.'" value="'.
10800: $defaults{$item}.'" size="25" onkeyup="portalExtras(this);" />';
10801: my $portalsty = 'none';
10802: if ($defaults{$item}) {
10803: $portalsty = 'block';
10804: }
10805: foreach my $field ('email','web') {
10806: my $checkedoff = ' checked="checked"';
10807: my $checkedon;
10808: if ($defaults{$item.'_'.$field}) {
10809: $checkedon = $checkedoff;
10810: $checkedoff = '';
1.425 raeburn 10811: }
1.414 raeburn 10812: $datatable .= '<div id="'.$item.'_'.$field.'_div" style="display:'.$portalsty.'">'.
10813: '<span class="LC_nobreak">'.$titles->{$field}.' '.
10814: '<label><input type="radio" name="'.$item.'_'.$field.'" value="1"'.$checkedon.'/>'.&mt('Yes').'</label>'.
10815: (' 'x2).
10816: '<label><input type="radio" name="'.$item.'_'.$field.'" value="0"'.$checkedoff.'/>'.&mt('No').'</label>'.
10817: '</div>';
10818: }
1.236 raeburn 10819: } else {
1.414 raeburn 10820: $datatable .= '<input type="text" name="'.$item.'" value="'.$defaults{$item}.'" />';
1.43 raeburn 10821: }
1.236 raeburn 10822: $datatable .= '</td></tr>';
10823: $rownum ++;
10824: }
1.409 raeburn 10825: } elsif ($position eq 'middle') {
1.294 raeburn 10826: my %defaults;
10827: if (ref($settings) eq 'HASH') {
1.354 raeburn 10828: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
10829: my $maxnum = @{$settings->{'inststatusorder'}};
10830: for (my $i=0; $i<$maxnum; $i++) {
10831: $css_class = $rownum%2?' class="LC_odd_row"':'';
10832: my $item = $settings->{'inststatusorder'}->[$i];
10833: my $title = $settings->{'inststatustypes'}->{$item};
10834: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
10835: $datatable .= '<tr'.$css_class.'>'.
10836: '<td><span class="LC_nobreak">'.
10837: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
10838: for (my $k=0; $k<=$maxnum; $k++) {
10839: my $vpos = $k+1;
10840: my $selstr;
10841: if ($k == $i) {
10842: $selstr = ' selected="selected" ';
10843: }
10844: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10845: }
10846: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
10847: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
10848: &mt('delete').'</span></td>'.
1.380 raeburn 10849: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.354 raeburn 10850: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
10851: '</span></td></tr>';
10852: }
10853: $css_class = $rownum%2?' class="LC_odd_row"':'';
10854: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
10855: $datatable .= '<tr '.$css_class.'>'.
10856: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
10857: for (my $k=0; $k<=$maxnum; $k++) {
10858: my $vpos = $k+1;
10859: my $selstr;
10860: if ($k == $maxnum) {
10861: $selstr = ' selected="selected" ';
10862: }
10863: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10864: }
10865: $datatable .= '</select> '.&mt('Internal ID:').
10866: '<input type="text" size="10" name="addinststatus" value="" />'.
10867: ' '.&mt('(new)').
10868: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.380 raeburn 10869: &mt('Name displayed').':'.
1.354 raeburn 10870: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
10871: '</tr>'."\n";
10872: $rownum ++;
1.294 raeburn 10873: }
1.354 raeburn 10874: }
1.409 raeburn 10875: } else {
10876: my ($unamemaprules,$ruleorder) =
10877: &Apache::lonnet::inst_userrules($dom,'unamemap');
10878: $css_class = $rownum%2?' class="LC_odd_row"':'';
10879: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10880: my $numinrow = 2;
10881: $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
10882: &user_formats_row('unamemap',$settings,$unamemaprules,
10883: $ruleorder,$numinrow).
10884: '</table></td></tr>';
10885: }
10886: if ($datatable eq '') {
10887: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
10888: &mt('No rules set for domain in customized localenroll.pm').
10889: '</td></tr>';
10890: }
1.354 raeburn 10891: }
10892: $$rowtotal += $rownum;
1.43 raeburn 10893: return $datatable;
10894: }
10895:
1.168 raeburn 10896: sub get_languages_hash {
10897: my %langchoices;
10898: foreach my $id (&Apache::loncommon::languageids()) {
10899: my $code = &Apache::loncommon::supportedlanguagecode($id);
10900: if ($code ne '') {
10901: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
10902: }
10903: }
10904: return %langchoices;
10905: }
10906:
1.43 raeburn 10907: sub defaults_titles {
1.141 raeburn 10908: my ($dom) = @_;
1.43 raeburn 10909: my %titles = &Apache::lonlocal::texthash (
10910: 'auth_def' => 'Default authentication type',
10911: 'auth_arg_def' => 'Default authentication argument',
10912: 'lang_def' => 'Default language',
1.54 raeburn 10913: 'timezone_def' => 'Default timezone',
1.68 raeburn 10914: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 10915: 'portal_def' => 'Portal/Default URL',
1.414 raeburn 10916: 'email' => 'Email links use portal URL',
10917: 'web' => 'Public web links use portal URL',
1.294 raeburn 10918: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
10919: 'intauth_check' => 'Check bcrypt cost if authenticated',
10920: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 10921: );
1.141 raeburn 10922: if ($dom) {
10923: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
10924: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
10925: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
10926: $protocol = 'http' if ($protocol ne 'https');
10927: if ($uint_dom) {
10928: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
10929: $uint_dom);
10930: }
10931: }
1.43 raeburn 10932: return (\%titles);
10933: }
10934:
1.346 raeburn 10935: sub print_scantron {
10936: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
10937: if ($position eq 'top') {
10938: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
10939: } else {
10940: return &print_scantronconfig($dom,$settings,\$rowtotal);
10941: }
10942: }
10943:
10944: sub scantron_javascript {
10945: return <<"ENDSCRIPT";
10946:
10947: <script type="text/javascript">
10948: // <![CDATA[
10949:
10950: function toggleScantron(form) {
1.347 raeburn 10951: var csvfieldset = new Array();
1.346 raeburn 10952: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 10953: csvfieldset.push(document.getElementById('scantroncsv_cols'));
10954: }
10955: if (document.getElementById('scantroncsv_options')) {
10956: csvfieldset.push(document.getElementById('scantroncsv_options'));
10957: }
10958: if (csvfieldset.length) {
1.346 raeburn 10959: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 10960: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 10961: if (scantroncsv.checked) {
1.347 raeburn 10962: for (var i=0; i<csvfieldset.length; i++) {
10963: csvfieldset[i].style.display = 'block';
10964: }
1.346 raeburn 10965: } else {
1.347 raeburn 10966: for (var i=0; i<csvfieldset.length; i++) {
10967: csvfieldset[i].style.display = 'none';
10968: }
1.346 raeburn 10969: var csvselects = document.getElementsByClassName('scantronconfig_csv');
10970: if (csvselects.length) {
10971: for (var j=0; j<csvselects.length; j++) {
10972: csvselects[j].selectedIndex = 0;
10973: }
10974: }
10975: }
10976: }
10977: }
10978: return;
10979: }
10980: // ]]>
10981: </script>
10982:
10983: ENDSCRIPT
10984:
10985: }
10986:
1.46 raeburn 10987: sub print_scantronformat {
10988: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
10989: my $itemcount = 1;
1.60 raeburn 10990: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
10991: %confhash);
1.46 raeburn 10992: my $switchserver = &check_switchserver($dom,$confname);
10993: my %lt = &Apache::lonlocal::texthash (
1.95 www 10994: default => 'Default bubblesheet format file error',
10995: custom => 'Custom bubblesheet format file error',
1.46 raeburn 10996: );
10997: my %scantronfiles = (
10998: default => 'default.tab',
10999: custom => 'custom.tab',
11000: );
11001: foreach my $key (keys(%scantronfiles)) {
11002: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
11003: .$scantronfiles{$key};
11004: }
11005: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
11006: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
11007: if (!$switchserver) {
11008: my $servadm = $r->dir_config('lonAdmEMail');
11009: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
11010: if ($configuserok eq 'ok') {
11011: if ($author_ok eq 'ok') {
11012: my %legacyfile = (
1.346 raeburn 11013: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
11014: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 11015: );
11016: my %md5chk;
11017: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 11018: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
11019: chomp($md5chk{$type});
1.46 raeburn 11020: }
11021: if ($md5chk{'default'} ne $md5chk{'custom'}) {
11022: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 11023: ($scantronurls{$type},my $error) =
1.46 raeburn 11024: &legacy_scantronformat($r,$dom,$confname,
11025: $type,$legacyfile{$type},
11026: $scantronurls{$type},
11027: $scantronfiles{$type});
1.60 raeburn 11028: if ($error ne '') {
11029: $error{$type} = $error;
11030: }
11031: }
11032: if (keys(%error) == 0) {
11033: $is_custom = 1;
1.346 raeburn 11034: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 11035: $scantronurls{'custom'};
1.346 raeburn 11036: my $putresult =
1.60 raeburn 11037: &Apache::lonnet::put_dom('configuration',
11038: \%confhash,$dom);
11039: if ($putresult ne 'ok') {
1.346 raeburn 11040: $error{'custom'} =
1.60 raeburn 11041: '<span class="LC_error">'.
11042: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
11043: }
1.46 raeburn 11044: }
11045: } else {
1.60 raeburn 11046: ($scantronurls{'default'},my $error) =
1.46 raeburn 11047: &legacy_scantronformat($r,$dom,$confname,
11048: 'default',$legacyfile{'default'},
11049: $scantronurls{'default'},
11050: $scantronfiles{'default'});
1.60 raeburn 11051: if ($error eq '') {
11052: $confhash{'scantron'}{'scantronformat'} = '';
11053: my $putresult =
11054: &Apache::lonnet::put_dom('configuration',
11055: \%confhash,$dom);
11056: if ($putresult ne 'ok') {
11057: $error{'default'} =
11058: '<span class="LC_error">'.
11059: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
11060: }
11061: } else {
11062: $error{'default'} = $error;
11063: }
1.46 raeburn 11064: }
11065: }
11066: }
11067: } else {
1.95 www 11068: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 11069: }
11070: }
11071: if (ref($settings) eq 'HASH') {
11072: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
11073: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
11074: if ((!@info) || ($info[0] eq 'no_such_dir')) {
11075: $scantronurl = '';
11076: } else {
11077: $scantronurl = $settings->{'scantronformat'};
11078: }
11079: $is_custom = 1;
11080: } else {
11081: $scantronurl = $scantronurls{'default'};
11082: }
11083: } else {
1.60 raeburn 11084: if ($is_custom) {
11085: $scantronurl = $scantronurls{'custom'};
11086: } else {
11087: $scantronurl = $scantronurls{'default'};
11088: }
1.46 raeburn 11089: }
11090: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11091: $datatable .= '<tr'.$css_class.'>';
11092: if (!$is_custom) {
1.65 raeburn 11093: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
11094: '<span class="LC_nobreak">';
1.46 raeburn 11095: if ($scantronurl) {
1.199 raeburn 11096: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
11097: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 11098: } else {
11099: $datatable = &mt('File unavailable for display');
11100: }
1.65 raeburn 11101: $datatable .= '</span></td>';
1.60 raeburn 11102: if (keys(%error) == 0) {
1.306 raeburn 11103: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 11104: if (!$switchserver) {
11105: $datatable .= &mt('Upload:').'<br />';
11106: }
11107: } else {
11108: my $errorstr;
11109: foreach my $key (sort(keys(%error))) {
11110: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
11111: }
11112: $datatable .= '<td>'.$errorstr;
11113: }
1.46 raeburn 11114: } else {
11115: if (keys(%error) > 0) {
11116: my $errorstr;
11117: foreach my $key (sort(keys(%error))) {
11118: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
11119: }
1.60 raeburn 11120: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 11121: } elsif ($scantronurl) {
1.199 raeburn 11122: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
11123: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 11124: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 11125: $link.
11126: '<label><input type="checkbox" name="scantronformat_del"'.
11127: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 11128: '<td><span class="LC_nobreak"> '.
11129: &mt('Replace:').'</span><br />';
1.46 raeburn 11130: }
11131: }
11132: if (keys(%error) == 0) {
11133: if ($switchserver) {
11134: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
11135: } else {
1.65 raeburn 11136: $datatable .='<span class="LC_nobreak"> '.
11137: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 11138: }
11139: }
11140: $datatable .= '</td></tr>';
11141: $$rowtotal ++;
11142: return $datatable;
11143: }
11144:
11145: sub legacy_scantronformat {
11146: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
11147: my ($url,$error);
11148: my @statinfo = &Apache::lonnet::stat_file($newurl);
11149: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
1.421 raeburn 11150: my $modified = [];
1.46 raeburn 11151: (my $result,$url) =
1.421 raeburn 11152: &Apache::lonconfigsettings::publishlogo($r,'copy',$legacyfile,$dom,$confname,
11153: 'scantron','','',$newfile,$modified);
11154: if ($result eq 'ok') {
11155: &update_modify_urls($r,$modified);
11156: } else {
1.130 raeburn 11157: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 11158: }
11159: }
11160: return ($url,$error);
11161: }
1.43 raeburn 11162:
1.346 raeburn 11163: sub print_scantronconfig {
11164: my ($dom,$settings,$rowtotal) = @_;
11165: my $itemcount = 2;
11166: my $is_checked = ' checked="checked"';
1.347 raeburn 11167: my %optionson = (
11168: hdr => ' checked="checked"',
11169: pad => ' checked="checked"',
11170: rem => ' checked="checked"',
11171: );
11172: my %optionsoff = (
11173: hdr => '',
11174: pad => '',
11175: rem => '',
11176: );
1.346 raeburn 11177: my $currcsvsty = 'none';
1.347 raeburn 11178: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 11179: my @fields = &scantroncsv_fields();
11180: my %titles = &scantronconfig_titles();
11181: if (ref($settings) eq 'HASH') {
11182: if (ref($settings->{config}) eq 'HASH') {
11183: if ($settings->{config}->{dat}) {
11184: $checked{'dat'} = $is_checked;
11185: }
11186: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 11187: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
11188: %csvfields = %{$settings->{config}->{csv}->{fields}};
11189: if (keys(%csvfields) > 0) {
11190: $checked{'csv'} = $is_checked;
11191: $currcsvsty = 'block';
11192: }
11193: }
11194: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
11195: %csvoptions = %{$settings->{config}->{csv}->{options}};
11196: foreach my $option (keys(%optionson)) {
11197: unless ($csvoptions{$option}) {
11198: $optionsoff{$option} = $optionson{$option};
11199: $optionson{$option} = '';
11200: }
11201: }
1.346 raeburn 11202: }
11203: }
11204: } else {
11205: $checked{'dat'} = $is_checked;
11206: }
11207: } else {
11208: $checked{'dat'} = $is_checked;
11209: }
11210: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
11211: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11212: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
11213: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
11214: foreach my $item ('dat','csv') {
11215: my $id;
11216: if ($item eq 'csv') {
11217: $id = 'id="scantronconfcsv" ';
1.347 raeburn 11218: }
1.346 raeburn 11219: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
11220: $titles{$item}.'</label>'.(' 'x3);
11221: if ($item eq 'csv') {
11222: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
11223: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
11224: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
11225: foreach my $col (@fields) {
11226: my $selnone;
11227: if ($csvfields{$col} eq '') {
11228: $selnone = ' selected="selected"';
11229: }
11230: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
11231: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
11232: '<option value=""'.$selnone.'></option>';
11233: for (my $i=0; $i<20; $i++) {
11234: my $shown = $i+1;
11235: my $sel;
11236: unless ($selnone) {
11237: if (exists($csvfields{$col})) {
11238: if ($csvfields{$col} == $i) {
11239: $sel = ' selected="selected"';
11240: }
11241: }
11242: }
11243: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
11244: }
11245: $datatable .= '</select></td></tr>';
11246: }
1.347 raeburn 11247: $datatable .= '</table></fieldset>'.
11248: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
11249: '<legend>'.&mt('CSV Options').'</legend>';
11250: foreach my $option ('hdr','pad','rem') {
11251: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
11252: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
11253: &mt('Yes').'</label>'.(' 'x2)."\n".
11254: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
11255: }
11256: $datatable .= '</fieldset>';
1.346 raeburn 11257: $itemcount ++;
11258: }
11259: }
11260: $datatable .= '</td></tr>';
11261: $$rowtotal ++;
11262: return $datatable;
11263: }
11264:
11265: sub scantronconfig_titles {
11266: return &Apache::lonlocal::texthash(
11267: dat => 'Standard format (.dat)',
11268: csv => 'Comma separated values (.csv)',
1.347 raeburn 11269: hdr => 'Remove first line in file (contains column titles)',
11270: pad => 'Prepend 0s to PaperID',
1.348 raeburn 11271: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 11272: CODE => 'CODE',
11273: ID => 'Student ID',
11274: PaperID => 'Paper ID',
11275: FirstName => 'First Name',
11276: LastName => 'Last Name',
11277: FirstQuestion => 'First Question Response',
11278: Section => 'Section',
11279: );
11280: }
11281:
11282: sub scantroncsv_fields {
11283: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
11284: }
11285:
1.49 raeburn 11286: sub print_coursecategories {
1.57 raeburn 11287: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
11288: my $datatable;
11289: if ($position eq 'top') {
1.238 raeburn 11290: my (%checked);
11291: my @catitems = ('unauth','auth');
11292: my @cattypes = ('std','domonly','codesrch','none');
11293: $checked{'unauth'} = 'std';
11294: $checked{'auth'} = 'std';
11295: if (ref($settings) eq 'HASH') {
11296: foreach my $type (@cattypes) {
11297: if ($type eq $settings->{'unauth'}) {
11298: $checked{'unauth'} = $type;
11299: }
11300: if ($type eq $settings->{'auth'}) {
11301: $checked{'auth'} = $type;
11302: }
11303: }
11304: }
11305: my %lt = &Apache::lonlocal::texthash (
11306: unauth => 'Catalog type for unauthenticated users',
11307: auth => 'Catalog type for authenticated users',
11308: none => 'No catalog',
11309: std => 'Standard catalog',
11310: domonly => 'Domain-only catalog',
11311: codesrch => "Code search form",
11312: );
11313: my $itemcount = 0;
11314: foreach my $item (@catitems) {
11315: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11316: $datatable .= '<tr '.$css_class.'>'.
11317: '<td>'.$lt{$item}.'</td>'.
11318: '<td class="LC_right_item"><span class="LC_nobreak">';
11319: foreach my $type (@cattypes) {
11320: my $ischecked;
11321: if ($checked{$item} eq $type) {
11322: $ischecked=' checked="checked"';
11323: }
11324: $datatable .= '<label>'.
11325: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
11326: ' />'.$lt{$type}.'</label> ';
11327: }
1.327 raeburn 11328: $datatable .= '</span></td></tr>';
1.238 raeburn 11329: $itemcount ++;
11330: }
11331: $$rowtotal += $itemcount;
11332: } elsif ($position eq 'middle') {
1.57 raeburn 11333: my $toggle_cats_crs = ' ';
11334: my $toggle_cats_dom = ' checked="checked" ';
11335: my $can_cat_crs = ' ';
11336: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 11337: my $toggle_catscomm_comm = ' ';
11338: my $toggle_catscomm_dom = ' checked="checked" ';
11339: my $can_catcomm_comm = ' ';
11340: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 11341: my $toggle_catsplace_place = ' ';
11342: my $toggle_catsplace_dom = ' checked="checked" ';
11343: my $can_catplace_place = ' ';
11344: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 11345:
1.57 raeburn 11346: if (ref($settings) eq 'HASH') {
11347: if ($settings->{'togglecats'} eq 'crs') {
11348: $toggle_cats_crs = $toggle_cats_dom;
11349: $toggle_cats_dom = ' ';
11350: }
11351: if ($settings->{'categorize'} eq 'crs') {
11352: $can_cat_crs = $can_cat_dom;
11353: $can_cat_dom = ' ';
11354: }
1.120 raeburn 11355: if ($settings->{'togglecatscomm'} eq 'comm') {
11356: $toggle_catscomm_comm = $toggle_catscomm_dom;
11357: $toggle_catscomm_dom = ' ';
11358: }
11359: if ($settings->{'categorizecomm'} eq 'comm') {
11360: $can_catcomm_comm = $can_catcomm_dom;
11361: $can_catcomm_dom = ' ';
11362: }
1.272 raeburn 11363: if ($settings->{'togglecatsplace'} eq 'place') {
11364: $toggle_catsplace_place = $toggle_catsplace_dom;
11365: $toggle_catsplace_dom = ' ';
11366: }
11367: if ($settings->{'categorizeplace'} eq 'place') {
11368: $can_catplace_place = $can_catplace_dom;
11369: $can_catplace_dom = ' ';
11370: }
1.57 raeburn 11371: }
11372: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 11373: togglecats => 'Show/Hide a course in catalog',
11374: togglecatscomm => 'Show/Hide a community in catalog',
11375: togglecatsplace => 'Show/Hide a placement test in catalog',
11376: categorize => 'Assign a category to a course',
11377: categorizecomm => 'Assign a category to a community',
11378: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 11379: );
11380: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 11381: dom => 'Set in Domain',
11382: crs => 'Set in Course',
11383: comm => 'Set in Community',
11384: place => 'Set in Placement Test',
1.57 raeburn 11385: );
11386: $datatable = '<tr class="LC_odd_row">'.
11387: '<td>'.$title{'togglecats'}.'</td>'.
11388: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11389: '<input type="radio" name="togglecats"'.
11390: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11391: '<label><input type="radio" name="togglecats"'.
11392: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
11393: '</tr><tr>'.
11394: '<td>'.$title{'categorize'}.'</td>'.
11395: '<td class="LC_right_item"><span class="LC_nobreak">'.
11396: '<label><input type="radio" name="categorize"'.
11397: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11398: '<label><input type="radio" name="categorize"'.
11399: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 11400: '</tr><tr class="LC_odd_row">'.
11401: '<td>'.$title{'togglecatscomm'}.'</td>'.
11402: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11403: '<input type="radio" name="togglecatscomm"'.
11404: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11405: '<label><input type="radio" name="togglecatscomm"'.
11406: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
11407: '</tr><tr>'.
11408: '<td>'.$title{'categorizecomm'}.'</td>'.
11409: '<td class="LC_right_item"><span class="LC_nobreak">'.
11410: '<label><input type="radio" name="categorizecomm"'.
11411: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11412: '<label><input type="radio" name="categorizecomm"'.
11413: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 11414: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 11415: '<td>'.$title{'togglecatsplace'}.'</td>'.
11416: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11417: '<input type="radio" name="togglecatsplace"'.
11418: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11419: '<label><input type="radio" name="togglecatscomm"'.
11420: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
11421: '</tr><tr>'.
11422: '<td>'.$title{'categorizeplace'}.'</td>'.
11423: '<td class="LC_right_item"><span class="LC_nobreak">'.
11424: '<label><input type="radio" name="categorizeplace"'.
11425: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11426: '<label><input type="radio" name="categorizeplace"'.
11427: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 11428: '</tr>';
1.272 raeburn 11429: $$rowtotal += 6;
1.57 raeburn 11430: } else {
11431: my $css_class;
11432: my $itemcount = 1;
11433: my $cathash;
11434: if (ref($settings) eq 'HASH') {
11435: $cathash = $settings->{'cats'};
11436: }
11437: if (ref($cathash) eq 'HASH') {
11438: my (@cats,@trails,%allitems,%idx,@jsarray);
11439: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
11440: \%allitems,\%idx,\@jsarray);
11441: my $maxdepth = scalar(@cats);
11442: my $colattrib = '';
11443: if ($maxdepth > 2) {
11444: $colattrib = ' colspan="2" ';
11445: }
11446: my @path;
11447: if (@cats > 0) {
11448: if (ref($cats[0]) eq 'ARRAY') {
11449: my $numtop = @{$cats[0]};
11450: my $maxnum = $numtop;
1.120 raeburn 11451: my %default_names = (
11452: instcode => &mt('Official courses'),
11453: communities => &mt('Communities'),
1.272 raeburn 11454: placement => &mt('Placement Tests'),
1.120 raeburn 11455: );
11456:
11457: if ((!grep(/^instcode$/,@{$cats[0]})) ||
11458: ($cathash->{'instcode::0'} eq '') ||
11459: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 11460: ($cathash->{'communities::0'} eq '') ||
11461: (!grep(/^placement$/,@{$cats[0]})) ||
11462: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 11463: $maxnum ++;
11464: }
11465: my $lastidx;
11466: for (my $i=0; $i<$numtop; $i++) {
11467: my $parent = $cats[0][$i];
11468: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11469: my $item = &escape($parent).'::0';
11470: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
11471: $lastidx = $idx{$item};
11472: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
11473: .'<select name="'.$item.'"'.$chgstr.'>';
11474: for (my $k=0; $k<=$maxnum; $k++) {
11475: my $vpos = $k+1;
11476: my $selstr;
11477: if ($k == $i) {
11478: $selstr = ' selected="selected" ';
11479: }
11480: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11481: }
1.214 raeburn 11482: $datatable .= '</select></span></td><td>';
1.272 raeburn 11483: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 11484: $datatable .= '<span class="LC_nobreak">'
11485: .$default_names{$parent}.'</span>';
11486: if ($parent eq 'instcode') {
11487: $datatable .= '<br /><span class="LC_nobreak">('
11488: .&mt('with institutional codes')
11489: .')</span></td><td'.$colattrib.'>';
11490: } else {
11491: $datatable .= '<table><tr><td>';
11492: }
11493: $datatable .= '<span class="LC_nobreak">'
11494: .'<label><input type="radio" name="'
11495: .$parent.'" value="1" checked="checked" />'
11496: .&mt('Display').'</label>';
11497: if ($parent eq 'instcode') {
11498: $datatable .= ' ';
11499: } else {
11500: $datatable .= '</span></td></tr><tr><td>'
11501: .'<span class="LC_nobreak">';
11502: }
11503: $datatable .= '<label><input type="radio" name="'
11504: .$parent.'" value="0" />'
11505: .&mt('Do not display').'</label></span>';
1.272 raeburn 11506: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 11507: $datatable .= '</td></tr></table>';
11508: }
11509: $datatable .= '</td>';
1.57 raeburn 11510: } else {
11511: $datatable .= $parent
1.214 raeburn 11512: .' <span class="LC_nobreak"><label>'
11513: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 11514: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
11515: }
11516: my $depth = 1;
11517: push(@path,$parent);
11518: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
11519: pop(@path);
11520: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
11521: $itemcount ++;
11522: }
1.48 raeburn 11523: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 11524: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
11525: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 11526: for (my $k=0; $k<=$maxnum; $k++) {
11527: my $vpos = $k+1;
11528: my $selstr;
1.57 raeburn 11529: if ($k == $numtop) {
1.48 raeburn 11530: $selstr = ' selected="selected" ';
11531: }
11532: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11533: }
1.59 bisitz 11534: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 11535: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
11536: .'</tr>'."\n";
1.48 raeburn 11537: $itemcount ++;
1.272 raeburn 11538: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11539: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
11540: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11541: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
11542: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
11543: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
11544: for (my $k=0; $k<=$maxnum; $k++) {
11545: my $vpos = $k+1;
11546: my $selstr;
11547: if ($k == $maxnum) {
11548: $selstr = ' selected="selected" ';
11549: }
11550: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 11551: }
1.120 raeburn 11552: $datatable .= '</select></span></td>'.
11553: '<td><span class="LC_nobreak">'.
11554: $default_names{$default}.'</span>';
11555: if ($default eq 'instcode') {
11556: $datatable .= '<br /><span class="LC_nobreak">('
11557: .&mt('with institutional codes').')</span>';
11558: }
11559: $datatable .= '</td>'
11560: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
11561: .&mt('Display').'</label> '
11562: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
11563: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 11564: }
11565: }
11566: }
1.57 raeburn 11567: } else {
11568: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 11569: }
11570: } else {
1.327 raeburn 11571: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 11572: .&initialize_categories($itemcount);
1.48 raeburn 11573: }
1.57 raeburn 11574: $$rowtotal += $itemcount;
1.48 raeburn 11575: }
11576: return $datatable;
11577: }
11578:
1.69 raeburn 11579: sub print_serverstatuses {
11580: my ($dom,$settings,$rowtotal) = @_;
11581: my $datatable;
11582: my @pages = &serverstatus_pages();
11583: my (%namedaccess,%machineaccess);
11584: foreach my $type (@pages) {
11585: $namedaccess{$type} = '';
11586: $machineaccess{$type}= '';
11587: }
11588: if (ref($settings) eq 'HASH') {
11589: foreach my $type (@pages) {
11590: if (exists($settings->{$type})) {
11591: if (ref($settings->{$type}) eq 'HASH') {
11592: foreach my $key (keys(%{$settings->{$type}})) {
11593: if ($key eq 'namedusers') {
11594: $namedaccess{$type} = $settings->{$type}->{$key};
11595: } elsif ($key eq 'machines') {
11596: $machineaccess{$type} = $settings->{$type}->{$key};
11597: }
11598: }
11599: }
11600: }
11601: }
11602: }
1.81 raeburn 11603: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11604: my $rownum = 0;
11605: my $css_class;
11606: foreach my $type (@pages) {
11607: $rownum ++;
11608: $css_class = $rownum%2?' class="LC_odd_row"':'';
11609: $datatable .= '<tr'.$css_class.'>'.
11610: '<td><span class="LC_nobreak">'.
11611: $titles->{$type}.'</span></td>'.
11612: '<td class="LC_left_item">'.
11613: '<input type="text" name="'.$type.'_namedusers" '.
11614: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
11615: '<td class="LC_right_item">'.
11616: '<span class="LC_nobreak">'.
11617: '<input type="text" name="'.$type.'_machines" '.
11618: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 11619: '</span></td></tr>'."\n";
1.69 raeburn 11620: }
11621: $$rowtotal += $rownum;
11622: return $datatable;
11623: }
11624:
11625: sub serverstatus_pages {
11626: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 11627: 'checksums','clusterstatus','certstatus','metadata_keywords',
11628: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
11629: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 11630: }
11631:
1.236 raeburn 11632: sub defaults_javascript {
11633: my ($settings) = @_;
1.354 raeburn 11634: return unless (ref($settings) eq 'HASH');
1.414 raeburn 11635: my $portal_js = <<"ENDPORTAL";
11636:
11637: function portalExtras(caller) {
11638: var x = caller.value;
11639: var y = new Array('email','web');
1.425 raeburn 11640: for (var i=0; i<y.length; i++) {
1.414 raeburn 11641: if (document.getElementById('portal_def_'+y[i]+'_div')) {
11642: var z = document.getElementById('portal_def_'+y[i]+'_div');
11643: if (x.length > 0) {
11644: z.style.display = 'block';
11645: } else {
11646: z.style.display = 'none';
11647: }
11648: }
11649: }
11650: }
11651: ENDPORTAL
1.236 raeburn 11652: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
11653: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
11654: if ($maxnum eq '') {
11655: $maxnum = 0;
11656: }
11657: $maxnum ++;
1.249 raeburn 11658: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 11659: return <<"ENDSCRIPT";
11660: <script type="text/javascript">
11661: // <![CDATA[
11662: function reorderTypes(form,caller) {
11663: var changedVal;
11664: $jstext
11665: var newpos = 'addinststatus_pos';
11666: var current = new Array;
11667: var maxh = $maxnum;
11668: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11669: var oldVal;
11670: if (caller == newpos) {
11671: changedVal = newitemVal;
11672: } else {
11673: var curritem = 'inststatus_pos_'+caller;
11674: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
11675: current[newitemVal] = newpos;
11676: }
11677: for (var i=0; i<inststatuses.length; i++) {
11678: if (inststatuses[i] != caller) {
11679: var elementName = 'inststatus_pos_'+inststatuses[i];
11680: if (form.elements[elementName]) {
11681: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11682: current[currVal] = elementName;
11683: }
11684: }
11685: }
11686: for (var j=0; j<maxh; j++) {
11687: if (current[j] == undefined) {
11688: oldVal = j;
11689: }
11690: }
11691: if (oldVal < changedVal) {
11692: for (var k=oldVal+1; k<=changedVal ; k++) {
11693: var elementName = current[k];
11694: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11695: }
11696: } else {
11697: for (var k=changedVal; k<oldVal; k++) {
11698: var elementName = current[k];
11699: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11700: }
11701: }
11702: return;
11703: }
11704:
1.414 raeburn 11705: $portal_js
11706:
11707: // ]]>
11708: </script>
11709:
11710: ENDSCRIPT
11711: } else {
11712: return <<"ENDSCRIPT";
11713: <script type="text/javascript">
11714: // <![CDATA[
11715: $portal_js
1.236 raeburn 11716: // ]]>
11717: </script>
11718:
11719: ENDSCRIPT
11720: }
1.354 raeburn 11721: return;
11722: }
11723:
11724: sub passwords_javascript {
1.405 raeburn 11725: my ($prefix) = @_;
11726: my %intalert;
11727: if ($prefix eq 'passwords') {
11728: %intalert = &Apache::lonlocal::texthash (
11729: 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.',
11730: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
11731: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
11732: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
11733: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
11734: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
11735: );
1.421 raeburn 11736: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 11737: %intalert = &Apache::lonlocal::texthash (
11738: passmin => 'Warning: minimum secret length must be a positive integer greater than 6.',
11739: passmax => 'Warning: maximum secret length must be a positive integer (or blank).',
11740: );
11741: }
1.365 raeburn 11742: &js_escape(\%intalert);
11743: my $defmin = $Apache::lonnet::passwdmin;
1.425 raeburn 11744: my $intauthjs;
1.405 raeburn 11745: if ($prefix eq 'passwords') { $intauthjs = <<"ENDSCRIPT";
1.354 raeburn 11746:
11747: function warnIntAuth(field) {
11748: if (field.name == 'intauth_check') {
11749: if (field.value == '2') {
1.365 raeburn 11750: alert('$intalert{authcheck}');
1.354 raeburn 11751: }
11752: }
11753: if (field.name == 'intauth_cost') {
11754: field.value.replace(/\s/g,'');
11755: if (field.value != '') {
11756: var regexdigit=/^\\d+\$/;
11757: if (!regexdigit.test(field.value)) {
1.365 raeburn 11758: alert('$intalert{authcost}');
11759: }
11760: }
11761: }
11762: return;
11763: }
11764:
1.405 raeburn 11765: ENDSCRIPT
11766:
11767: }
11768:
11769: $intauthjs .= <<"ENDSCRIPT";
11770:
11771: function warnInt$prefix(field) {
1.365 raeburn 11772: field.value.replace(/^\s+/,'');
11773: field.value.replace(/\s+\$/,'');
11774: var regexdigit=/^\\d+\$/;
1.408 raeburn 11775: if (field.name == '${prefix}_min') {
1.365 raeburn 11776: if (field.value == '') {
11777: alert('$intalert{passmin}');
11778: field.value = '$defmin';
11779: } else {
11780: if (!regexdigit.test(field.value)) {
11781: alert('$intalert{passmin}');
11782: field.value = '$defmin';
11783: }
1.366 raeburn 11784: var minval = parseInt(field.value,10);
1.365 raeburn 11785: if (minval < $defmin) {
11786: alert('$intalert{passmin}');
11787: field.value = '$defmin';
11788: }
11789: }
11790: } else {
11791: if (field.value == '0') {
11792: field.value = '';
11793: }
11794: if (field.value != '') {
1.408 raeburn 11795: if (field.name == '${prefix}_expire') {
1.365 raeburn 11796: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
11797: if (!regexpposnum.test(field.value)) {
11798: alert('$intalert{passexp}');
11799: field.value = '';
11800: } else {
11801: var expval = parseFloat(field.value);
11802: if (expval == 0) {
11803: alert('$intalert{passexp}');
11804: field.value = '';
11805: }
11806: }
11807: } else {
11808: if (!regexdigit.test(field.value)) {
1.408 raeburn 11809: if (field.name == '${prefix}_max') {
1.365 raeburn 11810: alert('$intalert{passmax}');
11811: } else {
1.408 raeburn 11812: if (field.name == '${prefix}_numsaved') {
1.365 raeburn 11813: alert('$intalert{passnum}');
11814: }
11815: }
1.370 raeburn 11816: field.value = '';
1.365 raeburn 11817: }
1.354 raeburn 11818: }
11819: }
11820: }
11821: return;
11822: }
11823:
11824: ENDSCRIPT
11825: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 11826: }
11827:
1.49 raeburn 11828: sub coursecategories_javascript {
11829: my ($settings) = @_;
1.57 raeburn 11830: my ($output,$jstext,$cathash);
1.49 raeburn 11831: if (ref($settings) eq 'HASH') {
1.57 raeburn 11832: $cathash = $settings->{'cats'};
11833: }
11834: if (ref($cathash) eq 'HASH') {
1.49 raeburn 11835: my (@cats,@jsarray,%idx);
1.57 raeburn 11836: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 11837: if (@jsarray > 0) {
11838: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
11839: for (my $i=0; $i<@jsarray; $i++) {
11840: if (ref($jsarray[$i]) eq 'ARRAY') {
11841: my $catstr = join('","',@{$jsarray[$i]});
11842: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
11843: }
11844: }
11845: }
11846: } else {
11847: $jstext = ' var categories = Array(1);'."\n".
11848: ' categories[0] = Array("instcode_pos");'."\n";
11849: }
1.237 bisitz 11850: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
11851: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 11852: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 11853: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
11854: &js_escape(\$instcode_reserved);
11855: &js_escape(\$communities_reserved);
1.272 raeburn 11856: &js_escape(\$placement_reserved);
1.265 damieng 11857: &js_escape(\$choose_again);
1.49 raeburn 11858: $output = <<"ENDSCRIPT";
11859: <script type="text/javascript">
1.109 raeburn 11860: // <![CDATA[
1.49 raeburn 11861: function reorderCats(form,parent,item,idx) {
11862: var changedVal;
11863: $jstext
11864: var newpos = 'addcategory_pos';
11865: if (parent == '') {
11866: var has_instcode = 0;
11867: var maxtop = categories[idx].length;
11868: for (var j=0; j<maxtop; j++) {
11869: if (categories[idx][j] == 'instcode::0') {
11870: has_instcode == 1;
11871: }
11872: }
11873: if (has_instcode == 0) {
11874: categories[idx][maxtop] = 'instcode_pos';
11875: }
11876: } else {
11877: newpos += '_'+parent;
11878: }
11879: var maxh = 1 + categories[idx].length;
11880: var current = new Array;
11881: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11882: if (item == newpos) {
11883: changedVal = newitemVal;
11884: } else {
11885: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
11886: current[newitemVal] = newpos;
11887: }
11888: for (var i=0; i<categories[idx].length; i++) {
11889: var elementName = categories[idx][i];
11890: if (elementName != item) {
11891: if (form.elements[elementName]) {
11892: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11893: current[currVal] = elementName;
11894: }
11895: }
11896: }
11897: var oldVal;
11898: for (var j=0; j<maxh; j++) {
11899: if (current[j] == undefined) {
11900: oldVal = j;
11901: }
11902: }
11903: if (oldVal < changedVal) {
11904: for (var k=oldVal+1; k<=changedVal ; k++) {
11905: var elementName = current[k];
11906: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11907: }
11908: } else {
11909: for (var k=changedVal; k<oldVal; k++) {
11910: var elementName = current[k];
11911: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11912: }
11913: }
11914: return;
11915: }
1.120 raeburn 11916:
11917: function categoryCheck(form) {
11918: if (form.elements['addcategory_name'].value == 'instcode') {
11919: alert('$instcode_reserved\\n$choose_again');
11920: return false;
11921: }
11922: if (form.elements['addcategory_name'].value == 'communities') {
11923: alert('$communities_reserved\\n$choose_again');
11924: return false;
11925: }
1.272 raeburn 11926: if (form.elements['addcategory_name'].value == 'placement') {
11927: alert('$placement_reserved\\n$choose_again');
11928: return false;
11929: }
1.120 raeburn 11930: return true;
11931: }
11932:
1.109 raeburn 11933: // ]]>
1.49 raeburn 11934: </script>
11935:
11936: ENDSCRIPT
11937: return $output;
11938: }
11939:
1.48 raeburn 11940: sub initialize_categories {
11941: my ($itemcount) = @_;
1.120 raeburn 11942: my ($datatable,$css_class,$chgstr);
1.380 raeburn 11943: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 11944: instcode => 'Official courses (with institutional codes)',
11945: communities => 'Communities',
1.272 raeburn 11946: placement => 'Placement Tests',
1.120 raeburn 11947: );
1.328 raeburn 11948: my %selnum = (
11949: instcode => '0',
11950: communities => '1',
11951: placement => '2',
11952: );
11953: my %selected;
1.272 raeburn 11954: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11955: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 11956: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 11957: map { $selected{$selnum{$_}} = '' } keys(%selnum);
11958: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 11959: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 11960: .'<select name="'.$default.'_pos"'.$chgstr.'>'
11961: .'<option value="0"'.$selected{'0'}.'>1</option>'
11962: .'<option value="1"'.$selected{'1'}.'>2</option>'
11963: .'<option value="2"'.$selected{'2'}.'>3</option>'
11964: .'<option value="3">4</option></select> '
1.120 raeburn 11965: .$default_names{$default}
11966: .'</span></td><td><span class="LC_nobreak">'
11967: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
11968: .&mt('Display').'</label> <label>'
11969: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 11970: .'</label></span></td></tr>';
1.120 raeburn 11971: $itemcount ++;
11972: }
1.48 raeburn 11973: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 11974: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 11975: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 11976: .'<select name="addcategory_pos"'.$chgstr.'>'
11977: .'<option value="0">1</option>'
11978: .'<option value="1">2</option>'
1.328 raeburn 11979: .'<option value="2">3</option>'
11980: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 11981: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
11982: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
11983: .'</td></tr>';
1.48 raeburn 11984: return $datatable;
11985: }
11986:
11987: sub build_category_rows {
1.49 raeburn 11988: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
11989: my ($text,$name,$item,$chgstr);
1.48 raeburn 11990: if (ref($cats) eq 'ARRAY') {
11991: my $maxdepth = scalar(@{$cats});
11992: if (ref($cats->[$depth]) eq 'HASH') {
11993: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
11994: my $numchildren = @{$cats->[$depth]{$parent}};
11995: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 11996: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 11997: my ($idxnum,$parent_name,$parent_item);
11998: my $higher = $depth - 1;
11999: if ($higher == 0) {
12000: $parent_name = &escape($parent).'::'.$higher;
12001: } else {
12002: if (ref($path) eq 'ARRAY') {
12003: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
12004: }
12005: }
12006: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 12007: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 12008: if ($j < $numchildren) {
1.48 raeburn 12009: $name = $cats->[$depth]{$parent}[$j];
12010: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 12011: $idxnum = $idx->{$item};
12012: } else {
12013: $name = $parent_name;
12014: $item = $parent_item;
1.48 raeburn 12015: }
1.49 raeburn 12016: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
12017: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 12018: for (my $i=0; $i<=$numchildren; $i++) {
12019: my $vpos = $i+1;
12020: my $selstr;
12021: if ($j == $i) {
12022: $selstr = ' selected="selected" ';
12023: }
12024: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
12025: }
12026: $text .= '</select> ';
12027: if ($j < $numchildren) {
12028: my $deeper = $depth+1;
12029: $text .= $name.' '
12030: .'<label><input type="checkbox" name="deletecategory" value="'
12031: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
12032: if(ref($path) eq 'ARRAY') {
12033: push(@{$path},$name);
1.49 raeburn 12034: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 12035: pop(@{$path});
12036: }
12037: } else {
1.330 raeburn 12038: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 12039: if ($j == $numchildren) {
12040: $text .= $name;
12041: } else {
12042: $text .= $item;
12043: }
12044: $text .= '" value="" />';
12045: }
12046: $text .= '</td></tr>';
12047: }
12048: $text .= '</table></td>';
12049: } else {
12050: my $higher = $depth-1;
12051: if ($higher == 0) {
12052: $name = &escape($parent).'::'.$higher;
12053: } else {
12054: if (ref($path) eq 'ARRAY') {
12055: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
12056: }
12057: }
12058: my $colspan;
12059: if ($parent ne 'instcode') {
12060: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 12061: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 12062: }
12063: }
12064: }
12065: }
12066: return $text;
12067: }
12068:
1.33 raeburn 12069: sub modifiable_userdata_row {
1.305 raeburn 12070: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357 raeburn 12071: $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228 raeburn 12072: my ($role,$rolename,$statustype);
12073: $role = $item;
1.224 raeburn 12074: if ($context eq 'cancreate') {
1.305 raeburn 12075: if ($item =~ /^(emailusername)_(.+)$/) {
12076: $role = $1;
12077: $statustype = $2;
1.228 raeburn 12078: if (ref($usertypes) eq 'HASH') {
12079: if ($usertypes->{$statustype}) {
12080: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
12081: } else {
12082: $rolename = &mt('Data provided by user');
12083: }
12084: }
1.224 raeburn 12085: }
12086: } elsif ($context eq 'selfcreate') {
1.63 raeburn 12087: if (ref($usertypes) eq 'HASH') {
12088: $rolename = $usertypes->{$role};
12089: } else {
12090: $rolename = $role;
12091: }
1.325 raeburn 12092: } elsif ($context eq 'lti') {
12093: $rolename = &mt('Institutional data used (if available)');
1.357 raeburn 12094: } elsif ($context eq 'privacy') {
12095: $rolename = $itemdesc;
1.33 raeburn 12096: } else {
1.63 raeburn 12097: if ($role eq 'cr') {
12098: $rolename = &mt('Custom role');
12099: } else {
12100: $rolename = &Apache::lonnet::plaintext($role);
12101: }
1.33 raeburn 12102: }
1.224 raeburn 12103: my (@fields,%fieldtitles);
12104: if (ref($fieldsref) eq 'ARRAY') {
12105: @fields = @{$fieldsref};
12106: } else {
12107: @fields = ('lastname','firstname','middlename','generation',
12108: 'permanentemail','id');
12109: }
12110: if ((ref($titlesref) eq 'HASH')) {
12111: %fieldtitles = %{$titlesref};
12112: } else {
12113: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12114: }
1.33 raeburn 12115: my $output;
1.305 raeburn 12116: my $css_class;
12117: if ($rowcount%2) {
12118: $css_class = 'LC_odd_row';
12119: }
12120: if ($customcss) {
12121: $css_class .= " $customcss";
12122: }
12123: $css_class =~ s/^\s+//;
12124: if ($css_class) {
12125: $css_class = ' class="'.$css_class.'"';
12126: }
12127: if ($rowstyle) {
12128: $css_class .= ' style="'.$rowstyle.'"';
12129: }
12130: if ($rowid) {
12131: $rowid = ' id="'.$rowid.'"';
12132: }
12133: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 12134: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
12135: '<td class="LC_left_item" colspan="2"><table>';
12136: my $rem;
12137: my %checks;
12138: if (ref($settings) eq 'HASH') {
1.325 raeburn 12139: my $hashref;
12140: if ($context eq 'lti') {
12141: if (ref($settings) eq 'HASH') {
12142: $hashref = $settings->{'instdata'};
12143: }
1.357 raeburn 12144: } elsif ($context eq 'privacy') {
12145: my ($key,$inner) = split(/_/,$role);
12146: if (ref($settings) eq 'HASH') {
12147: if (ref($settings->{$key}) eq 'HASH') {
12148: $hashref = $settings->{$key}->{$inner};
12149: }
12150: }
1.325 raeburn 12151: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 12152: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 12153: $hashref = $settings->{'lti_instdata'};
12154: }
12155: if ($role eq 'emailusername') {
12156: if ($statustype) {
12157: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
12158: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 12159: }
1.325 raeburn 12160: }
12161: }
12162: }
1.425 raeburn 12163: if (ref($hashref) eq 'HASH') {
1.325 raeburn 12164: foreach my $field (@fields) {
12165: if ($hashref->{$field}) {
12166: if ($role eq 'emailusername') {
12167: $checks{$field} = $hashref->{$field};
12168: } else {
12169: $checks{$field} = ' checked="checked" ';
1.33 raeburn 12170: }
12171: }
12172: }
12173: }
12174: }
1.305 raeburn 12175: my $total = scalar(@fields);
12176: for (my $i=0; $i<$total; $i++) {
12177: $rem = $i%($numinrow);
1.33 raeburn 12178: if ($rem == 0) {
12179: if ($i > 0) {
12180: $output .= '</tr>';
12181: }
12182: $output .= '<tr>';
12183: }
12184: my $check = ' ';
1.228 raeburn 12185: unless ($role eq 'emailusername') {
12186: if (exists($checks{$fields[$i]})) {
1.354 raeburn 12187: $check = $checks{$fields[$i]};
1.357 raeburn 12188: } elsif ($context eq 'privacy') {
12189: if ($role =~ /^priv_(domain|course)$/) {
12190: if (ref($settings) ne 'HASH') {
12191: $check = ' checked="checked" ';
12192: }
12193: } elsif ($role =~ /^priv_(author|community)$/) {
12194: if (ref($settings) ne 'HASH') {
12195: unless ($fields[$i] eq 'id') {
12196: $check = ' checked="checked" ';
12197: }
12198: }
12199: } elsif ($role =~ /^(unpriv|othdom)_/) {
12200: if (ref($settings) ne 'HASH') {
12201: if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
12202: $check = ' checked="checked" ';
12203: }
12204: }
12205: }
1.325 raeburn 12206: } elsif ($context ne 'lti') {
1.228 raeburn 12207: if ($role eq 'st') {
12208: if (ref($settings) ne 'HASH') {
12209: $check = ' checked="checked" ';
12210: }
1.33 raeburn 12211: }
12212: }
12213: }
12214: $output .= '<td class="LC_left_item">'.
1.228 raeburn 12215: '<span class="LC_nobreak">';
1.325 raeburn 12216: my $prefix = 'canmodify';
1.228 raeburn 12217: if ($role eq 'emailusername') {
12218: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
12219: $checks{$fields[$i]} = 'omit';
12220: }
12221: foreach my $option ('required','optional','omit') {
12222: my $checked='';
12223: if ($checks{$fields[$i]} eq $option) {
12224: $checked='checked="checked" ';
12225: }
12226: $output .= '<label>'.
1.325 raeburn 12227: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 12228: &mt($option).'</label>'.(' ' x2);
12229: }
12230: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
12231: } else {
1.325 raeburn 12232: if ($context eq 'lti') {
12233: $prefix = 'lti';
1.443 raeburn 12234: } elsif ($context eq 'coauthor') {
12235: $prefix = 'cacanmodify';
1.357 raeburn 12236: } elsif ($context eq 'privacy') {
12237: $prefix = 'privacy';
1.325 raeburn 12238: }
1.228 raeburn 12239: $output .= '<label>'.
1.325 raeburn 12240: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 12241: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
12242: '</label>';
12243: }
12244: $output .= '</span></td>';
1.33 raeburn 12245: }
1.305 raeburn 12246: $rem = $total%$numinrow;
12247: my $colsleft;
12248: if ($rem) {
12249: $colsleft = $numinrow - $rem;
12250: }
12251: if ($colsleft > 1) {
1.33 raeburn 12252: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
12253: ' </td>';
12254: } elsif ($colsleft == 1) {
12255: $output .= '<td class="LC_left_item"> </td>';
12256: }
12257: $output .= '</tr></table></td></tr>';
12258: return $output;
12259: }
1.28 raeburn 12260:
1.93 raeburn 12261: sub insttypes_row {
1.305 raeburn 12262: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
12263: $customcss,$rowstyle) = @_;
1.93 raeburn 12264: my %lt = &Apache::lonlocal::texthash (
1.429 raeburn 12265: cansearch => 'Users allowed to search',
1.93 raeburn 12266: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.429 raeburn 12267: lockablenames => 'User preference to lock name',
12268: selfassign => 'Self-reportable affiliations',
12269: overrides => "Override domain's helpdesk settings based on requester's affiliation",
12270: webdav => 'WebDAV access available',
12271: authorquota => 'Authoring Space quota (MB)',
1.93 raeburn 12272: );
1.429 raeburn 12273: my ($showdom,$defaultquota);
1.93 raeburn 12274: if ($context eq 'cansearch') {
12275: $showdom = ' ('.$dom.')';
1.429 raeburn 12276: } elsif ($context eq 'authorquota') {
12277: $defaultquota = 500;
1.93 raeburn 12278: }
1.165 raeburn 12279: my $class = 'LC_left_item';
12280: if ($context eq 'statustocreate') {
12281: $class = 'LC_right_item';
12282: }
1.305 raeburn 12283: my $css_class;
12284: if ($$rowtotal%2) {
12285: $css_class = 'LC_odd_row';
12286: }
12287: if ($customcss) {
12288: $css_class .= ' '.$customcss;
12289: }
12290: $css_class =~ s/^\s+//;
12291: if ($css_class) {
12292: $css_class = ' class="'.$css_class.'"';
12293: }
12294: if ($rowstyle) {
12295: $css_class .= ' style="'.$rowstyle.'"';
12296: }
12297: if ($onclick) {
12298: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 12299: }
12300: my $output = '<tr'.$css_class.'>'.
12301: '<td>'.$lt{$context}.$showdom.
12302: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 12303: my $rem;
12304: if (ref($types) eq 'ARRAY') {
12305: for (my $i=0; $i<@{$types}; $i++) {
12306: if (defined($usertypes->{$types->[$i]})) {
12307: my $rem = $i%($numinrow);
12308: if ($rem == 0) {
12309: if ($i > 0) {
12310: $output .= '</tr>';
12311: }
12312: $output .= '<tr>';
1.23 raeburn 12313: }
1.429 raeburn 12314: if ($context eq 'authorquota') {
12315: my $currquota;
12316: if ($settings->{$context}->{$types->[$i]} =~ /^\d+$/) {
12317: $currquota = $settings->{$context}->{$types->[$i]};
12318: } else {
12319: $currquota = $defaultquota;
12320: }
12321: $output .= '<td class="LC_left_item">'."\n".
12322: '<label><span class="LC_nobreak">'."\n".
12323: $usertypes->{$types->[$i]}.'</span><br />'."\n".
12324: '<input type="text" name="'.$context.'_'.$types->[$i].'" '.
12325: 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
12326: '</label></td>';
12327: } else {
12328: my $check = ' ';
12329: if (ref($settings) eq 'HASH') {
12330: if (ref($settings->{$context}) eq 'ARRAY') {
12331: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
12332: $check = ' checked="checked" ';
12333: }
12334: } elsif (ref($settings->{$context}) eq 'HASH') {
12335: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
12336: $check = ' checked="checked" ';
12337: } elsif ($context eq 'webdav') {
12338: if ($settings->{$context}->{$types->[$i]}) {
12339: $check = ' checked="checked" ';
12340: }
12341: }
12342: } elsif ($context eq 'statustocreate') {
1.315 raeburn 12343: $check = ' checked="checked" ';
12344: }
1.26 raeburn 12345: }
1.429 raeburn 12346: $output .= '<td class="LC_left_item">'.
12347: '<span class="LC_nobreak"><label>'.
12348: '<input type="checkbox" name="'.$context.'" '.
12349: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
12350: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 12351: }
12352: }
12353: }
1.26 raeburn 12354: $rem = @{$types}%($numinrow);
1.23 raeburn 12355: }
12356: my $colsleft = $numinrow - $rem;
1.315 raeburn 12357: if ($context eq 'overrides') {
12358: if ($colsleft > 1) {
12359: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12360: } else {
12361: $output .= '<td class="LC_left_item">';
12362: }
1.425 raeburn 12363: $output .= ' ';
1.23 raeburn 12364: } else {
1.334 raeburn 12365: if ($rem == 0) {
1.315 raeburn 12366: $output .= '<tr>';
12367: }
12368: if ($colsleft > 1) {
12369: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12370: } else {
12371: $output .= '<td class="LC_left_item">';
12372: }
1.429 raeburn 12373: if ($context eq 'authorquota') {
12374: my $currquota = 500;
12375: if ((ref($settings) eq 'HASH') && (ref($settings->{$context}) eq 'HASH')) {
12376: if ($settings->{$context}{'default'} =~ /^\d+$/) {
12377: $currquota = $settings->{$context}{'default'};
12378: }
12379: }
12380: $output .= '<label><span class="LC_nobreak">'.$othertitle.'</span><br />'."\n".
12381: '<input type="text" name="'.$context.'_default" '.
12382: 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
12383: '</label>';
12384: } else {
12385: my $defcheck = ' ';
12386: if (ref($settings) eq 'HASH') {
12387: if (ref($settings->{$context}) eq 'ARRAY') {
12388: if (grep(/^default$/,@{$settings->{$context}})) {
12389: $defcheck = ' checked="checked" ';
12390: }
12391: } elsif (ref($settings->{$context}) eq 'HASH') {
12392: if (ref($settings->{$context}->{'default'}) eq 'HASH') {
12393: $defcheck = ' checked="checked" ';
12394: } elsif ($context eq 'webdav') {
12395: if ($settings->{$context}->{'default'}) {
12396: $defcheck = ' checked="checked" ';
12397: }
12398: }
12399: } elsif ($context eq 'statustocreate') {
1.315 raeburn 12400: $defcheck = ' checked="checked" ';
12401: }
1.99 raeburn 12402: }
1.429 raeburn 12403: $output .= '<span class="LC_nobreak"><label>'.
12404: '<input type="checkbox" name="'.$context.'" '.
12405: 'value="default"'.$defcheck.$onclick.'/>'.
12406: $othertitle.'</label></span>';
1.26 raeburn 12407: }
1.23 raeburn 12408: }
1.315 raeburn 12409: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 12410: return $output;
1.23 raeburn 12411: }
12412:
12413: sub sorted_searchtitles {
12414: my %searchtitles = &Apache::lonlocal::texthash(
12415: 'uname' => 'username',
12416: 'lastname' => 'last name',
12417: 'lastfirst' => 'last name, first name',
12418: );
12419: my @titleorder = ('uname','lastname','lastfirst');
12420: return (\%searchtitles,\@titleorder);
12421: }
12422:
1.25 raeburn 12423: sub sorted_searchtypes {
12424: my %srchtypes_desc = (
12425: exact => 'is exact match',
12426: contains => 'contains ..',
12427: begins => 'begins with ..',
12428: );
12429: my @srchtypeorder = ('exact','begins','contains');
12430: return (\%srchtypes_desc,\@srchtypeorder);
12431: }
12432:
1.3 raeburn 12433: sub usertype_update_row {
12434: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
12435: my $datatable;
12436: my $numinrow = 4;
12437: foreach my $type (@{$types}) {
12438: if (defined($usertypes->{$type})) {
12439: $$rownums ++;
12440: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
12441: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
12442: '</td><td class="LC_left_item"><table>';
12443: for (my $i=0; $i<@{$fields}; $i++) {
12444: my $rem = $i%($numinrow);
12445: if ($rem == 0) {
12446: if ($i > 0) {
12447: $datatable .= '</tr>';
12448: }
12449: $datatable .= '<tr>';
12450: }
12451: my $check = ' ';
1.39 raeburn 12452: if (ref($settings) eq 'HASH') {
12453: if (ref($settings->{'fields'}) eq 'HASH') {
12454: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
12455: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
12456: $check = ' checked="checked" ';
12457: }
1.3 raeburn 12458: }
12459: }
12460: }
12461:
12462: if ($i == @{$fields}-1) {
12463: my $colsleft = $numinrow - $rem;
12464: if ($colsleft > 1) {
12465: $datatable .= '<td colspan="'.$colsleft.'">';
12466: } else {
12467: $datatable .= '<td>';
12468: }
12469: } else {
12470: $datatable .= '<td>';
12471: }
1.8 raeburn 12472: $datatable .= '<span class="LC_nobreak"><label>'.
12473: '<input type="checkbox" name="updateable_'.$type.
12474: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
12475: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 12476: }
12477: $datatable .= '</tr></table></td></tr>';
12478: }
12479: }
12480: return $datatable;
1.1 raeburn 12481: }
12482:
12483: sub modify_login {
1.205 raeburn 12484: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 12485: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.386 raeburn 12486: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
1.412 raeburn 12487: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso);
1.168 raeburn 12488: %title = ( coursecatalog => 'Display course catalog',
12489: adminmail => 'Display administrator E-mail address',
1.188 raeburn 12490: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 12491: newuser => 'Link for visitors to create a user account',
1.386 raeburn 12492: loginheader => 'Log-in box header',
12493: saml => 'Dual SSO and non-SSO login');
1.168 raeburn 12494: @offon = ('off','on');
1.112 raeburn 12495: if (ref($domconfig{login}) eq 'HASH') {
12496: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
12497: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
12498: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
12499: }
12500: }
1.386 raeburn 12501: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
12502: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
12503: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
12504: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
12505: $saml{$lonhost} = 1;
12506: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
12507: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
12508: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
12509: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
12510: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
1.412 raeburn 12511: $samlwindow{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'window'};
1.386 raeburn 12512: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
12513: }
12514: }
12515: }
1.112 raeburn 12516: }
1.9 raeburn 12517: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
12518: \%domconfig,\%loginhash);
1.188 raeburn 12519: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12520: foreach my $item (@toggles) {
12521: $loginhash{login}{$item} = $env{'form.'.$item};
12522: }
1.41 raeburn 12523: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 12524: if (ref($colchanges{'login'}) eq 'HASH') {
12525: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
12526: \%loginhash);
12527: }
1.110 raeburn 12528:
1.149 raeburn 12529: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 12530: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 12531: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 12532: if (keys(%servers) > 1) {
12533: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 12534: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
12535: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
12536: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
12537: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
12538: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
12539: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12540: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12541: $changes{'loginvia'}{$lonhost} = 1;
12542: } else {
12543: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
12544: $changes{'loginvia'}{$lonhost} = 1;
12545: }
12546: } else {
12547: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12548: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12549: $changes{'loginvia'}{$lonhost} = 1;
12550: }
12551: }
12552: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
12553: foreach my $item (@loginvia_attribs) {
12554: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
12555: }
12556: } else {
12557: foreach my $item (@loginvia_attribs) {
12558: my $new = $env{'form.'.$lonhost.'_'.$item};
12559: if (($item eq 'serverpath') && ($new eq 'custom')) {
12560: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
12561: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12562: $new = '/';
12563: }
12564: }
12565: if (($item eq 'custompath') &&
12566: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12567: $new = '';
12568: }
12569: if ($new ne $curr_loginvia{$lonhost}{$item}) {
12570: $changes{'loginvia'}{$lonhost} = 1;
12571: }
12572: if ($item eq 'exempt') {
1.256 raeburn 12573: $new = &check_exempt_addresses($new);
1.128 raeburn 12574: }
12575: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12576: }
12577: }
1.112 raeburn 12578: } else {
1.128 raeburn 12579: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12580: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 12581: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 12582: foreach my $item (@loginvia_attribs) {
12583: my $new = $env{'form.'.$lonhost.'_'.$item};
12584: if (($item eq 'serverpath') && ($new eq 'custom')) {
12585: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12586: $new = '/';
12587: }
12588: }
12589: if (($item eq 'custompath') &&
12590: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12591: $new = '';
12592: }
12593: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12594: }
1.110 raeburn 12595: }
12596: }
12597: }
12598: }
1.119 raeburn 12599:
1.168 raeburn 12600: my $servadm = $r->dir_config('lonAdmEMail');
12601: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
12602: if (ref($domconfig{'login'}) eq 'HASH') {
12603: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
12604: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
12605: if ($lang eq 'nolang') {
12606: push(@currlangs,$lang);
12607: } elsif (defined($langchoices{$lang})) {
12608: push(@currlangs,$lang);
12609: } else {
12610: next;
12611: }
12612: }
12613: }
12614: }
12615: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
12616: if (@currlangs > 0) {
12617: foreach my $lang (@currlangs) {
12618: if (grep(/^\Q$lang\E$/,@delurls)) {
12619: $changes{'helpurl'}{$lang} = 1;
12620: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
12621: $changes{'helpurl'}{$lang} = 1;
12622: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
12623: push(@newlangs,$lang);
12624: } else {
12625: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12626: }
12627: }
12628: }
12629: unless (grep(/^nolang$/,@currlangs)) {
12630: if ($env{'form.loginhelpurl_nolang.filename'}) {
12631: $changes{'helpurl'}{'nolang'} = 1;
12632: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
12633: push(@newlangs,'nolang');
12634: }
12635: }
12636: if ($env{'form.loginhelpurl_add_lang'}) {
12637: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
12638: ($env{'form.loginhelpurl_add_file.filename'})) {
12639: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
12640: $addedfile = $env{'form.loginhelpurl_add_lang'};
12641: }
12642: }
12643: if ((@newlangs > 0) || ($addedfile)) {
12644: my $error;
12645: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12646: if ($configuserok eq 'ok') {
12647: if ($switchserver) {
12648: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
12649: } elsif ($author_ok eq 'ok') {
12650: my @allnew = @newlangs;
12651: if ($addedfile ne '') {
12652: push(@allnew,$addedfile);
12653: }
1.421 raeburn 12654: my $modified = [];
1.168 raeburn 12655: foreach my $lang (@allnew) {
12656: my $formelem = 'loginhelpurl_'.$lang;
12657: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
12658: $formelem = 'loginhelpurl_add_file';
12659: }
1.425 raeburn 12660: (my $result,$newurl{$lang}) =
1.421 raeburn 12661: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12662: "help/$lang",'','',$newfile{$lang},
12663: $modified);
1.168 raeburn 12664: if ($result eq 'ok') {
12665: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
12666: $changes{'helpurl'}{$lang} = 1;
12667: } else {
12668: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
12669: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 12670: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 12671: (!grep(/^\Q$lang\E$/,@delurls))) {
12672: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12673: }
12674: }
12675: }
1.421 raeburn 12676: &update_modify_urls($r,$modified);
1.168 raeburn 12677: } else {
12678: $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);
12679: }
12680: } else {
12681: $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);
12682: }
12683: if ($error) {
12684: &Apache::lonnet::logthis($error);
12685: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12686: }
12687: }
1.256 raeburn 12688:
12689: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
12690: if (ref($domconfig{'login'}) eq 'HASH') {
12691: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
12692: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
12693: if ($domservers{$lonhost}) {
12694: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12695: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 12696: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 12697: }
12698: }
12699: }
12700: }
12701: }
12702: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
12703: foreach my $lonhost (sort(keys(%domservers))) {
12704: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12705: $changes{'headtag'}{$lonhost} = 1;
12706: } else {
12707: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
12708: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
12709: }
12710: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
12711: push(@newhosts,$lonhost);
12712: } elsif ($currheadtagurls{$lonhost}) {
12713: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
12714: if ($currexempt{$lonhost}) {
1.289 raeburn 12715: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 12716: $changes{'headtag'}{$lonhost} = 1;
12717: }
12718: } elsif ($possexempt{$lonhost}) {
12719: $changes{'headtag'}{$lonhost} = 1;
12720: }
12721: if ($possexempt{$lonhost}) {
12722: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12723: }
12724: }
12725: }
12726: }
12727: if (@newhosts) {
12728: my $error;
12729: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12730: if ($configuserok eq 'ok') {
12731: if ($switchserver) {
12732: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
12733: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12734: my $modified = [];
1.256 raeburn 12735: foreach my $lonhost (@newhosts) {
12736: my $formelem = 'loginheadtag_'.$lonhost;
1.425 raeburn 12737: (my $result,$newheadtagurls{$lonhost}) =
1.421 raeburn 12738: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12739: "login/headtag/$lonhost",'','',
12740: $env{'form.loginheadtag_'.$lonhost.'.filename'},
12741: $modified);
1.256 raeburn 12742: if ($result eq 'ok') {
12743: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
12744: $changes{'headtag'}{$lonhost} = 1;
12745: if ($possexempt{$lonhost}) {
12746: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12747: }
12748: } else {
12749: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
12750: $newheadtagurls{$lonhost},$result);
12751: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12752: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
12753: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
12754: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
12755: }
12756: }
12757: }
1.421 raeburn 12758: &update_modify_urls($r,$modified);
1.256 raeburn 12759: } else {
12760: $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);
12761: }
12762: } else {
12763: $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);
12764: }
12765: if ($error) {
12766: &Apache::lonnet::logthis($error);
12767: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12768: }
12769: }
1.386 raeburn 12770: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
12771: my @newsamlimgs;
12772: foreach my $lonhost (keys(%domservers)) {
12773: if ($env{'form.saml_'.$lonhost}) {
12774: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
12775: push(@newsamlimgs,$lonhost);
12776: }
1.412 raeburn 12777: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12778: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
12779: }
12780: if ($saml{$lonhost}) {
1.412 raeburn 12781: if ($env{'form.saml_window_'.$lonhost} ne '1') {
12782: $env{'form.saml_window_'.$lonhost} = '';
12783: }
1.386 raeburn 12784: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
12785: #FIXME Need to obsolete published image
12786: delete($currsaml{$lonhost}{'img'});
12787: $changes{'saml'}{$lonhost} = 1;
12788: }
12789: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
12790: $changes{'saml'}{$lonhost} = 1;
12791: }
12792: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
12793: $changes{'saml'}{$lonhost} = 1;
12794: }
12795: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
12796: $changes{'saml'}{$lonhost} = 1;
12797: }
12798: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
12799: $changes{'saml'}{$lonhost} = 1;
12800: }
1.412 raeburn 12801: if ($env{'form.saml_window_'.$lonhost} ne $samlwindow{$lonhost}) {
12802: $changes{'saml'}{$lonhost} = 1;
12803: }
1.386 raeburn 12804: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
12805: $changes{'saml'}{$lonhost} = 1;
12806: }
12807: } else {
12808: $changes{'saml'}{$lonhost} = 1;
12809: }
1.412 raeburn 12810: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12811: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
12812: }
12813: } else {
1.425 raeburn 12814: if ($saml{$lonhost}) {
1.389 raeburn 12815: $changes{'saml'}{$lonhost} = 1;
12816: delete($currsaml{$lonhost});
12817: }
1.386 raeburn 12818: }
12819: }
12820: foreach my $posshost (keys(%currsaml)) {
1.425 raeburn 12821: unless (exists($domservers{$posshost})) {
12822: delete($currsaml{$posshost});
1.386 raeburn 12823: }
12824: }
12825: %{$loginhash{'login'}{'saml'}} = %currsaml;
12826: if (@newsamlimgs) {
12827: my $error;
12828: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12829: if ($configuserok eq 'ok') {
12830: if ($switchserver) {
12831: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
12832: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12833: my $modified = [];
1.386 raeburn 12834: foreach my $lonhost (@newsamlimgs) {
12835: my $formelem = 'saml_img_'.$lonhost;
1.425 raeburn 12836: my ($result,$imgurl) =
1.421 raeburn 12837: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12838: "login/saml/$lonhost",'','',
12839: $env{'form.saml_img_'.$lonhost.'.filename'},
12840: $modified);
1.386 raeburn 12841: if ($result eq 'ok') {
12842: $currsaml{$lonhost}{'img'} = $imgurl;
12843: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
12844: $changes{'saml'}{$lonhost} = 1;
12845: } else {
12846: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
12847: $lonhost,$result);
12848: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12849: }
12850: }
1.421 raeburn 12851: &update_modify_urls($r,$modified);
1.386 raeburn 12852: } else {
12853: $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);
12854: }
12855: } else {
12856: $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);
12857: }
12858: if ($error) {
12859: &Apache::lonnet::logthis($error);
12860: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12861: }
12862: }
1.169 raeburn 12863: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 12864:
12865: my $defaulthelpfile = '/adm/loginproblems.html';
12866: my $defaulttext = &mt('Default in use');
12867:
1.1 raeburn 12868: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
12869: $dom);
12870: if ($putresult eq 'ok') {
1.188 raeburn 12871: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12872: my %defaultchecked = (
12873: 'coursecatalog' => 'on',
1.188 raeburn 12874: 'helpdesk' => 'on',
1.42 raeburn 12875: 'adminmail' => 'off',
1.43 raeburn 12876: 'newuser' => 'off',
1.42 raeburn 12877: );
1.55 raeburn 12878: if (ref($domconfig{'login'}) eq 'HASH') {
12879: foreach my $item (@toggles) {
12880: if ($defaultchecked{$item} eq 'on') {
12881: if (($domconfig{'login'}{$item} eq '0') &&
12882: ($env{'form.'.$item} eq '1')) {
12883: $changes{$item} = 1;
12884: } elsif (($domconfig{'login'}{$item} eq '' ||
12885: $domconfig{'login'}{$item} eq '1') &&
12886: ($env{'form.'.$item} eq '0')) {
12887: $changes{$item} = 1;
12888: }
12889: } elsif ($defaultchecked{$item} eq 'off') {
12890: if (($domconfig{'login'}{$item} eq '1') &&
12891: ($env{'form.'.$item} eq '0')) {
12892: $changes{$item} = 1;
12893: } elsif (($domconfig{'login'}{$item} eq '' ||
12894: $domconfig{'login'}{$item} eq '0') &&
12895: ($env{'form.'.$item} eq '1')) {
12896: $changes{$item} = 1;
12897: }
1.42 raeburn 12898: }
12899: }
1.41 raeburn 12900: }
1.6 raeburn 12901: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 12902: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.386 raeburn 12903: if (exists($changes{'saml'})) {
12904: my $hostid_in_use;
12905: my @hosts = &Apache::lonnet::current_machine_ids();
12906: if (@hosts > 1) {
12907: foreach my $hostid (@hosts) {
12908: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
12909: $hostid_in_use = $hostid;
12910: last;
12911: }
12912: }
12913: } else {
12914: $hostid_in_use = $r->dir_config('lonHostID');
12915: }
12916: if (($hostid_in_use) &&
12917: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
1.387 raeburn 12918: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
1.386 raeburn 12919: }
12920: if (ref($lastactref) eq 'HASH') {
12921: if (ref($changes{'saml'}) eq 'HASH') {
12922: my %updates;
12923: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
12924: $lastactref->{'samllanding'} = \%updates;
12925: }
12926: }
12927: }
1.212 raeburn 12928: if (ref($lastactref) eq 'HASH') {
12929: $lastactref->{'domainconfig'} = 1;
12930: }
1.1 raeburn 12931: $resulttext = &mt('Changes made:').'<ul>';
12932: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 12933: if ($item eq 'loginvia') {
1.112 raeburn 12934: if (ref($changes{$item}) eq 'HASH') {
12935: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
12936: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 12937: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
12938: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
12939: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
12940: $protocol = 'http' if ($protocol ne 'https');
12941: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
12942:
12943: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
12944: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
12945: } else {
12946: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
12947: }
12948: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
12949: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
12950: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
12951: }
12952: $resulttext .= '</li>';
12953: } else {
12954: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
12955: }
1.112 raeburn 12956: } else {
1.128 raeburn 12957: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 12958: }
12959: }
1.128 raeburn 12960: $resulttext .= '</ul></li>';
1.112 raeburn 12961: }
1.168 raeburn 12962: } elsif ($item eq 'helpurl') {
12963: if (ref($changes{$item}) eq 'HASH') {
12964: foreach my $lang (sort(keys(%{$changes{$item}}))) {
12965: if (grep(/^\Q$lang\E$/,@delurls)) {
12966: my ($chg,$link);
12967: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
12968: if ($lang eq 'nolang') {
12969: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
12970: } else {
12971: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
12972: }
12973: $resulttext .= '<li>'.$chg.'</li>';
12974: } else {
12975: my $chg;
12976: if ($lang eq 'nolang') {
12977: $chg = &mt('custom log-in help file for no preferred language');
12978: } else {
12979: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
12980: }
12981: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
12982: $loginhash{'login'}{'helpurl'}{$lang}.
12983: '?inhibitmenu=yes',$chg,600,500).
12984: '</li>';
12985: }
12986: }
12987: }
1.256 raeburn 12988: } elsif ($item eq 'headtag') {
12989: if (ref($changes{$item}) eq 'HASH') {
12990: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12991: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12992: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
12993: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12994: $resulttext .= '<li><a href="'.
12995: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
12996: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
12997: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
12998: if ($possexempt{$lonhost}) {
12999: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
13000: } else {
13001: $resulttext .= &mt('included for any client IP');
13002: }
13003: $resulttext .= '</li>';
13004: }
13005: }
13006: }
1.386 raeburn 13007: } elsif ($item eq 'saml') {
13008: if (ref($changes{$item}) eq 'HASH') {
13009: my %notlt = (
13010: text => 'Text for log-in by SSO',
13011: img => 'SSO button image',
13012: alt => 'Alt text for button image',
13013: url => 'SSO URL',
13014: title => 'Tooltip for SSO link',
1.412 raeburn 13015: window => 'Pop-up window if iframe',
1.386 raeburn 13016: notsso => 'Text for non-SSO log-in',
13017: );
13018: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
13019: if (ref($currsaml{$lonhost}) eq 'HASH') {
13020: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
13021: '<ul>';
1.412 raeburn 13022: foreach my $key ('text','img','alt','url','title','window','notsso') {
1.386 raeburn 13023: if ($currsaml{$lonhost}{$key} eq '') {
13024: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
13025: } else {
13026: my $value = "'$currsaml{$lonhost}{$key}'";
13027: if ($key eq 'img') {
13028: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
1.412 raeburn 13029: } elsif ($key eq 'window') {
13030: $value = 'On';
1.386 raeburn 13031: }
13032: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
13033: $value).'</li>';
13034: }
13035: }
13036: $resulttext .= '</ul></li>';
13037: } else {
13038: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
13039: }
13040: }
13041: }
1.169 raeburn 13042: } elsif ($item eq 'captcha') {
13043: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 13044: my $chgtxt;
1.169 raeburn 13045: if ($loginhash{'login'}{$item} eq 'notused') {
13046: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
13047: } else {
13048: my %captchas = &captcha_phrases();
13049: if ($captchas{$loginhash{'login'}{$item}}) {
13050: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
13051: } else {
13052: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
13053: }
13054: }
13055: $resulttext .= '<li>'.$chgtxt.'</li>';
13056: }
13057: } elsif ($item eq 'recaptchakeys') {
13058: if (ref($loginhash{'login'}) eq 'HASH') {
13059: my ($privkey,$pubkey);
13060: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
13061: $pubkey = $loginhash{'login'}{$item}{'public'};
13062: $privkey = $loginhash{'login'}{$item}{'private'};
13063: }
13064: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
13065: if (!$pubkey) {
13066: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
13067: } else {
13068: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
13069: }
13070: if (!$privkey) {
13071: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
13072: } else {
1.251 raeburn 13073: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 13074: }
13075: $chgtxt .= '</ul>';
13076: $resulttext .= '<li>'.$chgtxt.'</li>';
13077: }
1.269 raeburn 13078: } elsif ($item eq 'recaptchaversion') {
13079: if (ref($loginhash{'login'}) eq 'HASH') {
13080: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 13081: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 13082: '</li>';
13083: }
13084: }
1.41 raeburn 13085: } else {
13086: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
13087: }
1.1 raeburn 13088: }
1.6 raeburn 13089: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 13090: } else {
13091: $resulttext = &mt('No changes made to log-in page settings');
13092: }
13093: } else {
1.11 albertel 13094: $resulttext = '<span class="LC_error">'.
13095: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 13096: }
1.6 raeburn 13097: if ($errors) {
1.9 raeburn 13098: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 13099: $errors.'</ul>';
13100: }
13101: return $resulttext;
13102: }
13103:
1.256 raeburn 13104: sub check_exempt_addresses {
13105: my ($iplist) = @_;
13106: $iplist =~ s/^\s+//;
13107: $iplist =~ s/\s+$//;
13108: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
13109: my (@okips,$new);
13110: foreach my $ip (@poss_ips) {
13111: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
13112: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
13113: push(@okips,$ip);
13114: }
13115: }
13116: }
13117: if (@okips > 0) {
13118: $new = join(',',@okips);
13119: } else {
13120: $new = '';
13121: }
13122: return $new;
13123: }
13124:
1.6 raeburn 13125: sub color_font_choices {
13126: my %choices =
13127: &Apache::lonlocal::texthash (
13128: bgs => "Background colors",
13129: links => "Link colors",
1.55 raeburn 13130: images => "Images",
1.6 raeburn 13131: font => "Font color",
1.201 raeburn 13132: fontmenu => "Font menu",
1.76 raeburn 13133: pgbg => "Page",
1.6 raeburn 13134: tabbg => "Header",
13135: sidebg => "Border",
13136: link => "Link",
13137: alink => "Active link",
13138: vlink => "Visited link",
13139: );
13140: return %choices;
13141: }
13142:
1.394 raeburn 13143: sub modify_ipaccess {
13144: my ($dom,$lastactref,%domconfig) = @_;
13145: my (@allpos,%changes,%confhash,$errors,$resulttext);
13146: my (@items,%deletions,%itemids,@warnings);
13147: my ($typeorder,$types) = &commblocktype_text();
13148: if ($env{'form.ipaccess_add'}) {
13149: my $name = $env{'form.ipaccess_name_add'};
13150: my ($newid,$error) = &get_ipaccess_id($dom,$name);
13151: if ($newid) {
13152: $itemids{'add'} = $newid;
13153: push(@items,'add');
13154: $changes{$newid} = 1;
13155: } else {
13156: $error = &mt('Failed to acquire unique ID for new IP access control item');
13157: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13158: }
13159: }
13160: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
13161: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
13162: if (@todelete) {
13163: map { $deletions{$_} = 1; } @todelete;
13164: }
13165: my $maxnum = $env{'form.ipaccess_maxnum'};
13166: for (my $i=0; $i<$maxnum; $i++) {
13167: my $itemid = $env{'form.ipaccess_id_'.$i};
13168: $itemid =~ s/\D+//g;
13169: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13170: if ($deletions{$itemid}) {
13171: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
13172: } else {
13173: push(@items,$i);
13174: $itemids{$i} = $itemid;
13175: }
13176: }
13177: }
13178: }
13179: foreach my $idx (@items) {
13180: my $itemid = $itemids{$idx};
13181: next unless ($itemid);
13182: my %current;
13183: unless ($idx eq 'add') {
13184: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13185: %current = %{$domconfig{'ipaccess'}{$itemid}};
13186: }
13187: }
13188: my $position = $env{'form.ipaccess_pos_'.$itemid};
13189: $position =~ s/\D+//g;
13190: if ($position ne '') {
13191: $allpos[$position] = $itemid;
13192: }
13193: my $name = $env{'form.ipaccess_name_'.$idx};
13194: $name =~ s/^\s+|\s+$//g;
13195: $confhash{$itemid}{'name'} = $name;
13196: my $possrange = $env{'form.ipaccess_range_'.$idx};
13197: $possrange =~ s/^\s+|\s+$//g;
13198: unless ($possrange eq '') {
13199: $possrange =~ s/[\r\n]+/\s/g;
13200: $possrange =~ s/\s*-\s*/-/g;
13201: $possrange =~ s/\s+/,/g;
13202: $possrange =~ s/,+/,/g;
13203: if ($possrange ne '') {
13204: my (@ok,$count);
1.425 raeburn 13205: $count = 0;
1.394 raeburn 13206: foreach my $poss (split(/\,/,$possrange)) {
13207: $count ++;
13208: $poss = &validate_ip_pattern($poss);
13209: if ($poss ne '') {
13210: push(@ok,$poss);
13211: }
13212: }
13213: my $diff = $count - scalar(@ok);
13214: if ($diff) {
13215: $errors .= '<li><span class="LC_error">'.
13216: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
13217: $diff,$name).
13218: '</span></li>';
13219: }
13220: if (@ok) {
13221: my @cidr_list;
13222: foreach my $item (@ok) {
13223: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
13224: }
13225: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
13226: }
13227: }
13228: }
13229: foreach my $field ('name','ip') {
13230: unless (($idx eq 'add') || ($changes{$itemid})) {
13231: if ($current{$field} ne $confhash{$itemid}{$field}) {
13232: $changes{$itemid} = 1;
13233: last;
13234: }
13235: }
13236: }
13237: $confhash{$itemid}{'commblocks'} = {};
1.425 raeburn 13238:
1.394 raeburn 13239: my %commblocks;
1.425 raeburn 13240: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
1.394 raeburn 13241: foreach my $type (@{$typeorder}) {
13242: if ($commblocks{$type}) {
13243: $confhash{$itemid}{'commblocks'}{$type} = 'on';
13244: }
13245: unless (($idx eq 'add') || ($changes{$itemid})) {
13246: if (ref($current{'commblocks'}) eq 'HASH') {
13247: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
13248: $changes{$itemid} = 1;
13249: }
13250: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
13251: $changes{$itemid} = 1;
13252: }
13253: }
13254: }
13255: $confhash{$itemid}{'courses'} = {};
13256: my %crsdeletions;
13257: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
13258: if (@delcrs) {
13259: map { $crsdeletions{$_} = 1; } @delcrs;
13260: }
13261: if (ref($current{'courses'}) eq 'HASH') {
13262: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
13263: if ($crsdeletions{$cid}) {
13264: $changes{$itemid} = 1;
13265: } else {
13266: $confhash{$itemid}{'courses'}{$cid} = 1;
13267: }
13268: }
13269: }
13270: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
13271: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
1.425 raeburn 13272: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
1.394 raeburn 13273: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
13274: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
13275: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
13276: $errors .= '<li><span class="LC_error">'.
13277: &mt('Invalid courseID [_1] omitted from list of allowed courses',
13278: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
13279: '</span></li>';
13280: } else {
13281: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
13282: $changes{$itemid} = 1;
13283: }
13284: }
13285: }
13286: if (@allpos > 0) {
13287: my $idx = 0;
13288: foreach my $itemid (@allpos) {
13289: if ($itemid ne '') {
13290: $confhash{$itemid}{'order'} = $idx;
13291: unless ($changes{$itemid}) {
13292: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
13293: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13294: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
13295: $changes{$itemid} = 1;
13296: }
13297: }
13298: }
13299: }
13300: $idx ++;
13301: }
13302: }
13303: }
13304: if (keys(%changes)) {
13305: my %defaultshash = (
13306: ipaccess => \%confhash,
13307: );
13308: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13309: $dom);
13310: if ($putresult eq 'ok') {
13311: my $cachetime = 1800;
13312: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
13313: if (ref($lastactref) eq 'HASH') {
13314: $lastactref->{'ipaccess'} = 1;
13315: }
13316: $resulttext = &mt('Changes made:').'<ul>';
13317: my %bynum;
13318: foreach my $itemid (sort(keys(%changes))) {
13319: if (ref($confhash{$itemid}) eq 'HASH') {
13320: my $position = $confhash{$itemid}{'order'};
13321: if ($position =~ /^\d+$/) {
13322: $bynum{$position} = $itemid;
13323: }
13324: }
13325: }
13326: if (keys(%deletions)) {
13327: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
13328: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
13329: }
13330: }
13331: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
13332: my $itemid = $bynum{$pos};
13333: if (ref($confhash{$itemid}) eq 'HASH') {
13334: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
13335: my $position = $pos + 1;
13336: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
13337: if ($confhash{$itemid}{'ip'} eq '') {
13338: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
13339: } else {
13340: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
13341: }
13342: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
13343: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
13344: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
13345: '</li>';
13346: } else {
13347: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
13348: }
13349: if (keys(%{$confhash{$itemid}{'courses'}})) {
13350: my @courses;
13351: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
1.425 raeburn 13352: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1.394 raeburn 13353: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
13354: }
13355: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
13356: join('</li><li>',@courses).'</li></ul>';
13357: } else {
13358: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
13359: }
1.395 raeburn 13360: $resulttext .= '</ul></li>';
1.394 raeburn 13361: }
13362: }
1.395 raeburn 13363: $resulttext .= '</ul>';
1.394 raeburn 13364: } else {
13365: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13366: }
13367: } else {
13368: $resulttext = &mt('No changes made');
13369: }
13370: if ($errors) {
13371: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
13372: $errors.'</ul></p>';
13373: }
13374: return $resulttext;
13375: }
13376:
13377: sub get_ipaccess_id {
13378: my ($domain,$location) = @_;
13379: # get lock on ipaccess db
13380: my $lockhash = {
13381: lock => $env{'user.name'}.
13382: ':'.$env{'user.domain'},
13383: };
13384: my $tries = 0;
13385: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13386: my ($id,$error);
13387:
13388: while (($gotlock ne 'ok') && ($tries<10)) {
13389: $tries ++;
13390: sleep (0.1);
13391: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13392: }
13393: if ($gotlock eq 'ok') {
13394: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
13395: if ($currids{'lock'}) {
13396: delete($currids{'lock'});
13397: if (keys(%currids)) {
13398: my @curr = sort { $a <=> $b } keys(%currids);
13399: if ($curr[-1] =~ /^\d+$/) {
13400: $id = 1 + $curr[-1];
13401: }
13402: } else {
13403: $id = 1;
13404: }
13405: if ($id) {
13406: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
13407: $error = 'nostore';
13408: }
13409: } else {
13410: $error = 'nonumber';
13411: }
13412: }
13413: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
13414: } else {
13415: $error = 'nolock';
13416: }
13417: return ($id,$error);
13418: }
13419:
1.429 raeburn 13420: sub modify_authordefaults {
13421: my ($dom,$lastactref,%domconfig) = @_;
13422: #
13423: # Retrieve current domain configuration for webDAV and Authoring Space quotas from $domconfig{'quotas'}.
13424: #
13425: my (%curr_quotas,%save_quotas,%confhash,%changes,%newvalues);
13426: if (ref($domconfig{'quotas'}) eq 'HASH') {
13427: foreach my $key (keys(%{$domconfig{'quotas'}})) {
13428: if ($key =~ /^webdav|authorquota$/) {
13429: $curr_quotas{$key} = $domconfig{'quotas'}{$key};
13430: } else {
13431: $save_quotas{$key} = $domconfig{'quotas'}{$key};
13432: }
13433: }
13434: }
13435: my %staticdefaults = (
13436: 'copyright' => 'default',
13437: 'sourceavail' => 'closed',
13438: 'nocodemirror' => 'off',
1.437 raeburn 13439: 'daxecollapse' => 'off',
1.429 raeburn 13440: 'domcoordacc' => 'on',
1.439 raeburn 13441: 'editors' => ['edit','xml'],
1.429 raeburn 13442: 'authorquota' => 500,
13443: 'webdav' => 0,
1.440 raeburn 13444: 'archive' => 'off',
1.429 raeburn 13445: );
13446: my %titles = &authordefaults_titles();
1.440 raeburn 13447: foreach my $item ('nocodemirror','daxecollapse','domcoordacc','archive') {
1.429 raeburn 13448: if ($env{'form.'.$item} =~ /^(0|1)$/) {
13449: $confhash{$item} = $env{'form.'.$item};
13450: }
13451: }
13452: if ($env{'form.copyright'} =~ /^(default|domain|public)$/) {
13453: $confhash{'copyright'} = $1;
13454: }
13455: if ($env{'form.sourceavail'} =~ /^(closed|open)$/) {
13456: $confhash{'sourceavail'} = $1;
13457: }
13458: my @posseditors = &Apache::loncommon::get_env_multiple('form.author_editors');
13459: my @okeditors = ('edit','xml','daxe');
13460: my @editors;
13461: foreach my $item (@posseditors) {
13462: if (grep(/^\Q$item\E$/,@okeditors)) {
13463: push(@editors,$item);
13464: }
13465: }
13466: $confhash{'editors'} = \@editors;
1.436 raeburn 13467:
1.429 raeburn 13468: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13469: my @insttypes;
13470: if (ref($types) eq 'ARRAY') {
13471: @insttypes = @{$types};
13472: }
13473: my @webdavon = &Apache::loncommon::get_env_multiple('form.webdav');
13474: my %webdav;
13475: map { $webdav{$_} = 1; } @webdavon;
13476: foreach my $type (@insttypes,'default') {
13477: my $possquota = $env{'form.authorquota_'.$type};
13478: if ($possquota =~ /^\d+$/) {
13479: $save_quotas{'authorquota'}{$type} = $possquota;
13480: }
13481: if ($webdav{$type}) {
13482: $save_quotas{'webdav'}{$type} = 1;
13483: } else {
13484: $save_quotas{'webdav'}{$type} = 0;
13485: }
13486: }
13487: if ($env{'form.webdav_LC_adv'} =~ /^(0|1)$/) {
13488: $save_quotas{'webdav'}{'_LC_adv'} = $env{'form.webdav_LC_adv'};
13489: }
13490: if (ref($domconfig{'authordefaults'}) eq 'HASH') {
1.440 raeburn 13491: foreach my $item ('nocodemirror','daxecollapse','domcoordacc','copyright','sourceavail','archive') {
1.429 raeburn 13492: if ($domconfig{'authordefaults'}{$item} ne $confhash{$item}) {
13493: $changes{$item} = 1;
13494: }
13495: }
13496: if (ref($domconfig{'authordefaults'}{'editors'}) eq 'ARRAY') {
1.436 raeburn 13497: my @diffs =
1.429 raeburn 13498: &Apache::loncommon::compare_arrays($confhash{'editors'},
13499: $domconfig{'authordefaults'}{'editors'});
13500: unless (@diffs == 0) {
13501: $changes{'editors'} = 1;
13502: }
13503: } else {
13504: my @diffs =
13505: &Apache::loncommon::compare_arrays($confhash{'editors'},
13506: $staticdefaults{'editors'});
13507: unless (@diffs == 0) {
13508: $changes{'editors'} = 1;
13509: }
13510: }
13511: } else {
13512: my @offon = ('off','on');
1.440 raeburn 13513: foreach my $item ('nocodemirror','daxecollapse','domcoordacc','archive') {
1.436 raeburn 13514: if ($offon[$confhash{$item}] ne $staticdefaults{$item}) {
1.429 raeburn 13515: $changes{$item} = 1;
13516: }
13517: }
13518: foreach my $item ('copyright','sourceavail') {
13519: if ($confhash{$item} ne $staticdefaults{$item}) {
13520: $changes{$item} = 1;
13521: }
13522: }
1.439 raeburn 13523: my @diffs =
13524: &Apache::loncommon::compare_arrays($confhash{'editors'},
13525: $staticdefaults{'editors'});
13526: unless (@diffs == 0) {
13527: $changes{'editors'} = 1;
13528: }
1.429 raeburn 13529: }
13530: foreach my $key ('authorquota','webdav') {
13531: if (ref($curr_quotas{$key}) eq 'HASH') {
13532: foreach my $type (@insttypes,'default') {
13533: if (exists($save_quotas{$key}{$type})) {
13534: if ($save_quotas{$key}{$type} ne $curr_quotas{$key}{$type}) {
13535: $changes{$key}{$type} = 1;
13536: }
13537: } elsif (exists($curr_quotas{$key}{$type})) {
13538: $save_quotas{$key}{$type} = $curr_quotas{$key}{$type};
13539: } else {
13540: $save_quotas{$key}{$type} = $staticdefaults{$key};
13541: }
13542: }
13543: } else {
13544: foreach my $type (@insttypes,'default') {
13545: if (exists($save_quotas{$key}{$type})) {
13546: unless ($save_quotas{$key}{$type} eq $staticdefaults{$key}) {
13547: $changes{$key}{$type} = 1;
13548: }
13549: } else {
13550: $save_quotas{$key}{$type} = $staticdefaults{$key};
13551: }
13552: }
13553: }
13554: }
13555: if (ref($curr_quotas{'webdav'}) eq 'HASH') {
13556: if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
1.436 raeburn 13557: if ($save_quotas{'webdav'}{'_LC_adv'} ne $curr_quotas{'webdav'}{'_LC_adv'}) {
1.429 raeburn 13558: $changes{'webdav_LC_adv'} = 1;
13559: }
13560: } elsif (exists($curr_quotas{'webdav'}{'_LC_adv'})) {
13561: $changes{'webdav_LC_adv'} = 1;
13562: }
13563: } elsif (exists($save_quotas{'webdav'}{'_LC_adv'})) {
13564: $changes{'webdav_LC_adv'} = 1;
13565: }
13566: my %confighash = (
13567: quotas => \%save_quotas,
13568: authordefaults => \%confhash,
13569: );
13570: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,
13571: $dom);
13572: my $resulttext;
13573: if ($putresult eq 'ok') {
13574: if (keys(%changes)) {
1.431 raeburn 13575: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.429 raeburn 13576: if ((exists($changes{'authorquota'})) || (exists($changes{'webdav'})) ||
1.436 raeburn 13577: ($changes{'webdav_LC_adv'})) {
1.429 raeburn 13578: if ((exists($changes{'authorquota'})) && (ref($save_quotas{'authorquota'}) eq 'HASH')) {
13579: $domdefaults{'authorquota'} = $save_quotas{'authorquota'};
13580: }
13581: if (((exists($changes{'webdav'})) || ($changes{'webdav_LC_adv'})) &&
13582: (ref($save_quotas{'webdav'}) eq 'HASH')) {
13583: $domdefaults{'webdav'} = $save_quotas{'webdav'};
13584: }
13585: }
13586: $resulttext = &mt('Changes made:').'<ul>';
13587: my $authoroverride;
1.437 raeburn 13588: foreach my $key ('nocodemirror','daxecollapse','domcoordacc','copyright','sourceavail') {
1.429 raeburn 13589: if (exists($changes{$key})) {
1.431 raeburn 13590: $domdefaults{$key} = $confhash{$key};
1.429 raeburn 13591: my $shown;
13592: unless ($authoroverride) {
13593: $resulttext .= '<li>'.&mt('Defaults which can be overridden by Author').'<ul>';
13594: $authoroverride = 1;
13595: }
1.437 raeburn 13596: if (($key eq 'nocodemirror') || ($key eq 'daxecollapse') || ($key eq 'domcoordacc')) {
1.429 raeburn 13597: $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
13598: } elsif ($key eq 'copyright') {
13599: $shown = &Apache::loncommon::copyrightdescription($confhash{$key});
13600: } elsif ($key eq 'sourceavail') {
13601: $shown = &Apache::loncommon::source_copyrightdescription($confhash{$key});
13602: }
1.436 raeburn 13603: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
1.429 raeburn 13604: }
13605: }
13606: if ($authoroverride) {
13607: $resulttext .= '</ul></li>';
13608: }
13609: my $domcoordoverride;
1.440 raeburn 13610: foreach my $key ('editors','authorquota','webdav','webdav_LC_adv','archive') {
1.429 raeburn 13611: if (exists($changes{$key})) {
13612: my $shown;
13613: unless ($domcoordoverride) {
13614: $resulttext .= '<li>'.&mt('Defaults which can be overridden by a Domain Coodinator').'<ul>';
13615: $domcoordoverride = 1;
13616: }
13617: if ($key eq 'editors') {
1.431 raeburn 13618: if (ref($confhash{'editors'}) eq 'ARRAY') {
13619: $domdefaults{'editors'} = join(',',@{$confhash{'editors'}});
13620: if (@{$confhash{'editors'}}) {
13621: $shown = join(', ', map { $titles{$_} } @{$confhash{'editors'}});
13622: } else {
13623: $shown = &mt('None');
13624: }
1.429 raeburn 13625: }
13626: } elsif ($key eq 'authorquota') {
13627: foreach my $type (@insttypes) {
13628: $shown .= $usertypes->{$type}.' -- '.$save_quotas{$key}{$type}.', ';
13629: }
13630: $shown .= $othertitle.' -- '.$save_quotas{$key}{'default'};
13631: } elsif ($key eq 'webdav') {
13632: foreach my $type (@insttypes) {
13633: $shown .= $usertypes->{$type}.' -- '. ($save_quotas{$key}{$type} ? &mt('Yes') : &mt('No')).', ';
13634: }
13635: $shown .= $othertitle.' -- '. ($save_quotas{$key}{'default'} ? &mt('Yes') : &mt('No'));
13636: } elsif ($key eq 'webdav_LC_adv') {
13637: if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
13638: $shown = ($save_quotas{'webdav'}{'_LC_adv'} ? $titles{'overon'} : $titles{'overoff'});
13639: } else {
13640: $shown = $titles{'none'};
13641: }
1.440 raeburn 13642: } elsif ($key eq 'archive') {
1.441 raeburn 13643: $domdefaults{$key} = $confhash{$key};
1.440 raeburn 13644: $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
1.429 raeburn 13645: }
13646: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
1.436 raeburn 13647: }
1.429 raeburn 13648: }
13649: if ($domcoordoverride) {
13650: $resulttext .= '</ul></li>';
13651: }
1.439 raeburn 13652: $resulttext .= '</ul>';
1.431 raeburn 13653: my $cachetime = 24*60*60;
13654: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13655: if (ref($lastactref) eq 'HASH') {
13656: $lastactref->{'domdefaults'} = 1;
13657: }
1.429 raeburn 13658: } else {
13659: $resulttext = &mt('No changes made to Authoring Space defaults');
13660: }
13661: }
13662: return $resulttext;
13663: }
13664:
1.6 raeburn 13665: sub modify_rolecolors {
1.205 raeburn 13666: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 13667: my ($resulttext,%rolehash);
13668: $rolehash{'rolecolors'} = {};
1.55 raeburn 13669: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
13670: if ($domconfig{'rolecolors'} eq '') {
13671: $domconfig{'rolecolors'} = {};
13672: }
13673: }
1.9 raeburn 13674: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 13675: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
13676: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
13677: $dom);
13678: if ($putresult eq 'ok') {
13679: if (keys(%changes) > 0) {
1.41 raeburn 13680: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 13681: if (ref($lastactref) eq 'HASH') {
13682: $lastactref->{'domainconfig'} = 1;
13683: }
1.6 raeburn 13684: $resulttext = &display_colorchgs($dom,\%changes,$roles,
13685: $rolehash{'rolecolors'});
13686: } else {
13687: $resulttext = &mt('No changes made to default color schemes');
13688: }
13689: } else {
1.11 albertel 13690: $resulttext = '<span class="LC_error">'.
13691: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 13692: }
13693: if ($errors) {
13694: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
13695: $errors.'</ul>';
13696: }
13697: return $resulttext;
13698: }
13699:
13700: sub modify_colors {
1.9 raeburn 13701: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 13702: my (%changes,%choices);
1.51 raeburn 13703: my @bgs;
1.6 raeburn 13704: my @links = ('link','alink','vlink');
1.41 raeburn 13705: my @logintext;
1.6 raeburn 13706: my @images;
13707: my $servadm = $r->dir_config('lonAdmEMail');
13708: my $errors;
1.200 raeburn 13709: my %defaults;
1.6 raeburn 13710: foreach my $role (@{$roles}) {
13711: if ($role eq 'login') {
1.12 raeburn 13712: %choices = &login_choices();
1.41 raeburn 13713: @logintext = ('textcol','bgcol');
1.12 raeburn 13714: } else {
13715: %choices = &color_font_choices();
13716: }
13717: if ($role eq 'login') {
1.41 raeburn 13718: @images = ('img','logo','domlogo','login');
1.51 raeburn 13719: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 13720: } else {
1.445 ! raeburn 13721: @images = ();
1.200 raeburn 13722: @bgs = ('pgbg','tabbg','sidebg');
13723: }
13724: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
1.444 raeburn 13725: $env{'form.'.$role.'_font'} = lc($env{'form.'.$role.'_font'});
13726: if ($env{'form.'.$role.'_font'} =~ /^\w+/) {
13727: $env{'form.'.$role.'_font'} = '#'.$env{'form.'.$role.'_font'};
13728: }
13729: unless ($env{'form.'.$role.'_font'} eq lc($defaults{'font'})) {
1.200 raeburn 13730: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
13731: }
13732: if ($role eq 'login') {
13733: foreach my $item (@logintext) {
1.234 raeburn 13734: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13735: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13736: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13737: }
13738: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 13739: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13740: }
13741: }
13742: } else {
1.234 raeburn 13743: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
13744: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
13745: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
13746: }
1.445 ! raeburn 13747: unless ($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 13748: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
13749: }
1.6 raeburn 13750: }
1.200 raeburn 13751: foreach my $item (@bgs) {
1.234 raeburn 13752: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13753: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13754: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13755: }
13756: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 13757: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13758: }
13759: }
13760: foreach my $item (@links) {
1.234 raeburn 13761: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13762: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13763: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13764: }
13765: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 13766: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13767: }
1.6 raeburn 13768: }
1.46 raeburn 13769: my ($configuserok,$author_ok,$switchserver) =
13770: &config_check($dom,$confname,$servadm);
1.9 raeburn 13771: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 13772: if (ref($domconfig->{$role}) ne 'HASH') {
13773: $domconfig->{$role} = {};
13774: }
1.8 raeburn 13775: foreach my $img (@images) {
1.402 raeburn 13776: if ($role eq 'login') {
13777: if (($img eq 'img') || ($img eq 'logo')) {
13778: if (defined($env{'form.login_showlogo_'.$img})) {
13779: $confhash->{$role}{'showlogo'}{$img} = 1;
13780: } else {
13781: $confhash->{$role}{'showlogo'}{$img} = 0;
13782: }
13783: }
13784: if ($env{'form.login_alt_'.$img} ne '') {
13785: $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
1.70 raeburn 13786: }
1.402 raeburn 13787: }
1.18 albertel 13788: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
13789: && !defined($domconfig->{$role}{$img})
13790: && !$env{'form.'.$role.'_del_'.$img}
13791: && $env{'form.'.$role.'_import_'.$img}) {
13792: # import the old configured image from the .tab setting
13793: # if they haven't provided a new one
13794: $domconfig->{$role}{$img} =
13795: $env{'form.'.$role.'_import_'.$img};
13796: }
1.6 raeburn 13797: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 13798: my $error;
1.6 raeburn 13799: if ($configuserok eq 'ok') {
1.9 raeburn 13800: if ($switchserver) {
1.12 raeburn 13801: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 13802: } else {
13803: if ($author_ok eq 'ok') {
1.421 raeburn 13804: my $modified = [];
1.9 raeburn 13805: my ($result,$logourl) =
1.421 raeburn 13806: &Apache::lonconfigsettings::publishlogo($r,'upload',$role.'_'.$img,
13807: $dom,$confname,$img,$width,$height,
13808: '',$modified);
1.9 raeburn 13809: if ($result eq 'ok') {
13810: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 13811: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13812: &update_modify_urls($r,$modified);
1.9 raeburn 13813: } else {
1.12 raeburn 13814: $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 13815: }
13816: } else {
1.46 raeburn 13817: $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 13818: }
13819: }
13820: } else {
1.46 raeburn 13821: $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 13822: }
13823: if ($error) {
1.8 raeburn 13824: &Apache::lonnet::logthis($error);
1.11 albertel 13825: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 13826: }
13827: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 13828: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
13829: my $error;
13830: if ($configuserok eq 'ok') {
13831: # is confname an author?
13832: if ($switchserver eq '') {
13833: if ($author_ok eq 'ok') {
1.421 raeburn 13834: my $modified = [];
1.9 raeburn 13835: my ($result,$logourl) =
1.421 raeburn 13836: &Apache::lonconfigsettings::publishlogo($r,'copy',$domconfig->{$role}{$img},
13837: $dom,$confname,$img,$width,$height,
13838: '',$modified);
1.9 raeburn 13839: if ($result eq 'ok') {
13840: $confhash->{$role}{$img} = $logourl;
1.18 albertel 13841: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13842: &update_modify_urls($r,$modified);
1.9 raeburn 13843: }
13844: }
13845: }
13846: }
1.6 raeburn 13847: }
13848: }
13849: }
13850: if (ref($domconfig) eq 'HASH') {
13851: if (ref($domconfig->{$role}) eq 'HASH') {
13852: foreach my $img (@images) {
13853: if ($domconfig->{$role}{$img} ne '') {
13854: if ($env{'form.'.$role.'_del_'.$img}) {
13855: $confhash->{$role}{$img} = '';
1.12 raeburn 13856: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13857: } else {
1.9 raeburn 13858: if ($confhash->{$role}{$img} eq '') {
13859: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
13860: }
1.6 raeburn 13861: }
13862: } else {
13863: if ($env{'form.'.$role.'_del_'.$img}) {
13864: $confhash->{$role}{$img} = '';
1.12 raeburn 13865: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13866: }
13867: }
1.402 raeburn 13868: if ($role eq 'login') {
13869: if (($img eq 'logo') || ($img eq 'img')) {
13870: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
13871: if ($confhash->{$role}{'showlogo'}{$img} ne
13872: $domconfig->{$role}{'showlogo'}{$img}) {
13873: $changes{$role}{'showlogo'}{$img} = 1;
13874: }
13875: } else {
13876: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13877: $changes{$role}{'showlogo'}{$img} = 1;
13878: }
1.70 raeburn 13879: }
1.402 raeburn 13880: }
13881: if ($img ne 'login') {
13882: if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
13883: if ($confhash->{$role}{'alttext'}{$img} ne
13884: $domconfig->{$role}{'alttext'}{$img}) {
13885: $changes{$role}{'alttext'}{$img} = 1;
13886: }
13887: } else {
13888: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13889: $changes{$role}{'alttext'}{$img} = 1;
13890: }
1.70 raeburn 13891: }
13892: }
13893: }
13894: }
1.6 raeburn 13895: if ($domconfig->{$role}{'font'} ne '') {
13896: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
13897: $changes{$role}{'font'} = 1;
13898: }
13899: } else {
13900: if ($confhash->{$role}{'font'}) {
13901: $changes{$role}{'font'} = 1;
13902: }
13903: }
1.107 raeburn 13904: if ($role ne 'login') {
13905: if ($domconfig->{$role}{'fontmenu'} ne '') {
13906: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
13907: $changes{$role}{'fontmenu'} = 1;
13908: }
13909: } else {
13910: if ($confhash->{$role}{'fontmenu'}) {
13911: $changes{$role}{'fontmenu'} = 1;
13912: }
1.97 tempelho 13913: }
13914: }
1.6 raeburn 13915: foreach my $item (@bgs) {
13916: if ($domconfig->{$role}{$item} ne '') {
13917: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13918: $changes{$role}{'bgs'}{$item} = 1;
13919: }
13920: } else {
13921: if ($confhash->{$role}{$item}) {
13922: $changes{$role}{'bgs'}{$item} = 1;
13923: }
13924: }
13925: }
13926: foreach my $item (@links) {
13927: if ($domconfig->{$role}{$item} ne '') {
13928: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13929: $changes{$role}{'links'}{$item} = 1;
13930: }
13931: } else {
13932: if ($confhash->{$role}{$item}) {
13933: $changes{$role}{'links'}{$item} = 1;
13934: }
13935: }
13936: }
1.41 raeburn 13937: foreach my $item (@logintext) {
13938: if ($domconfig->{$role}{$item} ne '') {
13939: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13940: $changes{$role}{'logintext'}{$item} = 1;
13941: }
13942: } else {
13943: if ($confhash->{$role}{$item}) {
13944: $changes{$role}{'logintext'}{$item} = 1;
13945: }
13946: }
13947: }
1.6 raeburn 13948: } else {
13949: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13950: \@logintext,$confhash,\%changes);
1.6 raeburn 13951: }
13952: } else {
13953: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13954: \@logintext,$confhash,\%changes);
1.6 raeburn 13955: }
13956: }
13957: return ($errors,%changes);
13958: }
13959:
1.46 raeburn 13960: sub config_check {
13961: my ($dom,$confname,$servadm) = @_;
13962: my ($configuserok,$author_ok,$switchserver,%currroles);
13963: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
13964: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
13965: $confname,$servadm);
13966: if ($configuserok eq 'ok') {
13967: $switchserver = &check_switchserver($dom,$confname);
13968: if ($switchserver eq '') {
13969: $author_ok = &check_authorstatus($dom,$confname,%currroles);
13970: }
13971: }
13972: return ($configuserok,$author_ok,$switchserver);
13973: }
13974:
1.6 raeburn 13975: sub default_change_checker {
1.41 raeburn 13976: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 13977: foreach my $item (@{$links}) {
13978: if ($confhash->{$role}{$item}) {
13979: $changes->{$role}{'links'}{$item} = 1;
13980: }
13981: }
13982: foreach my $item (@{$bgs}) {
13983: if ($confhash->{$role}{$item}) {
13984: $changes->{$role}{'bgs'}{$item} = 1;
13985: }
13986: }
1.41 raeburn 13987: foreach my $item (@{$logintext}) {
13988: if ($confhash->{$role}{$item}) {
13989: $changes->{$role}{'logintext'}{$item} = 1;
13990: }
13991: }
1.6 raeburn 13992: foreach my $img (@{$images}) {
13993: if ($env{'form.'.$role.'_del_'.$img}) {
13994: $confhash->{$role}{$img} = '';
1.12 raeburn 13995: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 13996: }
1.70 raeburn 13997: if ($role eq 'login') {
13998: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13999: $changes->{$role}{'showlogo'}{$img} = 1;
14000: }
1.402 raeburn 14001: if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
14002: if ($confhash->{$role}{'alttext'}{$img} ne '') {
14003: $changes->{$role}{'alttext'}{$img} = 1;
14004: }
14005: }
1.70 raeburn 14006: }
1.6 raeburn 14007: }
14008: if ($confhash->{$role}{'font'}) {
14009: $changes->{$role}{'font'} = 1;
14010: }
1.48 raeburn 14011: }
1.6 raeburn 14012:
14013: sub display_colorchgs {
14014: my ($dom,$changes,$roles,$confhash) = @_;
14015: my (%choices,$resulttext);
14016: if (!grep(/^login$/,@{$roles})) {
14017: $resulttext = &mt('Changes made:').'<br />';
14018: }
14019: foreach my $role (@{$roles}) {
14020: if ($role eq 'login') {
14021: %choices = &login_choices();
14022: } else {
14023: %choices = &color_font_choices();
14024: }
14025: if (ref($changes->{$role}) eq 'HASH') {
14026: if ($role ne 'login') {
14027: $resulttext .= '<h4>'.&mt($role).'</h4>';
14028: }
14029: foreach my $key (sort(keys(%{$changes->{$role}}))) {
14030: if ($role ne 'login') {
14031: $resulttext .= '<ul>';
14032: }
14033: if (ref($changes->{$role}{$key}) eq 'HASH') {
14034: if ($role ne 'login') {
14035: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
14036: }
14037: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 14038: if (($role eq 'login') && ($key eq 'showlogo')) {
14039: if ($confhash->{$role}{$key}{$item}) {
14040: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
14041: } else {
14042: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
14043: }
1.402 raeburn 14044: } elsif (($role eq 'login') && ($key eq 'alttext')) {
14045: if ($confhash->{$role}{$key}{$item} ne '') {
1.403 raeburn 14046: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
1.402 raeburn 14047: $confhash->{$role}{$key}{$item}).'</li>';
14048: } else {
14049: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
14050: }
1.70 raeburn 14051: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 14052: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
14053: } else {
1.12 raeburn 14054: my $newitem = $confhash->{$role}{$item};
14055: if ($key eq 'images') {
1.306 raeburn 14056: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 14057: }
14058: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 14059: }
14060: }
14061: if ($role ne 'login') {
14062: $resulttext .= '</ul></li>';
14063: }
14064: } else {
14065: if ($confhash->{$role}{$key} eq '') {
14066: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
14067: } else {
14068: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
14069: }
14070: }
14071: if ($role ne 'login') {
14072: $resulttext .= '</ul>';
14073: }
14074: }
14075: }
14076: }
1.3 raeburn 14077: return $resulttext;
1.1 raeburn 14078: }
14079:
1.9 raeburn 14080: sub thumb_dimensions {
14081: return ('200','50');
14082: }
14083:
1.16 raeburn 14084: sub check_dimensions {
14085: my ($inputfile) = @_;
14086: my ($fullwidth,$fullheight);
14087: if ($inputfile =~ m|^[/\w.\-]+$|) {
14088: if (open(PIPE,"identify $inputfile 2>&1 |")) {
14089: my $imageinfo = <PIPE>;
14090: if (!close(PIPE)) {
14091: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
14092: }
14093: chomp($imageinfo);
14094: my ($fullsize) =
1.21 raeburn 14095: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 14096: if ($fullsize) {
14097: ($fullwidth,$fullheight) = split(/x/,$fullsize);
14098: }
14099: }
14100: }
14101: return ($fullwidth,$fullheight);
14102: }
14103:
1.9 raeburn 14104: sub check_configuser {
14105: my ($uhome,$dom,$confname,$servadm) = @_;
14106: my ($configuserok,%currroles);
14107: if ($uhome eq 'no_host') {
14108: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.361 raeburn 14109: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 14110: $configuserok =
14111: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
14112: $configpass,'','','','','',undef,$servadm);
14113: } else {
14114: $configuserok = 'ok';
14115: %currroles =
14116: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
14117: }
14118: return ($configuserok,%currroles);
14119: }
14120:
14121: sub check_authorstatus {
14122: my ($dom,$confname,%currroles) = @_;
14123: my $author_ok;
1.40 raeburn 14124: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 14125: my $start = time;
14126: my $end = 0;
14127: $author_ok =
14128: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 14129: 'au',$end,$start,'','','domconfig');
1.9 raeburn 14130: } else {
14131: $author_ok = 'ok';
14132: }
14133: return $author_ok;
14134: }
14135:
1.421 raeburn 14136: sub update_modify_urls {
14137: my ($r,$modified) = @_;
14138: if ((ref($modified) eq 'ARRAY') && (@{$modified})) {
14139: push(@{$modified_urls},$modified);
14140: unless ($registered_cleanup) {
14141: my $handlers = $r->get_handlers('PerlCleanupHandler');
14142: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
14143: $registered_cleanup=1;
1.9 raeburn 14144: }
14145: }
1.155 raeburn 14146: }
14147:
14148: sub notifysubscribed {
14149: foreach my $targetsource (@{$modified_urls}){
14150: next unless (ref($targetsource) eq 'ARRAY');
14151: my ($target,$source)=@{$targetsource};
14152: if ($source ne '') {
1.316 raeburn 14153: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 14154: print $logfh "\nCleanup phase: Notifications\n";
14155: my @subscribed=&subscribed_hosts($target);
14156: foreach my $subhost (@subscribed) {
14157: print $logfh "\nNotifying host ".$subhost.':';
14158: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
14159: print $logfh $reply;
14160: }
14161: my @subscribedmeta=&subscribed_hosts("$target.meta");
14162: foreach my $subhost (@subscribedmeta) {
14163: print $logfh "\nNotifying host for metadata only ".$subhost.':';
14164: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
14165: $subhost);
14166: print $logfh $reply;
14167: }
14168: print $logfh "\n============ Done ============\n";
1.160 raeburn 14169: close($logfh);
1.155 raeburn 14170: }
14171: }
14172: }
14173: return OK;
14174: }
14175:
14176: sub subscribed_hosts {
14177: my ($target) = @_;
14178: my @subscribed;
1.316 raeburn 14179: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 14180: while (my $subline=<$fh>) {
14181: if ($subline =~ /^($match_lonid):/) {
14182: my $host = $1;
14183: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
14184: unless (grep(/^\Q$host\E$/,@subscribed)) {
14185: push(@subscribed,$host);
14186: }
14187: }
14188: }
14189: }
14190: }
14191: return @subscribed;
1.9 raeburn 14192: }
14193:
14194: sub check_switchserver {
14195: my ($dom,$confname) = @_;
1.424 raeburn 14196: my ($allowed,$switchserver,$home);
14197: if ($confname eq '') {
1.9 raeburn 14198: $home = &Apache::lonnet::domain($dom,'primary');
1.424 raeburn 14199: } else {
14200: $home = &Apache::lonnet::homeserver($confname,$dom);
14201: if ($home eq 'no_host') {
14202: $home = &Apache::lonnet::domain($dom,'primary');
14203: }
1.9 raeburn 14204: }
14205: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 14206: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
14207: if (!$allowed) {
1.426 raeburn 14208: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
14209: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
14210: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 14211: }
14212: return $switchserver;
14213: }
14214:
1.1 raeburn 14215: sub modify_quotas {
1.216 raeburn 14216: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 14217: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 14218: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 14219: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
14220: $validationfieldsref);
1.86 raeburn 14221: if ($action eq 'quotas') {
1.429 raeburn 14222: $context = 'tools';
1.163 raeburn 14223: } else {
1.86 raeburn 14224: $context = $action;
14225: }
14226: if ($context eq 'requestcourses') {
1.325 raeburn 14227: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 14228: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 14229: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
14230: %titles = &courserequest_titles();
14231: $toolregexp = join('|',@usertools);
14232: %conditions = &courserequest_conditions();
1.216 raeburn 14233: $confname = $dom.'-domainconfig';
14234: my $servadm = $r->dir_config('lonAdmEMail');
14235: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 14236: ($validationitemsref,$validationnamesref,$validationfieldsref) =
14237: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 14238: } elsif ($context eq 'requestauthor') {
14239: @usertools = ('author');
14240: %titles = &authorrequest_titles();
1.86 raeburn 14241: } else {
1.430 raeburn 14242: @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.101 raeburn 14243: %titles = &tool_titles();
1.86 raeburn 14244: }
1.212 raeburn 14245: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 14246: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 14247: foreach my $key (keys(%env)) {
1.101 raeburn 14248: if ($context eq 'requestcourses') {
14249: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
14250: my $item = $1;
14251: my $type = $2;
14252: if ($type =~ /^limit_(.+)/) {
14253: $limithash{$item}{$1} = $env{$key};
14254: } else {
14255: $confhash{$item}{$type} = $env{$key};
14256: }
14257: }
1.163 raeburn 14258: } elsif ($context eq 'requestauthor') {
14259: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
14260: $confhash{$1} = $env{$key};
14261: }
1.101 raeburn 14262: } else {
1.86 raeburn 14263: if ($key =~ /^form\.quota_(.+)$/) {
14264: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 14265: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 14266: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
14267: }
1.72 raeburn 14268: }
14269: }
1.163 raeburn 14270: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 14271: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 14272: @approvalnotify = sort(@approvalnotify);
14273: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 14274: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 14275: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
14276: foreach my $type (@hasuniquecode) {
14277: if (grep(/^\Q$type\E$/,@crstypes)) {
14278: $confhash{'uniquecode'}{$type} = 1;
14279: }
1.216 raeburn 14280: }
1.242 raeburn 14281: my (%newbook,%allpos);
1.216 raeburn 14282: if ($context eq 'requestcourses') {
1.242 raeburn 14283: foreach my $type ('textbooks','templates') {
14284: @{$allpos{$type}} = ();
14285: my $invalid;
14286: if ($type eq 'textbooks') {
14287: $invalid = &mt('Invalid LON-CAPA course for textbook');
14288: } else {
14289: $invalid = &mt('Invalid LON-CAPA course for template');
14290: }
14291: if ($env{'form.'.$type.'_addbook'}) {
14292: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
14293: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
14294: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
14295: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
14296: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
14297: } else {
14298: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
14299: my $position = $env{'form.'.$type.'_addbook_pos'};
14300: $position =~ s/\D+//g;
14301: if ($position ne '') {
14302: $allpos{$type}[$position] = $newbook{$type};
14303: }
1.216 raeburn 14304: }
1.242 raeburn 14305: } else {
14306: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 14307: }
14308: }
1.242 raeburn 14309: }
1.216 raeburn 14310: }
1.102 raeburn 14311: if (ref($domconfig{$action}) eq 'HASH') {
14312: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
14313: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
14314: $changes{'notify'}{'approval'} = 1;
14315: }
14316: } else {
1.144 raeburn 14317: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14318: $changes{'notify'}{'approval'} = 1;
14319: }
14320: }
1.218 raeburn 14321: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
14322: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14323: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
14324: unless ($confhash{'uniquecode'}{$crstype}) {
14325: $changes{'uniquecode'} = 1;
14326: }
14327: }
14328: unless ($changes{'uniquecode'}) {
14329: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
14330: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
14331: $changes{'uniquecode'} = 1;
14332: }
14333: }
14334: }
14335: } else {
14336: $changes{'uniquecode'} = 1;
14337: }
14338: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
14339: $changes{'uniquecode'} = 1;
1.216 raeburn 14340: }
14341: if ($context eq 'requestcourses') {
1.242 raeburn 14342: foreach my $type ('textbooks','templates') {
14343: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14344: my %deletions;
14345: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
14346: if (@todelete) {
14347: map { $deletions{$_} = 1; } @todelete;
14348: }
14349: my %imgdeletions;
14350: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
14351: if (@todeleteimages) {
14352: map { $imgdeletions{$_} = 1; } @todeleteimages;
14353: }
14354: my $maxnum = $env{'form.'.$type.'_maxnum'};
14355: for (my $i=0; $i<=$maxnum; $i++) {
14356: my $itemid = $env{'form.'.$type.'_id_'.$i};
14357: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
14358: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
14359: if ($deletions{$key}) {
14360: if ($domconfig{$action}{$type}{$key}{'image'}) {
14361: #FIXME need to obsolete item in RES space
14362: }
14363: next;
14364: } else {
14365: my $newpos = $env{'form.'.$itemid};
14366: $newpos =~ s/\D+//g;
1.243 raeburn 14367: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 14368: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 14369: ($type eq 'templates'));
1.242 raeburn 14370: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
14371: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
14372: $changes{$type}{$key} = 1;
14373: }
14374: }
14375: $allpos{$type}[$newpos] = $key;
14376: }
14377: if ($imgdeletions{$key}) {
14378: $changes{$type}{$key} = 1;
1.216 raeburn 14379: #FIXME need to obsolete item in RES space
1.242 raeburn 14380: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
14381: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 14382: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14383: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14384: } else {
14385: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
14386: $cdom,$cnum,$type,$configuserok,
14387: $switchserver,$author_ok);
14388: if ($imgurl) {
14389: $confhash{$type}{$key}{'image'} = $imgurl;
14390: $changes{$type}{$key} = 1;
14391: }
14392: if ($error) {
14393: &Apache::lonnet::logthis($error);
14394: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14395: }
14396: }
1.242 raeburn 14397: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
14398: $confhash{$type}{$key}{'image'} =
14399: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 14400: }
14401: }
14402: }
14403: }
14404: }
14405: }
1.102 raeburn 14406: } else {
1.144 raeburn 14407: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14408: $changes{'notify'}{'approval'} = 1;
14409: }
1.218 raeburn 14410: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 14411: $changes{'uniquecode'} = 1;
14412: }
14413: }
14414: if ($context eq 'requestcourses') {
1.242 raeburn 14415: foreach my $type ('textbooks','templates') {
14416: if ($newbook{$type}) {
14417: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 14418: foreach my $item ('subject','title','publisher','author') {
14419: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14420: ($type eq 'template'));
1.242 raeburn 14421: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
14422: if ($env{'form.'.$type.'_addbook_'.$item}) {
14423: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
14424: }
14425: }
14426: if ($type eq 'textbooks') {
14427: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
14428: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 14429: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14430: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14431: } else {
14432: my ($imageurl,$error) =
14433: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
14434: $configuserok,$switchserver,$author_ok);
14435: if ($imageurl) {
14436: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
14437: }
14438: if ($error) {
14439: &Apache::lonnet::logthis($error);
14440: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14441: }
1.242 raeburn 14442: }
14443: }
1.216 raeburn 14444: }
14445: }
1.242 raeburn 14446: if (@{$allpos{$type}} > 0) {
14447: my $idx = 0;
14448: foreach my $item (@{$allpos{$type}}) {
14449: if ($item ne '') {
14450: $confhash{$type}{$item}{'order'} = $idx;
14451: if (ref($domconfig{$action}) eq 'HASH') {
14452: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14453: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
14454: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
14455: $changes{$type}{$item} = 1;
14456: }
1.216 raeburn 14457: }
14458: }
14459: }
1.242 raeburn 14460: $idx ++;
1.216 raeburn 14461: }
14462: }
14463: }
14464: }
1.235 raeburn 14465: if (ref($validationitemsref) eq 'ARRAY') {
14466: foreach my $item (@{$validationitemsref}) {
14467: if ($item eq 'fields') {
14468: my @changed;
14469: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
14470: if (@{$confhash{'validation'}{$item}} > 0) {
14471: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
14472: }
1.266 raeburn 14473: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14474: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14475: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
14476: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
14477: $domconfig{'requestcourses'}{'validation'}{$item});
14478: } else {
14479: @changed = @{$confhash{'validation'}{$item}};
14480: }
1.235 raeburn 14481: } else {
14482: @changed = @{$confhash{'validation'}{$item}};
14483: }
14484: } else {
14485: @changed = @{$confhash{'validation'}{$item}};
14486: }
14487: if (@changed) {
14488: if ($confhash{'validation'}{$item}) {
14489: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
14490: } else {
14491: $changes{'validation'}{$item} = &mt('None');
14492: }
14493: }
14494: } else {
14495: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
14496: if ($item eq 'markup') {
14497: if ($env{'form.requestcourses_validation_'.$item}) {
14498: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
14499: }
14500: }
1.266 raeburn 14501: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14502: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14503: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
14504: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14505: }
14506: } else {
14507: if ($confhash{'validation'}{$item} ne '') {
14508: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14509: }
1.235 raeburn 14510: }
14511: } else {
14512: if ($confhash{'validation'}{$item} ne '') {
14513: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14514: }
14515: }
14516: }
14517: }
14518: }
14519: if ($env{'form.validationdc'}) {
14520: my $newval = $env{'form.validationdc'};
1.285 raeburn 14521: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 14522: if (exists($domcoords{$newval})) {
14523: $confhash{'validation'}{'dc'} = $newval;
14524: }
14525: }
14526: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 14527: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14528: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14529: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14530: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
14531: if ($confhash{'validation'}{'dc'} eq '') {
14532: $changes{'validation'}{'dc'} = &mt('None');
14533: } else {
14534: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14535: }
1.235 raeburn 14536: }
1.266 raeburn 14537: } elsif ($confhash{'validation'}{'dc'} ne '') {
14538: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 14539: }
14540: } elsif ($confhash{'validation'}{'dc'} ne '') {
14541: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14542: }
14543: } elsif ($confhash{'validation'}{'dc'} ne '') {
14544: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 14545: }
1.266 raeburn 14546: } else {
14547: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14548: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14549: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14550: $changes{'validation'}{'dc'} = &mt('None');
14551: }
14552: }
1.235 raeburn 14553: }
14554: }
1.102 raeburn 14555: }
14556: } else {
1.86 raeburn 14557: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
14558: }
1.72 raeburn 14559: foreach my $item (@usertools) {
14560: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 14561: my $unset;
1.101 raeburn 14562: if ($context eq 'requestcourses') {
1.104 raeburn 14563: $unset = '0';
14564: if ($type eq '_LC_adv') {
14565: $unset = '';
14566: }
1.101 raeburn 14567: if ($confhash{$item}{$type} eq 'autolimit') {
14568: $confhash{$item}{$type} .= '=';
14569: unless ($limithash{$item}{$type} =~ /\D/) {
14570: $confhash{$item}{$type} .= $limithash{$item}{$type};
14571: }
14572: }
1.163 raeburn 14573: } elsif ($context eq 'requestauthor') {
14574: $unset = '0';
14575: if ($type eq '_LC_adv') {
14576: $unset = '';
14577: }
1.72 raeburn 14578: } else {
1.101 raeburn 14579: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
14580: $confhash{$item}{$type} = 1;
14581: } else {
14582: $confhash{$item}{$type} = 0;
14583: }
1.72 raeburn 14584: }
1.86 raeburn 14585: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 14586: if ($action eq 'requestauthor') {
14587: if ($domconfig{$action}{$type} ne $confhash{$type}) {
14588: $changes{$type} = 1;
14589: }
14590: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 14591: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
14592: $changes{$item}{$type} = 1;
14593: }
14594: } else {
14595: if ($context eq 'requestcourses') {
1.104 raeburn 14596: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 14597: $changes{$item}{$type} = 1;
14598: }
14599: } else {
14600: if (!$confhash{$item}{$type}) {
14601: $changes{$item}{$type} = 1;
14602: }
14603: }
14604: }
14605: } else {
14606: if ($context eq 'requestcourses') {
1.104 raeburn 14607: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 14608: $changes{$item}{$type} = 1;
14609: }
1.163 raeburn 14610: } elsif ($context eq 'requestauthor') {
14611: if ($confhash{$type} ne $unset) {
14612: $changes{$type} = 1;
14613: }
1.72 raeburn 14614: } else {
14615: if (!$confhash{$item}{$type}) {
14616: $changes{$item}{$type} = 1;
14617: }
14618: }
14619: }
1.1 raeburn 14620: }
14621: }
1.163 raeburn 14622: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 14623: if (ref($domconfig{'quotas'}) eq 'HASH') {
14624: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14625: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
14626: if (exists($confhash{'defaultquota'}{$key})) {
14627: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
14628: $changes{'defaultquota'}{$key} = 1;
14629: }
14630: } else {
14631: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 14632: }
14633: }
1.86 raeburn 14634: } else {
14635: foreach my $key (keys(%{$domconfig{'quotas'}})) {
14636: if (exists($confhash{'defaultquota'}{$key})) {
14637: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
14638: $changes{'defaultquota'}{$key} = 1;
14639: }
14640: } else {
14641: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 14642: }
1.1 raeburn 14643: }
14644: }
1.197 raeburn 14645: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
1.429 raeburn 14646: $confhash{'authorquota'} = $domconfig{'quotas'}{'authorquota'};
14647: }
14648: if (ref($domconfig{'quotas'}{'webdav'}) eq 'HASH') {
14649: $confhash{'webdav'} = $domconfig{'quotas'}{'webdav'};
1.197 raeburn 14650: }
1.1 raeburn 14651: }
1.86 raeburn 14652: if (ref($confhash{'defaultquota'}) eq 'HASH') {
14653: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
14654: if (ref($domconfig{'quotas'}) eq 'HASH') {
14655: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14656: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
14657: $changes{'defaultquota'}{$key} = 1;
14658: }
14659: } else {
14660: if (!exists($domconfig{'quotas'}{$key})) {
14661: $changes{'defaultquota'}{$key} = 1;
14662: }
1.72 raeburn 14663: }
14664: } else {
1.86 raeburn 14665: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 14666: }
1.1 raeburn 14667: }
14668: }
14669: }
1.72 raeburn 14670:
1.163 raeburn 14671: if ($context eq 'requestauthor') {
14672: $domdefaults{'requestauthor'} = \%confhash;
14673: } else {
14674: foreach my $key (keys(%confhash)) {
1.242 raeburn 14675: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 14676: $domdefaults{$key} = $confhash{$key};
14677: }
1.163 raeburn 14678: }
1.72 raeburn 14679: }
1.163 raeburn 14680:
1.1 raeburn 14681: my %quotahash = (
1.86 raeburn 14682: $action => { %confhash }
1.1 raeburn 14683: );
14684: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
14685: $dom);
14686: if ($putresult eq 'ok') {
14687: if (keys(%changes) > 0) {
1.72 raeburn 14688: my $cachetime = 24*60*60;
14689: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 14690: if (ref($lastactref) eq 'HASH') {
14691: $lastactref->{'domdefaults'} = 1;
14692: }
1.1 raeburn 14693: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 14694: unless (($context eq 'requestcourses') ||
1.163 raeburn 14695: ($context eq 'requestauthor')) {
1.86 raeburn 14696: if (ref($changes{'defaultquota'}) eq 'HASH') {
14697: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
14698: foreach my $type (@{$types},'default') {
14699: if (defined($changes{'defaultquota'}{$type})) {
14700: my $typetitle = $usertypes->{$type};
14701: if ($type eq 'default') {
14702: $typetitle = $othertitle;
14703: }
1.213 raeburn 14704: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 14705: }
14706: }
1.86 raeburn 14707: $resulttext .= '</ul></li>';
1.72 raeburn 14708: }
14709: }
1.80 raeburn 14710: my %newenv;
1.72 raeburn 14711: foreach my $item (@usertools) {
1.163 raeburn 14712: my (%haschgs,%inconf);
14713: if ($context eq 'requestauthor') {
14714: %haschgs = %changes;
1.210 raeburn 14715: %inconf = %confhash;
1.163 raeburn 14716: } else {
14717: if (ref($changes{$item}) eq 'HASH') {
14718: %haschgs = %{$changes{$item}};
14719: }
14720: if (ref($confhash{$item}) eq 'HASH') {
14721: %inconf = %{$confhash{$item}};
14722: }
14723: }
14724: if (keys(%haschgs) > 0) {
1.80 raeburn 14725: my $newacc =
14726: &Apache::lonnet::usertools_access($env{'user.name'},
14727: $env{'user.domain'},
1.86 raeburn 14728: $item,'reload',$context);
1.210 raeburn 14729: if (($context eq 'requestcourses') ||
1.163 raeburn 14730: ($context eq 'requestauthor')) {
1.108 raeburn 14731: if ($env{'environment.canrequest.'.$item} ne $newacc) {
14732: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 14733: }
14734: } else {
14735: if ($env{'environment.availabletools.'.$item} ne $newacc) {
14736: $newenv{'environment.availabletools.'.$item} = $newacc;
14737: }
1.80 raeburn 14738: }
1.163 raeburn 14739: unless ($context eq 'requestauthor') {
14740: $resulttext .= '<li>'.$titles{$item}.'<ul>';
14741: }
1.72 raeburn 14742: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 14743: if ($haschgs{$type}) {
1.72 raeburn 14744: my $typetitle = $usertypes->{$type};
14745: if ($type eq 'default') {
14746: $typetitle = $othertitle;
14747: } elsif ($type eq '_LC_adv') {
14748: $typetitle = 'LON-CAPA Advanced Users';
14749: }
1.163 raeburn 14750: if ($inconf{$type}) {
1.101 raeburn 14751: if ($context eq 'requestcourses') {
14752: my $cond;
1.163 raeburn 14753: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 14754: if ($1 eq '') {
14755: $cond = &mt('(Automatic processing of any request).');
14756: } else {
14757: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
14758: }
14759: } else {
1.163 raeburn 14760: $cond = $conditions{$inconf{$type}};
1.101 raeburn 14761: }
14762: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 14763: } elsif ($context eq 'requestauthor') {
14764: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
14765: $titles{$inconf{$type}},$typetitle);
14766:
1.101 raeburn 14767: } else {
14768: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
14769: }
1.72 raeburn 14770: } else {
1.104 raeburn 14771: if ($type eq '_LC_adv') {
1.163 raeburn 14772: if ($inconf{$type} eq '0') {
1.104 raeburn 14773: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14774: } else {
14775: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
14776: }
14777: } else {
14778: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14779: }
1.72 raeburn 14780: }
14781: }
1.26 raeburn 14782: }
1.163 raeburn 14783: unless ($context eq 'requestauthor') {
14784: $resulttext .= '</ul></li>';
14785: }
1.26 raeburn 14786: }
1.1 raeburn 14787: }
1.163 raeburn 14788: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 14789: if (ref($changes{'notify'}) eq 'HASH') {
14790: if ($changes{'notify'}{'approval'}) {
14791: if (ref($confhash{'notify'}) eq 'HASH') {
14792: if ($confhash{'notify'}{'approval'}) {
14793: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
14794: } else {
1.163 raeburn 14795: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 14796: }
14797: }
14798: }
14799: }
14800: }
1.216 raeburn 14801: if ($action eq 'requestcourses') {
14802: my @offon = ('off','on');
14803: if ($changes{'uniquecode'}) {
1.218 raeburn 14804: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14805: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
14806: $resulttext .= '<li>'.
14807: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
14808: '</li>';
14809: } else {
14810: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
14811: '</li>';
14812: }
1.216 raeburn 14813: }
1.242 raeburn 14814: foreach my $type ('textbooks','templates') {
14815: if (ref($changes{$type}) eq 'HASH') {
14816: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
14817: foreach my $key (sort(keys(%{$changes{$type}}))) {
14818: my %coursehash = &Apache::lonnet::coursedescription($key);
14819: my $coursetitle = $coursehash{'description'};
14820: my $position = $confhash{$type}{$key}{'order'} + 1;
14821: $resulttext .= '<li>';
1.243 raeburn 14822: foreach my $item ('subject','title','publisher','author') {
14823: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14824: ($type eq 'templates'));
1.242 raeburn 14825: my $name = $item.':';
14826: $name =~ s/^(\w)/\U$1/;
14827: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
14828: }
14829: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
14830: if ($type eq 'textbooks') {
14831: if ($confhash{$type}{$key}{'image'}) {
14832: $resulttext .= ' '.&mt('Image: [_1]',
14833: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
14834: ' alt="Textbook cover" />').'<br />';
14835: }
14836: }
14837: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 14838: }
1.242 raeburn 14839: $resulttext .= '</ul></li>';
1.216 raeburn 14840: }
14841: }
1.235 raeburn 14842: if (ref($changes{'validation'}) eq 'HASH') {
14843: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
14844: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
14845: foreach my $item (@{$validationitemsref}) {
14846: if (exists($changes{'validation'}{$item})) {
14847: if ($item eq 'markup') {
14848: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14849: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
14850: } else {
14851: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14852: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
14853: }
14854: }
14855: }
14856: if (exists($changes{'validation'}{'dc'})) {
14857: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
14858: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
14859: }
1.442 raeburn 14860: $resulttext .= '</ul></li>';
1.235 raeburn 14861: }
14862: }
1.216 raeburn 14863: }
1.1 raeburn 14864: $resulttext .= '</ul>';
1.80 raeburn 14865: if (keys(%newenv)) {
14866: &Apache::lonnet::appenv(\%newenv);
14867: }
1.1 raeburn 14868: } else {
1.86 raeburn 14869: if ($context eq 'requestcourses') {
14870: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 14871: } elsif ($context eq 'requestauthor') {
14872: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 14873: } else {
1.90 weissno 14874: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 14875: }
1.1 raeburn 14876: }
14877: } else {
1.11 albertel 14878: $resulttext = '<span class="LC_error">'.
14879: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14880: }
1.216 raeburn 14881: if ($errors) {
14882: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
14883: '<ul>'.$errors.'</ul></p>';
14884: }
1.3 raeburn 14885: return $resulttext;
1.1 raeburn 14886: }
14887:
1.216 raeburn 14888: sub process_textbook_image {
1.242 raeburn 14889: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 14890: my $filename = $env{'form.'.$caller.'.filename'};
14891: my ($error,$url);
14892: my ($width,$height) = (50,50);
14893: if ($configuserok eq 'ok') {
14894: if ($switchserver) {
14895: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
14896: $switchserver);
14897: } elsif ($author_ok eq 'ok') {
1.421 raeburn 14898: my $modified = [];
1.216 raeburn 14899: my ($result,$imageurl) =
1.421 raeburn 14900: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
14901: "$type/$cdom/$cnum/cover",$width,$height,
14902: '',$modified);
1.216 raeburn 14903: if ($result eq 'ok') {
14904: $url = $imageurl;
1.421 raeburn 14905: &update_modify_urls($r,$modified);
1.216 raeburn 14906: } else {
14907: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14908: }
14909: } else {
14910: $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);
14911: }
14912: } else {
14913: $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);
14914: }
14915: return ($url,$error);
14916: }
14917:
1.267 raeburn 14918: sub modify_ltitools {
14919: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.421 raeburn 14920: my (%currtoolsec,%secchanges,%newtoolsec,%newkeyset);
14921: &fetch_secrets($dom,'toolsec',\%domconfig,\%currtoolsec,\%secchanges,\%newtoolsec,\%newkeyset);
14922:
1.267 raeburn 14923: my $confname = $dom.'-domainconfig';
14924: my $servadm = $r->dir_config('lonAdmEMail');
14925: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.421 raeburn 14926:
14927: my ($resulttext,$ltitoolsoutput,$is_home,$errors,%ltitoolschg,%newtoolsenc,%newltitools);
14928: my $toolserror =
14929: &Apache::courseprefs::process_ltitools($r,$dom,$confname,$domconfig{'ltitools'},\%ltitoolschg,'domain',
14930: $lastactref,$configuserok,$switchserver,$author_ok);
14931:
14932: my $home = &Apache::lonnet::domain($dom,'primary');
14933: unless (($home eq 'no_host') || ($home eq '')) {
14934: my @ids=&Apache::lonnet::current_machine_ids();
14935: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; last; } }
14936: }
14937:
14938: if (keys(%ltitoolschg)) {
14939: foreach my $id (keys(%ltitoolschg)) {
14940: if (ref($ltitoolschg{$id}) eq 'HASH') {
14941: foreach my $inner (keys(%{$ltitoolschg{$id}})) {
14942: if (($inner eq 'secret') || ($inner eq 'key')) {
14943: if ($is_home) {
14944: $newtoolsenc{$id}{$inner} = $ltitoolschg{$id}{$inner};
14945: }
14946: }
14947: }
1.267 raeburn 14948: }
1.421 raeburn 14949: }
14950: $ltitoolsoutput = &Apache::courseprefs::store_ltitools($dom,'','domain',\%ltitoolschg,$domconfig{'ltitools'});
14951: if (keys(%ltitoolschg)) {
14952: %newltitools = %ltitoolschg;
14953: }
14954: }
14955: if (ref($domconfig{'ltitools'}) eq 'HASH') {
14956: foreach my $id (%{$domconfig{'ltitools'}}) {
14957: next if ($id !~ /^\d+$/);
14958: unless (exists($ltitoolschg{$id})) {
14959: if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
14960: foreach my $inner (keys(%{$domconfig{'ltitools'}{$id}})) {
14961: if (($inner eq 'secret') || ($inner eq 'key')) {
14962: if ($is_home) {
14963: $newtoolsenc{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14964: }
14965: } else {
14966: $newltitools{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14967: }
14968: }
14969: } else {
14970: $newltitools{$id} = $domconfig{'ltitools'}{$id};
1.322 raeburn 14971: }
1.421 raeburn 14972: }
14973: }
14974: }
14975: if ($toolserror) {
14976: $errors = '<li>'.$toolserror.'</li>';
14977: }
14978: if ((keys(%ltitoolschg) == 0) && (keys(%secchanges) == 0)) {
14979: $resulttext = &mt('No changes made.');
14980: if ($errors) {
14981: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
14982: $errors.'</ul>';
14983: }
14984: return $resulttext;
14985: }
14986: my %ltitoolshash = (
14987: $action => { %newltitools }
14988: );
14989: if (keys(%secchanges)) {
14990: $ltitoolshash{'toolsec'} = \%newtoolsec;
14991: }
14992: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,$dom);
14993: if ($putresult eq 'ok') {
14994: my %keystore;
14995: if ($is_home) {
14996: my %toolsenchash = (
14997: $action => { %newtoolsenc }
14998: );
14999: &Apache::lonnet::put_dom('encconfig',\%toolsenchash,$dom,undef,1);
1.423 raeburn 15000: my $cachetime = 24*60*60;
15001: &Apache::lonnet::do_cache_new('ltitoolsenc',$dom,\%newtoolsenc,$cachetime);
1.421 raeburn 15002: &store_security($dom,'ltitools',\%secchanges,\%newkeyset,\%keystore,$lastactref);
15003: }
15004: $resulttext = &mt('Changes made:').'<ul>';
15005: if (keys(%secchanges) > 0) {
1.423 raeburn 15006: $resulttext .= <i_security_results($dom,'ltitools',\%secchanges,\%newtoolsec,\%newkeyset,\%keystore);
1.421 raeburn 15007: }
15008: if (keys(%ltitoolschg) > 0) {
15009: $resulttext .= $ltitoolsoutput;
15010: }
1.423 raeburn 15011: my $cachetime = 24*60*60;
15012: &Apache::lonnet::do_cache_new('ltitools',$dom,\%newltitools,$cachetime);
15013: if (ref($lastactref) eq 'HASH') {
15014: $lastactref->{'ltitools'} = 1;
15015: }
1.421 raeburn 15016: } else {
15017: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15018: }
15019: if ($errors) {
15020: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
15021: $errors.'</ul></p>';
15022: }
15023: return $resulttext;
15024: }
15025:
15026: sub fetch_secrets {
15027: my ($dom,$context,$domconfig,$currsec,$secchanges,$newsec,$newkeyset) = @_;
15028: my %keyset;
15029: %{$currsec} = ();
15030: $newsec->{'private'}{'keys'} = [];
15031: $newsec->{'encrypt'} = {};
15032: $newsec->{'rules'} = {};
15033: if ($context eq 'ltisec') {
15034: $newsec->{'linkprot'} = {};
15035: }
15036: if (ref($domconfig->{$context}) eq 'HASH') {
15037: %{$currsec} = %{$domconfig->{$context}};
15038: if ($context eq 'ltisec') {
15039: if (ref($currsec->{'linkprot'}) eq 'HASH') {
15040: foreach my $id (keys(%{$currsec->{'linkprot'}})) {
15041: unless ($id =~ /^\d+$/) {
15042: delete($currsec->{'linkprot'}{$id});
1.297 raeburn 15043: }
1.267 raeburn 15044: }
15045: }
1.421 raeburn 15046: }
15047: if (ref($currsec->{'private'}) eq 'HASH') {
15048: if (ref($currsec->{'private'}{'keys'}) eq 'ARRAY') {
15049: $newsec->{'private'}{'keys'} = $currsec->{'private'}{'keys'};
15050: map { $keyset{$_} = 1; } @{$currsec->{'private'}{'keys'}};
1.267 raeburn 15051: }
1.421 raeburn 15052: }
15053: }
15054: my @items= ('crs','dom');
15055: if ($context eq 'ltisec') {
15056: push(@items,'consumers');
15057: }
15058: foreach my $item (@items) {
15059: my $formelement;
15060: if (($context eq 'toolsec') || ($item eq 'consumers')) {
15061: $formelement = 'form.'.$context.'_'.$item;
15062: } else {
15063: $formelement = 'form.'.$context.'_'.$item.'linkprot';
15064: }
15065: if ($env{$formelement}) {
15066: $newsec->{'encrypt'}{$item} = 1;
15067: if (ref($currsec->{'encrypt'}) eq 'HASH') {
15068: unless ($currsec->{'encrypt'}{$item}) {
15069: $secchanges->{'encrypt'} = 1;
15070: }
15071: } else {
15072: $secchanges->{'encrypt'} = 1;
1.267 raeburn 15073: }
1.421 raeburn 15074: } elsif (ref($currsec->{'encrypt'}) eq 'HASH') {
15075: if ($currsec->{'encrypt'}{$item}) {
15076: $secchanges->{'encrypt'} = 1;
1.323 raeburn 15077: }
1.421 raeburn 15078: }
15079: }
15080: my $secrets;
15081: if ($context eq 'ltisec') {
15082: $secrets = 'ltisecrets';
15083: } else {
15084: $secrets = 'toolsecrets';
15085: }
15086: unless (exists($currsec->{'rules'})) {
15087: $currsec->{'rules'} = {};
15088: }
15089: &password_rule_changes($secrets,$newsec->{'rules'},$currsec->{'rules'},$secchanges);
15090:
15091: my @ids=&Apache::lonnet::current_machine_ids();
15092: my %servers = &Apache::lonnet::get_servers($dom,'library');
15093:
15094: foreach my $hostid (keys(%servers)) {
15095: if (($hostid ne '') && (grep(/^\Q$hostid\E$/,@ids))) {
15096: my $keyitem = 'form.'.$context.'_privkey_'.$hostid;
15097: if (exists($env{$keyitem})) {
15098: $env{$keyitem} =~ s/(`)/'/g;
15099: if ($keyset{$hostid}) {
15100: if ($env{'form.'.$context.'_changeprivkey_'.$hostid}) {
15101: if ($env{$keyitem} ne '') {
15102: $secchanges->{'private'} = 1;
15103: $newkeyset->{$hostid} = $env{$keyitem};
15104: }
1.296 raeburn 15105: }
1.421 raeburn 15106: } elsif ($env{$keyitem} ne '') {
15107: unless (grep(/^\Q$hostid\E$/,@{$newsec->{'private'}{'keys'}})) {
15108: push(@{$newsec->{'private'}{'keys'}},$hostid);
1.296 raeburn 15109: }
1.421 raeburn 15110: $secchanges->{'private'} = 1;
15111: $newkeyset->{$hostid} = $env{$keyitem};
1.267 raeburn 15112: }
15113: }
1.421 raeburn 15114: }
15115: }
15116: }
15117:
15118: sub store_security {
1.424 raeburn 15119: my ($dom,$context,$secchanges,$newkeyset,$keystore) = @_;
1.421 raeburn 15120: return unless ((ref($secchanges) eq 'HASH') && (ref($newkeyset) eq 'HASH') &&
15121: (ref($keystore) eq 'HASH'));
15122: if (keys(%{$secchanges})) {
15123: if ($secchanges->{'private'}) {
15124: my $who = &escape($env{'user.name'}.':'.$env{'user.domain'});
15125: foreach my $hostid (keys(%{$newkeyset})) {
15126: my $storehash = {
15127: key => $newkeyset->{$hostid},
15128: who => $env{'user.name'}.':'.$env{'user.domain'},
15129: };
15130: $keystore->{$hostid} = &Apache::lonnet::store_dom($storehash,$context,'private',
15131: $dom,$hostid);
15132: }
15133: }
15134: }
15135: }
15136:
15137: sub lti_security_results {
1.423 raeburn 15138: my ($dom,$context,$secchanges,$newsec,$newkeyset,$keystore) = @_;
1.421 raeburn 15139: my $output;
1.423 raeburn 15140: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
15141: my $needs_update;
1.421 raeburn 15142: foreach my $item (keys(%{$secchanges})) {
15143: if ($item eq 'encrypt') {
1.423 raeburn 15144: $needs_update = 1;
1.421 raeburn 15145: my %encrypted;
15146: if ($context eq 'lti') {
15147: %encrypted = (
15148: crs => {
15149: on => &mt('Encryption of stored link protection secrets defined in courses enabled'),
15150: off => &mt('Encryption of stored link protection secrets defined in courses disabled'),
15151: },
15152: dom => {
15153: on => &mt('Encryption of stored link protection secrets defined in domain enabled'),
15154: off => &mt('Encryption of stored link protection secrets defined in domain disabled'),
15155: },
15156: consumers => {
15157: on => &mt('Encryption of stored consumer secrets defined in domain enabled'),
15158: off => &mt('Encryption of stored consumer secrets defined in domain disabled'),
15159: },
15160: );
1.267 raeburn 15161: } else {
1.421 raeburn 15162: %encrypted = (
15163: crs => {
15164: on => &mt('Encryption of stored external tool secrets defined in courses enabled'),
15165: off => &mt('Encryption of stored external tool secrets defined in courses disabled'),
15166: },
15167: dom => {
15168: on => &mt('Encryption of stored external tool secrets defined in domain enabled'),
15169: off => &mt('Encryption of stored external tool secrets defined in domain disabled'),
15170: },
15171: );
15172: }
15173: my @types= ('crs','dom');
15174: if ($context eq 'lti') {
1.423 raeburn 15175: foreach my $type (@types) {
15176: undef($domdefaults{'linkprotenc_'.$type});
15177: }
1.421 raeburn 15178: push(@types,'consumers');
1.423 raeburn 15179: undef($domdefaults{'ltienc_consumers'});
15180: } elsif ($context eq 'ltitools') {
15181: foreach my $type (@types) {
15182: undef($domdefaults{'toolenc_'.$type});
15183: }
1.267 raeburn 15184: }
1.421 raeburn 15185: foreach my $type (@types) {
15186: my $shown = $encrypted{$type}{'off'};
15187: if (ref($newsec->{$item}) eq 'HASH') {
15188: if ($newsec->{$item}{$type}) {
1.423 raeburn 15189: if ($context eq 'lti') {
15190: if ($type eq 'consumers') {
15191: $domdefaults{'ltienc_consumers'} = 1;
15192: } else {
15193: $domdefaults{'linkprotenc_'.$type} = 1;
15194: }
15195: } elsif ($context eq 'ltitools') {
15196: $domdefaults{'toolenc_'.$type} = 1;
15197: }
1.421 raeburn 15198: $shown = $encrypted{$type}{'on'};
1.319 raeburn 15199: }
1.267 raeburn 15200: }
1.421 raeburn 15201: $output .= '<li>'.$shown.'</li>';
1.267 raeburn 15202: }
1.421 raeburn 15203: } elsif ($item eq 'rules') {
15204: my %titles = &Apache::lonlocal::texthash(
15205: min => 'Minimum password length',
15206: max => 'Maximum password length',
15207: chars => 'Required characters',
15208: );
15209: foreach my $rule ('min','max') {
15210: if ($newsec->{rules}{$rule} eq '') {
15211: if ($rule eq 'min') {
15212: $output .= '<li>'.&mt('[_1] not set.',$titles{$rule});
15213: ' '.&mt('Default of [_1] will be used',
15214: $Apache::lonnet::passwdmin).'</li>';
15215: } else {
15216: $output .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
15217: }
15218: } else {
15219: $output .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$newsec->{rules}{$rule}).'</li>';
15220: }
15221: }
15222: if (ref($newsec->{'rules'}{'chars'}) eq 'ARRAY') {
15223: if (@{$newsec->{'rules'}{'chars'}} > 0) {
15224: my %rulenames = &Apache::lonlocal::texthash(
15225: uc => 'At least one upper case letter',
15226: lc => 'At least one lower case letter',
15227: num => 'At least one number',
15228: spec => 'At least one non-alphanumeric',
15229: );
15230: my $needed = '<ul><li>'.
15231: join('</li><li>',map {$rulenames{$_} } @{$newsec->{'rules'}{'chars'}}).
15232: '</li></ul>';
15233: $output .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
15234: } else {
15235: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 15236: }
1.421 raeburn 15237: } else {
15238: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 15239: }
1.421 raeburn 15240: } elsif ($item eq 'private') {
1.423 raeburn 15241: $needs_update = 1;
15242: if ($context eq 'lti') {
15243: undef($domdefaults{'ltiprivhosts'});
15244: } elsif ($context eq 'ltitools') {
15245: undef($domdefaults{'toolprivhosts'});
15246: }
1.421 raeburn 15247: if (keys(%{$newkeyset})) {
1.423 raeburn 15248: my @privhosts;
1.421 raeburn 15249: foreach my $hostid (sort(keys(%{$newkeyset}))) {
15250: if ($keystore->{$hostid} eq 'ok') {
15251: $output .= '<li>'.&mt('Encryption key for storage of shared secrets saved for [_1]',$hostid).'</li>';
1.423 raeburn 15252: unless (grep(/^\Q$hostid\E$/,@privhosts)) {
15253: push(@privhosts,$hostid);
15254: }
15255: }
15256: }
15257: if (@privhosts) {
15258: if ($context eq 'lti') {
15259: $domdefaults{'ltiprivhosts'} = \@privhosts;
15260: } elsif ($context eq 'ltitools') {
15261: $domdefaults{'toolprivhosts'} = \@privhosts;
1.267 raeburn 15262: }
15263: }
15264: }
1.421 raeburn 15265: } elsif ($item eq 'linkprot') {
15266: next;
1.434 raeburn 15267: } elsif ($item eq 'suggested') {
15268: if ((ref($secchanges->{'suggested'}) eq 'HASH') &&
15269: (ref($newsec->{'suggested'}) eq 'HASH')) {
15270: my $suggestions;
15271: foreach my $id (sort { $a <=> $b } keys(%{$secchanges->{'suggested'}})) {
15272: if (ref($newsec->{'suggested'}->{$id}) eq 'HASH') {
15273: my $name = $newsec->{'suggested'}->{$id}->{'name'};
15274: my $info = $newsec->{'suggested'}->{$id}->{'info'};
15275: $suggestions .= '<li>'.&mt('Launcher: [_1]',$name).'<br />'.
15276: &mt('Recommend: [_1]','<pre>'.$info.'</pre>').
15277: '</li>';
15278: } else {
15279: $suggestions .= '<li>'.&mt('Recommendations deleted for Launcher: [_1]',
15280: $newsec->{'suggested'}->{$id}).'</li>';
15281: }
15282: }
15283: if ($suggestions) {
15284: $output .= '<li>'.&mt('Hints in Courses for Link Protector Configuration').
15285: '<ul>'.$suggestions.'</ul>'.
15286: '</li>';
15287: }
15288: }
1.267 raeburn 15289: }
15290: }
1.423 raeburn 15291: if ($needs_update) {
15292: my $cachetime = 24*60*60;
15293: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15294: }
1.421 raeburn 15295: return $output;
15296: }
15297:
15298: sub modify_proctoring {
15299: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15300: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15301: my (@allpos,%changes,%confhash,%encconfhash,$errors,$resulttext,%imgdeletions);
15302: my $confname = $dom.'-domainconfig';
15303: my $servadm = $r->dir_config('lonAdmEMail');
1.372 raeburn 15304: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
15305: my %providernames = &proctoring_providernames();
15306: my $maxnum = scalar(keys(%providernames));
15307:
15308: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
15309: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
15310: if (ref($requref) eq 'HASH') {
15311: %requserfields = %{$requref};
15312: }
15313: if (ref($opturef) eq 'HASH') {
15314: %optuserfields = %{$opturef};
15315: }
15316: if (ref($defref) eq 'HASH') {
15317: %defaults = %{$defref};
15318: }
15319: if (ref($extref) eq 'HASH') {
15320: %extended = %{$extref};
15321: }
15322: if (ref($crsref) eq 'HASH') {
15323: %crsconf = %{$crsref};
15324: }
15325: if (ref($rolesref) eq 'ARRAY') {
15326: @courseroles = @{$rolesref};
15327: }
15328: if (ref($ltiref) eq 'ARRAY') {
15329: @ltiroles = @{$ltiref};
15330: }
15331:
15332: if (ref($domconfig{$action}) eq 'HASH') {
15333: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.proctoring_image_del');
15334: if (@todeleteimages) {
15335: map { $imgdeletions{$_} = 1; } @todeleteimages;
15336: }
15337: }
15338: my %customadds;
15339: my @newcustom = &Apache::loncommon::get_env_multiple('form.proctoring_customadd');
15340: if (@newcustom) {
15341: map { $customadds{$_} = 1; } @newcustom;
15342: }
15343: foreach my $provider (sort(keys(%providernames))) {
15344: $confhash{$provider} = {};
15345: my $pos = $env{'form.proctoring_pos_'.$provider};
15346: $pos =~ s/\D+//g;
15347: $allpos[$pos] = $provider;
15348: my (%current,%currentenc);
15349: my $showroles = 0;
15350: if (ref($domconfig{$action}) eq 'HASH') {
15351: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15352: %current = %{$domconfig{$action}{$provider}};
15353: foreach my $item ('key','secret') {
15354: $currentenc{$item} = $current{$item};
15355: delete($current{$item});
15356: }
15357: }
15358: }
15359: if ($env{'form.proctoring_available_'.$provider}) {
15360: $confhash{$provider}{'available'} = 1;
15361: unless ($current{'available'}) {
15362: $changes{$provider} = 1;
15363: }
15364: } else {
15365: %{$confhash{$provider}} = %current;
15366: %{$encconfhash{$provider}} = %currentenc;
15367: $confhash{$provider}{'available'} = 0;
15368: if ($current{'available'}) {
15369: $changes{$provider} = 1;
15370: }
15371: }
15372: if ($confhash{$provider}{'available'}) {
15373: foreach my $field ('lifetime','version','sigmethod','url','key','secret') {
15374: my $possval = $env{'form.proctoring_'.$provider.'_'.$field};
15375: if ($field eq 'lifetime') {
15376: if ($possval =~ /^\d+$/) {
15377: $confhash{$provider}{$field} = $possval;
15378: }
15379: } elsif ($field eq 'version') {
15380: if ($possval =~ /^\d+\.\d+$/) {
15381: $confhash{$provider}{$field} = $possval;
15382: }
15383: } elsif ($field eq 'sigmethod') {
15384: if ($possval =~ /^\QHMAC-SHA\E(1|256)$/) {
15385: $confhash{$provider}{$field} = $possval;
15386: }
15387: } elsif ($field eq 'url') {
15388: $confhash{$provider}{$field} = $possval;
15389: } elsif (($field eq 'key') || ($field eq 'secret')) {
15390: $encconfhash{$provider}{$field} = $possval;
15391: unless ($currentenc{$field} eq $possval) {
15392: $changes{$provider} = 1;
15393: }
15394: }
15395: unless (($field eq 'key') || ($field eq 'secret')) {
15396: unless ($current{$field} eq $confhash{$provider}{$field}) {
15397: $changes{$provider} = 1;
15398: }
15399: }
15400: }
15401: if ($imgdeletions{$provider}) {
15402: $changes{$provider} = 1;
15403: } elsif ($env{'form.proctoring_image_'.$provider.'.filename'} ne '') {
15404: my ($imageurl,$error) =
15405: &process_proctoring_image($r,$dom,$confname,'proctoring_image_'.$provider,$provider,
15406: $configuserok,$switchserver,$author_ok);
15407: if ($imageurl) {
15408: $confhash{$provider}{'image'} = $imageurl;
15409: $changes{$provider} = 1;
15410: }
15411: if ($error) {
15412: &Apache::lonnet::logthis($error);
15413: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15414: }
15415: } elsif (exists($current{'image'})) {
15416: $confhash{$provider}{'image'} = $current{'image'};
15417: }
15418: if (ref($requserfields{$provider}) eq 'ARRAY') {
15419: if (@{$requserfields{$provider}} > 0) {
15420: if (grep(/^user$/,@{$requserfields{$provider}})) {
15421: if ($env{'form.proctoring_userincdom_'.$provider}) {
15422: $confhash{$provider}{'incdom'} = 1;
15423: }
15424: unless ($current{'incdom'} eq $confhash{$provider}{'incdom'}) {
15425: $changes{$provider} = 1;
15426: }
15427: }
15428: if (grep(/^roles$/,@{$requserfields{$provider}})) {
15429: $showroles = 1;
15430: }
15431: }
15432: }
15433: $confhash{$provider}{'fields'} = [];
15434: if (ref($optuserfields{$provider}) eq 'ARRAY') {
15435: if (@{$optuserfields{$provider}} > 0) {
15436: my @optfields = &Apache::loncommon::get_env_multiple('form.proctoring_optional_'.$provider);
15437: foreach my $field (@{$optuserfields{$provider}}) {
15438: if (grep(/^\Q$field\E$/,@optfields)) {
15439: push(@{$confhash{$provider}{'fields'}},$field);
15440: }
15441: }
15442: }
15443: if (ref($current{'fields'}) eq 'ARRAY') {
15444: unless ($changes{$provider}) {
15445: my @new = sort(@{$confhash{$provider}{'fields'}});
15446: my @old = sort(@{$current{'fields'}});
15447: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15448: if (@diffs) {
15449: $changes{$provider} = 1;
15450: }
15451: }
15452: } elsif (@{$confhash{$provider}{'fields'}}) {
15453: $changes{$provider} = 1;
15454: }
15455: }
15456: if (ref($defaults{$provider}) eq 'ARRAY') {
15457: if (@{$defaults{$provider}} > 0) {
15458: my %options;
15459: if (ref($extended{$provider}) eq 'HASH') {
15460: %options = %{$extended{$provider}};
15461: }
15462: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_defaults_'.$provider);
15463: foreach my $field (@{$defaults{$provider}}) {
15464: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
15465: my $poss = $env{'form.proctoring_defaults_'.$field.'_'.$provider};
15466: if (grep(/^\Q$poss\E$/,@{$options{$field}})) {
15467: push(@{$confhash{$provider}{'defaults'}},$poss);
15468: }
15469: } elsif ((exists($options{$field})) && (ref($options{$field}) eq 'HASH')) {
15470: foreach my $inner (keys(%{$options{$field}})) {
15471: if (ref($options{$field}{$inner}) eq 'ARRAY') {
15472: my $poss = $env{'form.proctoring_'.$inner.'_'.$provider};
15473: if (grep(/^\Q$poss\E$/,@{$options{$field}{$inner}})) {
15474: $confhash{$provider}{'defaults'}{$inner} = $poss;
15475: }
15476: } else {
15477: $confhash{$provider}{'defaults'}{$inner} = $env{'form.proctoring_'.$inner.'_'.$provider};
15478: }
15479: }
15480: } else {
15481: if (grep(/^\Q$field\E$/,@checked)) {
15482: push(@{$confhash{$provider}{'defaults'}},$field);
15483: }
15484: }
15485: }
15486: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15487: if (ref($current{'defaults'}) eq 'ARRAY') {
15488: unless ($changes{$provider}) {
15489: my @new = sort(@{$confhash{$provider}{'defaults'}});
15490: my @old = sort(@{$current{'defaults'}});
15491: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15492: if (@diffs) {
15493: $changes{$provider} = 1;
15494: }
15495: }
15496: } elsif (ref($current{'defaults'}) eq 'ARRAY') {
15497: if (@{$current{'defaults'}}) {
15498: $changes{$provider} = 1;
15499: }
15500: }
15501: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15502: if (ref($current{'defaults'}) eq 'HASH') {
15503: unless ($changes{$provider}) {
15504: foreach my $key (keys(%{$confhash{$provider}{'defaults'}})) {
15505: unless ($confhash{$provider}{'defaults'}{$key} eq $current{'defaults'}{$key}) {
15506: $changes{$provider} = 1;
15507: last;
15508: }
15509: }
15510: }
15511: unless ($changes{$provider}) {
15512: foreach my $key (keys(%{$current{'defaults'}})) {
15513: unless ($current{'defaults'}{$key} eq $confhash{$provider}{'defaults'}{$key}) {
15514: $changes{$provider} = 1;
15515: last;
15516: }
15517: }
15518: }
15519: } elsif (keys(%{$confhash{$provider}{'defaults'}})) {
15520: $changes{$provider} = 1;
15521: }
15522: }
15523: }
15524: }
15525: if (ref($crsconf{$provider}) eq 'ARRAY') {
15526: if (@{$crsconf{$provider}} > 0) {
15527: $confhash{$provider}{'crsconf'} = [];
15528: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_crsconf_'.$provider);
15529: foreach my $crsfield (@{$crsconf{$provider}}) {
15530: if (grep(/^\Q$crsfield\E$/,@checked)) {
15531: push(@{$confhash{$provider}{'crsconf'}},$crsfield);
15532: }
15533: }
15534: if (ref($current{'crsconf'}) eq 'ARRAY') {
15535: unless ($changes{$provider}) {
15536: my @new = sort(@{$confhash{$provider}{'crsconf'}});
15537: my @old = sort(@{$current{'crsconf'}});
15538: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15539: if (@diffs) {
15540: $changes{$provider} = 1;
15541: }
15542: }
15543: } elsif (@{$confhash{$provider}{'crsconf'}}) {
15544: $changes{$provider} = 1;
15545: }
15546: }
15547: }
15548: if ($showroles) {
15549: $confhash{$provider}{'roles'} = {};
15550: foreach my $role (@courseroles) {
15551: my $poss = $env{'form.proctoring_roles_'.$role.'_'.$provider};
15552: if (grep(/^\Q$poss\E$/,@ltiroles)) {
15553: $confhash{$provider}{'roles'}{$role} = $poss;
15554: }
15555: }
15556: unless ($changes{$provider}) {
15557: if (ref($current{'roles'}) eq 'HASH') {
15558: foreach my $role (keys(%{$current{'roles'}})) {
15559: unless ($current{'roles'}{$role} eq $confhash{$provider}{'roles'}{$role}) {
15560: $changes{$provider} = 1;
15561: last
15562: }
15563: }
15564: unless ($changes{$provider}) {
15565: foreach my $role (keys(%{$confhash{$provider}{'roles'}})) {
15566: unless ($confhash{$provider}{'roles'}{$role} eq $current{'roles'}{$role}) {
15567: $changes{$provider} = 1;
15568: last;
15569: }
15570: }
15571: }
15572: } elsif (keys(%{$confhash{$provider}{'roles'}})) {
15573: $changes{$provider} = 1;
15574: }
15575: }
15576: }
15577: if (ref($current{'custom'}) eq 'HASH') {
15578: my @customdels = &Apache::loncommon::get_env_multiple('form.proctoring_customdel_'.$provider);
15579: foreach my $key (keys(%{$current{'custom'}})) {
15580: if (grep(/^\Q$key\E$/,@customdels)) {
15581: $changes{$provider} = 1;
15582: } else {
15583: $confhash{$provider}{'custom'}{$key} = $env{'form.proctoring_customval_'.$key.'_'.$provider};
15584: if ($confhash{$provider}{'custom'}{$key} ne $current{'custom'}{$key}) {
15585: $changes{$provider} = 1;
15586: }
15587: }
15588: }
15589: }
15590: if ($customadds{$provider}) {
15591: my $name = $env{'form.proctoring_custom_name_'.$provider};
15592: $name =~ s/(`)/'/g;
15593: $name =~ s/^\s+//;
15594: $name =~ s/\s+$//;
15595: my $value = $env{'form.proctoring_custom_value_'.$provider};
15596: $value =~ s/(`)/'/g;
15597: $value =~ s/^\s+//;
15598: $value =~ s/\s+$//;
15599: if ($name ne '') {
15600: $confhash{$provider}{'custom'}{$name} = $value;
15601: $changes{$provider} = 1;
15602: }
15603: }
15604: }
15605: }
15606: if (@allpos > 0) {
15607: my $idx = 0;
15608: foreach my $provider (@allpos) {
15609: if ($provider ne '') {
15610: $confhash{$provider}{'order'} = $idx;
15611: unless ($changes{$provider}) {
15612: if (ref($domconfig{$action}) eq 'HASH') {
15613: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15614: if ($domconfig{$action}{$provider}{'order'} ne $idx) {
15615: $changes{$provider} = 1;
15616: }
15617: }
15618: }
15619: }
15620: $idx ++;
15621: }
15622: }
15623: }
15624: my %proc_hash = (
15625: $action => { %confhash }
15626: );
15627: my $putresult = &Apache::lonnet::put_dom('configuration',\%proc_hash,
15628: $dom);
15629: if ($putresult eq 'ok') {
15630: my %proc_enchash = (
15631: $action => { %encconfhash }
15632: );
1.384 raeburn 15633: &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom,undef,1);
1.372 raeburn 15634: if (keys(%changes) > 0) {
15635: my $cachetime = 24*60*60;
15636: my %procall = %confhash;
15637: foreach my $provider (keys(%procall)) {
15638: if (ref($encconfhash{$provider}) eq 'HASH') {
15639: foreach my $key ('key','secret') {
15640: $procall{$provider}{$key} = $encconfhash{$provider}{$key};
15641: }
15642: }
15643: }
15644: &Apache::lonnet::do_cache_new('proctoring',$dom,\%procall,$cachetime);
15645: if (ref($lastactref) eq 'HASH') {
15646: $lastactref->{'proctoring'} = 1;
15647: }
15648: $resulttext = &mt('Configuration for Provider(s) with changes:').'<ul>';
15649: my %bynum;
15650: foreach my $provider (sort(keys(%changes))) {
15651: my $position = $confhash{$provider}{'order'};
15652: $bynum{$position} = $provider;
15653: }
15654: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
15655: my $provider = $bynum{$pos};
15656: my %lt = &proctoring_titles($provider);
15657: my %fieldtitles = &proctoring_fieldtitles($provider);
15658: if (!$confhash{$provider}{'available'}) {
15659: $resulttext .= '<li>'.&mt('Proctoring integration unavailable for: [_1]','<b>'.$providernames{$provider}.'</b>').'</li>';
15660: } else {
15661: $resulttext .= '<li>'.&mt('Proctoring integration available for: [_1]','<b>'.$providernames{$provider}.'</b>');
15662: if ($confhash{$provider}{'image'}) {
15663: $resulttext .= ' '.
15664: '<img src="'.$confhash{$provider}{'image'}.'"'.
15665: ' alt="'.&mt('Proctoring icon').'" />';
15666: }
15667: $resulttext .= '<ul>';
15668: my $position = $pos + 1;
15669: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
15670: foreach my $key ('version','sigmethod','url','lifetime') {
15671: if ($confhash{$provider}{$key} ne '') {
15672: $resulttext .= '<li>'.$lt{$key}.': '.$confhash{$provider}{$key}.'</li>';
15673: }
15674: }
15675: if ($encconfhash{$provider}{'key'} ne '') {
15676: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfhash{$provider}{'key'}.'</li>';
15677: }
15678: if ($encconfhash{$provider}{'secret'} ne '') {
15679: $resulttext .= '<li>'.$lt{'secret'}.': ';
15680: my $num = length($encconfhash{$provider}{'secret'});
15681: $resulttext .= ('*'x$num).'</li>';
15682: }
15683: my (@fields,$showroles);
15684: if (ref($requserfields{$provider}) eq 'ARRAY') {
15685: push(@fields,@{$requserfields{$provider}});
15686: }
15687: if (ref($confhash{$provider}{'fields'}) eq 'ARRAY') {
15688: push(@fields,@{$confhash{$provider}{'fields'}});
15689: } elsif (ref($confhash{$provider}{'fields'}) eq 'HASH') {
15690: push(@fields,(keys(%{$confhash{$provider}{'fields'}})));
15691: }
15692: if (@fields) {
15693: if (grep(/^roles$/,@fields)) {
15694: $showroles = 1;
15695: }
15696: $resulttext .= '<li>'.$lt{'udsl'}.': "'.
15697: join('", "', map { $lt{$_}; } @fields).'"</li>';
15698: }
15699: if (ref($requserfields{$provider}) eq 'ARRAY') {
15700: if (grep(/^user$/,@{$requserfields{$provider}})) {
15701: if ($confhash{$provider}{'incdom'}) {
15702: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'uname:dom'}).'</li>';
15703: } else {
15704: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'username'}).'</li>';
15705: }
15706: }
15707: }
15708: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15709: if (@{$confhash{$provider}{'defaults'}} > 0) {
15710: $resulttext .= '<li>'.$lt{'defa'};
15711: foreach my $field (@{$confhash{$provider}{'defaults'}}) {
15712: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15713: }
15714: $resulttext =~ s/,$//;
15715: $resulttext .= '</li>';
15716: }
15717: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15718: if (keys(%{$confhash{$provider}{'defaults'}})) {
15719: $resulttext .= '<li>'.$lt{'defa'}.': <ul>';
15720: foreach my $key (sort(keys(%{$confhash{$provider}{'defaults'}}))) {
15721: if ($confhash{$provider}{'defaults'}{$key} ne '') {
15722: $resulttext .= '<li>'.$fieldtitles{$key}.' = '.$confhash{$provider}{'defaults'}{$key}.'</li>';
15723: }
15724: }
15725: $resulttext .= '</ul></li>';
15726: }
15727: }
15728: if (ref($crsconf{$provider}) eq 'ARRAY') {
15729: if (@{$crsconf{$provider}} > 0) {
15730: $resulttext .= '<li>'.&mt('Configurable in course:');
15731: my $numconfig = 0;
15732: if (ref($confhash{$provider}{'crsconf'}) eq 'ARRAY') {
15733: if (@{$confhash{$provider}{'crsconf'}} > 0) {
15734: foreach my $field (@{$confhash{$provider}{'crsconf'}}) {
15735: $numconfig ++;
15736: if ($provider eq 'examity') {
15737: $resulttext .= ' "'.$lt{'crs'.$field}.'",';
15738: } else {
15739: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15740: }
15741: }
15742: $resulttext =~ s/,$//;
15743: }
15744: }
15745: if (!$numconfig) {
15746: $resulttext .= ' '.&mt('None');
15747: }
15748: $resulttext .= '</li>';
15749: }
15750: }
15751: if ($showroles) {
15752: if (ref($confhash{$provider}{'roles'}) eq 'HASH') {
15753: my $rolemaps;
15754: foreach my $role (@courseroles) {
15755: if ($confhash{$provider}{'roles'}{$role}) {
15756: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
15757: $confhash{$provider}{'roles'}{$role}.',';
15758: }
15759: }
15760: if ($rolemaps) {
15761: $rolemaps =~ s/,$//;
15762: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
15763: }
15764: }
15765: }
15766: if (ref($confhash{$provider}{'custom'}) eq 'HASH') {
15767: my $customlist;
15768: if (keys(%{$confhash{$provider}{'custom'}})) {
15769: foreach my $key (sort(keys(%{$confhash{$provider}{'custom'}}))) {
15770: $customlist .= $key.'='.$confhash{$provider}{'custom'}{$key}.', ';
15771: }
15772: $customlist =~ s/,$//;
15773: }
15774: if ($customlist) {
15775: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
15776: }
15777: }
15778: $resulttext .= '</ul></li>';
15779: }
15780: }
15781: $resulttext .= '</ul>';
15782: } else {
15783: $resulttext = &mt('No changes made.');
15784: }
15785: } else {
15786: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15787: }
15788: if ($errors) {
15789: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15790: $errors.'</ul>';
15791: }
15792: return $resulttext;
15793: }
15794:
15795: sub process_proctoring_image {
15796: my ($r,$dom,$confname,$caller,$provider,$configuserok,$switchserver,$author_ok) = @_;
15797: my $filename = $env{'form.'.$caller.'.filename'};
15798: my ($error,$url);
15799: my ($width,$height) = (21,21);
15800: if ($configuserok eq 'ok') {
15801: if ($switchserver) {
15802: $error = &mt('Upload of Remote Proctoring Provider icon is not permitted to this server: [_1]',
15803: $switchserver);
15804: } elsif ($author_ok eq 'ok') {
1.421 raeburn 15805: my $modified = [];
1.372 raeburn 15806: my ($result,$imageurl,$madethumb) =
1.421 raeburn 15807: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
15808: "proctoring/$provider/icon",$width,$height,
15809: '',$modified);
1.372 raeburn 15810: if ($result eq 'ok') {
15811: if ($madethumb) {
15812: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
15813: my $imagethumb = "$path/tn-".$imagefile;
15814: $url = $imagethumb;
15815: } else {
15816: $url = $imageurl;
15817: }
1.421 raeburn 15818: &update_modify_urls($r,$modified);
1.372 raeburn 15819: } else {
15820: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
15821: }
15822: } else {
15823: $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);
15824: }
15825: } else {
15826: $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);
15827: }
15828: return ($url,$error);
15829: }
15830:
1.320 raeburn 15831: sub modify_lti {
15832: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15833: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.424 raeburn 15834: my ($newid,@allpos,%changes,%confhash,%ltienc,$errors,$resulttext);
1.320 raeburn 15835: my (%posslti,%posslticrs,%posscrstype);
15836: my @courseroles = ('cc','in','ta','ep','st');
15837: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
15838: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
1.392 raeburn 15839: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 15840: my %coursetypetitles = &Apache::lonlocal::texthash (
15841: official => 'Official',
15842: unofficial => 'Unofficial',
15843: community => 'Community',
15844: textbook => 'Textbook',
15845: placement => 'Placement Test',
1.392 raeburn 15846: lti => 'LTI Provider',
1.320 raeburn 15847: );
1.325 raeburn 15848: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 15849: my %lt = <i_names();
15850: map { $posslti{$_} = 1; } @ltiroles;
15851: map { $posslticrs{$_} = 1; } @lticourseroles;
15852: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 15853:
1.326 raeburn 15854: my %menutitles = <imenu_titles();
1.421 raeburn 15855: my (%currltisec,%secchanges,%newltisec,%newltienc,%newkeyset);
1.326 raeburn 15856:
1.421 raeburn 15857: &fetch_secrets($dom,'ltisec',\%domconfig,\%currltisec,\%secchanges,\%newltisec,\%newkeyset);
1.405 raeburn 15858:
1.406 raeburn 15859: my (%linkprotchg,$linkprotoutput,$is_home);
15860: my $proterror = &Apache::courseprefs::process_linkprot($dom,'',$currltisec{'linkprot'},
15861: \%linkprotchg,'domain');
15862: my $home = &Apache::lonnet::domain($dom,'primary');
15863: unless (($home eq 'no_host') || ($home eq '')) {
15864: my @ids=&Apache::lonnet::current_machine_ids();
15865: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; } }
15866: }
15867:
15868: if (keys(%linkprotchg)) {
15869: $secchanges{'linkprot'} = 1;
15870: my %oldlinkprot;
15871: if (ref($currltisec{'linkprot'}) eq 'HASH') {
15872: %oldlinkprot = %{$currltisec{'linkprot'}};
15873: }
15874: foreach my $id (keys(%linkprotchg)) {
15875: if (ref($linkprotchg{$id}) eq 'HASH') {
15876: foreach my $inner (keys(%{$linkprotchg{$id}})) {
15877: if (($inner eq 'secret') || ($inner eq 'key')) {
15878: if ($is_home) {
15879: $newltienc{$id}{$inner} = $linkprotchg{$id}{$inner};
15880: }
15881: }
15882: }
15883: } else {
15884: $newltisec{'linkprot'}{$id} = $linkprotchg{$id};
15885: }
15886: }
15887: $linkprotoutput = &Apache::courseprefs::store_linkprot($dom,'','domain',\%linkprotchg,\%oldlinkprot);
15888: if (keys(%linkprotchg)) {
15889: %{$newltisec{'linkprot'}} = %linkprotchg;
15890: }
15891: }
15892: if (ref($currltisec{'linkprot'}) eq 'HASH') {
1.434 raeburn 15893: foreach my $id (keys(%{$currltisec{'linkprot'}})) {
1.406 raeburn 15894: next if ($id !~ /^\d+$/);
15895: unless (exists($linkprotchg{$id})) {
15896: if (ref($currltisec{'linkprot'}{$id}) eq 'HASH') {
15897: foreach my $inner (keys(%{$currltisec{'linkprot'}{$id}})) {
15898: if (($inner eq 'secret') || ($inner eq 'key')) {
15899: if ($is_home) {
15900: $newltienc{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15901: }
15902: } else {
15903: $newltisec{'linkprot'}{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15904: }
15905: }
15906: } else {
15907: $newltisec{'linkprot'}{$id} = $currltisec{'linkprot'}{$id};
15908: }
15909: }
15910: }
15911: }
15912: if ($proterror) {
15913: $errors .= '<li>'.$proterror.'</li>';
15914: }
1.434 raeburn 15915:
15916: my (%delsuggested,%suggids,@suggested);;
15917: if (ref($currltisec{'suggested'}) eq 'HASH') {
15918: my $maxnum = $env{'form.linkprot_suggested_maxnum'};
15919: my @todelete = &Apache::loncommon::get_env_multiple('form.linkprot_suggested_del');
15920: for (my $i=0; $i<$maxnum; $i++) {
15921: my $itemid = $env{'form.linkprot_suggested_id_'.$i};
15922: $itemid =~ s/\D+//g;
15923: if ($itemid) {
15924: if (ref($currltisec{'suggested'}->{$itemid}) eq 'HASH') {
15925: push(@suggested,$i);
15926: $suggids{$i} = $itemid;
15927: if ((@todelete > 0) && (grep(/^$i$/,@todelete))) {
15928: if (ref($currltisec{'suggested'}{$itemid}) eq 'HASH') {
15929: $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
15930: }
15931: } else {
15932: if ($env{'form.linkprot_suggested_name_'.$i} eq '') {
15933: $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
15934: } else {
15935: $env{'form.linkprot_suggested_name_'.$i} =~ s/(`)/'/g;
15936: $env{'form.linkprot_suggested_info_'.$i} =~ s/(`)/'/g;
15937: $newltisec{'suggested'}{$itemid}{'name'} = $env{'form.linkprot_suggested_name_'.$i};
15938: $newltisec{'suggested'}{$itemid}{'info'} = $env{'form.linkprot_suggested_info_'.$i};
15939: if (($currltisec{'suggested'}{$itemid}{'name'} ne $newltisec{'suggested'}{$itemid}{'name'}) ||
15940: ($currltisec{'suggested'}{$itemid}{'info'} ne $newltisec{'suggested'}{$itemid}{'info'})) {
15941: $secchanges{'suggested'}{$itemid} = 1;
15942: }
15943: }
15944: }
15945: }
15946: }
15947: }
15948: }
15949: foreach my $key (keys(%delsuggested)) {
15950: $newltisec{'suggested'}{$key} = $delsuggested{$key};
15951: $secchanges{'suggested'}{$key} = 1;
15952: }
15953: if (($env{'form.linkprot_suggested_add'}) &&
15954: ($env{'form.linkprot_suggested_name_add'} ne '')) {
15955: $env{'form.linkprot_suggested_name_add'} =~ s/(`)/'/g;
15956: $env{'form.linkprot_suggested_info_add'} =~ s/(`)/'/g;
15957: my ($newsuggid,$errormsg) = &get_lti_id($dom,$env{'form.linkprot_suggested_name_add'},'suggested');
15958: if ($newsuggid) {
15959: $newltisec{'suggested'}{$newsuggid}{'name'} = $env{'form.linkprot_suggested_name_add'};
15960: $newltisec{'suggested'}{$newsuggid}{'info'} = $env{'form.linkprot_suggested_info_add'};
15961: $secchanges{'suggested'}{$newsuggid} = 1;
15962: } else {
15963: my $error = &mt('Failed to acquire unique ID for new Link Protectors in Courses Suggestion');
15964: if ($errormsg) {
15965: $error .= ' ('.$errormsg.')';
15966: }
15967: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15968: }
15969: }
1.320 raeburn 15970: my (@items,%deletions,%itemids);
15971: if ($env{'form.lti_add'}) {
15972: my $consumer = $env{'form.lti_consumer_add'};
15973: $consumer =~ s/(`)/'/g;
1.434 raeburn 15974: ($newid,my $errormsg) = &get_lti_id($dom,$consumer,'lti');
1.320 raeburn 15975: if ($newid) {
15976: $itemids{'add'} = $newid;
15977: push(@items,'add');
15978: $changes{$newid} = 1;
15979: } else {
15980: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
1.434 raeburn 15981: if ($errormsg) {
15982: $error .= ' ('.$errormsg.')';
15983: }
1.320 raeburn 15984: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15985: }
15986: }
15987: if (ref($domconfig{$action}) eq 'HASH') {
15988: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
15989: if (@todelete) {
15990: map { $deletions{$_} = 1; } @todelete;
15991: }
15992: my $maxnum = $env{'form.lti_maxnum'};
1.390 raeburn 15993: for (my $i=0; $i<$maxnum; $i++) {
1.320 raeburn 15994: my $itemid = $env{'form.lti_id_'.$i};
15995: $itemid =~ s/\D+//g;
15996: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
15997: if ($deletions{$itemid}) {
15998: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
15999: } else {
1.390 raeburn 16000: push(@items,$i);
16001: $itemids{$i} = $itemid;
1.320 raeburn 16002: }
16003: }
16004: }
16005: }
1.424 raeburn 16006: my (%keystore,$secstored);
16007: if ($is_home) {
16008: &store_security($dom,'lti',\%secchanges,\%newkeyset,\%keystore);
16009: }
16010:
16011: my ($cipher,$privnum);
16012: if ((@items > 0) && ($is_home)) {
16013: ($cipher,$privnum) = &get_priv_creds($dom,$home,$secchanges{'encrypt'},
16014: $newltisec{'encrypt'},$keystore{$home});
16015: }
1.320 raeburn 16016: foreach my $idx (@items) {
16017: my $itemid = $itemids{$idx};
16018: next unless ($itemid);
1.424 raeburn 16019: my %currlti;
16020: unless ($idx eq 'add') {
16021: if (ref($domconfig{$action}) eq 'HASH') {
16022: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
16023: %currlti = %{$domconfig{$action}{$itemid}};
16024: }
16025: }
16026: }
1.390 raeburn 16027: my $position = $env{'form.lti_pos_'.$itemid};
1.320 raeburn 16028: $position =~ s/\D+//g;
16029: if ($position ne '') {
16030: $allpos[$position] = $itemid;
16031: }
1.424 raeburn 16032: foreach my $item ('consumer','lifetime','requser','crsinc') {
1.320 raeburn 16033: my $formitem = 'form.lti_'.$item.'_'.$idx;
16034: $env{$formitem} =~ s/(`)/'/g;
16035: if ($item eq 'lifetime') {
16036: $env{$formitem} =~ s/[^\d.]//g;
16037: }
16038: if ($env{$formitem} ne '') {
1.424 raeburn 16039: $confhash{$itemid}{$item} = $env{$formitem};
16040: unless (($idx eq 'add') || ($changes{$itemid})) {
16041: if ($currlti{$item} ne $confhash{$itemid}{$item}) {
16042: $changes{$itemid} = 1;
1.320 raeburn 16043: }
16044: }
16045: }
16046: }
16047: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
16048: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
16049: }
1.345 raeburn 16050: if ($confhash{$itemid}{'requser'}) {
16051: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
1.405 raeburn 16052: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
1.345 raeburn 16053: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
16054: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
16055: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
16056: my $mapuser = $env{'form.lti_customuser_'.$idx};
16057: $mapuser =~ s/(`)/'/g;
1.405 raeburn 16058: $mapuser =~ s/^\s+|\s+$//g;
16059: $confhash{$itemid}{'mapuser'} = $mapuser;
1.345 raeburn 16060: }
16061: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
16062: my @makeuser;
16063: foreach my $ltirole (sort(@possmakeuser)) {
16064: if ($posslti{$ltirole}) {
16065: push(@makeuser,$ltirole);
16066: }
16067: }
16068: $confhash{$itemid}{'makeuser'} = \@makeuser;
16069: if (@makeuser) {
16070: my $lcauth = $env{'form.lti_lcauth_'.$idx};
16071: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
16072: $confhash{$itemid}{'lcauth'} = $lcauth;
16073: if ($lcauth ne 'internal') {
16074: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
16075: $lcauthparm =~ s/^(\s+|\s+)$//g;
16076: $lcauthparm =~ s/`//g;
16077: if ($lcauthparm ne '') {
16078: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
16079: }
16080: }
16081: } else {
16082: $confhash{$itemid}{'lcauth'} = 'lti';
16083: }
1.320 raeburn 16084: }
1.345 raeburn 16085: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
16086: if (@possinstdata) {
16087: foreach my $field (@possinstdata) {
16088: if (exists($fieldtitles{$field})) {
16089: push(@{$confhash{$itemid}{'instdata'}});
1.325 raeburn 16090: }
16091: }
16092: }
1.363 raeburn 16093: if ($env{'form.lti_callback_'.$idx}) {
16094: if ($env{'form.lti_callbackparam_'.$idx}) {
16095: my $callback = $env{'form.lti_callbackparam_'.$idx};
16096: $callback =~ s/^\s+|\s+$//g;
16097: $confhash{$itemid}{'callback'} = $callback;
16098: }
16099: }
1.391 raeburn 16100: foreach my $field ('topmenu','inlinemenu') {
1.345 raeburn 16101: if ($env{'form.lti_'.$field.'_'.$idx}) {
16102: $confhash{$itemid}{$field} = 1;
16103: }
1.320 raeburn 16104: }
1.345 raeburn 16105: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
16106: $confhash{$itemid}{lcmenu} = [];
16107: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
16108: foreach my $field (@possmenu) {
16109: if (exists($menutitles{$field})) {
16110: if ($field eq 'grades') {
16111: next unless ($env{'form.lti_inlinemenu_'.$idx});
16112: }
16113: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 16114: }
16115: }
16116: }
1.391 raeburn 16117: if ($confhash{$itemid}{'crsinc'}) {
16118: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
16119: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
16120: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
16121: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
16122: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
16123: $mapcrs =~ s/(`)/'/g;
16124: $mapcrs =~ s/^\s+|\s+$//g;
16125: $confhash{$itemid}{'mapcrs'} = $mapcrs;
16126: }
16127: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
16128: my @crstypes;
16129: foreach my $type (sort(@posstypes)) {
16130: if ($posscrstype{$type}) {
16131: push(@crstypes,$type);
16132: }
16133: }
16134: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
1.392 raeburn 16135: if ($env{'form.lti_storecrs_'.$idx}) {
16136: $confhash{$itemid}{'storecrs'} = 1;
16137: }
1.391 raeburn 16138: if ($env{'form.lti_makecrs_'.$idx}) {
16139: $confhash{$itemid}{'makecrs'} = 1;
16140: }
16141: foreach my $ltirole (@lticourseroles) {
16142: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
16143: if (grep(/^\Q$possrole\E$/,@courseroles)) {
16144: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
16145: }
16146: }
16147: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
16148: my @selfenroll;
16149: foreach my $type (sort(@possenroll)) {
16150: if ($posslticrs{$type}) {
16151: push(@selfenroll,$type);
16152: }
16153: }
16154: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
16155: if ($env{'form.lti_crssec_'.$idx}) {
16156: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
16157: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
16158: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
16159: my $section = $env{'form.lti_customsection_'.$idx};
16160: $section =~ s/(`)/'/g;
16161: $section =~ s/^\s+|\s+$//g;
16162: if ($section ne '') {
16163: $confhash{$itemid}{'section'} = $section;
16164: }
16165: }
16166: }
16167: foreach my $field ('passback','roster') {
16168: if ($env{'form.lti_'.$field.'_'.$idx}) {
16169: $confhash{$itemid}{$field} = 1;
16170: }
16171: }
16172: if ($env{'form.lti_passback_'.$idx}) {
16173: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
16174: $confhash{$itemid}{'passbackformat'} = '1.0';
16175: } else {
16176: $confhash{$itemid}{'passbackformat'} = '1.1';
1.337 raeburn 16177: }
16178: }
1.391 raeburn 16179: }
16180: unless (($idx eq 'add') || ($changes{$itemid})) {
16181: if ($confhash{$itemid}{'crsinc'}) {
1.392 raeburn 16182: foreach my $field ('mapcrs','storecrs','makecrs','section','passback','roster') {
1.424 raeburn 16183: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.320 raeburn 16184: $changes{$itemid} = 1;
16185: }
1.345 raeburn 16186: }
16187: unless ($changes{$itemid}) {
1.424 raeburn 16188: if ($currlti{'passback'} eq $confhash{$itemid}{'passback'}) {
16189: if ($currlti{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 16190: $changes{$itemid} = 1;
16191: }
16192: }
1.345 raeburn 16193: }
1.391 raeburn 16194: foreach my $field ('mapcrstype','selfenroll') {
16195: unless ($changes{$itemid}) {
1.424 raeburn 16196: if (ref($currlti{$field}) eq 'ARRAY') {
1.391 raeburn 16197: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424 raeburn 16198: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391 raeburn 16199: $confhash{$itemid}{$field});
16200: if (@diffs) {
16201: $changes{$itemid} = 1;
16202: }
1.424 raeburn 16203: } elsif (@{$currlti{$field}} > 0) {
1.391 raeburn 16204: $changes{$itemid} = 1;
16205: }
16206: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
16207: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 16208: $changes{$itemid} = 1;
16209: }
16210: }
1.391 raeburn 16211: }
16212: }
16213: unless ($changes{$itemid}) {
1.424 raeburn 16214: if (ref($currlti{'maproles'}) eq 'HASH') {
1.391 raeburn 16215: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
1.424 raeburn 16216: foreach my $ltirole (keys(%{$currlti{'maproles'}})) {
16217: if ($currlti{'maproles'}{$ltirole} ne
1.391 raeburn 16218: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.345 raeburn 16219: $changes{$itemid} = 1;
16220: last;
16221: }
16222: }
1.391 raeburn 16223: unless ($changes{$itemid}) {
16224: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
16225: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
1.424 raeburn 16226: $currlti{'maproles'}{$ltirole}) {
1.391 raeburn 16227: $changes{$itemid} = 1;
16228: last;
16229: }
16230: }
16231: }
1.424 raeburn 16232: } elsif (keys(%{$currlti{'maproles'}}) > 0) {
1.391 raeburn 16233: $changes{$itemid} = 1;
1.345 raeburn 16234: }
1.391 raeburn 16235: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16236: unless ($changes{$itemid}) {
16237: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
16238: $changes{$itemid} = 1;
16239: }
16240: }
16241: }
16242: }
16243: }
16244: unless ($changes{$itemid}) {
16245: foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
1.424 raeburn 16246: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.345 raeburn 16247: $changes{$itemid} = 1;
1.320 raeburn 16248: }
1.391 raeburn 16249: }
16250: unless ($changes{$itemid}) {
16251: foreach my $field ('makeuser','lcmenu') {
1.424 raeburn 16252: if (ref($currlti{$field}) eq 'ARRAY') {
1.391 raeburn 16253: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424 raeburn 16254: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391 raeburn 16255: $confhash{$itemid}{$field});
16256: if (@diffs) {
16257: $changes{$itemid} = 1;
16258: }
1.424 raeburn 16259: } elsif (@{$currlti{$field}} > 0) {
1.391 raeburn 16260: $changes{$itemid} = 1;
16261: }
16262: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
16263: if (@{$confhash{$itemid}{$field}} > 0) {
16264: $changes{$itemid} = 1;
16265: }
1.345 raeburn 16266: }
1.320 raeburn 16267: }
16268: }
16269: }
16270: }
16271: }
1.424 raeburn 16272: if ($is_home) {
16273: my $keyitem = 'form.lti_key_'.$idx;
16274: $env{$keyitem} =~ s/(`)/'/g;
16275: if ($env{$keyitem} ne '') {
16276: $ltienc{$itemid}{'key'} = $env{$keyitem};
16277: unless ($changes{$itemid}) {
16278: if ($currlti{'key'} ne $env{$keyitem}) {
16279: $changes{$itemid} = 1;
16280: }
16281: }
16282: }
16283: my $secretitem = 'form.lti_secret_'.$idx;
16284: $env{$secretitem} =~ s/(`)/'/g;
16285: if ($currlti{'usable'}) {
16286: if ($env{'form.lti_changesecret_'.$idx}) {
16287: if ($env{$secretitem} ne '') {
16288: if ($privnum && $cipher) {
16289: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
16290: $confhash{$itemid}{'cipher'} = $privnum;
16291: } else {
16292: $ltienc{$itemid}{'secret'} = $env{$secretitem};
16293: }
16294: $changes{$itemid} = 1;
16295: }
16296: } else {
16297: $ltienc{$itemid}{'secret'} = $currlti{'secret'};
16298: $confhash{$itemid}{'cipher'} = $currlti{'cipher'};
16299: }
16300: if (ref($ltienc{$itemid}) eq 'HASH') {
16301: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'secret'} ne '')) {
16302: $confhash{$itemid}{'usable'} = 1;
16303: }
16304: }
16305: } elsif ($env{$secretitem} ne '') {
16306: if ($privnum && $cipher) {
16307: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
16308: $confhash{$itemid}{'cipher'} = $privnum;
16309: } else {
16310: $ltienc{$itemid}{'secret'} = $env{$secretitem};
16311: }
16312: if (ref($ltienc{$itemid}) eq 'HASH') {
16313: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'key'} ne '')) {
16314: $confhash{$itemid}{'usable'} = 1;
16315: }
16316: }
16317: $changes{$itemid} = 1;
16318: }
16319: }
16320: unless ($changes{$itemid}) {
16321: foreach my $key (keys(%currlti)) {
16322: if (ref($currlti{$key}) eq 'HASH') {
16323: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
16324: foreach my $innerkey (keys(%{$currlti{$key}})) {
16325: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
16326: $changes{$itemid} = 1;
16327: last;
16328: }
16329: }
16330: } elsif (keys(%{$currlti{$key}}) > 0) {
16331: $changes{$itemid} = 1;
16332: }
16333: }
16334: last if ($changes{$itemid});
16335: }
16336: }
1.320 raeburn 16337: }
16338: if (@allpos > 0) {
16339: my $idx = 0;
16340: foreach my $itemid (@allpos) {
16341: if ($itemid ne '') {
16342: $confhash{$itemid}{'order'} = $idx;
16343: if (ref($domconfig{$action}) eq 'HASH') {
16344: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
16345: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
16346: $changes{$itemid} = 1;
16347: }
16348: }
16349: }
16350: $idx ++;
16351: }
16352: }
16353: }
1.424 raeburn 16354:
16355: if ((keys(%changes) == 0) && (keys(%secchanges) == 0)) {
16356: return &mt('No changes made.');
16357: }
16358:
1.320 raeburn 16359: my %ltihash = (
1.405 raeburn 16360: $action => { %confhash }
16361: );
1.424 raeburn 16362: my %ltienchash;
16363:
16364: if ($is_home) {
16365: %ltienchash = (
16366: $action => { %ltienc }
16367: );
16368: }
1.405 raeburn 16369: if (keys(%secchanges)) {
16370: $ltihash{'ltisec'} = \%newltisec;
1.406 raeburn 16371: if ($secchanges{'linkprot'}) {
16372: if ($is_home) {
16373: $ltienchash{'linkprot'} = \%newltienc;
16374: }
16375: }
1.405 raeburn 16376: }
16377: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,$dom);
1.320 raeburn 16378: if ($putresult eq 'ok') {
1.424 raeburn 16379: if (keys(%ltienchash)) {
16380: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.405 raeburn 16381: }
16382: $resulttext = &mt('Changes made:').'<ul>';
16383: if (keys(%secchanges) > 0) {
1.423 raeburn 16384: $resulttext .= <i_security_results($dom,'lti',\%secchanges,\%newltisec,\%newkeyset,\%keystore);
1.421 raeburn 16385: if (exists($secchanges{'linkprot'})) {
16386: $resulttext .= $linkprotoutput;
1.405 raeburn 16387: }
16388: }
1.320 raeburn 16389: if (keys(%changes) > 0) {
16390: my $cachetime = 24*60*60;
1.424 raeburn 16391: &Apache::lonnet::do_cache_new('lti',$dom,\%confhash,$cachetime);
1.320 raeburn 16392: if (ref($lastactref) eq 'HASH') {
16393: $lastactref->{'lti'} = 1;
16394: }
16395: my %bynum;
16396: foreach my $itemid (sort(keys(%changes))) {
1.424 raeburn 16397: if (ref($confhash{$itemid}) eq 'HASH') {
16398: my $position = $confhash{$itemid}{'order'};
16399: $bynum{$position} = $itemid;
16400: }
1.320 raeburn 16401: }
16402: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
16403: my $itemid = $bynum{$pos};
1.424 raeburn 16404: if (ref($confhash{$itemid}) eq 'HASH') {
1.390 raeburn 16405: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1.320 raeburn 16406: my $position = $pos + 1;
16407: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
16408: foreach my $item ('version','lifetime') {
16409: if ($confhash{$itemid}{$item} ne '') {
16410: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
16411: }
16412: }
1.424 raeburn 16413: if ($ltienc{$itemid}{'key'} ne '') {
16414: $resulttext .= '<li>'.$lt{'key'}.': '.$ltienc{$itemid}{'key'}.'</li>';
1.320 raeburn 16415: }
1.424 raeburn 16416: if ($ltienc{$itemid}{'secret'} ne '') {
16417: $resulttext .= '<li>'.$lt{'secret'}.': ['.&mt('not shown').']</li>';
1.320 raeburn 16418: }
1.345 raeburn 16419: if ($confhash{$itemid}{'requser'}) {
1.391 raeburn 16420: if ($confhash{$itemid}{'callback'}) {
16421: $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
16422: } else {
1.392 raeburn 16423: $resulttext .= '<li>'.&mt('Callback to logout LON-CAPA on log out from Consumer').'</li>';
1.391 raeburn 16424: }
1.345 raeburn 16425: if ($confhash{$itemid}{'mapuser'}) {
16426: my $shownmapuser;
16427: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
16428: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
16429: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
16430: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
16431: } else {
16432: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 16433: }
1.345 raeburn 16434: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 16435: }
1.345 raeburn 16436: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
16437: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
16438: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
16439: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
16440: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
16441: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
16442: } else {
16443: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
16444: $confhash{$itemid}{'lcauth'});
16445: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
16446: $resulttext .= '; '.&mt('a randomly generated password will be created');
16447: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
16448: if ($confhash{$itemid}{'lcauthparm'} ne '') {
16449: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
16450: }
16451: } else {
16452: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
16453: }
16454: }
16455: $resulttext .= '</li>';
16456: } else {
16457: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
16458: }
1.320 raeburn 16459: }
1.345 raeburn 16460: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
16461: if (@{$confhash{$itemid}{'instdata'}} > 0) {
16462: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
16463: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 16464: } else {
1.345 raeburn 16465: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325 raeburn 16466: }
1.320 raeburn 16467: }
1.391 raeburn 16468: foreach my $item ('topmenu','inlinemenu') {
1.345 raeburn 16469: $resulttext .= '<li>'.$lt{$item}.': ';
16470: if ($confhash{$itemid}{$item}) {
16471: $resulttext .= &mt('Yes');
16472: } else {
16473: $resulttext .= &mt('No');
1.337 raeburn 16474: }
1.345 raeburn 16475: $resulttext .= '</li>';
1.320 raeburn 16476: }
1.345 raeburn 16477: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16478: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16479: $resulttext .= '<li>'.&mt('Menu items:').' '.
1.391 raeburn 16480: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16481: } else {
16482: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16483: }
16484: }
16485: if ($confhash{$itemid}{'crsinc'}) {
16486: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16487: my $rolemaps;
16488: foreach my $role (@ltiroles) {
16489: if ($confhash{$itemid}{'maproles'}{$role}) {
16490: $rolemaps .= (' 'x2).$role.'='.
16491: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
16492: 'Course').',';
16493: }
16494: }
16495: if ($rolemaps) {
16496: $rolemaps =~ s/,$//;
16497: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
16498: }
16499: }
16500: if ($confhash{$itemid}{'mapcrs'}) {
16501: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
16502: }
16503: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
16504: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
16505: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
16506: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
16507: '</li>';
16508: } else {
16509: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
16510: }
16511: }
1.392 raeburn 16512: if ($confhash{$itemid}{'storecrs'}) {
16513: $resulttext .= '<li>'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.$confhash{$itemid}{'storecrs'}.'</li>';
16514: }
1.391 raeburn 16515: if ($confhash{$itemid}{'makecrs'}) {
16516: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
16517: } else {
16518: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
16519: }
16520: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
16521: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
16522: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
16523: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
16524: '</li>';
16525: } else {
16526: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
16527: }
16528: }
16529: if ($confhash{$itemid}{'section'}) {
16530: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
16531: $resulttext .= '<li>'.&mt('User section from standard field:').
16532: ' (course_section_sourcedid)'.'</li>';
16533: } else {
16534: $resulttext .= '<li>'.&mt('User section from:').' '.
16535: $confhash{$itemid}{'section'}.'</li>';
16536: }
1.345 raeburn 16537: } else {
1.391 raeburn 16538: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
16539: }
16540: foreach my $item ('passback','roster','topmenu','inlinemenu') {
16541: $resulttext .= '<li>'.$lt{$item}.': ';
16542: if ($confhash{$itemid}{$item}) {
16543: $resulttext .= &mt('Yes');
16544: if ($item eq 'passback') {
16545: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
16546: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
16547: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
16548: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
16549: }
16550: }
16551: } else {
16552: $resulttext .= &mt('No');
16553: }
16554: $resulttext .= '</li>';
16555: }
16556: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16557: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16558: $resulttext .= '<li>'.&mt('Menu items:').' '.
16559: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16560: } else {
16561: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16562: }
1.345 raeburn 16563: }
1.326 raeburn 16564: }
16565: }
1.320 raeburn 16566: $resulttext .= '</ul></li>';
16567: }
16568: }
1.424 raeburn 16569: if (keys(%deletions)) {
16570: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
16571: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
16572: }
16573: }
1.320 raeburn 16574: }
1.405 raeburn 16575: $resulttext .= '</ul>';
1.424 raeburn 16576: if (ref($lastactref) eq 'HASH') {
1.434 raeburn 16577: if (($secchanges{'encrypt'}) || ($secchanges{'private'}) || (exists($secchanges{'suggested'}))) {
16578: &Apache::lonnet::get_domain_defaults($dom,1);
1.424 raeburn 16579: $lastactref->{'domdefaults'} = 1;
16580: }
16581: }
1.320 raeburn 16582: } else {
16583: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
16584: }
16585: if ($errors) {
16586: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
16587: $errors.'</ul>';
16588: }
16589: return $resulttext;
16590: }
16591:
1.424 raeburn 16592: sub get_priv_creds {
16593: my ($dom,$home,$encchg,$encrypt,$storedsec) = @_;
16594: my ($needenc,$cipher,$privnum);
16595: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
16596: if (($encchg) && (ref($encrypt) eq 'HASH')) {
16597: $needenc = $encrypt->{'consumers'}
16598: } else {
16599: $needenc = $domdefs{'ltienc_consumers'};
16600: }
16601: if ($needenc) {
16602: if (($storedsec eq 'ok') || ((ref($domdefs{'ltiprivhosts'}) eq 'ARRAY') &&
16603: (grep(/^\Q$home\E$/,@{$domdefs{'ltiprivhosts'}})))) {
16604: my %privhash = &Apache::lonnet::restore_dom('lti','private',$dom,$home,1);
16605: my $privkey = $privhash{'key'};
16606: $privnum = $privhash{'version'};
16607: if (($privnum) && ($privkey ne '')) {
16608: $cipher = Crypt::CBC->new({'key' => $privkey,
16609: 'cipher' => 'DES'});
16610: }
16611: }
16612: }
16613: return ($cipher,$privnum);
16614: }
16615:
1.320 raeburn 16616: sub get_lti_id {
1.434 raeburn 16617: my ($domain,$consumer,$dbname) = @_;
16618: unless (($dbname eq 'lti') || ($dbname eq 'suggested')) {
16619: return ('','invalid db');
16620: }
16621: # get lock on db
1.320 raeburn 16622: my $lockhash = {
16623: lock => $env{'user.name'}.
16624: ':'.$env{'user.domain'},
16625: };
16626: my $tries = 0;
1.434 raeburn 16627: my $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1.320 raeburn 16628: my ($id,$error);
16629:
16630: while (($gotlock ne 'ok') && ($tries<10)) {
16631: $tries ++;
16632: sleep (0.1);
1.434 raeburn 16633: $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1.320 raeburn 16634: }
16635: if ($gotlock eq 'ok') {
1.434 raeburn 16636: my %currids = &Apache::lonnet::dump_dom($dbname,$domain);
1.320 raeburn 16637: if ($currids{'lock'}) {
16638: delete($currids{'lock'});
16639: if (keys(%currids)) {
16640: my @curr = sort { $a <=> $b } keys(%currids);
16641: if ($curr[-1] =~ /^\d+$/) {
16642: $id = 1 + $curr[-1];
16643: }
16644: } else {
16645: $id = 1;
16646: }
16647: if ($id) {
1.434 raeburn 16648: unless (&Apache::lonnet::newput_dom($dbname,{ $id => $consumer },$domain) eq 'ok') {
1.320 raeburn 16649: $error = 'nostore';
16650: }
16651: } else {
16652: $error = 'nonumber';
16653: }
16654: }
1.434 raeburn 16655: my $dellockoutcome = &Apache::lonnet::del_dom($dbname,['lock'],$domain);
1.320 raeburn 16656: } else {
16657: $error = 'nolock';
16658: }
16659: return ($id,$error);
16660: }
16661:
1.3 raeburn 16662: sub modify_autoenroll {
1.205 raeburn 16663: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 16664: my ($resulttext,%changes);
16665: my %currautoenroll;
16666: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
16667: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
16668: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
16669: }
16670: }
16671: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
16672: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 16673: sender => 'Sender for notification messages',
1.274 raeburn 16674: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.399 raeburn 16675: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 16676: my @offon = ('off','on');
1.17 raeburn 16677: my $sender_uname = $env{'form.sender_uname'};
16678: my $sender_domain = $env{'form.sender_domain'};
16679: if ($sender_domain eq '') {
16680: $sender_uname = '';
16681: } elsif ($sender_uname eq '') {
16682: $sender_domain = '';
16683: }
1.129 raeburn 16684: my $coowners = $env{'form.autoassign_coowners'};
1.399 raeburn 16685: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
16686: $autofailsafe =~ s{^\s+|\s+$}{}g;
16687: if ($autofailsafe =~ /\D/) {
16688: undef($autofailsafe);
16689: }
1.274 raeburn 16690: my $failsafe = $env{'form.autoenroll_failsafe'};
1.399 raeburn 16691: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
16692: $failsafe = 'off';
1.400 raeburn 16693: undef($autofailsafe);
1.274 raeburn 16694: }
1.1 raeburn 16695: my %autoenrollhash = (
1.129 raeburn 16696: autoenroll => { 'run' => $env{'form.autoenroll_run'},
16697: 'sender_uname' => $sender_uname,
16698: 'sender_domain' => $sender_domain,
16699: 'co-owners' => $coowners,
1.399 raeburn 16700: 'autofailsafe' => $autofailsafe,
1.400 raeburn 16701: 'failsafe' => $failsafe,
1.1 raeburn 16702: }
16703: );
1.4 raeburn 16704: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
16705: $dom);
1.1 raeburn 16706: if ($putresult eq 'ok') {
16707: if (exists($currautoenroll{'run'})) {
16708: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
16709: $changes{'run'} = 1;
16710: }
16711: } elsif ($autorun) {
16712: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 16713: $changes{'run'} = 1;
1.1 raeburn 16714: }
16715: }
1.17 raeburn 16716: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 16717: $changes{'sender'} = 1;
16718: }
1.17 raeburn 16719: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 16720: $changes{'sender'} = 1;
16721: }
1.129 raeburn 16722: if ($currautoenroll{'co-owners'} ne '') {
16723: if ($currautoenroll{'co-owners'} ne $coowners) {
16724: $changes{'coowners'} = 1;
16725: }
16726: } elsif ($coowners) {
16727: $changes{'coowners'} = 1;
1.274 raeburn 16728: }
1.399 raeburn 16729: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.274 raeburn 16730: $changes{'autofailsafe'} = 1;
16731: }
1.399 raeburn 16732: if ($currautoenroll{'failsafe'} ne $failsafe) {
16733: $changes{'failsafe'} = 1;
16734: }
1.1 raeburn 16735: if (keys(%changes) > 0) {
16736: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 16737: if ($changes{'run'}) {
1.1 raeburn 16738: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
16739: }
16740: if ($changes{'sender'}) {
1.17 raeburn 16741: if ($sender_uname eq '' || $sender_domain eq '') {
16742: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
16743: } else {
16744: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
16745: }
1.1 raeburn 16746: }
1.129 raeburn 16747: if ($changes{'coowners'}) {
16748: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
16749: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 16750: if (ref($lastactref) eq 'HASH') {
16751: $lastactref->{'domainconfig'} = 1;
16752: }
1.129 raeburn 16753: }
1.274 raeburn 16754: if ($changes{'autofailsafe'}) {
1.399 raeburn 16755: if ($autofailsafe ne '') {
16756: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.274 raeburn 16757: } else {
1.399 raeburn 16758: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.274 raeburn 16759: }
1.399 raeburn 16760: }
16761: if ($changes{'failsafe'}) {
16762: if ($failsafe eq 'off') {
16763: unless ($changes{'autofailsafe'}) {
16764: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
16765: }
16766: } elsif ($failsafe eq 'zero') {
16767: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
16768: } else {
16769: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
16770: }
16771: }
16772: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.274 raeburn 16773: &Apache::lonnet::get_domain_defaults($dom,1);
16774: if (ref($lastactref) eq 'HASH') {
16775: $lastactref->{'domdefaults'} = 1;
16776: }
16777: }
1.1 raeburn 16778: $resulttext .= '</ul>';
16779: } else {
16780: $resulttext = &mt('No changes made to auto-enrollment settings');
16781: }
16782: } else {
1.11 albertel 16783: $resulttext = '<span class="LC_error">'.
16784: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16785: }
1.3 raeburn 16786: return $resulttext;
1.1 raeburn 16787: }
16788:
16789: sub modify_autoupdate {
1.3 raeburn 16790: my ($dom,%domconfig) = @_;
1.1 raeburn 16791: my ($resulttext,%currautoupdate,%fields,%changes);
16792: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
16793: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
16794: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
16795: }
16796: }
16797: my @offon = ('off','on');
16798: my %title = &Apache::lonlocal::texthash (
1.385 raeburn 16799: run => 'Auto-update:',
16800: classlists => 'Updates to user information in classlists?',
16801: unexpired => 'Skip updates for users without active or future roles?',
16802: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 16803: );
1.44 raeburn 16804: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 16805: my %fieldtitles = &Apache::lonlocal::texthash (
16806: id => 'Student/Employee ID',
1.20 raeburn 16807: permanentemail => 'E-mail address',
1.1 raeburn 16808: lastname => 'Last Name',
16809: firstname => 'First Name',
16810: middlename => 'Middle Name',
1.132 raeburn 16811: generation => 'Generation',
1.1 raeburn 16812: );
1.142 raeburn 16813: $othertitle = &mt('All users');
1.1 raeburn 16814: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 16815: $othertitle = &mt('Other users');
1.1 raeburn 16816: }
16817: foreach my $key (keys(%env)) {
16818: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 16819: my ($usertype,$item) = ($1,$2);
16820: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
16821: if ($usertype eq 'default') {
16822: push(@{$fields{$1}},$2);
16823: } elsif (ref($types) eq 'ARRAY') {
16824: if (grep(/^\Q$usertype\E$/,@{$types})) {
16825: push(@{$fields{$1}},$2);
16826: }
16827: }
16828: }
1.1 raeburn 16829: }
16830: }
1.131 raeburn 16831: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
16832: @lockablenames = sort(@lockablenames);
16833: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
16834: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16835: if (@changed) {
16836: $changes{'lockablenames'} = 1;
16837: }
16838: } else {
16839: if (@lockablenames) {
16840: $changes{'lockablenames'} = 1;
16841: }
16842: }
1.1 raeburn 16843: my %updatehash = (
16844: autoupdate => { run => $env{'form.autoupdate_run'},
16845: classlists => $env{'form.classlists'},
1.385 raeburn 16846: unexpired => $env{'form.unexpired'},
1.1 raeburn 16847: fields => {%fields},
1.131 raeburn 16848: lockablenames => \@lockablenames,
1.1 raeburn 16849: }
16850: );
1.385 raeburn 16851: my $lastactivedays;
16852: if ($env{'form.lastactive'}) {
16853: $lastactivedays = $env{'form.lastactivedays'};
16854: $lastactivedays =~ s/^\s+|\s+$//g;
16855: unless ($lastactivedays =~ /^\d+$/) {
16856: undef($lastactivedays);
16857: $env{'form.lastactive'} = 0;
16858: }
16859: }
16860: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 16861: foreach my $key (keys(%currautoupdate)) {
1.385 raeburn 16862: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 16863: if (exists($updatehash{autoupdate}{$key})) {
16864: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
16865: $changes{$key} = 1;
16866: }
16867: }
16868: } elsif ($key eq 'fields') {
16869: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 16870: foreach my $item (@{$types},'default') {
1.1 raeburn 16871: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
16872: my $change = 0;
16873: foreach my $type (@{$currautoupdate{$key}{$item}}) {
16874: if (!exists($fields{$item})) {
16875: $change = 1;
1.132 raeburn 16876: last;
1.1 raeburn 16877: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 16878: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 16879: $change = 1;
1.132 raeburn 16880: last;
1.1 raeburn 16881: }
16882: }
16883: }
16884: if ($change) {
16885: push(@{$changes{$key}},$item);
16886: }
1.26 raeburn 16887: }
1.1 raeburn 16888: }
16889: }
1.131 raeburn 16890: } elsif ($key eq 'lockablenames') {
16891: if (ref($currautoupdate{$key}) eq 'ARRAY') {
16892: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16893: if (@changed) {
16894: $changes{'lockablenames'} = 1;
16895: }
16896: } else {
16897: if (@lockablenames) {
16898: $changes{'lockablenames'} = 1;
16899: }
16900: }
16901: }
16902: }
16903: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
16904: if (@lockablenames) {
16905: $changes{'lockablenames'} = 1;
1.1 raeburn 16906: }
16907: }
1.385 raeburn 16908: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
16909: if ($updatehash{'autoupdate'}{'unexpired'}) {
16910: $changes{'unexpired'} = 1;
16911: }
16912: }
16913: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
16914: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
16915: $changes{'lastactive'} = 1;
16916: }
16917: }
1.26 raeburn 16918: foreach my $item (@{$types},'default') {
16919: if (defined($fields{$item})) {
16920: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 16921: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
16922: my $change = 0;
16923: if (ref($fields{$item}) eq 'ARRAY') {
16924: foreach my $type (@{$fields{$item}}) {
16925: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
16926: $change = 1;
16927: last;
16928: }
16929: }
16930: }
16931: if ($change) {
16932: push(@{$changes{'fields'}},$item);
16933: }
16934: } else {
1.26 raeburn 16935: push(@{$changes{'fields'}},$item);
16936: }
16937: } else {
16938: push(@{$changes{'fields'}},$item);
1.1 raeburn 16939: }
16940: }
16941: }
16942: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
16943: $dom);
16944: if ($putresult eq 'ok') {
16945: if (keys(%changes) > 0) {
16946: $resulttext = &mt('Changes made:').'<ul>';
16947: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 16948: if ($key eq 'lockablenames') {
16949: $resulttext .= '<li>';
16950: if (@lockablenames) {
16951: $usertypes->{'default'} = $othertitle;
16952: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
16953: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
16954: } else {
16955: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
16956: }
16957: $resulttext .= '</li>';
16958: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 16959: foreach my $item (@{$changes{$key}}) {
16960: my @newvalues;
16961: foreach my $type (@{$fields{$item}}) {
16962: push(@newvalues,$fieldtitles{$type});
16963: }
1.3 raeburn 16964: my $newvaluestr;
16965: if (@newvalues > 0) {
16966: $newvaluestr = join(', ',@newvalues);
16967: } else {
16968: $newvaluestr = &mt('none');
1.6 raeburn 16969: }
1.1 raeburn 16970: if ($item eq 'default') {
1.26 raeburn 16971: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 16972: } else {
1.26 raeburn 16973: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 16974: }
16975: }
16976: } else {
16977: my $newvalue;
16978: if ($key eq 'run') {
16979: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.385 raeburn 16980: } elsif ($key eq 'lastactive') {
16981: $newvalue = $offon[$env{'form.lastactive'}];
16982: unless ($lastactivedays eq '') {
16983: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
16984: }
1.1 raeburn 16985: } else {
16986: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 16987: }
1.1 raeburn 16988: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
16989: }
16990: }
16991: $resulttext .= '</ul>';
16992: } else {
1.3 raeburn 16993: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 16994: }
16995: } else {
1.11 albertel 16996: $resulttext = '<span class="LC_error">'.
16997: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16998: }
1.3 raeburn 16999: return $resulttext;
1.1 raeburn 17000: }
17001:
1.125 raeburn 17002: sub modify_autocreate {
17003: my ($dom,%domconfig) = @_;
17004: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
17005: if (ref($domconfig{'autocreate'}) eq 'HASH') {
17006: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
17007: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
17008: }
17009: }
17010: my %title= ( xml => 'Auto-creation of courses in XML course description files',
17011: req => 'Auto-creation of validated requests for official courses',
17012: xmldc => 'Identity of course creator of courses from XML files',
17013: );
17014: my @types = ('xml','req');
17015: foreach my $item (@types) {
17016: $newvals{$item} = $env{'form.autocreate_'.$item};
17017: $newvals{$item} =~ s/\D//g;
17018: $newvals{$item} = 0 if ($newvals{$item} eq '');
17019: }
17020: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 17021: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 17022: unless (exists($domcoords{$newvals{'xmldc'}})) {
17023: $newvals{'xmldc'} = '';
17024: }
17025: %autocreatehash = (
17026: autocreate => { xml => $newvals{'xml'},
17027: req => $newvals{'req'},
17028: }
17029: );
17030: if ($newvals{'xmldc'} ne '') {
17031: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
17032: }
17033: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
17034: $dom);
17035: if ($putresult eq 'ok') {
17036: my @items = @types;
17037: if ($newvals{'xml'}) {
17038: push(@items,'xmldc');
17039: }
17040: foreach my $item (@items) {
17041: if (exists($currautocreate{$item})) {
17042: if ($currautocreate{$item} ne $newvals{$item}) {
17043: $changes{$item} = 1;
17044: }
17045: } elsif ($newvals{$item}) {
17046: $changes{$item} = 1;
17047: }
17048: }
17049: if (keys(%changes) > 0) {
17050: my @offon = ('off','on');
17051: $resulttext = &mt('Changes made:').'<ul>';
17052: foreach my $item (@types) {
17053: if ($changes{$item}) {
17054: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 17055: $resulttext .= '<li>'.
17056: &mt("$title{$item} set to [_1]$newtxt [_2]",
17057: '<b>','</b>').
17058: '</li>';
1.125 raeburn 17059: }
17060: }
17061: if ($changes{'xmldc'}) {
17062: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
17063: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 17064: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 17065: }
17066: $resulttext .= '</ul>';
17067: } else {
17068: $resulttext = &mt('No changes made to auto-creation settings');
17069: }
17070: } else {
17071: $resulttext = '<span class="LC_error">'.
17072: &mt('An error occurred: [_1]',$putresult).'</span>';
17073: }
17074: return $resulttext;
17075: }
17076:
1.23 raeburn 17077: sub modify_directorysrch {
1.295 raeburn 17078: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 17079: my ($resulttext,%changes);
17080: my %currdirsrch;
17081: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
17082: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
17083: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
17084: }
17085: }
1.277 raeburn 17086: my %title = ( available => 'Institutional directory search available',
17087: localonly => 'Other domains can search institution',
17088: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 17089: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 17090: searchby => 'Search types',
17091: searchtypes => 'Search latitude');
17092: my @offon = ('off','on');
1.24 raeburn 17093: my @otherdoms = ('Yes','No');
1.23 raeburn 17094:
1.25 raeburn 17095: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 17096: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
17097: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
17098:
1.44 raeburn 17099: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 17100: if (keys(%{$usertypes}) == 0) {
17101: @cansearch = ('default');
17102: } else {
17103: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
17104: foreach my $type (@{$currdirsrch{'cansearch'}}) {
17105: if (!grep(/^\Q$type\E$/,@cansearch)) {
17106: push(@{$changes{'cansearch'}},$type);
17107: }
1.23 raeburn 17108: }
1.26 raeburn 17109: foreach my $type (@cansearch) {
17110: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
17111: push(@{$changes{'cansearch'}},$type);
17112: }
1.23 raeburn 17113: }
1.26 raeburn 17114: } else {
17115: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 17116: }
17117: }
17118:
17119: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
17120: foreach my $by (@{$currdirsrch{'searchby'}}) {
17121: if (!grep(/^\Q$by\E$/,@searchby)) {
17122: push(@{$changes{'searchby'}},$by);
17123: }
17124: }
17125: foreach my $by (@searchby) {
17126: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
17127: push(@{$changes{'searchby'}},$by);
17128: }
17129: }
17130: } else {
17131: push(@{$changes{'searchby'}},@searchby);
17132: }
1.25 raeburn 17133:
17134: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
17135: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
17136: if (!grep(/^\Q$type\E$/,@searchtypes)) {
17137: push(@{$changes{'searchtypes'}},$type);
17138: }
17139: }
17140: foreach my $type (@searchtypes) {
17141: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
17142: push(@{$changes{'searchtypes'}},$type);
17143: }
17144: }
17145: } else {
17146: if (exists($currdirsrch{'searchtypes'})) {
17147: foreach my $type (@searchtypes) {
17148: if ($type ne $currdirsrch{'searchtypes'}) {
17149: push(@{$changes{'searchtypes'}},$type);
17150: }
17151: }
17152: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
17153: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
17154: }
17155: } else {
17156: push(@{$changes{'searchtypes'}},@searchtypes);
17157: }
17158: }
17159:
1.23 raeburn 17160: my %dirsrch_hash = (
17161: directorysrch => { available => $env{'form.dirsrch_available'},
17162: cansearch => \@cansearch,
1.277 raeburn 17163: localonly => $env{'form.dirsrch_instlocalonly'},
17164: lclocalonly => $env{'form.dirsrch_domlocalonly'},
17165: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 17166: searchby => \@searchby,
1.25 raeburn 17167: searchtypes => \@searchtypes,
1.23 raeburn 17168: }
17169: );
17170: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
17171: $dom);
17172: if ($putresult eq 'ok') {
17173: if (exists($currdirsrch{'available'})) {
17174: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
17175: $changes{'available'} = 1;
17176: }
17177: } else {
17178: if ($env{'form.dirsrch_available'} eq '1') {
17179: $changes{'available'} = 1;
17180: }
17181: }
1.277 raeburn 17182: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 17183: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
17184: $changes{'lcavailable'} = 1;
17185: }
1.277 raeburn 17186: } else {
17187: if ($env{'form.dirsrch_lcavailable'} eq '1') {
17188: $changes{'lcavailable'} = 1;
17189: }
17190: }
1.24 raeburn 17191: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 17192: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
17193: $changes{'localonly'} = 1;
17194: }
1.24 raeburn 17195: } else {
1.277 raeburn 17196: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 17197: $changes{'localonly'} = 1;
17198: }
17199: }
1.277 raeburn 17200: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 17201: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
17202: $changes{'lclocalonly'} = 1;
17203: }
1.277 raeburn 17204: } else {
17205: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
17206: $changes{'lclocalonly'} = 1;
17207: }
17208: }
1.23 raeburn 17209: if (keys(%changes) > 0) {
17210: $resulttext = &mt('Changes made:').'<ul>';
17211: if ($changes{'available'}) {
17212: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
17213: }
1.277 raeburn 17214: if ($changes{'lcavailable'}) {
17215: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
17216: }
1.24 raeburn 17217: if ($changes{'localonly'}) {
1.277 raeburn 17218: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 17219: }
1.277 raeburn 17220: if ($changes{'lclocalonly'}) {
17221: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 17222: }
1.23 raeburn 17223: if (ref($changes{'cansearch'}) eq 'ARRAY') {
17224: my $chgtext;
1.26 raeburn 17225: if (ref($usertypes) eq 'HASH') {
17226: if (keys(%{$usertypes}) > 0) {
17227: foreach my $type (@{$types}) {
17228: if (grep(/^\Q$type\E$/,@cansearch)) {
17229: $chgtext .= $usertypes->{$type}.'; ';
17230: }
17231: }
17232: if (grep(/^default$/,@cansearch)) {
17233: $chgtext .= $othertitle;
17234: } else {
17235: $chgtext =~ s/\; $//;
17236: }
1.210 raeburn 17237: $resulttext .=
1.178 raeburn 17238: '<li>'.
17239: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
17240: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
17241: '</li>';
1.23 raeburn 17242: }
17243: }
17244: }
17245: if (ref($changes{'searchby'}) eq 'ARRAY') {
17246: my ($searchtitles,$titleorder) = &sorted_searchtitles();
17247: my $chgtext;
17248: foreach my $type (@{$titleorder}) {
17249: if (grep(/^\Q$type\E$/,@searchby)) {
17250: if (defined($searchtitles->{$type})) {
17251: $chgtext .= $searchtitles->{$type}.'; ';
17252: }
17253: }
17254: }
17255: $chgtext =~ s/\; $//;
17256: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
17257: }
1.25 raeburn 17258: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
17259: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
17260: my $chgtext;
17261: foreach my $type (@{$srchtypeorder}) {
17262: if (grep(/^\Q$type\E$/,@searchtypes)) {
17263: if (defined($srchtypes_desc->{$type})) {
17264: $chgtext .= $srchtypes_desc->{$type}.'; ';
17265: }
17266: }
17267: }
17268: $chgtext =~ s/\; $//;
1.178 raeburn 17269: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 17270: }
17271: $resulttext .= '</ul>';
1.295 raeburn 17272: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
17273: if (ref($lastactref) eq 'HASH') {
17274: $lastactref->{'directorysrch'} = 1;
17275: }
1.23 raeburn 17276: } else {
1.277 raeburn 17277: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 17278: }
17279: } else {
17280: $resulttext = '<span class="LC_error">'.
1.27 raeburn 17281: &mt('An error occurred: [_1]',$putresult).'</span>';
17282: }
17283: return $resulttext;
17284: }
17285:
1.28 raeburn 17286: sub modify_contacts {
1.205 raeburn 17287: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 17288: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
17289: if (ref($domconfig{'contacts'}) eq 'HASH') {
17290: foreach my $key (keys(%{$domconfig{'contacts'}})) {
17291: $currsetting{$key} = $domconfig{'contacts'}{$key};
17292: }
17293: }
1.286 raeburn 17294: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 17295: my @contacts = ('supportemail','adminemail');
1.286 raeburn 17296: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350 raeburn 17297: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340 raeburn 17298: my @toggles = ('reporterrors','reportupdates','reportstatus');
17299: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 17300: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 17301: foreach my $type (@mailings) {
17302: @{$newsetting{$type}} =
17303: &Apache::loncommon::get_env_multiple('form.'.$type);
17304: foreach my $item (@contacts) {
17305: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
17306: $contacts_hash{contacts}{$type}{$item} = 1;
17307: } else {
17308: $contacts_hash{contacts}{$type}{$item} = 0;
17309: }
1.289 raeburn 17310: }
1.28 raeburn 17311: $others{$type} = $env{'form.'.$type.'_others'};
17312: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 17313: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17314: $bcc{$type} = $env{'form.'.$type.'_bcc'};
17315: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 17316: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
17317: $includestr{$type} = $env{'form.'.$type.'_includestr'};
17318: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
17319: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17320: }
1.134 raeburn 17321: }
1.28 raeburn 17322: }
17323: foreach my $item (@contacts) {
17324: $to{$item} = $env{'form.'.$item};
17325: $contacts_hash{'contacts'}{$item} = $to{$item};
17326: }
1.203 raeburn 17327: foreach my $item (@toggles) {
17328: if ($env{'form.'.$item} =~ /^(0|1)$/) {
17329: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
17330: }
17331: }
1.340 raeburn 17332: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
17333: foreach my $item (@lonstatus) {
17334: if ($item eq 'excluded') {
17335: my (%serverhomes,@excluded);
17336: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
17337: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
17338: if (@possexcluded) {
17339: foreach my $id (sort(@possexcluded)) {
17340: if ($serverhomes{$id}) {
17341: push(@excluded,$id);
17342: }
17343: }
17344: }
17345: if (@excluded) {
17346: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
17347: }
17348: } elsif ($item eq 'weights') {
1.377 raeburn 17349: foreach my $type ('E','W','N','U') {
1.340 raeburn 17350: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
17351: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
17352: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
17353: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
17354: $env{'form.error'.$item.'_'.$type};
17355: }
17356: }
17357: }
17358: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
17359: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
17360: if ($env{'form.error'.$item} =~ /^\d+$/) {
17361: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
17362: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
17363: }
17364: }
17365: }
17366: }
1.286 raeburn 17367: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
17368: foreach my $field (@{$fields}) {
17369: if (ref($possoptions->{$field}) eq 'ARRAY') {
17370: my $value = $env{'form.helpform_'.$field};
17371: $value =~ s/^\s+|\s+$//g;
17372: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 17373: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 17374: if ($field eq 'screenshot') {
17375: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
17376: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 17377: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 17378: }
17379: }
17380: }
17381: }
17382: }
17383: }
1.315 raeburn 17384: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17385: my (@statuses,%usertypeshash,@overrides);
17386: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
17387: @statuses = @{$types};
17388: if (ref($usertypes) eq 'HASH') {
17389: %usertypeshash = %{$usertypes};
17390: }
17391: }
17392: if (@statuses) {
17393: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
17394: foreach my $type (@possoverrides) {
17395: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
17396: push(@overrides,$type);
17397: }
17398: }
17399: if (@overrides) {
17400: foreach my $type (@overrides) {
17401: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
17402: foreach my $item (@contacts) {
17403: if (grep(/^\Q$item\E$/,@standard)) {
17404: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
17405: $newsetting{'override_'.$type}{$item} = 1;
17406: } else {
17407: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
17408: $newsetting{'override_'.$type}{$item} = 0;
17409: }
17410: }
17411: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
17412: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17413: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
17414: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17415: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
17416: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
17417: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
17418: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17419: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
17420: }
1.425 raeburn 17421: }
1.315 raeburn 17422: }
17423: }
1.28 raeburn 17424: if (keys(%currsetting) > 0) {
17425: foreach my $item (@contacts) {
17426: if ($to{$item} ne $currsetting{$item}) {
17427: $changes{$item} = 1;
17428: }
17429: }
17430: foreach my $type (@mailings) {
17431: foreach my $item (@contacts) {
17432: if (ref($currsetting{$type}) eq 'HASH') {
17433: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
17434: push(@{$changes{$type}},$item);
17435: }
17436: } else {
17437: push(@{$changes{$type}},@{$newsetting{$type}});
17438: }
17439: }
17440: if ($others{$type} ne $currsetting{$type}{'others'}) {
17441: push(@{$changes{$type}},'others');
17442: }
1.289 raeburn 17443: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17444: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
17445: push(@{$changes{$type}},'bcc');
17446: }
1.286 raeburn 17447: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
17448: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
17449: push(@{$changes{$type}},'include');
17450: }
17451: }
17452: }
17453: if (ref($fields) eq 'ARRAY') {
17454: if (ref($currsetting{'helpform'}) eq 'HASH') {
17455: foreach my $field (@{$fields}) {
17456: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
17457: push(@{$changes{'helpform'}},$field);
17458: }
17459: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17460: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
17461: push(@{$changes{'helpform'}},'maxsize');
17462: }
17463: }
17464: }
17465: } else {
17466: foreach my $field (@{$fields}) {
17467: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17468: push(@{$changes{'helpform'}},$field);
17469: }
17470: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17471: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17472: push(@{$changes{'helpform'}},'maxsize');
17473: }
17474: }
17475: }
1.134 raeburn 17476: }
1.28 raeburn 17477: }
1.315 raeburn 17478: if (@statuses) {
1.425 raeburn 17479: if (ref($currsetting{'overrides'}) eq 'HASH') {
1.315 raeburn 17480: foreach my $key (keys(%{$currsetting{'overrides'}})) {
17481: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
17482: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
17483: foreach my $item (@contacts,'bcc','others','include') {
1.425 raeburn 17484: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
1.315 raeburn 17485: push(@{$changes{'overrides'}},$key);
17486: last;
17487: }
17488: }
17489: } else {
17490: push(@{$changes{'overrides'}},$key);
17491: }
17492: }
17493: }
17494: foreach my $key (@overrides) {
17495: unless (exists($currsetting{'overrides'}{$key})) {
17496: push(@{$changes{'overrides'}},$key);
17497: }
17498: }
17499: } else {
17500: foreach my $key (@overrides) {
1.425 raeburn 17501: push(@{$changes{'overrides'}},$key);
1.315 raeburn 17502: }
17503: }
17504: }
1.340 raeburn 17505: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
17506: foreach my $key ('excluded','weights','threshold','sysmail') {
17507: if ($key eq 'excluded') {
17508: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17509: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
17510: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17511: (@{$currsetting{'lonstatus'}{$key}})) {
17512: my @diffs =
17513: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
17514: $currsetting{'lonstatus'}{$key});
17515: if (@diffs) {
17516: push(@{$changes{'lonstatus'}},$key);
17517: }
17518: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
17519: push(@{$changes{'lonstatus'}},$key);
17520: }
17521: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17522: (@{$currsetting{'lonstatus'}{$key}})) {
17523: push(@{$changes{'lonstatus'}},$key);
17524: }
17525: } elsif ($key eq 'weights') {
17526: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17527: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
17528: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17529: foreach my $type ('E','W','N','U') {
1.340 raeburn 17530: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
17531: $currsetting{'lonstatus'}{$key}{$type}) {
17532: push(@{$changes{'lonstatus'}},$key);
17533: last;
17534: }
17535: }
17536: } else {
1.341 raeburn 17537: foreach my $type ('E','W','N','U') {
1.340 raeburn 17538: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
17539: push(@{$changes{'lonstatus'}},$key);
17540: last;
17541: }
17542: }
17543: }
17544: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17545: foreach my $type ('E','W','N','U') {
1.340 raeburn 17546: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
17547: push(@{$changes{'lonstatus'}},$key);
17548: last;
17549: }
17550: }
17551: }
17552: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
17553: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17554: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17555: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
17556: push(@{$changes{'lonstatus'}},$key);
17557: }
17558: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
17559: push(@{$changes{'lonstatus'}},$key);
17560: }
17561: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17562: push(@{$changes{'lonstatus'}},$key);
17563: }
17564: }
17565: }
17566: } else {
17567: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17568: foreach my $key ('excluded','weights','threshold','sysmail') {
17569: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17570: push(@{$changes{'lonstatus'}},$key);
17571: }
17572: }
17573: }
17574: }
1.28 raeburn 17575: } else {
17576: my %default;
17577: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
17578: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
17579: $default{'errormail'} = 'adminemail';
17580: $default{'packagesmail'} = 'adminemail';
17581: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 17582: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 17583: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 17584: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 17585: $default{'updatesmail'} = 'adminemail';
1.350 raeburn 17586: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 17587: foreach my $item (@contacts) {
17588: if ($to{$item} ne $default{$item}) {
1.286 raeburn 17589: $changes{$item} = 1;
1.203 raeburn 17590: }
1.28 raeburn 17591: }
17592: foreach my $type (@mailings) {
17593: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
17594: push(@{$changes{$type}},@{$newsetting{$type}});
17595: }
17596: if ($others{$type} ne '') {
17597: push(@{$changes{$type}},'others');
1.134 raeburn 17598: }
1.286 raeburn 17599: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17600: if ($bcc{$type} ne '') {
17601: push(@{$changes{$type}},'bcc');
17602: }
1.286 raeburn 17603: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
17604: push(@{$changes{$type}},'include');
17605: }
1.134 raeburn 17606: }
1.28 raeburn 17607: }
1.286 raeburn 17608: if (ref($fields) eq 'ARRAY') {
17609: foreach my $field (@{$fields}) {
17610: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17611: push(@{$changes{'helpform'}},$field);
17612: }
17613: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17614: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17615: push(@{$changes{'helpform'}},'maxsize');
17616: }
17617: }
17618: }
1.289 raeburn 17619: }
1.340 raeburn 17620: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17621: foreach my $key ('excluded','weights','threshold','sysmail') {
17622: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17623: push(@{$changes{'lonstatus'}},$key);
17624: }
17625: }
17626: }
1.28 raeburn 17627: }
1.203 raeburn 17628: foreach my $item (@toggles) {
17629: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
17630: $changes{$item} = 1;
17631: } elsif ((!$env{'form.'.$item}) &&
17632: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
17633: $changes{$item} = 1;
17634: }
17635: }
1.28 raeburn 17636: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
17637: $dom);
17638: if ($putresult eq 'ok') {
17639: if (keys(%changes) > 0) {
1.205 raeburn 17640: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 17641: if (ref($lastactref) eq 'HASH') {
17642: $lastactref->{'domainconfig'} = 1;
17643: }
1.28 raeburn 17644: my ($titles,$short_titles) = &contact_titles();
17645: $resulttext = &mt('Changes made:').'<ul>';
17646: foreach my $item (@contacts) {
17647: if ($changes{$item}) {
17648: $resulttext .= '<li>'.$titles->{$item}.
17649: &mt(' set to: ').
17650: '<span class="LC_cusr_emph">'.
17651: $to{$item}.'</span></li>';
17652: }
17653: }
17654: foreach my $type (@mailings) {
17655: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 17656: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 17657: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 17658: } else {
17659: $resulttext .= '<li>'.$titles->{$type}.': ';
17660: }
1.28 raeburn 17661: my @text;
17662: foreach my $item (@{$newsetting{$type}}) {
17663: push(@text,$short_titles->{$item});
17664: }
17665: if ($others{$type} ne '') {
17666: push(@text,$others{$type});
17667: }
1.286 raeburn 17668: if (@text) {
17669: $resulttext .= '<span class="LC_cusr_emph">'.
17670: join(', ',@text).'</span>';
17671: }
17672: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17673: if ($bcc{$type} ne '') {
1.286 raeburn 17674: my $bcctext;
17675: if (@text) {
1.289 raeburn 17676: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 17677: } else {
17678: $bcctext = '(Bcc)';
17679: }
17680: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
17681: } elsif (!@text) {
17682: $resulttext .= &mt('No one');
1.425 raeburn 17683: }
1.289 raeburn 17684: if ($includestr{$type} ne '') {
1.286 raeburn 17685: if ($includeloc{$type} eq 'b') {
17686: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
17687: } elsif ($includeloc{$type} eq 's') {
17688: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
17689: }
1.134 raeburn 17690: }
1.286 raeburn 17691: } elsif (!@text) {
17692: $resulttext .= &mt('No recipients');
1.134 raeburn 17693: }
17694: $resulttext .= '</li>';
1.28 raeburn 17695: }
17696: }
1.315 raeburn 17697: if (ref($changes{'overrides'}) eq 'ARRAY') {
17698: my @deletions;
17699: foreach my $type (@{$changes{'overrides'}}) {
17700: if ($usertypeshash{$type}) {
17701: if (grep(/^\Q$type\E/,@overrides)) {
17702: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
17703: $usertypeshash{$type}).'<ul><li>';
17704: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
17705: my @text;
17706: foreach my $item (@contacts) {
1.425 raeburn 17707: if ($newsetting{'override_'.$type}{$item}) {
1.315 raeburn 17708: push(@text,$short_titles->{$item});
17709: }
17710: }
17711: if ($newsetting{'override_'.$type}{'others'} ne '') {
17712: push(@text,$newsetting{'override_'.$type}{'others'});
17713: }
1.425 raeburn 17714:
1.315 raeburn 17715: if (@text) {
17716: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
17717: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
17718: }
17719: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
17720: my $bcctext;
17721: if (@text) {
17722: $bcctext = ' '.&mt('with Bcc to');
17723: } else {
17724: $bcctext = '(Bcc)';
17725: }
17726: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
17727: } elsif (!@text) {
17728: $resulttext .= &mt('Helpdesk e-mail sent to no one');
17729: }
17730: $resulttext .= '</li>';
17731: if ($newsetting{'override_'.$type}{'include'} ne '') {
17732: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
17733: if ($loc eq 'b') {
17734: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
17735: } elsif ($loc eq 's') {
17736: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
17737: }
17738: }
17739: }
17740: $resulttext .= '</li></ul></li>';
17741: } else {
17742: push(@deletions,$usertypeshash{$type});
17743: }
17744: }
17745: }
17746: if (@deletions) {
17747: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
17748: join(', ',@deletions)).'</li>';
17749: }
17750: }
1.203 raeburn 17751: my @offon = ('off','on');
1.340 raeburn 17752: my $corelink = &core_link_msu();
1.203 raeburn 17753: if ($changes{'reporterrors'}) {
17754: $resulttext .= '<li>'.
17755: &mt('E-mail error reports to [_1] set to "'.
17756: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 17757: $corelink).
1.203 raeburn 17758: '</li>';
17759: }
17760: if ($changes{'reportupdates'}) {
17761: $resulttext .= '<li>'.
17762: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
17763: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 17764: $corelink).
1.203 raeburn 17765: '</li>';
17766: }
1.340 raeburn 17767: if ($changes{'reportstatus'}) {
17768: $resulttext .= '<li>'.
17769: &mt('E-mail status if errors above threshold to [_1] set to "'.
17770: $offon[$env{'form.reportstatus'}].'".',
17771: $corelink).
17772: '</li>';
17773: }
17774: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
17775: $resulttext .= '<li>'.
17776: &mt('Nightly status check e-mail settings').':<ul>';
17777: my (%defval,%use_def,%shown);
17778: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
17779: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
17780: $defval{'weights'} =
1.341 raeburn 17781: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 17782: $defval{'excluded'} = &mt('None');
17783: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
17784: foreach my $item ('threshold','sysmail','weights','excluded') {
17785: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
17786: if (($item eq 'threshold') || ($item eq 'sysmail')) {
17787: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
17788: } elsif ($item eq 'weights') {
17789: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 17790: foreach my $type ('E','W','N','U') {
1.340 raeburn 17791: $shown{$item} .= $lonstatus_names->{$type}.'=';
17792: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
17793: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
17794: } else {
17795: $shown{$item} .= $lonstatus_defs->{$type};
17796: }
17797: $shown{$item} .= ', ';
17798: }
17799: $shown{$item} =~ s/, $//;
17800: } else {
17801: $shown{$item} = $defval{$item};
17802: }
17803: } elsif ($item eq 'excluded') {
17804: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
17805: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
17806: } else {
17807: $shown{$item} = $defval{$item};
17808: }
17809: }
17810: } else {
17811: $shown{$item} = $defval{$item};
17812: }
17813: }
17814: } else {
17815: foreach my $item ('threshold','weights','excluded','sysmail') {
17816: $shown{$item} = $defval{$item};
17817: }
17818: }
17819: foreach my $item ('threshold','weights','excluded','sysmail') {
17820: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
17821: $shown{$item}).'</li>';
17822: }
17823: $resulttext .= '</ul></li>';
17824: }
1.286 raeburn 17825: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
17826: my (@optional,@required,@unused,$maxsizechg);
17827: foreach my $field (@{$changes{'helpform'}}) {
17828: if ($field eq 'maxsize') {
17829: $maxsizechg = 1;
17830: next;
17831: }
17832: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 17833: push(@optional,$field);
1.286 raeburn 17834: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
17835: push(@unused,$field);
17836: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 17837: push(@required,$field);
1.286 raeburn 17838: }
17839: }
17840: if (@optional) {
17841: $resulttext .= '<li>'.
17842: &mt('Help form fields changed to "Optional": [_1].',
17843: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
17844: '</li>';
17845: }
17846: if (@required) {
17847: $resulttext .= '<li>'.
17848: &mt('Help form fields changed to "Required": [_1].',
17849: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
17850: '</li>';
17851: }
17852: if (@unused) {
17853: $resulttext .= '<li>'.
17854: &mt('Help form fields changed to "Not shown": [_1].',
17855: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
17856: '</li>';
17857: }
17858: if ($maxsizechg) {
17859: $resulttext .= '<li>'.
17860: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
17861: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
17862: '</li>';
17863: }
17864: }
1.28 raeburn 17865: $resulttext .= '</ul>';
17866: } else {
1.288 raeburn 17867: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 17868: }
17869: } else {
17870: $resulttext = '<span class="LC_error">'.
17871: &mt('An error occurred: [_1].',$putresult).'</span>';
17872: }
17873: return $resulttext;
17874: }
17875:
1.357 raeburn 17876: sub modify_privacy {
1.427 raeburn 17877: my ($dom,$lastactref,%domconfig) = @_;
1.357 raeburn 17878: my ($resulttext,%current,%changes);
17879: if (ref($domconfig{'privacy'}) eq 'HASH') {
17880: %current = %{$domconfig{'privacy'}};
17881: }
17882: my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
17883: my @items = ('domain','author','course','community');
17884: my %names = &Apache::lonlocal::texthash (
17885: domain => 'Assigned domain role(s)',
17886: author => 'Assigned co-author role(s)',
17887: course => 'Assigned course role(s)',
1.416 raeburn 17888: community => 'Assigned community role(s)',
1.357 raeburn 17889: );
17890: my %roles = &Apache::lonlocal::texthash (
17891: domain => 'Domain role',
17892: author => 'Co-author role',
17893: course => 'Course role',
17894: community => 'Community role',
17895: );
17896: my %titles = &Apache::lonlocal::texthash (
17897: approval => 'Approval for role in different domain',
17898: othdom => 'User information available in other domain',
17899: priv => 'Information viewable by privileged user in same domain',
17900: unpriv => 'Information viewable by unprivileged user in same domain',
17901: instdom => 'Other domain shares institution/provider',
17902: extdom => 'Other domain has different institution/provider',
17903: none => 'Not allowed',
17904: user => 'User authorizes',
17905: domain => 'Domain Coordinator authorizes',
17906: auto => 'Unrestricted',
1.418 raeburn 17907: notify => 'Notify when role needs authorization',
1.357 raeburn 17908: );
17909: my %fieldnames = &Apache::lonlocal::texthash (
17910: id => 'Student/Employee ID',
17911: permanentemail => 'E-mail address',
17912: lastname => 'Last Name',
17913: firstname => 'First Name',
17914: middlename => 'Middle Name',
17915: generation => 'Generation',
17916: );
17917: my ($othertitle,$usertypes,$types) =
17918: &Apache::loncommon::sorted_inst_types($dom);
17919: my (%by_ip,%by_location,@intdoms,@instdoms);
17920: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
17921:
17922: my %privacyhash = (
17923: 'approval' => {
17924: instdom => {},
17925: extdom => {},
17926: },
17927: 'othdom' => {},
17928: 'priv' => {},
17929: 'unpriv' => {},
17930: );
17931: foreach my $item (@items) {
17932: if (@instdoms > 1) {
1.416 raeburn 17933: if ($env{'form.privacy_approval_instdom_'.$item} =~ /^(none|user|domain|auto)$/) {
1.357 raeburn 17934: $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
17935: }
17936: if (ref($current{'approval'}) eq 'HASH') {
17937: if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
17938: unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
17939: $changes{'approval'} = 1;
17940: }
17941: }
17942: } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
17943: $changes{'approval'} = 1;
17944: }
17945: }
17946: if (keys(%by_location) > 0) {
17947: if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
17948: $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
17949: }
17950: if (ref($current{'approval'}) eq 'HASH') {
17951: if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
17952: unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
17953: $changes{'approval'} = 1;
17954: }
17955: }
17956: } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
17957: $changes{'approval'} = 1;
17958: }
17959: }
17960: foreach my $status ('priv','unpriv') {
17961: my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
17962: my @newvalues;
17963: foreach my $field (@possibles) {
17964: if (grep(/^\Q$field\E$/,@fields)) {
17965: $privacyhash{$status}{$item}{$field} = 1;
17966: push(@newvalues,$field);
17967: }
17968: }
17969: @newvalues = sort(@newvalues);
17970: if (ref($current{$status}) eq 'HASH') {
17971: if (ref($current{$status}{$item}) eq 'HASH') {
17972: my @currvalues = sort(keys(%{$current{$status}{$item}}));
17973: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
17974: if (@diffs > 0) {
17975: $changes{$status} = 1;
17976: }
17977: }
17978: } else {
17979: my @stdfields;
17980: foreach my $field (@fields) {
17981: if ($field eq 'id') {
17982: next if ($status eq 'unpriv');
17983: next if (($status eq 'priv') && ($item eq 'community'));
17984: }
17985: push(@stdfields,$field);
17986: }
17987: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
17988: if (@diffs > 0) {
17989: $changes{$status} = 1;
17990: }
17991: }
17992: }
17993: }
17994: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
17995: my @statuses;
17996: if (ref($types) eq 'ARRAY') {
17997: @statuses = @{$types};
17998: }
17999: foreach my $type (@statuses,'default') {
18000: my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
18001: my @newvalues;
18002: foreach my $field (sort(@possfields)) {
18003: if (grep(/^\Q$field\E$/,@fields)) {
18004: $privacyhash{'othdom'}{$type}{$field} = 1;
18005: push(@newvalues,$field);
18006: }
18007: }
18008: @newvalues = sort(@newvalues);
18009: if (ref($current{'othdom'}) eq 'HASH') {
18010: if (ref($current{'othdom'}{$type}) eq 'HASH') {
18011: my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
18012: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
18013: if (@diffs > 0) {
18014: $changes{'othdom'} = 1;
18015: }
18016: }
18017: } else {
18018: my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
18019: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
18020: if (@diffs > 0) {
18021: $changes{'othdom'} = 1;
18022: }
18023: }
18024: }
1.417 raeburn 18025: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
18026: my %notify;
18027: foreach my $possdc (&Apache::loncommon::get_env_multiple('form.privacy_notify')) {
18028: if (exists($domcoords{$possdc})) {
18029: $notify{$possdc} = 1;
18030: }
18031: }
18032: my $notify = join(',',sort(keys(%notify)));
18033: if ($current{'notify'} ne $notify) {
18034: $changes{'notify'} = 1;
18035: }
18036: $privacyhash{'notify'} = $notify;
1.357 raeburn 18037: }
18038: my %confighash = (
18039: privacy => \%privacyhash,
18040: );
18041: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
18042: if ($putresult eq 'ok') {
18043: if (keys(%changes) > 0) {
18044: $resulttext = &mt('Changes made: ').'<ul>';
1.417 raeburn 18045: foreach my $key ('approval','notify','othdom','priv','unpriv') {
1.357 raeburn 18046: if ($changes{$key}) {
18047: $resulttext .= '<li>'.$titles{$key}.':<ul>';
18048: if ($key eq 'approval') {
18049: if (keys(%{$privacyhash{$key}{instdom}})) {
18050: $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
18051: foreach my $item (@items) {
18052: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
18053: }
18054: $resulttext .= '</ul></li>';
18055: }
18056: if (keys(%{$privacyhash{$key}{extdom}})) {
18057: $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
18058: foreach my $item (@items) {
18059: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
18060: }
18061: $resulttext .= '</ul></li>';
18062: }
1.417 raeburn 18063: } elsif ($key eq 'notify') {
18064: if ($privacyhash{$key}) {
18065: foreach my $dc (split(/,/,$privacyhash{$key})) {
18066: my ($dcname,$dcdom) = split(/:/,$dc);
18067: $resulttext .= '<li>'.&Apache::loncommon::plainname($dcname,$dcdom).'</li>';
18068: }
18069: } else {
18070: $resulttext .= '<li>'.&mt('No DCs to notify').'</li>';
18071: }
1.357 raeburn 18072: } elsif ($key eq 'othdom') {
18073: my @statuses;
18074: if (ref($types) eq 'ARRAY') {
18075: @statuses = @{$types};
18076: }
18077: if (ref($privacyhash{$key}) eq 'HASH') {
18078: foreach my $status (@statuses,'default') {
18079: if ($status eq 'default') {
18080: $resulttext .= '<li>'.$othertitle.': ';
18081: } elsif (ref($usertypes) eq 'HASH') {
18082: $resulttext .= '<li>'.$usertypes->{$status}.': ';
18083: } else {
18084: next;
18085: }
18086: if (ref($privacyhash{$key}{$status}) eq 'HASH') {
18087: if (keys(%{$privacyhash{$key}{$status}})) {
18088: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
18089: } else {
18090: $resulttext .= &mt('none');
18091: }
18092: }
18093: $resulttext .= '</li>';
18094: }
18095: }
18096: } else {
18097: foreach my $item (@items) {
18098: if (ref($privacyhash{$key}{$item}) eq 'HASH') {
18099: $resulttext .= '<li>'.$names{$item}.': ';
18100: if (keys(%{$privacyhash{$key}{$item}})) {
18101: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
18102: } else {
18103: $resulttext .= &mt('none');
18104: }
18105: $resulttext .= '</li>';
18106: }
18107: }
18108: }
18109: $resulttext .= '</ul></li>';
18110: }
18111: }
1.421 raeburn 18112: $resulttext .= '</ul>';
1.427 raeburn 18113: if ($changes{'approval'}) {
18114: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
18115: delete($domdefaults{'userapprovals'});
18116: if (ref($privacyhash{'approval'}) eq 'HASH') {
18117: foreach my $domtype ('instdom','extdom') {
18118: if (ref($privacyhash{'approval'}{$domtype}) eq 'HASH') {
18119: foreach my $roletype ('domain','author','course','community') {
18120: if ($privacyhash{'approval'}{$domtype}{$roletype} eq 'user') {
18121: $domdefaults{'userapprovals'} = 1;
18122: last;
18123: }
18124: }
18125: }
18126: last if ($domdefaults{'userapprovals'});
18127: }
18128: }
18129: my $cachetime = 24*60*60;
18130: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18131: if (ref($lastactref) eq 'HASH') {
18132: $lastactref->{'domdefaults'} = 1;
18133: }
18134: }
1.357 raeburn 18135: } else {
18136: $resulttext = &mt('No changes made to user information settings');
18137: }
18138: } else {
18139: $resulttext = '<span class="LC_error">'.
18140: &mt('An error occurred: [_1]',$putresult).'</span>';
18141: }
18142: return $resulttext;
18143: }
18144:
1.354 raeburn 18145: sub modify_passwords {
18146: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 raeburn 18147: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
18148: $updatedefaults,$updateconf);
1.354 raeburn 18149: my $customfn = 'resetpw.html';
18150: if (ref($domconfig{'passwords'}) eq 'HASH') {
18151: %current = %{$domconfig{'passwords'}};
18152: }
18153: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
18154: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
18155: if (ref($types) eq 'ARRAY') {
18156: @oktypes = @{$types};
18157: }
18158: push(@oktypes,'default');
18159:
18160: my %titles = &Apache::lonlocal::texthash (
18161: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
18162: intauth_check => 'Check bcrypt cost if authenticated',
18163: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
18164: permanent => 'Permanent e-mail address',
18165: critical => 'Critical notification address',
18166: notify => 'Notification address',
18167: min => 'Minimum password length',
18168: max => 'Maximum password length',
18169: chars => 'Required characters',
18170: expire => 'Password expiration (days)',
1.356 raeburn 18171: numsaved => 'Number of previous passwords to save',
1.354 raeburn 18172: reset => 'Resetting Forgotten Password',
18173: intauth => 'Encryption of Stored Passwords (Internal Auth)',
18174: rules => 'Rules for LON-CAPA Passwords',
18175: crsownerchg => 'Course Owner Changing Student Passwords',
18176: username => 'Username',
18177: email => 'E-mail address',
18178: );
18179:
18180: #
18181: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
18182: #
18183: my (%curr_defaults,%save_defaults);
18184: if (ref($domconfig{'defaults'}) eq 'HASH') {
18185: foreach my $key (keys(%{$domconfig{'defaults'}})) {
18186: if ($key =~ /^intauth_(cost|check|switch)$/) {
18187: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
18188: } else {
18189: $save_defaults{$key} = $domconfig{'defaults'}{$key};
18190: }
18191: }
18192: }
18193: my %staticdefaults = (
18194: 'resetlink' => 2,
18195: 'resetcase' => \@oktypes,
18196: 'resetprelink' => 'both',
18197: 'resetemail' => ['critical','notify','permanent'],
18198: 'intauth_cost' => 10,
18199: 'intauth_check' => 0,
18200: 'intauth_switch' => 0,
18201: );
1.365 raeburn 18202: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354 raeburn 18203: foreach my $type (@oktypes) {
18204: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
18205: }
18206: my $linklife = $env{'form.passwords_link'};
18207: $linklife =~ s/^\s+|\s+$//g;
18208: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
18209: $newvalues{'resetlink'} = $linklife;
18210: if ($current{'resetlink'}) {
18211: if ($current{'resetlink'} ne $linklife) {
18212: $changes{'reset'} = 1;
18213: }
1.368 raeburn 18214: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18215: if ($staticdefaults{'resetlink'} ne $linklife) {
18216: $changes{'reset'} = 1;
18217: }
18218: }
18219: } elsif ($current{'resetlink'}) {
18220: $changes{'reset'} = 1;
18221: }
18222: my @casesens;
18223: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
18224: foreach my $case (sort(@posscase)) {
18225: if (grep(/^\Q$case\E$/,@oktypes)) {
18226: push(@casesens,$case);
18227: }
18228: }
18229: $newvalues{'resetcase'} = \@casesens;
18230: if (ref($current{'resetcase'}) eq 'ARRAY') {
18231: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
18232: if (@diffs > 0) {
18233: $changes{'reset'} = 1;
18234: }
1.368 raeburn 18235: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18236: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
18237: if (@diffs > 0) {
18238: $changes{'reset'} = 1;
18239: }
18240: }
18241: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
18242: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
18243: if (exists($current{'resetprelink'})) {
18244: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
18245: $changes{'reset'} = 1;
18246: }
1.368 raeburn 18247: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18248: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
18249: $changes{'reset'} = 1;
18250: }
18251: }
18252: } elsif ($current{'resetprelink'}) {
18253: $changes{'reset'} = 1;
18254: }
18255: foreach my $type (@oktypes) {
18256: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
18257: my @postlink;
18258: foreach my $item (sort(@possplink)) {
18259: if ($item =~ /^(email|username)$/) {
18260: push(@postlink,$item);
18261: }
18262: }
18263: $newvalues{'resetpostlink'}{$type} = \@postlink;
18264: unless ($changes{'reset'}) {
18265: if (ref($current{'resetpostlink'}) eq 'HASH') {
18266: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
18267: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
18268: if (@diffs > 0) {
18269: $changes{'reset'} = 1;
18270: }
18271: } else {
18272: $changes{'reset'} = 1;
18273: }
1.368 raeburn 18274: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18275: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
18276: if (@diffs > 0) {
18277: $changes{'reset'} = 1;
18278: }
18279: }
18280: }
18281: }
18282: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
18283: my @resetemail;
18284: foreach my $item (sort(@possemailsrc)) {
18285: if ($item =~ /^(permanent|critical|notify)$/) {
18286: push(@resetemail,$item);
18287: }
18288: }
18289: $newvalues{'resetemail'} = \@resetemail;
18290: unless ($changes{'reset'}) {
18291: if (ref($current{'resetemail'}) eq 'ARRAY') {
18292: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
18293: if (@diffs > 0) {
18294: $changes{'reset'} = 1;
18295: }
1.368 raeburn 18296: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18297: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
18298: if (@diffs > 0) {
18299: $changes{'reset'} = 1;
18300: }
18301: }
18302: }
18303: if ($env{'form.passwords_stdtext'} == 0) {
18304: $newvalues{'resetremove'} = 1;
18305: unless ($current{'resetremove'}) {
18306: $changes{'reset'} = 1;
18307: }
18308: } elsif ($current{'resetremove'}) {
18309: $changes{'reset'} = 1;
18310: }
18311: if ($env{'form.passwords_customfile.filename'} ne '') {
18312: my $servadm = $r->dir_config('lonAdmEMail');
18313: my ($configuserok,$author_ok,$switchserver) =
18314: &config_check($dom,$confname,$servadm);
18315: my $error;
18316: if ($configuserok eq 'ok') {
18317: if ($switchserver) {
18318: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
18319: } else {
18320: if ($author_ok eq 'ok') {
1.421 raeburn 18321: my $modified = [];
1.354 raeburn 18322: my ($result,$customurl) =
1.421 raeburn 18323: &Apache::lonconfigsettings::publishlogo($r,'upload','passwords_customfile',$dom,
18324: $confname,'customtext/resetpw','','',$customfn,
18325: $modified);
1.354 raeburn 18326: if ($result eq 'ok') {
18327: $newvalues{'resetcustom'} = $customurl;
18328: $changes{'reset'} = 1;
1.421 raeburn 18329: &update_modify_urls($r,$modified);
1.354 raeburn 18330: } else {
18331: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
18332: }
18333: } else {
18334: $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);
18335: }
18336: }
18337: } else {
18338: $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);
18339: }
18340: if ($error) {
18341: &Apache::lonnet::logthis($error);
18342: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
18343: }
18344: } elsif ($current{'resetcustom'}) {
18345: if ($env{'form.passwords_custom_del'}) {
18346: $changes{'reset'} = 1;
18347: } else {
18348: $newvalues{'resetcustom'} = $current{'resetcustom'};
18349: }
18350: }
18351: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
18352: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
18353: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
18354: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
18355: $changes{'intauth'} = 1;
18356: }
18357: } else {
18358: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
18359: }
18360: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
18361: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
18362: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
18363: $changes{'intauth'} = 1;
18364: }
18365: } else {
18366: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18367: }
18368: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
18369: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
18370: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
18371: $changes{'intauth'} = 1;
18372: }
18373: } else {
18374: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18375: }
18376: foreach my $item ('cost','check','switch') {
18377: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
18378: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
18379: $updatedefaults = 1;
18380: }
18381: }
1.405 raeburn 18382: &password_rule_changes('passwords',\%newvalues,\%current,\%changes);
1.359 raeburn 18383: my %crsownerchg = (
18384: by => [],
18385: for => [],
18386: );
18387: foreach my $item ('by','for') {
18388: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
18389: foreach my $type (sort(@posstypes)) {
18390: if (grep(/^\Q$type\E$/,@oktypes)) {
18391: push(@{$crsownerchg{$item}},$type);
18392: }
18393: }
18394: }
18395: $newvalues{'crsownerchg'} = \%crsownerchg;
18396: if (ref($current{'crsownerchg'}) eq 'HASH') {
18397: foreach my $item ('by','for') {
18398: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
18399: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
18400: if (@diffs > 0) {
18401: $changes{'crsownerchg'} = 1;
18402: last;
18403: }
18404: }
18405: }
1.368 raeburn 18406: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359 raeburn 18407: foreach my $item ('by','for') {
18408: if (@{$crsownerchg{$item}} > 0) {
18409: $changes{'crsownerchg'} = 1;
18410: last;
18411: }
1.354 raeburn 18412: }
18413: }
18414:
18415: my %confighash = (
18416: defaults => \%save_defaults,
18417: passwords => \%newvalues,
18418: );
18419: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
18420:
18421: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
18422: if ($putresult eq 'ok') {
18423: if (keys(%changes) > 0) {
18424: $resulttext = &mt('Changes made: ').'<ul>';
18425: foreach my $key ('reset','intauth','rules','crsownerchg') {
18426: if ($changes{$key}) {
1.355 raeburn 18427: unless ($key eq 'intauth') {
18428: $updateconf = 1;
18429: }
1.354 raeburn 18430: $resulttext .= '<li>'.$titles{$key}.':<ul>';
18431: if ($key eq 'reset') {
18432: if ($confighash{'passwords'}{'captcha'} eq 'original') {
18433: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
18434: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
18435: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369 raeburn 18436: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
18437: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
18438: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
18439: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
18440: }
1.354 raeburn 18441: } else {
18442: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
18443: }
18444: if ($confighash{'passwords'}{'resetlink'}) {
18445: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
18446: } else {
18447: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
18448: &mt('Will default to 2 hours').'</li>';
18449: }
18450: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
18451: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
18452: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
18453: } else {
18454: my $casesens;
18455: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
18456: if ($type eq 'default') {
18457: $casesens .= $othertitle.', ';
18458: } elsif ($usertypes->{$type} ne '') {
18459: $casesens .= $usertypes->{$type}.', ';
18460: }
18461: }
18462: $casesens =~ s/\Q, \E$//;
18463: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
18464: }
18465: } else {
18466: $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>';
18467: }
18468: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
18469: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
18470: } else {
18471: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
18472: }
18473: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
18474: my $output;
18475: if (ref($types) eq 'ARRAY') {
18476: foreach my $type (@{$types}) {
18477: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
18478: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
18479: $output .= $usertypes->{$type}.' -- '.&mt('none');
18480: } else {
18481: $output .= $usertypes->{$type}.' -- '.
18482: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
18483: }
18484: }
18485: }
18486: }
18487: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
18488: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
18489: $output .= $othertitle.' -- '.&mt('none');
18490: } else {
18491: $output .= $othertitle.' -- '.
18492: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
18493: }
18494: }
18495: if ($output) {
18496: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
18497: } else {
18498: $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>';
18499: }
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: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
18504: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
18505: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
18506: } else {
18507: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
18508: }
18509: } else {
1.379 raeburn 18510: $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 18511: }
18512: if ($confighash{'passwords'}{'resetremove'}) {
18513: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
18514: } else {
18515: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
18516: }
18517: if ($confighash{'passwords'}{'resetcustom'}) {
18518: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369 raeburn 18519: &mt('custom text'),600,500,undef,undef,
18520: undef,undef,'background-color:#ffffff');
18521: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354 raeburn 18522: } else {
18523: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
18524: }
18525: } elsif ($key eq 'intauth') {
18526: foreach my $item ('cost','switch','check') {
18527: my $value = $save_defaults{$key.'_'.$item};
18528: if ($item eq 'switch') {
18529: my %optiondesc = &Apache::lonlocal::texthash (
18530: 0 => 'No',
18531: 1 => 'Yes',
18532: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
18533: );
18534: if ($value =~ /^(0|1|2)$/) {
18535: $value = $optiondesc{$value};
18536: } else {
18537: $value = &mt('none -- defaults to No');
18538: }
18539: } elsif ($item eq 'check') {
18540: my %optiondesc = &Apache::lonlocal::texthash (
18541: 0 => 'No',
18542: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
18543: 2 => 'Yes, disallow login if stored cost is less than domain default',
18544: );
18545: if ($value =~ /^(0|1|2)$/) {
18546: $value = $optiondesc{$value};
18547: } else {
18548: $value = &mt('none -- defaults to No');
18549: }
18550: }
18551: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
18552: }
18553: } elsif ($key eq 'rules') {
1.356 raeburn 18554: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 18555: if ($confighash{'passwords'}{$rule} eq '') {
18556: if ($rule eq 'min') {
1.356 raeburn 18557: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365 raeburn 18558: ' '.&mt('Default of [_1] will be used',
18559: $Apache::lonnet::passwdmin).'</li>';
1.356 raeburn 18560: } else {
18561: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354 raeburn 18562: }
18563: } else {
18564: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
18565: }
18566: }
1.370 raeburn 18567: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
18568: if (@{$confighash{'passwords'}{'chars'}} > 0) {
18569: my %rulenames = &Apache::lonlocal::texthash(
18570: uc => 'At least one upper case letter',
18571: lc => 'At least one lower case letter',
18572: num => 'At least one number',
18573: spec => 'At least one non-alphanumeric',
18574: );
18575: my $needed = '<ul><li>'.
18576: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
1.425 raeburn 18577: '</li></ul>';
1.370 raeburn 18578: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
18579: } else {
18580: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18581: }
18582: } else {
18583: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18584: }
1.354 raeburn 18585: } elsif ($key eq 'crsownerchg') {
1.359 raeburn 18586: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
18587: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
18588: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
18589: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
18590: } else {
18591: my %crsownerstr;
18592: foreach my $item ('by','for') {
18593: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
18594: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
18595: if ($type eq 'default') {
18596: $crsownerstr{$item} .= $othertitle.', ';
18597: } elsif ($usertypes->{$type} ne '') {
18598: $crsownerstr{$item} .= $usertypes->{$type}.', ';
18599: }
18600: }
18601: $crsownerstr{$item} =~ s/\Q, \E$//;
18602: }
18603: }
18604: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
18605: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
18606: }
1.354 raeburn 18607: } else {
1.359 raeburn 18608: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354 raeburn 18609: }
18610: }
18611: $resulttext .= '</ul></li>';
18612: }
18613: }
18614: $resulttext .= '</ul>';
18615: } else {
18616: $resulttext = &mt('No changes made to password settings');
18617: }
1.355 raeburn 18618: my $cachetime = 24*60*60;
1.354 raeburn 18619: if ($updatedefaults) {
18620: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18621: if (ref($lastactref) eq 'HASH') {
18622: $lastactref->{'domdefaults'} = 1;
18623: }
18624: }
1.355 raeburn 18625: if ($updateconf) {
18626: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
18627: if (ref($lastactref) eq 'HASH') {
18628: $lastactref->{'passwdconf'} = 1;
18629: }
18630: }
1.354 raeburn 18631: } else {
18632: $resulttext = '<span class="LC_error">'.
18633: &mt('An error occurred: [_1]',$putresult).'</span>';
18634: }
18635: if ($errors) {
18636: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
18637: $errors.'</ul></p>';
18638: }
18639: return $resulttext;
18640: }
18641:
1.405 raeburn 18642: sub password_rule_changes {
18643: my ($prefix,$newvalues,$current,$changes) = @_;
18644: return unless ((ref($newvalues) eq 'HASH') &&
18645: (ref($current) eq 'HASH') &&
18646: (ref($changes) eq 'HASH'));
18647: my (@rules,%staticdefaults);
18648: if ($prefix eq 'passwords') {
18649: @rules = ('min','max','expire','numsaved');
1.421 raeburn 18650: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 18651: @rules = ('min','max');
18652: }
18653: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
18654: foreach my $rule (@rules) {
18655: $env{'form.'.$prefix.'_'.$rule} =~ s/^\s+|\s+$//g;
18656: my $ruleok;
18657: if ($rule eq 'expire') {
18658: if (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+(|\.\d*)$/) &&
18659: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18660: $ruleok = 1;
18661: }
18662: } elsif ($rule eq 'min') {
18663: if ($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) {
18664: if ($env{'form.'.$prefix.'_'.$rule} >= $staticdefaults{$rule}) {
18665: $ruleok = 1;
18666: }
18667: }
18668: } elsif (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) &&
18669: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18670: $ruleok = 1;
18671: }
18672: if ($ruleok) {
18673: $newvalues->{$rule} = $env{'form.'.$prefix.'_'.$rule};
18674: if (exists($current->{$rule})) {
18675: if ($newvalues->{$rule} ne $current->{$rule}) {
18676: $changes->{'rules'} = 1;
18677: }
18678: } elsif ($rule eq 'min') {
18679: if ($staticdefaults{$rule} ne $newvalues->{$rule}) {
18680: $changes->{'rules'} = 1;
18681: }
18682: } else {
18683: $changes->{'rules'} = 1;
18684: }
18685: } elsif (exists($current->{$rule})) {
18686: $changes->{'rules'} = 1;
18687: }
18688: }
18689: my @posschars = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_chars');
18690: my @chars;
18691: foreach my $item (sort(@posschars)) {
18692: if ($item =~ /^(uc|lc|num|spec)$/) {
18693: push(@chars,$item);
18694: }
18695: }
18696: $newvalues->{'chars'} = \@chars;
18697: unless ($changes->{'rules'}) {
18698: if (ref($current->{'chars'}) eq 'ARRAY') {
18699: my @diffs = &Apache::loncommon::compare_arrays($current->{'chars'},\@chars);
18700: if (@diffs > 0) {
18701: $changes->{'rules'} = 1;
18702: }
18703: } else {
18704: if (@chars > 0) {
18705: $changes->{'rules'} = 1;
18706: }
18707: }
18708: }
18709: return;
18710: }
18711:
1.28 raeburn 18712: sub modify_usercreation {
1.27 raeburn 18713: my ($dom,%domconfig) = @_;
1.224 raeburn 18714: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 18715: my $warningmsg;
1.27 raeburn 18716: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18717: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 18718: if ($key eq 'cancreate') {
18719: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18720: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 18721: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
18722: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18723: } else {
1.224 raeburn 18724: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18725: }
18726: }
18727: }
18728: } elsif ($key eq 'email_rule') {
18729: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18730: } else {
18731: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18732: }
1.27 raeburn 18733: }
18734: }
18735: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 18736: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 18737: my @contexts = ('author','course','requestcrs');
1.34 raeburn 18738: foreach my $item(@contexts) {
1.224 raeburn 18739: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 18740: }
1.34 raeburn 18741: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
18742: foreach my $item (@contexts) {
1.224 raeburn 18743: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
18744: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 18745: }
1.27 raeburn 18746: }
1.34 raeburn 18747: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
18748: foreach my $item (@contexts) {
1.43 raeburn 18749: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 18750: if ($cancreate{$item} ne 'any') {
18751: push(@{$changes{'cancreate'}},$item);
18752: }
18753: } else {
18754: if ($cancreate{$item} ne 'none') {
18755: push(@{$changes{'cancreate'}},$item);
18756: }
1.27 raeburn 18757: }
18758: }
18759: } else {
1.43 raeburn 18760: foreach my $item (@contexts) {
1.34 raeburn 18761: push(@{$changes{'cancreate'}},$item);
18762: }
1.27 raeburn 18763: }
1.34 raeburn 18764:
1.27 raeburn 18765: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
18766: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
18767: if (!grep(/^\Q$type\E$/,@username_rule)) {
18768: push(@{$changes{'username_rule'}},$type);
18769: }
18770: }
18771: foreach my $type (@username_rule) {
18772: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
18773: push(@{$changes{'username_rule'}},$type);
18774: }
18775: }
18776: } else {
18777: push(@{$changes{'username_rule'}},@username_rule);
18778: }
18779:
1.32 raeburn 18780: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
18781: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
18782: if (!grep(/^\Q$type\E$/,@id_rule)) {
18783: push(@{$changes{'id_rule'}},$type);
18784: }
18785: }
18786: foreach my $type (@id_rule) {
18787: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
18788: push(@{$changes{'id_rule'}},$type);
18789: }
18790: }
18791: } else {
18792: push(@{$changes{'id_rule'}},@id_rule);
18793: }
18794:
1.43 raeburn 18795: my @authen_contexts = ('author','course','domain');
1.325 raeburn 18796: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 18797: my %authhash;
1.43 raeburn 18798: foreach my $item (@authen_contexts) {
1.28 raeburn 18799: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
18800: foreach my $auth (@authtypes) {
18801: if (grep(/^\Q$auth\E$/,@authallowed)) {
18802: $authhash{$item}{$auth} = 1;
18803: } else {
18804: $authhash{$item}{$auth} = 0;
18805: }
18806: }
18807: }
18808: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 18809: foreach my $item (@authen_contexts) {
1.28 raeburn 18810: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
18811: foreach my $auth (@authtypes) {
18812: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
18813: push(@{$changes{'authtypes'}},$item);
18814: last;
18815: }
18816: }
18817: }
18818: }
18819: } else {
1.43 raeburn 18820: foreach my $item (@authen_contexts) {
1.28 raeburn 18821: push(@{$changes{'authtypes'}},$item);
18822: }
18823: }
18824:
1.224 raeburn 18825: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
18826: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
18827: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
18828: $save_usercreate{'id_rule'} = \@id_rule;
18829: $save_usercreate{'username_rule'} = \@username_rule,
18830: $save_usercreate{'authtypes'} = \%authhash;
18831:
1.27 raeburn 18832: my %usercreation_hash = (
1.224 raeburn 18833: usercreation => \%save_usercreate,
18834: );
1.27 raeburn 18835:
18836: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
18837: $dom);
1.50 raeburn 18838:
1.224 raeburn 18839: if ($putresult eq 'ok') {
18840: if (keys(%changes) > 0) {
18841: $resulttext = &mt('Changes made:').'<ul>';
18842: if (ref($changes{'cancreate'}) eq 'ARRAY') {
18843: my %lt = &usercreation_types();
18844: foreach my $type (@{$changes{'cancreate'}}) {
18845: my $chgtext = $lt{$type}.', ';
18846: if ($cancreate{$type} eq 'none') {
18847: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
18848: } elsif ($cancreate{$type} eq 'any') {
18849: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
18850: } elsif ($cancreate{$type} eq 'official') {
18851: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
18852: } elsif ($cancreate{$type} eq 'unofficial') {
18853: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
18854: }
18855: $resulttext .= '<li>'.$chgtext.'</li>';
18856: }
18857: }
18858: if (ref($changes{'username_rule'}) eq 'ARRAY') {
18859: my ($rules,$ruleorder) =
18860: &Apache::lonnet::inst_userrules($dom,'username');
18861: my $chgtext = '<ul>';
18862: foreach my $type (@username_rule) {
18863: if (ref($rules->{$type}) eq 'HASH') {
18864: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
18865: }
18866: }
18867: $chgtext .= '</ul>';
18868: if (@username_rule > 0) {
18869: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18870: } else {
18871: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
18872: }
18873: }
18874: if (ref($changes{'id_rule'}) eq 'ARRAY') {
18875: my ($idrules,$idruleorder) =
18876: &Apache::lonnet::inst_userrules($dom,'id');
18877: my $chgtext = '<ul>';
18878: foreach my $type (@id_rule) {
18879: if (ref($idrules->{$type}) eq 'HASH') {
18880: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
18881: }
18882: }
18883: $chgtext .= '</ul>';
18884: if (@id_rule > 0) {
18885: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18886: } else {
18887: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
18888: }
18889: }
18890: my %authname = &authtype_names();
18891: my %context_title = &context_names();
18892: if (ref($changes{'authtypes'}) eq 'ARRAY') {
18893: my $chgtext = '<ul>';
18894: foreach my $type (@{$changes{'authtypes'}}) {
18895: my @allowed;
18896: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
18897: foreach my $auth (@authtypes) {
18898: if ($authhash{$type}{$auth}) {
18899: push(@allowed,$authname{$auth});
18900: }
18901: }
18902: if (@allowed > 0) {
18903: $chgtext .= join(', ',@allowed).'</li>';
18904: } else {
18905: $chgtext .= &mt('none').'</li>';
18906: }
18907: }
18908: $chgtext .= '</ul>';
18909: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
18910: $resulttext .= '</li>';
18911: }
18912: $resulttext .= '</ul>';
18913: } else {
18914: $resulttext = &mt('No changes made to user creation settings');
18915: }
18916: } else {
18917: $resulttext = '<span class="LC_error">'.
18918: &mt('An error occurred: [_1]',$putresult).'</span>';
18919: }
18920: if ($warningmsg ne '') {
18921: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
18922: }
18923: return $resulttext;
18924: }
18925:
18926: sub modify_selfcreation {
1.305 raeburn 18927: my ($dom,$lastactref,%domconfig) = @_;
18928: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
18929: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
18930: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 18931: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
18932: if (ref($typesref) eq 'ARRAY') {
18933: @types = @{$typesref};
18934: }
18935: if (ref($usertypesref) eq 'HASH') {
18936: %usertypes = %{$usertypesref};
1.228 raeburn 18937: }
1.303 raeburn 18938: $usertypes{'default'} = $othertitle;
1.224 raeburn 18939: #
18940: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
18941: #
18942: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18943: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
18944: if ($key eq 'cancreate') {
18945: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18946: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
18947: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 18948: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
18949: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
18950: ($item eq 'emailusername') || ($item eq 'shibenv') ||
18951: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 18952: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 18953: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18954: } else {
18955: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18956: }
18957: }
18958: }
18959: } elsif ($key eq 'email_rule') {
18960: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18961: } else {
18962: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18963: }
18964: }
18965: }
18966: #
18967: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
18968: #
18969: if (ref($domconfig{'usermodification'}) eq 'HASH') {
18970: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
18971: if ($key eq 'selfcreate') {
18972: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
18973: } else {
18974: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
18975: }
18976: }
18977: }
1.305 raeburn 18978: #
18979: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
18980: #
18981: if (ref($domconfig{'inststatus'}) eq 'HASH') {
18982: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
18983: if ($key eq 'inststatusguest') {
18984: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
18985: } else {
18986: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
18987: }
18988: }
18989: }
1.224 raeburn 18990:
18991: my @contexts = ('selfcreate');
18992: @{$cancreate{'selfcreate'}} = ();
18993: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 18994: if (@types) {
18995: @{$cancreate{'statustocreate'}} = ();
18996: }
1.236 raeburn 18997: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 18998: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 18999: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 19000: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 19001: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 19002: my %selfcreatetypes = (
19003: sso => 'users authenticated by institutional single sign on',
19004: login => 'users authenticated by institutional log-in',
1.303 raeburn 19005: email => 'users verified by e-mail',
1.50 raeburn 19006: );
1.224 raeburn 19007: #
19008: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
19009: # is permitted.
19010: #
1.305 raeburn 19011: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 19012:
1.305 raeburn 19013: my (@statuses,%email_rule);
1.228 raeburn 19014: foreach my $item ('login','sso','email') {
1.224 raeburn 19015: if ($item eq 'email') {
1.236 raeburn 19016: if ($env{'form.cancreate_email'}) {
1.305 raeburn 19017: if (@types) {
19018: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
19019: foreach my $status (@poss_statuses) {
19020: if (grep(/^\Q$status\E$/,(@types,'default'))) {
19021: push(@statuses,$status);
19022: }
19023: }
19024: $save_inststatus{'inststatusguest'} = \@statuses;
19025: } else {
19026: push(@statuses,'default');
19027: }
19028: if (@statuses) {
19029: my %curr_rule;
19030: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
19031: foreach my $type (@statuses) {
19032: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 19033: }
1.305 raeburn 19034: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
19035: foreach my $type (@statuses) {
19036: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
19037: }
19038: }
19039: push(@{$cancreate{'selfcreate'}},'email');
19040: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
19041: my %curremaildom;
19042: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
19043: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
19044: }
19045: foreach my $type (@statuses) {
19046: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
19047: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
19048: }
19049: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
19050: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
19051: }
19052: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
19053: #
19054: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
19055: #
19056: my $chosen = $1;
19057: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
19058: my $emaildom;
19059: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
1.425 raeburn 19060: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
1.305 raeburn 19061: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
19062: if (ref($curremaildom{$type}) eq 'HASH') {
19063: if (exists($curremaildom{$type}{$chosen})) {
19064: if ($curremaildom{$type}{$chosen} ne $emaildom) {
19065: push(@{$changes{'cancreate'}},'emaildomain');
19066: }
19067: } elsif ($emaildom ne '') {
19068: push(@{$changes{'cancreate'}},'emaildomain');
19069: }
19070: } elsif ($emaildom ne '') {
19071: push(@{$changes{'cancreate'}},'emaildomain');
1.425 raeburn 19072: }
1.305 raeburn 19073: }
19074: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
19075: } elsif ($chosen eq 'custom') {
19076: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
19077: $email_rule{$type} = [];
19078: if (ref($emailrules) eq 'HASH') {
19079: foreach my $rule (@possemail_rules) {
19080: if (exists($emailrules->{$rule})) {
19081: push(@{$email_rule{$type}},$rule);
19082: }
19083: }
19084: }
19085: if (@{$email_rule{$type}}) {
19086: $cancreate{'emailoptions'}{$type} = 'custom';
19087: if (ref($curr_rule{$type}) eq 'ARRAY') {
19088: if (@{$curr_rule{$type}} > 0) {
19089: foreach my $rule (@{$curr_rule{$type}}) {
19090: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
19091: push(@{$changes{'email_rule'}},$type);
19092: }
19093: }
19094: }
19095: foreach my $type (@{$email_rule{$type}}) {
19096: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
19097: push(@{$changes{'email_rule'}},$type);
19098: }
19099: }
19100: } else {
19101: push(@{$changes{'email_rule'}},$type);
19102: }
19103: }
19104: } else {
19105: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
19106: }
19107: }
19108: }
19109: if (@types) {
19110: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19111: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
19112: if (@changed) {
19113: push(@{$changes{'inststatus'}},'inststatusguest');
19114: }
19115: } else {
19116: push(@{$changes{'inststatus'}},'inststatusguest');
19117: }
19118: }
19119: } else {
19120: delete($env{'form.cancreate_email'});
19121: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19122: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
19123: push(@{$changes{'inststatus'}},'inststatusguest');
19124: }
19125: }
19126: }
19127: } else {
19128: $save_inststatus{'inststatusguest'} = [];
19129: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19130: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
19131: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 19132: }
19133: }
1.224 raeburn 19134: }
19135: } else {
19136: if ($env{'form.cancreate_'.$item}) {
19137: push(@{$cancreate{'selfcreate'}},$item);
19138: }
19139: }
19140: }
1.305 raeburn 19141: my (%userinfo,%savecaptcha);
1.224 raeburn 19142: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
19143: #
1.228 raeburn 19144: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
19145: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 19146: #
1.236 raeburn 19147:
1.244 raeburn 19148: if ($env{'form.cancreate_email'}) {
1.228 raeburn 19149: push(@contexts,'emailusername');
1.305 raeburn 19150: if (@statuses) {
19151: foreach my $type (@statuses) {
1.228 raeburn 19152: if (ref($infofields) eq 'ARRAY') {
19153: foreach my $field (@{$infofields}) {
19154: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
19155: $cancreate{'emailusername'}{$type}{$field} = $1;
19156: }
19157: }
1.224 raeburn 19158: }
19159: }
19160: }
19161: #
19162: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 19163: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 19164: #
19165:
19166: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
19167: @approvalnotify = sort(@approvalnotify);
19168: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
19169: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
19170: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
19171: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
19172: push(@{$changes{'cancreate'}},'notify');
19173: }
19174: } else {
19175: if ($cancreate{'notify'}{'approval'}) {
19176: push(@{$changes{'cancreate'}},'notify');
19177: }
19178: }
19179: } elsif ($cancreate{'notify'}{'approval'}) {
19180: push(@{$changes{'cancreate'}},'notify');
19181: }
19182:
19183: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
19184: }
19185: #
1.236 raeburn 19186: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 19187: # institutional log-in.
19188: #
19189: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
19190: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
19191: ($domdefaults{'auth_def'} eq 'localauth'))) {
19192: $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.').' '.
19193: &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.');
19194: }
19195: }
19196: my @fields = ('lastname','firstname','middlename','generation',
19197: 'permanentemail','id');
1.240 raeburn 19198: my @shibfields = (@fields,'inststatus');
1.224 raeburn 19199: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19200: #
19201: # Where usernames may created for institutional log-in and/or institutional single sign on:
19202: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
19203: # may self-create accounts
19204: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
19205: # which the user may supply, if institutional data is unavailable.
19206: #
19207: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 19208: if (@types) {
1.305 raeburn 19209: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
19210: push(@contexts,'statustocreate');
1.303 raeburn 19211: foreach my $type (@types) {
1.224 raeburn 19212: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
19213: foreach my $field (@fields) {
19214: if (grep(/^\Q$field\E$/,@modifiable)) {
19215: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
19216: } else {
19217: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
19218: }
19219: }
19220: }
19221: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 19222: foreach my $type (@types) {
1.224 raeburn 19223: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
19224: foreach my $field (@fields) {
19225: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
19226: $curr_usermodify{'selfcreate'}{$type}{$field}) {
19227: push(@{$changes{'selfcreate'}},$type);
19228: last;
19229: }
19230: }
19231: }
19232: }
19233: } else {
1.303 raeburn 19234: foreach my $type (@types) {
1.224 raeburn 19235: push(@{$changes{'selfcreate'}},$type);
19236: }
19237: }
19238: }
1.240 raeburn 19239: foreach my $field (@shibfields) {
19240: if ($env{'form.shibenv_'.$field} ne '') {
19241: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
19242: }
19243: }
19244: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
19245: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
19246: foreach my $field (@shibfields) {
19247: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
19248: push(@{$changes{'cancreate'}},'shibenv');
19249: }
19250: }
19251: } else {
19252: foreach my $field (@shibfields) {
19253: if ($env{'form.shibenv_'.$field}) {
19254: push(@{$changes{'cancreate'}},'shibenv');
19255: last;
19256: }
19257: }
19258: }
19259: }
1.224 raeburn 19260: }
19261: foreach my $item (@contexts) {
19262: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
19263: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
19264: if (ref($cancreate{$item}) eq 'ARRAY') {
19265: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
19266: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19267: push(@{$changes{'cancreate'}},$item);
19268: }
19269: }
19270: }
19271: }
19272: if (ref($cancreate{$item}) eq 'ARRAY') {
19273: foreach my $type (@{$cancreate{$item}}) {
19274: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
19275: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19276: push(@{$changes{'cancreate'}},$item);
19277: }
19278: }
19279: }
19280: }
19281: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
19282: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 19283: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
19284: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19285: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
19286: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19287: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19288: push(@{$changes{'cancreate'}},$item);
19289: }
19290: }
19291: }
1.305 raeburn 19292: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19293: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19294: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19295: push(@{$changes{'cancreate'}},$item);
19296: }
1.224 raeburn 19297: }
19298: }
19299: }
1.305 raeburn 19300: foreach my $type (keys(%{$cancreate{$item}})) {
19301: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19302: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19303: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19304: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19305: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19306: push(@{$changes{'cancreate'}},$item);
19307: }
19308: }
19309: } else {
19310: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19311: push(@{$changes{'cancreate'}},$item);
19312: }
19313: }
19314: }
1.305 raeburn 19315: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19316: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19317: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19318: push(@{$changes{'cancreate'}},$item);
19319: }
1.224 raeburn 19320: }
19321: }
19322: }
19323: }
19324: } elsif ($curr_usercreation{'cancreate'}{$item}) {
19325: if (ref($cancreate{$item}) eq 'ARRAY') {
19326: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
19327: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19328: push(@{$changes{'cancreate'}},$item);
19329: }
19330: }
1.305 raeburn 19331: }
19332: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19333: if (ref($cancreate{$item}) eq 'HASH') {
19334: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19335: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 19336: }
19337: }
19338: } elsif ($item eq 'emailusername') {
1.228 raeburn 19339: if (ref($cancreate{$item}) eq 'HASH') {
19340: foreach my $type (keys(%{$cancreate{$item}})) {
19341: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19342: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19343: if ($cancreate{$item}{$type}{$field}) {
19344: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19345: push(@{$changes{'cancreate'}},$item);
19346: }
19347: last;
19348: }
19349: }
19350: }
19351: }
1.224 raeburn 19352: }
19353: }
19354: }
19355: #
19356: # Populate %save_usercreate hash with updates to self-creation configuration.
19357: #
19358: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
19359: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 19360: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 19361: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
19362: if (ref($cancreate{'notify'}) eq 'HASH') {
19363: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
19364: }
1.236 raeburn 19365: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
19366: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
19367: }
1.303 raeburn 19368: if (ref($cancreate{'emailverified'}) eq 'HASH') {
19369: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
19370: }
1.305 raeburn 19371: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
19372: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
19373: }
1.303 raeburn 19374: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
19375: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
19376: }
1.224 raeburn 19377: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19378: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
19379: }
1.240 raeburn 19380: if (ref($cancreate{'shibenv'}) eq 'HASH') {
19381: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
19382: }
1.224 raeburn 19383: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 19384: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 19385:
19386: my %userconfig_hash = (
19387: usercreation => \%save_usercreate,
19388: usermodification => \%save_usermodify,
1.305 raeburn 19389: inststatus => \%save_inststatus,
1.224 raeburn 19390: );
1.305 raeburn 19391:
1.224 raeburn 19392: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
19393: $dom);
19394: #
1.305 raeburn 19395: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 19396: #
1.27 raeburn 19397: if ($putresult eq 'ok') {
19398: if (keys(%changes) > 0) {
19399: $resulttext = &mt('Changes made:').'<ul>';
19400: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 19401: my %lt = &selfcreation_types();
1.34 raeburn 19402: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 19403: my $chgtext = '';
1.45 raeburn 19404: if ($type eq 'selfcreate') {
1.50 raeburn 19405: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 19406: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 19407: } else {
1.224 raeburn 19408: $chgtext .= &mt('Self-creation of a new account is permitted for:').
19409: '<ul>';
1.50 raeburn 19410: foreach my $case (@{$cancreate{$type}}) {
19411: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
19412: }
19413: $chgtext .= '</ul>';
1.100 raeburn 19414: if (ref($cancreate{$type}) eq 'ARRAY') {
19415: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
19416: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19417: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 19418: $chgtext .= '<span class="LC_warning">'.
19419: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
19420: '</span><br />';
19421: }
19422: }
19423: }
19424: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 19425: if (!@statuses) {
19426: $chgtext .= '<span class="LC_warning">'.
19427: &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.").
19428: '</span><br />';
1.303 raeburn 19429:
1.100 raeburn 19430: }
19431: }
19432: }
1.43 raeburn 19433: }
1.240 raeburn 19434: } elsif ($type eq 'shibenv') {
19435: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 19436: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 19437: } else {
19438: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
19439: '<ul>';
19440: foreach my $field (@shibfields) {
19441: next if ($cancreate{$type}{$field} eq '');
19442: if ($field eq 'inststatus') {
19443: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
19444: } else {
19445: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
19446: }
19447: }
19448: $chgtext .= '</ul>';
1.303 raeburn 19449: }
1.93 raeburn 19450: } elsif ($type eq 'statustocreate') {
1.96 raeburn 19451: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
19452: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
19453: if (@{$cancreate{'selfcreate'}} > 0) {
19454: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 19455: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 19456: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 19457: $chgtext .= '<br />'.
19458: '<span class="LC_warning">'.
19459: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
19460: '</span>';
19461: }
1.303 raeburn 19462: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 19463: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 19464: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
19465: } else {
19466: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
19467: }
19468: $chgtext .= '<ul>';
19469: foreach my $case (@{$cancreate{$type}}) {
19470: if ($case eq 'default') {
19471: $chgtext .= '<li>'.$othertitle.'</li>';
19472: } else {
1.303 raeburn 19473: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 19474: }
19475: }
1.100 raeburn 19476: $chgtext .= '</ul>';
19477: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 19478: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 19479: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
19480: '</span>';
1.100 raeburn 19481: }
19482: }
19483: } else {
19484: if (@{$cancreate{$type}} == 0) {
19485: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
19486: } else {
19487: $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 19488: }
19489: }
1.303 raeburn 19490: $chgtext .= '<br />';
1.93 raeburn 19491: }
1.236 raeburn 19492: } elsif ($type eq 'selfcreateprocessing') {
19493: my %choices = &Apache::lonlocal::texthash (
19494: automatic => 'Automatic approval',
19495: approval => 'Queued for approval',
19496: );
1.305 raeburn 19497: if (@types) {
19498: if (@statuses) {
1.425 raeburn 19499: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 19500: '<ul>';
1.305 raeburn 19501: foreach my $status (@statuses) {
19502: if ($status eq 'default') {
19503: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19504: } else {
1.305 raeburn 19505: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19506: }
19507: }
19508: $chgtext .= '</ul>';
19509: }
19510: } else {
19511: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
19512: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
19513: }
19514: } elsif ($type eq 'emailverified') {
19515: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 19516: all => 'Same as e-mail',
19517: first => 'Omit @domain',
19518: free => 'Free to choose',
1.303 raeburn 19519: );
1.305 raeburn 19520: if (@types) {
19521: if (@statuses) {
1.303 raeburn 19522: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
19523: '<ul>';
1.305 raeburn 19524: foreach my $status (@statuses) {
1.362 raeburn 19525: if ($status eq 'default') {
1.305 raeburn 19526: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19527: } else {
1.305 raeburn 19528: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19529: }
19530: }
19531: $chgtext .= '</ul>';
19532: }
19533: } else {
1.305 raeburn 19534: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 19535: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 19536: }
1.305 raeburn 19537: } elsif ($type eq 'emailoptions') {
19538: my %options = &Apache::lonlocal::texthash (
19539: any => 'Any e-mail',
19540: inst => 'Institutional only',
19541: noninst => 'Non-institutional only',
19542: custom => 'Custom restrictions',
19543: );
19544: if (@types) {
19545: if (@statuses) {
19546: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
19547: '<ul>';
19548: foreach my $status (@statuses) {
19549: if ($type eq 'default') {
19550: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
19551: } else {
19552: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 19553: }
19554: }
1.305 raeburn 19555: $chgtext .= '</ul>';
19556: }
19557: } else {
19558: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
19559: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
19560: } else {
19561: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
19562: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 19563: }
1.305 raeburn 19564: }
19565: } elsif ($type eq 'emaildomain') {
19566: my $output;
19567: if (@statuses) {
19568: foreach my $type (@statuses) {
19569: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
19570: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
19571: if ($type eq 'default') {
19572: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19573: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19574: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19575: } else {
19576: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
19577: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
19578: }
1.303 raeburn 19579: } else {
1.305 raeburn 19580: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19581: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19582: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19583: } else {
19584: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
1.421 raeburn 19585: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
1.305 raeburn 19586: }
1.303 raeburn 19587: }
1.305 raeburn 19588: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
19589: if ($type eq 'default') {
19590: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19591: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19592: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19593: } else {
19594: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
19595: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
19596: }
1.303 raeburn 19597: } else {
1.305 raeburn 19598: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19599: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19600: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19601: } else {
19602: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
1.421 raeburn 19603: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
1.305 raeburn 19604: }
1.303 raeburn 19605: }
19606: }
19607: }
19608: }
1.305 raeburn 19609: }
19610: if ($output ne '') {
19611: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
19612: '<ul>'.$output.'</ul>';
1.236 raeburn 19613: }
1.165 raeburn 19614: } elsif ($type eq 'captcha') {
1.224 raeburn 19615: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 19616: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
19617: } else {
19618: my %captchas = &captcha_phrases();
1.224 raeburn 19619: if ($captchas{$savecaptcha{$type}}) {
19620: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 19621: } else {
1.210 raeburn 19622: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 19623: }
19624: }
19625: } elsif ($type eq 'recaptchakeys') {
19626: my ($privkey,$pubkey);
1.224 raeburn 19627: if (ref($savecaptcha{$type}) eq 'HASH') {
19628: $pubkey = $savecaptcha{$type}{'public'};
19629: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 19630: }
19631: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
19632: if (!$pubkey) {
19633: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
19634: } else {
19635: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
19636: }
19637: if (!$privkey) {
19638: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
19639: } else {
19640: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
19641: }
19642: $chgtext .= '</ul>';
1.269 raeburn 19643: } elsif ($type eq 'recaptchaversion') {
19644: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 19645: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 19646: }
1.224 raeburn 19647: } elsif ($type eq 'emailusername') {
19648: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 19649: if (@statuses) {
19650: foreach my $type (@statuses) {
1.228 raeburn 19651: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
19652: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 19653: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 19654: '<ul>';
19655: foreach my $field (@{$infofields}) {
19656: if ($cancreate{'emailusername'}{$type}{$field}) {
19657: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
19658: }
19659: }
1.245 raeburn 19660: $chgtext .= '</ul>';
19661: } else {
1.303 raeburn 19662: $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 19663: }
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.224 raeburn 19666: }
19667: }
19668: }
19669: }
19670: } elsif ($type eq 'notify') {
1.303 raeburn 19671: my $numapprove = 0;
1.224 raeburn 19672: if (ref($changes{'cancreate'}) eq 'ARRAY') {
19673: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
19674: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 19675: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
19676: $numapprove ++;
1.224 raeburn 19677: }
19678: }
1.43 raeburn 19679: }
1.303 raeburn 19680: unless ($numapprove) {
19681: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
19682: }
1.34 raeburn 19683: }
1.224 raeburn 19684: if ($chgtext) {
19685: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 19686: }
19687: }
19688: }
1.305 raeburn 19689: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 19690: my ($emailrules,$emailruleorder) =
19691: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 19692: foreach my $type (@{$changes{'email_rule'}}) {
19693: if (ref($email_rule{$type}) eq 'ARRAY') {
19694: my $chgtext = '<ul>';
19695: foreach my $rule (@{$email_rule{$type}}) {
19696: if (ref($emailrules->{$rule}) eq 'HASH') {
19697: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
19698: }
19699: }
19700: $chgtext .= '</ul>';
1.310 raeburn 19701: my $typename;
1.305 raeburn 19702: if (@types) {
19703: if ($type eq 'default') {
19704: $typename = $othertitle;
19705: } else {
19706: $typename = $usertypes{$type};
1.425 raeburn 19707: }
1.305 raeburn 19708: $chgtext .= &mt('(Affiliation: [_1])',$typename);
19709: }
19710: if (@{$email_rule{$type}} > 0) {
19711: $resulttext .= '<li>'.
19712: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
19713: $usertypes{$type}).
19714: $chgtext.
19715: '</li>';
19716: } else {
19717: $resulttext .= '<li>'.
1.310 raeburn 19718: &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 19719: '</li>'.
1.310 raeburn 19720: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 19721: }
1.43 raeburn 19722: }
19723: }
1.305 raeburn 19724: }
19725: if (ref($changes{'inststatus'}) eq 'ARRAY') {
19726: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
19727: if (@{$save_inststatus{'inststatusguest'}} > 0) {
19728: my $chgtext = '<ul>';
19729: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
19730: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
19731: }
19732: $chgtext .= '</ul>';
19733: $resulttext .= '<li>'.
19734: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
19735: $chgtext.
19736: '</li>';
19737: } else {
19738: $resulttext .= '<li>'.
19739: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
19740: '</li>';
19741: }
1.43 raeburn 19742: }
19743: }
1.224 raeburn 19744: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
19745: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
19746: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19747: foreach my $type (@{$changes{'selfcreate'}}) {
19748: my $typename = $type;
1.303 raeburn 19749: if (keys(%usertypes) > 0) {
19750: if ($usertypes{$type} ne '') {
19751: $typename = $usertypes{$type};
1.224 raeburn 19752: }
19753: }
19754: my @modifiable;
19755: $resulttext .= '<li>'.
19756: &mt('Self-creation of account by users with status: [_1]',
19757: '<span class="LC_cusr_emph">'.$typename.'</span>').
19758: ' - '.&mt('modifiable fields (if institutional data blank): ');
19759: foreach my $field (@fields) {
19760: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
19761: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 19762: }
19763: }
1.224 raeburn 19764: if (@modifiable > 0) {
19765: $resulttext .= join(', ',@modifiable);
1.43 raeburn 19766: } else {
1.224 raeburn 19767: $resulttext .= &mt('none');
1.43 raeburn 19768: }
1.224 raeburn 19769: $resulttext .= '</li>';
1.28 raeburn 19770: }
1.224 raeburn 19771: $resulttext .= '</ul></li>';
1.28 raeburn 19772: }
1.27 raeburn 19773: $resulttext .= '</ul>';
1.305 raeburn 19774: my $cachetime = 24*60*60;
19775: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
19776: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19777: if (ref($lastactref) eq 'HASH') {
19778: $lastactref->{'domdefaults'} = 1;
19779: }
1.27 raeburn 19780: } else {
1.224 raeburn 19781: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 19782: }
19783: } else {
19784: $resulttext = '<span class="LC_error">'.
1.23 raeburn 19785: &mt('An error occurred: [_1]',$putresult).'</span>';
19786: }
1.43 raeburn 19787: if ($warningmsg ne '') {
19788: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
19789: }
1.23 raeburn 19790: return $resulttext;
19791: }
19792:
1.165 raeburn 19793: sub process_captcha {
1.369 raeburn 19794: my ($container,$changes,$newsettings,$currsettings) = @_;
19795: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165 raeburn 19796: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
19797: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
19798: $newsettings->{'captcha'} = 'original';
19799: }
1.369 raeburn 19800: my %current;
19801: if (ref($currsettings) eq 'HASH') {
19802: %current = %{$currsettings};
19803: }
19804: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 19805: if ($container eq 'cancreate') {
1.169 raeburn 19806: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19807: push(@{$changes->{'cancreate'}},'captcha');
19808: } elsif (!defined($changes->{'cancreate'})) {
19809: $changes->{'cancreate'} = ['captcha'];
19810: }
1.368 raeburn 19811: } elsif ($container eq 'passwords') {
19812: $changes->{'reset'} = 1;
1.169 raeburn 19813: } else {
19814: $changes->{'captcha'} = 1;
1.165 raeburn 19815: }
19816: }
1.269 raeburn 19817: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 19818: if ($newsettings->{'captcha'} eq 'recaptcha') {
19819: $newpub = $env{'form.'.$container.'_recaptchapub'};
19820: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 19821: $newpub =~ s/[^\w\-]//g;
19822: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 19823: $newsettings->{'recaptchakeys'} = {
19824: public => $newpub,
19825: private => $newpriv,
19826: };
1.269 raeburn 19827: $newversion = $env{'form.'.$container.'_recaptchaversion'};
19828: $newversion =~ s/\D//g;
19829: if ($newversion ne '2') {
19830: $newversion = 1;
19831: }
19832: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 19833: }
1.369 raeburn 19834: if (ref($current{'recaptchakeys'}) eq 'HASH') {
19835: $currpub = $current{'recaptchakeys'}{'public'};
19836: $currpriv = $current{'recaptchakeys'}{'private'};
1.179 raeburn 19837: unless ($newsettings->{'captcha'} eq 'recaptcha') {
19838: $newsettings->{'recaptchakeys'} = {
19839: public => '',
19840: private => '',
19841: }
19842: }
1.165 raeburn 19843: }
1.369 raeburn 19844: if ($current{'captcha'} eq 'recaptcha') {
19845: $currversion = $current{'recaptchaversion'};
1.269 raeburn 19846: if ($currversion ne '2') {
19847: $currversion = 1;
19848: }
19849: }
19850: if ($currversion ne $newversion) {
19851: if ($container eq 'cancreate') {
19852: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19853: push(@{$changes->{'cancreate'}},'recaptchaversion');
19854: } elsif (!defined($changes->{'cancreate'})) {
19855: $changes->{'cancreate'} = ['recaptchaversion'];
19856: }
1.368 raeburn 19857: } elsif ($container eq 'passwords') {
19858: $changes->{'reset'} = 1;
1.269 raeburn 19859: } else {
19860: $changes->{'recaptchaversion'} = 1;
19861: }
19862: }
1.165 raeburn 19863: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 19864: if ($container eq 'cancreate') {
19865: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19866: push(@{$changes->{'cancreate'}},'recaptchakeys');
19867: } elsif (!defined($changes->{'cancreate'})) {
19868: $changes->{'cancreate'} = ['recaptchakeys'];
19869: }
1.368 raeburn 19870: } elsif ($container eq 'passwords') {
19871: $changes->{'reset'} = 1;
1.169 raeburn 19872: } else {
1.210 raeburn 19873: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 19874: }
19875: }
19876: return;
19877: }
19878:
1.33 raeburn 19879: sub modify_usermodification {
19880: my ($dom,%domconfig) = @_;
1.224 raeburn 19881: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 19882: if (ref($domconfig{'usermodification'}) eq 'HASH') {
19883: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 19884: if ($key eq 'selfcreate') {
19885: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
19886: } else {
19887: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
19888: }
1.33 raeburn 19889: }
19890: }
1.443 raeburn 19891: my @contexts = ('author','coauthor','course');
1.33 raeburn 19892: my %context_title = (
19893: author => 'In author context',
1.443 raeburn 19894: coauthor => 'As co-author manager',
1.33 raeburn 19895: course => 'In course context',
19896: );
19897: my @fields = ('lastname','firstname','middlename','generation',
19898: 'permanentemail','id');
19899: my %roles = (
19900: author => ['ca','aa'],
1.443 raeburn 19901: coauthor => ['ca','aa'],
1.33 raeburn 19902: course => ['st','ep','ta','in','cr'],
19903: );
19904: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19905: foreach my $context (@contexts) {
1.443 raeburn 19906: my $prefix = 'canmodify';
19907: if ($context eq 'coauthor') {
19908: $prefix = 'cacanmodify';
19909: }
1.33 raeburn 19910: foreach my $role (@{$roles{$context}}) {
1.443 raeburn 19911: my @modifiable = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$role);
1.33 raeburn 19912: foreach my $item (@fields) {
19913: if (grep(/^\Q$item\E$/,@modifiable)) {
19914: $modifyhash{$context}{$role}{$item} = 1;
19915: } else {
19916: $modifyhash{$context}{$role}{$item} = 0;
19917: }
19918: }
19919: }
19920: if (ref($curr_usermodification{$context}) eq 'HASH') {
19921: foreach my $role (@{$roles{$context}}) {
19922: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
19923: foreach my $field (@fields) {
19924: if ($modifyhash{$context}{$role}{$field} ne
19925: $curr_usermodification{$context}{$role}{$field}) {
19926: push(@{$changes{$context}},$role);
19927: last;
19928: }
19929: }
19930: }
19931: }
19932: } else {
19933: foreach my $context (@contexts) {
19934: foreach my $role (@{$roles{$context}}) {
19935: push(@{$changes{$context}},$role);
19936: }
19937: }
19938: }
19939: }
19940: my %usermodification_hash = (
19941: usermodification => \%modifyhash,
19942: );
19943: my $putresult = &Apache::lonnet::put_dom('configuration',
19944: \%usermodification_hash,$dom);
19945: if ($putresult eq 'ok') {
19946: if (keys(%changes) > 0) {
19947: $resulttext = &mt('Changes made: ').'<ul>';
19948: foreach my $context (@contexts) {
19949: if (ref($changes{$context}) eq 'ARRAY') {
19950: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
19951: if (ref($changes{$context}) eq 'ARRAY') {
19952: foreach my $role (@{$changes{$context}}) {
19953: my $rolename;
1.224 raeburn 19954: if ($role eq 'cr') {
19955: $rolename = &mt('Custom');
1.33 raeburn 19956: } else {
1.224 raeburn 19957: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 19958: }
19959: my @modifiable;
1.224 raeburn 19960: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 19961: foreach my $field (@fields) {
19962: if ($modifyhash{$context}{$role}{$field}) {
19963: push(@modifiable,$fieldtitles{$field});
19964: }
19965: }
19966: if (@modifiable > 0) {
19967: $resulttext .= join(', ',@modifiable);
19968: } else {
19969: $resulttext .= &mt('none');
19970: }
19971: $resulttext .= '</li>';
19972: }
19973: $resulttext .= '</ul></li>';
19974: }
19975: }
19976: }
19977: $resulttext .= '</ul>';
19978: } else {
19979: $resulttext = &mt('No changes made to user modification settings');
19980: }
19981: } else {
19982: $resulttext = '<span class="LC_error">'.
19983: &mt('An error occurred: [_1]',$putresult).'</span>';
19984: }
19985: return $resulttext;
19986: }
19987:
1.43 raeburn 19988: sub modify_defaults {
1.212 raeburn 19989: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 19990: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 19991: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 19992: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 19993: 'portal_def');
1.325 raeburn 19994: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 19995: foreach my $item (@items) {
19996: $newvalues{$item} = $env{'form.'.$item};
19997: if ($item eq 'auth_def') {
19998: if ($newvalues{$item} ne '') {
19999: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
20000: push(@errors,$item);
20001: }
20002: }
20003: } elsif ($item eq 'lang_def') {
20004: if ($newvalues{$item} ne '') {
20005: if ($newvalues{$item} =~ /^(\w+)/) {
20006: my $langcode = $1;
1.103 raeburn 20007: if ($langcode ne 'x_chef') {
20008: if (code2language($langcode) eq '') {
20009: push(@errors,$item);
20010: }
1.43 raeburn 20011: }
20012: } else {
20013: push(@errors,$item);
20014: }
20015: }
1.54 raeburn 20016: } elsif ($item eq 'timezone_def') {
20017: if ($newvalues{$item} ne '') {
1.62 raeburn 20018: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 20019: push(@errors,$item);
20020: }
20021: }
1.68 raeburn 20022: } elsif ($item eq 'datelocale_def') {
20023: if ($newvalues{$item} ne '') {
20024: my @datelocale_ids = DateTime::Locale->ids();
20025: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
20026: push(@errors,$item);
20027: }
20028: }
1.141 raeburn 20029: } elsif ($item eq 'portal_def') {
20030: if ($newvalues{$item} ne '') {
1.414 raeburn 20031: 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])\/?$/) {
20032: foreach my $field ('email','web') {
20033: if ($env{'form.'.$item.'_'.$field}) {
20034: $newvalues{$item.'_'.$field} = $env{'form.'.$item.'_'.$field};
20035: }
20036: }
20037: } else {
1.141 raeburn 20038: push(@errors,$item);
20039: }
20040: }
1.43 raeburn 20041: }
20042: if (grep(/^\Q$item\E$/,@errors)) {
20043: $newvalues{$item} = $domdefaults{$item};
1.414 raeburn 20044: if ($item eq 'portal_def') {
20045: if ($domdefaults{$item}) {
20046: foreach my $field ('email','web') {
20047: if (exists($domdefaults{$item.'_'.$field})) {
20048: $newvalues{$item.'_'.$field} = $domdefaults{$item.'_'.$field};
20049: }
20050: }
20051: }
20052: }
1.43 raeburn 20053: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
20054: $changes{$item} = 1;
20055: }
1.414 raeburn 20056: if ($item eq 'portal_def') {
20057: unless (grep(/^\Q$item\E$/,@errors)) {
1.425 raeburn 20058: if ($newvalues{$item} eq '') {
1.414 raeburn 20059: foreach my $field ('email','web') {
20060: if (exists($domdefaults{$item.'_'.$field})) {
20061: delete($domdefaults{$item.'_'.$field});
20062: }
20063: }
20064: } else {
20065: unless ($changes{$item}) {
20066: foreach my $field ('email','web') {
20067: if ($domdefaults{$item.'_'.$field} ne $newvalues{$item.'_'.$field}) {
20068: $changes{$item} = 1;
20069: last;
20070: }
20071: }
20072: }
20073: foreach my $field ('email','web') {
20074: if ($newvalues{$item.'_'.$field}) {
20075: $domdefaults{$item.'_'.$field} = $newvalues{$item.'_'.$field};
20076: } elsif (exists($domdefaults{$item.'_'.$field})) {
20077: delete($domdefaults{$item.'_'.$field});
20078: }
20079: }
20080: }
20081: }
20082: }
1.72 raeburn 20083: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 20084: }
1.354 raeburn 20085: my %staticdefaults = (
20086: 'intauth_cost' => 10,
20087: 'intauth_check' => 0,
20088: 'intauth_switch' => 0,
20089: );
20090: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
20091: if (exists($domdefaults{$item})) {
20092: $newvalues{$item} = $domdefaults{$item};
20093: } else {
20094: $newvalues{$item} = $staticdefaults{$item};
20095: }
20096: }
1.409 raeburn 20097: my ($unamemaprules,$ruleorder);
20098: my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
20099: if (@possunamemaprules) {
20100: ($unamemaprules,$ruleorder) =
20101: &Apache::lonnet::inst_userrules($dom,'unamemap');
20102: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
20103: if (@{$ruleorder} > 0) {
20104: my %possrules;
20105: map { $possrules{$_} = 1; } @possunamemaprules;
20106: foreach my $rule (@{$ruleorder}) {
20107: if ($possrules{$rule}) {
20108: push(@{$newvalues{'unamemap_rule'}},$rule);
20109: }
20110: }
20111: }
20112: }
20113: }
20114: if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
20115: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20116: my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
20117: $newvalues{'unamemap_rule'});
20118: if (@rulediffs) {
20119: $changes{'unamemap_rule'} = 1;
20120: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
20121: }
20122: } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
20123: $changes{'unamemap_rule'} = 1;
20124: delete($domdefaults{'unamemap_rule'});
20125: }
20126: } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20127: if (@{$newvalues{'unamemap_rule'}} > 0) {
20128: $changes{'unamemap_rule'} = 1;
20129: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
20130: }
20131: }
1.43 raeburn 20132: my %defaults_hash = (
1.72 raeburn 20133: defaults => \%newvalues,
20134: );
1.43 raeburn 20135: my $title = &defaults_titles();
1.236 raeburn 20136:
20137: my $currinststatus;
20138: if (ref($domconfig{'inststatus'}) eq 'HASH') {
20139: $currinststatus = $domconfig{'inststatus'};
20140: } else {
20141: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
20142: $currinststatus = {
20143: inststatustypes => $usertypes,
20144: inststatusorder => $types,
20145: inststatusguest => [],
20146: };
20147: }
20148: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
20149: my @allpos;
20150: my %alltypes;
1.305 raeburn 20151: my @inststatusguest;
20152: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
20153: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
20154: unless (grep(/^\Q$type\E$/,@todelete)) {
20155: push(@inststatusguest,$type);
20156: }
20157: }
20158: }
20159: my ($currtitles,$currorder);
1.236 raeburn 20160: if (ref($currinststatus) eq 'HASH') {
20161: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
20162: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
20163: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
20164: if ($currinststatus->{inststatustypes}->{$type} ne '') {
20165: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
20166: }
20167: }
20168: unless (grep(/^\Q$type\E$/,@todelete)) {
20169: my $position = $env{'form.inststatus_pos_'.$type};
20170: $position =~ s/\D+//g;
20171: $allpos[$position] = $type;
20172: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
20173: $alltypes{$type} =~ s/`//g;
20174: }
20175: }
20176: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
20177: $currtitles =~ s/,$//;
20178: }
20179: }
20180: if ($env{'form.addinststatus'}) {
20181: my $newtype = $env{'form.addinststatus'};
20182: $newtype =~ s/\W//g;
20183: unless (exists($alltypes{$newtype})) {
20184: $alltypes{$newtype} = $env{'form.addinststatus_title'};
20185: $alltypes{$newtype} =~ s/`//g;
20186: my $position = $env{'form.addinststatus_pos'};
20187: $position =~ s/\D+//g;
20188: if ($position ne '') {
20189: $allpos[$position] = $newtype;
20190: }
20191: }
20192: }
1.305 raeburn 20193: my @orderedstatus;
1.236 raeburn 20194: foreach my $type (@allpos) {
20195: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
20196: push(@orderedstatus,$type);
20197: }
20198: }
20199: foreach my $type (keys(%alltypes)) {
20200: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
20201: delete($alltypes{$type});
20202: }
20203: }
20204: $defaults_hash{'inststatus'} = {
20205: inststatustypes => \%alltypes,
20206: inststatusorder => \@orderedstatus,
1.305 raeburn 20207: inststatusguest => \@inststatusguest,
1.236 raeburn 20208: };
20209: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
20210: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
20211: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
20212: }
20213: }
20214: if ($currorder ne join(',',@orderedstatus)) {
20215: $changes{'inststatus'}{'inststatusorder'} = 1;
20216: }
20217: my $newtitles;
20218: foreach my $item (@orderedstatus) {
20219: $newtitles .= $alltypes{$item}.',';
20220: }
20221: $newtitles =~ s/,$//;
20222: if ($currtitles ne $newtitles) {
20223: $changes{'inststatus'}{'inststatustypes'} = 1;
20224: }
1.43 raeburn 20225: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
20226: $dom);
20227: if ($putresult eq 'ok') {
20228: if (keys(%changes) > 0) {
20229: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 20230: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 20231: 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";
20232: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 20233: if ($item eq 'inststatus') {
20234: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 20235: if (@orderedstatus) {
1.236 raeburn 20236: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
20237: foreach my $type (@orderedstatus) {
20238: $resulttext .= $alltypes{$type}.', ';
20239: }
20240: $resulttext =~ s/, $//;
20241: $resulttext .= '</li>';
1.305 raeburn 20242: } else {
1.425 raeburn 20243: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 20244: }
20245: }
1.409 raeburn 20246: } elsif ($item eq 'unamemap_rule') {
20247: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20248: my @rulenames;
20249: if (ref($unamemaprules) eq 'HASH') {
20250: foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
20251: if (ref($unamemaprules->{$rule}) eq 'HASH') {
20252: push(@rulenames,$unamemaprules->{$rule}->{'name'});
20253: }
20254: }
20255: }
20256: if (@rulenames) {
20257: $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
20258: '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
20259: '</li>';
20260: } else {
20261: $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
20262: }
20263: } else {
20264: $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
20265: }
1.236 raeburn 20266: } else {
20267: my $value = $env{'form.'.$item};
20268: if ($value eq '') {
20269: $value = &mt('none');
20270: } elsif ($item eq 'auth_def') {
20271: my %authnames = &authtype_names();
20272: my %shortauth = (
20273: internal => 'int',
20274: krb4 => 'krb4',
20275: krb5 => 'krb5',
20276: localauth => 'loc',
1.325 raeburn 20277: lti => 'lti',
1.236 raeburn 20278: );
20279: $value = $authnames{$shortauth{$value}};
20280: }
20281: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
1.414 raeburn 20282: $mailmsgtext .= "$title->{$item} set to $value\n";
20283: if ($item eq 'portal_def') {
20284: if ($env{'form.'.$item} ne '') {
20285: foreach my $field ('email','web') {
20286: $value = $env{'form.'.$item.'_'.$field};
20287: if ($value) {
20288: $value = &mt('Yes');
20289: } else {
20290: $value = &mt('No');
20291: }
20292: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$field},$value).'</li>';
20293: }
20294: }
20295: }
1.43 raeburn 20296: }
20297: }
20298: $resulttext .= '</ul>';
20299: $mailmsgtext .= "\n";
20300: my $cachetime = 24*60*60;
1.72 raeburn 20301: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 20302: if (ref($lastactref) eq 'HASH') {
20303: $lastactref->{'domdefaults'} = 1;
20304: }
1.68 raeburn 20305: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 20306: my $notify = 1;
20307: if (ref($domconfig{'contacts'}) eq 'HASH') {
20308: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
20309: $notify = 0;
20310: }
20311: }
20312: if ($notify) {
20313: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
20314: "LON-CAPA Domain Settings Change - $dom",
20315: $mailmsgtext);
20316: }
1.54 raeburn 20317: }
1.43 raeburn 20318: } else {
1.54 raeburn 20319: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 20320: }
20321: } else {
20322: $resulttext = '<span class="LC_error">'.
20323: &mt('An error occurred: [_1]',$putresult).'</span>';
20324: }
20325: if (@errors > 0) {
20326: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
20327: foreach my $item (@errors) {
20328: $resulttext .= ' "'.$title->{$item}.'",';
20329: }
20330: $resulttext =~ s/,$//;
20331: }
20332: return $resulttext;
20333: }
20334:
1.46 raeburn 20335: sub modify_scantron {
1.205 raeburn 20336: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 20337: my ($resulttext,%confhash,%changes,$errors);
20338: my $custom = 'custom.tab';
20339: my $default = 'default.tab';
20340: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 20341: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 20342: &config_check($dom,$confname,$servadm);
20343: if ($env{'form.scantronformat.filename'} ne '') {
20344: my $error;
20345: if ($configuserok eq 'ok') {
20346: if ($switchserver) {
1.130 raeburn 20347: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 20348: } else {
20349: if ($author_ok eq 'ok') {
1.421 raeburn 20350: my $modified = [];
1.46 raeburn 20351: my ($result,$scantronurl) =
1.421 raeburn 20352: &Apache::lonconfigsettings::publishlogo($r,'upload','scantronformat',$dom,
20353: $confname,'scantron','','',$custom,
20354: $modified);
1.46 raeburn 20355: if ($result eq 'ok') {
20356: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 20357: $changes{'scantronformat'} = 1;
1.421 raeburn 20358: &update_modify_urls($r,$modified);
1.46 raeburn 20359: } else {
20360: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
20361: }
20362: } else {
20363: $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);
20364: }
20365: }
20366: } else {
20367: $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);
20368: }
20369: if ($error) {
20370: &Apache::lonnet::logthis($error);
20371: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
20372: }
20373: }
1.48 raeburn 20374: if (ref($domconfig{'scantron'}) eq 'HASH') {
20375: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
20376: if ($env{'form.scantronformat_del'}) {
20377: $confhash{'scantron'}{'scantronformat'} = '';
20378: $changes{'scantronformat'} = 1;
1.347 raeburn 20379: } else {
20380: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 20381: }
20382: }
20383: }
1.347 raeburn 20384: my @options = ('hdr','pad','rem');
1.346 raeburn 20385: my @fields = &scantroncsv_fields();
20386: my %titles = &scantronconfig_titles();
1.347 raeburn 20387: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 20388: my ($newdat,$currdat,%newcol,%currcol);
20389: if (grep(/^dat$/,@formats)) {
20390: $confhash{'scantron'}{config}{dat} = 1;
20391: $newdat = 1;
20392: } else {
20393: $newdat = 0;
20394: }
20395: if (grep(/^csv$/,@formats)) {
20396: my %bynum;
20397: foreach my $field (@fields) {
20398: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
20399: my $posscol = $1;
20400: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 20401: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 20402: $bynum{$posscol} = $field;
20403: $newcol{$field} = $posscol;
20404: }
20405: }
20406: }
1.347 raeburn 20407: if (keys(%newcol)) {
20408: foreach my $option (@options) {
20409: if ($env{'form.scantroncsv_'.$option}) {
20410: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
20411: }
20412: }
20413: }
1.346 raeburn 20414: }
20415: $currdat = 1;
20416: if (ref($domconfig{'scantron'}) eq 'HASH') {
20417: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 20418: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 20419: $currdat = 0;
20420: }
20421: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20422: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20423: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
20424: }
1.346 raeburn 20425: }
20426: }
20427: }
20428: if ($currdat != $newdat) {
20429: $changes{'config'} = 1;
20430: } else {
20431: foreach my $field (@fields) {
20432: if ($currcol{$field} ne '') {
20433: if ($currcol{$field} ne $newcol{$field}) {
20434: $changes{'config'} = 1;
20435: last;
1.347 raeburn 20436: }
1.346 raeburn 20437: } elsif ($newcol{$field} ne '') {
20438: $changes{'config'} = 1;
20439: last;
20440: }
20441: }
20442: }
1.46 raeburn 20443: if (keys(%confhash) > 0) {
20444: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
20445: $dom);
20446: if ($putresult eq 'ok') {
20447: if (keys(%changes) > 0) {
1.48 raeburn 20448: if (ref($confhash{'scantron'}) eq 'HASH') {
20449: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 20450: if ($changes{'scantronformat'}) {
20451: if ($confhash{'scantron'}{'scantronformat'} eq '') {
20452: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
20453: } else {
20454: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
20455: }
20456: }
1.347 raeburn 20457: if ($changes{'config'}) {
1.346 raeburn 20458: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
20459: if ($confhash{'scantron'}{'config'}{'dat'}) {
20460: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
20461: }
20462: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20463: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20464: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
20465: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
20466: foreach my $field (@fields) {
20467: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
20468: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
20469: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
20470: }
20471: }
20472: $resulttext .= '</ul></li>';
20473: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
20474: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
20475: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
20476: foreach my $option (@options) {
20477: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
20478: $resulttext .= '<li>'.$titles{$option}.'</li>';
20479: }
20480: }
20481: $resulttext .= '</ul></li>';
20482: }
1.346 raeburn 20483: }
20484: }
20485: }
20486: }
20487: } else {
20488: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
20489: }
1.46 raeburn 20490: }
1.48 raeburn 20491: $resulttext .= '</ul>';
20492: } else {
1.130 raeburn 20493: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 20494: }
20495: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 20496: if (ref($lastactref) eq 'HASH') {
20497: $lastactref->{'domainconfig'} = 1;
20498: }
1.46 raeburn 20499: } else {
1.346 raeburn 20500: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 20501: }
20502: } else {
20503: $resulttext = '<span class="LC_error">'.
20504: &mt('An error occurred: [_1]',$putresult).'</span>';
20505: }
20506: } else {
1.130 raeburn 20507: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 20508: }
20509: if ($errors) {
1.353 raeburn 20510: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
20511: $errors.'</ul></p>';
1.46 raeburn 20512: }
20513: return $resulttext;
20514: }
20515:
1.48 raeburn 20516: sub modify_coursecategories {
1.239 raeburn 20517: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 20518: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
20519: $cathash);
1.48 raeburn 20520: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 20521: my @catitems = ('unauth','auth');
20522: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 20523: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 20524: $cathash = $domconfig{'coursecategories'}{'cats'};
20525: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
20526: $changes{'togglecats'} = 1;
20527: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
20528: }
20529: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
20530: $changes{'categorize'} = 1;
20531: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
20532: }
1.120 raeburn 20533: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
20534: $changes{'togglecatscomm'} = 1;
20535: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
20536: }
20537: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
20538: $changes{'categorizecomm'} = 1;
20539: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 20540:
20541: }
20542: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
20543: $changes{'togglecatsplace'} = 1;
20544: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
20545: }
20546: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
20547: $changes{'categorizeplace'} = 1;
20548: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 20549: }
1.238 raeburn 20550: foreach my $item (@catitems) {
20551: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20552: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
20553: $changes{$item} = 1;
20554: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20555: }
20556: }
20557: }
1.57 raeburn 20558: } else {
20559: $changes{'togglecats'} = 1;
20560: $changes{'categorize'} = 1;
1.124 raeburn 20561: $changes{'togglecatscomm'} = 1;
20562: $changes{'categorizecomm'} = 1;
1.272 raeburn 20563: $changes{'togglecatsplace'} = 1;
20564: $changes{'categorizeplace'} = 1;
1.87 raeburn 20565: $domconfig{'coursecategories'} = {
20566: togglecats => $env{'form.togglecats'},
20567: categorize => $env{'form.categorize'},
1.124 raeburn 20568: togglecatscomm => $env{'form.togglecatscomm'},
20569: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 20570: togglecatsplace => $env{'form.togglecatsplace'},
20571: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 20572: };
1.238 raeburn 20573: foreach my $item (@catitems) {
20574: if ($env{'form.coursecat_'.$item} ne 'std') {
20575: $changes{$item} = 1;
20576: }
20577: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20578: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20579: }
20580: }
1.57 raeburn 20581: }
20582: if (ref($cathash) eq 'HASH') {
20583: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 20584: push (@deletecategory,'instcode::0');
20585: }
1.120 raeburn 20586: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
20587: push(@deletecategory,'communities::0');
20588: }
1.272 raeburn 20589: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
20590: push(@deletecategory,'placement::0');
20591: }
1.48 raeburn 20592: }
1.57 raeburn 20593: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
20594: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20595: if (@deletecategory > 0) {
20596: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 20597: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 20598: foreach my $item (@deletecategory) {
1.57 raeburn 20599: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
20600: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 20601: $deletions{$item} = 1;
1.57 raeburn 20602: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 20603: }
20604: }
20605: }
1.57 raeburn 20606: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 20607: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 20608: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 20609: $reorderings{$item} = 1;
1.57 raeburn 20610: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 20611: }
20612: if ($env{'form.addcategory_name_'.$item} ne '') {
20613: my $newcat = $env{'form.addcategory_name_'.$item};
20614: my $newdepth = $depth+1;
20615: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20616: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 20617: $adds{$newitem} = 1;
20618: }
20619: if ($env{'form.subcat_'.$item} ne '') {
20620: my $newcat = $env{'form.subcat_'.$item};
20621: my $newdepth = $depth+1;
20622: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20623: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 20624: $adds{$newitem} = 1;
20625: }
20626: }
20627: }
20628: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 20629: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20630: my $newitem = 'instcode::0';
1.57 raeburn 20631: if ($cathash->{$newitem} eq '') {
20632: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20633: $adds{$newitem} = 1;
20634: }
20635: } else {
20636: my $newitem = 'instcode::0';
1.57 raeburn 20637: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20638: $adds{$newitem} = 1;
20639: }
20640: }
1.120 raeburn 20641: if ($env{'form.communities'} eq '1') {
20642: if (ref($cathash) eq 'HASH') {
20643: my $newitem = 'communities::0';
20644: if ($cathash->{$newitem} eq '') {
20645: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20646: $adds{$newitem} = 1;
20647: }
20648: } else {
20649: my $newitem = 'communities::0';
20650: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20651: $adds{$newitem} = 1;
20652: }
20653: }
1.272 raeburn 20654: if ($env{'form.placement'} eq '1') {
20655: if (ref($cathash) eq 'HASH') {
20656: my $newitem = 'placement::0';
20657: if ($cathash->{$newitem} eq '') {
20658: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20659: $adds{$newitem} = 1;
20660: }
20661: } else {
20662: my $newitem = 'placement::0';
20663: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20664: $adds{$newitem} = 1;
20665: }
20666: }
1.48 raeburn 20667: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 20668: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 20669: ($env{'form.addcategory_name'} ne 'communities') &&
20670: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 20671: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
20672: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
20673: $adds{$newitem} = 1;
20674: }
1.48 raeburn 20675: }
1.57 raeburn 20676: my $putresult;
1.48 raeburn 20677: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20678: if (keys(%deletions) > 0) {
20679: foreach my $key (keys(%deletions)) {
20680: if ($predelallitems{$key} ne '') {
20681: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
20682: }
20683: }
20684: }
20685: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 20686: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 20687: if (ref($chkcats[0]) eq 'ARRAY') {
20688: my $depth = 0;
20689: my $chg = 0;
20690: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
20691: my $name = $chkcats[0][$i];
20692: my $item;
20693: if ($name eq '') {
20694: $chg ++;
20695: } else {
20696: $item = &escape($name).'::0';
20697: if ($chg) {
1.57 raeburn 20698: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 20699: }
20700: $depth ++;
1.57 raeburn 20701: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 20702: $depth --;
20703: }
20704: }
20705: }
1.57 raeburn 20706: }
20707: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20708: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 20709: if ($putresult eq 'ok') {
1.57 raeburn 20710: my %title = (
1.120 raeburn 20711: togglecats => 'Show/Hide a course in catalog',
20712: categorize => 'Assign a category to a course',
20713: togglecatscomm => 'Show/Hide a community in catalog',
20714: categorizecomm => 'Assign a category to a community',
1.57 raeburn 20715: );
20716: my %level = (
1.120 raeburn 20717: dom => 'set in Domain ("Modify Course/Community")',
20718: crs => 'set in Course ("Course Configuration")',
20719: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 20720: none => 'No catalog',
20721: std => 'Standard catalog',
20722: domonly => 'Domain-only catalog',
20723: codesrch => 'Code search form',
1.57 raeburn 20724: );
1.48 raeburn 20725: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 20726: if ($changes{'togglecats'}) {
20727: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
20728: }
20729: if ($changes{'categorize'}) {
20730: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 20731: }
1.120 raeburn 20732: if ($changes{'togglecatscomm'}) {
20733: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
20734: }
20735: if ($changes{'categorizecomm'}) {
20736: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
20737: }
1.238 raeburn 20738: if ($changes{'unauth'}) {
20739: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
20740: }
20741: if ($changes{'auth'}) {
20742: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
20743: }
1.57 raeburn 20744: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20745: my $cathash;
20746: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
20747: $cathash = $domconfig{'coursecategories'}{'cats'};
20748: } else {
20749: $cathash = {};
20750: }
20751: my (@cats,@trails,%allitems);
20752: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
20753: if (keys(%deletions) > 0) {
20754: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
20755: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
20756: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
20757: }
20758: $resulttext .= '</ul></li>';
20759: }
20760: if (keys(%reorderings) > 0) {
20761: my %sort_by_trail;
20762: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
20763: foreach my $key (keys(%reorderings)) {
20764: if ($allitems{$key} ne '') {
20765: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20766: }
1.48 raeburn 20767: }
1.57 raeburn 20768: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20769: $resulttext .= '<li>'.$trails[$trail].'</li>';
20770: }
20771: $resulttext .= '</ul></li>';
1.48 raeburn 20772: }
1.57 raeburn 20773: if (keys(%adds) > 0) {
20774: my %sort_by_trail;
20775: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
20776: foreach my $key (keys(%adds)) {
20777: if ($allitems{$key} ne '') {
20778: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20779: }
20780: }
20781: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20782: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 20783: }
1.57 raeburn 20784: $resulttext .= '</ul></li>';
1.48 raeburn 20785: }
1.364 raeburn 20786: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
20787: if (ref($lastactref) eq 'HASH') {
20788: $lastactref->{'cats'} = 1;
20789: }
1.48 raeburn 20790: }
20791: $resulttext .= '</ul>';
1.239 raeburn 20792: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 20793: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
20794: if ($changes{'auth'}) {
20795: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
20796: }
20797: if ($changes{'unauth'}) {
20798: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
20799: }
20800: my $cachetime = 24*60*60;
20801: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 20802: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 20803: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 20804: }
20805: }
1.48 raeburn 20806: } else {
20807: $resulttext = '<span class="LC_error">'.
1.57 raeburn 20808: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 20809: }
20810: } else {
1.120 raeburn 20811: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 20812: }
20813: return $resulttext;
20814: }
20815:
1.69 raeburn 20816: sub modify_serverstatuses {
20817: my ($dom,%domconfig) = @_;
20818: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
20819: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
20820: %currserverstatus = %{$domconfig{'serverstatuses'}};
20821: }
20822: my @pages = &serverstatus_pages();
20823: foreach my $type (@pages) {
20824: $newserverstatus{$type}{'namedusers'} = '';
20825: $newserverstatus{$type}{'machines'} = '';
20826: if (defined($env{'form.'.$type.'_namedusers'})) {
20827: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
20828: my @okusers;
20829: foreach my $user (@users) {
20830: my ($uname,$udom) = split(/:/,$user);
20831: if (($udom =~ /^$match_domain$/) &&
20832: (&Apache::lonnet::domain($udom)) &&
20833: ($uname =~ /^$match_username$/)) {
20834: if (!grep(/^\Q$user\E/,@okusers)) {
20835: push(@okusers,$user);
20836: }
20837: }
20838: }
20839: if (@okusers > 0) {
20840: @okusers = sort(@okusers);
20841: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
20842: }
20843: }
20844: if (defined($env{'form.'.$type.'_machines'})) {
20845: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
20846: my @okmachines;
20847: foreach my $ip (@machines) {
20848: my @parts = split(/\./,$ip);
20849: next if (@parts < 4);
20850: my $badip = 0;
20851: for (my $i=0; $i<4; $i++) {
20852: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
20853: $badip = 1;
20854: last;
20855: }
20856: }
20857: if (!$badip) {
20858: push(@okmachines,$ip);
20859: }
20860: }
20861: @okmachines = sort(@okmachines);
20862: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
20863: }
20864: }
20865: my %serverstatushash = (
20866: serverstatuses => \%newserverstatus,
20867: );
20868: foreach my $type (@pages) {
1.83 raeburn 20869: foreach my $setting ('namedusers','machines') {
1.84 raeburn 20870: my (@current,@new);
1.83 raeburn 20871: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 20872: if ($currserverstatus{$type}{$setting} ne '') {
20873: @current = split(/,/,$currserverstatus{$type}{$setting});
20874: }
20875: }
20876: if ($newserverstatus{$type}{$setting} ne '') {
20877: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 20878: }
20879: if (@current > 0) {
20880: if (@new > 0) {
20881: foreach my $item (@current) {
20882: if (!grep(/^\Q$item\E$/,@new)) {
20883: $changes{$type}{$setting} = 1;
1.82 raeburn 20884: last;
20885: }
20886: }
1.84 raeburn 20887: foreach my $item (@new) {
20888: if (!grep(/^\Q$item\E$/,@current)) {
20889: $changes{$type}{$setting} = 1;
20890: last;
1.82 raeburn 20891: }
20892: }
20893: } else {
1.83 raeburn 20894: $changes{$type}{$setting} = 1;
1.69 raeburn 20895: }
1.83 raeburn 20896: } elsif (@new > 0) {
20897: $changes{$type}{$setting} = 1;
1.69 raeburn 20898: }
20899: }
20900: }
20901: if (keys(%changes) > 0) {
1.81 raeburn 20902: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 20903: my $putresult = &Apache::lonnet::put_dom('configuration',
20904: \%serverstatushash,$dom);
20905: if ($putresult eq 'ok') {
20906: $resulttext .= &mt('Changes made:').'<ul>';
20907: foreach my $type (@pages) {
1.84 raeburn 20908: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 20909: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 20910: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 20911: if ($newserverstatus{$type}{'namedusers'} eq '') {
20912: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
20913: } else {
20914: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
20915: }
1.84 raeburn 20916: }
20917: if ($changes{$type}{'machines'}) {
1.69 raeburn 20918: if ($newserverstatus{$type}{'machines'} eq '') {
20919: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
20920: } else {
20921: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
20922: }
20923:
20924: }
20925: $resulttext .= '</ul></li>';
20926: }
20927: }
20928: $resulttext .= '</ul>';
20929: } else {
20930: $resulttext = '<span class="LC_error">'.
20931: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
20932:
20933: }
20934: } else {
20935: $resulttext = &mt('No changes made to access to server status pages');
20936: }
20937: return $resulttext;
20938: }
20939:
1.118 jms 20940: sub modify_helpsettings {
1.285 raeburn 20941: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 20942: my ($resulttext,$errors,%changes,%helphash);
20943: my %defaultchecked = ('submitbugs' => 'on');
20944: my @offon = ('off','on');
1.118 jms 20945: my @toggles = ('submitbugs');
1.285 raeburn 20946: my %current = ('submitbugs' => '',
20947: 'adhoc' => {},
20948: );
1.118 jms 20949: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 20950: %current = %{$domconfig{'helpsettings'}};
20951: }
1.285 raeburn 20952: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 20953: foreach my $item (@toggles) {
20954: if ($defaultchecked{$item} eq 'on') {
20955: if ($current{$item} eq '') {
20956: if ($env{'form.'.$item} eq '0') {
20957: $changes{$item} = 1;
20958: }
20959: } elsif ($current{$item} ne $env{'form.'.$item}) {
20960: $changes{$item} = 1;
20961: }
20962: } elsif ($defaultchecked{$item} eq 'off') {
20963: if ($current{$item} eq '') {
20964: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 20965: $changes{$item} = 1;
20966: }
1.282 raeburn 20967: } elsif ($current{$item} ne $env{'form.'.$item}) {
20968: $changes{$item} = 1;
20969: }
20970: }
20971: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
20972: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
20973: }
20974: }
1.285 raeburn 20975: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 20976: my $confname = $dom.'-domainconfig';
20977: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 20978: my (@allpos,%newsettings,%changedprivs,$newrole);
20979: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 20980: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 20981: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 20982: my %lt = &Apache::lonlocal::texthash(
20983: s => 'system',
20984: d => 'domain',
20985: order => 'Display order',
20986: access => 'Role usage',
1.291 raeburn 20987: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 20988: dh => 'All with domain helpdesk role',
20989: da => 'All with domain helpdesk assistant role',
1.285 raeburn 20990: none => 'None',
20991: status => 'Determined based on institutional status',
20992: inc => 'Include all, but exclude specific personnel',
20993: exc => 'Exclude all, but include specific personnel',
20994: );
20995: for (my $num=0; $num<=$maxnum; $num++) {
20996: my ($prefix,$identifier,$rolename,%curr);
20997: if ($num == $maxnum) {
20998: next unless ($env{'form.newcusthelp'} == $maxnum);
20999: $identifier = 'custhelp'.$num;
21000: $prefix = 'helproles_'.$num;
21001: $rolename = $env{'form.custhelpname'.$num};
21002: $rolename=~s/[^A-Za-z0-9]//gs;
21003: next if ($rolename eq '');
21004: next if (exists($existing{'rolesdef_'.$rolename}));
21005: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
21006: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
21007: $newprivs{'c'},$confname,$dom);
21008: if ($result ne 'ok') {
21009: $errors .= '<li><span class="LC_error">'.
21010: &mt('An error occurred storing the new custom role: [_1]',
21011: $result).'</span></li>';
21012: next;
21013: } else {
21014: $changedprivs{$rolename} = \%newprivs;
21015: $newrole = $rolename;
21016: }
21017: } else {
21018: $prefix = 'helproles_'.$num;
21019: $rolename = $env{'form.'.$prefix};
21020: next if ($rolename eq '');
21021: next unless (exists($existing{'rolesdef_'.$rolename}));
21022: $identifier = 'custhelp'.$num;
21023: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
21024: my %currprivs;
1.289 raeburn 21025: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 21026: split(/\_/,$existing{'rolesdef_'.$rolename});
21027: foreach my $level ('c','d','s') {
21028: if ($newprivs{$level} ne $currprivs{$level}) {
21029: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
21030: $newprivs{'c'},$confname,$dom);
21031: if ($result ne 'ok') {
21032: $errors .= '<li><span class="LC_error">'.
21033: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
21034: $rolename,$result).'</span></li>';
21035: } else {
21036: $changedprivs{$rolename} = \%newprivs;
21037: }
21038: last;
21039: }
21040: }
21041: if (ref($current{'adhoc'}) eq 'HASH') {
21042: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
21043: %curr = %{$current{'adhoc'}{$rolename}};
21044: }
21045: }
21046: }
21047: my $newpos = $env{'form.'.$prefix.'_pos'};
21048: $newpos =~ s/\D+//g;
21049: $allpos[$newpos] = $rolename;
21050: my $newdesc = $env{'form.'.$prefix.'_desc'};
21051: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
21052: if ($curr{'desc'}) {
21053: if ($curr{'desc'} ne $newdesc) {
21054: $changes{'customrole'}{$rolename}{'desc'} = 1;
21055: $newsettings{$rolename}{'desc'} = $newdesc;
21056: }
21057: } elsif ($newdesc ne '') {
21058: $changes{'customrole'}{$rolename}{'desc'} = 1;
21059: $newsettings{$rolename}{'desc'} = $newdesc;
21060: }
21061: my $access = $env{'form.'.$prefix.'_access'};
21062: if (grep(/^\Q$access\E$/,@accesstypes)) {
21063: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
21064: if ($access eq 'status') {
21065: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
21066: if (scalar(@statuses) == 0) {
1.289 raeburn 21067: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 21068: } else {
21069: my (@shownstatus,$numtypes);
21070: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
21071: if (ref($types) eq 'ARRAY') {
21072: $numtypes = scalar(@{$types});
21073: foreach my $type (sort(@statuses)) {
21074: if ($type eq 'default') {
21075: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
21076: } elsif (grep(/^\Q$type\E$/,@{$types})) {
21077: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
21078: push(@shownstatus,$usertypes->{$type});
21079: }
21080: }
21081: }
21082: if (grep(/^default$/,@statuses)) {
21083: push(@shownstatus,$othertitle);
21084: }
21085: if (scalar(@shownstatus) == 1+$numtypes) {
21086: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
21087: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
21088: } else {
21089: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
21090: if (ref($curr{'status'}) eq 'ARRAY') {
21091: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
21092: if (@diffs) {
21093: $changes{'customrole'}{$rolename}{$access} = 1;
21094: }
21095: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21096: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 21097: }
1.166 raeburn 21098: }
21099: }
1.285 raeburn 21100: } elsif (($access eq 'inc') || ($access eq 'exc')) {
21101: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
21102: my @newspecstaff;
21103: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
21104: foreach my $person (sort(@personnel)) {
21105: if ($domhelpdesk{$person}) {
21106: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
21107: }
21108: }
21109: if (ref($curr{$access}) eq 'ARRAY') {
21110: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
21111: if (@diffs) {
21112: $changes{'customrole'}{$rolename}{$access} = 1;
21113: }
21114: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21115: $changes{'customrole'}{$rolename}{$access} = 1;
21116: }
21117: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21118: my ($uname,$udom) = split(/:/,$person);
21119: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
21120: }
21121: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 21122: }
1.285 raeburn 21123: } else {
21124: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
21125: }
21126: unless ($curr{'access'} eq $access) {
21127: $changes{'customrole'}{$rolename}{'access'} = 1;
21128: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 21129: }
21130: }
1.285 raeburn 21131: if (@allpos > 0) {
21132: my $idx = 0;
21133: foreach my $rolename (@allpos) {
21134: if ($rolename ne '') {
21135: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
21136: if (ref($current{'adhoc'}) eq 'HASH') {
21137: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
21138: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
21139: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 21140: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 21141: }
21142: }
1.282 raeburn 21143: }
1.285 raeburn 21144: $idx ++;
1.166 raeburn 21145: }
21146: }
1.118 jms 21147: }
1.123 jms 21148: my $putresult;
21149: if (keys(%changes) > 0) {
1.166 raeburn 21150: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 21151: if ($putresult eq 'ok') {
1.285 raeburn 21152: if (ref($helphash{'helpsettings'}) eq 'HASH') {
21153: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
21154: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
21155: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
21156: }
21157: }
21158: my $cachetime = 24*60*60;
21159: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21160: if (ref($lastactref) eq 'HASH') {
21161: $lastactref->{'domdefaults'} = 1;
21162: }
21163: } else {
21164: $errors .= '<li><span class="LC_error">'.
21165: &mt('An error occurred storing the settings: [_1]',
21166: $putresult).'</span></li>';
21167: }
21168: }
21169: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
21170: $resulttext = &mt('Changes made:').'<ul>';
21171: my (%shownprivs,@levelorder);
21172: @levelorder = ('c','d','s');
21173: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 21174: foreach my $item (sort(keys(%changes))) {
21175: if ($item eq 'submitbugs') {
21176: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
21177: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
21178: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 21179: } elsif ($item eq 'customrole') {
21180: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 21181: my @keyorder = ('order','desc','access','status','exc','inc');
21182: my %keytext = &Apache::lonlocal::texthash(
21183: order => 'Order',
21184: desc => 'Role description',
21185: access => 'Role usage',
1.300 droeschl 21186: status => 'Allowed institutional types',
1.285 raeburn 21187: exc => 'Allowed personnel',
21188: inc => 'Disallowed personnel',
21189: );
1.282 raeburn 21190: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 21191: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
21192: if ($role eq $newrole) {
21193: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
21194: $role).'<ul>';
21195: } else {
21196: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
21197: $role).'<ul>';
21198: }
21199: foreach my $key (@keyorder) {
21200: if ($changes{'customrole'}{$role}{$key}) {
21201: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
21202: $keytext{$key},$newsettings{$role}{$key}).
21203: '</li>';
21204: }
21205: }
21206: if (ref($changedprivs{$role}) eq 'HASH') {
21207: $shownprivs{$role} = 1;
21208: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
21209: foreach my $level (@levelorder) {
21210: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
21211: next if ($item eq '');
21212: my ($priv) = split(/\&/,$item,2);
21213: if (&Apache::lonnet::plaintext($priv)) {
21214: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
21215: unless ($level eq 'c') {
21216: $resulttext .= ' ('.$lt{$level}.')';
21217: }
21218: $resulttext .= '</li>';
21219: }
21220: }
21221: }
21222: $resulttext .= '</ul>';
21223: }
21224: $resulttext .= '</ul></li>';
21225: }
21226: }
21227: }
21228: }
21229: }
21230: }
21231: if (keys(%changedprivs)) {
21232: foreach my $role (sort(keys(%changedprivs))) {
21233: unless ($shownprivs{$role}) {
21234: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
21235: $role).'<ul>'.
21236: '<li>'.&mt('Privileges set to :').'<ul>';
21237: foreach my $level (@levelorder) {
21238: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
21239: next if ($item eq '');
21240: my ($priv) = split(/\&/,$item,2);
21241: if (&Apache::lonnet::plaintext($priv)) {
21242: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
21243: unless ($level eq 'c') {
21244: $resulttext .= ' ('.$lt{$level}.')';
21245: }
21246: $resulttext .= '</li>';
21247: }
1.282 raeburn 21248: }
21249: }
1.285 raeburn 21250: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 21251: }
21252: }
21253: }
1.285 raeburn 21254: $resulttext .= '</ul>';
21255: } else {
21256: $resulttext = &mt('No changes made to help settings');
1.118 jms 21257: }
21258: if ($errors) {
1.168 raeburn 21259: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 21260: $errors.'</ul>';
1.118 jms 21261: }
21262: return $resulttext;
21263: }
21264:
1.121 raeburn 21265: sub modify_coursedefaults {
1.212 raeburn 21266: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 21267: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 21268: my %defaultchecked = (
21269: 'canuse_pdfforms' => 'off',
21270: 'uselcmath' => 'on',
1.398 raeburn 21271: 'usejsme' => 'on',
21272: 'inline_chem' => 'on',
1.404 raeburn 21273: 'ltiauth' => 'off',
1.257 raeburn 21274: );
1.404 raeburn 21275: my @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem','ltiauth');
1.198 raeburn 21276: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 21277: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
1.428 raeburn 21278: 'coursequota_official','coursequota_unofficial','coursequota_community',
21279: 'coursequota_textbook','coursequota_placement','mysqltables_official',
21280: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook',
21281: 'mysqltables_placement');
1.271 raeburn 21282: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 21283: my %staticdefaults = (
21284: anonsurvey_threshold => 10,
21285: uploadquota => 500,
1.428 raeburn 21286: coursequota => 20,
1.257 raeburn 21287: postsubmit => 60,
1.276 raeburn 21288: mysqltables => 172800,
1.422 raeburn 21289: domexttool => 1,
1.432 raeburn 21290: crsauthor => 1,
1.438 raeburn 21291: crseditors => ['edit','xml'],
1.198 raeburn 21292: );
1.314 raeburn 21293: my %texoptions = (
21294: MathJax => 'MathJax',
21295: mimetex => &mt('Convert to Images'),
21296: tth => &mt('TeX to HTML'),
21297: );
1.438 raeburn 21298:
21299: my @editors = ('edit','xml','daxe');
21300: my %editornames = &crseditor_titles();
21301:
1.121 raeburn 21302: $defaultshash{'coursedefaults'} = {};
21303:
21304: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
21305: if ($domconfig{'coursedefaults'} eq '') {
21306: $domconfig{'coursedefaults'} = {};
21307: }
21308: }
21309:
21310: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
21311: foreach my $item (@toggles) {
21312: if ($defaultchecked{$item} eq 'on') {
21313: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21314: ($env{'form.'.$item} eq '0')) {
21315: $changes{$item} = 1;
1.192 raeburn 21316: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 21317: $changes{$item} = 1;
21318: }
21319: } elsif ($defaultchecked{$item} eq 'off') {
21320: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21321: ($env{'form.'.$item} eq '1')) {
21322: $changes{$item} = 1;
21323: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
21324: $changes{$item} = 1;
21325: }
21326: }
21327: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
21328: }
1.198 raeburn 21329: foreach my $item (@numbers) {
21330: my ($currdef,$newdef);
1.208 raeburn 21331: $newdef = $env{'form.'.$item};
1.198 raeburn 21332: if ($item eq 'anonsurvey_threshold') {
21333: $currdef = $domconfig{'coursedefaults'}{$item};
21334: $newdef =~ s/\D//g;
21335: if ($newdef eq '' || $newdef < 1) {
21336: $newdef = 1;
21337: }
21338: $defaultshash{'coursedefaults'}{$item} = $newdef;
21339: } else {
1.428 raeburn 21340: my ($setting,$type) = ($item =~ /^(uploadquota|coursequota|mysqltables)_(\w+)$/);
1.276 raeburn 21341: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
21342: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 21343: }
21344: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 21345: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 21346: }
21347: if ($currdef ne $newdef) {
21348: if ($item eq 'anonsurvey_threshold') {
21349: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
21350: $changes{$item} = 1;
21351: }
1.428 raeburn 21352: } elsif ($item =~ /^(uploadquota|coursequota|mysqltables)_/) {
1.289 raeburn 21353: my $setting = $1;
1.276 raeburn 21354: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
21355: $changes{$setting} = 1;
1.198 raeburn 21356: }
21357: }
1.139 raeburn 21358: }
21359: }
1.314 raeburn 21360: my $texengine;
21361: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
21362: $texengine = $env{'form.texengine'};
1.349 raeburn 21363: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
21364: if ($currdef eq '') {
21365: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 21366: $changes{'texengine'} = 1;
21367: }
1.349 raeburn 21368: } elsif ($currdef ne $texengine) {
1.314 raeburn 21369: $changes{'texengine'} = 1;
21370: }
21371: }
21372: if ($texengine ne '') {
21373: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
21374: }
1.264 raeburn 21375: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
21376: my @currclonecode;
21377: if (ref($currclone) eq 'HASH') {
21378: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
21379: @currclonecode = @{$currclone->{'instcode'}};
21380: }
21381: }
21382: my $newclone;
1.289 raeburn 21383: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 21384: $newclone = $env{'form.canclone'};
21385: }
21386: if ($newclone eq 'instcode') {
21387: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
21388: my (%codedefaults,@code_order,@clonecode);
21389: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
21390: \@code_order);
21391: foreach my $item (@code_order) {
21392: if (grep(/^\Q$item\E$/,@newcodes)) {
21393: push(@clonecode,$item);
21394: }
21395: }
21396: if (@clonecode) {
21397: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
21398: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
21399: if (@diffs) {
21400: $changes{'canclone'} = 1;
21401: }
21402: } else {
21403: $newclone eq '';
21404: }
21405: } elsif ($newclone ne '') {
1.289 raeburn 21406: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
21407: }
1.264 raeburn 21408: if ($newclone ne $currclone) {
21409: $changes{'canclone'} = 1;
21410: }
1.257 raeburn 21411: my %credits;
21412: foreach my $type (@types) {
21413: unless ($type eq 'community') {
21414: $credits{$type} = $env{'form.'.$type.'_credits'};
21415: $credits{$type} =~ s/[^\d.]+//g;
21416: }
21417: }
21418: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
21419: ($env{'form.coursecredits'} eq '1')) {
21420: $changes{'coursecredits'} = 1;
21421: foreach my $type (keys(%credits)) {
21422: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21423: }
21424: } else {
1.289 raeburn 21425: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 21426: foreach my $type (@types) {
21427: unless ($type eq 'community') {
1.289 raeburn 21428: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 21429: $changes{'coursecredits'} = 1;
21430: }
21431: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21432: }
21433: }
21434: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21435: foreach my $type (@types) {
21436: unless ($type eq 'community') {
21437: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
21438: $changes{'coursecredits'} = 1;
21439: last;
21440: }
21441: }
21442: }
21443: }
21444: }
21445: if ($env{'form.postsubmit'} eq '1') {
21446: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
21447: my %currtimeout;
21448: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21449: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
21450: $changes{'postsubmit'} = 1;
21451: }
21452: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21453: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
21454: }
21455: } else {
21456: $changes{'postsubmit'} = 1;
21457: }
21458: foreach my $type (@types) {
21459: my $timeout = $env{'form.'.$type.'_timeout'};
21460: $timeout =~ s/\D//g;
21461: if ($timeout == $staticdefaults{'postsubmit'}) {
21462: $timeout = '';
21463: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
21464: $timeout = '0';
21465: }
21466: unless ($timeout eq '') {
21467: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
21468: }
21469: if (exists($currtimeout{$type})) {
21470: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 21471: $changes{'postsubmit'} = 1;
1.257 raeburn 21472: }
21473: } elsif ($timeout ne '') {
21474: $changes{'postsubmit'} = 1;
21475: }
21476: }
21477: } else {
21478: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
21479: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21480: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
21481: $changes{'postsubmit'} = 1;
21482: }
21483: } else {
21484: $changes{'postsubmit'} = 1;
21485: }
1.192 raeburn 21486: }
1.438 raeburn 21487: my (%newdomexttool,%newexttool,%newcrsauthor,%olddomexttool,%oldexttool,%oldcrsauthor,
21488: %posscrseditors);
1.422 raeburn 21489: map { $newdomexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.domexttool');
1.425 raeburn 21490: map { $newexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.exttool');
1.432 raeburn 21491: map { $newcrsauthor{$_} = 1; } &Apache::loncommon::get_env_multiple('form.crsauthor');
1.438 raeburn 21492: map { $posscrseditors{$_} = 1; } &Apache::loncommon::get_env_multiple('form.crseditors');
1.422 raeburn 21493: if (ref($domconfig{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21494: %olddomexttool = %{$domconfig{'coursedefaults'}{'domexttool'}};
21495: } else {
21496: foreach my $type (@types) {
21497: if ($staticdefaults{'domexttool'}) {
21498: $olddomexttool{$type} = 1;
21499: } else {
21500: $olddomexttool{$type} = 0;
21501: }
21502: }
21503: }
21504: if (ref($domconfig{'coursedefaults'}{'exttool'}) eq 'HASH') {
1.425 raeburn 21505: %oldexttool = %{$domconfig{'coursedefaults'}{'exttool'}};
1.422 raeburn 21506: } else {
21507: foreach my $type (@types) {
21508: if ($staticdefaults{'exttool'}) {
21509: $oldexttool{$type} = 1;
21510: } else {
21511: $oldexttool{$type} = 0;
21512: }
21513: }
21514: }
1.432 raeburn 21515: if (ref($domconfig{'coursedefaults'}{'crsauthor'}) eq 'HASH') {
21516: %oldcrsauthor = %{$domconfig{'coursedefaults'}{'crsauthor'}};
21517: } else {
21518: foreach my $type (@types) {
21519: if ($staticdefaults{'crsauthor'}) {
21520: $oldcrsauthor{$type} = 1;
21521: } else {
21522: $oldcrsauthor{$type} = 0;
21523: }
21524: }
21525: }
1.438 raeburn 21526: my @newcrseditors = ();
21527: foreach my $editor (@editors) {
21528: if ($posscrseditors{$editor}) {
21529: push(@newcrseditors,$editor);
21530: }
21531: }
21532: if (ref($domconfig{'coursedefaults'}{'crseditors'}) eq 'ARRAY') {
21533: my @diffs =
21534: &Apache::loncommon::compare_arrays($domconfig{'coursedefaults'}{'crseditors'},
21535: \@newcrseditors);
21536: if (@diffs) {
21537: $changes{'crseditors'} = 1;
21538: }
21539: } else {
21540: my @diffs =
21541: &Apache::loncommon::compare_arrays($staticdefaults{'crseditors'},
21542: \@newcrseditors);
21543: unless (@diffs == 0) {
21544: $changes{'crseditors'} = 1;
21545: }
21546: }
1.422 raeburn 21547: foreach my $type (@types) {
21548: unless ($newdomexttool{$type}) {
21549: $newdomexttool{$type} = 0;
21550: }
21551: unless ($newexttool{$type}) {
21552: $newexttool{$type} = 0;
21553: }
1.432 raeburn 21554: unless ($newcrsauthor{$type}) {
21555: $newcrsauthor{$type} = 0;
21556: }
1.422 raeburn 21557: if ($newdomexttool{$type} != $olddomexttool{$type}) {
21558: $changes{'domexttool'} = 1;
21559: }
21560: if ($newexttool{$type} != $oldexttool{$type}) {
21561: $changes{'exttool'} = 1;
21562: }
1.432 raeburn 21563: if ($newcrsauthor{$type} != $oldcrsauthor{$type}) {
21564: $changes{'crsauthor'} = 1;
21565: }
1.422 raeburn 21566: }
21567: $defaultshash{'coursedefaults'}{'domexttool'} = \%newdomexttool;
21568: $defaultshash{'coursedefaults'}{'exttool'} = \%newexttool;
1.432 raeburn 21569: $defaultshash{'coursedefaults'}{'crsauthor'} = \%newcrsauthor;
1.438 raeburn 21570: $defaultshash{'coursedefaults'}{'crseditors'} = \@newcrseditors;
1.121 raeburn 21571: }
21572: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21573: $dom);
21574: if ($putresult eq 'ok') {
21575: if (keys(%changes) > 0) {
1.213 raeburn 21576: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 21577: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 21578: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.398 raeburn 21579: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
1.422 raeburn 21580: ($changes{'inline_chem'}) || ($changes{'ltiauth'}) || ($changes{'domexttool'}) ||
1.432 raeburn 21581: ($changes{'exttool'}) || ($changes{'coursequota'}) || ($changes{'crsauthor'})) {
1.422 raeburn 21582: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','inline_chem','texengine',
21583: 'ltiauth') {
1.257 raeburn 21584: if ($changes{$item}) {
21585: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
21586: }
1.289 raeburn 21587: }
1.192 raeburn 21588: if ($changes{'coursecredits'}) {
21589: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 21590: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
21591: $domdefaults{$type.'credits'} =
21592: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
21593: }
21594: }
21595: }
21596: if ($changes{'postsubmit'}) {
21597: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21598: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
21599: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21600: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
21601: $domdefaults{$type.'postsubtimeout'} =
21602: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21603: }
21604: }
1.192 raeburn 21605: }
21606: }
1.198 raeburn 21607: if ($changes{'uploadquota'}) {
21608: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21609: foreach my $type (@types) {
21610: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
21611: }
21612: }
21613: }
1.428 raeburn 21614: if ($changes{'coursequota'}) {
21615: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
21616: foreach my $type (@types) {
21617: $domdefaults{$type.'coursequota'}=$defaultshash{'coursedefaults'}{'coursequota'}{$type};
21618: }
21619: }
21620: }
1.264 raeburn 21621: if ($changes{'canclone'}) {
21622: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21623: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21624: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
21625: if (@clonecodes) {
21626: $domdefaults{'canclone'} = join('+',@clonecodes);
21627: }
21628: }
21629: } else {
21630: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
21631: }
21632: }
1.422 raeburn 21633: if ($changes{'domexttool'}) {
21634: if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21635: foreach my $type (@types) {
21636: $domdefaults{$type.'domexttool'}=$defaultshash{'coursedefaults'}{'domexttool'}{$type};
21637: }
21638: }
21639: }
21640: if ($changes{'exttool'}) {
21641: if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
21642: foreach my $type (@types) {
21643: $domdefaults{$type.'exttool'}=$defaultshash{'coursedefaults'}{'exttool'}{$type};
21644: }
21645: }
21646: }
1.432 raeburn 21647: if ($changes{'crsauthor'}) {
21648: if (ref($defaultshash{'coursedefaults'}{'crsauthor'}) eq 'HASH') {
21649: foreach my $type (@types) {
21650: $domdefaults{$type.'crsauthor'}=$defaultshash{'coursedefaults'}{'crsauthor'}{$type};
21651: }
21652: }
21653: }
1.438 raeburn 21654: if ($changes{'crseditors'}) {
21655: if (ref($defaultshash{'coursedefaults'}{'crseditors'}) eq 'ARRAY') {
21656: $domdefaults{'crseditors'}=join(',',@{$defaultshash{'coursedefaults'}{'crseditors'}});
21657: }
21658: }
1.121 raeburn 21659: my $cachetime = 24*60*60;
21660: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 21661: if (ref($lastactref) eq 'HASH') {
21662: $lastactref->{'domdefaults'} = 1;
21663: }
1.121 raeburn 21664: }
21665: $resulttext = &mt('Changes made:').'<ul>';
21666: foreach my $item (sort(keys(%changes))) {
21667: if ($item eq 'canuse_pdfforms') {
21668: if ($env{'form.'.$item} eq '1') {
21669: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
21670: } else {
21671: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
21672: }
1.257 raeburn 21673: } elsif ($item eq 'uselcmath') {
21674: if ($env{'form.'.$item} eq '1') {
21675: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
21676: } else {
21677: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
21678: }
21679: } elsif ($item eq 'usejsme') {
21680: if ($env{'form.'.$item} eq '1') {
21681: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
21682: } else {
1.289 raeburn 21683: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 21684: }
1.398 raeburn 21685: } elsif ($item eq 'inline_chem') {
21686: if ($env{'form.'.$item} eq '1') {
21687: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
21688: } else {
21689: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
21690: }
1.314 raeburn 21691: } elsif ($item eq 'texengine') {
21692: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
21693: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
21694: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
21695: }
1.139 raeburn 21696: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 21697: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 21698: } elsif ($item eq 'uploadquota') {
21699: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21700: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
21701: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
21702: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 21703: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 21704: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 21705: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
21706: '</ul>'.
21707: '</li>';
21708: } else {
21709: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
21710: }
1.428 raeburn 21711: } elsif ($item eq 'coursequota') {
21712: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
21713: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course set as follows:').'<ul>'.
21714: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'official'}.'</b>').'</li>'.
21715: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'unofficial'}.'</b>').'</li>'.
21716: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'textbook'}.'</b>').'</li>'.
21717: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'placement'}.'</b>').'</li>'.
21718: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'community'}.'</b>').'</li>'.
21719: '</ul>'.
21720: '</li>';
21721: } else {
21722: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course remains default: [_1] MB',$staticdefaults{'coursequota'}).'</li>';
21723: }
1.276 raeburn 21724: } elsif ($item eq 'mysqltables') {
21725: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
21726: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
21727: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
21728: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
21729: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
21730: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
21731: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
21732: '</ul>'.
21733: '</li>';
21734: } else {
21735: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
21736: }
1.257 raeburn 21737: } elsif ($item eq 'postsubmit') {
21738: if ($domdefaults{'postsubmit'} eq 'off') {
21739: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
21740: } else {
21741: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 21742: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 21743: $resulttext .= &mt('durations:').'<ul>';
21744: foreach my $type (@types) {
21745: $resulttext .= '<li>';
21746: my $timeout;
21747: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21748: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21749: }
21750: my $display;
21751: if ($timeout eq '0') {
21752: $display = &mt('unlimited');
21753: } elsif ($timeout eq '') {
21754: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
21755: } else {
21756: $display = &mt('[quant,_1,second]',$timeout);
21757: }
21758: if ($type eq 'community') {
21759: $resulttext .= &mt('Communities');
21760: } elsif ($type eq 'official') {
21761: $resulttext .= &mt('Official courses');
21762: } elsif ($type eq 'unofficial') {
21763: $resulttext .= &mt('Unofficial courses');
21764: } elsif ($type eq 'textbook') {
21765: $resulttext .= &mt('Textbook courses');
1.271 raeburn 21766: } elsif ($type eq 'placement') {
21767: $resulttext .= &mt('Placement tests');
1.257 raeburn 21768: }
21769: $resulttext .= ' -- '.$display.'</li>';
21770: }
21771: $resulttext .= '</ul>';
21772: }
1.289 raeburn 21773: $resulttext .= '</li>';
1.257 raeburn 21774: }
1.192 raeburn 21775: } elsif ($item eq 'coursecredits') {
21776: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21777: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 21778: ($domdefaults{'unofficialcredits'} eq '') &&
21779: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 21780: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21781: } else {
21782: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
21783: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
21784: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 21785: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 21786: '</ul>'.
21787: '</li>';
21788: }
21789: } else {
21790: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21791: }
1.264 raeburn 21792: } elsif ($item eq 'canclone') {
21793: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21794: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21795: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
21796: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
21797: }
21798: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
21799: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
21800: } else {
1.289 raeburn 21801: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 21802: }
1.404 raeburn 21803: } elsif ($item eq 'ltiauth') {
21804: if ($env{'form.'.$item} eq '1') {
21805: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
21806: } else {
21807: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
21808: }
1.432 raeburn 21809: } elsif (($item eq 'domexttool') || ($item eq 'exttool') || ($item eq 'crsauthor')) {
1.422 raeburn 21810: my @noyes = (&mt('no'),&mt('yes'));
1.432 raeburn 21811: my %status = (
21812: domexttool => {
21813: ishash => &mt('External Tools defined in the domain may be used as follows:'),
21814: default => &mt('External Tools defined in the domain may be used in all course types, by default'),
21815: },
21816: exttool => {
21817: ishash => &mt('External Tools can be defined and configured in course containers as follows:'),
21818: default => &mt('External Tools can not be defined in any course types, by default'),
21819: },
21820: crsauthor => {
21821: ishash => &mt('Standard Problems can be created within course containers as follows:'),
21822: default => &mt('Standard Problems can be created within any course type, by default'),
21823: },
21824: );
21825:
21826: if (ref($defaultshash{'coursedefaults'}{$item}) eq 'HASH') {
21827: $resulttext .= '<li>'.$status{$item}{'ishash'}.'<ul>'.
21828: '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'official'}].'</b>').'</li>'.
21829: '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'unofficial'}].'</b>').'</li>'.
21830: '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'textbook'}].'</b>').'</li>'.
21831: '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'placement'}].'</b>').'</li>'.
21832: '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'community'}].'</b>').'</li>'.
1.422 raeburn 21833: '</ul>'.
21834: '</li>';
21835: } else {
1.432 raeburn 21836: $resulttext .= '<li>'.$status{$item}{'default'}.'</li>';
1.422 raeburn 21837: }
1.438 raeburn 21838: } elsif ($item eq 'crseditors') {
21839: if (ref($defaultshash{'coursedefaults'}{$item}) eq 'ARRAY') {
21840: my $shown;
21841: if (@{$defaultshash{'coursedefaults'}{$item}}) {
21842: $shown = join(', ', map { $editornames{$_} } @{$defaultshash{'coursedefaults'}{$item}});
21843: } else {
21844: $shown = &mt('None');
21845: }
21846: $resulttext .= '<li>'.&mt('Available editors for course/community resources: [_1]',$shown).'</li>';
21847: }
1.140 raeburn 21848: }
1.121 raeburn 21849: }
21850: $resulttext .= '</ul>';
21851: } else {
21852: $resulttext = &mt('No changes made to course defaults');
21853: }
21854: } else {
21855: $resulttext = '<span class="LC_error">'.
21856: &mt('An error occurred: [_1]',$putresult).'</span>';
21857: }
21858: return $resulttext;
21859: }
21860:
1.231 raeburn 21861: sub modify_selfenrollment {
21862: my ($dom,$lastactref,%domconfig) = @_;
21863: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 21864: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 21865: my %titles = &tool_titles();
1.232 raeburn 21866: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
21867: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 21868: $ordered{'default'} = ['types','registered','approval','limit'];
21869:
21870: my (%roles,%shown,%toplevel);
21871: $roles{'0'} = &Apache::lonnet::plaintext('dc');
21872:
21873: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
21874: if ($domconfig{'selfenrollment'} eq '') {
21875: $domconfig{'selfenrollment'} = {};
21876: }
21877: }
21878: %toplevel = (
21879: admin => 'Configuration Rights',
21880: default => 'Default settings',
21881: validation => 'Validation of self-enrollment requests',
21882: );
1.233 raeburn 21883: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 21884:
21885: if (ref($ordered{'admin'}) eq 'ARRAY') {
21886: foreach my $item (@{$ordered{'admin'}}) {
21887: foreach my $type (@types) {
21888: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
21889: $selfenrollhash{'admin'}{$type}{$item} = 1;
21890: } else {
21891: $selfenrollhash{'admin'}{$type}{$item} = 0;
21892: }
21893: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
21894: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
21895: if ($selfenrollhash{'admin'}{$type}{$item} ne
21896: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
21897: push(@{$changes{'admin'}{$type}},$item);
21898: }
21899: } else {
21900: if (!$selfenrollhash{'admin'}{$type}{$item}) {
21901: push(@{$changes{'admin'}{$type}},$item);
21902: }
21903: }
21904: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
21905: push(@{$changes{'admin'}{$type}},$item);
21906: }
21907: }
21908: }
21909: }
21910:
21911: foreach my $item (@{$ordered{'default'}}) {
21912: foreach my $type (@types) {
21913: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
21914: if ($item eq 'types') {
21915: unless (($value eq 'all') || ($value eq 'dom')) {
21916: $value = '';
21917: }
21918: } elsif ($item eq 'registered') {
21919: unless ($value eq '1') {
21920: $value = 0;
21921: }
21922: } elsif ($item eq 'approval') {
21923: unless ($value =~ /^[012]$/) {
21924: $value = 0;
21925: }
21926: } else {
21927: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21928: $value = 'none';
21929: }
21930: }
21931: $selfenrollhash{'default'}{$type}{$item} = $value;
21932: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
21933: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21934: if ($selfenrollhash{'default'}{$type}{$item} ne
21935: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
21936: push(@{$changes{'default'}{$type}},$item);
21937: }
21938: } else {
21939: push(@{$changes{'default'}{$type}},$item);
21940: }
21941: } else {
21942: push(@{$changes{'default'}{$type}},$item);
21943: }
21944: if ($item eq 'limit') {
21945: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21946: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
21947: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
21948: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
21949: }
21950: } else {
21951: $selfenrollhash{'default'}{$type}{'cap'} = '';
21952: }
21953: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21954: if ($selfenrollhash{'default'}{$type}{'cap'} ne
21955: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
21956: push(@{$changes{'default'}{$type}},'cap');
21957: }
21958: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
21959: push(@{$changes{'default'}{$type}},'cap');
21960: }
21961: }
21962: }
21963: }
21964:
21965: foreach my $item (@{$itemsref}) {
21966: if ($item eq 'fields') {
21967: my @changed;
21968: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
21969: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
21970: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
21971: }
21972: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21973: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
21974: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
21975: $domconfig{'selfenrollment'}{'validation'}{$item});
21976: } else {
21977: @changed = @{$selfenrollhash{'validation'}{$item}};
21978: }
21979: } else {
21980: @changed = @{$selfenrollhash{'validation'}{$item}};
21981: }
21982: if (@changed) {
21983: if ($selfenrollhash{'validation'}{$item}) {
21984: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
21985: } else {
21986: $changes{'validation'}{$item} = &mt('None');
21987: }
21988: }
21989: } else {
21990: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
21991: if ($item eq 'markup') {
21992: if ($env{'form.selfenroll_validation_'.$item}) {
21993: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
21994: }
21995: }
21996: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21997: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
21998: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
21999: }
22000: }
22001: }
22002: }
22003:
22004: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
22005: $dom);
22006: if ($putresult eq 'ok') {
22007: if (keys(%changes) > 0) {
22008: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22009: $resulttext = &mt('Changes made:').'<ul>';
22010: foreach my $key ('admin','default','validation') {
22011: if (ref($changes{$key}) eq 'HASH') {
22012: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
22013: if ($key eq 'validation') {
22014: foreach my $item (@{$itemsref}) {
22015: if (exists($changes{$key}{$item})) {
22016: if ($item eq 'markup') {
22017: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
22018: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
22019: } else {
22020: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
22021: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
22022: }
22023: }
22024: }
22025: } else {
22026: foreach my $type (@types) {
22027: if ($type eq 'community') {
22028: $roles{'1'} = &mt('Community personnel');
22029: } else {
22030: $roles{'1'} = &mt('Course personnel');
22031: }
22032: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 22033: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
22034: if ($key eq 'admin') {
22035: my @mgrdc = ();
22036: if (ref($ordered{$key}) eq 'ARRAY') {
22037: foreach my $item (@{$ordered{'admin'}}) {
22038: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
22039: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
22040: push(@mgrdc,$item);
22041: }
22042: }
22043: }
22044: if (@mgrdc) {
22045: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
22046: } else {
22047: delete($domdefaults{$type.'selfenrolladmdc'});
22048: }
22049: }
22050: } else {
22051: if (ref($ordered{$key}) eq 'ARRAY') {
22052: foreach my $item (@{$ordered{$key}}) {
22053: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
22054: $domdefaults{$type.'selfenroll'.$item} =
22055: $selfenrollhash{$key}{$type}{$item};
22056: }
22057: }
22058: }
22059: }
22060: }
1.231 raeburn 22061: $resulttext .= '<li>'.$titles{$type}.'<ul>';
22062: foreach my $item (@{$ordered{$key}}) {
22063: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
22064: $resulttext .= '<li>';
22065: if ($key eq 'admin') {
22066: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
22067: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
22068: } else {
22069: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
22070: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
22071: }
22072: $resulttext .= '</li>';
22073: }
22074: }
22075: $resulttext .= '</ul></li>';
22076: }
22077: }
22078: $resulttext .= '</ul></li>';
22079: }
22080: }
1.305 raeburn 22081: }
22082: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
22083: my $cachetime = 24*60*60;
22084: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22085: if (ref($lastactref) eq 'HASH') {
22086: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 22087: }
1.231 raeburn 22088: }
22089: $resulttext .= '</ul>';
22090: } else {
22091: $resulttext = &mt('No changes made to self-enrollment settings');
22092: }
22093: } else {
22094: $resulttext = '<span class="LC_error">'.
22095: &mt('An error occurred: [_1]',$putresult).'</span>';
22096: }
22097: return $resulttext;
22098: }
22099:
1.373 raeburn 22100: sub modify_wafproxy {
22101: my ($dom,$action,$lastactref,%domconfig) = @_;
22102: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 22103: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
22104: %wafproxy,%changes,%expirecache,%expiresaml);
1.373 raeburn 22105: foreach my $server (sort(keys(%servers))) {
22106: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
22107: if ($serverhome eq $server) {
22108: my $serverdom = &Apache::lonnet::host_domain($server);
22109: if ($serverdom eq $dom) {
22110: $canset{$server} = 1;
22111: }
22112: }
22113: }
1.381 raeburn 22114: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
22115: %{$values{$dom}} = ();
22116: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
22117: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
22118: }
1.388 raeburn 22119: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
22120: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
22121: }
1.382 raeburn 22122: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.381 raeburn 22123: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
22124: }
22125: }
1.373 raeburn 22126: my $output;
22127: if (keys(%canset)) {
22128: %{$wafproxy{'alias'}} = ();
1.388 raeburn 22129: %{$wafproxy{'saml'}} = ();
1.373 raeburn 22130: foreach my $key (sort(keys(%canset))) {
1.381 raeburn 22131: if ($env{'form.wafproxy_'.$dom}) {
22132: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
22133: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
22134: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
22135: $changes{'alias'} = 1;
22136: }
1.388 raeburn 22137: if ($env{'form.wafproxy_alias_saml_'.$key}) {
22138: $wafproxy{'saml'}{$key} = 1;
22139: }
22140: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
22141: $changes{'saml'} = 1;
22142: }
1.381 raeburn 22143: } else {
22144: $wafproxy{'alias'}{$key} = '';
1.388 raeburn 22145: $wafproxy{'saml'}{$key} = '';
1.381 raeburn 22146: if ($curralias{$key}) {
22147: $changes{'alias'} = 1;
22148: }
1.388 raeburn 22149: if ($currsaml{$key}) {
22150: $changes{'saml'} = 1;
22151: }
1.373 raeburn 22152: }
22153: if ($wafproxy{'alias'}{$key} eq '') {
22154: if ($curralias{$key}) {
22155: $expirecache{$key} = 1;
22156: }
22157: delete($wafproxy{'alias'}{$key});
22158: }
1.388 raeburn 22159: if ($wafproxy{'saml'}{$key} eq '') {
22160: if ($currsaml{$key}) {
22161: $expiresaml{$key} = 1;
22162: }
22163: delete($wafproxy{'saml'}{$key});
22164: }
1.373 raeburn 22165: }
22166: unless (keys(%{$wafproxy{'alias'}})) {
22167: delete($wafproxy{'alias'});
22168: }
1.388 raeburn 22169: unless (keys(%{$wafproxy{'saml'}})) {
22170: delete($wafproxy{'saml'});
22171: }
22172: # Localization for values in %warn occurs in &mt() calls separately.
1.373 raeburn 22173: my %warn = (
22174: trusted => 'trusted IP range(s)',
1.381 raeburn 22175: vpnint => 'internal IP range(s) for VPN sessions(s)',
22176: vpnext => 'IP range(s) for backend WAF connections',
1.373 raeburn 22177: );
1.382 raeburn 22178: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22179: my $possible = $env{'form.wafproxy_'.$item};
22180: $possible =~ s/^\s+|\s+$//g;
22181: if ($possible ne '') {
1.381 raeburn 22182: if ($item eq 'remoteip') {
22183: if ($possible =~ /^[mhn]$/) {
22184: $wafproxy{$item} = $possible;
22185: }
22186: } elsif ($item eq 'ipheader') {
22187: if ($wafproxy{'remoteip'} eq 'h') {
22188: $wafproxy{$item} = $possible;
22189: }
1.382 raeburn 22190: } elsif ($item eq 'sslopt') {
22191: if ($possible =~ /^0|1$/) {
22192: $wafproxy{$item} = $possible;
22193: }
1.373 raeburn 22194: } else {
22195: my (@ok,$count);
1.381 raeburn 22196: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
22197: unless ($env{'form.wafproxy_vpnaccess'}) {
22198: $possible = '';
22199: }
22200: } elsif ($item eq 'trusted') {
22201: unless ($wafproxy{'remoteip'} eq 'h') {
22202: $possible = '';
22203: }
22204: }
22205: unless ($possible eq '') {
22206: $possible =~ s/[\r\n]+/\s/g;
22207: $possible =~ s/\s*-\s*/-/g;
22208: $possible =~ s/\s+/,/g;
1.393 raeburn 22209: $possible =~ s/,+/,/g;
1.381 raeburn 22210: }
1.373 raeburn 22211: $count = 0;
1.381 raeburn 22212: if ($possible ne '') {
1.373 raeburn 22213: foreach my $poss (split(/\,/,$possible)) {
22214: $count ++;
1.393 raeburn 22215: $poss = &validate_ip_pattern($poss);
22216: if ($poss ne '') {
1.373 raeburn 22217: push(@ok,$poss);
22218: }
22219: }
22220: my $diff = $count - scalar(@ok);
22221: if ($diff) {
22222: push(@warnings,'<li>'.
22223: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
22224: $diff,$warn{$item}).
22225: '</li>');
22226: }
1.393 raeburn 22227: if (@ok) {
22228: my @cidr_list;
22229: foreach my $item (@ok) {
22230: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
22231: }
22232: $wafproxy{$item} = join(',',@cidr_list);
22233: }
1.373 raeburn 22234: }
22235: }
1.381 raeburn 22236: if ($wafproxy{$item} ne $currvalue{$item}) {
1.373 raeburn 22237: $changes{$item} = 1;
22238: }
1.381 raeburn 22239: } elsif ($currvalue{$item}) {
22240: $changes{$item} = 1;
1.425 raeburn 22241: }
1.381 raeburn 22242: }
22243: } else {
22244: if (keys(%curralias)) {
22245: $changes{'alias'} = 1;
1.388 raeburn 22246: }
22247: if (keys(%currsaml)) {
22248: $changes{'saml'} = 1;
1.425 raeburn 22249: }
1.381 raeburn 22250: if (keys(%currvalue)) {
22251: foreach my $key (keys(%currvalue)) {
22252: $changes{$key} = 1;
1.373 raeburn 22253: }
22254: }
22255: }
22256: if (keys(%changes)) {
22257: my %defaultshash = (
22258: wafproxy => \%wafproxy,
1.425 raeburn 22259: );
1.373 raeburn 22260: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22261: $dom);
22262: if ($putresult eq 'ok') {
22263: my $cachetime = 24*60*60;
22264: my (%domdefaults,$updatedomdefs);
1.382 raeburn 22265: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22266: if ($changes{$item}) {
22267: unless ($updatedomdefs) {
22268: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
22269: $updatedomdefs = 1;
22270: }
22271: if ($wafproxy{$item}) {
22272: $domdefaults{'waf_'.$item} = $wafproxy{$item};
22273: } elsif (exists($domdefaults{'waf_'.$item})) {
22274: delete($domdefaults{'waf_'.$item});
1.425 raeburn 22275: }
1.373 raeburn 22276: }
22277: }
22278: if ($updatedomdefs) {
22279: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22280: if (ref($lastactref) eq 'HASH') {
22281: $lastactref->{'domdefaults'} = 1;
22282: }
22283: }
22284: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
22285: my %updates = %expirecache;
22286: foreach my $key (keys(%expirecache)) {
22287: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
22288: }
22289: if (ref($wafproxy{'alias'}) eq 'HASH') {
22290: my $cachetime = 24*60*60;
22291: foreach my $key (keys(%{$wafproxy{'alias'}})) {
22292: $updates{$key} = 1;
22293: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
22294: $cachetime);
22295: }
22296: }
22297: if (ref($lastactref) eq 'HASH') {
22298: $lastactref->{'proxyalias'} = \%updates;
22299: }
22300: }
1.388 raeburn 22301: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
22302: my %samlupdates = %expiresaml;
22303: foreach my $key (keys(%expiresaml)) {
22304: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
22305: }
22306: if (ref($wafproxy{'saml'}) eq 'HASH') {
22307: my $cachetime = 24*60*60;
22308: foreach my $key (keys(%{$wafproxy{'saml'}})) {
22309: $samlupdates{$key} = 1;
22310: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
22311: $cachetime);
22312: }
22313: }
22314: if (ref($lastactref) eq 'HASH') {
22315: $lastactref->{'proxysaml'} = \%samlupdates;
22316: }
22317: }
1.373 raeburn 22318: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.401 raeburn 22319: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22320: if ($changes{$item}) {
22321: if ($item eq 'alias') {
22322: my $numaliased = 0;
22323: if (ref($wafproxy{'alias'}) eq 'HASH') {
22324: my $shown;
22325: if (keys(%{$wafproxy{'alias'}})) {
22326: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
22327: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
22328: &Apache::lonnet::hostname($server),
22329: $wafproxy{'alias'}{$server}).'</li>';
22330: $numaliased ++;
22331: }
22332: if ($numaliased) {
22333: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
22334: '<ul>'.$shown.'</ul>').'</li>';
22335: }
22336: }
22337: }
22338: unless ($numaliased) {
22339: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
22340: }
1.388 raeburn 22341: } elsif ($item eq 'saml') {
1.425 raeburn 22342: my $shown;
1.388 raeburn 22343: if (ref($wafproxy{'saml'}) eq 'HASH') {
22344: if (keys(%{$wafproxy{'saml'}})) {
22345: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
22346: }
22347: }
22348: if ($shown) {
1.396 raeburn 22349: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
1.388 raeburn 22350: $shown).'</li>';
22351: } else {
1.396 raeburn 22352: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
1.388 raeburn 22353: }
1.373 raeburn 22354: } else {
1.381 raeburn 22355: if ($item eq 'remoteip') {
22356: my %ip_methods = &remoteip_methods();
22357: if ($wafproxy{$item} =~ /^[mh]$/) {
22358: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
22359: $ip_methods{$wafproxy{$item}}).'</li>';
22360: } else {
22361: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
22362: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
22363: '</li>';
22364: } else {
22365: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
22366: }
22367: }
22368: } elsif ($item eq 'ipheader') {
1.373 raeburn 22369: if ($wafproxy{$item}) {
1.381 raeburn 22370: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
1.373 raeburn 22371: $wafproxy{$item}).'</li>';
22372: } else {
1.381 raeburn 22373: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
1.373 raeburn 22374: }
22375: } elsif ($item eq 'trusted') {
22376: if ($wafproxy{$item}) {
1.381 raeburn 22377: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
1.373 raeburn 22378: $wafproxy{$item}).'</li>';
22379: } else {
22380: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
22381: }
1.381 raeburn 22382: } elsif ($item eq 'vpnint') {
22383: if ($wafproxy{$item}) {
22384: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
22385: $wafproxy{$item}).'</li>';
22386: } else {
22387: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
22388: }
22389: } elsif ($item eq 'vpnext') {
1.373 raeburn 22390: if ($wafproxy{$item}) {
1.381 raeburn 22391: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
1.373 raeburn 22392: $wafproxy{$item}).'</li>';
22393: } else {
1.381 raeburn 22394: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
1.373 raeburn 22395: }
1.382 raeburn 22396: } elsif ($item eq 'sslopt') {
22397: if ($wafproxy{$item}) {
22398: $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>';
22399: } else {
22400: $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>';
22401: }
1.373 raeburn 22402: }
22403: }
22404: }
22405: }
1.420 raeburn 22406: $output .= '</ul>';
1.373 raeburn 22407: } else {
22408: $output = '<span class="LC_error">'.
22409: &mt('An error occurred: [_1]',$putresult).'</span>';
22410: }
22411: } elsif (keys(%canset)) {
22412: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
22413: }
22414: if (@warnings) {
22415: $output .= '<br />'.&mt('Warnings:').'<ul>'.
22416: join("\n",@warnings).'</ul>';
22417: }
22418: return $output;
22419: }
22420:
22421: sub validate_ip_pattern {
22422: my ($pattern) = @_;
22423: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
22424: my ($start,$end) = ($1,$2);
22425: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
1.393 raeburn 22426: if (($start !~ m{/}) && ($end !~ m{/})) {
22427: return $start.'-'.$end;
22428: }
22429: }
22430: } elsif ($pattern ne '') {
22431: $pattern = &Net::CIDR::cidrvalidate($pattern);
22432: if ($pattern ne '') {
22433: return $pattern;
1.373 raeburn 22434: }
22435: }
1.393 raeburn 22436: return;
1.373 raeburn 22437: }
22438:
1.137 raeburn 22439: sub modify_usersessions {
1.212 raeburn 22440: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 22441: my @hostingtypes = ('version','excludedomain','includedomain');
22442: my @offloadtypes = ('primary','default');
22443: my %types = (
22444: remote => \@hostingtypes,
22445: hosted => \@hostingtypes,
22446: spares => \@offloadtypes,
22447: );
22448: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 22449: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 22450: my (%by_ip,%by_location,@intdoms,@instdoms);
22451: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 22452: my @locations = sort(keys(%by_location));
1.137 raeburn 22453: my (%defaultshash,%changes);
22454: foreach my $prefix (@prefixes) {
22455: $defaultshash{'usersessions'}{$prefix} = {};
22456: }
1.212 raeburn 22457: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 22458: my $resulttext;
1.138 raeburn 22459: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 22460: foreach my $prefix (@prefixes) {
1.145 raeburn 22461: next if ($prefix eq 'spares');
22462: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 22463: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22464: if ($type eq 'version') {
22465: my $value = $env{'form.'.$prefix.'_'.$type};
22466: my $okvalue;
22467: if ($value ne '') {
22468: if (grep(/^\Q$value\E$/,@lcversions)) {
22469: $okvalue = $value;
22470: }
22471: }
22472: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22473: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22474: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
22475: if ($inuse == 0) {
22476: $changes{$prefix}{$type} = 1;
22477: } else {
22478: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
22479: $changes{$prefix}{$type} = 1;
22480: }
22481: if ($okvalue ne '') {
22482: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22483: }
22484: }
22485: } else {
22486: if (($inuse == 1) && ($okvalue ne '')) {
22487: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22488: $changes{$prefix}{$type} = 1;
22489: }
22490: }
22491: } else {
22492: if (($inuse == 1) && ($okvalue ne '')) {
22493: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22494: $changes{$prefix}{$type} = 1;
22495: }
22496: }
22497: } else {
22498: if (($inuse == 1) && ($okvalue ne '')) {
22499: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22500: $changes{$prefix}{$type} = 1;
22501: }
22502: }
22503: } else {
22504: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22505: my @okvals;
22506: foreach my $val (@vals) {
1.138 raeburn 22507: if ($val =~ /:/) {
22508: my @items = split(/:/,$val);
22509: foreach my $item (@items) {
22510: if (ref($by_location{$item}) eq 'ARRAY') {
22511: push(@okvals,$item);
22512: }
22513: }
22514: } else {
22515: if (ref($by_location{$val}) eq 'ARRAY') {
22516: push(@okvals,$val);
22517: }
1.137 raeburn 22518: }
22519: }
22520: @okvals = sort(@okvals);
22521: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22522: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22523: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22524: if ($inuse == 0) {
22525: $changes{$prefix}{$type} = 1;
22526: } else {
22527: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22528: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
22529: if (@changed > 0) {
22530: $changes{$prefix}{$type} = 1;
22531: }
22532: }
22533: } else {
22534: if ($inuse == 1) {
22535: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22536: $changes{$prefix}{$type} = 1;
22537: }
22538: }
22539: } else {
22540: if ($inuse == 1) {
22541: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22542: $changes{$prefix}{$type} = 1;
22543: }
22544: }
22545: } else {
22546: if ($inuse == 1) {
22547: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22548: $changes{$prefix}{$type} = 1;
22549: }
22550: }
22551: }
22552: }
22553: }
1.145 raeburn 22554:
22555: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 22556: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 22557: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
22558: my $savespares;
22559:
22560: foreach my $lonhost (sort(keys(%servers))) {
22561: my $serverhomeID =
22562: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 22563: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 22564: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
22565: my %spareschg;
22566: foreach my $type (@{$types{'spares'}}) {
22567: my @okspares;
22568: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
22569: foreach my $server (@checked) {
1.152 raeburn 22570: if (&Apache::lonnet::hostname($server) ne '') {
22571: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
22572: unless (grep(/^\Q$server\E$/,@okspares)) {
22573: push(@okspares,$server);
22574: }
1.145 raeburn 22575: }
22576: }
22577: }
22578: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
22579: my $newspare;
1.152 raeburn 22580: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
22581: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 22582: $newspare = $new;
22583: }
22584: }
1.152 raeburn 22585: my @spares;
22586: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
22587: @spares = sort(@okspares,$newspare);
22588: } else {
22589: @spares = sort(@okspares);
22590: }
22591: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 22592: if (ref($spareid{$lonhost}) eq 'HASH') {
22593: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 22594: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 22595: if (@diffs > 0) {
22596: $spareschg{$type} = 1;
22597: }
22598: }
22599: }
22600: }
22601: if (keys(%spareschg) > 0) {
22602: $changes{'spares'}{$lonhost} = \%spareschg;
22603: }
22604: }
1.261 raeburn 22605: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371 raeburn 22606: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261 raeburn 22607: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
22608: my @okoffload;
22609: if (@offloadnow) {
22610: foreach my $server (@offloadnow) {
22611: if (&Apache::lonnet::hostname($server) ne '') {
22612: unless (grep(/^\Q$server\E$/,@okoffload)) {
22613: push(@okoffload,$server);
22614: }
22615: }
22616: }
22617: if (@okoffload) {
22618: foreach my $lonhost (@okoffload) {
22619: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
22620: }
22621: }
22622: }
1.371 raeburn 22623: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
22624: my @okoffloadoth;
22625: if (@offloadoth) {
22626: foreach my $server (@offloadoth) {
22627: if (&Apache::lonnet::hostname($server) ne '') {
22628: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
22629: push(@okoffloadoth,$server);
22630: }
22631: }
22632: }
22633: if (@okoffloadoth) {
22634: foreach my $lonhost (@okoffloadoth) {
22635: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
22636: }
22637: }
22638: }
1.145 raeburn 22639: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22640: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
22641: if (ref($changes{'spares'}) eq 'HASH') {
22642: if (keys(%{$changes{'spares'}}) > 0) {
22643: $savespares = 1;
22644: }
22645: }
22646: } else {
22647: $savespares = 1;
22648: }
1.371 raeburn 22649: foreach my $offload ('offloadnow','offloadoth') {
22650: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
22651: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
22652: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
22653: $changes{$offload} = 1;
22654: last;
22655: }
1.261 raeburn 22656: }
1.371 raeburn 22657: unless ($changes{$offload}) {
22658: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
22659: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
22660: $changes{$offload} = 1;
22661: last;
22662: }
1.261 raeburn 22663: }
22664: }
1.371 raeburn 22665: } else {
22666: if (($offload eq 'offloadnow') && (@okoffload)) {
22667: $changes{'offloadnow'} = 1;
22668: }
22669: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
22670: $changes{'offloadoth'} = 1;
22671: }
1.425 raeburn 22672: }
1.371 raeburn 22673: }
22674: } else {
22675: if (@okoffload) {
1.261 raeburn 22676: $changes{'offloadnow'} = 1;
22677: }
1.371 raeburn 22678: if (@okoffloadoth) {
22679: $changes{'offloadoth'} = 1;
22680: }
1.145 raeburn 22681: }
1.147 raeburn 22682: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
22683: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 22684: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22685: $dom);
22686: if ($putresult eq 'ok') {
22687: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22688: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
22689: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
22690: }
22691: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
22692: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
22693: }
1.261 raeburn 22694: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22695: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
22696: }
1.371 raeburn 22697: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22698: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
22699: }
1.137 raeburn 22700: }
22701: my $cachetime = 24*60*60;
22702: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 22703: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 22704: if (ref($lastactref) eq 'HASH') {
22705: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 22706: $lastactref->{'usersessions'} = 1;
1.212 raeburn 22707: }
1.147 raeburn 22708: if (keys(%changes) > 0) {
22709: my %lt = &usersession_titles();
22710: $resulttext = &mt('Changes made:').'<ul>';
22711: foreach my $prefix (@prefixes) {
22712: if (ref($changes{$prefix}) eq 'HASH') {
22713: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
22714: if ($prefix eq 'spares') {
22715: if (ref($changes{$prefix}) eq 'HASH') {
22716: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
22717: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 22718: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 22719: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
22720: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 22721: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
22722: foreach my $type (@{$types{$prefix}}) {
22723: if ($changes{$prefix}{$lonhost}{$type}) {
22724: my $offloadto = &mt('None');
22725: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
22726: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
22727: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
22728: }
1.145 raeburn 22729: }
1.147 raeburn 22730: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 22731: }
1.137 raeburn 22732: }
22733: }
1.147 raeburn 22734: $resulttext .= '</li>';
1.137 raeburn 22735: }
22736: }
1.147 raeburn 22737: } else {
22738: foreach my $type (@{$types{$prefix}}) {
22739: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22740: my ($newvalue,$notinuse);
1.147 raeburn 22741: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22742: if (ref($defaultshash{'usersessions'}{$prefix})) {
22743: if ($type eq 'version') {
22744: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 22745: } else {
22746: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22747: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
22748: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
22749: }
22750: } else {
22751: $notinuse = 1;
1.147 raeburn 22752: }
1.145 raeburn 22753: }
22754: }
22755: }
1.147 raeburn 22756: if ($newvalue eq '') {
22757: if ($type eq 'version') {
22758: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 22759: } elsif ($notinuse) {
22760: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 22761: } else {
22762: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
22763: }
1.145 raeburn 22764: } else {
1.147 raeburn 22765: if ($type eq 'version') {
1.344 raeburn 22766: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 22767: }
22768: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 22769: }
1.137 raeburn 22770: }
22771: }
22772: }
1.147 raeburn 22773: $resulttext .= '</ul>';
1.137 raeburn 22774: }
22775: }
1.261 raeburn 22776: if ($changes{'offloadnow'}) {
22777: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22778: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371 raeburn 22779: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261 raeburn 22780: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
22781: $resulttext .= '<li>'.$lonhost.'</li>';
22782: }
22783: $resulttext .= '</ul>';
22784: } else {
1.371 raeburn 22785: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
22786: }
22787: } else {
22788: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
22789: }
22790: }
22791: if ($changes{'offloadoth'}) {
22792: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22793: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
22794: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
22795: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
22796: $resulttext .= '<li>'.$lonhost.'</li>';
22797: }
22798: $resulttext .= '</ul>';
22799: } else {
22800: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261 raeburn 22801: }
22802: } else {
1.371 raeburn 22803: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261 raeburn 22804: }
22805: }
1.147 raeburn 22806: $resulttext .= '</ul>';
22807: } else {
22808: $resulttext = $nochgmsg;
1.137 raeburn 22809: }
22810: } else {
22811: $resulttext = '<span class="LC_error">'.
22812: &mt('An error occurred: [_1]',$putresult).'</span>';
22813: }
22814: } else {
1.147 raeburn 22815: $resulttext = $nochgmsg;
1.137 raeburn 22816: }
22817: return $resulttext;
22818: }
22819:
1.275 raeburn 22820: sub modify_ssl {
22821: my ($dom,$lastactref,%domconfig) = @_;
22822: my (%by_ip,%by_location,@intdoms,@instdoms);
22823: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
22824: my @locations = sort(keys(%by_location));
22825: my %servers = &Apache::lonnet::internet_dom_servers($dom);
22826: my (%defaultshash,%changes);
22827: my $action = 'ssl';
1.293 raeburn 22828: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 22829: foreach my $prefix (@prefixes) {
22830: $defaultshash{$action}{$prefix} = {};
22831: }
22832: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22833: my $resulttext;
22834: my %iphost = &Apache::lonnet::get_iphost();
22835: my @reptypes = ('certreq','nocertreq');
22836: my @connecttypes = ('dom','intdom','other');
22837: my %types = (
1.293 raeburn 22838: connto => \@connecttypes,
22839: connfrom => \@connecttypes,
22840: replication => \@reptypes,
1.275 raeburn 22841: );
22842: foreach my $prefix (sort(keys(%types))) {
22843: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 22844: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22845: my $value = 'yes';
22846: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
22847: $value = $env{'form.'.$prefix.'_'.$type};
22848: }
1.335 raeburn 22849: if (ref($domconfig{$action}) eq 'HASH') {
22850: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22851: if ($domconfig{$action}{$prefix}{$type} ne '') {
22852: if ($value ne $domconfig{$action}{$prefix}{$type}) {
22853: $changes{$prefix}{$type} = 1;
22854: }
22855: $defaultshash{$action}{$prefix}{$type} = $value;
22856: } else {
22857: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 22858: $changes{$prefix}{$type} = 1;
22859: }
22860: } else {
22861: $defaultshash{$action}{$prefix}{$type} = $value;
22862: $changes{$prefix}{$type} = 1;
22863: }
22864: } else {
22865: $defaultshash{$action}{$prefix}{$type} = $value;
22866: $changes{$prefix}{$type} = 1;
22867: }
22868: if (($type eq 'dom') && (keys(%servers) == 1)) {
22869: delete($changes{$prefix}{$type});
22870: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
22871: delete($changes{$prefix}{$type});
22872: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
22873: delete($changes{$prefix}{$type});
22874: }
22875: } elsif ($prefix eq 'replication') {
22876: if (@locations > 0) {
22877: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22878: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22879: my @okvals;
22880: foreach my $val (@vals) {
22881: if ($val =~ /:/) {
22882: my @items = split(/:/,$val);
22883: foreach my $item (@items) {
22884: if (ref($by_location{$item}) eq 'ARRAY') {
22885: push(@okvals,$item);
22886: }
22887: }
22888: } else {
22889: if (ref($by_location{$val}) eq 'ARRAY') {
22890: push(@okvals,$val);
22891: }
22892: }
22893: }
22894: @okvals = sort(@okvals);
22895: if (ref($domconfig{$action}) eq 'HASH') {
22896: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22897: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
22898: if ($inuse == 0) {
22899: $changes{$prefix}{$type} = 1;
22900: } else {
22901: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22902: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
22903: if (@changed > 0) {
22904: $changes{$prefix}{$type} = 1;
22905: }
22906: }
22907: } else {
22908: if ($inuse == 1) {
22909: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22910: $changes{$prefix}{$type} = 1;
22911: }
22912: }
22913: } else {
22914: if ($inuse == 1) {
22915: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22916: $changes{$prefix}{$type} = 1;
22917: }
22918: }
22919: } else {
22920: if ($inuse == 1) {
22921: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22922: $changes{$prefix}{$type} = 1;
22923: }
22924: }
22925: }
22926: }
22927: }
22928: }
1.336 raeburn 22929: if (keys(%changes)) {
22930: foreach my $prefix (keys(%changes)) {
22931: if (ref($changes{$prefix}) eq 'HASH') {
22932: if (scalar(keys(%{$changes{$prefix}})) == 0) {
22933: delete($changes{$prefix});
22934: }
22935: } else {
22936: delete($changes{$prefix});
22937: }
22938: }
22939: }
1.275 raeburn 22940: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
22941: if (keys(%changes) > 0) {
22942: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22943: $dom);
22944: if ($putresult eq 'ok') {
22945: if (ref($defaultshash{$action}) eq 'HASH') {
22946: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
22947: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
22948: }
1.293 raeburn 22949: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 22950: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 22951: }
22952: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 22953: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 22954: }
22955: }
22956: my $cachetime = 24*60*60;
22957: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22958: if (ref($lastactref) eq 'HASH') {
22959: $lastactref->{'domdefaults'} = 1;
22960: }
22961: if (keys(%changes) > 0) {
22962: my %titles = &ssl_titles();
22963: $resulttext = &mt('Changes made:').'<ul>';
22964: foreach my $prefix (@prefixes) {
22965: if (ref($changes{$prefix}) eq 'HASH') {
22966: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
22967: foreach my $type (@{$types{$prefix}}) {
22968: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22969: my ($newvalue,$notinuse);
1.275 raeburn 22970: if (ref($defaultshash{$action}) eq 'HASH') {
22971: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 22972: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22973: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 22974: } else {
22975: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
22976: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
22977: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
22978: }
22979: } else {
22980: $notinuse = 1;
1.275 raeburn 22981: }
22982: }
22983: }
1.344 raeburn 22984: if ($notinuse) {
22985: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
22986: } elsif ($newvalue eq '') {
1.275 raeburn 22987: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
22988: } else {
22989: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
22990: }
22991: }
22992: }
22993: }
22994: $resulttext .= '</ul>';
22995: }
22996: }
22997: } else {
22998: $resulttext = $nochgmsg;
22999: }
23000: } else {
23001: $resulttext = '<span class="LC_error">'.
23002: &mt('An error occurred: [_1]',$putresult).'</span>';
23003: }
23004: } else {
23005: $resulttext = $nochgmsg;
23006: }
23007: return $resulttext;
23008: }
23009:
1.279 raeburn 23010: sub modify_trust {
23011: my ($dom,$lastactref,%domconfig) = @_;
23012: my (%by_ip,%by_location,@intdoms,@instdoms);
23013: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
23014: my @locations = sort(keys(%by_location));
23015: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
23016: my @types = ('exc','inc');
23017: my (%defaultshash,%changes);
23018: foreach my $prefix (@prefixes) {
23019: $defaultshash{'trust'}{$prefix} = {};
23020: }
23021: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
23022: my $resulttext;
23023: foreach my $prefix (@prefixes) {
23024: foreach my $type (@types) {
23025: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
23026: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
23027: my @okvals;
23028: foreach my $val (@vals) {
23029: if ($val =~ /:/) {
23030: my @items = split(/:/,$val);
23031: foreach my $item (@items) {
23032: if (ref($by_location{$item}) eq 'ARRAY') {
23033: push(@okvals,$item);
23034: }
23035: }
23036: } else {
23037: if (ref($by_location{$val}) eq 'ARRAY') {
23038: push(@okvals,$val);
23039: }
23040: }
23041: }
23042: @okvals = sort(@okvals);
23043: if (ref($domconfig{'trust'}) eq 'HASH') {
23044: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
23045: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
23046: if ($inuse == 0) {
23047: $changes{$prefix}{$type} = 1;
23048: } else {
23049: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23050: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
23051: if (@changed > 0) {
23052: $changes{$prefix}{$type} = 1;
23053: }
23054: }
23055: } else {
23056: if ($inuse == 1) {
23057: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23058: $changes{$prefix}{$type} = 1;
23059: }
23060: }
23061: } else {
23062: if ($inuse == 1) {
23063: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23064: $changes{$prefix}{$type} = 1;
23065: }
23066: }
23067: } else {
23068: if ($inuse == 1) {
23069: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23070: $changes{$prefix}{$type} = 1;
23071: }
23072: }
23073: }
23074: }
23075: my $nochgmsg = &mt('No changes made to trust settings.');
23076: if (keys(%changes) > 0) {
23077: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
23078: $dom);
23079: if ($putresult eq 'ok') {
23080: if (ref($defaultshash{'trust'}) eq 'HASH') {
23081: foreach my $prefix (@prefixes) {
23082: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
23083: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
23084: }
23085: }
23086: }
23087: my $cachetime = 24*60*60;
23088: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.410 raeburn 23089: &Apache::lonnet::do_cache_new('trust',$dom,$defaultshash{'trust'},3600);
1.279 raeburn 23090: if (ref($lastactref) eq 'HASH') {
23091: $lastactref->{'domdefaults'} = 1;
1.410 raeburn 23092: $lastactref->{'trust'} = 1;
1.279 raeburn 23093: }
23094: if (keys(%changes) > 0) {
23095: my %lt = &trust_titles();
23096: $resulttext = &mt('Changes made:').'<ul>';
23097: foreach my $prefix (@prefixes) {
23098: if (ref($changes{$prefix}) eq 'HASH') {
23099: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
23100: foreach my $type (@types) {
23101: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 23102: my ($newvalue,$notinuse);
1.279 raeburn 23103: if (ref($defaultshash{'trust'}) eq 'HASH') {
23104: if (ref($defaultshash{'trust'}{$prefix})) {
23105: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
23106: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
23107: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
23108: }
1.344 raeburn 23109: } else {
23110: $notinuse = 1;
1.279 raeburn 23111: }
23112: }
23113: }
1.344 raeburn 23114: if ($notinuse) {
23115: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
23116: } elsif ($newvalue eq '') {
1.279 raeburn 23117: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
23118: } else {
23119: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
23120: }
23121: }
23122: }
23123: $resulttext .= '</ul>';
23124: }
23125: }
23126: $resulttext .= '</ul>';
23127: } else {
23128: $resulttext = $nochgmsg;
23129: }
23130: } else {
23131: $resulttext = '<span class="LC_error">'.
23132: &mt('An error occurred: [_1]',$putresult).'</span>';
23133: }
23134: } else {
23135: $resulttext = $nochgmsg;
23136: }
23137: return $resulttext;
23138: }
23139:
1.150 raeburn 23140: sub modify_loadbalancing {
23141: my ($dom,%domconfig) = @_;
23142: my $primary_id = &Apache::lonnet::domain($dom,'primary');
23143: my $intdom = &Apache::lonnet::internet_dom($primary_id);
23144: my ($othertitle,$usertypes,$types) =
23145: &Apache::loncommon::sorted_inst_types($dom);
23146: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 23147: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 23148: my @sparestypes = ('primary','default');
23149: my %typetitles = &sparestype_titles();
23150: my $resulttext;
1.342 raeburn 23151: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 23152: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
23153: %existing = %{$domconfig{'loadbalancing'}};
23154: }
23155: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 23156: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 23157: my ($saveloadbalancing,%defaultshash,%changes);
23158: my ($alltypes,$othertypes,$titles) =
23159: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
23160: my %ruletitles = &offloadtype_text();
23161: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
23162: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
23163: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
23164: if ($balancer eq '') {
23165: next;
23166: }
1.210 raeburn 23167: if (!exists($servers{$balancer})) {
1.171 raeburn 23168: if (exists($currbalancer{$balancer})) {
23169: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 23170: }
1.171 raeburn 23171: next;
23172: }
23173: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
23174: push(@{$changes{'delete'}},$balancer);
23175: next;
23176: }
23177: if (!exists($currbalancer{$balancer})) {
23178: push(@{$changes{'add'}},$balancer);
23179: }
23180: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
23181: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
23182: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
23183: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
23184: $saveloadbalancing = 1;
23185: }
23186: foreach my $sparetype (@sparestypes) {
23187: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
23188: my @offloadto;
23189: foreach my $target (@targets) {
23190: if (($servers{$target}) && ($target ne $balancer)) {
23191: if ($sparetype eq 'default') {
23192: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
23193: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 23194: }
23195: }
1.171 raeburn 23196: unless(grep(/^\Q$target\E$/,@offloadto)) {
23197: push(@offloadto,$target);
23198: }
1.150 raeburn 23199: }
23200: }
1.284 raeburn 23201: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
23202: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
23203: push(@offloadto,$balancer);
23204: }
23205: }
23206: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 23207: }
1.342 raeburn 23208: if ($env{'form.loadbalancing_cookie_'.$i}) {
23209: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
1.425 raeburn 23210: if (exists($currbalancer{$balancer})) {
1.342 raeburn 23211: unless ($currcookies{$balancer}) {
23212: $changes{'curr'}{$balancer}{'cookie'} = 1;
23213: }
23214: }
23215: } elsif (exists($currbalancer{$balancer})) {
23216: if ($currcookies{$balancer}) {
23217: $changes{'curr'}{$balancer}{'cookie'} = 1;
23218: }
23219: }
1.171 raeburn 23220: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 23221: foreach my $sparetype (@sparestypes) {
1.171 raeburn 23222: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
23223: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 23224: if (@targetdiffs > 0) {
1.171 raeburn 23225: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 23226: }
1.171 raeburn 23227: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23228: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23229: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 23230: }
23231: }
23232: }
23233: } else {
1.171 raeburn 23234: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 23235: foreach my $sparetype (@sparestypes) {
1.171 raeburn 23236: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23237: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23238: $changes{'curr'}{$balancer}{'targets'} = 1;
23239: }
1.150 raeburn 23240: }
23241: }
1.210 raeburn 23242: }
1.150 raeburn 23243: }
23244: my $ishomedom;
1.171 raeburn 23245: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
23246: $ishomedom = 1;
1.150 raeburn 23247: }
23248: if (ref($alltypes) eq 'ARRAY') {
23249: foreach my $type (@{$alltypes}) {
23250: my $rule;
1.210 raeburn 23251: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 23252: (!$ishomedom)) {
1.171 raeburn 23253: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
23254: }
23255: if ($rule eq 'specific') {
1.255 raeburn 23256: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 23257: if (exists($servers{$specifiedhost})) {
1.255 raeburn 23258: $rule = $specifiedhost;
23259: }
1.150 raeburn 23260: }
1.171 raeburn 23261: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
23262: if (ref($currrules{$balancer}) eq 'HASH') {
23263: if ($rule ne $currrules{$balancer}{$type}) {
23264: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 23265: }
23266: } elsif ($rule ne '') {
1.171 raeburn 23267: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 23268: }
23269: }
23270: }
1.171 raeburn 23271: }
23272: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
23273: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
23274: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
23275: $defaultshash{'loadbalancing'} = {};
23276: }
23277: my $putresult = &Apache::lonnet::put_dom('configuration',
23278: \%defaultshash,$dom);
23279: if ($putresult eq 'ok') {
23280: if (keys(%changes) > 0) {
1.252 raeburn 23281: my %toupdate;
1.171 raeburn 23282: if (ref($changes{'delete'}) eq 'ARRAY') {
23283: foreach my $balancer (sort(@{$changes{'delete'}})) {
23284: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 23285: $toupdate{$balancer} = 1;
1.150 raeburn 23286: }
1.171 raeburn 23287: }
23288: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 23289: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 23290: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 23291: $toupdate{$balancer} = 1;
1.171 raeburn 23292: }
23293: }
23294: if (ref($changes{'curr'}) eq 'HASH') {
23295: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 23296: $toupdate{$balancer} = 1;
1.171 raeburn 23297: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
23298: if ($changes{'curr'}{$balancer}{'targets'}) {
23299: my %offloadstr;
23300: foreach my $sparetype (@sparestypes) {
23301: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23302: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23303: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
23304: }
23305: }
1.150 raeburn 23306: }
1.171 raeburn 23307: if (keys(%offloadstr) == 0) {
23308: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 23309: } else {
1.171 raeburn 23310: my $showoffload;
23311: foreach my $sparetype (@sparestypes) {
23312: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
23313: if (defined($offloadstr{$sparetype})) {
23314: $showoffload .= $offloadstr{$sparetype};
23315: } else {
23316: $showoffload .= &mt('None');
23317: }
23318: $showoffload .= (' 'x3);
23319: }
23320: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 23321: }
23322: }
23323: }
1.171 raeburn 23324: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
23325: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
23326: foreach my $type (@{$alltypes}) {
23327: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
23328: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23329: my $balancetext;
23330: if ($rule eq '') {
23331: $balancetext = $ruletitles{'default'};
1.209 raeburn 23332: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 23333: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 23334: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 23335: foreach my $sparetype (@sparestypes) {
23336: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23337: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
23338: }
23339: }
1.253 raeburn 23340: foreach my $item (@{$alltypes}) {
23341: next if ($item =~ /^_LC_ipchange/);
23342: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
23343: if ($hasrule eq 'homeserver') {
23344: map { $toupdate{$_} = 1; } (keys(%libraryservers));
23345: } else {
23346: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
23347: if ($servers{$hasrule}) {
23348: $toupdate{$hasrule} = 1;
23349: }
23350: }
23351: }
23352: }
1.254 raeburn 23353: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
23354: $balancetext = $ruletitles{$rule};
23355: } else {
23356: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23357: $balancetext = $ruletitles{'particular'}.' '.$receiver;
23358: if ($receiver) {
23359: $toupdate{$receiver};
23360: }
23361: }
23362: } else {
23363: $balancetext = $ruletitles{$rule};
1.252 raeburn 23364: }
1.171 raeburn 23365: } else {
23366: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
23367: }
1.210 raeburn 23368: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 23369: }
23370: }
23371: }
23372: }
1.342 raeburn 23373: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.389 raeburn 23374: if ($currcookies{$balancer}) {
23375: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
23376: $balancer).'</li>';
23377: } else {
23378: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
23379: $balancer).'</li>';
23380: }
1.342 raeburn 23381: }
1.375 raeburn 23382: }
23383: }
23384: if (keys(%toupdate)) {
23385: my %thismachine;
23386: my $updatedhere;
23387: my $cachetime = 60*60*24;
23388: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
23389: foreach my $lonhost (keys(%toupdate)) {
23390: if ($thismachine{$lonhost}) {
23391: unless ($updatedhere) {
23392: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
23393: $defaultshash{'loadbalancing'},
23394: $cachetime);
23395: $updatedhere = 1;
1.252 raeburn 23396: }
1.375 raeburn 23397: } else {
23398: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
23399: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.252 raeburn 23400: }
1.150 raeburn 23401: }
1.171 raeburn 23402: }
23403: if ($resulttext ne '') {
23404: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 23405: } else {
23406: $resulttext = $nochgmsg;
23407: }
23408: } else {
1.171 raeburn 23409: $resulttext = $nochgmsg;
1.150 raeburn 23410: }
23411: } else {
1.171 raeburn 23412: $resulttext = '<span class="LC_error">'.
23413: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 23414: }
23415: } else {
1.171 raeburn 23416: $resulttext = $nochgmsg;
1.150 raeburn 23417: }
23418: return $resulttext;
23419: }
23420:
1.48 raeburn 23421: sub recurse_check {
23422: my ($chkcats,$categories,$depth,$name) = @_;
23423: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
23424: my $chg = 0;
23425: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
23426: my $category = $chkcats->[$depth]{$name}[$j];
23427: my $item;
23428: if ($category eq '') {
23429: $chg ++;
23430: } else {
23431: my $deeper = $depth + 1;
23432: $item = &escape($category).':'.&escape($name).':'.$depth;
23433: if ($chg) {
23434: $categories->{$item} -= $chg;
23435: }
23436: &recurse_check($chkcats,$categories,$deeper,$category);
23437: $deeper --;
23438: }
23439: }
23440: }
23441: return;
23442: }
23443:
23444: sub recurse_cat_deletes {
23445: my ($item,$coursecategories,$deletions) = @_;
23446: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
23447: my $subdepth = $depth + 1;
23448: if (ref($coursecategories) eq 'HASH') {
23449: foreach my $subitem (keys(%{$coursecategories})) {
23450: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
23451: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
23452: delete($coursecategories->{$subitem});
23453: $deletions->{$subitem} = 1;
23454: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 23455: }
1.48 raeburn 23456: }
23457: }
23458: return;
23459: }
23460:
1.125 raeburn 23461: sub active_dc_picker {
1.191 raeburn 23462: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 23463: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 23464: my @domcoord = keys(%domcoords);
23465: if (keys(%currhash)) {
23466: foreach my $dc (keys(%currhash)) {
23467: unless (exists($domcoords{$dc})) {
23468: push(@domcoord,$dc);
23469: }
23470: }
23471: }
23472: @domcoord = sort(@domcoord);
1.210 raeburn 23473: my $numdcs = scalar(@domcoord);
1.191 raeburn 23474: my $rows = 0;
23475: my $table;
1.125 raeburn 23476: if ($numdcs > 1) {
1.191 raeburn 23477: $table = '<table>';
23478: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 23479: my $rem = $i%($numinrow);
23480: if ($rem == 0) {
23481: if ($i > 0) {
1.191 raeburn 23482: $table .= '</tr>';
1.125 raeburn 23483: }
1.191 raeburn 23484: $table .= '<tr>';
23485: $rows ++;
1.125 raeburn 23486: }
1.191 raeburn 23487: my $check = '';
23488: if ($inputtype eq 'radio') {
23489: if (keys(%currhash) == 0) {
23490: if (!$i) {
23491: $check = ' checked="checked"';
23492: }
23493: } elsif (exists($currhash{$domcoord[$i]})) {
23494: $check = ' checked="checked"';
23495: }
23496: } else {
23497: if (exists($currhash{$domcoord[$i]})) {
23498: $check = ' checked="checked"';
1.125 raeburn 23499: }
23500: }
1.191 raeburn 23501: if ($i == @domcoord - 1) {
1.125 raeburn 23502: my $colsleft = $numinrow - $rem;
23503: if ($colsleft > 1) {
1.191 raeburn 23504: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 23505: } else {
1.191 raeburn 23506: $table .= '<td class="LC_left_item">';
1.125 raeburn 23507: }
23508: } else {
1.191 raeburn 23509: $table .= '<td class="LC_left_item">';
23510: }
23511: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
23512: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
23513: $table .= '<span class="LC_nobreak"><label>'.
23514: '<input type="'.$inputtype.'" name="'.$name.'"'.
23515: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
23516: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 23517: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 23518: }
1.219 raeburn 23519: $table .= '</label></span></td>';
1.191 raeburn 23520: }
23521: $table .= '</tr></table>';
23522: } elsif ($numdcs == 1) {
1.219 raeburn 23523: my ($dcname,$dcdom) = split(':',$domcoord[0]);
23524: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 23525: if ($inputtype eq 'radio') {
1.247 raeburn 23526: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 23527: if ($user ne $dcname.':'.$dcdom) {
23528: $table .= ' ('.$dcname.':'.$dcdom.')';
23529: }
1.191 raeburn 23530: } else {
23531: my $check;
23532: if (exists($currhash{$domcoord[0]})) {
23533: $check = ' checked="checked"';
1.125 raeburn 23534: }
1.247 raeburn 23535: $table = '<span class="LC_nobreak"><label>'.
23536: '<input type="checkbox" name="'.$name.'" '.
23537: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 23538: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 23539: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 23540: }
1.220 raeburn 23541: $table .= '</label></span>';
1.191 raeburn 23542: $rows ++;
1.125 raeburn 23543: }
23544: }
1.191 raeburn 23545: return ($numdcs,$table,$rows);
1.125 raeburn 23546: }
23547:
1.137 raeburn 23548: sub usersession_titles {
23549: return &Apache::lonlocal::texthash(
23550: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
23551: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 23552: spares => 'Servers offloaded to, when busy',
1.137 raeburn 23553: version => 'LON-CAPA version requirement',
1.138 raeburn 23554: excludedomain => 'Allow all, but exclude specific domains',
23555: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 23556: primary => 'Primary (checked first)',
1.154 raeburn 23557: default => 'Default',
1.137 raeburn 23558: );
23559: }
23560:
1.152 raeburn 23561: sub id_for_thisdom {
23562: my (%servers) = @_;
23563: my %altids;
23564: foreach my $server (keys(%servers)) {
23565: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
23566: if ($serverhome ne $server) {
23567: $altids{$serverhome} = $server;
23568: }
23569: }
23570: return %altids;
23571: }
23572:
1.150 raeburn 23573: sub count_servers {
23574: my ($currbalancer,%servers) = @_;
23575: my (@spares,$numspares);
23576: foreach my $lonhost (sort(keys(%servers))) {
23577: next if ($currbalancer eq $lonhost);
23578: push(@spares,$lonhost);
23579: }
23580: if ($currbalancer) {
23581: $numspares = scalar(@spares);
23582: } else {
23583: $numspares = scalar(@spares) - 1;
23584: }
23585: return ($numspares,@spares);
23586: }
23587:
23588: sub lonbalance_targets_js {
1.171 raeburn 23589: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 23590: my $select = &mt('Select');
23591: my ($alltargets,$allishome,$allinsttypes,@alltypes);
23592: if (ref($servers) eq 'HASH') {
23593: $alltargets = join("','",sort(keys(%{$servers})));
23594: my @homedoms;
23595: foreach my $server (sort(keys(%{$servers}))) {
23596: if (&Apache::lonnet::host_domain($server) eq $dom) {
23597: push(@homedoms,'1');
23598: } else {
23599: push(@homedoms,'0');
23600: }
23601: }
23602: $allishome = join("','",@homedoms);
23603: }
23604: if (ref($types) eq 'ARRAY') {
23605: if (@{$types} > 0) {
23606: @alltypes = @{$types};
23607: }
23608: }
23609: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
23610: $allinsttypes = join("','",@alltypes);
1.342 raeburn 23611: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 23612: if (ref($settings) eq 'HASH') {
23613: %existing = %{$settings};
23614: }
23615: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 23616: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 23617: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 23618: return <<"END";
23619:
23620: <script type="text/javascript">
23621: // <![CDATA[
23622:
1.171 raeburn 23623: currBalancers = new Array('$balancers');
23624:
23625: function toggleTargets(balnum) {
23626: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23627: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
23628: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
23629: var prevbalancer = prevhostitem.value;
23630: var baltotal = document.getElementById('loadbalancing_total').value;
23631: prevhostitem.value = balancer;
23632: if (prevbalancer != '') {
23633: var prevIdx = currBalancers.indexOf(prevbalancer);
23634: if (prevIdx != -1) {
23635: currBalancers.splice(prevIdx,1);
23636: }
23637: }
1.150 raeburn 23638: if (balancer == '') {
1.171 raeburn 23639: hideSpares(balnum);
1.150 raeburn 23640: } else {
1.171 raeburn 23641: var currIdx = currBalancers.indexOf(balancer);
23642: if (currIdx == -1) {
23643: currBalancers.push(balancer);
23644: }
1.150 raeburn 23645: var homedoms = new Array('$allishome');
1.171 raeburn 23646: var ishomedom = homedoms[lonhostitem.selectedIndex];
23647: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 23648: }
1.171 raeburn 23649: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 23650: return;
23651: }
23652:
1.171 raeburn 23653: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 23654: var alltargets = new Array('$alltargets');
23655: var insttypes = new Array('$allinsttypes');
1.151 raeburn 23656: var offloadtypes = new Array('primary','default');
23657:
1.171 raeburn 23658: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
23659: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 23660:
1.151 raeburn 23661: for (var i=0; i<offloadtypes.length; i++) {
23662: var count = 0;
23663: for (var j=0; j<alltargets.length; j++) {
23664: if (alltargets[j] != balancer) {
1.171 raeburn 23665: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
23666: item.value = alltargets[j];
23667: item.style.textAlign='left';
23668: item.style.textFace='normal';
23669: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
23670: if (currBalancers.indexOf(alltargets[j]) == -1) {
23671: item.disabled = '';
23672: } else {
23673: item.disabled = 'disabled';
23674: item.checked = false;
23675: }
1.151 raeburn 23676: count ++;
23677: }
1.150 raeburn 23678: }
23679: }
1.151 raeburn 23680: for (var k=0; k<insttypes.length; k++) {
23681: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 23682: if (ishomedom == 1) {
1.171 raeburn 23683: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23684: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23685: } else {
1.171 raeburn 23686: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23687: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 23688: }
23689: } else {
1.171 raeburn 23690: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23691: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23692: }
1.151 raeburn 23693: if ((insttypes[k] != '_LC_external') &&
23694: ((insttypes[k] != '_LC_internetdom') ||
23695: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 23696: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
23697: item.options.length = 0;
23698: item.options[0] = new Option("","",true,true);
1.210 raeburn 23699: var idx = 0;
1.151 raeburn 23700: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 23701: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
23702: idx ++;
23703: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 23704: }
23705: }
23706: }
23707: }
23708: return;
23709: }
23710:
1.171 raeburn 23711: function hideSpares(balnum) {
1.150 raeburn 23712: var alltargets = new Array('$alltargets');
23713: var insttypes = new Array('$allinsttypes');
23714: var offloadtypes = new Array('primary','default');
23715:
1.171 raeburn 23716: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
23717: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 23718:
23719: var total = alltargets.length - 1;
23720: for (var i=0; i<offloadtypes; i++) {
23721: for (var j=0; j<total; j++) {
1.171 raeburn 23722: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
23723: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
23724: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 23725: }
1.150 raeburn 23726: }
23727: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 23728: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23729: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 23730: if (insttypes[k] != '_LC_external') {
1.171 raeburn 23731: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
23732: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 23733: }
23734: }
23735: return;
23736: }
23737:
1.171 raeburn 23738: function checkOffloads(item,balnum,type) {
1.150 raeburn 23739: var alltargets = new Array('$alltargets');
23740: var offloadtypes = new Array('primary','default');
23741: if (item.checked) {
23742: var total = alltargets.length - 1;
23743: var other;
23744: if (type == offloadtypes[0]) {
1.151 raeburn 23745: other = offloadtypes[1];
1.150 raeburn 23746: } else {
1.151 raeburn 23747: other = offloadtypes[0];
1.150 raeburn 23748: }
23749: for (var i=0; i<total; i++) {
1.171 raeburn 23750: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 23751: if (server == item.value) {
1.171 raeburn 23752: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
23753: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 23754: }
23755: }
23756: }
23757: }
23758: return;
23759: }
23760:
1.171 raeburn 23761: function singleServerToggle(balnum,type) {
23762: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 23763: if (offloadtoSelIdx == 0) {
1.171 raeburn 23764: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
23765: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23766:
23767: } else {
1.171 raeburn 23768: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
23769: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 23770: }
23771: return;
23772: }
23773:
1.171 raeburn 23774: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 23775: if (type == '_LC_external') {
1.171 raeburn 23776: return;
1.150 raeburn 23777: }
1.171 raeburn 23778: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 23779: for (var i=0; i<typesRules.length; i++) {
23780: if (formname.elements[typesRules[i]].checked) {
23781: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 23782: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
23783: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23784: } else {
1.171 raeburn 23785: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
23786: }
23787: }
23788: }
23789: return;
23790: }
23791:
23792: function balancerDeleteChange(balnum) {
23793: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23794: var baltotal = document.getElementById('loadbalancing_total').value;
23795: var addtarget;
23796: var removetarget;
23797: var action = 'delete';
23798: if (document.getElementById('loadbalancing_delete_'+balnum)) {
23799: var lonhost = hostitem.value;
23800: var currIdx = currBalancers.indexOf(lonhost);
23801: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
23802: if (currIdx != -1) {
23803: currBalancers.splice(currIdx,1);
23804: }
23805: addtarget = lonhost;
23806: } else {
23807: if (currIdx == -1) {
23808: currBalancers.push(lonhost);
23809: }
23810: removetarget = lonhost;
23811: action = 'undelete';
23812: }
23813: balancerChange(balnum,baltotal,action,addtarget,removetarget);
23814: }
23815: return;
23816: }
23817:
23818: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
23819: if (baltotal > 1) {
23820: var offloadtypes = new Array('primary','default');
23821: var alltargets = new Array('$alltargets');
23822: var insttypes = new Array('$allinsttypes');
23823: for (var i=0; i<baltotal; i++) {
23824: if (i != balnum) {
23825: for (var j=0; j<offloadtypes.length; j++) {
23826: var total = alltargets.length - 1;
23827: for (var k=0; k<total; k++) {
23828: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
23829: var server = serveritem.value;
23830: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23831: if (server == addtarget) {
23832: serveritem.disabled = '';
23833: }
23834: }
23835: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23836: if (server == removetarget) {
23837: serveritem.disabled = 'disabled';
23838: serveritem.checked = false;
23839: }
23840: }
23841: }
23842: }
23843: for (var j=0; j<insttypes.length; j++) {
23844: if (insttypes[j] != '_LC_external') {
23845: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
23846: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
23847: var currSel = singleserver.selectedIndex;
23848: var currVal = singleserver.options[currSel].value;
23849: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23850: var numoptions = singleserver.options.length;
23851: var needsnew = 1;
23852: for (var k=0; k<numoptions; k++) {
23853: if (singleserver.options[k] == addtarget) {
23854: needsnew = 0;
23855: break;
23856: }
23857: }
23858: if (needsnew == 1) {
23859: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
23860: }
23861: }
23862: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23863: singleserver.options.length = 0;
23864: if ((currVal) && (currVal != removetarget)) {
23865: singleserver.options[0] = new Option("","",false,false);
23866: } else {
23867: singleserver.options[0] = new Option("","",true,true);
23868: }
23869: var idx = 0;
23870: for (var m=0; m<alltargets.length; m++) {
23871: if (currBalancers.indexOf(alltargets[m]) == -1) {
23872: idx ++;
23873: if (currVal == alltargets[m]) {
23874: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
23875: } else {
23876: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
23877: }
23878: }
23879: }
23880: }
23881: }
23882: }
23883: }
1.150 raeburn 23884: }
23885: }
23886: }
23887: return;
23888: }
23889:
1.152 raeburn 23890: // ]]>
23891: </script>
23892:
23893: END
23894: }
23895:
23896: sub new_spares_js {
23897: my @sparestypes = ('primary','default');
23898: my $types = join("','",@sparestypes);
23899: my $select = &mt('Select');
23900: return <<"END";
23901:
23902: <script type="text/javascript">
23903: // <![CDATA[
23904:
23905: function updateNewSpares(formname,lonhost) {
23906: var types = new Array('$types');
23907: var include = new Array();
23908: var exclude = new Array();
23909: for (var i=0; i<types.length; i++) {
23910: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
23911: for (var j=0; j<spareboxes.length; j++) {
23912: if (formname.elements[spareboxes[j]].checked) {
23913: exclude.push(formname.elements[spareboxes[j]].value);
23914: } else {
23915: include.push(formname.elements[spareboxes[j]].value);
23916: }
23917: }
23918: }
23919: for (var i=0; i<types.length; i++) {
23920: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
23921: var selIdx = newSpare.selectedIndex;
23922: var currnew = newSpare.options[selIdx].value;
23923: var okSpares = new Array();
23924: for (var j=0; j<newSpare.options.length; j++) {
23925: var possible = newSpare.options[j].value;
23926: if (possible != '') {
23927: if (exclude.indexOf(possible) == -1) {
23928: okSpares.push(possible);
23929: } else {
23930: if (currnew == possible) {
23931: selIdx = 0;
23932: }
23933: }
23934: }
23935: }
23936: for (var k=0; k<include.length; k++) {
23937: if (okSpares.indexOf(include[k]) == -1) {
23938: okSpares.push(include[k]);
23939: }
23940: }
23941: okSpares.sort();
23942: newSpare.options.length = 0;
23943: if (selIdx == 0) {
23944: newSpare.options[0] = new Option("$select","",true,true);
23945: } else {
23946: newSpare.options[0] = new Option("$select","",false,false);
23947: }
23948: for (var m=0; m<okSpares.length; m++) {
23949: var idx = m+1;
23950: var selThis = 0;
23951: if (selIdx != 0) {
23952: if (okSpares[m] == currnew) {
23953: selThis = 1;
23954: }
23955: }
23956: if (selThis == 1) {
23957: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
23958: } else {
23959: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
23960: }
23961: }
23962: }
23963: return;
23964: }
23965:
23966: function checkNewSpares(lonhost,type) {
23967: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
23968: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.372 raeburn 23969: if (chosen != '') {
1.152 raeburn 23970: var othertype;
23971: var othernewSpare;
23972: if (type == 'primary') {
23973: othernewSpare = document.getElementById('newspare_default_'+lonhost);
23974: }
23975: if (type == 'default') {
23976: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
23977: }
23978: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
23979: othernewSpare.selectedIndex = 0;
23980: }
23981: }
23982: return;
23983: }
23984:
23985: // ]]>
23986: </script>
23987:
23988: END
23989:
23990: }
23991:
23992: sub common_domprefs_js {
23993: return <<"END";
23994:
23995: <script type="text/javascript">
23996: // <![CDATA[
23997:
1.150 raeburn 23998: function getIndicesByName(formname,item) {
1.152 raeburn 23999: var group = new Array();
1.150 raeburn 24000: for (var i=0;i<formname.elements.length;i++) {
24001: if (formname.elements[i].name == item) {
1.152 raeburn 24002: group.push(formname.elements[i].id);
1.150 raeburn 24003: }
24004: }
1.152 raeburn 24005: return group;
1.150 raeburn 24006: }
24007:
24008: // ]]>
24009: </script>
24010:
24011: END
1.152 raeburn 24012:
1.150 raeburn 24013: }
24014:
1.165 raeburn 24015: sub recaptcha_js {
24016: my %lt = &captcha_phrases();
24017: return <<"END";
24018:
24019: <script type="text/javascript">
24020: // <![CDATA[
24021:
24022: function updateCaptcha(caller,context) {
24023: var privitem;
24024: var pubitem;
24025: var privtext;
24026: var pubtext;
1.269 raeburn 24027: var versionitem;
24028: var versiontext;
1.165 raeburn 24029: if (document.getElementById(context+'_recaptchapub')) {
24030: pubitem = document.getElementById(context+'_recaptchapub');
24031: } else {
24032: return;
24033: }
24034: if (document.getElementById(context+'_recaptchapriv')) {
24035: privitem = document.getElementById(context+'_recaptchapriv');
24036: } else {
24037: return;
24038: }
24039: if (document.getElementById(context+'_recaptchapubtxt')) {
24040: pubtext = document.getElementById(context+'_recaptchapubtxt');
24041: } else {
24042: return;
24043: }
24044: if (document.getElementById(context+'_recaptchaprivtxt')) {
24045: privtext = document.getElementById(context+'_recaptchaprivtxt');
24046: } else {
24047: return;
24048: }
1.269 raeburn 24049: if (document.getElementById(context+'_recaptchaversion')) {
24050: versionitem = document.getElementById(context+'_recaptchaversion');
24051: } else {
24052: return;
24053: }
24054: if (document.getElementById(context+'_recaptchavertxt')) {
24055: versiontext = document.getElementById(context+'_recaptchavertxt');
24056: } else {
24057: return;
24058: }
1.165 raeburn 24059: if (caller.checked) {
24060: if (caller.value == 'recaptcha') {
24061: pubitem.type = 'text';
24062: privitem.type = 'text';
24063: pubitem.size = '40';
24064: privitem.size = '40';
24065: pubtext.innerHTML = "$lt{'pub'}";
24066: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 24067: versionitem.type = 'text';
24068: versionitem.size = '3';
1.289 raeburn 24069: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 24070: } else {
24071: pubitem.type = 'hidden';
24072: privitem.type = 'hidden';
1.269 raeburn 24073: versionitem.type = 'hidden';
1.165 raeburn 24074: pubtext.innerHTML = '';
24075: privtext.innerHTML = '';
1.269 raeburn 24076: versiontext.innerHTML = '';
1.165 raeburn 24077: }
24078: }
24079: return;
24080: }
24081:
24082: // ]]>
24083: </script>
24084:
24085: END
24086:
24087: }
24088:
1.236 raeburn 24089: sub toggle_display_js {
1.192 raeburn 24090: return <<"END";
24091:
24092: <script type="text/javascript">
24093: // <![CDATA[
24094:
1.236 raeburn 24095: function toggleDisplay(domForm,caller) {
24096: if (document.getElementById(caller)) {
24097: var divitem = document.getElementById(caller);
24098: var optionsElement = domForm.coursecredits;
1.264 raeburn 24099: var checkval = 1;
24100: var dispval = 'block';
1.303 raeburn 24101: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 24102: if (caller == 'emailoptions') {
1.372 raeburn 24103: optionsElement = domForm.cancreate_email;
1.236 raeburn 24104: }
1.257 raeburn 24105: if (caller == 'studentsubmission') {
24106: optionsElement = domForm.postsubmit;
24107: }
1.264 raeburn 24108: if (caller == 'cloneinstcode') {
24109: optionsElement = domForm.canclone;
24110: checkval = 'instcode';
24111: }
1.303 raeburn 24112: if (selfcreateRegExp.test(caller)) {
24113: optionsElement = domForm.elements[caller];
24114: checkval = 'other';
24115: dispval = 'inline'
24116: }
1.236 raeburn 24117: if (optionsElement.length) {
1.192 raeburn 24118: var currval;
1.236 raeburn 24119: for (var i=0; i<optionsElement.length; i++) {
24120: if (optionsElement[i].checked) {
24121: currval = optionsElement[i].value;
1.192 raeburn 24122: }
24123: }
1.264 raeburn 24124: if (currval == checkval) {
24125: divitem.style.display = dispval;
1.192 raeburn 24126: } else {
1.236 raeburn 24127: divitem.style.display = 'none';
1.192 raeburn 24128: }
24129: }
24130: }
24131: return;
24132: }
24133:
24134: // ]]>
24135: </script>
24136:
24137: END
24138:
24139: }
24140:
1.165 raeburn 24141: sub captcha_phrases {
24142: return &Apache::lonlocal::texthash (
24143: priv => 'Private key',
24144: pub => 'Public key',
24145: original => 'original (CAPTCHA)',
24146: recaptcha => 'successor (ReCAPTCHA)',
24147: notused => 'unused',
1.289 raeburn 24148: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 24149: );
24150: }
24151:
1.205 raeburn 24152: sub devalidate_remote_domconfs {
1.212 raeburn 24153: my ($dom,$cachekeys) = @_;
24154: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 24155: my %servers = &Apache::lonnet::internet_dom_servers($dom);
24156: my %thismachine;
24157: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 raeburn 24158: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.394 raeburn 24159: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
1.410 raeburn 24160: 'ipaccess','trust');
1.386 raeburn 24161: my %cache_by_lonhost;
24162: if (exists($cachekeys->{'samllanding'})) {
24163: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
24164: my %landing = %{$cachekeys->{'samllanding'}};
24165: my %domservers = &Apache::lonnet::get_servers($dom);
24166: if (keys(%domservers)) {
24167: foreach my $server (keys(%domservers)) {
24168: my @cached;
24169: next if ($thismachine{$server});
24170: if ($landing{$server}) {
24171: push(@cached,&escape('samllanding').':'.&escape($server));
24172: }
24173: if (@cached) {
24174: $cache_by_lonhost{$server} = \@cached;
24175: }
24176: }
24177: }
24178: }
24179: }
1.260 raeburn 24180: if (keys(%servers)) {
1.205 raeburn 24181: foreach my $server (keys(%servers)) {
24182: next if ($thismachine{$server});
1.212 raeburn 24183: my @cached;
24184: foreach my $name (@posscached) {
24185: if ($cachekeys->{$name}) {
1.388 raeburn 24186: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
1.386 raeburn 24187: if (ref($cachekeys->{$name}) eq 'HASH') {
1.373 raeburn 24188: foreach my $key (keys(%{$cachekeys->{$name}})) {
24189: push(@cached,&escape($name).':'.&escape($key));
24190: }
24191: }
24192: } else {
24193: push(@cached,&escape($name).':'.&escape($dom));
24194: }
1.212 raeburn 24195: }
24196: }
1.386 raeburn 24197: if ((exists($cache_by_lonhost{$server})) &&
24198: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
24199: push(@cached,@{$cache_by_lonhost{$server}});
24200: }
1.212 raeburn 24201: if (@cached) {
24202: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
24203: }
1.205 raeburn 24204: }
24205: }
24206: return;
24207: }
24208:
1.3 raeburn 24209: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>