Annotation of loncom/interface/domainprefs.pm, revision 1.433
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.433 ! raeburn 4: # $Id: domainprefs.pm,v 1.432 2023/12/23 02:17:38 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.429 raeburn 389: col3 => 'Portfilo quota (MB)',}],
1.230 raeburn 390: print => \&print_quotas,
391: modify => \&modify_quotas,
1.30 raeburn 392: },
393: 'autoenroll' =>
394: { text => 'Auto-enrollment settings',
1.67 raeburn 395: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 396: header => [{col1 => 'Configuration setting',
397: col2 => 'Value(s)'}],
1.230 raeburn 398: print => \&print_autoenroll,
399: modify => \&modify_autoenroll,
1.30 raeburn 400: },
401: 'autoupdate' =>
402: { text => 'Auto-update settings',
1.67 raeburn 403: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 404: header => [{col1 => 'Setting',
405: col2 => 'Value',},
1.131 raeburn 406: {col1 => 'Setting',
407: col2 => 'Affiliation'},
1.43 raeburn 408: {col1 => 'User population',
1.227 bisitz 409: col2 => 'Updatable user data'}],
1.230 raeburn 410: print => \&print_autoupdate,
411: modify => \&modify_autoupdate,
1.30 raeburn 412: },
1.125 raeburn 413: 'autocreate' =>
414: { text => 'Auto-course creation settings',
415: help => 'Domain_Configuration_Auto_Creation',
416: header => [{col1 => 'Configuration Setting',
417: col2 => 'Value',}],
1.230 raeburn 418: print => \&print_autocreate,
419: modify => \&modify_autocreate,
1.125 raeburn 420: },
1.30 raeburn 421: 'directorysrch' =>
1.277 raeburn 422: { text => 'Directory searches',
1.67 raeburn 423: help => 'Domain_Configuration_InstDirectory_Search',
1.277 raeburn 424: header => [{col1 => 'Institutional Directory Setting',
425: col2 => 'Value',},
426: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 427: col2 => 'Value',}],
1.230 raeburn 428: print => \&print_directorysrch,
429: modify => \&modify_directorysrch,
1.30 raeburn 430: },
431: 'contacts' =>
1.286 raeburn 432: { text => 'E-mail addresses and helpform',
1.67 raeburn 433: help => 'Domain_Configuration_Contact_Info',
1.286 raeburn 434: header => [{col1 => 'Default e-mail addresses',
435: col2 => 'Value',},
436: {col1 => 'Recipient(s) for notifications',
437: col2 => 'Value',},
1.340 raeburn 438: {col1 => 'Nightly status check e-mail',
439: col2 => 'Settings',},
1.286 raeburn 440: {col1 => 'Ask helpdesk form settings',
441: col2 => 'Value',},],
1.230 raeburn 442: print => \&print_contacts,
443: modify => \&modify_contacts,
1.30 raeburn 444: },
445: 'usercreation' =>
446: { text => 'User creation',
1.67 raeburn 447: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 448: header => [{col1 => 'Format rule type',
449: col2 => 'Format rules in force'},
1.34 raeburn 450: {col1 => 'User account creation',
451: col2 => 'Usernames which may be created',},
1.30 raeburn 452: {col1 => 'Context',
1.43 raeburn 453: col2 => 'Assignable authentication types'}],
1.230 raeburn 454: print => \&print_usercreation,
455: modify => \&modify_usercreation,
1.30 raeburn 456: },
1.224 raeburn 457: 'selfcreation' =>
458: { text => 'Users self-creating accounts',
459: help => 'Domain_Configuration_Self_Creation',
460: header => [{col1 => 'Self-creation with institutional username',
461: col2 => 'Enabled?'},
462: {col1 => 'Institutional user type (login/SSO self-creation)',
463: col2 => 'Information user can enter'},
1.303 raeburn 464: {col1 => 'Self-creation with e-mail verification',
1.224 raeburn 465: col2 => 'Settings'}],
1.230 raeburn 466: print => \&print_selfcreation,
467: modify => \&modify_selfcreation,
1.224 raeburn 468: },
1.69 raeburn 469: 'usermodification' =>
1.33 raeburn 470: { text => 'User modification',
1.67 raeburn 471: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 472: header => [{col1 => 'Target user has role',
1.227 bisitz 473: col2 => 'User information updatable in author context'},
1.33 raeburn 474: {col1 => 'Target user has role',
1.227 bisitz 475: col2 => 'User information updatable in course context'}],
1.230 raeburn 476: print => \&print_usermodification,
477: modify => \&modify_usermodification,
1.33 raeburn 478: },
1.69 raeburn 479: 'scantron' =>
1.346 raeburn 480: { text => 'Bubblesheet format',
1.67 raeburn 481: help => 'Domain_Configuration_Scantron_Format',
1.346 raeburn 482: header => [ {col1 => 'Bubblesheet format file',
483: col2 => ''},
484: {col1 => 'Bubblesheet data upload formats',
485: col2 => 'Settings'}],
1.230 raeburn 486: print => \&print_scantron,
487: modify => \&modify_scantron,
1.46 raeburn 488: },
1.86 raeburn 489: 'requestcourses' =>
490: {text => 'Request creation of courses',
491: help => 'Domain_Configuration_Request_Courses',
492: header => [{col1 => 'User affiliation',
1.102 raeburn 493: col2 => 'Availability/Processing of requests',},
494: {col1 => 'Setting',
1.216 raeburn 495: col2 => 'Value'},
496: {col1 => 'Available textbooks',
1.235 raeburn 497: col2 => ''},
1.242 raeburn 498: {col1 => 'Available templates',
499: col2 => ''},
1.235 raeburn 500: {col1 => 'Validation (not official courses)',
501: col2 => 'Value'},],
1.230 raeburn 502: print => \&print_quotas,
503: modify => \&modify_quotas,
1.86 raeburn 504: },
1.163 raeburn 505: 'requestauthor' =>
1.223 bisitz 506: {text => 'Request Authoring Space',
1.163 raeburn 507: help => 'Domain_Configuration_Request_Author',
508: header => [{col1 => 'User affiliation',
509: col2 => 'Availability/Processing of requests',},
510: {col1 => 'Setting',
511: col2 => 'Value'}],
1.230 raeburn 512: print => \&print_quotas,
513: modify => \&modify_quotas,
1.163 raeburn 514: },
1.69 raeburn 515: 'coursecategories' =>
1.120 raeburn 516: { text => 'Cataloging of courses/communities',
1.67 raeburn 517: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 518: header => [{col1 => 'Catalog type/availability',
519: col2 => '',},
520: {col1 => 'Category settings for standard catalog',
1.57 raeburn 521: col2 => '',},
522: {col1 => 'Categories',
523: col2 => '',
524: }],
1.230 raeburn 525: print => \&print_coursecategories,
526: modify => \&modify_coursecategories,
1.69 raeburn 527: },
528: 'serverstatuses' =>
1.77 raeburn 529: {text => 'Access to server status pages',
1.69 raeburn 530: help => 'Domain_Configuration_Server_Status',
531: header => [{col1 => 'Status Page',
532: col2 => 'Other named users',
533: col3 => 'Specific IPs',
534: }],
1.230 raeburn 535: print => \&print_serverstatuses,
536: modify => \&modify_serverstatuses,
1.69 raeburn 537: },
1.118 jms 538: 'helpsettings' =>
1.282 raeburn 539: {text => 'Support settings',
1.118 jms 540: help => 'Domain_Configuration_Help_Settings',
1.282 raeburn 541: header => [{col1 => 'Help Page Settings (logged-in users)',
542: col2 => 'Value'},
543: {col1 => 'Helpdesk Roles',
544: col2 => 'Settings'},],
1.230 raeburn 545: print => \&print_helpsettings,
546: modify => \&modify_helpsettings,
1.118 jms 547: },
1.121 raeburn 548: 'coursedefaults' =>
549: {text => 'Course/Community defaults',
550: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 551: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
552: col2 => 'Value',},
553: {col1 => 'Defaults which can be overridden for each course by a DC',
554: col2 => 'Value',},],
1.230 raeburn 555: print => \&print_coursedefaults,
556: modify => \&modify_coursedefaults,
1.121 raeburn 557: },
1.231 raeburn 558: 'selfenrollment' =>
559: {text => 'Self-enrollment in Course/Community',
560: help => 'Domain_Configuration_Selfenrollment',
561: header => [{col1 => 'Configuration Rights',
562: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
563: {col1 => 'Defaults',
564: col2 => 'Value'},
565: {col1 => 'Self-enrollment validation (optional)',
566: col2 => 'Value'},],
567: print => \&print_selfenrollment,
568: modify => \&modify_selfenrollment,
569: },
1.120 raeburn 570: 'privacy' =>
1.427 raeburn 571: {text => 'Role assignments and user privacy',
1.120 raeburn 572: help => 'Domain_Configuration_User_Privacy',
1.357 raeburn 573: header => [{col1 => 'Role assigned in different domain',
574: col2 => 'Approval options'},
575: {col1 => 'Role assigned in different domain to user of type',
576: col2 => 'User information available in that domain'},
577: {col1 => "Role assigned in user's domain",
578: col2 => 'Information viewable by privileged user'},
579: {col1 => "Role assigned in user's domain",
580: col2 => 'Information viewable by unprivileged user'}],
1.230 raeburn 581: print => \&print_privacy,
582: modify => \&modify_privacy,
1.120 raeburn 583: },
1.141 raeburn 584: 'usersessions' =>
1.145 raeburn 585: {text => 'User session hosting/offloading',
1.137 raeburn 586: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 587: header => [{col1 => 'Domain server',
588: col2 => 'Servers to offload sessions to when busy'},
589: {col1 => 'Hosting of users from other domains',
1.137 raeburn 590: col2 => 'Rules'},
591: {col1 => "Hosting domain's own users elsewhere",
592: col2 => 'Rules'}],
1.230 raeburn 593: print => \&print_usersessions,
594: modify => \&modify_usersessions,
1.137 raeburn 595: },
1.279 raeburn 596: 'loadbalancing' =>
1.185 raeburn 597: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 598: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 599: header => [{col1 => 'Balancers',
1.150 raeburn 600: col2 => 'Default destinations',
1.183 bisitz 601: col3 => 'User affiliation',
1.150 raeburn 602: col4 => 'Overrides'},
603: ],
1.230 raeburn 604: print => \&print_loadbalancing,
605: modify => \&modify_loadbalancing,
1.150 raeburn 606: },
1.425 raeburn 607: 'ltitools' =>
1.267 raeburn 608: {text => 'External Tools (LTI)',
1.296 raeburn 609: help => 'Domain_Configuration_LTI_Tools',
1.421 raeburn 610: header => [{col1 => 'Encryption of shared secrets',
611: col2 => 'Settings'},
612: {col1 => 'Rules for shared secrets',
613: col2 => 'Settings'},
614: {col1 => 'Providers',
615: col2 => 'Settings',}],
1.267 raeburn 616: print => \&print_ltitools,
617: modify => \&modify_ltitools,
618: },
1.372 raeburn 619: 'proctoring' =>
620: {text => 'Remote Proctoring Integration',
621: help => 'Domain_Configuration_Proctoring',
622: header => [{col1 => 'Name',
623: col2 => 'Configuration'}],
624: print => \&print_proctoring,
625: modify => \&modify_proctoring,
626: },
1.279 raeburn 627: 'ssl' =>
1.275 raeburn 628: {text => 'LON-CAPA Network (SSL)',
629: help => 'Domain_Configuration_Network_SSL',
630: header => [{col1 => 'Server',
631: col2 => 'Certificate Status'},
632: {col1 => 'Connections to other servers',
633: col2 => 'Rules'},
1.293 raeburn 634: {col1 => 'Connections from other servers',
635: col2 => 'Rules'},
1.275 raeburn 636: {col1 => "Replicating domain's published content",
637: col2 => 'Rules'}],
638: print => \&print_ssl,
639: modify => \&modify_ssl,
640: },
1.279 raeburn 641: 'trust' =>
642: {text => 'Trust Settings',
643: help => 'Domain_Configuration_Trust',
644: header => [{col1 => "Access to this domain's content by others",
645: col2 => 'Rules'},
646: {col1 => "Access to other domain's content by this domain",
647: col2 => 'Rules'},
648: {col1 => "Enrollment in this domain's courses by others",
649: col2 => 'Rules',},
650: {col1 => "Co-author roles in this domain for others",
651: col2 => 'Rules',},
652: {col1 => "Co-author roles for this domain's users elsewhere",
653: col2 => 'Rules',},
654: {col1 => "Domain roles in this domain assignable to others",
655: col2 => 'Rules'},
656: {col1 => "Course catalog for this domain displayed elsewhere",
657: col2 => 'Rules'},
658: {col1 => "Requests for creation of courses in this domain by others",
659: col2 => 'Rules'},
660: {col1 => "Users in other domains can send messages to this domain",
661: col2 => 'Rules'},],
662: print => \&print_trust,
663: modify => \&modify_trust,
664: },
1.425 raeburn 665: 'lti' =>
1.405 raeburn 666: {text => 'LTI Link Protection and LTI Consumers',
1.320 raeburn 667: help => 'Domain_Configuration_LTI_Provider',
1.405 raeburn 668: header => [{col1 => 'Encryption of shared secrets',
669: col2 => 'Settings'},
1.425 raeburn 670: {col1 => 'Rules for shared secrets',
1.405 raeburn 671: col2 => 'Settings'},
1.406 raeburn 672: {col1 => 'Link Protectors',
1.405 raeburn 673: col2 => 'Settings'},
674: {col1 => 'Consumers',
675: col2 => 'Settings'},],
1.320 raeburn 676: print => \&print_lti,
677: modify => \&modify_lti,
678: },
1.425 raeburn 679: 'ipaccess' =>
1.394 raeburn 680: {text => 'IP-based access control',
681: help => 'Domain_Configuration_IP_Access',
682: header => [{col1 => 'Setting',
683: col2 => 'Value'},],
684: print => \&print_ipaccess,
685: modify => \&modify_ipaccess,
686: },
1.429 raeburn 687: 'authordefaults' =>
688: {text => 'Authoring Space defaults',
689: help => 'Domain_Configuration_Author_Defaults',
690: header => [{col1 => 'Defaults which can be overridden by Author',
691: col2 => 'Settings',},
692: {col1 => 'Defaults which can be overridden by a Dom. Coord.',
693: col2 => 'Settings',},],
694: print => \&print_authordefaults,
695: modify => \&modify_authordefaults,
696: },
1.3 raeburn 697: );
1.110 raeburn 698: if (keys(%servers) > 1) {
699: $prefs{'login'} = { text => 'Log-in page options',
700: help => 'Domain_Configuration_Login_Page',
701: header => [{col1 => 'Log-in Service',
702: col2 => 'Server Setting',},
703: {col1 => 'Log-in Page Items',
1.405 raeburn 704: col2 => 'Settings'},
1.168 raeburn 705: {col1 => 'Log-in Help',
1.256 raeburn 706: col2 => 'Value'},
707: {col1 => 'Custom HTML in document head',
1.386 raeburn 708: col2 => 'Value'},
709: {col1 => 'SSO',
710: col2 => 'Dual login: SSO and non-SSO options'},
711: ],
1.230 raeburn 712: print => \&print_login,
713: modify => \&modify_login,
1.110 raeburn 714: };
715: }
1.174 foxr 716:
1.6 raeburn 717: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 718: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 719: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 720: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 721: text=>"Settings to display/modify"});
1.9 raeburn 722: my $confname = $dom.'-domainconfig';
1.174 foxr 723:
1.3 raeburn 724: if ($phase eq 'process') {
1.212 raeburn 725: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
726: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 727: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 728: $r->rflush();
1.212 raeburn 729: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 730: }
1.30 raeburn 731: } elsif ($phase eq 'display') {
1.192 raeburn 732: my $js = &recaptcha_js().
1.236 raeburn 733: &toggle_display_js();
1.171 raeburn 734: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 735: my ($othertitle,$usertypes,$types) =
736: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 737: $js .= &lonbalance_targets_js($dom,$types,\%servers,
738: $domconfig{'loadbalancing'}).
1.170 raeburn 739: &new_spares_js().
740: &common_domprefs_js().
741: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 742: }
1.216 raeburn 743: if (grep(/^requestcourses$/,@actions)) {
744: my $javascript_validations;
745: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
746: $js .= <<END;
747: <script type="text/javascript">
748: $javascript_validations
749: </script>
750: $coursebrowserjs
751: END
1.394 raeburn 752: } elsif (grep(/^ipaccess$/,@actions)) {
753: $js .= &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
1.216 raeburn 754: }
1.305 raeburn 755: if (grep(/^selfcreation$/,@actions)) {
756: $js .= &selfcreate_javascript();
757: }
1.286 raeburn 758: if (grep(/^contacts$/,@actions)) {
759: $js .= &contacts_javascript();
760: }
1.346 raeburn 761: if (grep(/^scantron$/,@actions)) {
762: $js .= &scantron_javascript();
763: }
1.150 raeburn 764: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 765: } else {
1.180 raeburn 766: # check if domconfig user exists for the domain.
767: my $servadm = $r->dir_config('lonAdmEMail');
768: my ($configuserok,$author_ok,$switchserver) =
769: &config_check($dom,$confname,$servadm);
770: unless ($configuserok eq 'ok') {
1.181 raeburn 771: &Apache::lonconfigsettings::print_header($r,$phase,$context);
772: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 773: $confname).
1.181 raeburn 774: '<br />'
775: );
1.180 raeburn 776: if ($switchserver) {
1.181 raeburn 777: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
778: '<br />'.
779: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
780: '<br />'.
781: &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).
782: '<br />'.
783: &mt('To do that now, use the following link: [_1]',$switchserver)
784: );
785: } else {
786: $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.').
787: '<br />'.
788: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
789: );
1.180 raeburn 790: }
791: $r->print(&Apache::loncommon::end_page());
792: return OK;
793: }
1.21 raeburn 794: if (keys(%domconfig) == 0) {
795: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 796: my @ids=&Apache::lonnet::current_machine_ids();
797: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 798: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 799: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 800: my $custom_img_count = 0;
801: foreach my $img (@loginimages) {
802: if ($designhash{$dom.'.login.'.$img} ne '') {
803: $custom_img_count ++;
804: }
805: }
806: foreach my $role (@roles) {
807: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
808: $custom_img_count ++;
809: }
810: }
811: if ($custom_img_count > 0) {
1.94 raeburn 812: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 813: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 814: $r->print(
815: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
816: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
817: &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 />'.
818: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
819: if ($switch_server) {
1.30 raeburn 820: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 821: }
1.91 raeburn 822: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 823: return OK;
824: }
825: }
826: }
1.91 raeburn 827: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 828: }
829: return OK;
830: }
831:
832: sub process_changes {
1.205 raeburn 833: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 834: my %domconfig;
835: if (ref($values) eq 'HASH') {
836: %domconfig = %{$values};
837: }
1.3 raeburn 838: my $output;
839: if ($action eq 'login') {
1.205 raeburn 840: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 841: } elsif ($action eq 'rolecolors') {
1.9 raeburn 842: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 843: $lastactref,%domconfig);
1.3 raeburn 844: } elsif ($action eq 'quotas') {
1.216 raeburn 845: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 846: } elsif ($action eq 'autoenroll') {
1.205 raeburn 847: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 848: } elsif ($action eq 'autoupdate') {
849: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 850: } elsif ($action eq 'autocreate') {
851: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 852: } elsif ($action eq 'directorysrch') {
1.295 raeburn 853: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 854: } elsif ($action eq 'usercreation') {
1.28 raeburn 855: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 856: } elsif ($action eq 'selfcreation') {
1.305 raeburn 857: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 858: } elsif ($action eq 'usermodification') {
859: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 860: } elsif ($action eq 'contacts') {
1.205 raeburn 861: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 862: } elsif ($action eq 'defaults') {
1.212 raeburn 863: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 864: } elsif ($action eq 'scantron') {
1.205 raeburn 865: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 866: } elsif ($action eq 'coursecategories') {
1.239 raeburn 867: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 868: } elsif ($action eq 'serverstatuses') {
869: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 870: } elsif ($action eq 'requestcourses') {
1.216 raeburn 871: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 872: } elsif ($action eq 'requestauthor') {
1.216 raeburn 873: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 874: } elsif ($action eq 'helpsettings') {
1.285 raeburn 875: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 876: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 877: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 878: } elsif ($action eq 'selfenrollment') {
879: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 880: } elsif ($action eq 'usersessions') {
1.212 raeburn 881: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 882: } elsif ($action eq 'loadbalancing') {
883: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 884: } elsif ($action eq 'ltitools') {
885: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.372 raeburn 886: } elsif ($action eq 'proctoring') {
887: $output = &modify_proctoring($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 888: } elsif ($action eq 'ssl') {
889: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 890: } elsif ($action eq 'trust') {
891: $output = &modify_trust($dom,$lastactref,%domconfig);
1.320 raeburn 892: } elsif ($action eq 'lti') {
893: $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.357 raeburn 894: } elsif ($action eq 'privacy') {
1.427 raeburn 895: $output = &modify_privacy($dom,$lastactref,%domconfig);
1.354 raeburn 896: } elsif ($action eq 'passwords') {
897: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.373 raeburn 898: } elsif ($action eq 'wafproxy') {
899: $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
1.394 raeburn 900: } elsif ($action eq 'ipaccess') {
901: $output = &modify_ipaccess($dom,$lastactref,%domconfig);
1.429 raeburn 902: } elsif ($action eq 'authordefaults') {
903: $output = &modify_authordefaults($dom,$lastactref,%domconfig);
1.3 raeburn 904: }
905: return $output;
906: }
907:
908: sub print_config_box {
1.9 raeburn 909: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 910: my $rowtotal = 0;
1.49 raeburn 911: my $output;
912: if ($action eq 'coursecategories') {
913: $output = &coursecategories_javascript($settings);
1.236 raeburn 914: } elsif ($action eq 'defaults') {
915: $output = &defaults_javascript($settings);
1.354 raeburn 916: } elsif ($action eq 'passwords') {
1.405 raeburn 917: $output = &passwords_javascript($action);
1.282 raeburn 918: } elsif ($action eq 'helpsettings') {
919: my (%privs,%levelscurrent);
920: my %full=();
921: my %levels=(
922: course => {},
923: domain => {},
924: system => {},
925: );
926: my $context = 'domain';
927: my $crstype = 'Course';
928: my $formname = 'display';
929: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
930: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
931: $output =
1.425 raeburn 932: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
1.282 raeburn 933: \@templateroles);
1.334 raeburn 934: } elsif ($action eq 'ltitools') {
1.421 raeburn 935: $output .= &Apache::lonconfigsettings::ltitools_javascript($settings);
1.334 raeburn 936: } elsif ($action eq 'lti') {
1.421 raeburn 937: $output .= &passwords_javascript('ltisecrets')."\n".
1.405 raeburn 938: <i_javascript($dom,$settings);
1.372 raeburn 939: } elsif ($action eq 'proctoring') {
940: $output .= &proctoring_javascript($settings);
1.381 raeburn 941: } elsif ($action eq 'wafproxy') {
942: $output .= &wafproxy_javascript($dom);
1.385 raeburn 943: } elsif ($action eq 'autoupdate') {
944: $output .= &autoupdate_javascript();
1.399 raeburn 945: } elsif ($action eq 'autoenroll') {
946: $output .= &autoenroll_javascript();
1.386 raeburn 947: } elsif ($action eq 'login') {
948: $output .= &saml_javascript();
1.394 raeburn 949: } elsif ($action eq 'ipaccess') {
950: $output .= &ipaccess_javascript($settings);
1.429 raeburn 951: } elsif ($action eq 'authordefaults') {
952: $output .= &authordefaults_javascript();
1.91 raeburn 953: }
1.236 raeburn 954: $output .=
1.30 raeburn 955: '<table class="LC_nested_outer">
1.3 raeburn 956: <tr>
1.306 raeburn 957: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 958: &mt($item->{text}).' '.
959: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
960: '</tr>';
1.30 raeburn 961: $rowtotal ++;
1.110 raeburn 962: my $numheaders = 1;
963: if (ref($item->{'header'}) eq 'ARRAY') {
964: $numheaders = scalar(@{$item->{'header'}});
965: }
966: if ($numheaders > 1) {
1.64 raeburn 967: my $colspan = '';
1.145 raeburn 968: my $rightcolspan = '';
1.369 raeburn 969: my $leftnobr = '';
1.238 raeburn 970: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 971: ($action eq 'directorysrch') ||
1.386 raeburn 972: (($action eq 'login') && ($numheaders < 5))) {
1.64 raeburn 973: $colspan = ' colspan="2"';
974: }
1.145 raeburn 975: if ($action eq 'usersessions') {
976: $rightcolspan = ' colspan="3"';
977: }
1.369 raeburn 978: if ($action eq 'passwords') {
979: $leftnobr = ' LC_nobreak';
980: }
1.30 raeburn 981: $output .= '
1.3 raeburn 982: <tr>
983: <td>
984: <table class="LC_nested">
985: <tr class="LC_info_row">
1.369 raeburn 986: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 987: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 988: </tr>';
1.69 raeburn 989: $rowtotal ++;
1.230 raeburn 990: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 991: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 992: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 993: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
1.421 raeburn 994: ($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'wafproxy') ||
1.429 raeburn 995: ($action eq 'lti') || ($action eq 'ltitools') || ($action eq 'authordefaults')) {
1.230 raeburn 996: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.354 raeburn 997: } elsif ($action eq 'passwords') {
998: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 999: } elsif ($action eq 'coursecategories') {
1.230 raeburn 1000: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.346 raeburn 1001: } elsif ($action eq 'scantron') {
1002: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 1003: } elsif ($action eq 'login') {
1.386 raeburn 1004: if ($numheaders == 5) {
1.168 raeburn 1005: $colspan = ' colspan="2"';
1006: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
1007: } else {
1008: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
1009: }
1.230 raeburn 1010: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 1011: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 1012: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1013: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 1014: }
1.30 raeburn 1015: $output .= '
1.6 raeburn 1016: </table>
1017: </td>
1018: </tr>
1019: <tr>
1020: <td>
1021: <table class="LC_nested">
1022: <tr class="LC_info_row">
1.230 raeburn 1023: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 1024: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 1025: </tr>';
1026: $rowtotal ++;
1.230 raeburn 1027: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
1028: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 1029: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.409 raeburn 1030: ($action eq 'trust') || ($action eq 'contacts') || ($action eq 'defaults') ||
1.421 raeburn 1031: ($action eq 'privacy') || ($action eq 'passwords') || ($action eq 'lti') ||
1032: ($action eq 'ltitools')) {
1.238 raeburn 1033: if ($action eq 'coursecategories') {
1034: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
1035: $colspan = ' colspan="2"';
1.279 raeburn 1036: } elsif ($action eq 'trust') {
1037: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.354 raeburn 1038: } elsif ($action eq 'passwords') {
1039: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.238 raeburn 1040: } else {
1041: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
1042: }
1.279 raeburn 1043: if ($action eq 'trust') {
1044: $output .= '
1045: </table>
1046: </td>
1047: </tr>';
1048: my @trusthdrs = qw(2 3 4 5 6 7);
1049: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
1050: for (my $i=0; $i<@trusthdrs; $i++) {
1051: $output .= '
1052: <tr>
1053: <td>
1054: <table class="LC_nested">
1055: <tr class="LC_info_row">
1056: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
1057: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
1058: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
1059: </table>
1060: </td>
1061: </tr>';
1062: }
1063: $output .= '
1064: <tr>
1065: <td>
1066: <table class="LC_nested">
1067: <tr class="LC_info_row">
1068: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
1069: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
1070: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1071: } else {
1072: $output .= '
1.63 raeburn 1073: </table>
1074: </td>
1075: </tr>
1076: <tr>
1077: <td>
1078: <table class="LC_nested">
1079: <tr class="LC_info_row">
1080: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 1081: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 1082: </tr>'."\n";
1.279 raeburn 1083: if ($action eq 'coursecategories') {
1084: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.405 raeburn 1085: } elsif (($action eq 'contacts') || ($action eq 'privacy') ||
1086: ($action eq 'passwords') || ($action eq 'lti')) {
1.354 raeburn 1087: if ($action eq 'passwords') {
1088: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
1089: } else {
1090: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
1091: }
1092: $output .= '
1.340 raeburn 1093: </tr>
1094: </table>
1095: </td>
1096: </tr>
1097: <tr>
1098: <td>
1099: <table class="LC_nested">
1100: <tr class="LC_info_row">
1.369 raeburn 1101: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1.354 raeburn 1102: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
1103: if ($action eq 'passwords') {
1104: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
1105: } else {
1106: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1107: }
1108: $output .= '
1.340 raeburn 1109: </table>
1110: </td>
1111: </tr>
1112: <tr>';
1.279 raeburn 1113: } else {
1114: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1115: }
1.238 raeburn 1116: }
1.63 raeburn 1117: $rowtotal ++;
1.236 raeburn 1118: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.409 raeburn 1119: ($action eq 'directorysrch') || ($action eq 'helpsettings') ||
1.429 raeburn 1120: ($action eq 'wafproxy') || ($action eq 'authordefaults')) {
1.230 raeburn 1121: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.346 raeburn 1122: } elsif ($action eq 'scantron') {
1123: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.293 raeburn 1124: } elsif ($action eq 'ssl') {
1125: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
1126: </table>
1127: </td>
1128: </tr>
1129: <tr>
1130: <td>
1131: <table class="LC_nested">
1132: <tr class="LC_info_row">
1133: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1134: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1135: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
1136: </table>
1137: </td>
1138: </tr>
1139: <tr>
1140: <td>
1141: <table class="LC_nested">
1142: <tr class="LC_info_row">
1143: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1144: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
1145: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 1146: } elsif ($action eq 'login') {
1.386 raeburn 1147: if ($numheaders == 5) {
1.168 raeburn 1148: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
1149: </table>
1150: </td>
1151: </tr>
1152: <tr>
1153: <td>
1154: <table class="LC_nested">
1155: <tr class="LC_info_row">
1156: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 1157: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 1158: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1159: $rowtotal ++;
1160: } else {
1161: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1162: }
1.256 raeburn 1163: $output .= '
1164: </table>
1165: </td>
1166: </tr>
1167: <tr>
1168: <td>
1169: <table class="LC_nested">
1170: <tr class="LC_info_row">';
1.386 raeburn 1171: if ($numheaders == 5) {
1.256 raeburn 1172: $output .= '
1173: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1174: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1175: </tr>';
1176: } else {
1177: $output .= '
1178: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1179: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1180: </tr>';
1181: }
1182: $rowtotal ++;
1.386 raeburn 1183: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
1184: </table>
1185: </td>
1186: </tr>
1187: <tr>
1188: <td>
1189: <table class="LC_nested">
1190: <tr class="LC_info_row">';
1191: if ($numheaders == 5) {
1192: $output .= '
1193: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1194: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1195: </tr>';
1196: } else {
1197: $output .= '
1198: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1199: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1200: </tr>';
1201: }
1202: $rowtotal ++;
1203: $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 1204: } elsif ($action eq 'requestcourses') {
1.247 raeburn 1205: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1206: $rowtotal ++;
1207: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 1208: </table>
1209: </td>
1210: </tr>
1211: <tr>
1212: <td>
1213: <table class="LC_nested">
1214: <tr class="LC_info_row">
1215: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1216: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 1217: &textbookcourses_javascript($settings).
1218: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
1219: </table>
1220: </td>
1221: </tr>
1222: <tr>
1223: <td>
1224: <table class="LC_nested">
1225: <tr class="LC_info_row">
1226: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1227: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1228: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 1229: </table>
1230: </td>
1231: </tr>
1232: <tr>
1233: <td>
1234: <table class="LC_nested">
1235: <tr class="LC_info_row">
1.306 raeburn 1236: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1237: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 1238: </tr>'.
1239: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 1240: } elsif ($action eq 'requestauthor') {
1241: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 1242: $rowtotal ++;
1.122 jms 1243: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1244: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1245: </table>
1246: </td>
1247: </tr>
1248: <tr>
1249: <td>
1250: <table class="LC_nested">
1251: <tr class="LC_info_row">
1.306 raeburn 1252: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69 raeburn 1253: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306 raeburn 1254: <td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1255: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1256: </tr>'.
1.30 raeburn 1257: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1258: </table>
1259: </td>
1260: </tr>
1261: <tr>
1262: <td>
1263: <table class="LC_nested">
1264: <tr class="LC_info_row">
1.59 bisitz 1265: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1266: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1267: </tr>'.
1.30 raeburn 1268: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1269: $rowtotal += 2;
1.6 raeburn 1270: }
1.3 raeburn 1271: } else {
1.30 raeburn 1272: $output .= '
1.3 raeburn 1273: <tr>
1274: <td>
1275: <table class="LC_nested">
1.30 raeburn 1276: <tr class="LC_info_row">';
1.277 raeburn 1277: if ($action eq 'login') {
1.30 raeburn 1278: $output .= '
1.59 bisitz 1279: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1280: } elsif ($action eq 'serverstatuses') {
1281: $output .= '
1.306 raeburn 1282: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69 raeburn 1283: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1284:
1.6 raeburn 1285: } else {
1.30 raeburn 1286: $output .= '
1.306 raeburn 1287: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1288: }
1.72 raeburn 1289: if (defined($item->{'header'}->[0]->{'col3'})) {
1.306 raeburn 1290: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72 raeburn 1291: &mt($item->{'header'}->[0]->{'col2'});
1292: if ($action eq 'serverstatuses') {
1293: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1294: }
1.69 raeburn 1295: } else {
1.306 raeburn 1296: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1297: &mt($item->{'header'}->[0]->{'col2'});
1298: }
1299: $output .= '</td>';
1300: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1301: if (defined($item->{'header'}->[0]->{'col4'})) {
1.306 raeburn 1302: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150 raeburn 1303: &mt($item->{'header'}->[0]->{'col3'});
1304: } else {
1.306 raeburn 1305: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1306: &mt($item->{'header'}->[0]->{'col3'});
1307: }
1.69 raeburn 1308: if ($action eq 'serverstatuses') {
1309: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1310: }
1311: $output .= '</td>';
1.6 raeburn 1312: }
1.150 raeburn 1313: if ($item->{'header'}->[0]->{'col4'}) {
1.306 raeburn 1314: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1315: &mt($item->{'header'}->[0]->{'col4'});
1316: }
1.69 raeburn 1317: $output .= '</tr>';
1.48 raeburn 1318: $rowtotal ++;
1.168 raeburn 1319: if ($action eq 'quotas') {
1.86 raeburn 1320: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1321: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1322: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.421 raeburn 1323: ($action eq 'proctoring') || ($action eq 'ipaccess')) {
1.230 raeburn 1324: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1325: }
1.3 raeburn 1326: }
1.30 raeburn 1327: $output .= '
1.3 raeburn 1328: </table>
1329: </td>
1330: </tr>
1.30 raeburn 1331: </table><br />';
1332: return ($output,$rowtotal);
1.1 raeburn 1333: }
1334:
1.3 raeburn 1335: sub print_login {
1.168 raeburn 1336: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.386 raeburn 1337: my ($css_class,$datatable,$switchserver,%lt);
1.6 raeburn 1338: my %choices = &login_choices();
1.386 raeburn 1339: if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
1340: %lt = &login_file_options();
1341: $switchserver = &check_switchserver($dom,$confname);
1342: }
1.168 raeburn 1343: if ($caller eq 'service') {
1.149 raeburn 1344: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1345: my $choice = $choices{'disallowlogin'};
1346: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1347: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306 raeburn 1348: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1349: '<th>'.$choices{'server'}.'</th>'.
1350: '<th>'.$choices{'serverpath'}.'</th>'.
1351: '<th>'.$choices{'custompath'}.'</th>'.
1352: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1353: my %disallowed;
1354: if (ref($settings) eq 'HASH') {
1355: if (ref($settings->{'loginvia'}) eq 'HASH') {
1356: %disallowed = %{$settings->{'loginvia'}};
1357: }
1358: }
1359: foreach my $lonhost (sort(keys(%servers))) {
1360: my $direct = 'selected="selected"';
1.128 raeburn 1361: if (ref($disallowed{$lonhost}) eq 'HASH') {
1362: if ($disallowed{$lonhost}{'server'} ne '') {
1363: $direct = '';
1364: }
1.110 raeburn 1365: }
1.115 raeburn 1366: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1367: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1368: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1369: '</option>';
1.184 raeburn 1370: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1371: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1372: my $selected = '';
1.128 raeburn 1373: if (ref($disallowed{$lonhost}) eq 'HASH') {
1374: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1375: $selected = 'selected="selected"';
1376: }
1.110 raeburn 1377: }
1378: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1379: $servers{$hostid}.'</option>';
1380: }
1.128 raeburn 1381: $datatable .= '</select></td>'.
1382: '<td><select name="'.$lonhost.'_serverpath">';
1383: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1384: my $pathname = $path;
1385: if ($path eq 'custom') {
1386: $pathname = &mt('Custom Path').' ->';
1387: }
1388: my $selected = '';
1389: if (ref($disallowed{$lonhost}) eq 'HASH') {
1390: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1391: $selected = 'selected="selected"';
1392: }
1393: } elsif ($path eq '') {
1394: $selected = 'selected="selected"';
1395: }
1396: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1397: }
1398: $datatable .= '</select></td>';
1399: my ($custom,$exempt);
1400: if (ref($disallowed{$lonhost}) eq 'HASH') {
1401: $custom = $disallowed{$lonhost}{'custompath'};
1402: $exempt = $disallowed{$lonhost}{'exempt'};
1403: }
1404: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1405: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1406: '</tr>';
1.110 raeburn 1407: }
1408: $datatable .= '</table></td></tr>';
1409: return $datatable;
1.168 raeburn 1410: } elsif ($caller eq 'page') {
1411: my %defaultchecked = (
1412: 'coursecatalog' => 'on',
1.188 raeburn 1413: 'helpdesk' => 'on',
1.168 raeburn 1414: 'adminmail' => 'off',
1415: 'newuser' => 'off',
1416: );
1.188 raeburn 1417: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1418: my (%checkedon,%checkedoff);
1.42 raeburn 1419: foreach my $item (@toggles) {
1.168 raeburn 1420: if ($defaultchecked{$item} eq 'on') {
1421: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1422: $checkedoff{$item} = ' ';
1.168 raeburn 1423: } elsif ($defaultchecked{$item} eq 'off') {
1424: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1425: $checkedon{$item} = ' ';
1426: }
1.1 raeburn 1427: }
1.168 raeburn 1428: my @images = ('img','logo','domlogo','login');
1.402 raeburn 1429: my @alttext = ('img','logo','domlogo');
1.168 raeburn 1430: my @logintext = ('textcol','bgcol');
1431: my @bgs = ('pgbg','mainbg','sidebg');
1432: my @links = ('link','alink','vlink');
1433: my %designhash = &Apache::loncommon::get_domainconf($dom);
1434: my %defaultdesign = %Apache::loncommon::defaultdesign;
1435: my (%is_custom,%designs);
1436: my %defaults = (
1437: font => $defaultdesign{'login.font'},
1438: );
1.6 raeburn 1439: foreach my $item (@images) {
1.168 raeburn 1440: $defaults{$item} = $defaultdesign{'login.'.$item};
1441: $defaults{'showlogo'}{$item} = 1;
1442: }
1443: foreach my $item (@bgs) {
1444: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1445: }
1.41 raeburn 1446: foreach my $item (@logintext) {
1.168 raeburn 1447: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1448: }
1.168 raeburn 1449: foreach my $item (@links) {
1450: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1451: }
1.168 raeburn 1452: if (ref($settings) eq 'HASH') {
1453: foreach my $item (@toggles) {
1454: if ($settings->{$item} eq '1') {
1455: $checkedon{$item} = ' checked="checked" ';
1456: $checkedoff{$item} = ' ';
1457: } elsif ($settings->{$item} eq '0') {
1458: $checkedoff{$item} = ' checked="checked" ';
1459: $checkedon{$item} = ' ';
1460: }
1461: }
1462: foreach my $item (@images) {
1463: if (defined($settings->{$item})) {
1464: $designs{$item} = $settings->{$item};
1465: $is_custom{$item} = 1;
1466: }
1467: if (defined($settings->{'showlogo'}{$item})) {
1468: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1469: }
1470: }
1.402 raeburn 1471: foreach my $item (@alttext) {
1472: if (ref($settings->{'alttext'}) eq 'HASH') {
1473: if ($settings->{'alttext'}->{$item} ne '') {
1474: $designs{'alttext'}{$item} = $settings->{'alttext'}{$item};
1475: }
1476: }
1477: }
1.168 raeburn 1478: foreach my $item (@logintext) {
1479: if ($settings->{$item} ne '') {
1480: $designs{'logintext'}{$item} = $settings->{$item};
1481: $is_custom{$item} = 1;
1482: }
1483: }
1484: if ($settings->{'font'} ne '') {
1485: $designs{'font'} = $settings->{'font'};
1486: $is_custom{'font'} = 1;
1487: }
1488: foreach my $item (@bgs) {
1489: if ($settings->{$item} ne '') {
1490: $designs{'bgs'}{$item} = $settings->{$item};
1491: $is_custom{$item} = 1;
1492: }
1493: }
1494: foreach my $item (@links) {
1495: if ($settings->{$item} ne '') {
1496: $designs{'links'}{$item} = $settings->{$item};
1497: $is_custom{$item} = 1;
1498: }
1499: }
1500: } else {
1501: if ($designhash{$dom.'.login.font'} ne '') {
1502: $designs{'font'} = $designhash{$dom.'.login.font'};
1503: $is_custom{'font'} = 1;
1504: }
1505: foreach my $item (@images) {
1506: if ($designhash{$dom.'.login.'.$item} ne '') {
1507: $designs{$item} = $designhash{$dom.'.login.'.$item};
1508: $is_custom{$item} = 1;
1509: }
1510: }
1511: foreach my $item (@bgs) {
1512: if ($designhash{$dom.'.login.'.$item} ne '') {
1513: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1514: $is_custom{$item} = 1;
1515: }
1.6 raeburn 1516: }
1.168 raeburn 1517: foreach my $item (@links) {
1518: if ($designhash{$dom.'.login.'.$item} ne '') {
1519: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1520: $is_custom{$item} = 1;
1521: }
1.6 raeburn 1522: }
1523: }
1.168 raeburn 1524: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1525: logo => 'Institution Logo',
1526: domlogo => 'Domain Logo',
1527: login => 'Login box');
1528: my $itemcount = 1;
1529: foreach my $item (@toggles) {
1530: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1531: $datatable .=
1532: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1533: '</td><td>'.
1534: '<span class="LC_nobreak"><label><input type="radio" name="'.
1535: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1536: '</label> <label><input type="radio" name="'.$item.'"'.
1537: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1538: '</tr>';
1539: $itemcount ++;
1.6 raeburn 1540: }
1.168 raeburn 1541: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1542: $datatable .= '</tr></table></td></tr>';
1543: } elsif ($caller eq 'help') {
1.386 raeburn 1544: my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1.168 raeburn 1545: my $itemcount = 1;
1546: $defaulturl = '/adm/loginproblems.html';
1547: $defaulttype = 'default';
1548: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1549: my @currlangs;
1550: if (ref($settings) eq 'HASH') {
1551: if (ref($settings->{'helpurl'}) eq 'HASH') {
1552: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1553: next if ($settings->{'helpurl'}{$key} eq '');
1554: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1555: $type{$key} = 'custom';
1556: unless ($key eq 'nolang') {
1557: push(@currlangs,$key);
1558: }
1559: }
1560: } elsif ($settings->{'helpurl'} ne '') {
1561: $type{'nolang'} = 'custom';
1562: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1563: }
1564: }
1.168 raeburn 1565: foreach my $lang ('nolang',sort(@currlangs)) {
1566: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1567: $datatable .= '<tr'.$css_class.'>';
1568: if ($url{$lang} eq '') {
1569: $url{$lang} = $defaulturl;
1570: }
1571: if ($type{$lang} eq '') {
1572: $type{$lang} = $defaulttype;
1573: }
1574: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1575: if ($lang eq 'nolang') {
1576: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1577: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1578: } else {
1579: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1580: $langchoices{$lang},
1581: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1582: }
1583: $datatable .= '</span></td>'."\n".
1584: '<td class="LC_left_item">';
1585: if ($type{$lang} eq 'custom') {
1586: $datatable .= '<span class="LC_nobreak"><label>'.
1587: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1588: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1589: } else {
1590: $datatable .= $lt{'upl'};
1591: }
1592: $datatable .='<br />';
1593: if ($switchserver) {
1594: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1595: } else {
1596: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1597: }
1.168 raeburn 1598: $datatable .= '</td></tr>';
1599: $itemcount ++;
1.6 raeburn 1600: }
1.168 raeburn 1601: my @addlangs;
1602: foreach my $lang (sort(keys(%langchoices))) {
1603: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1604: push(@addlangs,$lang);
1605: }
1606: if (@addlangs > 0) {
1607: my %toadd;
1608: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1609: $toadd{''} = &mt('Select');
1610: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1611: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1612: &mt('Add log-in help page for a specific language:').' '.
1613: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1614: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1615: if ($switchserver) {
1616: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1617: } else {
1618: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1619: }
1.168 raeburn 1620: $datatable .= '</td></tr>';
1.169 raeburn 1621: $itemcount ++;
1.6 raeburn 1622: }
1.169 raeburn 1623: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1624: } elsif ($caller eq 'headtag') {
1625: my %domservers = &Apache::lonnet::get_servers($dom);
1626: my $choice = $choices{'headtag'};
1627: $css_class = ' class="LC_odd_row"';
1628: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306 raeburn 1629: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256 raeburn 1630: '<th>'.$choices{'current'}.'</th>'.
1631: '<th>'.$choices{'action'}.'</th>'.
1632: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1633: my (%currurls,%currexempt);
1634: if (ref($settings) eq 'HASH') {
1635: if (ref($settings->{'headtag'}) eq 'HASH') {
1636: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1637: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1638: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1639: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1640: }
1641: }
1642: }
1643: }
1644: foreach my $lonhost (sort(keys(%domservers))) {
1645: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1646: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1647: if ($currurls{$lonhost}) {
1648: $datatable .= '<td class="LC_right_item"><a href="'.
1649: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1650: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1651: '">'.$lt{'curr'}.'</a></td>'.
1652: '<td><span class="LC_nobreak"><label>'.
1653: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1654: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1655: } else {
1656: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1657: }
1658: $datatable .='<br />';
1659: if ($switchserver) {
1660: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1661: } else {
1662: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1663: }
1.330 raeburn 1664: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256 raeburn 1665: }
1666: $datatable .= '</table></td></tr>';
1.386 raeburn 1667: } elsif ($caller eq 'saml') {
1668: my %domservers = &Apache::lonnet::get_servers($dom);
1669: $datatable .= '<tr><td colspan="3" style="text-align: left">'.
1670: '<table><tr><th>'.$choices{'hostid'}.'</th>'.
1671: '<th>'.$choices{'samllanding'}.'</th>'.
1672: '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
1.412 raeburn 1673: my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso,%styleon,%styleoff);
1.386 raeburn 1674: foreach my $lonhost (keys(%domservers)) {
1675: $samlurl{$lonhost} = '/adm/sso';
1676: $styleon{$lonhost} = 'display:none';
1677: $styleoff{$lonhost} = '';
1678: }
1.411 raeburn 1679: if ((ref($settings) eq 'HASH') && (ref($settings->{'saml'}) eq 'HASH')) {
1.386 raeburn 1680: foreach my $lonhost (keys(%{$settings->{'saml'}})) {
1681: if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
1682: $saml{$lonhost} = 1;
1683: $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
1684: $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
1685: $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
1686: $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
1687: $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
1.412 raeburn 1688: $samlwindow{$lonhost} = $settings->{'saml'}{$lonhost}{'window'};
1.386 raeburn 1689: $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
1690: $styleon{$lonhost} = '';
1691: $styleoff{$lonhost} = 'display:none';
1692: } else {
1693: $styleon{$lonhost} = 'display:none';
1694: $styleoff{$lonhost} = '';
1695: }
1696: }
1697: }
1698: my $itemcount = 1;
1699: foreach my $lonhost (sort(keys(%domservers))) {
1700: my $samlon = ' ';
1701: my $samloff = ' checked="checked" ';
1702: if ($saml{$lonhost}) {
1703: $samlon = $samloff;
1704: $samloff = ' ';
1705: }
1.412 raeburn 1706: my $samlwinon = '';
1707: my $samlwinoff = ' checked="checked"';
1708: if ($samlwindow{$lonhost}) {
1709: $samlwinon = $samlwinoff;
1710: $samlwinoff = '';
1711: }
1.386 raeburn 1712: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1713: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
1714: '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
1715: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
1716: &mt('No').'</label>'.(' 'x2).
1717: '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
1718: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
1719: &mt('Yes').'</label></span></td>'.
1720: '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
1.412 raeburn 1721: '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th></tr>'.
1.386 raeburn 1722: '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
1.412 raeburn 1723: '<th>'.&mt('Alt Text').'</th></tr>'.
1724: '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="20" value="'.
1.386 raeburn 1725: $samltext{$lonhost}.'" /></td><td>';
1726: if ($samlimg{$lonhost}) {
1727: $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
1728: '<span class="LC_nobreak"><label>'.
1729: '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
1730: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1731: } else {
1732: $datatable .= $lt{'upl'};
1733: }
1734: $datatable .='<br />';
1735: if ($switchserver) {
1736: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1737: } else {
1738: $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
1739: }
1740: $datatable .= '</td>'.
1.412 raeburn 1741: '<td><input type="text" name="saml_alt_'.$lonhost.'" size="25" '.
1742: 'value="'.$samlalt{$lonhost}.'" /></td></tr></table><br />'.
1743: '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th><th align="center">'.
1744: '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
1745: '<tr><th>'.&mt('URL').'</th><th>'.&mt('Tool Tip').'</th>'.
1746: '<th>'.&mt('Pop-up if iframe').'</th><th>'.&mt('Text').'</th></tr>'.
1747: '<tr'.$css_class.'>'.
1748: '<td><input type="text" name="saml_url_'.$lonhost.'" size="30" '.
1.386 raeburn 1749: 'value="'.$samlurl{$lonhost}.'" /></td>'.
1.412 raeburn 1750: '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="20">'.
1.386 raeburn 1751: $samltitle{$lonhost}.'</textarea></td>'.
1.412 raeburn 1752: '<td><label><input type="radio" name="saml_window_'.$lonhost.'" value=""'.$samlwinoff.'>'.
1753: &mt('No').'</label>'.(' 'x2).'<label><input type="radio" '.
1754: 'name="saml_window_'.$lonhost.'" value="1"'.$samlwinon.'>'.&mt('Yes').'</label></td>'.
1755: '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="12" '.
1.386 raeburn 1756: 'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
1757: '</table></td>'.
1758: '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%"> </td></tr>';
1759: $itemcount ++;
1760: }
1761: $datatable .= '</table></td></tr>';
1.1 raeburn 1762: }
1.6 raeburn 1763: return $datatable;
1764: }
1765:
1766: sub login_choices {
1767: my %choices =
1768: &Apache::lonlocal::texthash (
1.116 bisitz 1769: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1770: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1771: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1772: disallowlogin => "Login page requests redirected",
1773: hostid => "Server",
1.128 raeburn 1774: server => "Redirect to:",
1775: serverpath => "Path",
1776: custompath => "Custom",
1777: exempt => "Exempt IP(s)",
1.110 raeburn 1778: directlogin => "No redirect",
1779: newuser => "Link to create a user account",
1780: img => "Header",
1781: logo => "Main Logo",
1782: domlogo => "Domain Logo",
1783: login => "Log-in Header",
1784: textcol => "Text color",
1785: bgcol => "Box color",
1786: bgs => "Background colors",
1787: links => "Link colors",
1788: font => "Font color",
1789: pgbg => "Header",
1790: mainbg => "Page",
1791: sidebg => "Login box",
1792: link => "Link",
1793: alink => "Active link",
1794: vlink => "Visited link",
1.256 raeburn 1795: headtag => "Custom markup",
1796: action => "Action",
1797: current => "Current",
1.386 raeburn 1798: samllanding => "Dual login?",
1799: samloptions => "Options",
1.402 raeburn 1800: alttext => "Alt text",
1.6 raeburn 1801: );
1802: return %choices;
1803: }
1804:
1.386 raeburn 1805: sub login_file_options {
1806: return &Apache::lonlocal::texthash(
1807: del => 'Delete?',
1808: rep => 'Replace:',
1809: upl => 'Upload:',
1810: curr => 'View contents',
1811: default => 'Default',
1812: custom => 'Custom',
1813: none => 'None',
1814: );
1815: }
1816:
1.394 raeburn 1817: sub print_ipaccess {
1818: my ($dom,$settings,$rowtotal) = @_;
1819: my $css_class;
1820: my $itemcount = 0;
1821: my $datatable;
1822: my %ordered;
1823: if (ref($settings) eq 'HASH') {
1824: foreach my $item (keys(%{$settings})) {
1825: if (ref($settings->{$item}) eq 'HASH') {
1826: my $num = $settings->{$item}{'order'};
1827: if ($num eq '') {
1828: $num = scalar(keys(%{$settings}));
1829: }
1830: $ordered{$num} = $item;
1831: }
1832: }
1833: }
1834: my $maxnum = scalar(keys(%ordered));
1835: if (keys(%ordered)) {
1836: my @items = sort { $a <=> $b } keys(%ordered);
1837: for (my $i=0; $i<@items; $i++) {
1838: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1839: my $item = $ordered{$items[$i]};
1840: my ($name,$ipranges,%commblocks,%courses);
1841: if (ref($settings->{$item}) eq 'HASH') {
1842: $name = $settings->{$item}->{'name'};
1843: $ipranges = $settings->{$item}->{'ip'};
1844: if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
1845: %commblocks = %{$settings->{$item}->{'commblocks'}};
1846: }
1847: if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
1848: %courses = %{$settings->{$item}->{'courses'}};
1849: }
1850: }
1851: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
1852: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1853: .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
1854: for (my $k=0; $k<=$maxnum; $k++) {
1855: my $vpos = $k+1;
1856: my $selstr;
1857: if ($k == $i) {
1858: $selstr = ' selected="selected" ';
1859: }
1860: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1861: }
1862: $datatable .= '</select>'.(' 'x2).
1863: '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
1864: &mt('Delete?').'</label></span></td>'.
1865: '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
1866: &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
1867: '</td></tr>';
1868: $itemcount ++;
1869: }
1870: }
1871: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1872: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
1873: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1874: '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
1875: '<select name="ipaccess_pos_add"'.$chgstr.'>';
1876: for (my $k=0; $k<$maxnum+1; $k++) {
1877: my $vpos = $k+1;
1878: my $selstr;
1879: if ($k == $maxnum) {
1880: $selstr = ' selected="selected" ';
1881: }
1882: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1883: }
1884: $datatable .= '</select> '."\n".
1885: '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1886: '<td colspan="2">'.
1887: &ipaccess_options('add',$itemcount,$dom).
1888: '</td>'."\n".
1889: '</tr>'."\n";
1890: $$rowtotal ++;
1891: return $datatable;
1892: }
1893:
1894: sub ipaccess_options {
1895: my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
1896: my (%currblocks,%currcourses,$output);
1897: if (ref($blocksref) eq 'HASH') {
1898: %currblocks = %{$blocksref};
1899: }
1900: if (ref($coursesref) eq 'HASH') {
1901: %currcourses = %{$coursesref};
1902: }
1903: $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
1904: '<span class="LC_nobreak">'.&mt('Name').': '.
1905: '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
1906: '</span></fieldset>'.
1907: '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
1908: &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
1909: &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
1910: '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
1911: $ipranges.'</textarea></fieldset>'.
1912: '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
1913: &blocker_checkboxes($num,$blocksref).'</fieldset>'.
1914: '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
1915: '<table>';
1916: foreach my $cid (sort(keys(%currcourses))) {
1917: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1918: $output .= '<tr><td><span class="LC_nobreak">'.
1919: '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
1920: &mt('Delete?').' <span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
1921: ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
1922: }
1923: $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').': '.
1924: '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
1925: &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
1926: '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
1927: '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
1928: '</span></td></tr></table>'."\n".
1929: '</fieldset>';
1930: return $output;
1931: }
1932:
1933: sub blocker_checkboxes {
1934: my ($num,$blocks) = @_;
1935: my ($typeorder,$types) = &commblocktype_text();
1936: my $numinrow = 6;
1937: my $output = '<table>';
1938: for (my $i=0; $i<@{$typeorder}; $i++) {
1939: my $block = $typeorder->[$i];
1940: my $blockstatus;
1941: if (ref($blocks) eq 'HASH') {
1942: if ($blocks->{$block} eq 'on') {
1943: $blockstatus = 'checked="checked"';
1944: }
1945: }
1946: my $rem = $i%($numinrow);
1947: if ($rem == 0) {
1948: if ($i > 0) {
1949: $output .= '</tr>';
1950: }
1951: $output .= '<tr>';
1952: }
1953: if ($i == scalar(@{$typeorder})-1) {
1954: my $colsleft = $numinrow-$rem;
1955: if ($colsleft > 1) {
1956: $output .= '<td colspan="'.$colsleft.'">';
1957: } else {
1958: $output .= '<td>';
1959: }
1960: } else {
1961: $output .= '<td>';
1962: }
1963: my $item = 'ipaccess_block_'.$num;
1964: if ($blockstatus) {
1965: $blockstatus = ' '.$blockstatus;
1966: }
1967: $output .= '<span class="LC_nobreak"><label>'."\n".
1968: '<input type="checkbox" name="'.$item.'"'.
1969: $blockstatus.' value="'.$block.'"'.' />'.
1970: $types->{$block}.'</label></span>'."\n".
1971: '<br /></td>';
1972: }
1973: $output .= '</tr></table>';
1974: return $output;
1975: }
1976:
1977: sub commblocktype_text {
1978: my %types = &Apache::lonlocal::texthash(
1979: 'com' => 'Messaging',
1980: 'chat' => 'Chat Room',
1981: 'boards' => 'Discussion',
1982: 'port' => 'Portfolio',
1983: 'groups' => 'Groups',
1984: 'blogs' => 'Blogs',
1985: 'about' => 'User Information',
1986: 'printout' => 'Printouts',
1987: 'passwd' => 'Change Password',
1988: 'grades' => 'Gradebook',
1.397 raeburn 1989: 'search' => 'Course search',
1990: 'wishlist' => 'Stored links',
1991: 'annotate' => 'Annotations',
1.394 raeburn 1992: );
1.397 raeburn 1993: my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','annotate','passwd'];
1.394 raeburn 1994: return ($typeorder,\%types);
1995: }
1996:
1.6 raeburn 1997: sub print_rolecolors {
1.30 raeburn 1998: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1999: my %choices = &color_font_choices();
2000: my @bgs = ('pgbg','tabbg','sidebg');
2001: my @links = ('link','alink','vlink');
2002: my @images = ('img');
2003: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 2004: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 2005: my %defaultdesign = %Apache::loncommon::defaultdesign;
2006: my (%is_custom,%designs);
1.200 raeburn 2007: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 2008: if (ref($settings) eq 'HASH') {
2009: if (ref($settings->{$role}) eq 'HASH') {
2010: if ($settings->{$role}->{'img'} ne '') {
2011: $designs{'img'} = $settings->{$role}->{'img'};
2012: $is_custom{'img'} = 1;
2013: }
2014: if ($settings->{$role}->{'font'} ne '') {
2015: $designs{'font'} = $settings->{$role}->{'font'};
2016: $is_custom{'font'} = 1;
2017: }
1.97 tempelho 2018: if ($settings->{$role}->{'fontmenu'} ne '') {
2019: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
2020: $is_custom{'fontmenu'} = 1;
2021: }
1.6 raeburn 2022: foreach my $item (@bgs) {
2023: if ($settings->{$role}->{$item} ne '') {
2024: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
2025: $is_custom{$item} = 1;
2026: }
2027: }
2028: foreach my $item (@links) {
2029: if ($settings->{$role}->{$item} ne '') {
2030: $designs{'links'}{$item} = $settings->{$role}->{$item};
2031: $is_custom{$item} = 1;
2032: }
2033: }
2034: }
2035: } else {
2036: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
2037: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
2038: $is_custom{'img'} = 1;
2039: }
1.97 tempelho 2040: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
2041: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
2042: $is_custom{'fontmenu'} = 1;
2043: }
1.6 raeburn 2044: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
2045: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
2046: $is_custom{'font'} = 1;
2047: }
2048: foreach my $item (@bgs) {
2049: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
2050: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
2051: $is_custom{$item} = 1;
2052:
2053: }
2054: }
2055: foreach my $item (@links) {
2056: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
2057: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
2058: $is_custom{$item} = 1;
2059: }
2060: }
2061: }
2062: my $itemcount = 1;
1.30 raeburn 2063: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 2064: $datatable .= '</tr></table></td></tr>';
2065: return $datatable;
2066: }
2067:
1.200 raeburn 2068: sub role_defaults {
2069: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 2070: my %defaults;
2071: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 2072: return %defaults;
2073: }
2074: my %defaultdesign = %Apache::loncommon::defaultdesign;
2075: if ($role eq 'login') {
2076: %defaults = (
2077: font => $defaultdesign{$role.'.font'},
2078: );
2079: if (ref($logintext) eq 'ARRAY') {
2080: foreach my $item (@{$logintext}) {
2081: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
2082: }
2083: }
2084: foreach my $item (@{$images}) {
2085: $defaults{'showlogo'}{$item} = 1;
2086: }
2087: } else {
2088: %defaults = (
2089: img => $defaultdesign{$role.'.img'},
2090: font => $defaultdesign{$role.'.font'},
2091: fontmenu => $defaultdesign{$role.'.fontmenu'},
2092: );
2093: }
2094: foreach my $item (@{$bgs}) {
2095: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
2096: }
2097: foreach my $item (@{$links}) {
2098: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
2099: }
2100: foreach my $item (@{$images}) {
2101: $defaults{$item} = $defaultdesign{$role.'.'.$item};
2102: }
2103: return %defaults;
2104: }
2105:
1.6 raeburn 2106: sub display_color_options {
1.9 raeburn 2107: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 2108: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 2109: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 2110: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 2111: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 2112: '<td>'.$choices->{'font'}.'</td>';
2113: if (!$is_custom->{'font'}) {
1.329 raeburn 2114: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 2115: } else {
2116: $datatable .= '<td> </td>';
2117: }
1.174 foxr 2118: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
2119:
1.8 raeburn 2120: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2121: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 2122: ' value="'.$current_color.'" /> '.
1.329 raeburn 2123: ' </span></td></tr>';
1.107 raeburn 2124: unless ($role eq 'login') {
2125: $datatable .= '<tr'.$css_class.'>'.
2126: '<td>'.$choices->{'fontmenu'}.'</td>';
2127: if (!$is_custom->{'fontmenu'}) {
1.329 raeburn 2128: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 2129: } else {
2130: $datatable .= '<td> </td>';
2131: }
1.202 raeburn 2132: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 2133: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 2134: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2135: '<input class="colorchooser" type="text" size="10" name="'
2136: .$role.'_fontmenu"'.
2137: ' value="'.$current_color.'" /> '.
1.329 raeburn 2138: ' </span></td></tr>';
1.97 tempelho 2139: }
1.9 raeburn 2140: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 2141: foreach my $img (@{$images}) {
1.18 albertel 2142: $itemcount ++;
1.6 raeburn 2143: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 2144: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 2145: '<td>'.$choices->{$img};
1.402 raeburn 2146: my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext);
1.70 raeburn 2147: if ($role eq 'login') {
2148: if ($img eq 'login') {
2149: $login_hdr_pick =
1.135 bisitz 2150: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 2151: $logincolors =
2152: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 2153: $designs,$defaults);
1.402 raeburn 2154: } else {
2155: if ($img ne 'domlogo') {
2156: $datatable.= &logo_display_options($img,$defaults,$designs);
2157: }
2158: if (ref($designs->{'alttext'}) eq 'HASH') {
2159: $alttext = $designs->{'alttext'}{$img};
2160: }
1.70 raeburn 2161: }
2162: }
2163: $datatable .= '</td>';
1.6 raeburn 2164: if ($designs->{$img} ne '') {
2165: $imgfile = $designs->{$img};
1.18 albertel 2166: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 2167: } else {
2168: $imgfile = $defaults->{$img};
2169: }
2170: if ($imgfile) {
1.9 raeburn 2171: my ($showfile,$fullsize);
2172: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 2173: my $urldir = $1;
2174: my $filename = $2;
2175: my @info = &Apache::lonnet::stat_file($designs->{$img});
2176: if (@info) {
2177: my $thumbfile = 'tn-'.$filename;
2178: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
2179: if (@thumb) {
2180: $showfile = $urldir.'/'.$thumbfile;
2181: } else {
2182: $showfile = $imgfile;
2183: }
2184: } else {
2185: $showfile = '';
2186: }
2187: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 2188: $showfile = $imgfile;
1.6 raeburn 2189: my $imgdir = $1;
2190: my $filename = $2;
1.159 raeburn 2191: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 2192: $showfile = "/$imgdir/tn-".$filename;
2193: } else {
1.159 raeburn 2194: my $input = $londocroot.$imgfile;
2195: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 2196: if (!-e $output) {
1.9 raeburn 2197: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 2198: my ($fullwidth,$fullheight) = &check_dimensions($input);
2199: if ($fullwidth ne '' && $fullheight ne '') {
2200: if ($fullwidth > $width && $fullheight > $height) {
2201: my $size = $width.'x'.$height;
1.316 raeburn 2202: my @args = ('convert','-sample',$size,$input,$output);
2203: system({$args[0]} @args);
1.159 raeburn 2204: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 2205: }
2206: }
1.6 raeburn 2207: }
2208: }
1.16 raeburn 2209: }
1.6 raeburn 2210: if ($showfile) {
1.40 raeburn 2211: if ($showfile =~ m{^/(adm|res)/}) {
2212: if ($showfile =~ m{^/res/}) {
2213: my $local_showfile =
2214: &Apache::lonnet::filelocation('',$showfile);
2215: &Apache::lonnet::repcopy($local_showfile);
2216: }
2217: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
2218: }
2219: if ($imgfile) {
2220: if ($imgfile =~ m{^/(adm|res)/}) {
2221: if ($imgfile =~ m{^/res/}) {
2222: my $local_imgfile =
2223: &Apache::lonnet::filelocation('',$imgfile);
2224: &Apache::lonnet::repcopy($local_imgfile);
2225: }
2226: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
2227: } else {
2228: $fullsize = $imgfile;
2229: }
2230: }
1.41 raeburn 2231: $datatable .= '<td>';
2232: if ($img eq 'login') {
1.135 bisitz 2233: $datatable .= $login_hdr_pick;
2234: }
1.41 raeburn 2235: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
2236: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 2237: } else {
1.201 raeburn 2238: $datatable .= '<td> </td><td class="LC_left_item">'.
2239: &mt('Upload:').'<br />';
1.6 raeburn 2240: }
2241: } else {
1.201 raeburn 2242: $datatable .= '<td> </td><td class="LC_left_item">'.
2243: &mt('Upload:').'<br />';
1.6 raeburn 2244: }
1.9 raeburn 2245: if ($switchserver) {
2246: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2247: } else {
1.135 bisitz 2248: if ($img ne 'login') { # suppress file selection for Log-in header
2249: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
2250: }
1.9 raeburn 2251: }
1.402 raeburn 2252: if (($role eq 'login') && ($img ne 'login')) {
2253: $datatable .= (' ' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'.
2254: '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'.
2255: '</label></span>';
2256: }
1.9 raeburn 2257: $datatable .= '</td></tr>';
1.6 raeburn 2258: }
2259: $itemcount ++;
2260: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2261: $datatable .= '<tr'.$css_class.'>'.
2262: '<td>'.$choices->{'bgs'}.'</td>';
2263: my $bgs_def;
2264: foreach my $item (@{$bgs}) {
2265: if (!$is_custom->{$item}) {
1.329 raeburn 2266: $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 2267: }
2268: }
2269: if ($bgs_def) {
1.8 raeburn 2270: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 2271: } else {
2272: $datatable .= '<td> </td>';
2273: }
2274: $datatable .= '<td class="LC_right_item">'.
2275: '<table border="0"><tr>';
1.174 foxr 2276:
1.6 raeburn 2277: foreach my $item (@{$bgs}) {
1.306 raeburn 2278: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 2279: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 2280: if ($designs->{'bgs'}{$item}) {
1.174 foxr 2281: $datatable .= ' ';
1.6 raeburn 2282: }
1.174 foxr 2283: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 2284: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 2285: }
2286: $datatable .= '</tr></table></td></tr>';
2287: $itemcount ++;
2288: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2289: $datatable .= '<tr'.$css_class.'>'.
2290: '<td>'.$choices->{'links'}.'</td>';
2291: my $links_def;
2292: foreach my $item (@{$links}) {
2293: if (!$is_custom->{$item}) {
1.329 raeburn 2294: $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 2295: }
2296: }
2297: if ($links_def) {
1.8 raeburn 2298: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 2299: } else {
2300: $datatable .= '<td> </td>';
2301: }
2302: $datatable .= '<td class="LC_right_item">'.
2303: '<table border="0"><tr>';
2304: foreach my $item (@{$links}) {
1.234 raeburn 2305: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 2306: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 2307: if ($designs->{'links'}{$item}) {
1.174 foxr 2308: $datatable.=' ';
1.6 raeburn 2309: }
1.174 foxr 2310: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 2311: '" /></td>';
2312: }
1.30 raeburn 2313: $$rowtotal += $itemcount;
1.3 raeburn 2314: return $datatable;
2315: }
2316:
1.70 raeburn 2317: sub logo_display_options {
2318: my ($img,$defaults,$designs) = @_;
2319: my $checkedon;
2320: if (ref($defaults) eq 'HASH') {
2321: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2322: if ($defaults->{'showlogo'}{$img}) {
2323: $checkedon = 'checked="checked" ';
2324: }
2325: }
2326: }
2327: if (ref($designs) eq 'HASH') {
2328: if (ref($designs->{'showlogo'}) eq 'HASH') {
2329: if (defined($designs->{'showlogo'}{$img})) {
2330: if ($designs->{'showlogo'}{$img} == 0) {
2331: $checkedon = '';
2332: } elsif ($designs->{'showlogo'}{$img} == 1) {
2333: $checkedon = 'checked="checked" ';
2334: }
2335: }
2336: }
2337: }
2338: return '<br /><label> <input type="checkbox" name="'.
2339: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2340: &mt('show').'</label>'."\n";
2341: }
2342:
1.41 raeburn 2343: sub login_header_options {
1.135 bisitz 2344: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2345: my $output = '';
1.41 raeburn 2346: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 2347: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 2348: if (!$is_custom->{'textcol'}) {
2349: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2350: ' ';
2351: }
2352: if (!$is_custom->{'bgcol'}) {
2353: $output .= $choices->{'bgcol'}.': '.
2354: '<span id="css_'.$role.'_font" style="background-color: '.
2355: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2356: }
2357: $output .= '<br />';
2358: }
2359: $output .='<br />';
2360: return $output;
2361: }
2362:
2363: sub login_text_colors {
1.201 raeburn 2364: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 2365: my $color_menu = '<table border="0"><tr>';
2366: foreach my $item (@{$logintext}) {
1.306 raeburn 2367: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 2368: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2369: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2370: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 2371: }
2372: $color_menu .= '</tr></table><br />';
2373: return $color_menu;
2374: }
2375:
2376: sub image_changes {
2377: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2378: my $output;
1.135 bisitz 2379: if ($img eq 'login') {
1.331 raeburn 2380: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 2381: } elsif (!$is_custom) {
1.70 raeburn 2382: if ($img ne 'domlogo') {
1.331 raeburn 2383: $output = &mt('Default image:').'<br />';
1.41 raeburn 2384: } else {
1.331 raeburn 2385: $output = &mt('Default in use:').'<br />';
1.41 raeburn 2386: }
2387: }
1.331 raeburn 2388: if ($img ne 'login') {
1.135 bisitz 2389: if ($img_import) {
2390: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2391: }
2392: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2393: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2394: if ($is_custom) {
2395: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2396: '<input type="checkbox" name="'.
2397: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2398: '</label> '.&mt('Replace:').'</span><br />';
2399: } else {
1.306 raeburn 2400: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 2401: }
1.41 raeburn 2402: }
2403: return $output;
2404: }
2405:
1.3 raeburn 2406: sub print_quotas {
1.86 raeburn 2407: my ($dom,$settings,$rowtotal,$action) = @_;
2408: my $context;
2409: if ($action eq 'quotas') {
2410: $context = 'tools';
2411: } else {
2412: $context = $action;
2413: }
1.429 raeburn 2414: my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44 raeburn 2415: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2416: my $typecount = 0;
1.101 raeburn 2417: my ($css_class,%titles);
1.86 raeburn 2418: if ($context eq 'requestcourses') {
1.325 raeburn 2419: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 2420: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2421: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2422: %titles = &courserequest_titles();
1.163 raeburn 2423: } elsif ($context eq 'requestauthor') {
2424: @usertools = ('author');
2425: @options = ('norequest','approval','automatic');
1.210 raeburn 2426: %titles = &authorrequest_titles();
1.86 raeburn 2427: } else {
1.430 raeburn 2428: @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.101 raeburn 2429: %titles = &tool_titles();
1.86 raeburn 2430: }
1.26 raeburn 2431: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2432: foreach my $type (@{$types}) {
1.429 raeburn 2433: my $currdefquota;
1.163 raeburn 2434: unless (($context eq 'requestcourses') ||
2435: ($context eq 'requestauthor')) {
1.86 raeburn 2436: if (ref($settings) eq 'HASH') {
2437: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 2438: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2439: } else {
2440: $currdefquota = $settings->{$type};
2441: }
1.78 raeburn 2442: }
1.72 raeburn 2443: }
1.3 raeburn 2444: if (defined($usertypes->{$type})) {
2445: $typecount ++;
2446: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2447: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2448: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2449: '<td class="LC_left_item">';
1.101 raeburn 2450: if ($context eq 'requestcourses') {
2451: $datatable .= '<table><tr>';
2452: }
2453: my %cell;
1.72 raeburn 2454: foreach my $item (@usertools) {
1.101 raeburn 2455: if ($context eq 'requestcourses') {
2456: my ($curroption,$currlimit);
2457: if (ref($settings) eq 'HASH') {
2458: if (ref($settings->{$item}) eq 'HASH') {
2459: $curroption = $settings->{$item}->{$type};
2460: if ($curroption =~ /^autolimit=(\d*)$/) {
2461: $currlimit = $1;
2462: }
2463: }
2464: }
2465: if (!$curroption) {
2466: $curroption = 'norequest';
2467: }
2468: $datatable .= '<th>'.$titles{$item}.'</th>';
2469: foreach my $option (@options) {
2470: my $val = $option;
2471: if ($option eq 'norequest') {
2472: $val = 0;
2473: }
2474: if ($option eq 'validate') {
2475: my $canvalidate = 0;
2476: if (ref($validations{$item}) eq 'HASH') {
2477: if ($validations{$item}{$type}) {
2478: $canvalidate = 1;
2479: }
2480: }
2481: next if (!$canvalidate);
2482: }
2483: my $checked = '';
2484: if ($option eq $curroption) {
2485: $checked = ' checked="checked"';
2486: } elsif ($option eq 'autolimit') {
2487: if ($curroption =~ /^autolimit/) {
2488: $checked = ' checked="checked"';
2489: }
2490: }
2491: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2492: '<input type="radio" name="crsreq_'.$item.
2493: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2494: $titles{$option}.'</label>';
1.101 raeburn 2495: if ($option eq 'autolimit') {
1.127 raeburn 2496: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2497: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2498: 'value="'.$currlimit.'" />';
1.101 raeburn 2499: }
1.127 raeburn 2500: $cell{$item} .= '</span> ';
1.103 raeburn 2501: if ($option eq 'autolimit') {
1.127 raeburn 2502: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2503: }
1.101 raeburn 2504: }
1.163 raeburn 2505: } elsif ($context eq 'requestauthor') {
2506: my $curroption;
2507: if (ref($settings) eq 'HASH') {
2508: $curroption = $settings->{$type};
2509: }
2510: if (!$curroption) {
2511: $curroption = 'norequest';
2512: }
2513: foreach my $option (@options) {
2514: my $val = $option;
2515: if ($option eq 'norequest') {
2516: $val = 0;
2517: }
2518: my $checked = '';
2519: if ($option eq $curroption) {
2520: $checked = ' checked="checked"';
2521: }
2522: $datatable .= '<span class="LC_nobreak"><label>'.
2523: '<input type="radio" name="authorreq_'.$type.
2524: '" value="'.$val.'"'.$checked.' />'.
2525: $titles{$option}.'</label></span> ';
2526: }
1.101 raeburn 2527: } else {
2528: my $checked = 'checked="checked" ';
1.413 raeburn 2529: if ($item eq 'timezone') {
2530: $checked = '';
2531: }
1.101 raeburn 2532: if (ref($settings) eq 'HASH') {
2533: if (ref($settings->{$item}) eq 'HASH') {
1.413 raeburn 2534: if (!$settings->{$item}->{$type}) {
1.101 raeburn 2535: $checked = '';
2536: } elsif ($settings->{$item}->{$type} == 1) {
2537: $checked = 'checked="checked" ';
2538: }
1.78 raeburn 2539: }
1.72 raeburn 2540: }
1.101 raeburn 2541: $datatable .= '<span class="LC_nobreak"><label>'.
2542: '<input type="checkbox" name="'.$context.'_'.$item.
2543: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2544: '</label></span> ';
1.72 raeburn 2545: }
1.101 raeburn 2546: }
2547: if ($context eq 'requestcourses') {
2548: $datatable .= '</tr><tr>';
2549: foreach my $item (@usertools) {
1.106 raeburn 2550: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2551: }
2552: $datatable .= '</tr></table>';
1.72 raeburn 2553: }
1.86 raeburn 2554: $datatable .= '</td>';
1.163 raeburn 2555: unless (($context eq 'requestcourses') ||
2556: ($context eq 'requestauthor')) {
1.86 raeburn 2557: $datatable .=
1.197 raeburn 2558: '<td class="LC_right_item">'.
1.429 raeburn 2559: '<span class="LC_nobreak">'.
1.3 raeburn 2560: '<input type="text" name="quota_'.$type.
1.72 raeburn 2561: '" value="'.$currdefquota.
1.197 raeburn 2562: '" size="5" /></span></td>';
1.86 raeburn 2563: }
2564: $datatable .= '</tr>';
1.3 raeburn 2565: }
2566: }
2567: }
1.163 raeburn 2568: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2569: $defaultquota = '20';
2570: if (ref($settings) eq 'HASH') {
2571: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2572: $defaultquota = $settings->{'defaultquota'}->{'default'};
2573: } elsif (defined($settings->{'default'})) {
2574: $defaultquota = $settings->{'default'};
2575: }
1.3 raeburn 2576: }
2577: }
2578: $typecount ++;
2579: $css_class = $typecount%2?' class="LC_odd_row"':'';
2580: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2581: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2582: '<td class="LC_left_item">';
1.101 raeburn 2583: if ($context eq 'requestcourses') {
2584: $datatable .= '<table><tr>';
2585: }
2586: my %defcell;
1.72 raeburn 2587: foreach my $item (@usertools) {
1.101 raeburn 2588: if ($context eq 'requestcourses') {
2589: my ($curroption,$currlimit);
2590: if (ref($settings) eq 'HASH') {
2591: if (ref($settings->{$item}) eq 'HASH') {
2592: $curroption = $settings->{$item}->{'default'};
2593: if ($curroption =~ /^autolimit=(\d*)$/) {
2594: $currlimit = $1;
2595: }
2596: }
2597: }
2598: if (!$curroption) {
2599: $curroption = 'norequest';
2600: }
2601: $datatable .= '<th>'.$titles{$item}.'</th>';
2602: foreach my $option (@options) {
2603: my $val = $option;
2604: if ($option eq 'norequest') {
2605: $val = 0;
2606: }
2607: if ($option eq 'validate') {
2608: my $canvalidate = 0;
2609: if (ref($validations{$item}) eq 'HASH') {
2610: if ($validations{$item}{'default'}) {
2611: $canvalidate = 1;
2612: }
2613: }
2614: next if (!$canvalidate);
2615: }
2616: my $checked = '';
2617: if ($option eq $curroption) {
2618: $checked = ' checked="checked"';
2619: } elsif ($option eq 'autolimit') {
2620: if ($curroption =~ /^autolimit/) {
2621: $checked = ' checked="checked"';
2622: }
2623: }
2624: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2625: '<input type="radio" name="crsreq_'.$item.
2626: '_default" value="'.$val.'"'.$checked.' />'.
2627: $titles{$option}.'</label>';
2628: if ($option eq 'autolimit') {
1.127 raeburn 2629: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2630: $item.'_limit_default" size="1" '.
2631: 'value="'.$currlimit.'" />';
2632: }
1.127 raeburn 2633: $defcell{$item} .= '</span> ';
1.104 raeburn 2634: if ($option eq 'autolimit') {
1.127 raeburn 2635: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2636: }
1.101 raeburn 2637: }
1.163 raeburn 2638: } elsif ($context eq 'requestauthor') {
2639: my $curroption;
2640: if (ref($settings) eq 'HASH') {
1.172 raeburn 2641: $curroption = $settings->{'default'};
1.163 raeburn 2642: }
2643: if (!$curroption) {
2644: $curroption = 'norequest';
2645: }
2646: foreach my $option (@options) {
2647: my $val = $option;
2648: if ($option eq 'norequest') {
2649: $val = 0;
2650: }
2651: my $checked = '';
2652: if ($option eq $curroption) {
2653: $checked = ' checked="checked"';
2654: }
2655: $datatable .= '<span class="LC_nobreak"><label>'.
2656: '<input type="radio" name="authorreq_default"'.
2657: ' value="'.$val.'"'.$checked.' />'.
2658: $titles{$option}.'</label></span> ';
2659: }
1.101 raeburn 2660: } else {
2661: my $checked = 'checked="checked" ';
2662: if (ref($settings) eq 'HASH') {
2663: if (ref($settings->{$item}) eq 'HASH') {
2664: if ($settings->{$item}->{'default'} == 0) {
2665: $checked = '';
2666: } elsif ($settings->{$item}->{'default'} == 1) {
2667: $checked = 'checked="checked" ';
2668: }
1.78 raeburn 2669: }
1.72 raeburn 2670: }
1.101 raeburn 2671: $datatable .= '<span class="LC_nobreak"><label>'.
2672: '<input type="checkbox" name="'.$context.'_'.$item.
2673: '" value="default" '.$checked.'/>'.$titles{$item}.
2674: '</label></span> ';
2675: }
2676: }
2677: if ($context eq 'requestcourses') {
2678: $datatable .= '</tr><tr>';
2679: foreach my $item (@usertools) {
1.106 raeburn 2680: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2681: }
1.101 raeburn 2682: $datatable .= '</tr></table>';
1.72 raeburn 2683: }
1.86 raeburn 2684: $datatable .= '</td>';
1.163 raeburn 2685: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2686: $datatable .= '<td class="LC_right_item">'.
1.429 raeburn 2687: '<span class="LC_nobreak">'.
1.86 raeburn 2688: '<input type="text" name="defaultquota" value="'.
1.429 raeburn 2689: $defaultquota.'" size="5" /></span></td>';
1.86 raeburn 2690: }
2691: $datatable .= '</tr>';
1.72 raeburn 2692: $typecount ++;
2693: $css_class = $typecount%2?' class="LC_odd_row"':'';
2694: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2695: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2696: if ($context eq 'requestcourses') {
1.109 raeburn 2697: $datatable .= &mt('(overrides affiliation, if set)').
2698: '</td>'.
2699: '<td class="LC_left_item">'.
2700: '<table><tr>';
1.101 raeburn 2701: } else {
1.109 raeburn 2702: $datatable .= &mt('(overrides affiliation, if checked)').
2703: '</td>'.
2704: '<td class="LC_left_item" colspan="2">'.
2705: '<br />';
1.101 raeburn 2706: }
2707: my %advcell;
1.72 raeburn 2708: foreach my $item (@usertools) {
1.101 raeburn 2709: if ($context eq 'requestcourses') {
2710: my ($curroption,$currlimit);
2711: if (ref($settings) eq 'HASH') {
2712: if (ref($settings->{$item}) eq 'HASH') {
2713: $curroption = $settings->{$item}->{'_LC_adv'};
2714: if ($curroption =~ /^autolimit=(\d*)$/) {
2715: $currlimit = $1;
2716: }
2717: }
2718: }
2719: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2720: my $checked = '';
2721: if ($curroption eq '') {
2722: $checked = ' checked="checked"';
2723: }
2724: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2725: '<input type="radio" name="crsreq_'.$item.
2726: '__LC_adv" value=""'.$checked.' />'.
2727: &mt('No override set').'</label></span> ';
1.101 raeburn 2728: foreach my $option (@options) {
2729: my $val = $option;
2730: if ($option eq 'norequest') {
2731: $val = 0;
2732: }
2733: if ($option eq 'validate') {
2734: my $canvalidate = 0;
2735: if (ref($validations{$item}) eq 'HASH') {
2736: if ($validations{$item}{'_LC_adv'}) {
2737: $canvalidate = 1;
2738: }
2739: }
2740: next if (!$canvalidate);
2741: }
2742: my $checked = '';
1.104 raeburn 2743: if ($val eq $curroption) {
1.101 raeburn 2744: $checked = ' checked="checked"';
2745: } elsif ($option eq 'autolimit') {
2746: if ($curroption =~ /^autolimit/) {
2747: $checked = ' checked="checked"';
2748: }
2749: }
2750: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2751: '<input type="radio" name="crsreq_'.$item.
2752: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2753: $titles{$option}.'</label>';
2754: if ($option eq 'autolimit') {
1.127 raeburn 2755: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2756: $item.'_limit__LC_adv" size="1" '.
2757: 'value="'.$currlimit.'" />';
2758: }
1.127 raeburn 2759: $advcell{$item} .= '</span> ';
1.104 raeburn 2760: if ($option eq 'autolimit') {
1.127 raeburn 2761: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2762: }
1.101 raeburn 2763: }
1.163 raeburn 2764: } elsif ($context eq 'requestauthor') {
2765: my $curroption;
2766: if (ref($settings) eq 'HASH') {
2767: $curroption = $settings->{'_LC_adv'};
2768: }
2769: my $checked = '';
2770: if ($curroption eq '') {
2771: $checked = ' checked="checked"';
2772: }
2773: $datatable .= '<span class="LC_nobreak"><label>'.
2774: '<input type="radio" name="authorreq__LC_adv"'.
2775: ' value=""'.$checked.' />'.
2776: &mt('No override set').'</label></span> ';
2777: foreach my $option (@options) {
2778: my $val = $option;
2779: if ($option eq 'norequest') {
2780: $val = 0;
2781: }
2782: my $checked = '';
2783: if ($val eq $curroption) {
2784: $checked = ' checked="checked"';
2785: }
2786: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2787: '<input type="radio" name="authorreq__LC_adv"'.
2788: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2789: $titles{$option}.'</label></span> ';
2790: }
1.101 raeburn 2791: } else {
2792: my $checked = 'checked="checked" ';
2793: if (ref($settings) eq 'HASH') {
2794: if (ref($settings->{$item}) eq 'HASH') {
2795: if ($settings->{$item}->{'_LC_adv'} == 0) {
2796: $checked = '';
2797: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2798: $checked = 'checked="checked" ';
2799: }
1.79 raeburn 2800: }
1.72 raeburn 2801: }
1.101 raeburn 2802: $datatable .= '<span class="LC_nobreak"><label>'.
2803: '<input type="checkbox" name="'.$context.'_'.$item.
2804: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2805: '</label></span> ';
2806: }
2807: }
2808: if ($context eq 'requestcourses') {
2809: $datatable .= '</tr><tr>';
2810: foreach my $item (@usertools) {
1.106 raeburn 2811: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2812: }
1.101 raeburn 2813: $datatable .= '</tr></table>';
1.72 raeburn 2814: }
1.98 raeburn 2815: $datatable .= '</td></tr>';
1.30 raeburn 2816: $$rowtotal += $typecount;
1.3 raeburn 2817: return $datatable;
2818: }
2819:
1.163 raeburn 2820: sub print_requestmail {
1.305 raeburn 2821: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2822: my ($now,$datatable,%currapp);
1.102 raeburn 2823: $now = time;
2824: if (ref($settings) eq 'HASH') {
2825: if (ref($settings->{'notify'}) eq 'HASH') {
2826: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2827: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2828: }
2829: }
2830: }
1.191 raeburn 2831: my $numinrow = 2;
1.224 raeburn 2832: my $css_class;
1.305 raeburn 2833: if ($$rowtotal%2) {
2834: $css_class = 'LC_odd_row';
2835: }
2836: if ($customcss) {
2837: $css_class .= " $customcss";
2838: }
2839: $css_class =~ s/^\s+//;
2840: if ($css_class) {
2841: $css_class = ' class="'.$css_class.'"';
2842: }
2843: if ($rowstyle) {
2844: $css_class .= ' style="'.$rowstyle.'"';
2845: }
1.163 raeburn 2846: my $text;
2847: if ($action eq 'requestcourses') {
2848: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2849: } elsif ($action eq 'requestauthor') {
2850: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2851: } else {
1.224 raeburn 2852: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2853: }
1.224 raeburn 2854: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2855: ' <td>'.$text.'</td>'.
1.102 raeburn 2856: ' <td class="LC_left_item">';
1.191 raeburn 2857: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2858: $action.'notifyapproval',%currapp);
1.191 raeburn 2859: if ($numdc > 0) {
2860: $datatable .= $table;
1.102 raeburn 2861: } else {
2862: $datatable .= &mt('There are no active Domain Coordinators');
2863: }
2864: $datatable .='</td></tr>';
2865: return $datatable;
2866: }
2867:
1.216 raeburn 2868: sub print_studentcode {
2869: my ($settings,$rowtotal) = @_;
2870: my $rownum = 0;
1.218 raeburn 2871: my ($output,%current);
1.325 raeburn 2872: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248 raeburn 2873: if (ref($settings) eq 'HASH') {
2874: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2875: foreach my $type (@crstypes) {
2876: $current{$type} = $settings->{'uniquecode'}{$type};
2877: }
1.218 raeburn 2878: }
2879: }
2880: $output .= '<tr>'.
2881: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2882: '<td class="LC_left_item">';
2883: foreach my $type (@crstypes) {
2884: my $check = ' ';
2885: if ($current{$type}) {
2886: $check = ' checked="checked" ';
2887: }
2888: $output .= '<span class="LC_nobreak"><label>'.
2889: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2890: &mt($type).'</label></span>'.(' 'x2).' ';
2891: }
2892: $output .= '</td></tr>';
2893: $$rowtotal ++;
2894: return $output;
1.216 raeburn 2895: }
2896:
2897: sub print_textbookcourses {
1.242 raeburn 2898: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2899: my $rownum = 0;
2900: my $css_class;
2901: my $itemcount = 1;
2902: my $maxnum = 0;
2903: my $bookshash;
2904: if (ref($settings) eq 'HASH') {
1.242 raeburn 2905: $bookshash = $settings->{$type};
1.216 raeburn 2906: }
2907: my %ordered;
2908: if (ref($bookshash) eq 'HASH') {
2909: foreach my $item (keys(%{$bookshash})) {
2910: if (ref($bookshash->{$item}) eq 'HASH') {
2911: my $num = $bookshash->{$item}{'order'};
2912: $ordered{$num} = $item;
2913: }
2914: }
2915: }
2916: my $confname = $dom.'-domainconfig';
2917: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2918: my $maxnum = scalar(keys(%ordered));
2919: my $datatable;
1.216 raeburn 2920: if (keys(%ordered)) {
2921: my @items = sort { $a <=> $b } keys(%ordered);
2922: for (my $i=0; $i<@items; $i++) {
2923: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2924: my $key = $ordered{$items[$i]};
2925: my %coursehash=&Apache::lonnet::coursedescription($key);
2926: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2927: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2928: if (ref($bookshash->{$key}) eq 'HASH') {
2929: $subject = $bookshash->{$key}->{'subject'};
2930: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2931: if ($type eq 'textbooks') {
1.243 raeburn 2932: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2933: $author = $bookshash->{$key}->{'author'};
2934: $image = $bookshash->{$key}->{'image'};
2935: if ($image ne '') {
2936: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2937: my $imagethumb = "$path/tn-".$imagefile;
2938: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2939: }
1.216 raeburn 2940: }
2941: }
1.242 raeburn 2942: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2943: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2944: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2945: for (my $k=0; $k<=$maxnum; $k++) {
2946: my $vpos = $k+1;
2947: my $selstr;
2948: if ($k == $i) {
2949: $selstr = ' selected="selected" ';
2950: }
2951: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2952: }
2953: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2954: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2955: &mt('Delete?').'</label></span></td>'.
2956: '<td colspan="2">'.
1.242 raeburn 2957: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2958: (' 'x2).
1.242 raeburn 2959: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2960: if ($type eq 'textbooks') {
2961: $datatable .= (' 'x2).
1.243 raeburn 2962: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2963: (' 'x2).
1.242 raeburn 2964: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2965: (' 'x2).
2966: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2967: if ($image) {
1.267 raeburn 2968: $datatable .= $imgsrc.
1.242 raeburn 2969: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2970: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2971: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2972: }
2973: if ($switchserver) {
2974: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2975: } else {
2976: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2977: }
1.216 raeburn 2978: }
1.242 raeburn 2979: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2980: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2981: $coursetitle.'</span></td></tr>'."\n";
2982: $itemcount ++;
2983: }
2984: }
2985: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2986: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2987: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2988: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2989: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2990: for (my $k=0; $k<$maxnum+1; $k++) {
2991: my $vpos = $k+1;
2992: my $selstr;
2993: if ($k == $maxnum) {
2994: $selstr = ' selected="selected" ';
2995: }
2996: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2997: }
2998: $datatable .= '</select> '."\n".
1.334 raeburn 2999: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216 raeburn 3000: '<td colspan="2">'.
1.242 raeburn 3001: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 3002: (' 'x2).
1.242 raeburn 3003: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
3004: (' 'x2);
3005: if ($type eq 'textbooks') {
1.243 raeburn 3006: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
3007: (' 'x2).
3008: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 3009: (' 'x2).
3010: '<span class="LC_nobreak">'.&mt('Image:').' ';
3011: if ($switchserver) {
3012: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3013: } else {
3014: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
3015: }
1.334 raeburn 3016: $datatable .= '</span>'."\n";
1.216 raeburn 3017: }
1.334 raeburn 3018: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 3019: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
3020: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 3021: &Apache::loncommon::selectcourse_link
1.334 raeburn 3022: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216 raeburn 3023: '</span></td>'."\n".
3024: '</tr>'."\n";
3025: $itemcount ++;
3026: return $datatable;
3027: }
3028:
1.217 raeburn 3029: sub textbookcourses_javascript {
1.242 raeburn 3030: my ($settings) = @_;
3031: return unless(ref($settings) eq 'HASH');
3032: my (%ordered,%total,%jstext);
3033: foreach my $type ('textbooks','templates') {
3034: $total{$type} = 0;
3035: if (ref($settings->{$type}) eq 'HASH') {
3036: foreach my $item (keys(%{$settings->{$type}})) {
3037: if (ref($settings->{$type}->{$item}) eq 'HASH') {
3038: my $num = $settings->{$type}->{$item}{'order'};
3039: $ordered{$type}{$num} = $item;
3040: }
3041: }
3042: $total{$type} = scalar(keys(%{$settings->{$type}}));
3043: }
3044: my @jsarray = ();
3045: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
3046: push(@jsarray,$ordered{$type}{$item});
3047: }
3048: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 3049: }
3050: return <<"ENDSCRIPT";
3051: <script type="text/javascript">
3052: // <![CDATA[
1.242 raeburn 3053: function reorderBooks(form,item,caller) {
1.217 raeburn 3054: var changedVal;
1.242 raeburn 3055: $jstext{'textbooks'};
3056: $jstext{'templates'};
3057: var newpos;
3058: var maxh;
3059: if (caller == 'textbooks') {
3060: newpos = 'textbooks_addbook_pos';
3061: maxh = 1 + $total{'textbooks'};
3062: } else {
3063: newpos = 'templates_addbook_pos';
3064: maxh = 1 + $total{'templates'};
3065: }
1.217 raeburn 3066: var current = new Array;
3067: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3068: if (item == newpos) {
3069: changedVal = newitemVal;
3070: } else {
3071: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3072: current[newitemVal] = newpos;
3073: }
1.242 raeburn 3074: if (caller == 'textbooks') {
3075: for (var i=0; i<textbooks.length; i++) {
3076: var elementName = 'textbooks_'+textbooks[i];
3077: if (elementName != item) {
3078: if (form.elements[elementName]) {
3079: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3080: current[currVal] = elementName;
3081: }
3082: }
3083: }
3084: }
3085: if (caller == 'templates') {
3086: for (var i=0; i<templates.length; i++) {
3087: var elementName = 'templates_'+templates[i];
3088: if (elementName != item) {
3089: if (form.elements[elementName]) {
3090: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3091: current[currVal] = elementName;
3092: }
1.217 raeburn 3093: }
3094: }
3095: }
3096: var oldVal;
3097: for (var j=0; j<maxh; j++) {
3098: if (current[j] == undefined) {
3099: oldVal = j;
3100: }
3101: }
3102: if (oldVal < changedVal) {
3103: for (var k=oldVal+1; k<=changedVal ; k++) {
3104: var elementName = current[k];
3105: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3106: }
3107: } else {
3108: for (var k=changedVal; k<oldVal; k++) {
3109: var elementName = current[k];
3110: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3111: }
3112: }
3113: return;
3114: }
3115:
3116: // ]]>
3117: </script>
3118:
3119: ENDSCRIPT
3120: }
3121:
1.267 raeburn 3122: sub ltitools_javascript {
3123: my ($settings) = @_;
1.319 raeburn 3124: my $togglejs = <itools_toggle_js();
3125: unless (ref($settings) eq 'HASH') {
3126: return $togglejs;
3127: }
1.267 raeburn 3128: my (%ordered,$total,%jstext);
3129: $total = 0;
3130: foreach my $item (keys(%{$settings})) {
3131: if (ref($settings->{$item}) eq 'HASH') {
3132: my $num = $settings->{$item}{'order'};
3133: $ordered{$num} = $item;
3134: }
3135: }
3136: $total = scalar(keys(%{$settings}));
3137: my @jsarray = ();
3138: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3139: push(@jsarray,$ordered{$item});
3140: }
3141: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
3142: return <<"ENDSCRIPT";
3143: <script type="text/javascript">
3144: // <![CDATA[
1.319 raeburn 3145: function reorderLTITools(form,item) {
1.267 raeburn 3146: var changedVal;
3147: $jstext
3148: var newpos = 'ltitools_add_pos';
3149: var maxh = 1 + $total;
3150: var current = new Array;
3151: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3152: if (item == newpos) {
3153: changedVal = newitemVal;
3154: } else {
3155: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3156: current[newitemVal] = newpos;
3157: }
3158: for (var i=0; i<ltitools.length; i++) {
3159: var elementName = 'ltitools_'+ltitools[i];
3160: if (elementName != item) {
3161: if (form.elements[elementName]) {
3162: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3163: current[currVal] = elementName;
3164: }
3165: }
3166: }
3167: var oldVal;
3168: for (var j=0; j<maxh; j++) {
3169: if (current[j] == undefined) {
3170: oldVal = j;
3171: }
3172: }
3173: if (oldVal < changedVal) {
3174: for (var k=oldVal+1; k<=changedVal ; k++) {
3175: var elementName = current[k];
3176: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3177: }
3178: } else {
3179: for (var k=changedVal; k<oldVal; k++) {
3180: var elementName = current[k];
3181: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3182: }
3183: }
3184: return;
3185: }
3186:
3187: // ]]>
3188: </script>
3189:
1.319 raeburn 3190: $togglejs
3191:
3192: ENDSCRIPT
3193: }
3194:
3195: sub ltitools_toggle_js {
3196: return <<"ENDSCRIPT";
3197: <script type="text/javascript">
3198: // <![CDATA[
3199:
3200: function toggleLTITools(form,setting,item) {
3201: var radioname = '';
3202: var divid = '';
3203: if ((setting == 'passback') || (setting == 'roster')) {
3204: radioname = 'ltitools_'+setting+'_'+item;
3205: divid = 'ltitools_'+setting+'time_'+item;
3206: var num = form.elements[radioname].length;
3207: if (num) {
3208: var setvis = '';
3209: for (var i=0; i<num; i++) {
3210: if (form.elements[radioname][i].checked) {
3211: if (form.elements[radioname][i].value == '1') {
3212: if (document.getElementById(divid)) {
3213: document.getElementById(divid).style.display = 'inline-block';
3214: }
3215: setvis = 1;
3216: }
3217: break;
3218: }
3219: }
3220: }
3221: if (!setvis) {
3222: if (document.getElementById(divid)) {
3223: document.getElementById(divid).style.display = 'none';
3224: }
3225: }
3226: }
1.324 raeburn 3227: if (setting == 'user') {
3228: divid = 'ltitools_'+setting+'_div_'+item;
3229: var checkid = 'ltitools_'+setting+'_field_'+item;
3230: if (document.getElementById(divid)) {
3231: if (document.getElementById(checkid)) {
3232: if (document.getElementById(checkid).checked) {
3233: document.getElementById(divid).style.display = 'inline-block';
3234: } else {
3235: document.getElementById(divid).style.display = 'none';
3236: }
3237: }
3238: }
3239: }
1.319 raeburn 3240: return;
3241: }
3242: // ]]>
3243: </script>
3244:
1.267 raeburn 3245: ENDSCRIPT
3246: }
3247:
1.381 raeburn 3248: sub wafproxy_javascript {
3249: my ($dom) = @_;
3250: return <<"ENDSCRIPT";
3251: <script type="text/javascript">
3252: // <![CDATA[
3253: function updateWAF() {
3254: if (document.getElementById('wafproxy_remoteip')) {
3255: var wafremote = 0;
3256: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
3257: wafremote = 1;
3258: }
3259: var fields = new Array('header','trust');
3260: for (var i=0; i<fields.length; i++) {
3261: if (document.getElementById('wafproxy_'+fields[i])) {
3262: if (wafremote == 1) {
3263: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
3264: }
3265: else {
3266: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
3267: }
3268: }
3269: }
3270: if (document.getElementById('wafproxyranges_$dom')) {
3271: if (wafremote == 1) {
3272: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3273: } else {
3274: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3275: if (document.display.wafproxy_vpnaccess[i].checked) {
3276: if (document.display.wafproxy_vpnaccess[i].value == 0) {
3277: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3278: }
3279: }
3280: }
3281: }
3282: }
3283: }
3284: return;
3285: }
3286:
3287: function checkWAF() {
3288: if (document.getElementById('wafproxy_remoteip')) {
3289: var wafvpn = 0;
3290: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3291: if (document.display.wafproxy_vpnaccess[i].checked) {
3292: if (document.display.wafproxy_vpnaccess[i].value == 1) {
3293: wafvpn = 1;
3294: }
3295: break;
3296: }
3297: }
3298: var vpn = new Array('vpnint','vpnext');
3299: for (var i=0; i<vpn.length; i++) {
3300: if (document.getElementById('wafproxy_show_'+vpn[i])) {
3301: if (wafvpn == 1) {
3302: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
3303: }
3304: else {
3305: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
3306: }
3307: }
3308: }
3309: if (document.getElementById('wafproxyranges_$dom')) {
3310: if (wafvpn == 1) {
3311: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3312: }
3313: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
3314: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3315: }
3316: }
3317: }
3318: return;
3319: }
3320:
3321: function toggleWAF() {
3322: if (document.getElementById('wafproxy_table')) {
3323: var wafproxy = 0;
3324: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
3325: if (document.display.wafproxy_${dom}[i].checked) {
3326: if (document.display.wafproxy_${dom}[i].value == 1) {
3327: wafproxy = 1;
3328: break;
3329: }
3330: }
3331: }
3332: if (wafproxy == 1) {
3333: document.getElementById('wafproxy_table').style.display='inline';
3334: }
3335: else {
3336: document.getElementById('wafproxy_table').style.display='none';
3337: }
3338: if (document.getElementById('wafproxyrow_${dom}')) {
3339: if (wafproxy == 1) {
3340: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
3341: }
3342: else {
3343: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
3344: }
3345: }
3346: if (document.getElementById('nowafproxyrow_$dom')) {
3347: if (wafproxy == 1) {
3348: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
3349: }
3350: else {
3351: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
3352: }
3353: }
3354: }
3355: return;
3356: }
3357: // ]]>
3358: </script>
3359:
3360: ENDSCRIPT
3361: }
3362:
1.372 raeburn 3363: sub proctoring_javascript {
3364: my ($settings) = @_;
3365: my (%ordered,$total,%jstext);
3366: $total = 0;
3367: if (ref($settings) eq 'HASH') {
3368: foreach my $item (keys(%{$settings})) {
3369: if (ref($settings->{$item}) eq 'HASH') {
3370: my $num = $settings->{$item}{'order'};
3371: $ordered{$num} = $item;
3372: }
3373: }
3374: $total = scalar(keys(%{$settings}));
3375: } else {
3376: %ordered = (
3377: 0 => 'proctorio',
3378: 1 => 'examity',
3379: );
3380: $total = 2;
3381: }
3382: my @jsarray = ();
3383: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3384: push(@jsarray,$ordered{$item});
3385: }
3386: my $jstext = ' var proctors = Array('."'".join("','",@jsarray)."'".');'."\n";
3387: return <<"ENDSCRIPT";
3388: <script type="text/javascript">
3389: // <![CDATA[
3390: function reorderProctoring(form,item) {
3391: var changedVal;
3392: $jstext
3393: var maxh = $total;
3394: var current = new Array;
3395: var changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3396: for (var i=0; i<proctors.length; i++) {
3397: var elementName = 'proctoring_pos_'+proctors[i];
3398: if (elementName != item) {
3399: if (form.elements[elementName]) {
3400: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3401: current[currVal] = elementName;
3402: }
3403: }
3404: }
3405: var oldVal;
3406: for (var j=0; j<maxh; j++) {
3407: if (current[j] == undefined) {
3408: oldVal = j;
3409: }
3410: }
3411: if (oldVal < changedVal) {
3412: for (var k=oldVal+1; k<=changedVal ; k++) {
3413: var elementName = current[k];
3414: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3415: }
3416: } else {
3417: for (var k=changedVal; k<oldVal; k++) {
3418: var elementName = current[k];
3419: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3420: }
3421: }
3422: return;
3423: }
3424:
3425: function toggleProctoring(form,item) {
3426: var fieldsets = document.getElementsByClassName('proctoring_'+item);
3427: if (fieldsets.length) {
3428: var radioname = 'proctoring_available_'+item;
3429: var num = form.elements[radioname].length;
3430: if (num) {
3431: var setvis = '';
3432: for (var i=0; i<num; i++) {
3433: if (form.elements[radioname][i].checked) {
3434: if (form.elements[radioname][i].value == '1') {
3435: setvis = 1;
3436: break;
3437: }
3438: }
3439: }
3440: for (var j=0; j<fieldsets.length; j++) {
3441: if (setvis) {
3442: fieldsets[j].style.display = 'block';
3443: } else {
3444: fieldsets[j].style.display = 'none';
3445: }
3446: }
3447: }
3448: }
3449: return;
3450: }
3451:
3452: // ]]>
3453: </script>
3454:
3455: ENDSCRIPT
3456: }
3457:
3458:
1.320 raeburn 3459: sub lti_javascript {
1.405 raeburn 3460: my ($dom,$settings) = @_;
3461: my $togglejs = <i_toggle_js($dom);
1.419 raeburn 3462: my $linkprot_js = &Apache::courseprefs::linkprot_javascript();
1.320 raeburn 3463: unless (ref($settings) eq 'HASH') {
1.419 raeburn 3464: return $togglejs.'
3465: <script type="text/javascript">
3466: // <![CDATA[
3467:
3468: '.$linkprot_js.'
3469:
3470: // ]]>
3471: </script>
3472: ';
1.320 raeburn 3473: }
3474: my (%ordered,$total,%jstext);
1.390 raeburn 3475: $total = scalar(keys(%{$settings}));
1.320 raeburn 3476: foreach my $item (keys(%{$settings})) {
3477: if (ref($settings->{$item}) eq 'HASH') {
3478: my $num = $settings->{$item}{'order'};
1.390 raeburn 3479: if ($num eq '') {
3480: $num = $total - 1;
3481: }
1.320 raeburn 3482: $ordered{$num} = $item;
3483: }
3484: }
3485: my @jsarray = ();
3486: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3487: push(@jsarray,$ordered{$item});
3488: }
3489: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
3490: return <<"ENDSCRIPT";
3491: <script type="text/javascript">
3492: // <![CDATA[
3493: function reorderLTI(form,item) {
3494: var changedVal;
3495: $jstext
3496: var newpos = 'lti_pos_add';
3497: var maxh = 1 + $total;
3498: var current = new Array;
3499: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3500: if (item == newpos) {
3501: changedVal = newitemVal;
3502: } else {
3503: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3504: current[newitemVal] = newpos;
3505: }
3506: for (var i=0; i<lti.length; i++) {
3507: var elementName = 'lti_pos_'+lti[i];
3508: if (elementName != item) {
3509: if (form.elements[elementName]) {
3510: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3511: current[currVal] = elementName;
3512: }
3513: }
3514: }
3515: var oldVal;
3516: for (var j=0; j<maxh; j++) {
3517: if (current[j] == undefined) {
3518: oldVal = j;
3519: }
3520: }
3521: if (oldVal < changedVal) {
3522: for (var k=oldVal+1; k<=changedVal ; k++) {
3523: var elementName = current[k];
3524: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3525: }
3526: } else {
3527: for (var k=changedVal; k<oldVal; k++) {
3528: var elementName = current[k];
3529: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3530: }
3531: }
3532: return;
3533: }
1.406 raeburn 3534:
3535: $linkprot_js
3536:
1.320 raeburn 3537: // ]]>
3538: </script>
3539:
3540: $togglejs
3541:
3542: ENDSCRIPT
3543: }
3544:
3545: sub lti_toggle_js {
1.405 raeburn 3546: my ($dom) = @_;
1.325 raeburn 3547: my %lcauthparmtext = &Apache::lonlocal::texthash (
3548: localauth => 'Local auth argument',
3549: krb => 'Kerberos domain',
3550: );
1.391 raeburn 3551: my $crsincalert = &mt('"User\'s identity sent" needs to be set to "Yes" first,[_1] before setting "Course\'s identity sent" to "Yes"',"\n");
3552: &js_escape(\$crsincalert);
1.405 raeburn 3553: my %servers = &Apache::lonnet::get_servers($dom,'library');
3554: my $primary = &Apache::lonnet::domain($dom,'primary');
3555: my $course_servers = "'".join("','",keys(%servers))."'";
1.320 raeburn 3556: return <<"ENDSCRIPT";
3557: <script type="text/javascript">
3558: // <![CDATA[
3559:
3560: function toggleLTI(form,setting,item) {
1.391 raeburn 3561: if ((setting == 'requser') || (setting == 'crsinc')) {
3562: var usrfieldsets = document.getElementsByClassName('ltioption_usr_'+item);
3563: var setvis = '';
3564: var radioname = 'lti_requser_'+item;
3565: var num = form.elements[radioname].length;
3566: if (num) {
3567: for (var i=0; i<num; i++) {
3568: if (form.elements[radioname][i].checked) {
3569: if (form.elements[radioname][i].value == '1') {
3570: setvis = 1;
3571: break;
3572: }
3573: }
3574: }
3575: }
3576: if (usrfieldsets.length) {
3577: for (var j=0; j<usrfieldsets.length; j++) {
3578: if (setvis) {
3579: usrfieldsets[j].style.display = 'block';
3580: } else {
3581: usrfieldsets[j].style.display = 'none';
3582: }
3583: }
3584: }
3585: var crsfieldsets = document.getElementsByClassName('ltioption_crs_'+item);
3586: if (crsfieldsets.length) {
3587: radioname = 'lti_crsinc_'+item;
1.345 raeburn 3588: var num = form.elements[radioname].length;
3589: if (num) {
1.391 raeburn 3590: var crsvis = '';
1.345 raeburn 3591: for (var i=0; i<num; i++) {
3592: if (form.elements[radioname][i].checked) {
3593: if (form.elements[radioname][i].value == '1') {
1.391 raeburn 3594: if (setvis == '') {
3595: if (setting == 'crsinc'){
3596: alert("$crsincalert");
3597: form.elements[radioname][0].checked = true;
3598: }
3599: } else {
3600: crsvis = 1;
3601: }
3602: break;
1.345 raeburn 3603: }
3604: }
3605: }
1.391 raeburn 3606: setvis = crsvis;
3607: }
3608: for (var j=0; j<crsfieldsets.length; j++) {
3609: if (setvis) {
3610: crsfieldsets[j].style.display = 'block';
3611: } else {
3612: crsfieldsets[j].style.display = 'none';
1.345 raeburn 3613: }
3614: }
3615: }
1.363 raeburn 3616: } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
1.320 raeburn 3617: var radioname = '';
3618: var divid = '';
3619: if (setting == 'user') {
3620: radioname = 'lti_mapuser_'+item;
3621: divid = 'lti_userfield_'+item;
1.343 raeburn 3622: } else if (setting == 'crs') {
1.320 raeburn 3623: radioname = 'lti_mapcrs_'+item;
3624: divid = 'lti_crsfield_'+item;
1.363 raeburn 3625: } else if (setting == 'callback') {
3626: radioname = 'lti_callback_'+item;
3627: divid = 'lti_callbackfield_'+item;
1.337 raeburn 3628: } else {
1.351 raeburn 3629: radioname = 'lti_passback_'+item;
1.337 raeburn 3630: divid = 'lti_passback_'+item;
1.320 raeburn 3631: }
3632: var num = form.elements[radioname].length;
3633: if (num) {
3634: var setvis = '';
3635: for (var i=0; i<num; i++) {
3636: if (form.elements[radioname][i].checked) {
1.363 raeburn 3637: if ((setting == 'passback') || (setting == 'callback')) {
1.337 raeburn 3638: if (form.elements[radioname][i].value == '1') {
3639: if (document.getElementById(divid)) {
3640: document.getElementById(divid).style.display = 'inline-block';
3641: }
3642: setvis = 1;
3643: break;
3644: }
3645: } else {
3646: if (form.elements[radioname][i].value == 'other') {
3647: if (document.getElementById(divid)) {
3648: document.getElementById(divid).style.display = 'inline-block';
3649: }
3650: setvis = 1;
3651: break;
1.320 raeburn 3652: }
3653: }
1.425 raeburn 3654: }
1.320 raeburn 3655: }
3656: if (!setvis) {
3657: if (document.getElementById(divid)) {
3658: document.getElementById(divid).style.display = 'none';
3659: }
3660: }
3661: }
3662: } else if ((setting == 'sec') || (setting == 'secsrc')) {
3663: var numsec = form.elements['lti_crssec_'+item].length;
3664: if (numsec) {
3665: var setvis = '';
3666: for (var i=0; i<numsec; i++) {
3667: if (form.elements['lti_crssec_'+item][i].checked) {
3668: if (form.elements['lti_crssec_'+item][i].value == '1') {
3669: if (document.getElementById('lti_crssecfield_'+item)) {
3670: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
3671: setvis = 1;
3672: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
3673: if (numsrcsec) {
3674: var setsrcvis = '';
3675: for (var j=0; j<numsrcsec; j++) {
3676: if (form.elements['lti_crssecsrc_'+item][j].checked) {
3677: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
3678: if (document.getElementById('lti_secsrcfield_'+item)) {
3679: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
3680: setsrcvis = 1;
3681: }
3682: }
3683: }
3684: }
3685: if (!setsrcvis) {
3686: if (document.getElementById('lti_secsrcfield_'+item)) {
3687: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3688: }
3689: }
3690: }
3691: }
3692: }
3693: }
3694: }
3695: if (!setvis) {
3696: if (document.getElementById('lti_crssecfield_'+item)) {
3697: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
3698: }
3699: if (document.getElementById('lti_secsrcfield_'+item)) {
3700: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3701: }
3702: }
3703: }
1.325 raeburn 3704: } else if (setting == 'lcauth') {
3705: var numauth = form.elements['lti_lcauth_'+item].length;
3706: if (numauth) {
3707: for (var i=0; i<numauth; i++) {
3708: if (form.elements['lti_lcauth_'+item][i].checked) {
3709: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
3710: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
3711: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
3712: } else {
3713: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
3714: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
3715: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
3716: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
3717: } else {
3718: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
3719: }
3720: }
3721: }
3722: }
3723: }
3724: }
3725: }
1.326 raeburn 3726: } else if (setting == 'lcmenu') {
3727: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3728: var divid = 'lti_menufield_'+item;
3729: var setvis = '';
3730: for (var i=0; i<menus.length; i++) {
1.425 raeburn 3731: var radioname = menus[i];
1.326 raeburn 3732: var num = form.elements[radioname].length;
3733: if (num) {
3734: for (var j=0; j<num; j++) {
3735: if (form.elements[radioname][j].checked) {
3736: if (form.elements[radioname][j].value == '1') {
3737: if (document.getElementById(divid)) {
3738: document.getElementById(divid).style.display = 'inline-block';
3739: }
3740: setvis = 1;
3741: break;
3742: }
3743: }
3744: }
3745: }
3746: if (setvis == 1) {
3747: break;
3748: }
3749: }
3750: if (!setvis) {
3751: if (document.getElementById(divid)) {
3752: document.getElementById(divid).style.display = 'none';
3753: }
3754: }
1.320 raeburn 3755: }
3756: return;
3757: }
1.405 raeburn 3758:
1.320 raeburn 3759: // ]]>
3760: </script>
3761:
3762: ENDSCRIPT
3763: }
3764:
1.385 raeburn 3765: sub autoupdate_javascript {
3766: return <<"ENDSCRIPT";
3767: <script type="text/javascript">
3768: // <![CDATA[
3769: function toggleLastActiveDays(form) {
3770: var radioname = 'lastactive';
3771: var divid = 'lastactive_div';
3772: var num = form.elements[radioname].length;
3773: if (num) {
3774: var setvis = '';
3775: for (var i=0; i<num; i++) {
3776: if (form.elements[radioname][i].checked) {
3777: if (form.elements[radioname][i].value == '1') {
3778: if (document.getElementById(divid)) {
3779: document.getElementById(divid).style.display = 'inline-block';
3780: }
3781: setvis = 1;
3782: }
3783: break;
3784: }
3785: }
3786: if (!setvis) {
3787: if (document.getElementById(divid)) {
3788: document.getElementById(divid).style.display = 'none';
3789: }
3790: }
3791: }
3792: return;
3793: }
3794: // ]]>
3795: </script>
3796:
3797: ENDSCRIPT
3798: }
3799:
1.399 raeburn 3800: sub autoenroll_javascript {
3801: return <<"ENDSCRIPT";
3802: <script type="text/javascript">
3803: // <![CDATA[
3804: function toggleFailsafe(form) {
3805: var radioname = 'autoenroll_failsafe';
3806: var divid = 'autoenroll_failsafe_div';
3807: var num = form.elements[radioname].length;
3808: if (num) {
3809: var setvis = '';
3810: for (var i=0; i<num; i++) {
3811: if (form.elements[radioname][i].checked) {
3812: if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
3813: if (document.getElementById(divid)) {
3814: document.getElementById(divid).style.display = 'inline-block';
3815: }
3816: setvis = 1;
3817: }
3818: break;
3819: }
3820: }
3821: if (!setvis) {
3822: if (document.getElementById(divid)) {
3823: document.getElementById(divid).style.display = 'none';
3824: }
3825: }
3826: }
3827: return;
3828: }
3829: // ]]>
3830: </script>
3831:
3832: ENDSCRIPT
3833: }
3834:
1.386 raeburn 3835: sub saml_javascript {
3836: return <<"ENDSCRIPT";
3837: <script type="text/javascript">
3838: // <![CDATA[
1.425 raeburn 3839: function toggleSamlOptions(form,hostid) {
1.386 raeburn 3840: var radioname = 'saml_'+hostid;
3841: var tablecellon = 'samloptionson_'+hostid;
3842: var tablecelloff = 'samloptionsoff_'+hostid;
3843: var num = form.elements[radioname].length;
3844: if (num) {
1.425 raeburn 3845: var setvis = '';
1.386 raeburn 3846: for (var i=0; i<num; i++) {
3847: if (form.elements[radioname][i].checked) {
1.425 raeburn 3848: if (form.elements[radioname][i].value == '1') {
1.386 raeburn 3849: if (document.getElementById(tablecellon)) {
3850: document.getElementById(tablecellon).style.display='';
3851: }
3852: if (document.getElementById(tablecelloff)) {
3853: document.getElementById(tablecelloff).style.display='none';
3854: }
3855: setvis = 1;
3856: }
3857: break;
3858: }
3859: }
3860: if (!setvis) {
3861: if (document.getElementById(tablecellon)) {
3862: document.getElementById(tablecellon).style.display='none';
3863: }
3864: if (document.getElementById(tablecelloff)) {
3865: document.getElementById(tablecelloff).style.display='';
3866: }
3867: }
3868: }
3869: return;
3870: }
3871: // ]]>
3872: </script>
3873:
3874: ENDSCRIPT
3875: }
3876:
1.394 raeburn 3877: sub ipaccess_javascript {
3878: my ($settings) = @_;
3879: my (%ordered,$total,%jstext);
3880: $total = 0;
3881: if (ref($settings) eq 'HASH') {
3882: foreach my $item (keys(%{$settings})) {
3883: if (ref($settings->{$item}) eq 'HASH') {
3884: my $num = $settings->{$item}{'order'};
3885: $ordered{$num} = $item;
3886: }
3887: }
3888: $total = scalar(keys(%{$settings}));
3889: }
3890: my @jsarray = ();
3891: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3892: push(@jsarray,$ordered{$item});
3893: }
3894: my $jstext = ' var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
3895: return <<"ENDSCRIPT";
3896: <script type="text/javascript">
3897: // <![CDATA[
3898: function reorderIPaccess(form,item) {
3899: var changedVal;
3900: $jstext
3901: var newpos = 'ipaccess_pos_add';
3902: var maxh = 1 + $total;
3903: var current = new Array;
3904: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3905: if (item == newpos) {
3906: changedVal = newitemVal;
3907: } else {
3908: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3909: current[newitemVal] = newpos;
3910: }
3911: for (var i=0; i<ipaccess.length; i++) {
3912: var elementName = 'ipaccess_pos_'+ipaccess[i];
3913: if (elementName != item) {
3914: if (form.elements[elementName]) {
3915: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3916: current[currVal] = elementName;
3917: }
3918: }
3919: }
3920: var oldVal;
3921: for (var j=0; j<maxh; j++) {
3922: if (current[j] == undefined) {
3923: oldVal = j;
3924: }
3925: }
3926: if (oldVal < changedVal) {
3927: for (var k=oldVal+1; k<=changedVal ; k++) {
3928: var elementName = current[k];
3929: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3930: }
3931: } else {
3932: for (var k=changedVal; k<oldVal; k++) {
3933: var elementName = current[k];
3934: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3935: }
3936: }
3937: return;
3938: }
3939: // ]]>
3940: </script>
3941:
3942: ENDSCRIPT
3943: }
3944:
1.429 raeburn 3945: sub authordefaults_javascript {
3946: my %alert = &Apache::lonlocal::texthash (
3947: reqd => 'Warning: at least one editor needs to be available.',
3948: rest => 'Unchecking this editor disallowed while others unchecked.',
3949: );
3950: &js_escape(\%alert);
3951: return <<"ENDSCRIPT";
3952: <script type="text/javascript">
3953: // <![CDATA[
3954:
3955: function checkEditors(form,checkbox,current) {
3956: if (form.elements[checkbox].length != undefined) {
3957: var count = 0;
3958: for (var i=0; i<form.elements[checkbox].length; i++) {
3959: if (form.elements[checkbox][i].checked) {
3960: count ++;
3961: }
3962: }
3963: if (count == 0) {
3964: if (current.type =='radio') {
3965: current.checked = true;
3966: alert('$alert{reqd}\\n$alert{rest}');
3967: }
3968: }
3969: }
3970: return;
3971: }
3972: // ]]>
3973: </script>
3974:
3975: ENDSCRIPT
3976: }
3977:
1.3 raeburn 3978: sub print_autoenroll {
1.30 raeburn 3979: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3980: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.399 raeburn 3981: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
3982: $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
3983: $failsafesty = 'none';
3984: %failsafechecked = (
3985: off => ' checked="checked"',
3986: );
1.3 raeburn 3987: if (ref($settings) eq 'HASH') {
3988: if (exists($settings->{'run'})) {
3989: if ($settings->{'run'} eq '0') {
3990: $runoff = ' checked="checked" ';
3991: $runon = ' ';
3992: } else {
3993: $runon = ' checked="checked" ';
3994: $runoff = ' ';
3995: }
3996: } else {
3997: if ($autorun) {
3998: $runon = ' checked="checked" ';
3999: $runoff = ' ';
4000: } else {
4001: $runoff = ' checked="checked" ';
4002: $runon = ' ';
4003: }
4004: }
1.129 raeburn 4005: if (exists($settings->{'co-owners'})) {
4006: if ($settings->{'co-owners'} eq '0') {
4007: $coownersoff = ' checked="checked" ';
4008: $coownerson = ' ';
4009: } else {
4010: $coownerson = ' checked="checked" ';
4011: $coownersoff = ' ';
4012: }
4013: } else {
4014: $coownersoff = ' checked="checked" ';
4015: $coownerson = ' ';
4016: }
1.3 raeburn 4017: if (exists($settings->{'sender_domain'})) {
4018: $defdom = $settings->{'sender_domain'};
4019: }
1.399 raeburn 4020: if (exists($settings->{'failsafe'})) {
4021: $failsafe = $settings->{'failsafe'};
4022: if ($failsafe eq 'zero') {
1.400 raeburn 4023: $failsafechecked{'zero'} = ' checked="checked"';
1.399 raeburn 4024: $failsafechecked{'off'} = '';
4025: $failsafesty = 'inline-block';
4026: } elsif ($failsafe eq 'any') {
4027: $failsafechecked{'any'} = ' checked="checked"';
4028: $failsafechecked{'off'} = '';
4029: }
4030: $autofailsafe = $settings->{'autofailsafe'};
4031: } elsif (exists($settings->{'autofailsafe'})) {
4032: $autofailsafe = $settings->{'autofailsafe'};
4033: if ($autofailsafe ne '') {
4034: $failsafechecked{'zero'} = ' checked="checked"';
4035: $failsafe = 'zero';
1.400 raeburn 4036: $failsafechecked{'off'} = '';
1.399 raeburn 4037: }
1.274 raeburn 4038: }
1.14 raeburn 4039: } else {
4040: if ($autorun) {
4041: $runon = ' checked="checked" ';
4042: $runoff = ' ';
4043: } else {
4044: $runoff = ' checked="checked" ';
4045: $runon = ' ';
4046: }
1.3 raeburn 4047: }
4048: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 4049: my $notif_sender;
4050: if (ref($settings) eq 'HASH') {
4051: $notif_sender = $settings->{'sender_uname'};
4052: }
1.3 raeburn 4053: my $datatable='<tr class="LC_odd_row">'.
4054: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 4055: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 4056: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 4057: $runon.' value="1" />'.&mt('Yes').'</label> '.
4058: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 4059: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 4060: '</tr><tr>'.
4061: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 4062: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 4063: &mt('username').': '.
4064: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 4065: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 4066: ': '.$domform.'</span></td></tr>'.
4067: '<tr class="LC_odd_row">'.
4068: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
4069: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4070: '<input type="radio" name="autoassign_coowners"'.
4071: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
4072: '<label><input type="radio" name="autoassign_coowners"'.
4073: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 4074: '</tr><tr>'.
4075: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
1.400 raeburn 4076: '<td class="LC_left_item"><span class="LC_nobreak">'.
4077: '<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> '.
4078: '<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 />'.
4079: '<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 4080: '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
4081: '<span class="LC_nobreak">'.
4082: &mt('Threshold for number of students in section to drop: [_1]',
4083: '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
4084: '</span></div></td></tr>';
1.274 raeburn 4085: $$rowtotal += 4;
1.3 raeburn 4086: return $datatable;
4087: }
4088:
4089: sub print_autoupdate {
1.30 raeburn 4090: my ($position,$dom,$settings,$rowtotal) = @_;
1.385 raeburn 4091: my ($enable,$datatable);
1.3 raeburn 4092: if ($position eq 'top') {
1.385 raeburn 4093: my %choices = &Apache::lonlocal::texthash (
4094: run => 'Auto-update active?',
4095: classlists => 'Update information in classlists?',
4096: unexpired => 'Skip updates for users without active or future roles?',
4097: lastactive => 'Skip updates for inactive users?',
4098: );
4099: my $itemcount = 0;
1.3 raeburn 4100: my $updateon = ' ';
4101: my $updateoff = ' checked="checked" ';
4102: if (ref($settings) eq 'HASH') {
4103: if ($settings->{'run'} eq '1') {
4104: $updateon = $updateoff;
4105: $updateoff = ' ';
4106: }
4107: }
1.385 raeburn 4108: $enable = '<tr class="LC_odd_row">'.
4109: '<td>'.$choices{'run'}.'</td>'.
4110: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 4111: '<input type="radio" name="autoupdate_run"'.
1.397 raeburn 4112: $updateoff.'value="0" />'.&mt('No').'</label> '.
1.8 raeburn 4113: '<label><input type="radio" name="autoupdate_run"'.
1.385 raeburn 4114: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 4115: '</tr>';
1.385 raeburn 4116: my @toggles = ('classlists','unexpired');
4117: my %defaultchecked = ('classlists' => 'off',
4118: 'unexpired' => 'off'
4119: );
4120: $$rowtotal ++;
4121: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4122: \%choices,$itemcount,'','','left','no');
4123: $datatable = $enable.$datatable;
4124: $$rowtotal += $itemcount;
4125: my $lastactiveon = ' ';
4126: my $lastactiveoff = ' checked="checked" ';
4127: my $lastactivestyle = 'none';
4128: my $lastactivedays;
4129: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
4130: if (ref($settings) eq 'HASH') {
4131: if ($settings->{'lastactive'} =~ /^\d+$/) {
4132: $lastactiveon = $lastactiveoff;
4133: $lastactiveoff = ' ';
4134: $lastactivestyle = 'inline-block';
4135: $lastactivedays = $settings->{'lastactive'};
4136: }
4137: }
4138: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4139: $datatable .= '<tr'.$css_class.'>'.
4140: '<td>'.$choices{'lastactive'}.'</td>'.
4141: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
4142: '<input type="radio" name="lastactive"'.
4143: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
4144: ' <label>'.
4145: '<input type="radio" name="lastactive"'.
4146: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
4147: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
4148: ': '.&mt('inactive = no activity in last [_1] days',
4149: '<input type="text" size="5" name="lastactivedays" value="'.
4150: $lastactivedays.'" />').
4151: '</span></td>'.
4152: '</tr>';
4153: $$rowtotal ++;
1.131 raeburn 4154: } elsif ($position eq 'middle') {
4155: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4156: my $numinrow = 3;
4157: my $locknamesettings;
4158: $datatable .= &insttypes_row($settings,$types,$usertypes,
4159: $dom,$numinrow,$othertitle,
1.305 raeburn 4160: 'lockablenames',$rowtotal);
1.131 raeburn 4161: $$rowtotal ++;
1.3 raeburn 4162: } else {
1.44 raeburn 4163: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 4164: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 4165: 'permanentemail','id');
1.33 raeburn 4166: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 4167: my $numrows = 0;
1.26 raeburn 4168: if (ref($types) eq 'ARRAY') {
4169: if (@{$types} > 0) {
4170: $datatable =
4171: &usertype_update_row($settings,$usertypes,\%fieldtitles,
4172: \@fields,$types,\$numrows);
1.30 raeburn 4173: $$rowtotal += @{$types};
1.26 raeburn 4174: }
1.3 raeburn 4175: }
4176: $datatable .=
4177: &usertype_update_row($settings,{'default' => $othertitle},
4178: \%fieldtitles,\@fields,['default'],
4179: \$numrows);
1.30 raeburn 4180: $$rowtotal ++;
1.3 raeburn 4181: }
4182: return $datatable;
4183: }
4184:
1.125 raeburn 4185: sub print_autocreate {
4186: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 4187: my (%createon,%createoff,%currhash);
1.125 raeburn 4188: my @types = ('xml','req');
4189: if (ref($settings) eq 'HASH') {
4190: foreach my $item (@types) {
4191: $createoff{$item} = ' checked="checked" ';
4192: $createon{$item} = ' ';
4193: if (exists($settings->{$item})) {
4194: if ($settings->{$item}) {
4195: $createon{$item} = ' checked="checked" ';
4196: $createoff{$item} = ' ';
4197: }
4198: }
4199: }
1.210 raeburn 4200: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 4201: $currhash{$settings->{'xmldc'}} = 1;
4202: }
1.125 raeburn 4203: } else {
4204: foreach my $item (@types) {
4205: $createoff{$item} = ' checked="checked" ';
4206: $createon{$item} = ' ';
4207: }
4208: }
4209: $$rowtotal += 2;
1.191 raeburn 4210: my $numinrow = 2;
1.125 raeburn 4211: my $datatable='<tr class="LC_odd_row">'.
4212: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
4213: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4214: '<input type="radio" name="autocreate_xml"'.
4215: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
4216: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 4217: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
4218: '</td></tr><tr>'.
4219: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
4220: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4221: '<input type="radio" name="autocreate_req"'.
4222: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
4223: '<label><input type="radio" name="autocreate_req"'.
4224: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 4225: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4226: 'autocreate_xmldc',%currhash);
1.247 raeburn 4227: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 4228: if ($numdc > 1) {
1.247 raeburn 4229: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
4230: '</td><td class="LC_left_item">';
1.125 raeburn 4231: } else {
1.247 raeburn 4232: $datatable .= &mt('Course creation processed as:').
4233: '</td><td class="LC_right_item">';
1.125 raeburn 4234: }
1.247 raeburn 4235: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 4236: $$rowtotal += $rows;
1.125 raeburn 4237: return $datatable;
4238: }
4239:
1.23 raeburn 4240: sub print_directorysrch {
1.277 raeburn 4241: my ($position,$dom,$settings,$rowtotal) = @_;
4242: my $datatable;
4243: if ($position eq 'top') {
4244: my $instsrchon = ' ';
4245: my $instsrchoff = ' checked="checked" ';
4246: my ($exacton,$containson,$beginson);
4247: my $instlocalon = ' ';
4248: my $instlocaloff = ' checked="checked" ';
4249: if (ref($settings) eq 'HASH') {
4250: if ($settings->{'available'} eq '1') {
4251: $instsrchon = $instsrchoff;
4252: $instsrchoff = ' ';
4253: }
4254: if ($settings->{'localonly'} eq '1') {
4255: $instlocalon = $instlocaloff;
4256: $instlocaloff = ' ';
4257: }
4258: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
4259: foreach my $type (@{$settings->{'searchtypes'}}) {
4260: if ($type eq 'exact') {
4261: $exacton = ' checked="checked" ';
4262: } elsif ($type eq 'contains') {
4263: $containson = ' checked="checked" ';
4264: } elsif ($type eq 'begins') {
4265: $beginson = ' checked="checked" ';
4266: }
4267: }
4268: } else {
4269: if ($settings->{'searchtypes'} eq 'exact') {
4270: $exacton = ' checked="checked" ';
4271: } elsif ($settings->{'searchtypes'} eq 'contains') {
4272: $containson = ' checked="checked" ';
4273: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 4274: $exacton = ' checked="checked" ';
4275: $containson = ' checked="checked" ';
4276: }
4277: }
1.277 raeburn 4278: }
4279: my ($searchtitles,$titleorder) = &sorted_searchtitles();
4280: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4281:
4282: my $numinrow = 4;
4283: my $cansrchrow = 0;
4284: $datatable='<tr class="LC_odd_row">'.
4285: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
4286: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4287: '<input type="radio" name="dirsrch_available"'.
4288: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
4289: '<label><input type="radio" name="dirsrch_available"'.
4290: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4291: '</tr><tr>'.
4292: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
4293: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4294: '<input type="radio" name="dirsrch_instlocalonly"'.
4295: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4296: '<label><input type="radio" name="dirsrch_instlocalonly"'.
4297: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4298: '</tr>';
4299: $$rowtotal += 2;
4300: if (ref($usertypes) eq 'HASH') {
4301: if (keys(%{$usertypes}) > 0) {
4302: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 4303: $numinrow,$othertitle,'cansearch',
4304: $rowtotal);
1.277 raeburn 4305: $cansrchrow = 1;
1.25 raeburn 4306: }
1.23 raeburn 4307: }
1.277 raeburn 4308: if ($cansrchrow) {
4309: $$rowtotal ++;
4310: $datatable .= '<tr>';
4311: } else {
4312: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 4313: }
1.277 raeburn 4314: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
4315: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
4316: foreach my $title (@{$titleorder}) {
4317: if (defined($searchtitles->{$title})) {
4318: my $check = ' ';
4319: if (ref($settings) eq 'HASH') {
4320: if (ref($settings->{'searchby'}) eq 'ARRAY') {
4321: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
4322: $check = ' checked="checked" ';
4323: }
1.39 raeburn 4324: }
1.25 raeburn 4325: }
1.277 raeburn 4326: $datatable .= '<td class="LC_left_item">'.
4327: '<span class="LC_nobreak"><label>'.
4328: '<input type="checkbox" name="searchby" '.
4329: 'value="'.$title.'"'.$check.'/>'.
4330: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 4331: }
4332: }
1.277 raeburn 4333: $datatable .= '</tr></table></td></tr>';
4334: $$rowtotal ++;
4335: if ($cansrchrow) {
4336: $datatable .= '<tr class="LC_odd_row">';
4337: } else {
4338: $datatable .= '<tr>';
4339: }
4340: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
4341: '<td class="LC_left_item" colspan="2">'.
4342: '<span class="LC_nobreak"><label>'.
4343: '<input type="checkbox" name="searchtypes" '.
4344: $exacton.' value="exact" />'.&mt('Exact match').
4345: '</label> '.
4346: '<label><input type="checkbox" name="searchtypes" '.
4347: $beginson.' value="begins" />'.&mt('Begins with').
4348: '</label> '.
4349: '<label><input type="checkbox" name="searchtypes" '.
4350: $containson.' value="contains" />'.&mt('Contains').
4351: '</label></span></td></tr>';
4352: $$rowtotal ++;
1.26 raeburn 4353: } else {
1.277 raeburn 4354: my $domsrchon = ' checked="checked" ';
4355: my $domsrchoff = ' ';
4356: my $domlocalon = ' ';
4357: my $domlocaloff = ' checked="checked" ';
4358: if (ref($settings) eq 'HASH') {
4359: if ($settings->{'lclocalonly'} eq '1') {
4360: $domlocalon = $domlocaloff;
4361: $domlocaloff = ' ';
4362: }
4363: if ($settings->{'lcavailable'} eq '0') {
4364: $domsrchoff = $domsrchon;
4365: $domsrchon = ' ';
4366: }
4367: }
4368: $datatable='<tr class="LC_odd_row">'.
4369: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
4370: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4371: '<input type="radio" name="dirsrch_domavailable"'.
4372: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
4373: '<label><input type="radio" name="dirsrch_domavailable"'.
4374: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4375: '</tr><tr>'.
4376: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
4377: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4378: '<input type="radio" name="dirsrch_domlocalonly"'.
4379: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4380: '<label><input type="radio" name="dirsrch_domlocalonly"'.
4381: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4382: '</tr>';
4383: $$rowtotal += 2;
1.26 raeburn 4384: }
1.25 raeburn 4385: return $datatable;
4386: }
4387:
1.28 raeburn 4388: sub print_contacts {
1.286 raeburn 4389: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 4390: my $datatable;
4391: my @contacts = ('adminemail','supportemail');
1.286 raeburn 4392: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340 raeburn 4393: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286 raeburn 4394: if ($position eq 'top') {
4395: if (ref($settings) eq 'HASH') {
4396: foreach my $item (@contacts) {
4397: if (exists($settings->{$item})) {
4398: $to{$item} = $settings->{$item};
4399: }
4400: }
4401: }
4402: } elsif ($position eq 'middle') {
4403: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350 raeburn 4404: 'updatesmail','idconflictsmail','hostipmail');
1.288 raeburn 4405: foreach my $type (@mailings) {
4406: $otheremails{$type} = '';
4407: }
1.340 raeburn 4408: } elsif ($position eq 'lower') {
4409: if (ref($settings) eq 'HASH') {
4410: if (ref($settings->{'lonstatus'}) eq 'HASH') {
4411: %lonstatus = %{$settings->{'lonstatus'}};
4412: }
4413: }
1.286 raeburn 4414: } else {
4415: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 4416: foreach my $type (@mailings) {
4417: $otheremails{$type} = '';
4418: }
1.286 raeburn 4419: $bccemails{'helpdeskmail'} = '';
4420: $bccemails{'otherdomsmail'} = '';
4421: $includestr{'helpdeskmail'} = '';
4422: $includestr{'otherdomsmail'} = '';
4423: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
4424: }
1.28 raeburn 4425: if (ref($settings) eq 'HASH') {
1.340 raeburn 4426: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4427: foreach my $type (@mailings) {
4428: if (exists($settings->{$type})) {
4429: if (ref($settings->{$type}) eq 'HASH') {
4430: foreach my $item (@contacts) {
4431: if ($settings->{$type}{$item}) {
4432: $checked{$type}{$item} = ' checked="checked" ';
4433: }
4434: }
4435: $otheremails{$type} = $settings->{$type}{'others'};
4436: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4437: $bccemails{$type} = $settings->{$type}{'bcc'};
4438: if ($settings->{$type}{'include'} ne '') {
4439: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4440: $includestr{$type} = &unescape($includestr{$type});
4441: }
4442: }
4443: }
4444: } elsif ($type eq 'lonstatusmail') {
4445: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
4446: }
1.28 raeburn 4447: }
4448: }
1.286 raeburn 4449: if ($position eq 'bottom') {
4450: foreach my $type (@mailings) {
4451: $bccemails{$type} = $settings->{$type}{'bcc'};
4452: if ($settings->{$type}{'include'} ne '') {
4453: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4454: $includestr{$type} = &unescape($includestr{$type});
4455: }
4456: }
4457: if (ref($settings->{'helpform'}) eq 'HASH') {
4458: if (ref($fields) eq 'ARRAY') {
4459: foreach my $field (@{$fields}) {
4460: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 4461: }
1.286 raeburn 4462: }
4463: if (exists($settings->{'helpform'}{'maxsize'})) {
4464: $maxsize = $settings->{'helpform'}{'maxsize'};
4465: } else {
1.289 raeburn 4466: $maxsize = '1.0';
1.286 raeburn 4467: }
4468: } else {
4469: if (ref($fields) eq 'ARRAY') {
4470: foreach my $field (@{$fields}) {
4471: $currfield{$field} = 'yes';
1.134 raeburn 4472: }
1.28 raeburn 4473: }
1.286 raeburn 4474: $maxsize = '1.0';
1.28 raeburn 4475: }
4476: }
4477: } else {
1.286 raeburn 4478: if ($position eq 'top') {
4479: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
4480: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
4481: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
4482: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 4483: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4484: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
4485: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
4486: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350 raeburn 4487: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4488: } elsif ($position eq 'bottom') {
4489: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
4490: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
4491: if (ref($fields) eq 'ARRAY') {
4492: foreach my $field (@{$fields}) {
4493: $currfield{$field} = 'yes';
4494: }
4495: }
4496: $maxsize = '1.0';
4497: }
1.28 raeburn 4498: }
4499: my ($titles,$short_titles) = &contact_titles();
4500: my $rownum = 0;
4501: my $css_class;
1.286 raeburn 4502: if ($position eq 'top') {
4503: foreach my $item (@contacts) {
4504: $css_class = $rownum%2?' class="LC_odd_row"':'';
4505: $datatable .= '<tr'.$css_class.'>'.
4506: '<td><span class="LC_nobreak">'.$titles->{$item}.
4507: '</span></td><td class="LC_right_item">'.
4508: '<input type="text" name="'.$item.'" value="'.
4509: $to{$item}.'" /></td></tr>';
4510: $rownum ++;
4511: }
1.315 raeburn 4512: } elsif ($position eq 'bottom') {
4513: $css_class = $rownum%2?' class="LC_odd_row"':'';
4514: $datatable .= '<tr'.$css_class.'>'.
4515: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
4516: &mt('(e-mail, subject, and description always shown)').
4517: '</td><td class="LC_left_item">';
4518: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
4519: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
4520: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
4521: foreach my $field (@{$fields}) {
4522: $datatable .= '<tr><td>'.$fieldtitles->{$field};
4523: if (($field eq 'screenshot') || ($field eq 'cc')) {
4524: $datatable .= ' '.&mt('(logged-in users)');
4525: }
4526: $datatable .='</td><td>';
4527: my $clickaction;
4528: if ($field eq 'screenshot') {
4529: $clickaction = ' onclick="screenshotSize(this);"';
4530: }
4531: if (ref($possoptions->{$field}) eq 'ARRAY') {
4532: foreach my $option (@{$possoptions->{$field}}) {
4533: my $checked;
4534: if ($currfield{$field} eq $option) {
4535: $checked = ' checked="checked"';
4536: }
4537: $datatable .= '<span class="LC_nobreak"><label>'.
4538: '<input type="radio" name="helpform_'.$field.'" '.
4539: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
4540: '</label></span>'.(' 'x2);
4541: }
4542: }
4543: if ($field eq 'screenshot') {
4544: my $display;
4545: if ($currfield{$field} eq 'no') {
4546: $display = ' style="display:none"';
4547: }
1.334 raeburn 4548: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315 raeburn 4549: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
4550: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
4551: }
4552: $datatable .= '</td></tr>';
4553: }
4554: $datatable .= '</table>';
4555: }
4556: $datatable .= '</td></tr>'."\n";
4557: $rownum ++;
4558: }
1.340 raeburn 4559: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4560: foreach my $type (@mailings) {
4561: $css_class = $rownum%2?' class="LC_odd_row"':'';
4562: $datatable .= '<tr'.$css_class.'>'.
4563: '<td><span class="LC_nobreak">'.
4564: $titles->{$type}.': </span></td>'.
4565: '<td class="LC_left_item">';
4566: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4567: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
4568: }
4569: $datatable .= '<span class="LC_nobreak">';
4570: foreach my $item (@contacts) {
4571: $datatable .= '<label>'.
4572: '<input type="checkbox" name="'.$type.'"'.
4573: $checked{$type}{$item}.
4574: ' value="'.$item.'" />'.$short_titles->{$item}.
4575: '</label> ';
4576: }
4577: $datatable .= '</span><br />'.&mt('Others').': '.
4578: '<input type="text" name="'.$type.'_others" '.
4579: 'value="'.$otheremails{$type}.'" />';
4580: my %locchecked;
4581: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4582: foreach my $loc ('s','b') {
4583: if ($includeloc{$type} eq $loc) {
4584: $locchecked{$loc} = ' checked="checked"';
4585: last;
4586: }
4587: }
4588: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
4589: '<input type="text" name="'.$type.'_bcc" '.
4590: 'value="'.$bccemails{$type}.'" /></fieldset>'.
4591: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4592: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4593: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286 raeburn 4594: '<span class="LC_nobreak">'.&mt('Location:').' '.
4595: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4596: (' 'x2).
4597: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4598: '</span></fieldset>';
4599: }
4600: $datatable .= '</td></tr>'."\n";
4601: $rownum ++;
4602: }
1.28 raeburn 4603: }
1.286 raeburn 4604: if ($position eq 'middle') {
4605: my %choices;
1.340 raeburn 4606: my $corelink = &core_link_msu();
4607: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286 raeburn 4608: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340 raeburn 4609: $corelink);
4610: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
4611: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286 raeburn 4612: my %defaultchecked = ('reporterrors' => 'on',
1.340 raeburn 4613: 'reportupdates' => 'on',
4614: 'reportstatus' => 'on');
1.286 raeburn 4615: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4616: \%choices,$rownum);
4617: $datatable .= $reports;
1.340 raeburn 4618: } elsif ($position eq 'lower') {
1.378 raeburn 4619: my (%current,%excluded,%weights);
1.340 raeburn 4620: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
4621: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.378 raeburn 4622: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.340 raeburn 4623: } else {
1.378 raeburn 4624: $current{'errorthreshold'} = $defaults->{'threshold'};
1.340 raeburn 4625: }
4626: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.378 raeburn 4627: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.340 raeburn 4628: } else {
1.378 raeburn 4629: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.340 raeburn 4630: }
4631: if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341 raeburn 4632: foreach my $type ('E','W','N','U') {
1.340 raeburn 4633: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
4634: $weights{$type} = $lonstatus{'weights'}{$type};
4635: } else {
4636: $weights{$type} = $defaults->{$type};
4637: }
4638: }
4639: } else {
1.341 raeburn 4640: foreach my $type ('E','W','N','U') {
1.340 raeburn 4641: $weights{$type} = $defaults->{$type};
4642: }
4643: }
4644: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
4645: if (@{$lonstatus{'excluded'}} > 0) {
4646: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
4647: }
4648: }
1.425 raeburn 4649: foreach my $item ('errorthreshold','errorsysmail') {
1.378 raeburn 4650: $css_class = $rownum%2?' class="LC_odd_row"':'';
4651: $datatable .= '<tr'.$css_class.'>'.
4652: '<td class="LC_left_item"><span class="LC_nobreak">'.
4653: $titles->{$item}.
4654: '</span></td><td class="LC_left_item">'.
4655: '<input type="text" name="'.$item.'" value="'.
4656: $current{$item}.'" size="5" /></td></tr>';
4657: $rownum ++;
4658: }
1.340 raeburn 4659: $css_class = $rownum%2?' class="LC_odd_row"':'';
4660: $datatable .= '<tr'.$css_class.'>'.
4661: '<td class="LC_left_item">'.
4662: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
4663: '</span></td><td class="LC_left_item"><table><tr>';
1.341 raeburn 4664: foreach my $type ('E','W','N','U') {
1.340 raeburn 4665: $datatable .= '<td>'.$names->{$type}.'<br />'.
4666: '<input type="text" name="errorweights_'.$type.'" value="'.
4667: $weights{$type}.'" size="5" /></td>';
4668: }
4669: $datatable .= '</tr></table></tr>';
4670: $rownum ++;
4671: $css_class = $rownum%2?' class="LC_odd_row"':'';
4672: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
4673: $titles->{'errorexcluded'}.'</td>'.
4674: '<td class="LC_left_item"><table>';
4675: my $numinrow = 4;
4676: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
4677: for (my $i=0; $i<@ids; $i++) {
4678: my $rem = $i%($numinrow);
4679: if ($rem == 0) {
4680: if ($i > 0) {
4681: $datatable .= '</tr>';
4682: }
4683: $datatable .= '<tr>';
4684: }
4685: my $check;
4686: if ($excluded{$ids[$i]}) {
4687: $check = ' checked="checked" ';
4688: }
4689: $datatable .= '<td class="LC_left_item">'.
4690: '<span class="LC_nobreak"><label>'.
4691: '<input type="checkbox" name="errorexcluded" '.
4692: 'value="'.$ids[$i].'"'.$check.' />'.
4693: $ids[$i].'</label></span></td>';
4694: }
4695: my $colsleft = $numinrow - @ids%($numinrow);
4696: if ($colsleft > 1 ) {
4697: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4698: ' </td>';
4699: } elsif ($colsleft == 1) {
4700: $datatable .= '<td class="LC_left_item"> </td>';
4701: }
4702: $datatable .= '</tr></table></td></tr>';
4703: $rownum ++;
1.286 raeburn 4704: } elsif ($position eq 'bottom') {
1.315 raeburn 4705: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4706: my (@posstypes,%usertypeshash);
4707: if (ref($types) eq 'ARRAY') {
4708: @posstypes = @{$types};
4709: }
4710: if (@posstypes) {
4711: if (ref($usertypes) eq 'HASH') {
4712: %usertypeshash = %{$usertypes};
4713: }
4714: my @overridden;
4715: my $numinrow = 4;
4716: if (ref($settings) eq 'HASH') {
4717: if (ref($settings->{'overrides'}) eq 'HASH') {
4718: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
4719: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
4720: push(@overridden,$key);
4721: foreach my $item (@contacts) {
4722: if ($settings->{'overrides'}{$key}{$item}) {
4723: $checked{'override_'.$key}{$item} = ' checked="checked" ';
4724: }
4725: }
4726: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
4727: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
4728: $includeloc{'override_'.$key} = '';
4729: $includestr{'override_'.$key} = '';
4730: if ($settings->{'overrides'}{$key}{'include'} ne '') {
1.425 raeburn 4731: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
1.315 raeburn 4732: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
4733: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
4734: }
1.286 raeburn 4735: }
4736: }
4737: }
1.315 raeburn 4738: }
4739: my $customclass = 'LC_helpdesk_override';
4740: my $optionsprefix = 'LC_options_helpdesk_';
4741:
4742: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
4743: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
4744: $numinrow,$othertitle,'overrides',
4745: \$rownum,$onclicktypes,$customclass);
4746: $rownum ++;
4747: $usertypeshash{'default'} = $othertitle;
4748: foreach my $status (@posstypes) {
4749: my $css_class;
4750: if ($rownum%2) {
4751: $css_class = 'LC_odd_row ';
4752: }
4753: $css_class .= $customclass;
4754: my $rowid = $optionsprefix.$status;
4755: my $hidden = 1;
4756: my $currstyle = 'display:none';
4757: if (grep(/^\Q$status\E$/,@overridden)) {
4758: $currstyle = 'display:table-row';
4759: $hidden = 0;
4760: }
4761: my $key = 'override_'.$status;
4762: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
4763: $includeloc{$key},$includestr{$key},$status,$rowid,
4764: $usertypeshash{$status},$css_class,$currstyle,
4765: \@contacts,$short_titles);
4766: unless ($hidden) {
4767: $rownum ++;
1.286 raeburn 4768: }
4769: }
1.134 raeburn 4770: }
1.28 raeburn 4771: }
1.30 raeburn 4772: $$rowtotal += $rownum;
1.28 raeburn 4773: return $datatable;
4774: }
4775:
1.340 raeburn 4776: sub core_link_msu {
4777: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
4778: &mt('LON-CAPA core group - MSU'),600,500);
4779: }
4780:
1.315 raeburn 4781: sub overridden_helpdesk {
4782: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
4783: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
4784: my $class = 'LC_left_item';
4785: if ($css_class) {
4786: $css_class = ' class="'.$css_class.'"';
4787: }
4788: if ($rowid) {
4789: $rowid = ' id="'.$rowid.'"';
4790: }
4791: if ($rowstyle) {
4792: $rowstyle = ' style="'.$rowstyle.'"';
4793: }
4794: my ($output,$description);
4795: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
4796: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
4797: "<td>$description</td>\n".
4798: '<td class="'.$class.'" colspan="2">'.
4799: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
4800: '<span class="LC_nobreak">';
4801: if (ref($contacts) eq 'ARRAY') {
4802: foreach my $item (@{$contacts}) {
4803: my $check;
4804: if (ref($checked) eq 'HASH') {
4805: $check = $checked->{$item};
4806: }
4807: my $title;
4808: if (ref($short_titles) eq 'HASH') {
1.425 raeburn 4809: $title = $short_titles->{$item};
1.315 raeburn 4810: }
4811: $output .= '<label>'.
4812: '<input type="checkbox" name="override_'.$type.'"'.$check.
4813: ' value="'.$item.'" />'.$title.'</label> ';
4814: }
4815: }
4816: $output .= '</span><br />'.&mt('Others').': '.
4817: '<input type="text" name="override_'.$type.'_others" '.
4818: 'value="'.$otheremails.'" />';
4819: my %locchecked;
4820: foreach my $loc ('s','b') {
4821: if ($includeloc eq $loc) {
4822: $locchecked{$loc} = ' checked="checked"';
4823: last;
4824: }
4825: }
4826: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4827: '<input type="text" name="override_'.$type.'_bcc" '.
4828: 'value="'.$bccemails.'" /></fieldset>'.
4829: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4830: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4831: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315 raeburn 4832: '<span class="LC_nobreak">'.&mt('Location:').' '.
4833: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4834: (' 'x2).
4835: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4836: '</span></fieldset>'.
4837: '</td></tr>'."\n";
4838: return $output;
4839: }
4840:
1.286 raeburn 4841: sub contacts_javascript {
4842: return <<"ENDSCRIPT";
4843:
4844: <script type="text/javascript">
4845: // <![CDATA[
4846:
4847: function screenshotSize(field) {
4848: if (document.getElementById('help_screenshotsize')) {
4849: if (field.value == 'no') {
1.289 raeburn 4850: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 4851: } else {
4852: document.getElementById('help_screenshotsize').style.display="";
4853: }
4854: }
4855: return;
4856: }
4857:
1.315 raeburn 4858: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4859: if (form.elements[checkbox].length != undefined) {
4860: var count = 0;
4861: if (docount) {
4862: for (var i=0; i<form.elements[checkbox].length; i++) {
4863: if (form.elements[checkbox][i].checked) {
4864: count ++;
4865: }
4866: }
4867: }
4868: for (var i=0; i<form.elements[checkbox].length; i++) {
4869: var type = form.elements[checkbox][i].value;
4870: if (document.getElementById(prefix+type)) {
4871: if (form.elements[checkbox][i].checked) {
4872: document.getElementById(prefix+type).style.display = 'table-row';
4873: if (count % 2 == 1) {
4874: document.getElementById(prefix+type).className = target+' LC_odd_row';
4875: } else {
4876: document.getElementById(prefix+type).className = target;
4877: }
4878: count ++;
4879: } else {
4880: document.getElementById(prefix+type).style.display = 'none';
4881: }
4882: }
4883: }
4884: }
4885: return;
4886: }
4887:
1.286 raeburn 4888: // ]]>
4889: </script>
4890:
4891: ENDSCRIPT
4892: }
4893:
1.118 jms 4894: sub print_helpsettings {
1.282 raeburn 4895: my ($position,$dom,$settings,$rowtotal) = @_;
4896: my $confname = $dom.'-domainconfig';
1.285 raeburn 4897: my $formname = 'display';
1.168 raeburn 4898: my ($datatable,$itemcount);
1.282 raeburn 4899: if ($position eq 'top') {
4900: $itemcount = 1;
4901: my (%choices,%defaultchecked,@toggles);
4902: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4903: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4904: &mt('LON-CAPA bug tracker'),600,500));
4905: %defaultchecked = ('submitbugs' => 'on');
4906: @toggles = ('submitbugs');
4907: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4908: \%choices,$itemcount);
4909: $$rowtotal ++;
4910: } else {
4911: my $css_class;
4912: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 4913: my (%customroles,%ordered,%current);
1.301 raeburn 4914: if (ref($settings) eq 'HASH') {
4915: if (ref($settings->{'adhoc'}) eq 'HASH') {
4916: %current = %{$settings->{'adhoc'}};
4917: }
1.285 raeburn 4918: }
4919: my $count = 0;
4920: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 4921: if ($key=~/^rolesdef\_(\w+)$/) {
4922: my $rolename = $1;
1.285 raeburn 4923: my (%privs,$order);
1.282 raeburn 4924: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4925: $customroles{$rolename} = \%privs;
1.285 raeburn 4926: if (ref($current{$rolename}) eq 'HASH') {
4927: $order = $current{$rolename}{'order'};
4928: }
4929: if ($order eq '') {
4930: $order = $count;
4931: }
4932: $ordered{$order} = $rolename;
4933: $count++;
4934: }
4935: }
4936: my $maxnum = scalar(keys(%ordered));
4937: my @roles_by_num = ();
4938: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4939: push(@roles_by_num,$item);
4940: }
4941: my $context = 'domprefs';
4942: my $crstype = 'Course';
4943: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 4944: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 4945: my ($numstatustypes,@jsarray);
4946: if (ref($types) eq 'ARRAY') {
4947: if (@{$types} > 0) {
4948: $numstatustypes = scalar(@{$types});
4949: push(@accesstypes,'status');
4950: @jsarray = ('bystatus');
1.282 raeburn 4951: }
4952: }
1.290 raeburn 4953: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 4954: if (keys(%domhelpdesk)) {
4955: push(@accesstypes,('inc','exc'));
4956: push(@jsarray,('notinc','notexc'));
4957: }
4958: my $hiddenstr = join("','",@jsarray);
1.282 raeburn 4959: my $context = 'domprefs';
4960: my $crstype = 'Course';
1.285 raeburn 4961: my $prefix = 'helproles_';
4962: my $add_class = 'LC_hidden';
4963: foreach my $num (@roles_by_num) {
4964: my $role = $ordered{$num};
4965: my ($desc,$access,@statuses);
4966: if (ref($current{$role}) eq 'HASH') {
4967: $desc = $current{$role}{'desc'};
4968: $access = $current{$role}{'access'};
4969: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4970: @statuses = @{$current{$role}{'insttypes'}};
4971: }
4972: }
4973: if ($desc eq '') {
4974: $desc = $role;
4975: }
4976: my $identifier = 'custhelp'.$num;
1.282 raeburn 4977: my %full=();
4978: my %levels= (
4979: course => {},
4980: domain => {},
4981: system => {},
4982: );
4983: my %levelscurrent=(
4984: course => {},
4985: domain => {},
4986: system => {},
4987: );
4988: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4989: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4990: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 4991: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 4992: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 4993: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4994: for (my $k=0; $k<=$maxnum; $k++) {
4995: my $vpos = $k+1;
4996: my $selstr;
4997: if ($k == $num) {
4998: $selstr = ' selected="selected" ';
4999: }
5000: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5001: }
5002: $datatable .= '</select>'.(' 'x2).
5003: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
5004: '</td>'.
5005: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
5006: &mt('Name shown to users:').
5007: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
5008: '</fieldset>'.
5009: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
5010: $othertitle,$usertypes,$types,\%domhelpdesk).
5011: '<fieldset>'.
5012: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 5013: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 5014: \%levelscurrent,$identifier,
5015: 'LC_hidden',$prefix.$num.'_privs').
5016: '</fieldset></td>';
1.282 raeburn 5017: $itemcount ++;
5018: }
5019: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5020: my $newcust = 'custhelp'.$count;
5021: my (%privs,%levelscurrent);
5022: my %full=();
5023: my %levels= (
5024: course => {},
5025: domain => {},
5026: system => {},
5027: );
5028: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
5029: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 5030: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 5031: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 5032: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
5033: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
5034: for (my $k=0; $k<$maxnum+1; $k++) {
5035: my $vpos = $k+1;
5036: my $selstr;
5037: if ($k == $maxnum) {
5038: $selstr = ' selected="selected" ';
5039: }
5040: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5041: }
5042: $datatable .= '</select> '."\n".
1.282 raeburn 5043: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
5044: '</label></span></td>'.
1.285 raeburn 5045: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
5046: '<span class="LC_nobreak">'.
5047: &mt('Internal name:').
5048: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
5049: '</span>'.(' 'x4).
5050: '<span class="LC_nobreak">'.
5051: &mt('Name shown to users:').
5052: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
5053: '</span></fieldset>'.
5054: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
5055: $usertypes,$types,\%domhelpdesk).
5056: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 5057: &Apache::lonuserutils::custom_role_header($context,$crstype,
5058: \@templateroles,$newcust).
5059: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
5060: \%levelscurrent,$newcust).
1.334 raeburn 5061: '</fieldset>'.
5062: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
5063: '</td></tr>';
1.282 raeburn 5064: $count ++;
5065: $$rowtotal += $count;
5066: }
1.166 raeburn 5067: return $datatable;
1.121 raeburn 5068: }
5069:
1.285 raeburn 5070: sub adhocbutton {
5071: my ($prefix,$num,$field,$visibility) = @_;
5072: my %lt = &Apache::lonlocal::texthash(
5073: show => 'Show details',
5074: hide => 'Hide details',
5075: );
5076: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
5077: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
5078: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
5079: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
5080: }
5081:
5082: sub helpsettings_javascript {
5083: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
5084: return unless(ref($roles_by_num) eq 'ARRAY');
5085: my %html_js_lt = &Apache::lonlocal::texthash(
5086: show => 'Show details',
5087: hide => 'Hide details',
5088: );
5089: &html_escape(\%html_js_lt);
5090: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
5091: return <<"ENDSCRIPT";
5092: <script type="text/javascript">
5093: // <![CDATA[
5094:
5095: function reorderHelpRoles(form,item) {
5096: var changedVal;
5097: $jstext
5098: var newpos = 'helproles_${total}_pos';
5099: var maxh = 1 + $total;
5100: var current = new Array();
5101: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5102: if (item == newpos) {
5103: changedVal = newitemVal;
5104: } else {
5105: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5106: current[newitemVal] = newpos;
5107: }
5108: for (var i=0; i<helproles.length; i++) {
5109: var elementName = 'helproles_'+helproles[i]+'_pos';
5110: if (elementName != item) {
5111: if (form.elements[elementName]) {
5112: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5113: current[currVal] = elementName;
5114: }
5115: }
5116: }
5117: var oldVal;
5118: for (var j=0; j<maxh; j++) {
5119: if (current[j] == undefined) {
5120: oldVal = j;
5121: }
5122: }
5123: if (oldVal < changedVal) {
5124: for (var k=oldVal+1; k<=changedVal ; k++) {
5125: var elementName = current[k];
5126: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5127: }
5128: } else {
5129: for (var k=changedVal; k<oldVal; k++) {
5130: var elementName = current[k];
5131: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5132: }
5133: }
5134: return;
5135: }
5136:
5137: function helpdeskAccess(num) {
5138: var curraccess = null;
5139: if (document.$formname.elements['helproles_'+num+'_access'].length) {
5140: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
5141: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
5142: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
5143: }
5144: }
5145: }
5146: var shown = Array();
5147: var hidden = Array();
5148: if (curraccess == 'none') {
5149: hidden = Array('$hiddenstr');
5150: } else {
5151: if (curraccess == 'status') {
5152: shown = Array('bystatus');
5153: hidden = Array('notinc','notexc');
5154: } else {
5155: if (curraccess == 'exc') {
5156: shown = Array('notexc');
5157: hidden = Array('notinc','bystatus');
5158: }
5159: if (curraccess == 'inc') {
5160: shown = Array('notinc');
5161: hidden = Array('notexc','bystatus');
5162: }
1.293 raeburn 5163: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 5164: hidden = Array('notinc','notexc','bystatus');
5165: }
5166: }
5167: }
5168: if (hidden.length > 0) {
5169: for (var i=0; i<hidden.length; i++) {
5170: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
5171: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
5172: }
5173: }
5174: }
5175: if (shown.length > 0) {
5176: for (var i=0; i<shown.length; i++) {
5177: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
5178: if (shown[i] == 'privs') {
5179: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
5180: } else {
5181: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
5182: }
5183: }
5184: }
5185: }
5186: return;
5187: }
5188:
5189: function toggleHelpdeskItem(num,field) {
5190: if (document.getElementById('helproles_'+num+'_'+field)) {
5191: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 5192: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 5193: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
5194: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5195: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
5196: }
5197: } else {
5198: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
5199: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5200: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
5201: }
5202: }
5203: }
5204: return;
5205: }
5206:
5207: // ]]>
5208: </script>
5209:
5210: ENDSCRIPT
5211: }
5212:
5213: sub helpdeskroles_access {
5214: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
5215: $usertypes,$types,$domhelpdesk) = @_;
5216: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
5217: my %lt = &Apache::lonlocal::texthash(
5218: 'rou' => 'Role usage',
5219: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 5220: 'all' => 'All with domain helpdesk or helpdesk assistant role',
5221: 'dh' => 'All with domain helpdesk role',
5222: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 5223: 'none' => 'None',
5224: 'status' => 'Determined based on institutional status',
5225: 'inc' => 'Include all, but exclude specific personnel',
5226: 'exc' => 'Exclude all, but include specific personnel',
5227: );
5228: my %usecheck = (
5229: all => ' checked="checked"',
5230: );
5231: my %displaydiv = (
5232: status => 'none',
5233: inc => 'none',
5234: exc => 'none',
5235: priv => 'block',
5236: );
5237: my $output;
5238: if (ref($current) eq 'HASH') {
5239: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
5240: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
5241: $usecheck{$current->{access}} = $usecheck{'all'};
5242: delete($usecheck{'all'});
5243: if ($current->{access} =~ /^(status|inc|exc)$/) {
5244: my $access = $1;
5245: $displaydiv{$access} = 'inline';
5246: } elsif ($current->{access} eq 'none') {
5247: $displaydiv{'priv'} = 'none';
5248: }
5249: }
5250: }
5251: }
5252: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
5253: '<p>'.$lt{'whi'}.'</p>';
5254: foreach my $access (@{$accesstypes}) {
5255: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
5256: ' onclick="helpdeskAccess('."'$num'".');" />'.
5257: $lt{$access}.'</label>';
5258: if ($access eq 'status') {
5259: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
5260: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
5261: $othertitle,$usertypes,$types).
5262: '</div>';
5263: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
5264: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
5265: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5266: '</div>';
5267: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
5268: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
5269: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5270: '</div>';
5271: }
5272: $output .= '</p>';
5273: }
5274: $output .= '</fieldset>';
5275: return $output;
5276: }
5277:
1.121 raeburn 5278: sub radiobutton_prefs {
1.192 raeburn 5279: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.385 raeburn 5280: $additional,$align,$firstval) = @_;
1.121 raeburn 5281: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
5282: (ref($choices) eq 'HASH'));
5283:
1.170 raeburn 5284: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 5285:
5286: foreach my $item (@{$toggles}) {
5287: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 5288: $checkedon{$item} = ' checked="checked" ';
5289: $checkedoff{$item} = ' ';
1.121 raeburn 5290: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 5291: $checkedoff{$item} = ' checked="checked" ';
5292: $checkedon{$item} = ' ';
5293: }
5294: }
5295: if (ref($settings) eq 'HASH') {
1.121 raeburn 5296: foreach my $item (@{$toggles}) {
1.118 jms 5297: if ($settings->{$item} eq '1') {
5298: $checkedon{$item} = ' checked="checked" ';
5299: $checkedoff{$item} = ' ';
5300: } elsif ($settings->{$item} eq '0') {
5301: $checkedoff{$item} = ' checked="checked" ';
5302: $checkedon{$item} = ' ';
5303: }
5304: }
1.121 raeburn 5305: }
1.192 raeburn 5306: if ($onclick) {
5307: $onclick = ' onclick="'.$onclick.'"';
5308: }
1.121 raeburn 5309: foreach my $item (@{$toggles}) {
1.118 jms 5310: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 5311: $datatable .=
1.306 raeburn 5312: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 5313: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 5314: '</span></td>';
5315: if ($align eq 'left') {
5316: $datatable .= '<td class="LC_left_item">';
5317: } else {
5318: $datatable .= '<td class="LC_right_item">';
5319: }
1.385 raeburn 5320: $datatable .= '<span class="LC_nobreak">';
5321: if ($firstval eq 'no') {
5322: $datatable .=
5323: '<label><input type="radio" name="'.
5324: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
5325: '</label> <label><input type="radio" name="'.$item.'" '.
5326: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
5327: } else {
5328: $datatable .=
5329: '<label><input type="radio" name="'.
5330: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
5331: '</label> <label><input type="radio" name="'.$item.'" '.
5332: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
5333: }
5334: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 5335: $itemcount ++;
1.121 raeburn 5336: }
5337: return ($datatable,$itemcount);
5338: }
5339:
1.267 raeburn 5340: sub print_ltitools {
1.421 raeburn 5341: my ($position,$dom,$settings,$rowtotal) = @_;
5342: my (%rules,%encrypt,%privkeys,%linkprot);
1.267 raeburn 5343: if (ref($settings) eq 'HASH') {
1.421 raeburn 5344: if ($position eq 'top') {
5345: if (exists($settings->{'encrypt'})) {
5346: if (ref($settings->{'encrypt'}) eq 'HASH') {
5347: foreach my $key (keys(%{$settings->{'encrypt'}})) {
5348: $encrypt{'toolsec_'.$key} = $settings->{'encrypt'}{$key};
1.324 raeburn 5349: }
5350: }
1.267 raeburn 5351: }
1.421 raeburn 5352: if (exists($settings->{'private'})) {
5353: if (ref($settings->{'private'}) eq 'HASH') {
5354: if (ref($settings->{'private'}) eq 'HASH') {
5355: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
5356: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
1.267 raeburn 5357: }
5358: }
5359: }
5360: }
1.421 raeburn 5361: } elsif ($position eq 'middle') {
5362: if (exists($settings->{'rules'})) {
5363: if (ref($settings->{'rules'}) eq 'HASH') {
5364: %rules = %{$settings->{'rules'}};
1.273 raeburn 5365: }
5366: }
1.421 raeburn 5367: } else {
5368: foreach my $key ('encrypt','private','rules') {
5369: if (exists($settings->{$key})) {
5370: delete($settings->{$key});
1.267 raeburn 5371: }
5372: }
5373: }
5374: }
1.421 raeburn 5375: my $datatable;
5376: my $itemcount = 1;
5377: if ($position eq 'top') {
5378: $datatable = &secrets_form($dom,'toolsec',\%encrypt,\%privkeys,$rowtotal);
5379: } elsif ($position eq 'middle') {
5380: $datatable = &password_rules('toolsecrets',\$itemcount,\%rules);
5381: $$rowtotal += $itemcount;
5382: } else {
5383: $datatable = &Apache::courseprefs::print_ltitools($dom,'',$settings,\$rowtotal,'','','domain');
1.267 raeburn 5384: }
5385: return $datatable;
5386: }
5387:
5388: sub ltitools_names {
5389: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 5390: 'title' => 'Title',
5391: 'version' => 'Version',
5392: 'msgtype' => 'Message Type',
1.323 raeburn 5393: 'sigmethod' => 'Signature Method',
1.296 raeburn 5394: 'url' => 'URL',
5395: 'key' => 'Key',
1.322 raeburn 5396: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 5397: 'secret' => 'Secret',
1.425 raeburn 5398: 'icon' => 'Icon',
1.324 raeburn 5399: 'user' => 'User',
1.296 raeburn 5400: 'fullname' => 'Full Name',
5401: 'firstname' => 'First Name',
5402: 'lastname' => 'Last Name',
5403: 'email' => 'E-mail',
5404: 'roles' => 'Role',
1.298 raeburn 5405: 'window' => 'Window',
5406: 'tab' => 'Tab',
1.296 raeburn 5407: 'iframe' => 'iFrame',
5408: 'height' => 'Height',
5409: 'width' => 'Width',
5410: 'linktext' => 'Default Link Text',
5411: 'explanation' => 'Default Explanation',
5412: 'passback' => 'Tool can return grades:',
5413: 'roster' => 'Tool can retrieve roster:',
5414: 'crstarget' => 'Display target',
5415: 'crslabel' => 'Course label',
1.425 raeburn 5416: 'crstitle' => 'Course title',
1.296 raeburn 5417: 'crslinktext' => 'Link Text',
5418: 'crsexplanation' => 'Explanation',
1.318 raeburn 5419: 'crsappend' => 'Provider URL',
1.267 raeburn 5420: );
5421: return %lt;
5422: }
5423:
1.421 raeburn 5424: sub secrets_form {
5425: my ($dom,$context,$encrypt,$privkeys,$rowtotal) = @_;
5426: my @ids=&Apache::lonnet::current_machine_ids();
5427: my %servers = &Apache::lonnet::get_servers($dom,'library');
5428: my $primary = &Apache::lonnet::domain($dom,'primary');
5429: my ($css_class,$extra,$numshown,$itemcount,$output);
5430: $itemcount = 0;
5431: foreach my $hostid (sort(keys(%servers))) {
5432: my ($showextra,$divsty,$switch);
5433: if ($hostid eq $primary) {
5434: if ($context eq 'ltisec') {
5435: if (($encrypt->{'ltisec_consumers'}) || ($encrypt->{'ltisec_domlinkprot'})) {
5436: $showextra = 1;
5437: }
5438: if ($encrypt->{'ltisec_crslinkprot'}) {
5439: $showextra = 1;
5440: }
5441: } else {
5442: if (($encrypt->{'toolsec_crs'}) || ($encrypt->{'toolsec_dom'})) {
5443: $showextra = 1;
5444: }
5445: }
5446: unless (grep(/^\Q$hostid\E$/,@ids)) {
5447: $switch = 1;
5448: }
5449: if ($showextra) {
5450: $numshown ++;
5451: $divsty = 'display:inline-block';
5452: } else {
5453: $divsty = 'display:none';
5454: }
5455: $extra .= '<fieldset id="'.$context.'_info_'.$hostid.'" style="'.$divsty.'">'.
5456: '<legend>'.$hostid.'</legend>';
5457: if ($switch) {
5458: my $switchserver = '<a href="/adm/switchserver?otherserver='.$hostid.'&role='.
5459: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
5460: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
5461: if (exists($privkeys->{$hostid})) {
5462: $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" />'.
5463: '<span class="LC_nobreak">'.
5464: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5465: '<span class="LC_nobreak">'.&mt('Change?').
5466: '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5467: (' 'x2).
5468: '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5469: '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5470: '<span class="LC_nobreak"> - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5471: '</span></div>';
5472: } else {
5473: $extra .= '<span class="LC_nobreak">'.
5474: &mt('Key required').' - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5475: '</span>'."\n";
5476: }
5477: } elsif (exists($privkeys->{$hostid})) {
5478: $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" /><span class="LC_nobreak">'.
5479: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5480: '<span class="LC_nobreak">'.&mt('Change?').
5481: '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5482: (' 'x2).
5483: '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5484: '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5485: '<span class="LC_nobreak">'.&mt('New Key').':'.
5486: '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5487: '<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>'.
5488: '</span></div>';
5489: } else {
5490: $extra .= '<span class="LC_nobreak">'.&mt('Encryption Key').':'.
5491: '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5492: '<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>';
5493: }
5494: $extra .= '</fieldset>';
5495: }
5496: }
5497: my (%choices,@toggles,%defaultchecked);
5498: if ($context eq 'ltisec') {
5499: %choices = &Apache::lonlocal::texthash (
5500: ltisec_crslinkprot => 'Encrypt stored link protection secrets defined in courses',
5501: ltisec_domlinkprot => 'Encrypt stored link protection secrets defined in domain',
5502: ltisec_consumers => 'Encrypt stored consumer secrets defined in domain',
5503: );
5504: @toggles = qw(ltisec_crslinkprot ltisec_domlinkprot ltisec_consumers);
5505: %defaultchecked = (
5506: 'ltisec_crslinkprot' => 'off',
5507: 'ltisec_domlinkprot' => 'off',
5508: 'ltisec_consumers' => 'off',
5509: );
5510: } else {
5511: %choices = &Apache::lonlocal::texthash (
5512: toolsec_crs => 'Encrypt stored external tool secrets defined in courses',
5513: toolsec_dom => 'Encrypt stored external tool secrets defined in domain',
5514: );
5515: @toggles = qw(toolsec_crs toolsec_dom);
5516: %defaultchecked = (
5517: 'toolsec_crs' => 'off',
5518: 'toolsec_dom' => 'off',
5519: );
5520: }
5521: my ($onclick,$itemcount);
5522: $onclick = 'javascript:toggleLTIEncKey(this.form,'."'$context'".');';
5523: ($output,$itemcount) = &radiobutton_prefs($encrypt,\@toggles,\%defaultchecked,
5524: \%choices,$itemcount,$onclick,'','left','no');
5525:
5526: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5527: my $noprivkeysty = 'display:inline-block';
5528: if ($numshown) {
5529: $noprivkeysty = 'display:none';
5530: }
5531: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.&mt('Encryption Key(s)').'</td>'.
5532: '<td><div id="'.$context.'_noprivkey" style="'.$noprivkeysty.'" >'.
5533: '<span class="LC_nobreak">'.&mt('Not in use').'</span></div>'.
5534: $extra.
5535: '</td></tr>';
5536: $itemcount ++;
5537: $$rowtotal += $itemcount;
5538: return $output;
5539: }
5540:
1.372 raeburn 5541: sub print_proctoring {
5542: my ($dom,$settings,$rowtotal) = @_;
5543: my $itemcount = 1;
5544: my (%ordered,%providernames,%current,%currentdef);
5545: my $confname = $dom.'-domainconfig';
5546: my $switchserver = &check_switchserver($dom,$confname);
5547: if (ref($settings) eq 'HASH') {
5548: foreach my $item (keys(%{$settings})) {
5549: if (ref($settings->{$item}) eq 'HASH') {
5550: my $num = $settings->{$item}{'order'};
5551: $ordered{$num} = $item;
5552: }
5553: }
5554: } else {
5555: %ordered = (
5556: 1 => 'proctorio',
5557: 2 => 'examity',
5558: );
5559: }
5560: %providernames = &proctoring_providernames();
5561: my $maxnum = scalar(keys(%ordered));
5562: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
5563: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
5564: if (ref($requref) eq 'HASH') {
5565: %requserfields = %{$requref};
5566: }
5567: if (ref($opturef) eq 'HASH') {
5568: %optuserfields = %{$opturef};
5569: }
5570: if (ref($defref) eq 'HASH') {
5571: %defaults = %{$defref};
5572: }
5573: if (ref($extref) eq 'HASH') {
5574: %extended = %{$extref};
5575: }
5576: if (ref($crsref) eq 'HASH') {
5577: %crsconf = %{$crsref};
5578: }
5579: if (ref($rolesref) eq 'ARRAY') {
5580: @courseroles = @{$rolesref};
5581: }
5582: if (ref($ltiref) eq 'ARRAY') {
5583: @ltiroles = @{$ltiref};
5584: }
5585: my $datatable;
5586: my $css_class;
5587: if (keys(%ordered)) {
5588: my @items = sort { $a <=> $b } keys(%ordered);
5589: for (my $i=0; $i<@items; $i++) {
5590: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5591: my $provider = $ordered{$items[$i]};
5592: my $optionsty = 'none';
5593: my ($available,$version,$lifetime,$imgsrc,$userincdom,$showroles,
5594: %checkedfields,%rolemaps,%inuse,%crsconfig,%current);
5595: if (ref($settings) eq 'HASH') {
5596: if (ref($settings->{$provider}) eq 'HASH') {
5597: %current = %{$settings->{$provider}};
5598: if ($current{'available'}) {
5599: $optionsty = 'block';
5600: $available = 1;
5601: }
5602: if ($current{'lifetime'} =~ /^\d+$/) {
5603: $lifetime = $current{'lifetime'};
5604: }
5605: if ($current{'version'} =~ /^\d+\.\d+$/) {
5606: $version = $current{'version'};
5607: }
5608: if ($current{'image'} ne '') {
5609: $imgsrc = '<img src="'.$current{'image'}.'" alt="'.&mt('Proctoring service icon').'" />';
5610: }
5611: if (ref($current{'fields'}) eq 'ARRAY') {
5612: map { $checkedfields{$_} = 1; } @{$current{'fields'}};
5613: }
5614: $userincdom = $current{'incdom'};
5615: if (ref($current{'roles'}) eq 'HASH') {
5616: %rolemaps = %{$current{'roles'}};
5617: $checkedfields{'roles'} = 1;
5618: }
5619: if (ref($current{'defaults'}) eq 'ARRAY') {
5620: foreach my $val (@{$current{'defaults'}}) {
5621: if (grep(/^\Q$val\E$/,@{$defaults{$provider}})) {
5622: $inuse{$val} = 1;
5623: } else {
5624: foreach my $poss (keys(%{$extended{$provider}})) {
5625: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5626: if (grep(/^\Q$val\E$/,@{$extended{$provider}{$poss}})) {
5627: $inuse{$poss} = $val;
5628: last;
5629: }
5630: }
5631: }
5632: }
5633: }
5634: } elsif (ref($current{'defaults'}) eq 'HASH') {
5635: foreach my $key (keys(%{$current{'defaults'}})) {
5636: my $currval = $current{'defaults'}{$key};
5637: if (grep(/^\Q$key\E$/,@{$defaults{$provider}})) {
5638: $inuse{$key} = 1;
5639: } else {
5640: my $match;
5641: foreach my $poss (keys(%{$extended{$provider}})) {
5642: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5643: if (grep(/^\Q$key\E$/,@{$extended{$provider}{$poss}})) {
5644: $inuse{$poss} = $key;
5645: last;
5646: }
5647: } elsif (ref($extended{$provider}{$poss}) eq 'HASH') {
5648: foreach my $inner (sort(keys(%{$extended{$provider}{$poss}}))) {
5649: if (ref($extended{$provider}{$poss}{$inner}) eq 'ARRAY') {
5650: if (grep(/^\Q$currval\E$/,@{$extended{$provider}{$poss}{$inner}})) {
5651: $currentdef{$inner} = $currval;
5652: $match = 1;
5653: last;
5654: }
5655: } elsif ($inner eq $key) {
5656: $currentdef{$key} = $currval;
5657: $match = 1;
5658: last;
5659: }
5660: }
5661: }
5662: last if ($match);
5663: }
5664: }
5665: }
5666: }
5667: if (ref($current{'crsconf'}) eq 'ARRAY') {
5668: map { $crsconfig{$_} = 1; } @{$current{'crsconf'}};
5669: }
5670: }
5671: }
5672: my %lt = &proctoring_titles($provider);
5673: my %fieldtitles = &proctoring_fieldtitles($provider);
5674: my $onclickavailable = ' onclick="toggleProctoring(this.form,'."'$provider'".');"';
5675: my %checkedavailable = (
5676: yes => '',
5677: no => ' checked="checked"',
5678: );
5679: if ($available) {
5680: $checkedavailable{'yes'} = $checkedavailable{'no'};
5681: $checkedavailable{'no'} = '';
5682: }
5683: my $chgstr = ' onchange="javascript:reorderProctoring(this.form,'."'proctoring_pos_".$provider."'".');"';
5684: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5685: .'<select name="proctoring_pos_'.$provider.'"'.$chgstr.'>';
5686: for (my $k=0; $k<$maxnum; $k++) {
5687: my $vpos = $k+1;
5688: my $selstr;
5689: if ($k == $i) {
5690: $selstr = ' selected="selected" ';
5691: }
5692: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5693: }
5694: if ($version eq '') {
5695: if ($provider eq 'proctorio') {
5696: $version = '1.0';
5697: } elsif ($provider eq 'examity') {
5698: $version = '1.1';
5699: }
5700: }
5701: if ($lifetime eq '') {
5702: $lifetime = '300';
5703: }
5704: $datatable .=
5705: '</select>'.(' 'x2).'<b>'.$providernames{$provider}.'</b></span><br />'.
5706: '<span class="LC_nobreak">'.$lt{'avai'}.' '.
5707: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="1"'.$onclickavailable.$checkedavailable{yes}.' />'.&mt('Yes').'</label> '."\n".
5708: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="0"'.$onclickavailable.$checkedavailable{no}.' />'.&mt('No').'</label></span>'."\n".
5709: '</td>'.
5710: '<td colspan="2">'.
5711: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'base'}.'</legend>'.
5712: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="proctoring_'.$provider.'_version">'.
5713: '<option value="'.$version.'" selected="selected">'.$version.'</option></select></span> '."\n".
5714: (' 'x2).
5715: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="proctoring_'.$provider.'_sigmethod">'.
5716: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5717: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
5718: (' 'x2).
5719: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="proctoring_'.$provider.'_lifetime" value="'.$lifetime.'" /></span> '."\n".
5720: '<br />'.
5721: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="proctoring_'.$provider.'_url" value="'.$current{'url'}.'" /></span> '."\n".
5722: '<br />'.
5723: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="proctoring_'.$provider.'_key" value="'.$current{'key'}.'" /></span> '."\n".
5724: (' 'x2).
5725: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="proctoring_'.$provider.'_secret" value="'.$current{'secret'}.'" />'.
5726: '<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";
5727: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
5728: if ($imgsrc) {
5729: $datatable .= $imgsrc.
5730: '<label><input type="checkbox" name="proctoring_image_del"'.
5731: ' value="'.$provider.'" />'.&mt('Delete?').'</label></span> '.
5732: '<span class="LC_nobreak"> '.&mt('Replace:');
5733: }
5734: $datatable .= ' ';
5735: if ($switchserver) {
5736: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5737: } else {
5738: $datatable .= '<input type="file" name="proctoring_image_'.$provider.'" value="" />';
5739: }
5740: unless ($imgsrc) {
5741: $datatable .= '<br />('.&mt('if larger than 21x21 pixels, image will be scaled').')';
5742: }
5743: $datatable .= '</fieldset>'."\n";
5744: if (ref($requserfields{$provider}) eq 'ARRAY') {
5745: if (@{$requserfields{$provider}} > 0) {
5746: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'requ'}.'</legend>';
5747: foreach my $field (@{$requserfields{$provider}}) {
5748: $datatable .= '<span class="LC_nobreak">'.
5749: '<label><input type="checkbox" name="proctoring_reqd_'.$provider.'" value="'.$field.'" checked="checked" disabled="disabled" />'.
5750: $lt{$field}.'</label>';
5751: if ($field eq 'user') {
5752: my $seluserdom = '';
5753: my $unseluserdom = ' selected="selected"';
5754: if ($userincdom) {
5755: $seluserdom = $unseluserdom;
5756: $unseluserdom = '';
5757: }
5758: $datatable .= ': '.
5759: '<select name="proctoring_userincdom_'.$provider.'">'.
5760: '<option value="0"'.$unseluserdom.'>'.$lt{'username'}.'</option>'.
5761: '<option value="1"'.$seluserdom.'>'.$lt{'uname:dom'}.'</option>'.
5762: '</select> ';
5763: } else {
5764: $datatable .= ' ';
5765: if ($field eq 'roles') {
5766: $showroles = 1;
5767: }
5768: }
5769: $datatable .= '</span> ';
5770: }
5771: }
5772: $datatable .= '</fieldset>'."\n";
5773: }
5774: if (ref($optuserfields{$provider}) eq 'ARRAY') {
5775: if (@{$optuserfields{$provider}} > 0) {
5776: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'optu'}.'</legend>';
5777: foreach my $field (@{$optuserfields{$provider}}) {
5778: my $checked;
5779: if ($checkedfields{$field}) {
5780: $checked = ' checked="checked"';
5781: }
5782: $datatable .= '<span class="LC_nobreak">'.
5783: '<label><input type="checkbox" name="proctoring_optional_'.$provider.'" value="'.$field.'"'.$checked.' />'.$lt{$field}.'</label></span> ';
5784: }
5785: $datatable .= '</fieldset>'."\n";
5786: }
5787: }
5788: if (ref($defaults{$provider}) eq 'ARRAY') {
5789: if (@{$defaults{$provider}}) {
5790: my (%options,@selectboxes);
5791: if (ref($extended{$provider}) eq 'HASH') {
5792: %options = %{$extended{$provider}};
5793: }
5794: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'defa'}.'</legend>';
5795: my ($rem,$numinrow,$dropdowns);
5796: if ($provider eq 'proctorio') {
5797: $datatable .= '<table>';
5798: $numinrow = 4;
5799: }
5800: my $i = 0;
5801: foreach my $field (@{$defaults{$provider}}) {
5802: my $checked;
5803: if ($inuse{$field}) {
5804: $checked = ' checked="checked"';
5805: }
5806: if ($provider eq 'examity') {
5807: if ($field eq 'display') {
5808: $datatable .= '<span class="LC_nobreak">'.&mt('Display target:');
5809: foreach my $option ('iframe','tab','window') {
5810: my $checkdisp;
5811: if ($currentdef{'target'} eq $option) {
5812: $checkdisp = ' checked="checked"';
5813: }
5814: $datatable .= '<label><input type="radio" name="proctoring_target_'.$provider.'" value="'.$option.'"'.$checkdisp.' />'.
5815: $fieldtitles{$option}.'</label>'.(' 'x2);
5816: }
5817: $datatable .= (' 'x4);
5818: foreach my $dimen ('width','height') {
5819: $datatable .= '<label>'.$fieldtitles{$dimen}.' '.
5820: '<input type="text" name="proctoring_'.$dimen.'_'.$provider.'" size="5" '.
5821: 'value="'.$currentdef{$dimen}.'" /></label>'.
5822: (' 'x2);
5823: }
5824: $datatable .= '</span><br />'.
5825: '<div class="LC_left_float">'.$fieldtitles{'linktext'}.'<br />'.
5826: '<input type="text" name="proctoring_linktext_'.$provider.'" '.
5827: 'size="25" value="'.$currentdef{'linktext'}.'" /></div>'.
5828: '<div class="LC_left_float">'.$fieldtitles{'explanation'}.'<br />'.
5829: '<textarea name="proctoring_explanation_'.$provider.'" rows="5" cols="40">'.
5830: $currentdef{'explanation'}.
5831: '</textarea></div><div style=""></div><br />';
5832: }
5833: } else {
5834: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
5835: my ($output,$selnone);
5836: unless ($checked) {
5837: $selnone = ' selected="selected"';
5838: }
5839: $output .= '<span class="LC_nobreak">'.$fieldtitles{$field}.': '.
5840: '<select name="proctoring_defaults_'.$field.'_'.$provider.'">'.
5841: '<option value=""'.$selnone.'>'.&mt('Not in use').'</option>';
5842: foreach my $option (@{$options{$field}}) {
5843: my $sel;
5844: if ($inuse{$field} eq $option) {
5845: $sel = ' selected="selected"';
5846: }
5847: $output .= '<option value="'.$option.'"'.$sel.'>'.$fieldtitles{$option}.'</option>';
5848: }
5849: $output .= '</select></span>';
5850: push(@selectboxes,$output);
5851: } else {
5852: $rem = $i%($numinrow);
5853: if ($rem == 0) {
5854: if ($i > 0) {
5855: $datatable .= '</tr>';
5856: }
5857: $datatable .= '<tr>';
5858: }
5859: $datatable .= '<td class="LC_left_item">'.
5860: '<span class="LC_nobreak">'.
5861: '<label><input type="checkbox" name="proctoring_defaults_'.$provider.'" value="'.$field.'"'.$checked.' />'.
5862: $fieldtitles{$field}.'</label></span></td>';
5863: $i++;
5864: }
5865: }
5866: }
5867: if ($provider eq 'proctorio') {
5868: if ($numinrow) {
5869: $rem = $i%$numinrow;
5870: }
5871: my $colsleft = $numinrow - $rem;
5872: if ($colsleft > 1) {
5873: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5874: } else {
5875: $datatable .= '<td class="LC_left_item">';
5876: }
5877: $datatable .= ' '.
5878: '</td></tr></table>';
5879: if (@selectboxes) {
5880: $datatable .= '<hr /><table>';
5881: $numinrow = 2;
5882: for (my $i=0; $i<@selectboxes; $i++) {
5883: $rem = $i%($numinrow);
5884: if ($rem == 0) {
5885: if ($i > 0) {
5886: $datatable .= '</tr>';
5887: }
5888: $datatable .= '<tr>';
5889: }
5890: $datatable .= '<td class="LC_left_item">'.
5891: $selectboxes[$i].'</td>';
5892: }
5893: if ($numinrow) {
5894: $rem = $i%$numinrow;
5895: }
5896: $colsleft = $numinrow - $rem;
5897: if ($colsleft > 1) {
5898: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5899: } else {
5900: $datatable .= '<td class="LC_left_item">';
5901: }
5902: $datatable .= ' '.
5903: '</td></tr></table>';
5904: }
5905: }
5906: $datatable .= '</fieldset>';
5907: }
5908: if (ref($crsconf{$provider}) eq 'ARRAY') {
5909: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5910: '<legend>'.&mt('Configurable in course').'</legend>';
5911: my ($rem,$numinrow);
5912: if ($provider eq 'proctorio') {
5913: $datatable .= '<table>';
5914: $numinrow = 4;
5915: }
5916: my $i = 0;
5917: foreach my $item (@{$crsconf{$provider}}) {
5918: my $name;
5919: if ($provider eq 'examity') {
5920: $name = $lt{'crs'.$item};
5921: } elsif ($provider eq 'proctorio') {
5922: $name = $fieldtitles{$item};
5923: $rem = $i%($numinrow);
5924: if ($rem == 0) {
5925: if ($i > 0) {
5926: $datatable .= '</tr>';
5927: }
5928: $datatable .= '<tr>';
5929: }
5930: $datatable .= '<td class="LC_left_item>';
5931: }
5932: my $checked;
5933: if ($crsconfig{$item}) {
5934: $checked = ' checked="checked"';
5935: }
5936: $datatable .= '<span class="LC_nobreak"><label>'.
5937: '<input type="checkbox" name="proctoring_crsconf_'.$provider.'" value="'.$item.'"'.$checked.' />'.
5938: $name.'</label></span>';
5939: if ($provider eq 'examity') {
5940: $datatable .= ' ';
5941: }
5942: $datatable .= "\n";
5943: $i++;
5944: }
5945: if ($provider eq 'proctorio') {
5946: if ($numinrow) {
5947: $rem = $i%$numinrow;
5948: }
5949: my $colsleft = $numinrow - $rem;
5950: if ($colsleft > 1) {
5951: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5952: } else {
5953: $datatable .= '<td class="LC_left_item">';
5954: }
5955: $datatable .= ' '.
5956: '</td></tr></table>';
5957: }
5958: $datatable .= '</fieldset>';
5959: }
5960: if ($showroles) {
5961: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5962: '<legend>'.&mt('Role mapping').'</legend><table><tr>';
5963: foreach my $role (@courseroles) {
5964: my ($selected,$selectnone);
5965: if (!$rolemaps{$role}) {
5966: $selectnone = ' selected="selected"';
5967: }
5968: $datatable .= '<td style="text-align: center">'.
5969: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5970: '<select name="proctoring_roles_'.$role.'_'.$provider.'">'.
5971: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5972: foreach my $ltirole (@ltiroles) {
5973: unless ($selectnone) {
5974: if ($rolemaps{$role} eq $ltirole) {
5975: $selected = ' selected="selected"';
5976: } else {
5977: $selected = '';
5978: }
5979: }
5980: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
5981: }
5982: $datatable .= '</select></td>';
5983: }
5984: $datatable .= '</tr></table></fieldset>'.
5985: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5986: '<legend>'.&mt('Custom items sent on launch').'</legend>'.
5987: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
5988: '<tr><td></td><td>lms</td>'.
5989: '<td><input type="text" name="proctoring_customval_lms_'.$provider.'"'.
5990: ' value="Loncapa" disabled="disabled"/></td></tr>';
5991: if ((ref($settings) eq 'HASH') && (ref($settings->{$provider}) eq 'HASH') &&
5992: (ref($settings->{$provider}->{'custom'}) eq 'HASH')) {
5993: my %custom = %{$settings->{$provider}->{'custom'}};
5994: if (keys(%custom) > 0) {
5995: foreach my $key (sort(keys(%custom))) {
5996: next if ($key eq 'lms');
5997: $datatable .= '<tr><td><span class="LC_nobreak">'.
5998: '<label><input type="checkbox" name="proctoring_customdel_'.$provider.'" value="'.
5999: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
6000: '<td><input type="text" name="proctoring_customval_'.$key.'_'.$provider.'"'.
6001: ' value="'.$custom{$key}.'" /></td></tr>';
6002: }
6003: }
6004: }
6005: $datatable .= '<tr><td><span class="LC_nobreak">'.
6006: '<label><input type="checkbox" name="proctoring_customadd" value="'.$provider.'" />'.
6007: &mt('Add more').'</label></span></td><td><input type="text" name="proctoring_custom_name_'.$provider.'" />'.
6008: '</td><td><input type="text" name="proctoring_custom_value_'.$provider.'" /></td></tr>'.
6009: '</table></fieldset></td></tr>'."\n";
6010: }
6011: $datatable .= '</td></tr>';
6012: }
6013: $itemcount ++;
6014: }
6015: }
6016: return $datatable;
6017: }
6018:
6019: sub proctoring_data {
6020: my $requserfields = {
6021: proctorio => ['user'],
6022: examity => ['roles','user'],
6023: };
6024: my $optuserfields = {
6025: proctorio => ['fullname'],
6026: examity => ['fullname','firstname','lastname','email'],
6027: };
6028: my $defaults = {
6029: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6030: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6031: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6032: 'closetabs','onescreen','print','downloads','cache','rightclick',
6033: 'reentry','calculator','whiteboard'],
6034: examity => ['display'],
6035: };
6036: my $extended = {
6037: proctorio => {
6038: verifyid => ['verifyidauto','verifyidlive'],
6039: fullscreen => ['fullscreenlenient','fullscreenmoderate','fullscreensever'],
6040: tabslinks => ['notabs','linksonly'],
6041: reentry => ['noreentry','agentreentry'],
6042: calculator => ['calculatorbasic','calculatorsci'],
6043: },
6044: examity => {
6045: display => {
6046: target => ['iframe','tab','window'],
6047: width => '',
6048: height => '',
6049: linktext => '',
6050: explanation => '',
6051: },
6052: },
6053: };
6054: my $crsconf = {
6055: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6056: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6057: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6058: 'closetabs','onescreen','print','downloads','cache','rightclick',
6059: 'reentry','calculator','whiteboard'],
6060: examity => ['label','title','target','linktext','explanation','append'],
6061: };
6062: my $courseroles = ['cc','in','ta','ep','st'];
6063: my $ltiroles = ['Instructor','ContentDeveloper','TeachingAssistant','Learner'];
6064: return ($requserfields,$optuserfields,$defaults,$extended,$crsconf,$courseroles,$ltiroles);
6065: }
6066:
6067: sub proctoring_titles {
6068: my ($item) = @_;
6069: my (%common_lt,%custom_lt);
6070: %common_lt = &Apache::lonlocal::texthash (
6071: 'avai' => 'Available?',
6072: 'base' => 'Basic Settings',
6073: 'requ' => 'User data required to be sent on launch',
6074: 'optu' => 'User data optionally sent on launch',
6075: 'udsl' => 'User data sent on launch',
6076: 'defa' => 'Defaults for items configurable in course',
6077: 'sigmethod' => 'Signature Method',
6078: 'key' => 'Key',
6079: 'lifetime' => 'Nonce lifetime (s)',
6080: 'secret' => 'Secret',
6081: 'icon' => 'Icon',
6082: 'fullname' => 'Full Name',
6083: 'visible' => 'Visible input',
6084: 'username' => 'username',
6085: 'user' => 'User',
6086: );
6087: if ($item eq 'proctorio') {
6088: %custom_lt = &Apache::lonlocal::texthash (
6089: 'version' => 'OAuth version',
6090: 'url' => 'API URL',
6091: 'uname:dom' => 'username-domain',
6092: );
6093: } elsif ($item eq 'examity') {
6094: %custom_lt = &Apache::lonlocal::texthash (
6095: 'version' => 'LTI Version',
6096: 'url' => 'URL',
6097: 'uname:dom' => 'username:domain',
6098: 'msgtype' => 'Message Type',
6099: 'firstname' => 'First Name',
6100: 'lastname' => 'Last Name',
6101: 'email' => 'E-mail',
6102: 'roles' => 'Role',
6103: 'crstarget' => 'Display target',
6104: 'crslabel' => 'Course label',
6105: 'crstitle' => 'Course title',
6106: 'crslinktext' => 'Link Text',
6107: 'crsexplanation' => 'Explanation',
6108: 'crsappend' => 'Provider URL',
6109: );
6110: }
6111: my %lt = (%common_lt,%custom_lt);
6112: return %lt;
6113: }
6114:
6115: sub proctoring_fieldtitles {
6116: my ($item) = @_;
6117: if ($item eq 'proctorio') {
6118: return &Apache::lonlocal::texthash (
6119: 'recordvideo' => 'Record video',
6120: 'recordaudio' => 'Record audio',
6121: 'recordscreen' => 'Record screen',
6122: 'recordwebtraffic' => 'Record web traffic',
6123: 'recordroomstart' => 'Record room scan',
6124: 'verifyvideo' => 'Verify webcam',
6125: 'verifyaudio' => 'Verify microphone',
6126: 'verifydesktop' => 'Verify desktop recording',
6127: 'verifyid' => 'Photo ID verification',
6128: 'verifysignature' => 'Require signature',
6129: 'fullscreen' => 'Fullscreen',
6130: 'clipboard' => 'Disable copy/paste',
6131: 'tabslinks' => 'New tabs/windows',
6132: 'closetabs' => 'Close other tabs',
6133: 'onescreen' => 'Limit to single screen',
6134: 'print' => 'Disable Printing',
6135: 'downloads' => 'Disable Downloads',
6136: 'cache' => 'Empty cache after exam',
6137: 'rightclick' => 'Disable right click',
6138: 'reentry' => 'Re-entry to exam',
6139: 'calculator' => 'Onscreen calculator',
6140: 'whiteboard' => 'Onscreen whiteboard',
6141: 'verifyidauto' => 'Automated verification',
6142: 'verifyidlive' => 'Live agent verification',
6143: 'fullscreenlenient' => 'Forced, but can navigate away for up to 30s',
6144: 'fullscreenmoderate' => 'Forced, but can navigate away for up to 15s',
6145: 'fullscreensever' => 'Forced, navigation away ends exam',
6146: 'notabs' => 'Disaallowed',
6147: 'linksonly' => 'Allowed from links in exam',
6148: 'noreentry' => 'Disallowed',
6149: 'agentreentry' => 'Agent required for re-entry',
6150: 'calculatorbasic' => 'Basic',
6151: 'calculatorsci' => 'Scientific',
6152: );
6153: } elsif ($item eq 'examity') {
6154: return &Apache::lonlocal::texthash (
6155: 'target' => 'Display target',
6156: 'window' => 'Window',
6157: 'tab' => 'Tab',
6158: 'iframe' => 'iFrame',
6159: 'height' => 'Height (pixels)',
6160: 'width' => 'Width (pixels)',
6161: 'linktext' => 'Default Link Text',
6162: 'explanation' => 'Default Explanation',
6163: 'append' => 'Provider URL',
6164: );
6165: }
6166: }
6167:
6168: sub proctoring_providernames {
6169: return (
6170: proctorio => 'Proctorio',
6171: examity => 'Examity',
6172: );
6173: }
6174:
1.320 raeburn 6175: sub print_lti {
1.405 raeburn 6176: my ($position,$dom,$settings,$rowtotal) = @_;
1.320 raeburn 6177: my $itemcount = 1;
1.405 raeburn 6178: my ($datatable,$css_class);
6179: my (%rules,%encrypt,%privkeys,%linkprot);
1.320 raeburn 6180: if (ref($settings) eq 'HASH') {
1.405 raeburn 6181: if ($position eq 'top') {
6182: if (exists($settings->{'encrypt'})) {
6183: if (ref($settings->{'encrypt'}) eq 'HASH') {
6184: foreach my $key (keys(%{$settings->{'encrypt'}})) {
6185: if ($key eq 'consumers') {
6186: $encrypt{'ltisec_'.$key} = $settings->{'encrypt'}{$key};
6187: } else {
6188: $encrypt{'ltisec_'.$key.'linkprot'} = $settings->{'encrypt'}{$key};
6189: }
6190: }
6191: }
6192: }
6193: if (exists($settings->{'private'})) {
6194: if (ref($settings->{'private'}) eq 'HASH') {
6195: if (ref($settings->{'private'}) eq 'HASH') {
6196: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
6197: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
6198: }
6199: }
6200: }
6201: }
6202: } elsif ($position eq 'middle') {
6203: if (exists($settings->{'rules'})) {
6204: if (ref($settings->{'rules'}) eq 'HASH') {
6205: %rules = %{$settings->{'rules'}};
6206: }
6207: }
6208: } elsif ($position eq 'lower') {
6209: if (exists($settings->{'linkprot'})) {
6210: if (ref($settings->{'linkprot'}) eq 'HASH') {
6211: %linkprot = %{$settings->{'linkprot'}};
1.406 raeburn 6212: if ($linkprot{'lock'}) {
6213: delete($linkprot{'lock'});
6214: }
1.405 raeburn 6215: }
6216: }
6217: } else {
6218: foreach my $key ('encrypt','private','rules','linkprot') {
6219: if (exists($settings->{$key})) {
6220: delete($settings->{$key});
1.390 raeburn 6221: }
1.320 raeburn 6222: }
6223: }
6224: }
1.405 raeburn 6225: if ($position eq 'top') {
1.421 raeburn 6226: $datatable = &secrets_form($dom,'ltisec',\%encrypt,\%privkeys,$rowtotal);
6227: } elsif ($position eq 'middle') {
6228: $datatable = &password_rules('ltisecrets',\$itemcount,\%rules);
6229: $$rowtotal += $itemcount;
6230: } elsif ($position eq 'lower') {
6231: $datatable .= &Apache::courseprefs::print_linkprotection($dom,'',$settings,$rowtotal,'','','domain');
6232: } else {
1.424 raeburn 6233: my ($switchserver,$switchmessage);
6234: $switchserver = &check_switchserver($dom);
6235: $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
1.421 raeburn 6236: my $maxnum = 0;
6237: my %ordered;
6238: if (ref($settings) eq 'HASH') {
6239: foreach my $item (keys(%{$settings})) {
6240: if (ref($settings->{$item}) eq 'HASH') {
6241: my $num = $settings->{$item}{'order'};
6242: if ($num eq '') {
6243: $num = scalar(keys(%{$settings}));
6244: }
6245: $ordered{$num} = $item;
1.405 raeburn 6246: }
1.352 raeburn 6247: }
1.405 raeburn 6248: }
6249: $maxnum = scalar(keys(%ordered));
6250: my %lt = <i_names();
6251: if (keys(%ordered)) {
6252: my @items = sort { $a <=> $b } keys(%ordered);
6253: for (my $i=0; $i<@items; $i++) {
6254: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6255: my $item = $ordered{$items[$i]};
1.424 raeburn 6256: my ($key,$secret,$usable,$lifetime,$consumer,$requser,$crsinc,$current);
1.405 raeburn 6257: if (ref($settings->{$item}) eq 'HASH') {
6258: $key = $settings->{$item}->{'key'};
1.424 raeburn 6259: $usable = $settings->{$item}->{'usable'};
1.405 raeburn 6260: $lifetime = $settings->{$item}->{'lifetime'};
6261: $consumer = $settings->{$item}->{'consumer'};
6262: $requser = $settings->{$item}->{'requser'};
6263: $crsinc = $settings->{$item}->{'crsinc'};
6264: $current = $settings->{$item};
6265: }
6266: my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
6267: my %checkedrequser = (
6268: yes => ' checked="checked"',
6269: no => '',
6270: );
6271: if (!$requser) {
6272: $checkedrequser{'no'} = $checkedrequser{'yes'};
6273: $checkedrequser{'yes'} = '';
6274: }
6275: my $onclickcrsinc = ' onclick="toggleLTI(this.form,'."'crsinc','$i'".');"';
6276: my %checkedcrsinc = (
1.391 raeburn 6277: yes => ' checked="checked"',
6278: no => '',
1.405 raeburn 6279: );
6280: if (!$crsinc) {
6281: $checkedcrsinc{'no'} = $checkedcrsinc{'yes'};
6282: $checkedcrsinc{'yes'} = '';
6283: }
6284: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
6285: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6286: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
6287: for (my $k=0; $k<=$maxnum; $k++) {
6288: my $vpos = $k+1;
6289: my $selstr;
6290: if ($k == $i) {
6291: $selstr = ' selected="selected" ';
6292: }
6293: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320 raeburn 6294: }
1.405 raeburn 6295: $datatable .= '</select>'.(' 'x2).
6296: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
6297: &mt('Delete?').'</label></span></td>'.
6298: '<td colspan="2">'.
6299: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6300: '<span class="LC_nobreak">'.$lt{'consumer'}.
6301: ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
6302: (' 'x2).
6303: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
6304: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
6305: (' 'x2).
6306: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
1.424 raeburn 6307: 'value="'.$lifetime.'" size="3" /></span><br /><br />';
6308: if ($key ne '') {
6309: $datatable .= '<span class="LC_nobreak">'.$lt{'key'};
6310: if ($switchserver) {
6311: $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
6312: } else {
6313: $datatable .= ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />';
6314: }
6315: $datatable .= '</span> '.(' 'x2);
6316: } elsif (!$switchserver) {
6317: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':'.
6318: '<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />'.
6319: '</span> '.(' 'x2);
6320: }
6321: if ($switchserver) {
6322: if ($usable ne '') {
6323: $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6324: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6325: '<span class="LC_nobreak">'.&mt('Change secret?').
6326: '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
6327: (' 'x2).
6328: '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').'</label>'.(' 'x2).
6329: '</span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
6330: '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
6331: '</div>';
6332: } elsif ($key eq '') {
6333: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6334: } else {
6335: $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
6336: }
6337: } else {
6338: if ($usable ne '') {
6339: $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6340: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6341: '<span class="LC_nobreak">'.&mt('Change?').
6342: '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
6343: (' 'x2).
6344: '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').
6345: '</label> </span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
6346: '<span class="LC_nobreak">'.&mt('New Secret').':'.
6347: '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
6348: '<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>';
6349: } else {
6350: $datatable .=
6351: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
6352: '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
6353: '<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>';
6354: }
6355: }
1.425 raeburn 6356: $datatable .= '<br /><br />'.
1.405 raeburn 6357: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6358: '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
6359: '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
6360: '<br /><br />'.
6361: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6362: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="1"'.$onclickcrsinc.$checkedcrsinc{yes}.' />'.&mt('Yes').'</label> '."\n".
6363: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="0"'.$onclickcrsinc.$checkedcrsinc{no}.' />'.&mt('No').'</label></span>'."\n".
6364: (' 'x4).
6365: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
6366: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
6367: $itemcount ++;
1.320 raeburn 6368: }
6369: }
1.405 raeburn 6370: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6371: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
6372: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6373: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
6374: '<select name="lti_pos_add"'.$chgstr.'>';
6375: for (my $k=0; $k<$maxnum+1; $k++) {
6376: my $vpos = $k+1;
6377: my $selstr;
6378: if ($k == $maxnum) {
6379: $selstr = ' selected="selected" ';
6380: }
6381: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320 raeburn 6382: }
1.405 raeburn 6383: $datatable .= '</select> '."\n".
6384: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6385: '<td colspan="2">'.
6386: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6387: '<span class="LC_nobreak">'.$lt{'consumer'}.
6388: ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
6389: (' 'x2).
6390: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
6391: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
6392: (' 'x2).
1.424 raeburn 6393: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span><br /><br />'."\n";
6394: if ($switchserver) {
6395: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6396: } else {
6397: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" autocomplete="off" /></span> '."\n".
6398: (' 'x2).
6399: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" autocomplete="new-password" />'.
6400: '<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";
6401: }
6402: $datatable .= '<br /><br />'.
1.405 raeburn 6403: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6404: '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6405: '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
6406: '<br /><br />'.
6407: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6408: '<label><input type="radio" name="lti_crsinc_add" value="1" onclick="toggleLTI(this.form,'."'crsinc','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6409: '<label><input type="radio" name="lti_crsinc_add" value="0" onclick="toggleLTI(this.form,'."'crsinc','add'".');" />'.&mt('No').'</label></span>'."\n".
6410: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
6411: '</td>'."\n".
6412: '</tr>'."\n";
6413: $itemcount ++;
1.320 raeburn 6414: }
1.405 raeburn 6415: $$rowtotal += $itemcount;
6416: return $datatable;
1.320 raeburn 6417: }
6418:
6419: sub lti_names {
6420: my %lt = &Apache::lonlocal::texthash(
6421: 'version' => 'LTI Version',
6422: 'url' => 'URL',
6423: 'key' => 'Key',
1.322 raeburn 6424: 'lifetime' => 'Nonce lifetime (s)',
1.345 raeburn 6425: 'consumer' => 'Consumer',
1.320 raeburn 6426: 'secret' => 'Secret',
1.345 raeburn 6427: 'requser' => "User's identity sent",
1.391 raeburn 6428: 'crsinc' => "Course's identity sent",
1.320 raeburn 6429: 'email' => 'Email address',
6430: 'sourcedid' => 'User ID',
6431: 'other' => 'Other',
6432: 'passback' => 'Can return grades to Consumer:',
6433: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 6434: 'topmenu' => 'Display LON-CAPA page header',
1.345 raeburn 6435: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 6436: );
6437: return %lt;
6438: }
6439:
6440: sub lti_options {
1.325 raeburn 6441: my ($num,$current,$itemcount,%lt) = @_;
1.363 raeburn 6442: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
1.320 raeburn 6443: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
6444: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
1.392 raeburn 6445: $checked{'storecrs'}{'Y'} = ' checked="checked"';
6446: $checked{'makecrs'}{'N'} = ' checked="checked"';
1.320 raeburn 6447: $checked{'mapcrstype'} = {};
6448: $checked{'makeuser'} = {};
6449: $checked{'selfenroll'} = {};
6450: $checked{'crssec'} = {};
6451: $checked{'crssecsrc'} = {};
1.325 raeburn 6452: $checked{'lcauth'} = {};
1.326 raeburn 6453: $checked{'menuitem'} = {};
1.325 raeburn 6454: if ($num eq 'add') {
6455: $checked{'lcauth'}{'lti'} = ' checked="checked"';
6456: }
1.320 raeburn 6457: my $userfieldsty = 'none';
6458: my $crsfieldsty = 'none';
6459: my $crssecfieldsty = 'none';
6460: my $secsrcfieldsty = 'none';
1.363 raeburn 6461: my $callbacksty = 'none';
1.337 raeburn 6462: my $passbacksty = 'none';
1.345 raeburn 6463: my $optionsty = 'block';
1.391 raeburn 6464: my $crssty = 'block';
1.325 raeburn 6465: my $lcauthparm;
6466: my $lcauthparmstyle = 'display:none';
6467: my $lcauthparmtext;
1.326 raeburn 6468: my $menusty;
1.325 raeburn 6469: my $numinrow = 4;
1.326 raeburn 6470: my %menutitles = <imenu_titles();
1.320 raeburn 6471:
6472: if (ref($current) eq 'HASH') {
1.345 raeburn 6473: if (!$current->{'requser'}) {
6474: $optionsty = 'none';
1.391 raeburn 6475: $crssty = 'none';
6476: } elsif (!$current->{'crsinc'}) {
6477: $crssty = 'none';
1.345 raeburn 6478: }
1.320 raeburn 6479: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
6480: $checked{'mapuser'}{'sourcedid'} = '';
6481: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
1.425 raeburn 6482: $checked{'mapuser'}{'email'} = ' checked="checked"';
1.320 raeburn 6483: } else {
6484: $checked{'mapuser'}{'other'} = ' checked="checked"';
6485: $userfield = $current->{'mapuser'};
6486: $userfieldsty = 'inline-block';
6487: }
6488: }
6489: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
6490: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
6491: if ($current->{'mapcrs'} eq 'context_id') {
1.425 raeburn 6492: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
1.320 raeburn 6493: } else {
6494: $checked{'mapcrs'}{'other'} = ' checked="checked"';
6495: $cidfield = $current->{'mapcrs'};
6496: $crsfieldsty = 'inline-block';
6497: }
6498: }
6499: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
6500: foreach my $type (@{$current->{'mapcrstype'}}) {
6501: $checked{'mapcrstype'}{$type} = ' checked="checked"';
6502: }
6503: }
1.392 raeburn 6504: if (!$current->{'storecrs'}) {
6505: $checked{'storecrs'}{'N'} = $checked{'storecrs'}{'Y'};
6506: $checked{'storecrs'}{'Y'} = '';
6507: }
1.345 raeburn 6508: if ($current->{'makecrs'}) {
1.320 raeburn 6509: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 6510: }
1.320 raeburn 6511: if (ref($current->{'makeuser'}) eq 'ARRAY') {
6512: foreach my $role (@{$current->{'makeuser'}}) {
6513: $checked{'makeuser'}{$role} = ' checked="checked"';
6514: }
6515: }
1.325 raeburn 6516: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
6517: $checked{'lcauth'}{$1} = ' checked="checked"';
6518: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
6519: $lcauthparm = $current->{'lcauthparm'};
1.425 raeburn 6520: $lcauthparmstyle = 'display:table-row';
1.325 raeburn 6521: if ($current->{'lcauth'} eq 'localauth') {
6522: $lcauthparmtext = &mt('Local auth argument');
6523: } else {
6524: $lcauthparmtext = &mt('Kerberos domain');
6525: }
6526: }
6527: }
1.320 raeburn 6528: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
6529: foreach my $role (@{$current->{'selfenroll'}}) {
6530: $checked{'selfenroll'}{$role} = ' checked="checked"';
6531: }
6532: }
6533: if (ref($current->{'maproles'}) eq 'HASH') {
6534: %rolemaps = %{$current->{'maproles'}};
6535: }
6536: if ($current->{'section'} ne '') {
1.425 raeburn 6537: $checked{'crssec'}{'Y'} = ' checked="checked"';
1.320 raeburn 6538: $crssecfieldsty = 'inline-block';
6539: if ($current->{'section'} eq 'course_section_sourcedid') {
6540: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
6541: } else {
6542: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
6543: $crssecsrc = $current->{'section'};
6544: $secsrcfieldsty = 'inline-block';
6545: }
6546: } else {
6547: $checked{'crssec'}{'N'} = ' checked="checked"';
6548: }
1.363 raeburn 6549: if ($current->{'callback'} ne '') {
6550: $callback = $current->{'callback'};
6551: $checked{'callback'}{'Y'} = ' checked="checked"';
6552: $callbacksty = 'inline-block';
6553: } else {
6554: $checked{'callback'}{'N'} = ' checked="checked"';
6555: }
1.326 raeburn 6556: if ($current->{'topmenu'}) {
6557: $checked{'topmenu'}{'Y'} = ' checked="checked"';
6558: } else {
6559: $checked{'topmenu'}{'N'} = ' checked="checked"';
6560: }
6561: if ($current->{'inlinemenu'}) {
6562: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
6563: } else {
6564: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
6565: }
6566: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
6567: $menusty = 'inline-block';
6568: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
6569: foreach my $item (@{$current->{'lcmenu'}}) {
6570: if (exists($menutitles{$item})) {
6571: $checked{'menuitem'}{$item} = ' checked="checked"';
6572: }
6573: }
6574: }
6575: } else {
6576: $menusty = 'none';
6577: }
1.320 raeburn 6578: } else {
6579: $checked{'makecrs'}{'N'} = ' checked="checked"';
6580: $checked{'crssec'}{'N'} = ' checked="checked"';
1.363 raeburn 6581: $checked{'callback'}{'N'} = ' checked="checked"';
1.326 raeburn 6582: $checked{'topmenu'}{'N'} = ' checked="checked"';
1.425 raeburn 6583: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
1.326 raeburn 6584: $checked{'menuitem'}{'grades'} = ' checked="checked"';
1.425 raeburn 6585: $menusty = 'inline-block';
1.320 raeburn 6586: }
1.325 raeburn 6587: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 6588: my %coursetypetitles = &Apache::lonlocal::texthash (
6589: official => 'Official',
6590: unofficial => 'Unofficial',
6591: community => 'Community',
6592: textbook => 'Textbook',
6593: placement => 'Placement Test',
1.325 raeburn 6594: lti => 'LTI Provider',
1.320 raeburn 6595: );
1.325 raeburn 6596: my @authtypes = ('internal','krb4','krb5','localauth');
6597: my %shortauth = (
6598: internal => 'int',
6599: krb4 => 'krb4',
6600: krb5 => 'krb5',
6601: localauth => 'loc'
6602: );
6603: my %authnames = &authtype_names();
1.320 raeburn 6604: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
6605: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
6606: my @courseroles = ('cc','in','ta','ep','st');
6607: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
6608: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
6609: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
1.363 raeburn 6610: my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
1.320 raeburn 6611: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 6612: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 6613: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.391 raeburn 6614: my $output = '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Logout options').'</legend>'.
1.392 raeburn 6615: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback to logout LON-CAPA on log out from Consumer').': '.
1.391 raeburn 6616: '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
6617: $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.(' 'x2).
6618: '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
6619: $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
6620: '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
6621: '<span class="LC_nobreak">'.&mt('Parameter').': '.
6622: '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
6623: '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
6624: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320 raeburn 6625: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
6626: foreach my $option ('sourcedid','email','other') {
6627: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
6628: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
6629: ($option eq 'other' ? '' : (' 'x2) );
6630: }
6631: $output .= '</span></div>'.
6632: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
6633: '<input type="text" name="lti_customuser_'.$num.'" '.
1.372 raeburn 6634: 'value="'.$userfield.'" /></div></fieldset>'.
1.391 raeburn 6635: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320 raeburn 6636: foreach my $ltirole (@ltiroles) {
6637: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
1.425 raeburn 6638: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
1.320 raeburn 6639: }
6640: $output .= '</fieldset>'.
1.391 raeburn 6641: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325 raeburn 6642: '<table>'.
6643: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
6644: '</table>'.
6645: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
6646: '<td class="LC_left_item">';
6647: foreach my $auth ('lti',@authtypes) {
6648: my $authtext;
6649: if ($auth eq 'lti') {
6650: $authtext = &mt('None');
6651: } else {
6652: $authtext = $authnames{$shortauth{$auth}};
6653: }
6654: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
6655: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
6656: $authtext.'</label></span> ';
6657: }
6658: $output .= '</td></tr>'.
6659: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
6660: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
6661: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
6662: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
6663: '</table></fieldset>'.
1.391 raeburn 6664: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.
6665: &mt('LON-CAPA menu items (Course Coordinator can override)').'</legend>'.
6666: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
6667: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
6668: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6669: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
6670: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
6671: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6672: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
6673: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
6674: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6675: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
6676: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
6677: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6678: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
6679: '<span class="LC_nobreak">'.&mt('Menu items').': ';
6680: foreach my $type ('fullname','coursetitle','role','logout','grades') {
6681: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
6682: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
6683: (' 'x2);
6684: }
6685: $output .= '</span></div></fieldset>'.
6686: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320 raeburn 6687: '<div class="LC_floatleft"><span class="LC_nobreak">'.
6688: &mt('Unique course identifier').': ';
6689: foreach my $option ('course_offering_sourcedid','context_id','other') {
6690: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
6691: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
6692: ($option eq 'other' ? '' : (' 'x2) );
6693: }
1.334 raeburn 6694: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320 raeburn 6695: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
6696: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
6697: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
6698: foreach my $type (@coursetypes) {
6699: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
6700: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
6701: (' 'x2);
6702: }
1.392 raeburn 6703: $output .= '</span><br /><br />'.
6704: '<span class="LC_nobreak">'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.
6705: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="0"'.
6706: $checked{'storecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6707: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="1"'.
6708: $checked{'storecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6709: '</fieldset>'.
1.391 raeburn 6710: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
6711: foreach my $ltirole (@lticourseroles) {
6712: my ($selected,$selectnone);
6713: if ($rolemaps{$ltirole} eq '') {
6714: $selectnone = ' selected="selected"';
6715: }
6716: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
6717: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
6718: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
6719: foreach my $role (@courseroles) {
6720: unless ($selectnone) {
6721: if ($rolemaps{$ltirole} eq $role) {
6722: $selected = ' selected="selected"';
6723: } else {
6724: $selected = '';
6725: }
6726: }
6727: $output .= '<option value="'.$role.'"'.$selected.'>'.
6728: &Apache::lonnet::plaintext($role,'Course').
6729: '</option>';
6730: }
6731: $output .= '</select></td>';
6732: }
6733: $output .= '</tr></table></fieldset>'.
6734: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320 raeburn 6735: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
6736: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
6737: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6738: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
6739: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6740: '</fieldset>'.
1.391 raeburn 6741: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320 raeburn 6742: foreach my $lticrsrole (@lticourseroles) {
6743: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
6744: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
6745: }
6746: $output .= '</fieldset>'.
1.391 raeburn 6747: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Course options').'</legend>'.
1.320 raeburn 6748: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
6749: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
6750: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
6751: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334 raeburn 6752: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320 raeburn 6753: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
6754: '<span class="LC_nobreak">'.&mt('From').':<label>'.
6755: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
6756: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
6757: &mt('Standard field').'</label>'.(' 'x2).
6758: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
6759: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334 raeburn 6760: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320 raeburn 6761: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337 raeburn 6762: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6763: my ($pb1p1chk,$pb1p0chk,$onclickpb);
6764: foreach my $extra ('roster','passback') {
1.320 raeburn 6765: my $checkedon = '';
6766: my $checkedoff = ' checked="checked"';
1.337 raeburn 6767: if ($extra eq 'passback') {
6768: $pb1p1chk = ' checked="checked"';
6769: $pb1p0chk = '';
1.425 raeburn 6770: $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
1.337 raeburn 6771: } else {
1.425 raeburn 6772: $onclickpb = '';
1.337 raeburn 6773: }
1.320 raeburn 6774: if (ref($current) eq 'HASH') {
6775: if (($current->{$extra})) {
6776: $checkedon = $checkedoff;
6777: $checkedoff = '';
1.337 raeburn 6778: if ($extra eq 'passback') {
6779: $passbacksty = 'inline-block';
6780: }
6781: if ($current->{'passbackformat'} eq '1.0') {
6782: $pb1p0chk = ' checked="checked"';
6783: $pb1p1chk = '';
6784: }
1.320 raeburn 6785: }
6786: }
6787: $output .= $lt{$extra}.' '.
1.337 raeburn 6788: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320 raeburn 6789: &mt('No').'</label>'.(' 'x2).
1.339 raeburn 6790: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320 raeburn 6791: &mt('Yes').'</label><br />';
6792: }
1.337 raeburn 6793: $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
6794: '<span class="LC_nobreak">'.&mt('Grade format').
6795: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
6796: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
6797: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
1.363 raeburn 6798: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
1.391 raeburn 6799: '<div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>';
1.334 raeburn 6800: $output .= '</span></div></fieldset>';
1.320 raeburn 6801: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
6802: #
6803: # $output .= '</fieldset>'.
6804: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
6805: return $output;
6806: }
6807:
1.326 raeburn 6808: sub ltimenu_titles {
6809: return &Apache::lonlocal::texthash(
6810: fullname => 'Full name',
6811: coursetitle => 'Course title',
6812: role => 'Role',
6813: logout => 'Logout',
6814: grades => 'Grades',
6815: );
6816: }
6817:
1.121 raeburn 6818: sub print_coursedefaults {
1.139 raeburn 6819: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 6820: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 6821: my $itemcount = 1;
1.192 raeburn 6822: my %choices = &Apache::lonlocal::texthash (
6823: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 6824: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.432 raeburn 6825: coursequota => 'Default cumulative quota for all group portfolio spaces in course (MB)',
1.192 raeburn 6826: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
6827: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 6828: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
6829: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.398 raeburn 6830: inline_chem => 'Use inline previewer for chemical reaction response in place of pop-up',
1.314 raeburn 6831: texengine => 'Default method to display mathematics',
1.257 raeburn 6832: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 6833: canclone => "People who may clone a course (besides course's owner and coordinators)",
6834: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.405 raeburn 6835: ltiauth => 'Student username in LTI launch of deep-linked URL can be accepted without re-authentication',
1.422 raeburn 6836: domexttool => 'External Tools defined in the domain may be used in courses/communities (by type)',
6837: exttool => 'External Tools can be defined and configured in courses/communities (by type)',
1.432 raeburn 6838: crsauthor => 'Standard LON-CAPA problems can be created within a course/community (by type)',
1.192 raeburn 6839: );
1.198 raeburn 6840: my %staticdefaults = (
6841: anonsurvey_threshold => 10,
6842: uploadquota => 500,
1.428 raeburn 6843: coursequota => 20,
1.257 raeburn 6844: postsubmit => 60,
1.276 raeburn 6845: mysqltables => 172800,
1.422 raeburn 6846: domexttool => 1,
6847: exttool => 0,
1.432 raeburn 6848: crsauthor => 1,
1.198 raeburn 6849: );
1.139 raeburn 6850: if ($position eq 'top') {
1.257 raeburn 6851: %defaultchecked = (
6852: 'canuse_pdfforms' => 'off',
6853: 'uselcmath' => 'on',
6854: 'usejsme' => 'on',
1.398 raeburn 6855: 'inline_chem' => 'on',
1.289 raeburn 6856: 'canclone' => 'none',
1.257 raeburn 6857: );
1.398 raeburn 6858: @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem');
1.349 raeburn 6859: my $deftex = $Apache::lonnet::deftex;
1.314 raeburn 6860: if (ref($settings) eq 'HASH') {
6861: if ($settings->{'texengine'}) {
6862: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
6863: $deftex = $settings->{'texengine'};
6864: }
6865: }
6866: }
6867: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6868: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
6869: '<span class="LC_nobreak">'.$choices{'texengine'}.
6870: '</span></td><td class="LC_right_item">'.
6871: '<select name="texengine">'."\n";
6872: my %texoptions = (
6873: MathJax => 'MathJax',
6874: mimetex => &mt('Convert to Images'),
6875: tth => &mt('TeX to HTML'),
6876: );
6877: foreach my $renderer ('MathJax','mimetex','tth') {
6878: my $selected = '';
6879: if ($renderer eq $deftex) {
6880: $selected = ' selected="selected"';
6881: }
6882: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
6883: }
6884: $mathdisp .= '</select></td></tr>'."\n";
6885: $itemcount ++;
1.139 raeburn 6886: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 6887: \%choices,$itemcount);
1.314 raeburn 6888: $datatable = $mathdisp.$datatable;
1.264 raeburn 6889: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6890: $datatable .=
1.306 raeburn 6891: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 6892: '<span class="LC_nobreak">'.$choices{'canclone'}.
6893: '</span></td><td class="LC_left_item">';
6894: my $currcanclone = 'none';
6895: my $onclick;
6896: my @cloneoptions = ('none','domain');
1.380 raeburn 6897: my %clonetitles = &Apache::lonlocal::texthash (
1.264 raeburn 6898: none => 'No additional course requesters',
6899: domain => "Any course requester in course's domain",
6900: instcode => 'Course requests for official courses ...',
6901: );
6902: my (%codedefaults,@code_order,@posscodes);
6903: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
6904: \@code_order) eq 'ok') {
6905: if (@code_order > 0) {
6906: push(@cloneoptions,'instcode');
6907: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
6908: }
6909: }
6910: if (ref($settings) eq 'HASH') {
6911: if ($settings->{'canclone'}) {
6912: if (ref($settings->{'canclone'}) eq 'HASH') {
6913: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
6914: if (@code_order > 0) {
6915: $currcanclone = 'instcode';
6916: @posscodes = @{$settings->{'canclone'}{'instcode'}};
6917: }
6918: }
6919: } elsif ($settings->{'canclone'} eq 'domain') {
6920: $currcanclone = $settings->{'canclone'};
6921: }
6922: }
1.289 raeburn 6923: }
1.264 raeburn 6924: foreach my $option (@cloneoptions) {
6925: my ($checked,$additional);
6926: if ($currcanclone eq $option) {
6927: $checked = ' checked="checked"';
6928: }
6929: if ($option eq 'instcode') {
6930: if (@code_order) {
6931: my $show = 'none';
6932: if ($checked) {
6933: $show = 'block';
6934: }
1.317 raeburn 6935: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 6936: &mt('Institutional codes for new and cloned course have identical:').
6937: '<br />';
6938: foreach my $item (@code_order) {
6939: my $codechk;
6940: if ($checked) {
6941: if (grep(/^\Q$item\E$/,@posscodes)) {
6942: $codechk = ' checked="checked"';
6943: }
6944: }
6945: $additional .= '<label>'.
6946: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
6947: $item.'</label>';
6948: }
6949: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
6950: }
6951: }
6952: $datatable .=
6953: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
6954: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
6955: '</label> '.$additional.'</span><br />';
6956: }
6957: $datatable .= '</td>'.
6958: '</tr>';
6959: $itemcount ++;
1.139 raeburn 6960: } else {
6961: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.428 raeburn 6962: my ($currdefresponder,%defcredits,%curruploadquota,%currcoursequota,
6963: %deftimeout,%currmysql);
1.192 raeburn 6964: my $currusecredits = 0;
1.257 raeburn 6965: my $postsubmitclient = 1;
1.405 raeburn 6966: my $ltiauth = 0;
1.422 raeburn 6967: my %domexttool;
6968: my %exttool;
1.432 raeburn 6969: my %crsauthor;
1.271 raeburn 6970: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 6971: if (ref($settings) eq 'HASH') {
1.404 raeburn 6972: if ($settings->{'ltiauth'}) {
6973: $ltiauth = 1;
1.405 raeburn 6974: }
1.422 raeburn 6975: if (ref($settings->{'domexttool'}) eq 'HASH') {
6976: foreach my $type (@types) {
6977: if ($settings->{'domexttool'}->{$type}) {
6978: $domexttool{$type} = ' checked="checked"';
6979: }
6980: }
6981: } else {
6982: foreach my $type (@types) {
6983: if ($staticdefaults{'domexttool'}) {
6984: $domexttool{$type} = ' checked="checked"';
6985: }
6986: }
6987: }
6988: if (ref($settings->{'exttool'}) eq 'HASH') {
6989: foreach my $type (@types) {
6990: if ($settings->{'exttool'}->{$type}) {
6991: $exttool{$type} = ' checked="checked"';
6992: }
6993: }
6994: }
1.432 raeburn 6995: if (ref($settings->{'crsauthor'}) eq 'HASH') {
6996: foreach my $type (@types) {
6997: if ($settings->{'crsauthor'}->{$type}) {
6998: $crsauthor{$type} = ' checked="checked"';
6999: }
7000: }
7001: } else {
7002: foreach my $type (@types) {
7003: if ($staticdefaults{'crsauthor'}) {
7004: $crsauthor{$type} = ' checked="checked"';
7005: }
7006: }
7007: }
1.139 raeburn 7008: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 7009: if (ref($settings->{'uploadquota'}) eq 'HASH') {
7010: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
7011: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
7012: }
7013: }
1.428 raeburn 7014: if (ref($settings->{'coursequota'}) eq 'HASH') {
7015: foreach my $type (keys(%{$settings->{'coursequota'}})) {
7016: $currcoursequota{$type} = $settings->{'coursequota'}{$type};
7017: }
7018: }
1.192 raeburn 7019: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 7020: foreach my $type (@types) {
7021: next if ($type eq 'community');
7022: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
7023: if ($defcredits{$type} ne '') {
7024: $currusecredits = 1;
7025: }
7026: }
7027: }
7028: if (ref($settings->{'postsubmit'}) eq 'HASH') {
7029: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
7030: $postsubmitclient = 0;
7031: foreach my $type (@types) {
7032: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7033: }
7034: } else {
7035: foreach my $type (@types) {
7036: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
7037: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 7038: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 7039: } else {
7040: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7041: }
7042: } else {
7043: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7044: }
7045: }
7046: }
7047: } else {
7048: foreach my $type (@types) {
7049: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 7050: }
7051: }
1.276 raeburn 7052: if (ref($settings->{'mysqltables'}) eq 'HASH') {
7053: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
7054: $currmysql{$type} = $settings->{'mysqltables'}{$type};
7055: }
7056: } else {
7057: foreach my $type (@types) {
7058: $currmysql{$type} = $staticdefaults{'mysqltables'};
7059: }
7060: }
1.258 raeburn 7061: } else {
7062: foreach my $type (@types) {
7063: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.422 raeburn 7064: if ($staticdefaults{'domexttool'}) {
7065: $domexttool{$type} = ' checked="checked"';
7066: }
1.432 raeburn 7067: if ($staticdefaults{'crsauthor'}) {
7068: $crsauthor{$type} = ' checked="checked"';
7069: }
1.258 raeburn 7070: }
1.139 raeburn 7071: }
7072: if (!$currdefresponder) {
1.198 raeburn 7073: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 7074: } elsif ($currdefresponder < 1) {
7075: $currdefresponder = 1;
7076: }
1.198 raeburn 7077: foreach my $type (@types) {
7078: if ($curruploadquota{$type} eq '') {
7079: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
7080: }
1.428 raeburn 7081: if ($currcoursequota{$type} eq '') {
7082: $currcoursequota{$type} = $staticdefaults{'coursequota'};
7083: }
1.198 raeburn 7084: }
1.139 raeburn 7085: $datatable .=
1.192 raeburn 7086: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7087: $choices{'anonsurvey_threshold'}.
1.139 raeburn 7088: '</span></td>'.
7089: '<td class="LC_right_item"><span class="LC_nobreak">'.
7090: '<input type="text" name="anonsurvey_threshold"'.
7091: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 7092: '</td></tr>'."\n";
7093: $itemcount ++;
7094: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7095: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7096: $choices{'uploadquota'}.
7097: '</span></td>'.
1.306 raeburn 7098: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 7099: '<table><tr>';
1.198 raeburn 7100: foreach my $type (@types) {
1.306 raeburn 7101: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 7102: '<input type="text" name="uploadquota_'.$type.'"'.
7103: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
7104: }
7105: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 7106: $itemcount ++;
1.428 raeburn 7107: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7108: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7109: $choices{'coursequota'}.
7110: '</span></td>'.
7111: '<td style="text-align: right" class="LC_right_item">'.
7112: '<table><tr>';
7113: foreach my $type (@types) {
7114: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
7115: '<input type="text" name="coursequota_'.$type.'"'.
7116: ' value="'.$currcoursequota{$type}.'" size="5" /></td>';
7117: }
7118: $datatable .= '</tr></table></td></tr>'."\n";
7119: $itemcount ++;
1.236 raeburn 7120: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 7121: my $display = 'none';
1.192 raeburn 7122: if ($currusecredits) {
7123: $display = 'block';
7124: }
7125: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 7126: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
7127: foreach my $type (@types) {
7128: next if ($type eq 'community');
1.306 raeburn 7129: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7130: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 7131: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 7132: }
7133: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 7134: %defaultchecked = ('coursecredits' => 'off');
7135: @toggles = ('coursecredits');
7136: my $current = {
7137: 'coursecredits' => $currusecredits,
7138: };
7139: (my $table,$itemcount) =
7140: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 7141: \%choices,$itemcount,$onclick,$additional,'left');
7142: $datatable .= $table;
7143: $onclick = "toggleDisplay(this.form,'studentsubmission');";
7144: my $display = 'none';
7145: if ($postsubmitclient) {
7146: $display = 'block';
7147: }
7148: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 7149: &mt('Number of seconds submit is disabled').'<br />'.
7150: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
7151: '<table><tr>';
1.257 raeburn 7152: foreach my $type (@types) {
1.306 raeburn 7153: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7154: '<input type="text" name="'.$type.'_timeout" value="'.
7155: $deftimeout{$type}.'" size="5" /></td>';
7156: }
7157: $additional .= '</tr></table></div>'."\n";
7158: %defaultchecked = ('postsubmit' => 'on');
7159: @toggles = ('postsubmit');
1.280 raeburn 7160: $current = {
7161: 'postsubmit' => $postsubmitclient,
7162: };
1.257 raeburn 7163: ($table,$itemcount) =
7164: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7165: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 7166: $datatable .= $table;
1.276 raeburn 7167: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7168: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7169: $choices{'mysqltables'}.
7170: '</span></td>'.
1.306 raeburn 7171: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 7172: '<table><tr>';
7173: foreach my $type (@types) {
1.306 raeburn 7174: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 7175: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 7176: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 7177: }
7178: $datatable .= '</tr></table></td></tr>'."\n";
7179: $itemcount ++;
1.404 raeburn 7180: %defaultchecked = ('ltiauth' => 'off');
7181: @toggles = ('ltiauth');
7182: $current = {
7183: 'ltiauth' => $ltiauth,
7184: };
7185: ($table,$itemcount) =
7186: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7187: \%choices,$itemcount,undef,undef,'left');
7188: $datatable .= $table;
1.422 raeburn 7189: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7190: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7191: $choices{'domexttool'}.
7192: '</span></td>'.
7193: '<td style="text-align: right" class="LC_right_item">'.
7194: '<table><tr>';
7195: foreach my $type (@types) {
7196: $datatable .= '<td style="text-align: left">'.
7197: '<span class="LC_nobreak">'.
7198: '<input type="checkbox" name="domexttool"'.
7199: ' value="'.$type.'"'.$domexttool{$type}.' />'.
7200: &mt($type).'</span></td>'."\n";
7201: }
7202: $datatable .= '</tr></table></td></tr>'."\n";
1.404 raeburn 7203: $itemcount ++;
1.422 raeburn 7204: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7205: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7206: $choices{'exttool'}.
7207: '</span></td>'.
7208: '<td style="text-align: right" class="LC_right_item">'.
7209: '<table><tr>';
7210: foreach my $type (@types) {
7211: $datatable .= '<td style="text-align: left">'.
7212: '<span class="LC_nobreak">'.
7213: '<input type="checkbox" name="exttool"'.
7214: ' value="'.$type.'"'.$exttool{$type}.' />'.
7215: &mt($type).'</span></td>'."\n";
7216: }
7217: $datatable .= '</tr></table></td></tr>'."\n";
1.432 raeburn 7218: $itemcount ++;
7219: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7220: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7221: $choices{'crsauthor'}.
7222: '</span></td>'.
7223: '<td style="text-align: right" class="LC_right_item">'.
7224: '<table><tr>';
7225: foreach my $type (@types) {
7226: $datatable .= '<td style="text-align: left">'.
7227: '<span class="LC_nobreak">'.
7228: '<input type="checkbox" name="crsauthor"'.
7229: ' value="'.$type.'"'.$crsauthor{$type}.' />'.
7230: &mt($type).'</span></td>'."\n";
7231: }
7232: $datatable .= '</tr></table></td></tr>'."\n";
1.139 raeburn 7233: }
1.192 raeburn 7234: $$rowtotal += $itemcount;
1.121 raeburn 7235: return $datatable;
1.118 jms 7236: }
7237:
1.429 raeburn 7238: sub print_authordefaults {
7239: my ($position,$dom,$settings,$rowtotal) = @_;
7240: my ($css_class,$datatable,%checkedon,%checkedoff);
7241: my $itemcount = 1;
7242: my %titles = &authordefaults_titles();
7243: if ($position eq 'top') {
7244: my %defaultchecked = (
7245: 'nocodemirror' => 'off',
7246: 'domcoordacc' => 'on',
7247: );
7248: my @toggles = ('nocodemirror','domcoordacc');
7249: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
7250: \%titles,$itemcount);
7251: my %staticdefaults = (
7252: 'copyright' => 'default',
7253: 'sourceavail' => 'closed',
7254: );
7255: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7256: my %currrights;
7257: foreach my $item ('copyright','sourceavail') {
7258: $currrights{$item} = $staticdefaults{$item};
7259: if (ref($settings) eq 'HASH') {
7260: if (exists($settings->{$item})) {
7261: $currrights{$item} = $settings->{$item};
7262: }
7263: }
7264: }
7265: $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
7266: '<span class="LC_nobreak">'.$titles{'copyright'}.
7267: '</span></td><td class="LC_right_item">'.
7268: &selectbox('copyright',$currrights{'copyright'},'',
7269: \&Apache::loncommon::copyrightdescription,
7270: (grep !/^priv|custom$/,(&Apache::loncommon::copyrightids))).
7271: '</td></tr>'."\n";
7272: $itemcount ++;
7273: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7274: $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
7275: '<span class="LC_nobreak">'.$titles{'sourceavail'}.
7276: '</span></td><td class="LC_right_item">'.
7277: &selectbox('sourceavail',$currrights{'sourceavail'},'',
7278: \&Apache::loncommon::source_copyrightdescription,
7279: (&Apache::loncommon::source_copyrightids)).
7280: '</td></tr>'."\n";
7281: } else {
7282: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7283: my $curreditors;
7284: my %staticdefaults = (
7285: editors => ['edit','xml'],
7286: authorquota => 500,
7287: webdav => 0,
7288: );
7289: my $curreditors = $staticdefaults{'editors'};
7290: if ((ref($settings) eq 'HASH') &&
7291: (ref($settings->{'editors'}) eq 'ARRAY')) {
7292: $curreditors = $settings->{'editors'};
7293: } else {
7294: $curreditors = $staticdefaults{'editors'};
7295: }
7296: my @editors = ('edit','xml','daxe');
7297: $datatable = '<tr'.$css_class.'>'."\n".
7298: '<td>'.$titles{'editors'}.'</td>'."\n".
7299: '<td class="LC_left_item">'."\n".
7300: '<span class="LC_nobreak">';
7301: foreach my $editor (@editors) {
7302: my $checked;
7303: if (grep(/^\Q$editor\E$/,@{$curreditors})) {
7304: $checked = ' checked="checked"';
7305: }
7306: $datatable .= '<label>'.
7307: '<input type="checkbox" name="author_editors" '.
7308: $checked.' value="'.$editor.'" '.
7309: 'onclick="javascript:checkEditors(this.form,'."'author_editors'".',this);" />'.
7310: $titles{$editor}.'</label> ';
7311: }
7312: $datatable .= '</span>'."\n".'</td>'."\n".'</tr>'."\n";
7313: $itemcount ++;
7314: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7315: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7316: my @insttypes;
7317: if (ref($types) eq 'ARRAY') {
7318: @insttypes = @{$types};
7319: }
7320: my $typecount = 0;
7321: my %domconf = &Apache::lonnet::get_dom('configuration',['quotas'],$dom);
7322: my @items = ('webdav','authorquota');
7323: my %quotas;
7324: if (ref($domconf{'quotas'}) eq 'HASH') {
7325: %quotas = %{$domconf{'quotas'}};
7326: foreach my $item (@items) {
7327: if (ref($quotas{$item}) eq 'HASH') {
7328: foreach my $type (@insttypes,'default') {
7329: if ($item eq 'authorquota') {
7330: if ($quotas{$item}{$type} !~ /^\d+$/) {
7331: $quotas{$item}{$type} = $staticdefaults{$item};
7332: }
7333: } elsif ($item eq 'webdav') {
7334: if ($quotas{$item}{$type} !~ /^(0|1)$/) {
7335: $quotas{$item}{$type} = $staticdefaults{$item};
7336: }
7337: }
7338: }
7339: } else {
7340: foreach my $type (@insttypes,'default') {
7341: $quotas{$item}{$type} = $staticdefaults{$item};
7342: }
7343: }
7344: }
7345: } else {
7346: foreach my $item (@items) {
7347: foreach my $type (@insttypes,'default') {
7348: $quotas{$item}{$type} = $staticdefaults{$item};
7349: }
7350: }
7351: }
7352: if (ref($usertypes) eq 'HASH') {
7353: my $numinrow = 4;
7354: my $onclick = '';
7355: $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
7356: $numinrow,$othertitle,'authorquota',
7357: \$itemcount,$onclick);
7358: $itemcount ++;
7359: $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
7360: $numinrow,$othertitle,'webdav',
7361: \$itemcount);
7362: $itemcount ++;
7363: }
7364: my $checkedno = ' checked="checked"';
7365: my ($checkedon,$checkedoff);
7366: if (ref($quotas{'webdav'}) eq 'HASH') {
7367: if ($quotas{'webdav'}{'_LC_adv'} =~ /^0|1$/) {
7368: if ($quotas{'webdav'}{'_LC_adv'}) {
7369: $checkedon = $checkedno;
7370: } else {
7371: $checkedoff = $checkedno;
7372: }
7373: undef($checkedno);
7374: }
7375: }
7376: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7377: $datatable .= '<tr'.$css_class.'>'.
7378: '<td>'.$titles{'webdav_LC_adv'}.'<br />'.
7379: $titles{'webdav_LC_adv_over'}.
7380: '</td>'.
7381: '<td class="LC_left_item">';
7382: foreach my $option ('none','off','on') {
7383: my ($text,$val,$checked);
7384: if ($option eq 'none') {
7385: $text = $titles{'none'};
7386: $val = '';
7387: $checked = $checkedno;
7388: } elsif ($option eq 'off') {
7389: $text = $titles{'overoff'};
7390: $val = 0;
7391: $checked = $checkedoff;
7392: } elsif ($option eq 'on') {
7393: $text = $titles{'overon'};
7394: $val = 1;
7395: $checked = $checkedon;
7396: }
7397: $datatable .= '<span class="LC_nobreak"><label>'.
7398: '<input type="radio" name="webdav_LC_adv"'.
7399: ' value="'.$val.'"'.$checked.' />'.
7400: $text.'</label></span> ';
7401: }
7402: $datatable .= '</td></tr>';
7403: $itemcount ++;
7404: }
7405: $$rowtotal += $itemcount;
7406: return $datatable;
7407: }
7408:
7409: sub authordefaults_titles {
7410: return &Apache::lonlocal::texthash(
7411: copyright => 'Copyright/Distribution',
7412: sourceavail => ' Source Available',
7413: editors => 'Available Editors',
7414: webdav => 'WebDAV',
7415: authorquota => 'Authoring Space quotas (MB)',
7416: nocodemirror => 'Deactivate CodeMirror for EditXML editor',
7417: domcoordacc => 'Dom. Coords. can enter Authoring Spaces in domain',
7418: edit => 'Standard editor (Edit)',
7419: xml => 'Text editor (EditXML)',
7420: daxe => 'Daxe editor (Daxe)',
7421: webdav_LC_adv => 'WebDAV access for LON-CAPA "advanced" users',
7422: webdav_LC_adv_over => '(overrides access based on affiliation, if set)',
7423: none => 'No override set',
7424: overon => 'Override -- webDAV on',
7425: overoff => 'Override -- webDAV off',
7426: );
7427: }
7428:
7429: sub selectbox {
7430: my ($name,$value,$readonly,$functionref,@idlist)=@_;
7431: my $selout = '<select name="'.$name.'">';
7432: foreach my $id (@idlist) {
7433: $selout.='<option value="'.$id.'"';
7434: if ($id eq $value) {
7435: $selout.=' selected="selected"';
7436: }
7437: if ($readonly) {
7438: $selout .= ' disabled="disabled"';
7439: }
7440: $selout.='>'.&{$functionref}($id).'</option>';
7441: }
7442: $selout.='</select>';
7443: return $selout;
7444: }
7445:
1.231 raeburn 7446: sub print_selfenrollment {
7447: my ($position,$dom,$settings,$rowtotal) = @_;
7448: my ($css_class,$datatable);
7449: my $itemcount = 1;
1.271 raeburn 7450: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 7451: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 7452: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
7453: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 7454: my @rows;
7455: my $key;
7456: if ($position eq 'top') {
7457: $key = 'admin';
7458: if (ref($rowsref) eq 'ARRAY') {
7459: @rows = @{$rowsref};
7460: }
7461: } elsif ($position eq 'middle') {
7462: $key = 'default';
7463: @rows = ('types','registered','approval','limit');
7464: }
7465: foreach my $row (@rows) {
7466: if (defined($titlesref->{$row})) {
7467: $itemcount ++;
7468: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7469: $datatable .= '<tr'.$css_class.'>'.
7470: '<td>'.$titlesref->{$row}.'</td>'.
7471: '<td class="LC_left_item">'.
7472: '<table><tr>';
7473: my (%current,%currentcap);
7474: if (ref($settings) eq 'HASH') {
7475: if (ref($settings->{$key}) eq 'HASH') {
7476: foreach my $type (@types) {
7477: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7478: $current{$type} = $settings->{$key}->{$type}->{$row};
7479: }
7480: if (($row eq 'limit') && ($key eq 'default')) {
7481: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7482: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
7483: }
7484: }
7485: }
7486: }
7487: }
7488: my %roles = (
7489: '0' => &Apache::lonnet::plaintext('dc'),
7490: );
7491:
7492: foreach my $type (@types) {
7493: unless (($row eq 'registered') && ($key eq 'default')) {
7494: $datatable .= '<th>'.&mt($type).'</th>';
7495: }
7496: }
7497: unless (($row eq 'registered') && ($key eq 'default')) {
7498: $datatable .= '</tr><tr>';
7499: }
7500: foreach my $type (@types) {
7501: if ($type eq 'community') {
7502: $roles{'1'} = &mt('Community personnel');
7503: } else {
7504: $roles{'1'} = &mt('Course personnel');
7505: }
7506: $datatable .= '<td style="vertical-align: top">';
7507: if ($position eq 'top') {
7508: my %checked;
7509: if ($current{$type} eq '0') {
7510: $checked{'0'} = ' checked="checked"';
7511: } else {
7512: $checked{'1'} = ' checked="checked"';
7513: }
7514: foreach my $role ('1','0') {
7515: $datatable .= '<span class="LC_nobreak"><label>'.
7516: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
7517: 'value="'.$role.'"'.$checked{$role}.' />'.
7518: $roles{$role}.'</label></span> ';
7519: }
7520: } else {
7521: if ($row eq 'types') {
7522: my %checked;
7523: if ($current{$type} =~ /^(all|dom)$/) {
7524: $checked{$1} = ' checked="checked"';
7525: } else {
7526: $checked{''} = ' checked="checked"';
7527: }
7528: foreach my $val ('','dom','all') {
7529: $datatable .= '<span class="LC_nobreak"><label>'.
7530: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7531: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7532: }
7533: } elsif ($row eq 'registered') {
7534: my %checked;
7535: if ($current{$type} eq '1') {
7536: $checked{'1'} = ' checked="checked"';
7537: } else {
7538: $checked{'0'} = ' checked="checked"';
7539: }
7540: foreach my $val ('0','1') {
7541: $datatable .= '<span class="LC_nobreak"><label>'.
7542: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7543: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7544: }
7545: } elsif ($row eq 'approval') {
7546: my %checked;
7547: if ($current{$type} =~ /^([12])$/) {
7548: $checked{$1} = ' checked="checked"';
7549: } else {
7550: $checked{'0'} = ' checked="checked"';
7551: }
7552: for my $val (0..2) {
7553: $datatable .= '<span class="LC_nobreak"><label>'.
7554: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7555: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7556: }
7557: } elsif ($row eq 'limit') {
7558: my %checked;
7559: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
7560: $checked{$1} = ' checked="checked"';
7561: } else {
7562: $checked{'none'} = ' checked="checked"';
7563: }
7564: my $cap;
7565: if ($currentcap{$type} =~ /^\d+$/) {
7566: $cap = $currentcap{$type};
7567: }
7568: foreach my $val ('none','allstudents','selfenrolled') {
7569: $datatable .= '<span class="LC_nobreak"><label>'.
7570: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7571: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7572: }
7573: $datatable .= '<br />'.
7574: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
7575: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
7576: '</span>';
7577: }
7578: }
7579: $datatable .= '</td>';
7580: }
7581: $datatable .= '</tr>';
7582: }
7583: $datatable .= '</table></td></tr>';
7584: }
7585: } elsif ($position eq 'bottom') {
1.235 raeburn 7586: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
7587: }
7588: $$rowtotal += $itemcount;
7589: return $datatable;
7590: }
7591:
7592: sub print_validation_rows {
7593: my ($caller,$dom,$settings,$rowtotal) = @_;
7594: my ($itemsref,$namesref,$fieldsref);
7595: if ($caller eq 'selfenroll') {
7596: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
7597: } elsif ($caller eq 'requestcourses') {
7598: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
7599: }
7600: my %currvalidation;
7601: if (ref($settings) eq 'HASH') {
7602: if (ref($settings->{'validation'}) eq 'HASH') {
7603: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 7604: }
1.235 raeburn 7605: }
7606: my $datatable;
7607: my $itemcount = 0;
7608: foreach my $item (@{$itemsref}) {
7609: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7610: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7611: $namesref->{$item}.
7612: '</span></td>'.
7613: '<td class="LC_left_item">';
7614: if (($item eq 'url') || ($item eq 'button')) {
7615: $datatable .= '<span class="LC_nobreak">'.
7616: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
7617: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
7618: } elsif ($item eq 'fields') {
7619: my @currfields;
7620: if (ref($currvalidation{$item}) eq 'ARRAY') {
7621: @currfields = @{$currvalidation{$item}};
7622: }
7623: foreach my $field (@{$fieldsref}) {
7624: my $check = '';
7625: if (grep(/^\Q$field\E$/,@currfields)) {
7626: $check = ' checked="checked"';
7627: }
7628: $datatable .= '<span class="LC_nobreak"><label>'.
7629: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
7630: ' value="'.$field.'"'.$check.' />'.$field.
7631: '</label></span> ';
7632: }
7633: } elsif ($item eq 'markup') {
1.334 raeburn 7634: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 7635: $currvalidation{$item}.
1.231 raeburn 7636: '</textarea>';
1.235 raeburn 7637: }
7638: $datatable .= '</td></tr>'."\n";
7639: if (ref($rowtotal)) {
1.231 raeburn 7640: $itemcount ++;
7641: }
7642: }
1.235 raeburn 7643: if ($caller eq 'requestcourses') {
7644: my %currhash;
1.248 raeburn 7645: if (ref($settings) eq 'HASH') {
7646: if (ref($settings->{'validation'}) eq 'HASH') {
7647: if ($settings->{'validation'}{'dc'} ne '') {
7648: $currhash{$settings->{'validation'}{'dc'}} = 1;
7649: }
1.235 raeburn 7650: }
7651: }
7652: my $numinrow = 2;
7653: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
7654: 'validationdc',%currhash);
1.247 raeburn 7655: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 7656: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 7657: if ($numdc > 1) {
1.247 raeburn 7658: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 7659: } else {
1.247 raeburn 7660: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 7661: }
1.247 raeburn 7662: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 7663: $itemcount ++;
7664: }
7665: if (ref($rowtotal)) {
7666: $$rowtotal += $itemcount;
7667: }
1.231 raeburn 7668: return $datatable;
7669: }
7670:
1.357 raeburn 7671: sub print_privacy {
7672: my ($position,$dom,$settings,$rowtotal) = @_;
7673: my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
7674: my $itemcount = 0;
1.417 raeburn 7675: if ($position eq 'top') {
7676: $numinrow = 2;
7677: } else {
1.357 raeburn 7678: @items = ('domain','author','course','community');
7679: %names = &Apache::lonlocal::texthash (
7680: domain => 'Assigned domain role(s)',
7681: author => 'Assigned co-author role(s)',
7682: course => 'Assigned course role(s)',
1.416 raeburn 7683: community => 'Assigned community role(s)',
1.357 raeburn 7684: );
7685: $numinrow = 4;
7686: ($othertitle,$usertypes,$types) =
7687: &Apache::loncommon::sorted_inst_types($dom);
7688: }
7689: if (($position eq 'top') || ($position eq 'middle')) {
7690: my (%by_ip,%by_location,@intdoms,@instdoms);
7691: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
7692: if ($position eq 'top') {
7693: my %curr;
7694: my @options = ('none','user','domain','auto');
7695: my %titles = &Apache::lonlocal::texthash (
7696: none => 'Not allowed',
7697: user => 'User authorizes',
7698: domain => 'DC authorizes',
7699: auto => 'Unrestricted',
7700: instdom => 'Other domain shares institution/provider',
7701: extdom => 'Other domain has different institution/provider',
1.418 raeburn 7702: notify => 'Notify when role needs authorization',
1.357 raeburn 7703: );
7704: my %names = &Apache::lonlocal::texthash (
7705: domain => 'Domain role',
7706: author => 'Co-author role',
7707: course => 'Course role',
7708: community => 'Community role',
7709: );
7710: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7711: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7712: foreach my $domtype ('instdom','extdom') {
7713: my (%checked,$skip);
7714: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7715: $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
7716: '<td class="LC_left_item">';
7717: if ($domtype eq 'instdom') {
7718: unless (@instdoms > 1) {
7719: $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
7720: $skip = 1;
7721: }
7722: } elsif ($domtype eq 'extdom') {
7723: if (keys(%by_location) == 0) {
7724: $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
7725: $skip = 1;
7726: }
7727: }
7728: unless ($skip) {
7729: foreach my $roletype ('domain','author','course','community') {
7730: $checked{'auto'} = ' checked="checked"';
7731: if (ref($settings) eq 'HASH') {
7732: if (ref($settings->{approval}) eq 'HASH') {
7733: if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
7734: if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
7735: $checked{$1} = ' checked="checked"';
7736: $checked{'auto'} = '';
7737: }
7738: }
7739: }
7740: }
7741: $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
7742: foreach my $option (@options) {
7743: $datatable .= '<span class="LC_nobreak"><label>'.
7744: '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
7745: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
7746: '</label></span> ';
7747: }
7748: $datatable .= '</fieldset>';
7749: }
7750: }
7751: $datatable .= '</td></tr>';
7752: $itemcount ++;
7753: }
1.417 raeburn 7754: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7755: $datatable .= '<tr'.$css_class.'><td>'.$titles{'notify'}.'</td>'.
7756: '<td class="LC_left_item">';
7757: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7758: my %curr;
7759: if (ref($settings) eq 'HASH') {
7760: if ($settings->{'notify'} ne '') {
7761: map {$curr{$_}=1;} split(/,/,$settings->{'notify'});
7762: }
7763: }
7764: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7765: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
7766: 'privacy_notify',%curr);
7767: if ($numdc > 0) {
7768: $datatable .= $table;
7769: } else {
7770: $datatable .= &mt('There are no active Domain Coordinators');
7771: }
7772: } else {
7773: $datatable .= &mt('Nothing to set here, as there are no other domains');
7774: }
7775: $datatable .='</td></tr>';
1.357 raeburn 7776: } elsif ($position eq 'middle') {
7777: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7778: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7779: foreach my $item (@{$types}) {
7780: $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
7781: $numinrow,$itemcount,'','','','','',
7782: '',$usertypes->{$item});
7783: $itemcount ++;
7784: }
7785: }
7786: $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
7787: $numinrow,$itemcount,'','','','','',
7788: '',$othertitle);
7789: $itemcount ++;
7790: } else {
1.360 raeburn 7791: my (@insttypes,%insttitles);
7792: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7793: @insttypes = @{$types};
7794: %insttitles = %{$usertypes};
7795: }
7796: foreach my $item (@insttypes,'default') {
7797: my $title;
7798: if ($item eq 'default') {
7799: $title = $othertitle;
7800: } else {
7801: $title = $insttitles{$item};
7802: }
7803: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7804: $datatable .= '<tr'.$css_class.'>'.
7805: '<td class="LC_left_item">'.$title.'</td>'.
7806: '<td class="LC_left_item">'.
7807: &mt('Nothing to set here, as there are no other domains').
7808: '</td></tr>';
7809: $itemcount ++;
7810: }
1.357 raeburn 7811: }
7812: }
7813: } else {
7814: my $prefix;
7815: if ($position eq 'lower') {
7816: $prefix = 'priv';
7817: } else {
7818: $prefix = 'unpriv';
7819: }
7820: foreach my $item (@items) {
7821: $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
7822: $numinrow,$itemcount,'','','','','',
7823: '',$names{$item});
7824: $itemcount ++;
7825: }
7826: }
7827: if (ref($rowtotal)) {
7828: $$rowtotal += $itemcount;
7829: }
7830: return $datatable;
7831: }
7832:
1.354 raeburn 7833: sub print_passwords {
7834: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
7835: my ($datatable,$css_class);
7836: my $itemcount = 0;
7837: my %titles = &Apache::lonlocal::texthash (
7838: captcha => '"Forgot Password" CAPTCHA validation',
7839: link => 'Reset link expiration (hours)',
7840: case => 'Case-sensitive usernames/e-mail',
7841: prelink => 'Information required (form 1)',
7842: postlink => 'Information required (form 2)',
7843: emailsrc => 'LON-CAPA e-mail address type(s)',
7844: customtext => 'Domain specific text (HTML)',
7845: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
7846: intauth_check => 'Check bcrypt cost if authenticated',
7847: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
7848: permanent => 'Permanent e-mail address',
7849: critical => 'Critical notification address',
7850: notify => 'Notification address',
7851: min => 'Minimum password length',
7852: max => 'Maximum password length',
7853: chars => 'Required characters',
7854: expire => 'Password expiration (days)',
1.356 raeburn 7855: numsaved => 'Number of previous passwords to save and disallow reuse',
1.354 raeburn 7856: );
7857: if ($position eq 'top') {
7858: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7859: my $shownlinklife = 2;
7860: my $prelink = 'both';
7861: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
7862: if (ref($settings) eq 'HASH') {
7863: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
7864: $shownlinklife = $settings->{resetlink};
7865: }
7866: if (ref($settings->{resetcase}) eq 'ARRAY') {
7867: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
7868: }
7869: if ($settings->{resetprelink} =~ /^(both|either)$/) {
7870: $prelink = $settings->{resetprelink};
7871: }
7872: if (ref($settings->{resetpostlink}) eq 'HASH') {
7873: %postlink = %{$settings->{resetpostlink}};
7874: }
7875: if (ref($settings->{resetemail}) eq 'ARRAY') {
7876: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
7877: }
7878: if ($settings->{resetremove}) {
7879: $nostdtext = 1;
7880: }
7881: if ($settings->{resetcustom}) {
7882: $customurl = $settings->{resetcustom};
7883: }
7884: } else {
7885: if (ref($types) eq 'ARRAY') {
7886: foreach my $item (@{$types}) {
7887: $casesens{$item} = 1;
7888: $postlink{$item} = ['username','email'];
7889: }
7890: }
7891: $casesens{'default'} = 1;
7892: $postlink{'default'} = ['username','email'];
7893: $prelink = 'both';
7894: %emailsrc = (
7895: permanent => 1,
7896: critical => 1,
7897: notify => 1,
7898: );
7899: }
7900: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
7901: $itemcount ++;
7902: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7903: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
7904: '<td class="LC_left_item">'.
7905: '<input type="textbox" value="'.$shownlinklife.'" '.
7906: 'name="passwords_link" size="3" /></td></tr>';
7907: $itemcount ++;
7908: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7909: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
7910: '<td class="LC_left_item">';
7911: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7912: foreach my $item (@{$types}) {
7913: my $checkedcase;
7914: if ($casesens{$item}) {
7915: $checkedcase = ' checked="checked"';
7916: }
7917: $datatable .= '<span class="LC_nobreak"><label>'.
7918: '<input type="checkbox" name="passwords_case_sensitive" value="'.
7919: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369 raeburn 7920: '</span> ';
1.354 raeburn 7921: }
7922: }
7923: my $checkedcase;
7924: if ($casesens{'default'}) {
7925: $checkedcase = ' checked="checked"';
7926: }
7927: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
7928: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
7929: $othertitle.'</label></span></td>';
7930: $itemcount ++;
7931: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7932: my %checkedpre = (
7933: both => ' checked="checked"',
7934: either => '',
7935: );
7936: if ($prelink eq 'either') {
7937: $checkedpre{either} = ' checked="checked"';
7938: $checkedpre{both} = '';
7939: }
7940: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
7941: '<td class="LC_left_item"><span class="LC_nobreak">'.
7942: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
7943: &mt('Both username and e-mail address').'</label></span> '.
7944: '<span class="LC_nobreak"><label>'.
7945: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
7946: &mt('Either username or e-mail address').'</label></span></td></tr>';
7947: $itemcount ++;
7948: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7949: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
7950: '<td class="LC_left_item">';
7951: my %postlinked;
7952: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7953: foreach my $item (@{$types}) {
7954: undef(%postlinked);
7955: $datatable .= '<fieldset style="display: inline-block;">'.
7956: '<legend>'.$usertypes->{$item}.'</legend>';
7957: if (ref($postlink{$item}) eq 'ARRAY') {
7958: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
7959: }
7960: foreach my $field ('email','username') {
7961: my $checked;
7962: if ($postlinked{$field}) {
7963: $checked = ' checked="checked"';
7964: }
7965: $datatable .= '<span class="LC_nobreak"><label>'.
7966: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
7967: $field.'"'.$checked.' />'.$field.'</label>'.
7968: '<span> ';
7969: }
7970: $datatable .= '</fieldset>';
7971: }
7972: }
7973: if (ref($postlink{'default'}) eq 'ARRAY') {
7974: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
7975: }
7976: $datatable .= '<fieldset style="display: inline-block;">'.
7977: '<legend>'.$othertitle.'</legend>';
7978: foreach my $field ('email','username') {
7979: my $checked;
7980: if ($postlinked{$field}) {
7981: $checked = ' checked="checked"';
7982: }
7983: $datatable .= '<span class="LC_nobreak"><label>'.
7984: '<input type="checkbox" name="passwords_postlink_default" value="'.
7985: $field.'"'.$checked.' />'.$field.'</label>'.
7986: '<span> ';
7987: }
7988: $datatable .= '</fieldset></td></tr>';
7989: $itemcount ++;
7990: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7991: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
7992: '<td class="LC_left_item">';
7993: foreach my $type ('permanent','critical','notify') {
7994: my $checkedemail;
7995: if ($emailsrc{$type}) {
7996: $checkedemail = ' checked="checked"';
7997: }
7998: $datatable .= '<span class="LC_nobreak"><label>'.
7999: '<input type="checkbox" name="passwords_emailsrc" value="'.
8000: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
8001: '<span> ';
8002: }
8003: $datatable .= '</td></tr>';
8004: $itemcount ++;
8005: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8006: my $switchserver = &check_switchserver($dom,$confname);
8007: my ($showstd,$noshowstd);
8008: if ($nostdtext) {
8009: $noshowstd = ' checked="checked"';
8010: } else {
8011: $showstd = ' checked="checked"';
8012: }
8013: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
8014: '<td class="LC_left_item"><span class="LC_nobreak">'.
8015: &mt('Retain standard text:').
8016: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
8017: &mt('Yes').'</label>'.' '.
8018: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
8019: &mt('No').'</label></span><br />'.
8020: '<span class="LC_fontsize_small">'.
8021: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
8022: &mt('Include custom text:');
8023: if ($customurl) {
1.369 raeburn 8024: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354 raeburn 8025: undef,undef,undef,undef,'background-color:#ffffff');
8026: $datatable .= '<span class="LC_nobreak"> '.$link.
8027: '<label><input type="checkbox" name="passwords_custom_del"'.
8028: ' value="1" />'.&mt('Delete?').'</label></span>'.
8029: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
8030: }
8031: if ($switchserver) {
8032: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
8033: } else {
8034: $datatable .='<span class="LC_nobreak"> '.
8035: '<input type="file" name="passwords_customfile" /></span>';
8036: }
8037: $datatable .= '</td></tr>';
8038: } elsif ($position eq 'middle') {
8039: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
8040: my @items = ('intauth_cost','intauth_check','intauth_switch');
8041: my %defaults;
8042: if (ref($domconf{'defaults'}) eq 'HASH') {
8043: %defaults = %{$domconf{'defaults'}};
8044: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
8045: $defaults{'intauth_cost'} = 10;
8046: }
8047: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
8048: $defaults{'intauth_check'} = 0;
8049: }
8050: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
8051: $defaults{'intauth_switch'} = 0;
8052: }
8053: } else {
8054: %defaults = (
8055: 'intauth_cost' => 10,
8056: 'intauth_check' => 0,
8057: 'intauth_switch' => 0,
8058: );
8059: }
8060: foreach my $item (@items) {
8061: if ($itemcount%2) {
8062: $css_class = '';
8063: } else {
8064: $css_class = ' class="LC_odd_row" ';
8065: }
8066: $datatable .= '<tr'.$css_class.'>'.
8067: '<td><span class="LC_nobreak">'.$titles{$item}.
8068: '</span></td><td class="LC_left_item" colspan="3">';
8069: if ($item eq 'intauth_switch') {
8070: my @options = (0,1,2);
8071: my %optiondesc = &Apache::lonlocal::texthash (
8072: 0 => 'No',
8073: 1 => 'Yes',
8074: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
8075: );
8076: $datatable .= '<table width="100%">';
8077: foreach my $option (@options) {
8078: my $checked = ' ';
8079: if ($defaults{$item} eq $option) {
8080: $checked = ' checked="checked"';
8081: }
8082: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8083: '<label><input type="radio" name="'.$item.
8084: '" value="'.$option.'"'.$checked.' />'.
8085: $optiondesc{$option}.'</label></span></td></tr>';
8086: }
8087: $datatable .= '</table>';
8088: } elsif ($item eq 'intauth_check') {
8089: my @options = (0,1,2);
8090: my %optiondesc = &Apache::lonlocal::texthash (
8091: 0 => 'No',
8092: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
8093: 2 => 'Yes, disallow login if stored cost is less than domain default',
8094: );
8095: $datatable .= '<table width="100%">';
8096: foreach my $option (@options) {
8097: my $checked = ' ';
8098: my $onclick;
8099: if ($defaults{$item} eq $option) {
8100: $checked = ' checked="checked"';
8101: }
8102: if ($option == 2) {
8103: $onclick = ' onclick="javascript:warnIntAuth(this);"';
8104: }
8105: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8106: '<label><input type="radio" name="'.$item.
8107: '" value="'.$option.'"'.$checked.$onclick.' />'.
8108: $optiondesc{$option}.'</label></span></td></tr>';
8109: }
8110: $datatable .= '</table>';
8111: } else {
8112: $datatable .= '<input type="text" name="'.$item.'" value="'.
8113: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
8114: }
8115: $datatable .= '</td></tr>';
8116: $itemcount ++;
8117: }
8118: } elsif ($position eq 'lower') {
1.405 raeburn 8119: $datatable .= &password_rules('passwords',\$itemcount,$settings);
1.354 raeburn 8120: } else {
1.359 raeburn 8121: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8122: my %ownerchg = (
8123: by => {},
8124: for => {},
8125: );
8126: my %ownertitles = &Apache::lonlocal::texthash (
8127: by => 'Course owner status(es) allowed',
8128: for => 'Student status(es) allowed',
8129: );
1.354 raeburn 8130: if (ref($settings) eq 'HASH') {
1.359 raeburn 8131: if (ref($settings->{crsownerchg}) eq 'HASH') {
8132: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
8133: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
8134: }
8135: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
8136: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
8137: }
1.354 raeburn 8138: }
8139: }
8140: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8141: $datatable .= '<tr '.$css_class.'>'.
8142: '<td>'.
8143: &mt('Requirements').'<ul>'.
1.359 raeburn 8144: '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354 raeburn 8145: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
8146: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359 raeburn 8147: '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354 raeburn 8148: '</ul>'.
8149: '</td>'.
1.359 raeburn 8150: '<td class="LC_left_item">';
8151: foreach my $item ('by','for') {
8152: $datatable .= '<fieldset style="display: inline-block;">'.
8153: '<legend>'.$ownertitles{$item}.'</legend>';
8154: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8155: foreach my $type (@{$types}) {
8156: my $checked;
8157: if ($ownerchg{$item}{$type}) {
8158: $checked = ' checked="checked"';
8159: }
8160: $datatable .= '<span class="LC_nobreak"><label>'.
8161: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
8162: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369 raeburn 8163: '</span> ';
1.359 raeburn 8164: }
8165: }
8166: my $checked;
8167: if ($ownerchg{$item}{'default'}) {
8168: $checked = ' checked="checked"';
8169: }
8170: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
8171: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
8172: $othertitle.'</label></span></fieldset>';
8173: }
8174: $datatable .= '</td></tr>';
1.354 raeburn 8175: }
8176: return $datatable;
8177: }
8178:
1.405 raeburn 8179: sub password_rules {
8180: my ($prefix,$itemcountref,$settings) = @_;
8181: my ($min,$max,%chars,$expire,$numsaved,$numinrow);
8182: my %titles;
8183: if ($prefix eq 'passwords') {
8184: %titles = &Apache::lonlocal::texthash (
8185: min => 'Minimum password length',
8186: max => 'Maximum password length',
8187: chars => 'Required characters',
8188: );
1.421 raeburn 8189: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 8190: %titles = &Apache::lonlocal::texthash (
8191: min => 'Minimum secret length',
8192: max => 'Maximum secret length',
8193: chars => 'Required characters',
8194: );
8195: }
8196: $min = $Apache::lonnet::passwdmin;
8197: my $datatable;
8198: my $itemcount;
8199: if (ref($itemcountref)) {
8200: $itemcount = $$itemcountref;
8201: }
8202: if (ref($settings) eq 'HASH') {
8203: if ($settings->{min}) {
8204: $min = $settings->{min};
8205: }
8206: if ($settings->{max}) {
8207: $max = $settings->{max};
8208: }
8209: if (ref($settings->{chars}) eq 'ARRAY') {
8210: map { $chars{$_} = 1; } (@{$settings->{chars}});
8211: }
1.425 raeburn 8212: if ($prefix eq 'passwords') {
1.405 raeburn 8213: if ($settings->{expire}) {
8214: $expire = $settings->{expire};
8215: }
8216: if ($settings->{numsaved}) {
8217: $numsaved = $settings->{numsaved};
8218: }
8219: }
8220: }
8221: my %rulenames = &Apache::lonlocal::texthash(
8222: uc => 'At least one upper case letter',
8223: lc => 'At least one lower case letter',
8224: num => 'At least one number',
8225: spec => 'At least one non-alphanumeric',
8226: );
8227: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
8228: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
8229: '<td class="LC_left_item"><span class="LC_nobreak">'.
8230: '<input type="text" name="'.$prefix.'_min" value="'.$min.'" size="3" '.
8231: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8232: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
8233: '</span></td></tr>';
8234: $itemcount ++;
8235: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8236: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
8237: '<td class="LC_left_item"><span class="LC_nobreak">'.
8238: '<input type="text" name="'.$prefix.'_max" value="'.$max.'" size="3" '.
8239: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8240: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
8241: '</span></td></tr>';
8242: $itemcount ++;
8243: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8244: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
8245: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
8246: '</span></td>';
8247: my $numinrow = 2;
8248: my @possrules = ('uc','lc','num','spec');
8249: $datatable .= '<td class="LC_left_item"><table>';
8250: for (my $i=0; $i<@possrules; $i++) {
8251: my ($rem,$checked);
8252: if ($chars{$possrules[$i]}) {
8253: $checked = ' checked="checked"';
8254: }
8255: $rem = $i%($numinrow);
8256: if ($rem == 0) {
8257: if ($i > 0) {
8258: $datatable .= '</tr>';
8259: }
8260: $datatable .= '<tr>';
8261: }
8262: $datatable .= '<td><span class="LC_nobreak"><label>'.
8263: '<input type="checkbox" name="'.$prefix.'_chars" value="'.$possrules[$i].'"'.$checked.' />'.
8264: $rulenames{$possrules[$i]}.'</label></span></td>';
8265: }
8266: my $rem = @possrules%($numinrow);
8267: my $colsleft = $numinrow - $rem;
8268: if ($colsleft > 1 ) {
8269: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8270: ' </td>';
8271: } elsif ($colsleft == 1) {
8272: $datatable .= '<td class="LC_left_item"> </td>';
8273: }
8274: $datatable .='</table></td></tr>';
8275: $itemcount ++;
8276: if ($prefix eq 'passwords') {
8277: $titles{'expire'} = &mt('Password expiration (days)');
8278: $titles{'numsaved'} = &mt('Number of previous passwords to save and disallow reuse');
8279: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8280: $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
8281: '<td class="LC_left_item"><span class="LC_nobreak">'.
8282: '<input type="text" name="'.$prefix.'_expire" value="'.$expire.'" size="4" '.
8283: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8284: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
8285: '</span></td></tr>';
8286: $itemcount ++;
8287: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8288: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
8289: '<td class="LC_left_item"><span class="LC_nobreak">'.
8290: '<input type="text" name="'.$prefix.'_numsaved" value="'.$numsaved.'" size="3" '.
8291: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8292: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
8293: '</span></td></tr>';
8294: $itemcount ++;
8295: }
8296: if (ref($itemcountref)) {
8297: $$itemcountref += $itemcount;
8298: }
8299: return $datatable;
8300: }
8301:
1.373 raeburn 8302: sub print_wafproxy {
8303: my ($position,$dom,$settings,$rowtotal) = @_;
8304: my $css_class;
8305: my $itemcount = 0;
8306: my $datatable;
8307: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 8308: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
1.374 raeburn 8309: my %lt = &wafproxy_titles();
1.373 raeburn 8310: foreach my $server (sort(keys(%servers))) {
8311: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
1.381 raeburn 8312: next if ($serverhome eq '');
1.373 raeburn 8313: my $serverdom;
8314: if ($serverhome ne $server) {
8315: $serverdom = &Apache::lonnet::host_domain($serverhome);
1.381 raeburn 8316: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
8317: $othercontrol{$server} = $serverdom;
8318: }
1.373 raeburn 8319: } else {
8320: $serverdom = &Apache::lonnet::host_domain($server);
1.381 raeburn 8321: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
1.373 raeburn 8322: if ($serverdom ne $dom) {
8323: $othercontrol{$server} = $serverdom;
8324: } else {
8325: $setdom = 1;
8326: if (ref($settings) eq 'HASH') {
8327: if (ref($settings->{'alias'}) eq 'HASH') {
8328: $aliases{$dom} = $settings->{'alias'};
1.381 raeburn 8329: if ($aliases{$dom} ne '') {
8330: $showdom = 1;
8331: }
1.373 raeburn 8332: }
1.388 raeburn 8333: if (ref($settings->{'saml'}) eq 'HASH') {
8334: $saml{$dom} = $settings->{'saml'};
8335: }
1.373 raeburn 8336: }
8337: }
8338: }
8339: }
1.381 raeburn 8340: if ($setdom) {
8341: %{$values{$dom}} = ();
8342: if (ref($settings) eq 'HASH') {
8343: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8344: $values{$dom}{$item} = $settings->{$item};
8345: }
8346: }
8347: }
1.373 raeburn 8348: if (keys(%othercontrol)) {
8349: %otherdoms = reverse(%othercontrol);
8350: foreach my $domain (keys(%otherdoms)) {
8351: %{$values{$domain}} = ();
8352: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
1.383 raeburn 8353: if (ref($config{'wafproxy'}) eq 'HASH') {
8354: $aliases{$domain} = $config{'wafproxy'}{'alias'};
1.425 raeburn 8355: if (exists($config{'wafproxy'}{'saml'})) {
1.388 raeburn 8356: $saml{$domain} = $config{'wafproxy'}{'saml'};
8357: }
1.383 raeburn 8358: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8359: $values{$domain}{$item} = $config{'wafproxy'}{$item};
1.373 raeburn 8360: }
8361: }
8362: }
8363: }
8364: if ($position eq 'top') {
8365: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.381 raeburn 8366: my %aliasinfo;
1.373 raeburn 8367: foreach my $server (sort(keys(%servers))) {
1.381 raeburn 8368: $itemcount ++;
8369: my $dom_in_effect;
8370: my $aliasrows = '<tr>'.
1.383 raeburn 8371: '<td class="LC_left_item" style="vertical-align: baseline;">'.
1.433 ! raeburn 8372: &mt('Hostname').': '.
! 8373: '<span class="LC_nobreak LC_cusr_emph">'.
! 8374: &Apache::lonnet::hostname($server).
! 8375: '</span></td><td> </td>';
1.373 raeburn 8376: if ($othercontrol{$server}) {
1.381 raeburn 8377: $dom_in_effect = $othercontrol{$server};
1.388 raeburn 8378: my ($current,$forsaml);
1.383 raeburn 8379: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
8380: $current = $aliases{$dom_in_effect}{$server};
1.373 raeburn 8381: }
1.388 raeburn 8382: if (ref($saml{$dom_in_effect}) eq 'HASH') {
8383: if ($saml{$dom_in_effect}{$server}) {
8384: $forsaml = 1;
8385: }
8386: }
1.383 raeburn 8387: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8388: &mt('Alias').': ';
1.373 raeburn 8389: if ($current) {
1.381 raeburn 8390: $aliasrows .= $current;
1.388 raeburn 8391: if ($forsaml) {
1.396 raeburn 8392: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
1.388 raeburn 8393: }
1.373 raeburn 8394: } else {
1.383 raeburn 8395: $aliasrows .= &mt('None');
1.373 raeburn 8396: }
1.383 raeburn 8397: $aliasrows .= ' <span class="LC_small">('.
8398: &mt('controlled by domain: [_1]',
8399: '<b>'.$dom_in_effect.'</b>').')</span></td>';
1.373 raeburn 8400: } else {
1.381 raeburn 8401: $dom_in_effect = $dom;
1.388 raeburn 8402: my ($current,$samlon,$samloff);
8403: $samloff = ' checked="checked"';
1.373 raeburn 8404: if (ref($aliases{$dom}) eq 'HASH') {
8405: if ($aliases{$dom}{$server}) {
8406: $current = $aliases{$dom}{$server};
8407: }
8408: }
1.388 raeburn 8409: if (ref($saml{$dom}) eq 'HASH') {
8410: if ($saml{$dom}{$server}) {
8411: $samlon = $samloff;
8412: undef($samloff);
8413: }
8414: }
1.383 raeburn 8415: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8416: &mt('Alias').': '.
1.381 raeburn 8417: '<input type="text" name="wafproxy_alias_'.$server.'" '.
1.388 raeburn 8418: 'value="'.$current.'" size="30" />'.
8419: (' 'x2).'<span class="LC_nobreak">'.
1.396 raeburn 8420: &mt('Alias used for SSO Auth').': <label>'.
1.388 raeburn 8421: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
1.425 raeburn 8422: &mt('No').'</label> <label>'.
1.388 raeburn 8423: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
8424: &mt('Yes').'</label></span>'.
1.425 raeburn 8425: '</td>';
1.381 raeburn 8426: }
8427: $aliasrows .= '</tr>';
8428: $aliasinfo{$dom_in_effect} .= $aliasrows;
8429: }
8430: if ($aliasinfo{$dom}) {
8431: my ($onclick,$wafon,$wafoff,$showtable);
8432: $onclick = ' onclick="javascript:toggleWAF();"';
8433: $wafoff = ' checked="checked"';
8434: $showtable = ' style="display:none";';
8435: if ($showdom) {
8436: $wafon = $wafoff;
8437: $wafoff = '';
8438: $showtable = ' style="display:inline;"';
8439: }
8440: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8441: $datatable = '<tr'.$css_class.'>'.
8442: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
8443: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
8444: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
8445: &mt('Yes').'</label>'.(' 'x2).'<label>'.
8446: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
8447: &mt('No').'</label></span></td>'.
8448: '<td class="LC_left_item">'.
8449: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
8450: '</table></td></tr>';
8451: $itemcount++;
8452: }
1.383 raeburn 8453: if (keys(%otherdoms)) {
8454: foreach my $key (sort(keys(%otherdoms))) {
1.381 raeburn 8455: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.383 raeburn 8456: $datatable .= '<tr'.$css_class.'>'.
8457: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
8458: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
8459: '</table></td></tr>';
1.381 raeburn 8460: $itemcount++;
1.373 raeburn 8461: }
8462: }
8463: } else {
1.383 raeburn 8464: my %ip_methods = &remoteip_methods();
1.373 raeburn 8465: if ($setdom) {
8466: $itemcount ++;
8467: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.381 raeburn 8468: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
1.382 raeburn 8469: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
1.381 raeburn 8470: $wafstyle = ' style="display:none;"';
8471: $nowafstyle = ' style="display:table-row;"';
8472: $currwafdisplay = ' style="display: none"';
8473: $wafrangestyle = ' style="display: none"';
8474: $curr_remotip = 'n';
1.382 raeburn 8475: $ssltossl = ' checked="checked"';
1.381 raeburn 8476: if ($showdom) {
8477: $wafstyle = ' style="display:table-row;"';
8478: $nowafstyle = ' style="display:none;"';
8479: if (keys(%{$values{$dom}})) {
8480: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
8481: $curr_remotip = $values{$dom}{remoteip};
8482: }
8483: if ($curr_remotip eq 'h') {
8484: $currwafdisplay = ' style="display:table-row"';
8485: $wafrangestyle = ' style="display:inline-block;"';
8486: }
1.382 raeburn 8487: if ($values{$dom}{'sslopt'}) {
8488: $alltossl = ' checked="checked"';
8489: $ssltossl = '';
8490: }
1.381 raeburn 8491: }
8492: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
8493: $vpndircheck = ' checked="checked"';
8494: $currwafvpn = ' style="display:table-row;"';
8495: $wafrangestyle = ' style="display:inline-block;"';
8496: } else {
8497: $vpnaliascheck = ' checked="checked"';
8498: $currwafvpn = ' style="display:none;"';
8499: }
8500: }
8501: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
8502: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
8503: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
8504: '</tr>'.
8505: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
1.374 raeburn 8506: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
1.381 raeburn 8507: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
1.393 raeburn 8508: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
8509: &mt('Range(s) stored in CIDR notation').'</div></td>'.
1.381 raeburn 8510: '<td class="LC_left_item"><table>'.
8511: '<tr>'.
8512: '<td valign="top">'.$lt{'remoteip'}.': '.
8513: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
8514: foreach my $option ('m','h','n') {
8515: my $sel;
8516: if ($option eq $curr_remotip) {
8517: $sel = ' selected="selected"';
8518: }
8519: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
8520: $ip_methods{$option}.'</option>';
8521: }
8522: $datatable .= '</select></td></tr>'."\n".
8523: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
8524: $lt{'ipheader'}.': '.
8525: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
8526: 'name="wafproxy_ipheader" />'.
8527: '</td></tr>'."\n".
8528: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
1.382 raeburn 8529: $lt{'trusted'}.':<br />'.
1.381 raeburn 8530: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
8531: $values{$dom}{'trusted'}.'</textarea>'.
8532: '</td></tr>'."\n".
8533: '<tr><td><hr /></td></tr>'."\n".
8534: '<tr>'.
8535: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
8536: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
8537: $lt{'vpndirect'}.'</label>'.(' 'x2).
8538: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
8539: $lt{'vpnaliased'}.'</label></span></td></tr>';
8540: foreach my $item ('vpnint','vpnext') {
8541: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
1.382 raeburn 8542: '<td valign="top">'.$lt{$item}.':<br />'.
1.381 raeburn 8543: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
8544: $values{$dom}{$item}.'</textarea>'.
8545: '</td></tr>'."\n";
1.373 raeburn 8546: }
1.382 raeburn 8547: $datatable .= '<tr><td><hr /></td></tr>'."\n".
8548: '<tr>'.
8549: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
8550: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
8551: $lt{'alltossl'}.'</label>'.(' 'x2).
8552: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
8553: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
8554: '</table></td></tr>';
1.373 raeburn 8555: }
8556: if (keys(%otherdoms)) {
8557: foreach my $domain (sort(keys(%otherdoms))) {
8558: $itemcount ++;
8559: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8560: $datatable .= '<tr'.$css_class.'>'.
1.383 raeburn 8561: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
1.374 raeburn 8562: '<td class="LC_left_item"><table>';
1.382 raeburn 8563: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 8564: my $showval = &mt('None');
1.382 raeburn 8565: if ($item eq 'ssl') {
8566: $showval = $lt{'ssltossl'};
8567: }
1.373 raeburn 8568: if ($values{$domain}{$item}) {
1.381 raeburn 8569: $showval = $values{$domain}{$item};
1.382 raeburn 8570: if ($item eq 'ssl') {
8571: $showval = $lt{'alltossl'};
1.383 raeburn 8572: } elsif ($item eq 'remoteip') {
8573: $showval = $ip_methods{$values{$domain}{$item}};
1.382 raeburn 8574: }
1.373 raeburn 8575: }
8576: $datatable .= '<tr>'.
8577: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
8578: }
1.381 raeburn 8579: $datatable .= '</table></td></tr>';
1.373 raeburn 8580: }
8581: }
8582: }
8583: $$rowtotal += $itemcount;
8584: return $datatable;
8585: }
8586:
8587: sub wafproxy_titles {
8588: return &Apache::lonlocal::texthash(
1.381 raeburn 8589: remoteip => "Method for determining user's IP",
8590: ipheader => 'Request header containing remote IP',
8591: trusted => 'Trusted IP range(s)',
8592: vpnaccess => 'Access from institutional VPN',
8593: vpndirect => 'via regular hostname (no WAF)',
8594: vpnaliased => 'via aliased hostname (WAF)',
8595: vpnint => 'Internal IP Range(s) for VPN sessions',
8596: vpnext => 'IP Range(s) for backend WAF connections',
1.382 raeburn 8597: sslopt => 'Forwarding http/https',
1.381 raeburn 8598: alltossl => 'WAF forwards both http and https requests to https',
8599: ssltossl => 'WAF forwards http requests to http and https to https',
8600: );
8601: }
8602:
8603: sub remoteip_methods {
8604: return &Apache::lonlocal::texthash(
8605: m => 'Use Apache mod_remoteip',
8606: h => 'Use headers parsed by LON-CAPA',
8607: n => 'Not in use',
1.373 raeburn 8608: );
8609: }
8610:
1.137 raeburn 8611: sub print_usersessions {
8612: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 8613: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 8614: my (%by_ip,%by_location,@intdoms,@instdoms);
8615: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 8616:
8617: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 8618: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 8619: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 8620: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 8621: if ($position eq 'top') {
1.152 raeburn 8622: if (keys(%serverhomes) > 1) {
1.145 raeburn 8623: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.371 raeburn 8624: my ($curroffloadnow,$curroffloadoth);
1.261 raeburn 8625: if (ref($settings) eq 'HASH') {
8626: if (ref($settings->{'offloadnow'}) eq 'HASH') {
8627: $curroffloadnow = $settings->{'offloadnow'};
8628: }
1.371 raeburn 8629: if (ref($settings->{'offloadoth'}) eq 'HASH') {
8630: $curroffloadoth = $settings->{'offloadoth'};
8631: }
1.261 raeburn 8632: }
1.371 raeburn 8633: my $other_insts = scalar(keys(%by_location));
8634: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
8635: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 8636: } else {
1.140 raeburn 8637: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 8638: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
8639: '</td></tr>';
1.140 raeburn 8640: }
1.137 raeburn 8641: } else {
1.279 raeburn 8642: my %titles = &usersession_titles();
8643: my ($prefix,@types);
8644: if ($position eq 'bottom') {
8645: $prefix = 'remote';
8646: @types = ('version','excludedomain','includedomain');
1.145 raeburn 8647: } else {
1.279 raeburn 8648: $prefix = 'hosted';
8649: @types = ('excludedomain','includedomain');
8650: }
8651: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8652: }
8653: $$rowtotal += $itemcount;
8654: return $datatable;
8655: }
8656:
8657: sub rules_by_location {
8658: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
8659: my ($datatable,$itemcount,$css_class);
8660: if (keys(%{$by_location}) == 0) {
8661: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8662: $datatable = '<tr'.$css_class.'><td colspan="2">'.
8663: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
8664: '</td></tr>';
8665: $itemcount = 1;
8666: } else {
8667: $itemcount = 0;
8668: my $numinrow = 5;
8669: my (%current,%checkedon,%checkedoff);
8670: my @locations = sort(keys(%{$by_location}));
8671: foreach my $type (@{$types}) {
8672: $checkedon{$type} = '';
8673: $checkedoff{$type} = ' checked="checked"';
8674: }
8675: if (ref($settings) eq 'HASH') {
8676: if (ref($settings->{$prefix}) eq 'HASH') {
8677: foreach my $key (keys(%{$settings->{$prefix}})) {
8678: $current{$key} = $settings->{$prefix}{$key};
8679: if ($key eq 'version') {
8680: if ($current{$key} ne '') {
1.145 raeburn 8681: $checkedon{$key} = ' checked="checked"';
8682: $checkedoff{$key} = '';
8683: }
1.279 raeburn 8684: } elsif (ref($current{$key}) eq 'ARRAY') {
8685: $checkedon{$key} = ' checked="checked"';
8686: $checkedoff{$key} = '';
1.137 raeburn 8687: }
8688: }
8689: }
1.279 raeburn 8690: }
8691: foreach my $type (@{$types}) {
8692: next if ($type ne 'version' && !@locations);
8693: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8694: $datatable .= '<tr'.$css_class.'>
8695: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
8696: <span class="LC_nobreak">
8697: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
8698: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
8699: if ($type eq 'version') {
8700: my @lcversions = &Apache::lonnet::all_loncaparevs();
8701: my $selector = '<select name="'.$prefix.'_version">';
8702: foreach my $version (@lcversions) {
8703: my $selected = '';
8704: if ($current{'version'} eq $version) {
8705: $selected = ' selected="selected"';
1.145 raeburn 8706: }
1.279 raeburn 8707: $selector .= ' <option value="'.$version.'"'.
8708: $selected.'>'.$version.'</option>';
8709: }
8710: $selector .= '</select> ';
8711: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
8712: } else {
8713: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
8714: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
8715: ' />'.(' 'x2).
8716: '<input type="button" value="'.&mt('uncheck all').'" '.
8717: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
8718: "\n".
8719: '</div><div><table>';
8720: my $rem;
8721: for (my $i=0; $i<@locations; $i++) {
8722: my ($showloc,$value,$checkedtype);
8723: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
8724: my $ip = $by_location->{$locations[$i]}->[0];
8725: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8726: $value = join(':',@{$by_ip->{$ip}});
8727: $showloc = join(', ',@{$by_ip->{$ip}});
8728: if (ref($current{$type}) eq 'ARRAY') {
8729: foreach my $loc (@{$by_ip->{$ip}}) {
8730: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
8731: $checkedtype = ' checked="checked"';
8732: last;
1.145 raeburn 8733: }
1.138 raeburn 8734: }
8735: }
8736: }
1.137 raeburn 8737: }
1.279 raeburn 8738: $rem = $i%($numinrow);
8739: if ($rem == 0) {
8740: if ($i > 0) {
8741: $datatable .= '</tr>';
8742: }
8743: $datatable .= '<tr>';
8744: }
8745: $datatable .= '<td class="LC_left_item">'.
8746: '<span class="LC_nobreak"><label>'.
8747: '<input type="checkbox" name="'.$prefix.'_'.$type.
8748: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
8749: '</label></span></td>';
8750: }
8751: $rem = @locations%($numinrow);
8752: my $colsleft = $numinrow - $rem;
8753: if ($colsleft > 1 ) {
8754: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8755: ' </td>';
8756: } elsif ($colsleft == 1) {
8757: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 8758: }
1.279 raeburn 8759: $datatable .= '</tr></table>';
1.137 raeburn 8760: }
1.279 raeburn 8761: $datatable .= '</td></tr>';
8762: $itemcount ++;
1.137 raeburn 8763: }
8764: }
1.279 raeburn 8765: return ($datatable,$itemcount);
1.137 raeburn 8766: }
8767:
1.275 raeburn 8768: sub print_ssl {
8769: my ($position,$dom,$settings,$rowtotal) = @_;
8770: my ($css_class,$datatable);
8771: my $itemcount = 1;
8772: if ($position eq 'top') {
1.281 raeburn 8773: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8774: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8775: my $same_institution;
8776: if ($intdom ne '') {
8777: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
8778: if (ref($internet_names) eq 'ARRAY') {
8779: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
8780: $same_institution = 1;
8781: }
8782: }
8783: }
1.275 raeburn 8784: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 8785: $datatable = '<tr'.$css_class.'><td colspan="2">';
8786: if ($same_institution) {
8787: my %domservers = &Apache::lonnet::get_servers($dom);
8788: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
8789: } else {
8790: $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.");
8791: }
8792: $datatable .= '</td></tr>';
1.275 raeburn 8793: $itemcount ++;
8794: } else {
8795: my %titles = &ssl_titles();
8796: my (%by_ip,%by_location,@intdoms,@instdoms);
8797: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8798: my @alldoms = &Apache::lonnet::all_domains();
8799: my %serverhomes = %Apache::lonnet::serverhomeIDs;
8800: my @domservers = &Apache::lonnet::get_servers($dom);
8801: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8802: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 8803: if (($position eq 'connto') || ($position eq 'connfrom')) {
8804: my $legacy;
8805: unless (ref($settings) eq 'HASH') {
8806: my $name;
8807: if ($position eq 'connto') {
8808: $name = 'loncAllowInsecure';
8809: } else {
8810: $name = 'londAllowInsecure';
8811: }
8812: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
8813: my @ids=&Apache::lonnet::current_machine_ids();
8814: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
8815: my %what = (
8816: $name => 1,
8817: );
8818: my ($result,$returnhash) =
8819: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
8820: if ($result eq 'ok') {
8821: if (ref($returnhash) eq 'HASH') {
8822: $legacy = $returnhash->{$name};
8823: }
8824: }
8825: } else {
8826: $legacy = $Apache::lonnet::perlvar{$name};
8827: }
8828: }
1.275 raeburn 8829: foreach my $type ('dom','intdom','other') {
8830: my %checked;
8831: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8832: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
8833: '<td class="LC_right_item">';
8834: my $skip;
8835: if ($type eq 'dom') {
8836: unless (keys(%servers) > 1) {
8837: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
8838: $skip = 1;
8839: }
8840: }
8841: if ($type eq 'intdom') {
8842: unless (@instdoms > 1) {
8843: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
8844: $skip = 1;
8845: }
8846: } elsif ($type eq 'other') {
8847: if (keys(%by_location) == 0) {
8848: $datatable .= &mt('Nothing to set here, as there are no other institutions');
8849: $skip = 1;
8850: }
8851: }
8852: unless ($skip) {
8853: $checked{'yes'} = ' checked="checked"';
8854: if (ref($settings) eq 'HASH') {
1.293 raeburn 8855: if (ref($settings->{$position}) eq 'HASH') {
8856: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 8857: $checked{$1} = $checked{'yes'};
8858: delete($checked{'yes'});
8859: }
8860: }
1.293 raeburn 8861: } else {
8862: if ($legacy == 0) {
8863: $checked{'req'} = $checked{'yes'};
8864: delete($checked{'yes'});
8865: }
1.275 raeburn 8866: }
8867: foreach my $option ('no','yes','req') {
8868: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 8869: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 8870: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
8871: '</label></span>'.(' 'x2);
8872: }
8873: }
8874: $datatable .= '</td></tr>';
8875: $itemcount ++;
8876: }
8877: } else {
8878: my $prefix = 'replication';
8879: my @types = ('certreq','nocertreq');
1.279 raeburn 8880: if (keys(%by_location) == 0) {
8881: $datatable .= '<tr'.$css_class.'><td>'.
8882: &mt('Nothing to set here, as there are no other institutions').
8883: '</td></tr>';
8884: $itemcount ++;
1.275 raeburn 8885: } else {
1.279 raeburn 8886: ($datatable,$itemcount) =
8887: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 8888: }
8889: }
8890: }
8891: $$rowtotal += $itemcount;
8892: return $datatable;
8893: }
8894:
8895: sub ssl_titles {
8896: return &Apache::lonlocal::texthash (
8897: dom => 'LON-CAPA servers/VMs from same domain',
8898: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
8899: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 8900: connto => 'Connections to other servers',
8901: connfrom => 'Connections from other servers',
1.275 raeburn 8902: replication => 'Replicating content to other institutions',
8903: certreq => 'Client certificate required, but specific domains exempt',
8904: nocertreq => 'No client certificate required, except for specific domains',
8905: no => 'SSL not used',
8906: yes => 'SSL Optional (used if available)',
8907: req => 'SSL Required',
8908: );
1.279 raeburn 8909: }
8910:
8911: sub print_trust {
8912: my ($prefix,$dom,$settings,$rowtotal) = @_;
8913: my ($css_class,$datatable,%checked,%choices);
8914: my (%by_ip,%by_location,@intdoms,@instdoms);
8915: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8916: my $itemcount = 1;
8917: my %titles = &trust_titles();
8918: my @types = ('exc','inc');
8919: if ($prefix eq 'top') {
8920: $prefix = 'content';
8921: } elsif ($prefix eq 'bottom') {
8922: $prefix = 'msg';
8923: }
8924: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8925: $$rowtotal += $itemcount;
8926: return $datatable;
8927: }
8928:
8929: sub trust_titles {
8930: return &Apache::lonlocal::texthash(
8931: content => "Access to this domain's content by others",
8932: shared => "Access to other domain's content by this domain",
8933: enroll => "Enrollment in this domain's courses by others",
8934: othcoau => "Co-author roles in this domain for others",
8935: coaurem => "Co-author roles for this domain's users elsewhere",
8936: domroles => "Domain roles in this domain assignable to others",
8937: catalog => "Course Catalog for this domain displayed elsewhere",
8938: reqcrs => "Requests for creation of courses in this domain by others",
8939: msg => "Users in other domains can send messages to this domain",
8940: exc => "Allow all, but exclude specific domains",
8941: inc => "Deny all, but include specific domains",
8942: );
1.275 raeburn 8943: }
8944:
1.138 raeburn 8945: sub build_location_hashes {
1.275 raeburn 8946: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 8947: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 8948: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 8949: my %iphost = &Apache::lonnet::get_iphost();
8950: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
8951: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
8952: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
8953: foreach my $id (@{$iphost{$primary_ip}}) {
8954: my $intdom = &Apache::lonnet::internet_dom($id);
8955: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
8956: push(@{$intdoms},$intdom);
8957: }
8958: }
8959: }
8960: foreach my $ip (keys(%iphost)) {
8961: if (ref($iphost{$ip}) eq 'ARRAY') {
8962: foreach my $id (@{$iphost{$ip}}) {
8963: my $location = &Apache::lonnet::internet_dom($id);
8964: if ($location) {
1.275 raeburn 8965: if (grep(/^\Q$location\E$/,@{$intdoms})) {
8966: my $dom = &Apache::lonnet::host_domain($id);
8967: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
8968: push(@{$instdoms},$dom);
8969: }
8970: next;
8971: }
1.138 raeburn 8972: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8973: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
8974: push(@{$by_ip->{$ip}},$location);
8975: }
8976: } else {
8977: $by_ip->{$ip} = [$location];
8978: }
8979: }
8980: }
8981: }
8982: }
8983: foreach my $ip (sort(keys(%{$by_ip}))) {
8984: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8985: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
8986: my $first = $by_ip->{$ip}->[0];
8987: if (ref($by_location->{$first}) eq 'ARRAY') {
8988: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
8989: push(@{$by_location->{$first}},$ip);
8990: }
8991: } else {
8992: $by_location->{$first} = [$ip];
8993: }
8994: }
8995: }
8996: return;
8997: }
8998:
1.145 raeburn 8999: sub current_offloads_to {
9000: my ($dom,$settings,$servers) = @_;
9001: my (%spareid,%otherdomconfigs);
1.152 raeburn 9002: if (ref($servers) eq 'HASH') {
1.145 raeburn 9003: foreach my $lonhost (sort(keys(%{$servers}))) {
9004: my $gotspares;
1.152 raeburn 9005: if (ref($settings) eq 'HASH') {
9006: if (ref($settings->{'spares'}) eq 'HASH') {
9007: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
9008: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
9009: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
9010: $gotspares = 1;
9011: }
1.145 raeburn 9012: }
9013: }
9014: unless ($gotspares) {
9015: my $gotspares;
9016: my $serverhomeID =
9017: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
9018: my $serverhomedom =
9019: &Apache::lonnet::host_domain($serverhomeID);
9020: if ($serverhomedom ne $dom) {
9021: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
9022: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
9023: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
9024: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
9025: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
9026: $gotspares = 1;
9027: }
9028: }
9029: } else {
9030: $otherdomconfigs{$serverhomedom} =
9031: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
9032: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
9033: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
9034: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
9035: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
9036: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
9037: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
9038: $gotspares = 1;
9039: }
9040: }
9041: }
9042: }
9043: }
9044: }
9045: }
9046: unless ($gotspares) {
9047: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
9048: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9049: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9050: } else {
9051: my $server_hostname = &Apache::lonnet::hostname($lonhost);
9052: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
9053: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
9054: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9055: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9056: } else {
1.150 raeburn 9057: my %what = (
9058: spareid => 1,
9059: );
9060: my ($result,$returnhash) =
9061: &Apache::lonnet::get_remote_globals($lonhost,\%what);
9062: if ($result eq 'ok') {
9063: if (ref($returnhash) eq 'HASH') {
9064: if (ref($returnhash->{'spareid'}) eq 'HASH') {
9065: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
9066: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
9067: }
9068: }
1.145 raeburn 9069: }
9070: }
9071: }
9072: }
9073: }
9074: }
9075: return %spareid;
9076: }
9077:
9078: sub spares_row {
1.371 raeburn 9079: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
9080: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 9081: my $css_class;
9082: my $numinrow = 4;
9083: my $itemcount = 1;
9084: my $datatable;
1.152 raeburn 9085: my %typetitles = &sparestype_titles();
9086: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 9087: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 9088: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
9089: my ($othercontrol,$serverdom);
9090: if ($serverhome ne $server) {
9091: $serverdom = &Apache::lonnet::host_domain($serverhome);
9092: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9093: } else {
9094: $serverdom = &Apache::lonnet::host_domain($server);
9095: if ($serverdom ne $dom) {
9096: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9097: }
9098: }
9099: next unless (ref($spareid->{$server}) eq 'HASH');
1.371 raeburn 9100: my ($checkednow,$checkedoth);
1.261 raeburn 9101: if (ref($curroffloadnow) eq 'HASH') {
9102: if ($curroffloadnow->{$server}) {
9103: $checkednow = ' checked="checked"';
9104: }
9105: }
1.371 raeburn 9106: if (ref($curroffloadoth) eq 'HASH') {
9107: if ($curroffloadoth->{$server}) {
9108: $checkedoth = ' checked="checked"';
9109: }
9110: }
1.145 raeburn 9111: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
9112: $datatable .= '<tr'.$css_class.'>
9113: <td rowspan="2">
1.183 bisitz 9114: <span class="LC_nobreak">'.
9115: &mt('[_1] when busy, offloads to:'
1.261 raeburn 9116: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 9117: '<span class="LC_nobreak">'."\n".
1.261 raeburn 9118: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.371 raeburn 9119: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.183 bisitz 9120: "\n";
1.371 raeburn 9121: if ($other_insts) {
9122: $datatable .= '<br />'.
9123: '<span class="LC_nobreak">'."\n".
9124: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
9125: ' '.&mt('Switch other institutions on next access').'</label></span>'.
9126: "\n";
9127: }
1.145 raeburn 9128: my (%current,%canselect);
1.152 raeburn 9129: my @choices =
9130: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
9131: foreach my $type ('primary','default') {
9132: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 9133: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
9134: my @spares = @{$spareid->{$server}{$type}};
9135: if (@spares > 0) {
1.152 raeburn 9136: if ($othercontrol) {
9137: $current{$type} = join(', ',@spares);
9138: } else {
9139: $current{$type} .= '<table>';
9140: my $numspares = scalar(@spares);
9141: for (my $i=0; $i<@spares; $i++) {
9142: my $rem = $i%($numinrow);
9143: if ($rem == 0) {
9144: if ($i > 0) {
9145: $current{$type} .= '</tr>';
9146: }
9147: $current{$type} .= '<tr>';
1.145 raeburn 9148: }
1.152 raeburn 9149: $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'".');" /> '.
9150: $spareid->{$server}{$type}[$i].
9151: '</label></td>'."\n";
9152: }
9153: my $rem = @spares%($numinrow);
9154: my $colsleft = $numinrow - $rem;
9155: if ($colsleft > 1 ) {
9156: $current{$type} .= '<td colspan="'.$colsleft.
9157: '" class="LC_left_item">'.
9158: ' </td>';
9159: } elsif ($colsleft == 1) {
9160: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 9161: }
1.152 raeburn 9162: $current{$type} .= '</tr></table>';
1.150 raeburn 9163: }
1.145 raeburn 9164: }
9165: }
9166: if ($current{$type} eq '') {
9167: $current{$type} = &mt('None specified');
9168: }
1.152 raeburn 9169: if ($othercontrol) {
9170: if ($type eq 'primary') {
9171: $canselect{$type} = $othercontrol;
9172: }
9173: } else {
9174: $canselect{$type} =
9175: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
9176: '<select name="newspare_'.$type.'_'.$server.'" '.
9177: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
9178: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
9179: if (@choices > 0) {
9180: foreach my $lonhost (@choices) {
9181: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
9182: }
9183: }
9184: $canselect{$type} .= '</select>'."\n";
9185: }
9186: } else {
9187: $current{$type} = &mt('Could not be determined');
9188: if ($type eq 'primary') {
9189: $canselect{$type} = $othercontrol;
9190: }
1.145 raeburn 9191: }
1.152 raeburn 9192: if ($type eq 'default') {
9193: $datatable .= '<tr'.$css_class.'>';
9194: }
9195: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
9196: '<td>'.$current{$type}.'</td>'."\n".
9197: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 9198: }
9199: $itemcount ++;
9200: }
9201: }
9202: $$rowtotal += $itemcount;
9203: return $datatable;
9204: }
9205:
1.152 raeburn 9206: sub possible_newspares {
9207: my ($server,$currspares,$serverhomes,$altids) = @_;
9208: my $serverhostname = &Apache::lonnet::hostname($server);
9209: my %excluded;
9210: if ($serverhostname ne '') {
9211: %excluded = (
9212: $serverhostname => 1,
9213: );
9214: }
9215: if (ref($currspares) eq 'HASH') {
9216: foreach my $type (keys(%{$currspares})) {
9217: if (ref($currspares->{$type}) eq 'ARRAY') {
9218: if (@{$currspares->{$type}} > 0) {
9219: foreach my $curr (@{$currspares->{$type}}) {
9220: my $hostname = &Apache::lonnet::hostname($curr);
9221: $excluded{$hostname} = 1;
9222: }
9223: }
9224: }
9225: }
9226: }
9227: my @choices;
9228: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
9229: if (keys(%{$serverhomes}) > 1) {
9230: foreach my $name (sort(keys(%{$serverhomes}))) {
9231: unless ($excluded{$name}) {
9232: if (exists($altids->{$serverhomes->{$name}})) {
9233: push(@choices,$altids->{$serverhomes->{$name}});
9234: } else {
9235: push(@choices,$serverhomes->{$name});
1.145 raeburn 9236: }
9237: }
9238: }
9239: }
9240: }
1.152 raeburn 9241: return sort(@choices);
1.145 raeburn 9242: }
9243:
1.150 raeburn 9244: sub print_loadbalancing {
9245: my ($dom,$settings,$rowtotal) = @_;
9246: my $primary_id = &Apache::lonnet::domain($dom,'primary');
9247: my $intdom = &Apache::lonnet::internet_dom($primary_id);
9248: my $numinrow = 1;
9249: my $datatable;
9250: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 9251: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 9252: if (ref($settings) eq 'HASH') {
9253: %existing = %{$settings};
9254: }
9255: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
9256: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 9257: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 9258: } else {
9259: return;
9260: }
9261: my ($othertitle,$usertypes,$types) =
9262: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 9263: my $rownum = 8;
1.150 raeburn 9264: if (ref($types) eq 'ARRAY') {
9265: $rownum += scalar(@{$types});
9266: }
1.171 raeburn 9267: my @css_class = ('LC_odd_row','LC_even_row');
9268: my $balnum = 0;
9269: my $islast;
9270: my (@toshow,$disabledtext);
9271: if (keys(%currbalancer) > 0) {
9272: @toshow = sort(keys(%currbalancer));
9273: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
9274: push(@toshow,'');
9275: }
9276: } else {
9277: @toshow = ('');
9278: $disabledtext = &mt('No existing load balancer');
9279: }
9280: foreach my $lonhost (@toshow) {
9281: if ($balnum == scalar(@toshow)-1) {
9282: $islast = 1;
9283: } else {
9284: $islast = 0;
9285: }
9286: my $cssidx = $balnum%2;
9287: my $targets_div_style = 'display: none';
9288: my $disabled_div_style = 'display: block';
9289: my $homedom_div_style = 'display: none';
9290: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 9291: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9292: '<p>';
9293: if ($lonhost eq '') {
1.210 raeburn 9294: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 9295: if (keys(%currbalancer) > 0) {
9296: $datatable .= &mt('Add balancer:');
9297: } else {
9298: $datatable .= &mt('Enable balancer:');
9299: }
9300: $datatable .= ' '.
9301: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
9302: ' id="loadbalancing_lonhost_'.$balnum.'"'.
9303: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
9304: '<option value="" selected="selected">'.&mt('None').
9305: '</option>'."\n";
9306: foreach my $server (sort(keys(%servers))) {
9307: next if ($currbalancer{$server});
9308: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
9309: }
1.210 raeburn 9310: $datatable .=
1.171 raeburn 9311: '</select>'."\n".
9312: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
9313: } else {
9314: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
9315: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
9316: &mt('Stop balancing').'</label>'.
9317: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
9318: $targets_div_style = 'display: block';
9319: $disabled_div_style = 'display: none';
9320: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
9321: $homedom_div_style = 'display: block';
9322: }
9323: }
1.306 raeburn 9324: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9325: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
9326: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
9327: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
9328: my ($numspares,@spares) = &count_servers($lonhost,%servers);
9329: my @sparestypes = ('primary','default');
9330: my %typetitles = &sparestype_titles();
1.284 raeburn 9331: my %hostherechecked = (
9332: no => ' checked="checked"',
9333: );
1.342 raeburn 9334: my %balcookiechecked = (
1.425 raeburn 9335: no => ' checked="checked"',
1.342 raeburn 9336: );
1.171 raeburn 9337: foreach my $sparetype (@sparestypes) {
9338: my $targettable;
9339: for (my $i=0; $i<$numspares; $i++) {
9340: my $checked;
9341: if (ref($currtargets{$lonhost}) eq 'HASH') {
9342: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9343: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9344: $checked = ' checked="checked"';
9345: }
9346: }
9347: }
9348: my ($chkboxval,$disabled);
9349: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
9350: $chkboxval = $spares[$i];
9351: }
9352: if (exists($currbalancer{$spares[$i]})) {
9353: $disabled = ' disabled="disabled"';
9354: }
1.210 raeburn 9355: $targettable .=
1.253 raeburn 9356: '<td><span class="LC_nobreak"><label>'.
9357: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 9358: $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 9359: '</span></label></span></td>';
1.171 raeburn 9360: my $rem = $i%($numinrow);
9361: if ($rem == 0) {
9362: if (($i > 0) && ($i < $numspares-1)) {
9363: $targettable .= '</tr>';
9364: }
9365: if ($i < $numspares-1) {
9366: $targettable .= '<tr>';
1.150 raeburn 9367: }
9368: }
9369: }
1.171 raeburn 9370: if ($targettable ne '') {
9371: my $rem = $numspares%($numinrow);
9372: my $colsleft = $numinrow - $rem;
9373: if ($colsleft > 1 ) {
9374: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9375: ' </td>';
9376: } elsif ($colsleft == 1) {
9377: $targettable .= '<td class="LC_left_item"> </td>';
9378: }
9379: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
9380: '<table><tr>'.$targettable.'</tr></table><br />';
9381: }
1.284 raeburn 9382: $hostherechecked{$sparetype} = '';
9383: if (ref($currtargets{$lonhost}) eq 'HASH') {
9384: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9385: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9386: $hostherechecked{$sparetype} = ' checked="checked"';
9387: $hostherechecked{'no'} = '';
9388: }
9389: }
9390: }
9391: }
1.342 raeburn 9392: if ($currcookies{$lonhost}) {
9393: %balcookiechecked = (
9394: yes => ' checked="checked"',
9395: );
9396: }
1.284 raeburn 9397: $datatable .= &mt('Hosting on balancer itself').'<br />'.
9398: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
9399: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
9400: foreach my $sparetype (@sparestypes) {
9401: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
9402: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
9403: '</i></label><br />';
1.171 raeburn 9404: }
1.342 raeburn 9405: $datatable .= &mt('Use balancer cookie').'<br />'.
9406: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
9407: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
9408: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
9409: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
9410: '</div></td></tr>'.
1.171 raeburn 9411: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
9412: $othertitle,$usertypes,$types,\%servers,
9413: \%currbalancer,$lonhost,
9414: $targets_div_style,$homedom_div_style,
9415: $css_class[$cssidx],$balnum,$islast);
9416: $$rowtotal += $rownum;
9417: $balnum ++;
9418: }
9419: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
9420: return $datatable;
9421: }
9422:
9423: sub get_loadbalancers_config {
1.342 raeburn 9424: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 9425: return unless ((ref($servers) eq 'HASH') &&
9426: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 9427: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
9428: (ref($currcookies) eq 'HASH'));
1.171 raeburn 9429: if (keys(%{$existing}) > 0) {
9430: my $oldlonhost;
9431: foreach my $key (sort(keys(%{$existing}))) {
9432: if ($key eq 'lonhost') {
9433: $oldlonhost = $existing->{'lonhost'};
9434: $currbalancer->{$oldlonhost} = 1;
9435: } elsif ($key eq 'targets') {
9436: if ($oldlonhost) {
9437: $currtargets->{$oldlonhost} = $existing->{'targets'};
9438: }
9439: } elsif ($key eq 'rules') {
9440: if ($oldlonhost) {
9441: $currrules->{$oldlonhost} = $existing->{'rules'};
9442: }
9443: } elsif (ref($existing->{$key}) eq 'HASH') {
9444: $currbalancer->{$key} = 1;
9445: $currtargets->{$key} = $existing->{$key}{'targets'};
9446: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 9447: if ($existing->{$key}{'cookie'}) {
9448: $currcookies->{$key} = 1;
9449: }
1.150 raeburn 9450: }
9451: }
1.171 raeburn 9452: } else {
9453: my ($balancerref,$targetsref) =
9454: &Apache::lonnet::get_lonbalancer_config($servers);
9455: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
9456: foreach my $server (sort(keys(%{$balancerref}))) {
9457: $currbalancer->{$server} = 1;
9458: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 9459: }
9460: }
9461: }
1.171 raeburn 9462: return;
1.150 raeburn 9463: }
9464:
9465: sub loadbalancing_rules {
9466: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 9467: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
9468: $css_class,$balnum,$islast) = @_;
1.150 raeburn 9469: my $output;
1.171 raeburn 9470: my $num = 0;
1.210 raeburn 9471: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 9472: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
9473: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
9474: foreach my $type (@{$alltypes}) {
1.171 raeburn 9475: $num ++;
1.150 raeburn 9476: my $current;
9477: if (ref($currrules) eq 'HASH') {
9478: $current = $currrules->{$type};
9479: }
1.253 raeburn 9480: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 9481: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 9482: $current = '';
9483: }
9484: }
9485: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 9486: $servers,$currbalancer,$lonhost,$dom,
9487: $targets_div_style,$homedom_div_style,
9488: $css_class,$balnum,$num,$islast);
1.150 raeburn 9489: }
9490: }
9491: return $output;
9492: }
9493:
9494: sub loadbalancing_titles {
9495: my ($dom,$intdom,$usertypes,$types) = @_;
9496: my %othertypes = (
9497: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
9498: '_LC_author' => &mt('Users from [_1] with author role',$dom),
9499: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
9500: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 9501: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
9502: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 9503: );
1.209 raeburn 9504: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 9505: my @available;
1.150 raeburn 9506: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9507: @available = @{$types};
1.150 raeburn 9508: }
1.302 raeburn 9509: unless (grep(/^default$/,@available)) {
9510: push(@available,'default');
9511: }
9512: unshift(@alltypes,@available);
1.150 raeburn 9513: my %titles;
9514: foreach my $type (@alltypes) {
9515: if ($type =~ /^_LC_/) {
9516: $titles{$type} = $othertypes{$type};
9517: } elsif ($type eq 'default') {
9518: $titles{$type} = &mt('All users from [_1]',$dom);
9519: if (ref($types) eq 'ARRAY') {
9520: if (@{$types} > 0) {
9521: $titles{$type} = &mt('Other users from [_1]',$dom);
9522: }
9523: }
9524: } elsif (ref($usertypes) eq 'HASH') {
9525: $titles{$type} = $usertypes->{$type};
9526: }
9527: }
9528: return (\@alltypes,\%othertypes,\%titles);
9529: }
9530:
9531: sub loadbalance_rule_row {
1.171 raeburn 9532: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
9533: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 9534: my @rulenames;
1.150 raeburn 9535: my %ruletitles = &offloadtype_text();
1.209 raeburn 9536: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 9537: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 9538: } else {
1.209 raeburn 9539: @rulenames = ('default','homeserver');
9540: if ($type eq '_LC_external') {
9541: push(@rulenames,'externalbalancer');
9542: } else {
9543: push(@rulenames,'specific');
9544: }
9545: push(@rulenames,'none');
1.150 raeburn 9546: }
9547: my $style = $targets_div_style;
1.253 raeburn 9548: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 9549: $style = $homedom_div_style;
9550: }
1.171 raeburn 9551: my $space;
9552: if ($islast && $num == 1) {
1.317 raeburn 9553: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 9554: }
1.210 raeburn 9555: my $output =
1.306 raeburn 9556: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 9557: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
9558: '<td valaign="top">'.$space.
9559: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 9560: for (my $i=0; $i<@rulenames; $i++) {
9561: my $rule = $rulenames[$i];
9562: my ($checked,$extra);
9563: if ($rulenames[$i] eq 'default') {
9564: $rule = '';
9565: }
9566: if ($rulenames[$i] eq 'specific') {
9567: if (ref($servers) eq 'HASH') {
9568: my $default;
9569: if (($current ne '') && (exists($servers->{$current}))) {
9570: $checked = ' checked="checked"';
9571: }
9572: unless ($checked) {
9573: $default = ' selected="selected"';
9574: }
1.210 raeburn 9575: $extra =
1.171 raeburn 9576: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
9577: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
9578: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
9579: '<option value=""'.$default.'></option>'."\n";
9580: foreach my $server (sort(keys(%{$servers}))) {
9581: if (ref($currbalancer) eq 'HASH') {
9582: next if (exists($currbalancer->{$server}));
9583: }
1.150 raeburn 9584: my $selected;
1.171 raeburn 9585: if ($server eq $current) {
1.150 raeburn 9586: $selected = ' selected="selected"';
9587: }
1.171 raeburn 9588: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 9589: }
9590: $extra .= '</select>';
9591: }
9592: } elsif ($rule eq $current) {
9593: $checked = ' checked="checked"';
9594: }
9595: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 9596: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
9597: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
9598: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 9599: ')"'.$checked.' /> ';
9600: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
9601: $output .= $ruletitles{'particular'};
9602: } else {
9603: $output .= $ruletitles{$rulenames[$i]};
9604: }
9605: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 9606: }
9607: $output .= '</div></td></tr>'."\n";
9608: return $output;
9609: }
9610:
9611: sub offloadtype_text {
9612: my %ruletitles = &Apache::lonlocal::texthash (
9613: 'default' => 'Offloads to default destinations',
9614: 'homeserver' => "Offloads to user's home server",
9615: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
9616: 'specific' => 'Offloads to specific server',
1.161 raeburn 9617: 'none' => 'No offload',
1.209 raeburn 9618: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
9619: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 9620: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 9621: );
9622: return %ruletitles;
9623: }
9624:
9625: sub sparestype_titles {
9626: my %typestitles = &Apache::lonlocal::texthash (
9627: 'primary' => 'primary',
9628: 'default' => 'default',
9629: );
9630: return %typestitles;
9631: }
9632:
1.28 raeburn 9633: sub contact_titles {
9634: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 9635: 'supportemail' => 'Support E-mail address',
9636: 'adminemail' => 'Default Server Admin E-mail address',
9637: 'errormail' => 'Error reports to be e-mailed to',
9638: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 9639: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
9640: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 9641: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
9642: 'requestsmail' => 'E-mail from course requests requiring approval',
9643: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 9644: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350 raeburn 9645: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.378 raeburn 9646: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
9647: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.340 raeburn 9648: 'errorweights' => 'Weights used to compute error count',
9649: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 9650: );
9651: my %short_titles = &Apache::lonlocal::texthash (
9652: adminemail => 'Admin E-mail address',
9653: supportemail => 'Support E-mail',
9654: );
9655: return (\%titles,\%short_titles);
9656: }
9657:
1.286 raeburn 9658: sub helpform_fields {
9659: my %titles = &Apache::lonlocal::texthash (
9660: 'username' => 'Name',
9661: 'user' => 'Username/domain',
9662: 'phone' => 'Phone',
9663: 'cc' => 'Cc e-mail',
9664: 'course' => 'Course Details',
9665: 'section' => 'Sections',
1.289 raeburn 9666: 'screenshot' => 'File upload',
1.286 raeburn 9667: );
9668: my @fields = ('username','phone','user','course','section','cc','screenshot');
9669: my %possoptions = (
9670: username => ['yes','no','req'],
1.289 raeburn 9671: phone => ['yes','no','req'],
1.286 raeburn 9672: user => ['yes','no'],
1.289 raeburn 9673: cc => ['yes','no'],
1.286 raeburn 9674: course => ['yes','no'],
9675: section => ['yes','no'],
9676: screenshot => ['yes','no'],
9677: );
9678: my %fieldoptions = &Apache::lonlocal::texthash (
9679: 'yes' => 'Optional',
9680: 'req' => 'Required',
9681: 'no' => "Not shown",
9682: );
9683: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
9684: }
9685:
1.72 raeburn 9686: sub tool_titles {
9687: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 9688: aboutme => 'Personal web page',
1.86 raeburn 9689: blog => 'Blog',
9690: portfolio => 'Portfolio',
1.430 raeburn 9691: portaccess => 'Share portfolio files',
1.413 raeburn 9692: timezone => 'Can set time zone',
1.88 bisitz 9693: official => 'Official courses (with institutional codes)',
9694: unofficial => 'Unofficial courses',
1.98 raeburn 9695: community => 'Communities',
1.216 raeburn 9696: textbook => 'Textbook courses',
1.271 raeburn 9697: placement => 'Placement tests',
1.86 raeburn 9698: );
1.72 raeburn 9699: return %titles;
9700: }
9701:
1.101 raeburn 9702: sub courserequest_titles {
9703: my %titles = &Apache::lonlocal::texthash (
9704: official => 'Official',
9705: unofficial => 'Unofficial',
9706: community => 'Communities',
1.216 raeburn 9707: textbook => 'Textbook',
1.271 raeburn 9708: placement => 'Placement tests',
1.325 raeburn 9709: lti => 'LTI Provider',
1.101 raeburn 9710: norequest => 'Not allowed',
1.325 raeburn 9711: approval => 'Approval by DC',
1.101 raeburn 9712: validate => 'With validation',
9713: autolimit => 'Numerical limit',
1.103 raeburn 9714: unlimited => '(blank for unlimited)',
1.101 raeburn 9715: );
9716: return %titles;
9717: }
9718:
1.163 raeburn 9719: sub authorrequest_titles {
9720: my %titles = &Apache::lonlocal::texthash (
9721: norequest => 'Not allowed',
9722: approval => 'Approval by Dom. Coord.',
9723: automatic => 'Automatic approval',
9724: );
9725: return %titles;
1.210 raeburn 9726: }
1.163 raeburn 9727:
1.101 raeburn 9728: sub courserequest_conditions {
9729: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 9730: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 9731: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 9732: );
9733: return %conditions;
9734: }
9735:
9736:
1.27 raeburn 9737: sub print_usercreation {
1.30 raeburn 9738: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 9739: my $numinrow = 4;
1.28 raeburn 9740: my $datatable;
9741: if ($position eq 'top') {
1.30 raeburn 9742: $$rowtotal ++;
1.34 raeburn 9743: my $rowcount = 0;
1.32 raeburn 9744: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 9745: if (ref($rules) eq 'HASH') {
9746: if (keys(%{$rules}) > 0) {
1.32 raeburn 9747: $datatable .= &user_formats_row('username',$settings,$rules,
9748: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 9749: $$rowtotal ++;
1.32 raeburn 9750: $rowcount ++;
9751: }
9752: }
9753: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
9754: if (ref($idrules) eq 'HASH') {
9755: if (keys(%{$idrules}) > 0) {
9756: $datatable .= &user_formats_row('id',$settings,$idrules,
9757: $idruleorder,$numinrow,$rowcount);
9758: $$rowtotal ++;
9759: $rowcount ++;
1.28 raeburn 9760: }
9761: }
1.39 raeburn 9762: if ($rowcount == 0) {
9763: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
9764: $$rowtotal ++;
9765: $rowcount ++;
9766: }
1.34 raeburn 9767: } elsif ($position eq 'middle') {
1.224 raeburn 9768: my @creators = ('author','course','requestcrs');
1.37 raeburn 9769: my ($rules,$ruleorder) =
9770: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 9771: my %lt = &usercreation_types();
9772: my %checked;
9773: if (ref($settings) eq 'HASH') {
9774: if (ref($settings->{'cancreate'}) eq 'HASH') {
9775: foreach my $item (@creators) {
9776: $checked{$item} = $settings->{'cancreate'}{$item};
9777: }
9778: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
9779: foreach my $item (@creators) {
9780: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
9781: $checked{$item} = 'none';
9782: }
9783: }
9784: }
9785: }
9786: my $rownum = 0;
9787: foreach my $item (@creators) {
9788: $rownum ++;
1.224 raeburn 9789: if ($checked{$item} eq '') {
9790: $checked{$item} = 'any';
1.34 raeburn 9791: }
9792: my $css_class;
9793: if ($rownum%2) {
9794: $css_class = '';
9795: } else {
9796: $css_class = ' class="LC_odd_row" ';
9797: }
9798: $datatable .= '<tr'.$css_class.'>'.
9799: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 9800: '</span></td><td style="text-align: right">';
1.224 raeburn 9801: my @options = ('any');
9802: if (ref($rules) eq 'HASH') {
9803: if (keys(%{$rules}) > 0) {
9804: push(@options,('official','unofficial'));
1.37 raeburn 9805: }
9806: }
1.224 raeburn 9807: push(@options,'none');
1.37 raeburn 9808: foreach my $option (@options) {
1.50 raeburn 9809: my $type = 'radio';
1.34 raeburn 9810: my $check = ' ';
1.224 raeburn 9811: if ($checked{$item} eq $option) {
9812: $check = ' checked="checked" ';
1.34 raeburn 9813: }
9814: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 9815: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 9816: $item.'" value="'.$option.'"'.$check.'/> '.
9817: $lt{$option}.'</label> </span>';
9818: }
9819: $datatable .= '</td></tr>';
9820: }
1.28 raeburn 9821: } else {
9822: my @contexts = ('author','course','domain');
1.325 raeburn 9823: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 9824: my %checked;
9825: if (ref($settings) eq 'HASH') {
9826: if (ref($settings->{'authtypes'}) eq 'HASH') {
9827: foreach my $item (@contexts) {
9828: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
9829: foreach my $auth (@authtypes) {
9830: if ($settings->{'authtypes'}{$item}{$auth}) {
9831: $checked{$item}{$auth} = ' checked="checked" ';
9832: }
9833: }
9834: }
9835: }
1.27 raeburn 9836: }
1.35 raeburn 9837: } else {
9838: foreach my $item (@contexts) {
1.36 raeburn 9839: foreach my $auth (@authtypes) {
1.35 raeburn 9840: $checked{$item}{$auth} = ' checked="checked" ';
9841: }
9842: }
1.27 raeburn 9843: }
1.28 raeburn 9844: my %title = &context_names();
9845: my %authname = &authtype_names();
9846: my $rownum = 0;
9847: my $css_class;
9848: foreach my $item (@contexts) {
9849: if ($rownum%2) {
9850: $css_class = '';
9851: } else {
9852: $css_class = ' class="LC_odd_row" ';
9853: }
1.30 raeburn 9854: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 9855: '<td>'.$title{$item}.
9856: '</td><td class="LC_left_item">'.
9857: '<span class="LC_nobreak">';
9858: foreach my $auth (@authtypes) {
9859: $datatable .= '<label>'.
9860: '<input type="checkbox" name="'.$item.'_auth" '.
9861: $checked{$item}{$auth}.' value="'.$auth.'" />'.
9862: $authname{$auth}.'</label> ';
9863: }
9864: $datatable .= '</span></td></tr>';
9865: $rownum ++;
1.27 raeburn 9866: }
1.30 raeburn 9867: $$rowtotal += $rownum;
1.27 raeburn 9868: }
9869: return $datatable;
9870: }
9871:
1.224 raeburn 9872: sub print_selfcreation {
9873: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 9874: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
9875: $emaildomain,$datatable);
1.224 raeburn 9876: if (ref($settings) eq 'HASH') {
9877: if (ref($settings->{'cancreate'}) eq 'HASH') {
9878: $createsettings = $settings->{'cancreate'};
1.236 raeburn 9879: if (ref($createsettings) eq 'HASH') {
9880: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
9881: @selfcreate = @{$createsettings->{'selfcreate'}};
9882: } elsif ($createsettings->{'selfcreate'} ne '') {
9883: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
9884: @selfcreate = ('email','login','sso');
9885: } elsif ($createsettings->{'selfcreate'} ne 'none') {
9886: @selfcreate = ($createsettings->{'selfcreate'});
9887: }
9888: }
9889: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
9890: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 9891: }
1.305 raeburn 9892: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
9893: $emailoptions = $createsettings->{'emailoptions'};
9894: }
1.303 raeburn 9895: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
9896: $emailverified = $createsettings->{'emailverified'};
9897: }
9898: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
9899: $emaildomain = $createsettings->{'emaildomain'};
9900: }
1.224 raeburn 9901: }
9902: }
9903: }
9904: my %radiohash;
9905: my $numinrow = 4;
9906: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 9907: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 9908: if ($position eq 'top') {
9909: my %choices = &Apache::lonlocal::texthash (
9910: cancreate_login => 'Institutional Login',
9911: cancreate_sso => 'Institutional Single Sign On',
9912: );
9913: my @toggles = sort(keys(%choices));
9914: my %defaultchecked = (
9915: 'cancreate_login' => 'off',
9916: 'cancreate_sso' => 'off',
9917: );
1.228 raeburn 9918: my ($onclick,$itemcount);
1.224 raeburn 9919: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
9920: \%choices,$itemcount,$onclick);
1.228 raeburn 9921: $$rowtotal += $itemcount;
1.425 raeburn 9922:
1.224 raeburn 9923: if (ref($usertypes) eq 'HASH') {
9924: if (keys(%{$usertypes}) > 0) {
9925: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
9926: $dom,$numinrow,$othertitle,
1.305 raeburn 9927: 'statustocreate',$rowtotal);
1.224 raeburn 9928: $$rowtotal ++;
9929: }
9930: }
1.240 raeburn 9931: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
9932: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9933: $fieldtitles{'inststatus'} = &mt('Institutional status');
9934: my $rem;
9935: my $numperrow = 2;
9936: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
9937: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 9938: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 9939: '<td class="LC_left_item">'."\n".
1.334 raeburn 9940: '<table>'."\n";
1.240 raeburn 9941: for (my $i=0; $i<@fields; $i++) {
9942: $rem = $i%($numperrow);
9943: if ($rem == 0) {
9944: if ($i > 0) {
9945: $datatable .= '</tr>';
9946: }
9947: $datatable .= '<tr>';
9948: }
9949: my $currval;
1.248 raeburn 9950: if (ref($createsettings) eq 'HASH') {
9951: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
9952: $currval = $createsettings->{'shibenv'}{$fields[$i]};
9953: }
1.240 raeburn 9954: }
9955: $datatable .= '<td class="LC_left_item">'.
9956: '<span class="LC_nobreak">'.
9957: '<input type="text" name="shibenv_'.$fields[$i].'" '.
9958: 'value="'.$currval.'" size="10" /> '.
9959: $fieldtitles{$fields[$i]}.'</span></td>';
9960: }
9961: my $colsleft = $numperrow - $rem;
9962: if ($colsleft > 1 ) {
9963: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9964: ' </td>';
9965: } elsif ($colsleft == 1) {
9966: $datatable .= '<td class="LC_left_item"> </td>';
9967: }
9968: $datatable .= '</tr></table></td></tr>';
9969: $$rowtotal ++;
1.224 raeburn 9970: } elsif ($position eq 'middle') {
9971: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 9972: my @posstypes;
1.224 raeburn 9973: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9974: @posstypes = @{$types};
9975: }
9976: unless (grep(/^default$/,@posstypes)) {
9977: push(@posstypes,'default');
9978: }
9979: my %usertypeshash;
9980: if (ref($usertypes) eq 'HASH') {
9981: %usertypeshash = %{$usertypes};
9982: }
9983: $usertypeshash{'default'} = $othertitle;
9984: foreach my $status (@posstypes) {
9985: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
9986: $numinrow,$$rowtotal,\%usertypeshash);
9987: $$rowtotal ++;
1.224 raeburn 9988: }
9989: } else {
1.236 raeburn 9990: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 9991: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 9992: );
9993: my @toggles = sort(keys(%choices));
9994: my %defaultchecked = (
9995: 'cancreate_email' => 'off',
9996: );
1.305 raeburn 9997: my $customclass = 'LC_selfcreate_email';
9998: my $classprefix = 'LC_canmodify_emailusername_';
9999: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 10000: my $display = 'none';
1.305 raeburn 10001: my $rowstyle = 'display:none';
1.236 raeburn 10002: if (grep(/^\Qemail\E$/,@selfcreate)) {
10003: $display = 'block';
1.305 raeburn 10004: $rowstyle = 'display:table-row';
1.236 raeburn 10005: }
1.305 raeburn 10006: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
10007: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
10008: \%choices,$$rowtotal,$onclick);
10009: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
10010: $rowstyle);
10011: $$rowtotal ++;
10012: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
10013: $rowstyle);
10014: $$rowtotal ++;
10015: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 10016: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 10017: my ($emailrules,$emailruleorder) =
10018: &Apache::lonnet::inst_userrules($dom,'email');
10019: my $primary_id = &Apache::lonnet::domain($dom,'primary');
10020: my $intdom = &Apache::lonnet::internet_dom($primary_id);
10021: if (ref($types) eq 'ARRAY') {
10022: @posstypes = @{$types};
10023: }
10024: if (@posstypes) {
10025: unless (grep(/^default$/,@posstypes)) {
10026: push(@posstypes,'default');
1.302 raeburn 10027: }
10028: if (ref($usertypes) eq 'HASH') {
10029: %usertypeshash = %{$usertypes};
10030: }
1.305 raeburn 10031: my $currassign;
10032: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
10033: $currassign = {
10034: selfassign => $domdefaults{'inststatusguest'},
10035: };
10036: @ordered = @{$domdefaults{'inststatusguest'}};
10037: } else {
10038: $currassign = { selfassign => [] };
10039: }
10040: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
10041: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
10042: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
10043: $numinrow,$othertitle,'selfassign',
10044: $rowtotal,$onclicktypes,$customclass,
10045: $rowstyle);
10046: $$rowtotal ++;
1.302 raeburn 10047: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10048: foreach my $status (@posstypes) {
10049: my $css_class;
10050: if ($$rowtotal%2) {
10051: $css_class = 'LC_odd_row ';
10052: }
10053: $css_class .= $customclass;
10054: my $rowid = $optionsprefix.$status;
10055: my $hidden = 1;
10056: my $currstyle = 'display:none';
10057: if (grep(/^\Q$status\E$/,@ordered)) {
10058: $currstyle = $rowstyle;
1.425 raeburn 10059: $hidden = 0;
1.305 raeburn 10060: }
10061: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10062: $emailrules,$emailruleorder,$settings,$status,$rowid,
10063: $usertypeshash{$status},$css_class,$currstyle,$intdom);
10064: unless ($hidden) {
10065: $$rowtotal ++;
10066: }
1.224 raeburn 10067: }
1.302 raeburn 10068: } else {
1.305 raeburn 10069: my $css_class;
10070: if ($$rowtotal%2) {
10071: $css_class = 'LC_odd_row ';
10072: }
10073: $css_class .= $customclass;
1.302 raeburn 10074: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10075: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10076: $emailrules,$emailruleorder,$settings,'default','',
10077: $othertitle,$css_class,$rowstyle,$intdom);
10078: $$rowtotal ++;
1.224 raeburn 10079: }
10080: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 10081: $numinrow = 1;
1.305 raeburn 10082: if (@posstypes) {
10083: foreach my $status (@posstypes) {
10084: my $rowid = $classprefix.$status;
10085: my $datarowstyle = 'display:none';
1.425 raeburn 10086: if (grep(/^\Q$status\E$/,@ordered)) {
10087: $datarowstyle = $rowstyle;
1.305 raeburn 10088: }
10089: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
10090: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10091: $infotitles,$rowid,$customclass,$datarowstyle);
10092: unless ($datarowstyle eq 'display:none') {
10093: $$rowtotal ++;
10094: }
1.224 raeburn 10095: }
1.305 raeburn 10096: } else {
10097: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
10098: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10099: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 10100: }
10101: }
10102: return $datatable;
10103: }
10104:
1.305 raeburn 10105: sub selfcreate_javascript {
10106: return <<"ENDSCRIPT";
10107:
10108: <script type="text/javascript">
10109: // <![CDATA[
10110:
10111: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
10112: var x = document.getElementsByClassName(target);
10113: var insttypes = 0;
10114: var insttypeRegExp = new RegExp(prefix);
10115: if ((x.length != undefined) && (x.length > 0)) {
10116: if (form.elements[radio].length != undefined) {
10117: for (var i=0; i<form.elements[radio].length; i++) {
10118: if (form.elements[radio][i].checked) {
10119: if (form.elements[radio][i].value == 1) {
10120: for (var j=0; j<x.length; j++) {
10121: if (x[j].id == 'undefined') {
10122: x[j].style.display = 'table-row';
10123: } else if (insttypeRegExp.test(x[j].id)) {
10124: insttypes ++;
10125: } else {
10126: x[j].style.display = 'table-row';
10127: }
10128: }
10129: } else {
10130: for (var j=0; j<x.length; j++) {
10131: x[j].style.display = 'none';
10132: }
1.236 raeburn 10133: }
1.305 raeburn 10134: break;
10135: }
10136: }
10137: if (insttypes > 0) {
10138: toggleDataRow(form,checkbox,target,altprefix);
10139: toggleDataRow(form,checkbox,target,prefix,1);
10140: }
10141: }
10142: }
10143: return;
10144: }
10145:
10146: function toggleDataRow(form,checkbox,target,prefix,docount) {
10147: if (form.elements[checkbox].length != undefined) {
10148: var count = 0;
10149: if (docount) {
10150: for (var i=0; i<form.elements[checkbox].length; i++) {
10151: if (form.elements[checkbox][i].checked) {
10152: count ++;
1.236 raeburn 10153: }
1.305 raeburn 10154: }
10155: }
10156: for (var i=0; i<form.elements[checkbox].length; i++) {
10157: var type = form.elements[checkbox][i].value;
10158: if (document.getElementById(prefix+type)) {
10159: if (form.elements[checkbox][i].checked) {
10160: document.getElementById(prefix+type).style.display = 'table-row';
10161: if (count % 2 == 1) {
10162: document.getElementById(prefix+type).className = target+' LC_odd_row';
10163: } else {
10164: document.getElementById(prefix+type).className = target;
1.236 raeburn 10165: }
1.305 raeburn 10166: count ++;
1.236 raeburn 10167: } else {
1.305 raeburn 10168: document.getElementById(prefix+type).style.display = 'none';
10169: }
10170: }
10171: }
10172: }
10173: return;
10174: }
10175:
10176: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
10177: var caller = radio+'_'+status;
10178: if (form.elements[caller].length != undefined) {
10179: for (var i=0; i<form.elements[caller].length; i++) {
10180: if (form.elements[caller][i].checked) {
10181: if (document.getElementById(altprefix+'_inst_'+status)) {
10182: var curr = form.elements[caller][i].value;
10183: if (prefix) {
10184: document.getElementById(prefix+'_'+status).style.display = 'none';
10185: }
10186: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
10187: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
10188: if (curr == 'custom') {
1.425 raeburn 10189: if (prefix) {
1.305 raeburn 10190: document.getElementById(prefix+'_'+status).style.display = 'inline';
10191: }
10192: } else if (curr == 'inst') {
10193: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
10194: } else if (curr == 'noninst') {
10195: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 10196: }
1.305 raeburn 10197: break;
1.236 raeburn 10198: }
10199: }
10200: }
10201: }
10202: }
10203:
1.305 raeburn 10204: // ]]>
10205: </script>
10206:
10207: ENDSCRIPT
10208: }
10209:
10210: sub noninst_users {
10211: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
1.425 raeburn 10212: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
1.305 raeburn 10213: my $class = 'LC_left_item';
10214: if ($css_class) {
1.425 raeburn 10215: $css_class = ' class="'.$css_class.'"';
1.305 raeburn 10216: }
10217: if ($rowid) {
10218: $rowid = ' id="'.$rowid.'"';
10219: }
10220: if ($rowstyle) {
10221: $rowstyle = ' style="'.$rowstyle.'"';
10222: }
10223: my ($output,$description);
10224: if ($type eq 'default') {
10225: $description = &mt('Requests for: [_1]',$typetitle);
10226: } else {
10227: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
10228: }
10229: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
1.425 raeburn 10230: "<td>$description</td>\n".
1.305 raeburn 10231: '<td class="'.$class.'" colspan="2">'.
10232: '<table><tr>';
1.425 raeburn 10233: my %headers = &Apache::lonlocal::texthash(
1.305 raeburn 10234: approve => 'Processing',
10235: email => 'E-mail',
10236: username => 'Username',
10237: );
10238: foreach my $item ('approve','email','username') {
10239: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 10240: }
1.305 raeburn 10241: $output .= '</tr><tr>';
10242: foreach my $item ('approve','email','username') {
1.306 raeburn 10243: $output .= '<td style="vertical-align: top">';
1.305 raeburn 10244: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
10245: if ($item eq 'approve') {
10246: %choices = &Apache::lonlocal::texthash (
10247: automatic => 'Automatically approved',
10248: approval => 'Queued for approval',
10249: );
10250: @options = ('automatic','approval');
10251: $hashref = $processing;
10252: $defoption = 'automatic';
10253: $name = 'cancreate_emailprocess_'.$type;
10254: } elsif ($item eq 'email') {
10255: %choices = &Apache::lonlocal::texthash (
10256: any => 'Any e-mail',
10257: inst => 'Institutional only',
10258: noninst => 'Non-institutional only',
10259: custom => 'Custom restrictions',
10260: );
10261: @options = ('any','inst','noninst');
10262: my $showcustom;
10263: if (ref($emailrules) eq 'HASH') {
10264: if (keys(%{$emailrules}) > 0) {
10265: push(@options,'custom');
10266: $showcustom = 'cancreate_emailrule';
10267: if (ref($settings) eq 'HASH') {
10268: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
10269: foreach my $rule (@{$settings->{'email_rule'}}) {
10270: if (exists($emailrules->{$rule})) {
10271: $hascustom ++;
10272: }
10273: }
10274: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
10275: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
10276: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
10277: if (exists($emailrules->{$rule})) {
10278: $hascustom ++;
10279: }
10280: }
10281: }
10282: }
10283: }
10284: }
10285: }
10286: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
10287: "'cancreate_emaildomain','$type'".');"';
10288: $hashref = $emailoptions;
10289: $defoption = 'any';
10290: $name = 'cancreate_emailoptions_'.$type;
10291: } elsif ($item eq 'username') {
10292: %choices = &Apache::lonlocal::texthash (
10293: all => 'Same as e-mail',
10294: first => 'Omit @domain',
10295: free => 'Free to choose',
10296: );
10297: @options = ('all','first','free');
10298: $hashref = $emailverified;
10299: $defoption = 'all';
10300: $name = 'cancreate_usernameoptions_'.$type;
10301: }
10302: foreach my $option (@options) {
10303: my $checked;
10304: if (ref($hashref) eq 'HASH') {
10305: if ($type eq '') {
10306: if (!exists($hashref->{'default'})) {
10307: if ($option eq $defoption) {
10308: $checked = ' checked="checked"';
10309: }
10310: } else {
10311: if ($hashref->{'default'} eq $option) {
10312: $checked = ' checked="checked"';
10313: }
1.303 raeburn 10314: }
10315: } else {
1.305 raeburn 10316: if (!exists($hashref->{$type})) {
10317: if ($option eq $defoption) {
10318: $checked = ' checked="checked"';
10319: }
10320: } else {
10321: if ($hashref->{$type} eq $option) {
10322: $checked = ' checked="checked"';
10323: }
1.303 raeburn 10324: }
10325: }
1.305 raeburn 10326: } elsif (($item eq 'email') && ($hascustom)) {
10327: if ($option eq 'custom') {
10328: $checked = ' checked="checked"';
10329: }
10330: } elsif ($option eq $defoption) {
10331: $checked = ' checked="checked"';
10332: }
10333: $output .= '<span class="LC_nobreak"><label>'.
10334: '<input type="radio" name="'.$name.'"'.
10335: $checked.' value="'.$option.'"'.$onclick.' />'.
10336: $choices{$option}.'</label></span><br />';
10337: if ($item eq 'email') {
10338: if ($option eq 'custom') {
10339: my $id = 'cancreate_emailrule_'.$type;
10340: my $display = 'none';
10341: if ($checked) {
10342: $display = 'inline';
1.303 raeburn 10343: }
1.305 raeburn 10344: my $numinrow = 2;
10345: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
10346: '<legend>'.&mt('Disallow').'</legend><table>'.
10347: &user_formats_row('email',$settings,$emailrules,
10348: $emailruleorder,$numinrow,'',$type);
10349: '</table></fieldset>';
10350: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
10351: my %text = &Apache::lonlocal::texthash (
10352: inst => 'must end:',
10353: noninst => 'cannot end:',
10354: );
10355: my $value;
10356: if (ref($emaildomain) eq 'HASH') {
10357: if (ref($emaildomain->{$type}) eq 'HASH') {
1.425 raeburn 10358: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 10359: }
10360: }
1.305 raeburn 10361: if ($value eq '') {
10362: $value = '@'.$intdom;
10363: }
10364: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
10365: my $display = 'none';
10366: if ($checked) {
10367: $display = 'inline';
10368: }
10369: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
10370: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
10371: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
10372: '</div>';
1.303 raeburn 10373: }
10374: }
10375: }
1.305 raeburn 10376: $output .= '</td>'."\n";
1.303 raeburn 10377: }
1.305 raeburn 10378: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 10379: return $output;
10380: }
10381:
1.165 raeburn 10382: sub captcha_choice {
1.305 raeburn 10383: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 10384: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
10385: $vertext,$currver);
1.165 raeburn 10386: my %lt = &captcha_phrases();
10387: $keyentry = 'hidden';
1.354 raeburn 10388: my $colspan=2;
1.165 raeburn 10389: if ($context eq 'cancreate') {
1.224 raeburn 10390: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 10391: } elsif ($context eq 'login') {
10392: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.354 raeburn 10393: } elsif ($context eq 'passwords') {
10394: $rowname = &mt('"Forgot Password" CAPTCHA validation');
10395: $colspan=1;
1.165 raeburn 10396: }
10397: if (ref($settings) eq 'HASH') {
10398: if ($settings->{'captcha'}) {
10399: $checked{$settings->{'captcha'}} = ' checked="checked"';
10400: } else {
10401: $checked{'original'} = ' checked="checked"';
10402: }
10403: if ($settings->{'captcha'} eq 'recaptcha') {
10404: $pubtext = $lt{'pub'};
10405: $privtext = $lt{'priv'};
10406: $keyentry = 'text';
1.269 raeburn 10407: $vertext = $lt{'ver'};
10408: $currver = $settings->{'recaptchaversion'};
10409: if ($currver ne '2') {
10410: $currver = 1;
10411: }
1.165 raeburn 10412: }
10413: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
10414: $currpub = $settings->{'recaptchakeys'}{'public'};
10415: $currpriv = $settings->{'recaptchakeys'}{'private'};
10416: }
10417: } else {
10418: $checked{'original'} = ' checked="checked"';
10419: }
1.305 raeburn 10420: my $css_class;
10421: if ($itemcount%2) {
10422: $css_class = 'LC_odd_row';
10423: }
10424: if ($customcss) {
10425: $css_class .= " $customcss";
10426: }
10427: $css_class =~ s/^\s+//;
10428: if ($css_class) {
10429: $css_class = ' class="'.$css_class.'"';
10430: }
10431: if ($rowstyle) {
10432: $css_class .= ' style="'.$rowstyle.'"';
10433: }
1.169 raeburn 10434: my $output = '<tr'.$css_class.'>'.
1.354 raeburn 10435: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165 raeburn 10436: '<table><tr><td>'."\n";
10437: foreach my $option ('original','recaptcha','notused') {
10438: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
10439: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
10440: $lt{$option}.'</label></span>';
10441: unless ($option eq 'notused') {
10442: $output .= (' 'x2)."\n";
10443: }
10444: }
10445: #
10446: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
10447: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 10448: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 10449: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 10450: #
1.165 raeburn 10451: $output .= '</td></tr>'."\n".
1.305 raeburn 10452: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 10453: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
10454: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
10455: $currpub.'" size="40" /></span><br />'."\n".
10456: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
10457: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 10458: $currpriv.'" size="40" /></span><br />'.
10459: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
10460: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
10461: $currver.'" size="3" /></span><br />'.
10462: '</td></tr></table>'."\n".
1.165 raeburn 10463: '</td></tr>';
10464: return $output;
10465: }
10466:
1.32 raeburn 10467: sub user_formats_row {
1.305 raeburn 10468: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 10469: my $output;
10470: my %text = (
10471: 'username' => 'new usernames',
10472: 'id' => 'IDs',
10473: );
1.409 raeburn 10474: unless (($type eq 'email') || ($type eq 'unamemap')) {
1.305 raeburn 10475: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
10476: $output = '<tr '.$css_class.'>'.
10477: '<td><span class="LC_nobreak">'.
10478: &mt("Format rules to check for $text{$type}: ").
10479: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 10480: }
1.27 raeburn 10481: my $rem;
10482: if (ref($ruleorder) eq 'ARRAY') {
10483: for (my $i=0; $i<@{$ruleorder}; $i++) {
10484: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
10485: my $rem = $i%($numinrow);
10486: if ($rem == 0) {
10487: if ($i > 0) {
10488: $output .= '</tr>';
10489: }
10490: $output .= '<tr>';
10491: }
10492: my $check = ' ';
1.39 raeburn 10493: if (ref($settings) eq 'HASH') {
10494: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
10495: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
10496: $check = ' checked="checked" ';
10497: }
1.305 raeburn 10498: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
10499: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
10500: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
10501: $check = ' checked="checked" ';
10502: }
10503: }
1.27 raeburn 10504: }
10505: }
1.305 raeburn 10506: my $name = $type.'_rule';
10507: if ($type eq 'email') {
10508: $name .= '_'.$status;
10509: }
1.27 raeburn 10510: $output .= '<td class="LC_left_item">'.
10511: '<span class="LC_nobreak"><label>'.
1.311 raeburn 10512: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 10513: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
10514: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
10515: }
10516: }
10517: $rem = @{$ruleorder}%($numinrow);
10518: }
1.305 raeburn 10519: my $colsleft;
10520: if ($rem) {
10521: $colsleft = $numinrow - $rem;
10522: }
1.27 raeburn 10523: if ($colsleft > 1 ) {
10524: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10525: ' </td>';
10526: } elsif ($colsleft == 1) {
10527: $output .= '<td class="LC_left_item"> </td>';
10528: }
1.409 raeburn 10529: $output .= '</tr>';
10530: unless (($type eq 'email') || ($type eq 'unamemap')) {
10531: $output .= '</table></td></tr>';
1.305 raeburn 10532: }
1.27 raeburn 10533: return $output;
10534: }
10535:
1.34 raeburn 10536: sub usercreation_types {
10537: my %lt = &Apache::lonlocal::texthash (
10538: author => 'When adding a co-author',
10539: course => 'When adding a user to a course',
1.100 raeburn 10540: requestcrs => 'When requesting a course',
1.34 raeburn 10541: any => 'Any',
10542: official => 'Institutional only ',
10543: unofficial => 'Non-institutional only',
10544: none => 'None',
10545: );
10546: return %lt;
1.48 raeburn 10547: }
1.34 raeburn 10548:
1.224 raeburn 10549: sub selfcreation_types {
10550: my %lt = &Apache::lonlocal::texthash (
10551: selfcreate => 'User creates own account',
10552: any => 'Any',
10553: official => 'Institutional only ',
10554: unofficial => 'Non-institutional only',
10555: email => 'E-mail address',
10556: login => 'Institutional Login',
10557: sso => 'SSO',
10558: );
10559: }
10560:
1.28 raeburn 10561: sub authtype_names {
10562: my %lt = &Apache::lonlocal::texthash(
10563: int => 'Internal',
10564: krb4 => 'Kerberos 4',
10565: krb5 => 'Kerberos 5',
10566: loc => 'Local',
1.325 raeburn 10567: lti => 'LTI',
1.28 raeburn 10568: );
10569: return %lt;
10570: }
10571:
10572: sub context_names {
10573: my %context_title = &Apache::lonlocal::texthash(
10574: author => 'Creating users when an Author',
10575: course => 'Creating users when in a course',
10576: domain => 'Creating users when a Domain Coordinator',
10577: );
10578: return %context_title;
10579: }
10580:
1.33 raeburn 10581: sub print_usermodification {
10582: my ($position,$dom,$settings,$rowtotal) = @_;
10583: my $numinrow = 4;
10584: my ($context,$datatable,$rowcount);
10585: if ($position eq 'top') {
10586: $rowcount = 0;
10587: $context = 'author';
10588: foreach my $role ('ca','aa') {
10589: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10590: $numinrow,$rowcount);
10591: $$rowtotal ++;
10592: $rowcount ++;
10593: }
1.230 raeburn 10594: } elsif ($position eq 'bottom') {
1.33 raeburn 10595: $context = 'course';
10596: $rowcount = 0;
10597: foreach my $role ('st','ep','ta','in','cr') {
10598: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10599: $numinrow,$rowcount);
10600: $$rowtotal ++;
10601: $rowcount ++;
10602: }
10603: }
10604: return $datatable;
10605: }
10606:
1.43 raeburn 10607: sub print_defaults {
1.236 raeburn 10608: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 10609: my $rownum = 0;
1.294 raeburn 10610: my ($datatable,$css_class,$titles);
10611: unless ($position eq 'bottom') {
10612: $titles = &defaults_titles($dom);
10613: }
1.236 raeburn 10614: if ($position eq 'top') {
10615: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
10616: 'datelocale_def','portal_def');
10617: my %defaults;
10618: if (ref($settings) eq 'HASH') {
10619: %defaults = %{$settings};
1.43 raeburn 10620: } else {
1.236 raeburn 10621: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10622: foreach my $item (@items) {
10623: $defaults{$item} = $domdefaults{$item};
10624: }
1.43 raeburn 10625: }
1.236 raeburn 10626: foreach my $item (@items) {
10627: if ($rownum%2) {
10628: $css_class = '';
10629: } else {
10630: $css_class = ' class="LC_odd_row" ';
10631: }
10632: $datatable .= '<tr'.$css_class.'>'.
10633: '<td><span class="LC_nobreak">'.$titles->{$item}.
10634: '</span></td><td class="LC_right_item" colspan="3">';
10635: if ($item eq 'auth_def') {
1.325 raeburn 10636: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 10637: my %shortauth = (
10638: internal => 'int',
10639: krb4 => 'krb4',
10640: krb5 => 'krb5',
1.325 raeburn 10641: localauth => 'loc',
10642: lti => 'lti',
1.236 raeburn 10643: );
10644: my %authnames = &authtype_names();
10645: foreach my $auth (@authtypes) {
10646: my $checked = ' ';
10647: if ($defaults{$item} eq $auth) {
10648: $checked = ' checked="checked" ';
10649: }
10650: $datatable .= '<label><input type="radio" name="'.$item.
10651: '" value="'.$auth.'"'.$checked.'/>'.
10652: $authnames{$shortauth{$auth}}.'</label> ';
10653: }
10654: } elsif ($item eq 'timezone_def') {
10655: my $includeempty = 1;
10656: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
10657: } elsif ($item eq 'datelocale_def') {
10658: my $includeempty = 1;
10659: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
10660: } elsif ($item eq 'lang_def') {
1.263 raeburn 10661: my $includeempty = 1;
10662: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.414 raeburn 10663: } elsif ($item eq 'portal_def') {
10664: $datatable .= '<input type="text" name="'.$item.'" value="'.
10665: $defaults{$item}.'" size="25" onkeyup="portalExtras(this);" />';
10666: my $portalsty = 'none';
10667: if ($defaults{$item}) {
10668: $portalsty = 'block';
10669: }
10670: foreach my $field ('email','web') {
10671: my $checkedoff = ' checked="checked"';
10672: my $checkedon;
10673: if ($defaults{$item.'_'.$field}) {
10674: $checkedon = $checkedoff;
10675: $checkedoff = '';
1.425 raeburn 10676: }
1.414 raeburn 10677: $datatable .= '<div id="'.$item.'_'.$field.'_div" style="display:'.$portalsty.'">'.
10678: '<span class="LC_nobreak">'.$titles->{$field}.' '.
10679: '<label><input type="radio" name="'.$item.'_'.$field.'" value="1"'.$checkedon.'/>'.&mt('Yes').'</label>'.
10680: (' 'x2).
10681: '<label><input type="radio" name="'.$item.'_'.$field.'" value="0"'.$checkedoff.'/>'.&mt('No').'</label>'.
10682: '</div>';
10683: }
1.236 raeburn 10684: } else {
1.414 raeburn 10685: $datatable .= '<input type="text" name="'.$item.'" value="'.$defaults{$item}.'" />';
1.43 raeburn 10686: }
1.236 raeburn 10687: $datatable .= '</td></tr>';
10688: $rownum ++;
10689: }
1.409 raeburn 10690: } elsif ($position eq 'middle') {
1.294 raeburn 10691: my %defaults;
10692: if (ref($settings) eq 'HASH') {
1.354 raeburn 10693: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
10694: my $maxnum = @{$settings->{'inststatusorder'}};
10695: for (my $i=0; $i<$maxnum; $i++) {
10696: $css_class = $rownum%2?' class="LC_odd_row"':'';
10697: my $item = $settings->{'inststatusorder'}->[$i];
10698: my $title = $settings->{'inststatustypes'}->{$item};
10699: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
10700: $datatable .= '<tr'.$css_class.'>'.
10701: '<td><span class="LC_nobreak">'.
10702: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
10703: for (my $k=0; $k<=$maxnum; $k++) {
10704: my $vpos = $k+1;
10705: my $selstr;
10706: if ($k == $i) {
10707: $selstr = ' selected="selected" ';
10708: }
10709: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10710: }
10711: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
10712: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
10713: &mt('delete').'</span></td>'.
1.380 raeburn 10714: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.354 raeburn 10715: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
10716: '</span></td></tr>';
10717: }
10718: $css_class = $rownum%2?' class="LC_odd_row"':'';
10719: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
10720: $datatable .= '<tr '.$css_class.'>'.
10721: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
10722: for (my $k=0; $k<=$maxnum; $k++) {
10723: my $vpos = $k+1;
10724: my $selstr;
10725: if ($k == $maxnum) {
10726: $selstr = ' selected="selected" ';
10727: }
10728: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10729: }
10730: $datatable .= '</select> '.&mt('Internal ID:').
10731: '<input type="text" size="10" name="addinststatus" value="" />'.
10732: ' '.&mt('(new)').
10733: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.380 raeburn 10734: &mt('Name displayed').':'.
1.354 raeburn 10735: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
10736: '</tr>'."\n";
10737: $rownum ++;
1.294 raeburn 10738: }
1.354 raeburn 10739: }
1.409 raeburn 10740: } else {
10741: my ($unamemaprules,$ruleorder) =
10742: &Apache::lonnet::inst_userrules($dom,'unamemap');
10743: $css_class = $rownum%2?' class="LC_odd_row"':'';
10744: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10745: my $numinrow = 2;
10746: $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
10747: &user_formats_row('unamemap',$settings,$unamemaprules,
10748: $ruleorder,$numinrow).
10749: '</table></td></tr>';
10750: }
10751: if ($datatable eq '') {
10752: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
10753: &mt('No rules set for domain in customized localenroll.pm').
10754: '</td></tr>';
10755: }
1.354 raeburn 10756: }
10757: $$rowtotal += $rownum;
1.43 raeburn 10758: return $datatable;
10759: }
10760:
1.168 raeburn 10761: sub get_languages_hash {
10762: my %langchoices;
10763: foreach my $id (&Apache::loncommon::languageids()) {
10764: my $code = &Apache::loncommon::supportedlanguagecode($id);
10765: if ($code ne '') {
10766: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
10767: }
10768: }
10769: return %langchoices;
10770: }
10771:
1.43 raeburn 10772: sub defaults_titles {
1.141 raeburn 10773: my ($dom) = @_;
1.43 raeburn 10774: my %titles = &Apache::lonlocal::texthash (
10775: 'auth_def' => 'Default authentication type',
10776: 'auth_arg_def' => 'Default authentication argument',
10777: 'lang_def' => 'Default language',
1.54 raeburn 10778: 'timezone_def' => 'Default timezone',
1.68 raeburn 10779: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 10780: 'portal_def' => 'Portal/Default URL',
1.414 raeburn 10781: 'email' => 'Email links use portal URL',
10782: 'web' => 'Public web links use portal URL',
1.294 raeburn 10783: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
10784: 'intauth_check' => 'Check bcrypt cost if authenticated',
10785: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 10786: );
1.141 raeburn 10787: if ($dom) {
10788: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
10789: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
10790: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
10791: $protocol = 'http' if ($protocol ne 'https');
10792: if ($uint_dom) {
10793: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
10794: $uint_dom);
10795: }
10796: }
1.43 raeburn 10797: return (\%titles);
10798: }
10799:
1.346 raeburn 10800: sub print_scantron {
10801: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
10802: if ($position eq 'top') {
10803: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
10804: } else {
10805: return &print_scantronconfig($dom,$settings,\$rowtotal);
10806: }
10807: }
10808:
10809: sub scantron_javascript {
10810: return <<"ENDSCRIPT";
10811:
10812: <script type="text/javascript">
10813: // <![CDATA[
10814:
10815: function toggleScantron(form) {
1.347 raeburn 10816: var csvfieldset = new Array();
1.346 raeburn 10817: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 10818: csvfieldset.push(document.getElementById('scantroncsv_cols'));
10819: }
10820: if (document.getElementById('scantroncsv_options')) {
10821: csvfieldset.push(document.getElementById('scantroncsv_options'));
10822: }
10823: if (csvfieldset.length) {
1.346 raeburn 10824: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 10825: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 10826: if (scantroncsv.checked) {
1.347 raeburn 10827: for (var i=0; i<csvfieldset.length; i++) {
10828: csvfieldset[i].style.display = 'block';
10829: }
1.346 raeburn 10830: } else {
1.347 raeburn 10831: for (var i=0; i<csvfieldset.length; i++) {
10832: csvfieldset[i].style.display = 'none';
10833: }
1.346 raeburn 10834: var csvselects = document.getElementsByClassName('scantronconfig_csv');
10835: if (csvselects.length) {
10836: for (var j=0; j<csvselects.length; j++) {
10837: csvselects[j].selectedIndex = 0;
10838: }
10839: }
10840: }
10841: }
10842: }
10843: return;
10844: }
10845: // ]]>
10846: </script>
10847:
10848: ENDSCRIPT
10849:
10850: }
10851:
1.46 raeburn 10852: sub print_scantronformat {
10853: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
10854: my $itemcount = 1;
1.60 raeburn 10855: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
10856: %confhash);
1.46 raeburn 10857: my $switchserver = &check_switchserver($dom,$confname);
10858: my %lt = &Apache::lonlocal::texthash (
1.95 www 10859: default => 'Default bubblesheet format file error',
10860: custom => 'Custom bubblesheet format file error',
1.46 raeburn 10861: );
10862: my %scantronfiles = (
10863: default => 'default.tab',
10864: custom => 'custom.tab',
10865: );
10866: foreach my $key (keys(%scantronfiles)) {
10867: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
10868: .$scantronfiles{$key};
10869: }
10870: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
10871: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
10872: if (!$switchserver) {
10873: my $servadm = $r->dir_config('lonAdmEMail');
10874: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
10875: if ($configuserok eq 'ok') {
10876: if ($author_ok eq 'ok') {
10877: my %legacyfile = (
1.346 raeburn 10878: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
10879: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 10880: );
10881: my %md5chk;
10882: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 10883: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
10884: chomp($md5chk{$type});
1.46 raeburn 10885: }
10886: if ($md5chk{'default'} ne $md5chk{'custom'}) {
10887: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 10888: ($scantronurls{$type},my $error) =
1.46 raeburn 10889: &legacy_scantronformat($r,$dom,$confname,
10890: $type,$legacyfile{$type},
10891: $scantronurls{$type},
10892: $scantronfiles{$type});
1.60 raeburn 10893: if ($error ne '') {
10894: $error{$type} = $error;
10895: }
10896: }
10897: if (keys(%error) == 0) {
10898: $is_custom = 1;
1.346 raeburn 10899: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 10900: $scantronurls{'custom'};
1.346 raeburn 10901: my $putresult =
1.60 raeburn 10902: &Apache::lonnet::put_dom('configuration',
10903: \%confhash,$dom);
10904: if ($putresult ne 'ok') {
1.346 raeburn 10905: $error{'custom'} =
1.60 raeburn 10906: '<span class="LC_error">'.
10907: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
10908: }
1.46 raeburn 10909: }
10910: } else {
1.60 raeburn 10911: ($scantronurls{'default'},my $error) =
1.46 raeburn 10912: &legacy_scantronformat($r,$dom,$confname,
10913: 'default',$legacyfile{'default'},
10914: $scantronurls{'default'},
10915: $scantronfiles{'default'});
1.60 raeburn 10916: if ($error eq '') {
10917: $confhash{'scantron'}{'scantronformat'} = '';
10918: my $putresult =
10919: &Apache::lonnet::put_dom('configuration',
10920: \%confhash,$dom);
10921: if ($putresult ne 'ok') {
10922: $error{'default'} =
10923: '<span class="LC_error">'.
10924: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
10925: }
10926: } else {
10927: $error{'default'} = $error;
10928: }
1.46 raeburn 10929: }
10930: }
10931: }
10932: } else {
1.95 www 10933: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 10934: }
10935: }
10936: if (ref($settings) eq 'HASH') {
10937: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
10938: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
10939: if ((!@info) || ($info[0] eq 'no_such_dir')) {
10940: $scantronurl = '';
10941: } else {
10942: $scantronurl = $settings->{'scantronformat'};
10943: }
10944: $is_custom = 1;
10945: } else {
10946: $scantronurl = $scantronurls{'default'};
10947: }
10948: } else {
1.60 raeburn 10949: if ($is_custom) {
10950: $scantronurl = $scantronurls{'custom'};
10951: } else {
10952: $scantronurl = $scantronurls{'default'};
10953: }
1.46 raeburn 10954: }
10955: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10956: $datatable .= '<tr'.$css_class.'>';
10957: if (!$is_custom) {
1.65 raeburn 10958: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
10959: '<span class="LC_nobreak">';
1.46 raeburn 10960: if ($scantronurl) {
1.199 raeburn 10961: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
10962: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 10963: } else {
10964: $datatable = &mt('File unavailable for display');
10965: }
1.65 raeburn 10966: $datatable .= '</span></td>';
1.60 raeburn 10967: if (keys(%error) == 0) {
1.306 raeburn 10968: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 10969: if (!$switchserver) {
10970: $datatable .= &mt('Upload:').'<br />';
10971: }
10972: } else {
10973: my $errorstr;
10974: foreach my $key (sort(keys(%error))) {
10975: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
10976: }
10977: $datatable .= '<td>'.$errorstr;
10978: }
1.46 raeburn 10979: } else {
10980: if (keys(%error) > 0) {
10981: my $errorstr;
10982: foreach my $key (sort(keys(%error))) {
10983: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
10984: }
1.60 raeburn 10985: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 10986: } elsif ($scantronurl) {
1.199 raeburn 10987: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
10988: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 10989: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 10990: $link.
10991: '<label><input type="checkbox" name="scantronformat_del"'.
10992: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 10993: '<td><span class="LC_nobreak"> '.
10994: &mt('Replace:').'</span><br />';
1.46 raeburn 10995: }
10996: }
10997: if (keys(%error) == 0) {
10998: if ($switchserver) {
10999: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
11000: } else {
1.65 raeburn 11001: $datatable .='<span class="LC_nobreak"> '.
11002: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 11003: }
11004: }
11005: $datatable .= '</td></tr>';
11006: $$rowtotal ++;
11007: return $datatable;
11008: }
11009:
11010: sub legacy_scantronformat {
11011: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
11012: my ($url,$error);
11013: my @statinfo = &Apache::lonnet::stat_file($newurl);
11014: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
1.421 raeburn 11015: my $modified = [];
1.46 raeburn 11016: (my $result,$url) =
1.421 raeburn 11017: &Apache::lonconfigsettings::publishlogo($r,'copy',$legacyfile,$dom,$confname,
11018: 'scantron','','',$newfile,$modified);
11019: if ($result eq 'ok') {
11020: &update_modify_urls($r,$modified);
11021: } else {
1.130 raeburn 11022: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 11023: }
11024: }
11025: return ($url,$error);
11026: }
1.43 raeburn 11027:
1.346 raeburn 11028: sub print_scantronconfig {
11029: my ($dom,$settings,$rowtotal) = @_;
11030: my $itemcount = 2;
11031: my $is_checked = ' checked="checked"';
1.347 raeburn 11032: my %optionson = (
11033: hdr => ' checked="checked"',
11034: pad => ' checked="checked"',
11035: rem => ' checked="checked"',
11036: );
11037: my %optionsoff = (
11038: hdr => '',
11039: pad => '',
11040: rem => '',
11041: );
1.346 raeburn 11042: my $currcsvsty = 'none';
1.347 raeburn 11043: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 11044: my @fields = &scantroncsv_fields();
11045: my %titles = &scantronconfig_titles();
11046: if (ref($settings) eq 'HASH') {
11047: if (ref($settings->{config}) eq 'HASH') {
11048: if ($settings->{config}->{dat}) {
11049: $checked{'dat'} = $is_checked;
11050: }
11051: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 11052: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
11053: %csvfields = %{$settings->{config}->{csv}->{fields}};
11054: if (keys(%csvfields) > 0) {
11055: $checked{'csv'} = $is_checked;
11056: $currcsvsty = 'block';
11057: }
11058: }
11059: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
11060: %csvoptions = %{$settings->{config}->{csv}->{options}};
11061: foreach my $option (keys(%optionson)) {
11062: unless ($csvoptions{$option}) {
11063: $optionsoff{$option} = $optionson{$option};
11064: $optionson{$option} = '';
11065: }
11066: }
1.346 raeburn 11067: }
11068: }
11069: } else {
11070: $checked{'dat'} = $is_checked;
11071: }
11072: } else {
11073: $checked{'dat'} = $is_checked;
11074: }
11075: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
11076: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11077: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
11078: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
11079: foreach my $item ('dat','csv') {
11080: my $id;
11081: if ($item eq 'csv') {
11082: $id = 'id="scantronconfcsv" ';
1.347 raeburn 11083: }
1.346 raeburn 11084: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
11085: $titles{$item}.'</label>'.(' 'x3);
11086: if ($item eq 'csv') {
11087: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
11088: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
11089: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
11090: foreach my $col (@fields) {
11091: my $selnone;
11092: if ($csvfields{$col} eq '') {
11093: $selnone = ' selected="selected"';
11094: }
11095: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
11096: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
11097: '<option value=""'.$selnone.'></option>';
11098: for (my $i=0; $i<20; $i++) {
11099: my $shown = $i+1;
11100: my $sel;
11101: unless ($selnone) {
11102: if (exists($csvfields{$col})) {
11103: if ($csvfields{$col} == $i) {
11104: $sel = ' selected="selected"';
11105: }
11106: }
11107: }
11108: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
11109: }
11110: $datatable .= '</select></td></tr>';
11111: }
1.347 raeburn 11112: $datatable .= '</table></fieldset>'.
11113: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
11114: '<legend>'.&mt('CSV Options').'</legend>';
11115: foreach my $option ('hdr','pad','rem') {
11116: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
11117: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
11118: &mt('Yes').'</label>'.(' 'x2)."\n".
11119: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
11120: }
11121: $datatable .= '</fieldset>';
1.346 raeburn 11122: $itemcount ++;
11123: }
11124: }
11125: $datatable .= '</td></tr>';
11126: $$rowtotal ++;
11127: return $datatable;
11128: }
11129:
11130: sub scantronconfig_titles {
11131: return &Apache::lonlocal::texthash(
11132: dat => 'Standard format (.dat)',
11133: csv => 'Comma separated values (.csv)',
1.347 raeburn 11134: hdr => 'Remove first line in file (contains column titles)',
11135: pad => 'Prepend 0s to PaperID',
1.348 raeburn 11136: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 11137: CODE => 'CODE',
11138: ID => 'Student ID',
11139: PaperID => 'Paper ID',
11140: FirstName => 'First Name',
11141: LastName => 'Last Name',
11142: FirstQuestion => 'First Question Response',
11143: Section => 'Section',
11144: );
11145: }
11146:
11147: sub scantroncsv_fields {
11148: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
11149: }
11150:
1.49 raeburn 11151: sub print_coursecategories {
1.57 raeburn 11152: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
11153: my $datatable;
11154: if ($position eq 'top') {
1.238 raeburn 11155: my (%checked);
11156: my @catitems = ('unauth','auth');
11157: my @cattypes = ('std','domonly','codesrch','none');
11158: $checked{'unauth'} = 'std';
11159: $checked{'auth'} = 'std';
11160: if (ref($settings) eq 'HASH') {
11161: foreach my $type (@cattypes) {
11162: if ($type eq $settings->{'unauth'}) {
11163: $checked{'unauth'} = $type;
11164: }
11165: if ($type eq $settings->{'auth'}) {
11166: $checked{'auth'} = $type;
11167: }
11168: }
11169: }
11170: my %lt = &Apache::lonlocal::texthash (
11171: unauth => 'Catalog type for unauthenticated users',
11172: auth => 'Catalog type for authenticated users',
11173: none => 'No catalog',
11174: std => 'Standard catalog',
11175: domonly => 'Domain-only catalog',
11176: codesrch => "Code search form",
11177: );
11178: my $itemcount = 0;
11179: foreach my $item (@catitems) {
11180: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11181: $datatable .= '<tr '.$css_class.'>'.
11182: '<td>'.$lt{$item}.'</td>'.
11183: '<td class="LC_right_item"><span class="LC_nobreak">';
11184: foreach my $type (@cattypes) {
11185: my $ischecked;
11186: if ($checked{$item} eq $type) {
11187: $ischecked=' checked="checked"';
11188: }
11189: $datatable .= '<label>'.
11190: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
11191: ' />'.$lt{$type}.'</label> ';
11192: }
1.327 raeburn 11193: $datatable .= '</span></td></tr>';
1.238 raeburn 11194: $itemcount ++;
11195: }
11196: $$rowtotal += $itemcount;
11197: } elsif ($position eq 'middle') {
1.57 raeburn 11198: my $toggle_cats_crs = ' ';
11199: my $toggle_cats_dom = ' checked="checked" ';
11200: my $can_cat_crs = ' ';
11201: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 11202: my $toggle_catscomm_comm = ' ';
11203: my $toggle_catscomm_dom = ' checked="checked" ';
11204: my $can_catcomm_comm = ' ';
11205: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 11206: my $toggle_catsplace_place = ' ';
11207: my $toggle_catsplace_dom = ' checked="checked" ';
11208: my $can_catplace_place = ' ';
11209: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 11210:
1.57 raeburn 11211: if (ref($settings) eq 'HASH') {
11212: if ($settings->{'togglecats'} eq 'crs') {
11213: $toggle_cats_crs = $toggle_cats_dom;
11214: $toggle_cats_dom = ' ';
11215: }
11216: if ($settings->{'categorize'} eq 'crs') {
11217: $can_cat_crs = $can_cat_dom;
11218: $can_cat_dom = ' ';
11219: }
1.120 raeburn 11220: if ($settings->{'togglecatscomm'} eq 'comm') {
11221: $toggle_catscomm_comm = $toggle_catscomm_dom;
11222: $toggle_catscomm_dom = ' ';
11223: }
11224: if ($settings->{'categorizecomm'} eq 'comm') {
11225: $can_catcomm_comm = $can_catcomm_dom;
11226: $can_catcomm_dom = ' ';
11227: }
1.272 raeburn 11228: if ($settings->{'togglecatsplace'} eq 'place') {
11229: $toggle_catsplace_place = $toggle_catsplace_dom;
11230: $toggle_catsplace_dom = ' ';
11231: }
11232: if ($settings->{'categorizeplace'} eq 'place') {
11233: $can_catplace_place = $can_catplace_dom;
11234: $can_catplace_dom = ' ';
11235: }
1.57 raeburn 11236: }
11237: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 11238: togglecats => 'Show/Hide a course in catalog',
11239: togglecatscomm => 'Show/Hide a community in catalog',
11240: togglecatsplace => 'Show/Hide a placement test in catalog',
11241: categorize => 'Assign a category to a course',
11242: categorizecomm => 'Assign a category to a community',
11243: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 11244: );
11245: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 11246: dom => 'Set in Domain',
11247: crs => 'Set in Course',
11248: comm => 'Set in Community',
11249: place => 'Set in Placement Test',
1.57 raeburn 11250: );
11251: $datatable = '<tr class="LC_odd_row">'.
11252: '<td>'.$title{'togglecats'}.'</td>'.
11253: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11254: '<input type="radio" name="togglecats"'.
11255: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11256: '<label><input type="radio" name="togglecats"'.
11257: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
11258: '</tr><tr>'.
11259: '<td>'.$title{'categorize'}.'</td>'.
11260: '<td class="LC_right_item"><span class="LC_nobreak">'.
11261: '<label><input type="radio" name="categorize"'.
11262: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11263: '<label><input type="radio" name="categorize"'.
11264: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 11265: '</tr><tr class="LC_odd_row">'.
11266: '<td>'.$title{'togglecatscomm'}.'</td>'.
11267: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11268: '<input type="radio" name="togglecatscomm"'.
11269: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11270: '<label><input type="radio" name="togglecatscomm"'.
11271: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
11272: '</tr><tr>'.
11273: '<td>'.$title{'categorizecomm'}.'</td>'.
11274: '<td class="LC_right_item"><span class="LC_nobreak">'.
11275: '<label><input type="radio" name="categorizecomm"'.
11276: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11277: '<label><input type="radio" name="categorizecomm"'.
11278: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 11279: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 11280: '<td>'.$title{'togglecatsplace'}.'</td>'.
11281: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11282: '<input type="radio" name="togglecatsplace"'.
11283: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11284: '<label><input type="radio" name="togglecatscomm"'.
11285: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
11286: '</tr><tr>'.
11287: '<td>'.$title{'categorizeplace'}.'</td>'.
11288: '<td class="LC_right_item"><span class="LC_nobreak">'.
11289: '<label><input type="radio" name="categorizeplace"'.
11290: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11291: '<label><input type="radio" name="categorizeplace"'.
11292: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 11293: '</tr>';
1.272 raeburn 11294: $$rowtotal += 6;
1.57 raeburn 11295: } else {
11296: my $css_class;
11297: my $itemcount = 1;
11298: my $cathash;
11299: if (ref($settings) eq 'HASH') {
11300: $cathash = $settings->{'cats'};
11301: }
11302: if (ref($cathash) eq 'HASH') {
11303: my (@cats,@trails,%allitems,%idx,@jsarray);
11304: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
11305: \%allitems,\%idx,\@jsarray);
11306: my $maxdepth = scalar(@cats);
11307: my $colattrib = '';
11308: if ($maxdepth > 2) {
11309: $colattrib = ' colspan="2" ';
11310: }
11311: my @path;
11312: if (@cats > 0) {
11313: if (ref($cats[0]) eq 'ARRAY') {
11314: my $numtop = @{$cats[0]};
11315: my $maxnum = $numtop;
1.120 raeburn 11316: my %default_names = (
11317: instcode => &mt('Official courses'),
11318: communities => &mt('Communities'),
1.272 raeburn 11319: placement => &mt('Placement Tests'),
1.120 raeburn 11320: );
11321:
11322: if ((!grep(/^instcode$/,@{$cats[0]})) ||
11323: ($cathash->{'instcode::0'} eq '') ||
11324: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 11325: ($cathash->{'communities::0'} eq '') ||
11326: (!grep(/^placement$/,@{$cats[0]})) ||
11327: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 11328: $maxnum ++;
11329: }
11330: my $lastidx;
11331: for (my $i=0; $i<$numtop; $i++) {
11332: my $parent = $cats[0][$i];
11333: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11334: my $item = &escape($parent).'::0';
11335: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
11336: $lastidx = $idx{$item};
11337: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
11338: .'<select name="'.$item.'"'.$chgstr.'>';
11339: for (my $k=0; $k<=$maxnum; $k++) {
11340: my $vpos = $k+1;
11341: my $selstr;
11342: if ($k == $i) {
11343: $selstr = ' selected="selected" ';
11344: }
11345: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11346: }
1.214 raeburn 11347: $datatable .= '</select></span></td><td>';
1.272 raeburn 11348: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 11349: $datatable .= '<span class="LC_nobreak">'
11350: .$default_names{$parent}.'</span>';
11351: if ($parent eq 'instcode') {
11352: $datatable .= '<br /><span class="LC_nobreak">('
11353: .&mt('with institutional codes')
11354: .')</span></td><td'.$colattrib.'>';
11355: } else {
11356: $datatable .= '<table><tr><td>';
11357: }
11358: $datatable .= '<span class="LC_nobreak">'
11359: .'<label><input type="radio" name="'
11360: .$parent.'" value="1" checked="checked" />'
11361: .&mt('Display').'</label>';
11362: if ($parent eq 'instcode') {
11363: $datatable .= ' ';
11364: } else {
11365: $datatable .= '</span></td></tr><tr><td>'
11366: .'<span class="LC_nobreak">';
11367: }
11368: $datatable .= '<label><input type="radio" name="'
11369: .$parent.'" value="0" />'
11370: .&mt('Do not display').'</label></span>';
1.272 raeburn 11371: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 11372: $datatable .= '</td></tr></table>';
11373: }
11374: $datatable .= '</td>';
1.57 raeburn 11375: } else {
11376: $datatable .= $parent
1.214 raeburn 11377: .' <span class="LC_nobreak"><label>'
11378: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 11379: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
11380: }
11381: my $depth = 1;
11382: push(@path,$parent);
11383: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
11384: pop(@path);
11385: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
11386: $itemcount ++;
11387: }
1.48 raeburn 11388: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 11389: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
11390: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 11391: for (my $k=0; $k<=$maxnum; $k++) {
11392: my $vpos = $k+1;
11393: my $selstr;
1.57 raeburn 11394: if ($k == $numtop) {
1.48 raeburn 11395: $selstr = ' selected="selected" ';
11396: }
11397: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11398: }
1.59 bisitz 11399: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 11400: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
11401: .'</tr>'."\n";
1.48 raeburn 11402: $itemcount ++;
1.272 raeburn 11403: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11404: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
11405: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11406: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
11407: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
11408: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
11409: for (my $k=0; $k<=$maxnum; $k++) {
11410: my $vpos = $k+1;
11411: my $selstr;
11412: if ($k == $maxnum) {
11413: $selstr = ' selected="selected" ';
11414: }
11415: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 11416: }
1.120 raeburn 11417: $datatable .= '</select></span></td>'.
11418: '<td><span class="LC_nobreak">'.
11419: $default_names{$default}.'</span>';
11420: if ($default eq 'instcode') {
11421: $datatable .= '<br /><span class="LC_nobreak">('
11422: .&mt('with institutional codes').')</span>';
11423: }
11424: $datatable .= '</td>'
11425: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
11426: .&mt('Display').'</label> '
11427: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
11428: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 11429: }
11430: }
11431: }
1.57 raeburn 11432: } else {
11433: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 11434: }
11435: } else {
1.327 raeburn 11436: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 11437: .&initialize_categories($itemcount);
1.48 raeburn 11438: }
1.57 raeburn 11439: $$rowtotal += $itemcount;
1.48 raeburn 11440: }
11441: return $datatable;
11442: }
11443:
1.69 raeburn 11444: sub print_serverstatuses {
11445: my ($dom,$settings,$rowtotal) = @_;
11446: my $datatable;
11447: my @pages = &serverstatus_pages();
11448: my (%namedaccess,%machineaccess);
11449: foreach my $type (@pages) {
11450: $namedaccess{$type} = '';
11451: $machineaccess{$type}= '';
11452: }
11453: if (ref($settings) eq 'HASH') {
11454: foreach my $type (@pages) {
11455: if (exists($settings->{$type})) {
11456: if (ref($settings->{$type}) eq 'HASH') {
11457: foreach my $key (keys(%{$settings->{$type}})) {
11458: if ($key eq 'namedusers') {
11459: $namedaccess{$type} = $settings->{$type}->{$key};
11460: } elsif ($key eq 'machines') {
11461: $machineaccess{$type} = $settings->{$type}->{$key};
11462: }
11463: }
11464: }
11465: }
11466: }
11467: }
1.81 raeburn 11468: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11469: my $rownum = 0;
11470: my $css_class;
11471: foreach my $type (@pages) {
11472: $rownum ++;
11473: $css_class = $rownum%2?' class="LC_odd_row"':'';
11474: $datatable .= '<tr'.$css_class.'>'.
11475: '<td><span class="LC_nobreak">'.
11476: $titles->{$type}.'</span></td>'.
11477: '<td class="LC_left_item">'.
11478: '<input type="text" name="'.$type.'_namedusers" '.
11479: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
11480: '<td class="LC_right_item">'.
11481: '<span class="LC_nobreak">'.
11482: '<input type="text" name="'.$type.'_machines" '.
11483: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 11484: '</span></td></tr>'."\n";
1.69 raeburn 11485: }
11486: $$rowtotal += $rownum;
11487: return $datatable;
11488: }
11489:
11490: sub serverstatus_pages {
11491: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 11492: 'checksums','clusterstatus','certstatus','metadata_keywords',
11493: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
11494: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 11495: }
11496:
1.236 raeburn 11497: sub defaults_javascript {
11498: my ($settings) = @_;
1.354 raeburn 11499: return unless (ref($settings) eq 'HASH');
1.414 raeburn 11500: my $portal_js = <<"ENDPORTAL";
11501:
11502: function portalExtras(caller) {
11503: var x = caller.value;
11504: var y = new Array('email','web');
1.425 raeburn 11505: for (var i=0; i<y.length; i++) {
1.414 raeburn 11506: if (document.getElementById('portal_def_'+y[i]+'_div')) {
11507: var z = document.getElementById('portal_def_'+y[i]+'_div');
11508: if (x.length > 0) {
11509: z.style.display = 'block';
11510: } else {
11511: z.style.display = 'none';
11512: }
11513: }
11514: }
11515: }
11516: ENDPORTAL
1.236 raeburn 11517: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
11518: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
11519: if ($maxnum eq '') {
11520: $maxnum = 0;
11521: }
11522: $maxnum ++;
1.249 raeburn 11523: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 11524: return <<"ENDSCRIPT";
11525: <script type="text/javascript">
11526: // <![CDATA[
11527: function reorderTypes(form,caller) {
11528: var changedVal;
11529: $jstext
11530: var newpos = 'addinststatus_pos';
11531: var current = new Array;
11532: var maxh = $maxnum;
11533: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11534: var oldVal;
11535: if (caller == newpos) {
11536: changedVal = newitemVal;
11537: } else {
11538: var curritem = 'inststatus_pos_'+caller;
11539: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
11540: current[newitemVal] = newpos;
11541: }
11542: for (var i=0; i<inststatuses.length; i++) {
11543: if (inststatuses[i] != caller) {
11544: var elementName = 'inststatus_pos_'+inststatuses[i];
11545: if (form.elements[elementName]) {
11546: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11547: current[currVal] = elementName;
11548: }
11549: }
11550: }
11551: for (var j=0; j<maxh; j++) {
11552: if (current[j] == undefined) {
11553: oldVal = j;
11554: }
11555: }
11556: if (oldVal < changedVal) {
11557: for (var k=oldVal+1; k<=changedVal ; k++) {
11558: var elementName = current[k];
11559: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11560: }
11561: } else {
11562: for (var k=changedVal; k<oldVal; k++) {
11563: var elementName = current[k];
11564: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11565: }
11566: }
11567: return;
11568: }
11569:
1.414 raeburn 11570: $portal_js
11571:
11572: // ]]>
11573: </script>
11574:
11575: ENDSCRIPT
11576: } else {
11577: return <<"ENDSCRIPT";
11578: <script type="text/javascript">
11579: // <![CDATA[
11580: $portal_js
1.236 raeburn 11581: // ]]>
11582: </script>
11583:
11584: ENDSCRIPT
11585: }
1.354 raeburn 11586: return;
11587: }
11588:
11589: sub passwords_javascript {
1.405 raeburn 11590: my ($prefix) = @_;
11591: my %intalert;
11592: if ($prefix eq 'passwords') {
11593: %intalert = &Apache::lonlocal::texthash (
11594: 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.',
11595: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
11596: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
11597: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
11598: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
11599: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
11600: );
1.421 raeburn 11601: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 11602: %intalert = &Apache::lonlocal::texthash (
11603: passmin => 'Warning: minimum secret length must be a positive integer greater than 6.',
11604: passmax => 'Warning: maximum secret length must be a positive integer (or blank).',
11605: );
11606: }
1.365 raeburn 11607: &js_escape(\%intalert);
11608: my $defmin = $Apache::lonnet::passwdmin;
1.425 raeburn 11609: my $intauthjs;
1.405 raeburn 11610: if ($prefix eq 'passwords') { $intauthjs = <<"ENDSCRIPT";
1.354 raeburn 11611:
11612: function warnIntAuth(field) {
11613: if (field.name == 'intauth_check') {
11614: if (field.value == '2') {
1.365 raeburn 11615: alert('$intalert{authcheck}');
1.354 raeburn 11616: }
11617: }
11618: if (field.name == 'intauth_cost') {
11619: field.value.replace(/\s/g,'');
11620: if (field.value != '') {
11621: var regexdigit=/^\\d+\$/;
11622: if (!regexdigit.test(field.value)) {
1.365 raeburn 11623: alert('$intalert{authcost}');
11624: }
11625: }
11626: }
11627: return;
11628: }
11629:
1.405 raeburn 11630: ENDSCRIPT
11631:
11632: }
11633:
11634: $intauthjs .= <<"ENDSCRIPT";
11635:
11636: function warnInt$prefix(field) {
1.365 raeburn 11637: field.value.replace(/^\s+/,'');
11638: field.value.replace(/\s+\$/,'');
11639: var regexdigit=/^\\d+\$/;
1.408 raeburn 11640: if (field.name == '${prefix}_min') {
1.365 raeburn 11641: if (field.value == '') {
11642: alert('$intalert{passmin}');
11643: field.value = '$defmin';
11644: } else {
11645: if (!regexdigit.test(field.value)) {
11646: alert('$intalert{passmin}');
11647: field.value = '$defmin';
11648: }
1.366 raeburn 11649: var minval = parseInt(field.value,10);
1.365 raeburn 11650: if (minval < $defmin) {
11651: alert('$intalert{passmin}');
11652: field.value = '$defmin';
11653: }
11654: }
11655: } else {
11656: if (field.value == '0') {
11657: field.value = '';
11658: }
11659: if (field.value != '') {
1.408 raeburn 11660: if (field.name == '${prefix}_expire') {
1.365 raeburn 11661: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
11662: if (!regexpposnum.test(field.value)) {
11663: alert('$intalert{passexp}');
11664: field.value = '';
11665: } else {
11666: var expval = parseFloat(field.value);
11667: if (expval == 0) {
11668: alert('$intalert{passexp}');
11669: field.value = '';
11670: }
11671: }
11672: } else {
11673: if (!regexdigit.test(field.value)) {
1.408 raeburn 11674: if (field.name == '${prefix}_max') {
1.365 raeburn 11675: alert('$intalert{passmax}');
11676: } else {
1.408 raeburn 11677: if (field.name == '${prefix}_numsaved') {
1.365 raeburn 11678: alert('$intalert{passnum}');
11679: }
11680: }
1.370 raeburn 11681: field.value = '';
1.365 raeburn 11682: }
1.354 raeburn 11683: }
11684: }
11685: }
11686: return;
11687: }
11688:
11689: ENDSCRIPT
11690: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 11691: }
11692:
1.49 raeburn 11693: sub coursecategories_javascript {
11694: my ($settings) = @_;
1.57 raeburn 11695: my ($output,$jstext,$cathash);
1.49 raeburn 11696: if (ref($settings) eq 'HASH') {
1.57 raeburn 11697: $cathash = $settings->{'cats'};
11698: }
11699: if (ref($cathash) eq 'HASH') {
1.49 raeburn 11700: my (@cats,@jsarray,%idx);
1.57 raeburn 11701: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 11702: if (@jsarray > 0) {
11703: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
11704: for (my $i=0; $i<@jsarray; $i++) {
11705: if (ref($jsarray[$i]) eq 'ARRAY') {
11706: my $catstr = join('","',@{$jsarray[$i]});
11707: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
11708: }
11709: }
11710: }
11711: } else {
11712: $jstext = ' var categories = Array(1);'."\n".
11713: ' categories[0] = Array("instcode_pos");'."\n";
11714: }
1.237 bisitz 11715: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
11716: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 11717: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 11718: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
11719: &js_escape(\$instcode_reserved);
11720: &js_escape(\$communities_reserved);
1.272 raeburn 11721: &js_escape(\$placement_reserved);
1.265 damieng 11722: &js_escape(\$choose_again);
1.49 raeburn 11723: $output = <<"ENDSCRIPT";
11724: <script type="text/javascript">
1.109 raeburn 11725: // <![CDATA[
1.49 raeburn 11726: function reorderCats(form,parent,item,idx) {
11727: var changedVal;
11728: $jstext
11729: var newpos = 'addcategory_pos';
11730: if (parent == '') {
11731: var has_instcode = 0;
11732: var maxtop = categories[idx].length;
11733: for (var j=0; j<maxtop; j++) {
11734: if (categories[idx][j] == 'instcode::0') {
11735: has_instcode == 1;
11736: }
11737: }
11738: if (has_instcode == 0) {
11739: categories[idx][maxtop] = 'instcode_pos';
11740: }
11741: } else {
11742: newpos += '_'+parent;
11743: }
11744: var maxh = 1 + categories[idx].length;
11745: var current = new Array;
11746: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11747: if (item == newpos) {
11748: changedVal = newitemVal;
11749: } else {
11750: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
11751: current[newitemVal] = newpos;
11752: }
11753: for (var i=0; i<categories[idx].length; i++) {
11754: var elementName = categories[idx][i];
11755: if (elementName != item) {
11756: if (form.elements[elementName]) {
11757: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11758: current[currVal] = elementName;
11759: }
11760: }
11761: }
11762: var oldVal;
11763: for (var j=0; j<maxh; j++) {
11764: if (current[j] == undefined) {
11765: oldVal = j;
11766: }
11767: }
11768: if (oldVal < changedVal) {
11769: for (var k=oldVal+1; k<=changedVal ; k++) {
11770: var elementName = current[k];
11771: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11772: }
11773: } else {
11774: for (var k=changedVal; k<oldVal; k++) {
11775: var elementName = current[k];
11776: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11777: }
11778: }
11779: return;
11780: }
1.120 raeburn 11781:
11782: function categoryCheck(form) {
11783: if (form.elements['addcategory_name'].value == 'instcode') {
11784: alert('$instcode_reserved\\n$choose_again');
11785: return false;
11786: }
11787: if (form.elements['addcategory_name'].value == 'communities') {
11788: alert('$communities_reserved\\n$choose_again');
11789: return false;
11790: }
1.272 raeburn 11791: if (form.elements['addcategory_name'].value == 'placement') {
11792: alert('$placement_reserved\\n$choose_again');
11793: return false;
11794: }
1.120 raeburn 11795: return true;
11796: }
11797:
1.109 raeburn 11798: // ]]>
1.49 raeburn 11799: </script>
11800:
11801: ENDSCRIPT
11802: return $output;
11803: }
11804:
1.48 raeburn 11805: sub initialize_categories {
11806: my ($itemcount) = @_;
1.120 raeburn 11807: my ($datatable,$css_class,$chgstr);
1.380 raeburn 11808: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 11809: instcode => 'Official courses (with institutional codes)',
11810: communities => 'Communities',
1.272 raeburn 11811: placement => 'Placement Tests',
1.120 raeburn 11812: );
1.328 raeburn 11813: my %selnum = (
11814: instcode => '0',
11815: communities => '1',
11816: placement => '2',
11817: );
11818: my %selected;
1.272 raeburn 11819: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11820: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 11821: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 11822: map { $selected{$selnum{$_}} = '' } keys(%selnum);
11823: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 11824: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 11825: .'<select name="'.$default.'_pos"'.$chgstr.'>'
11826: .'<option value="0"'.$selected{'0'}.'>1</option>'
11827: .'<option value="1"'.$selected{'1'}.'>2</option>'
11828: .'<option value="2"'.$selected{'2'}.'>3</option>'
11829: .'<option value="3">4</option></select> '
1.120 raeburn 11830: .$default_names{$default}
11831: .'</span></td><td><span class="LC_nobreak">'
11832: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
11833: .&mt('Display').'</label> <label>'
11834: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 11835: .'</label></span></td></tr>';
1.120 raeburn 11836: $itemcount ++;
11837: }
1.48 raeburn 11838: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 11839: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 11840: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 11841: .'<select name="addcategory_pos"'.$chgstr.'>'
11842: .'<option value="0">1</option>'
11843: .'<option value="1">2</option>'
1.328 raeburn 11844: .'<option value="2">3</option>'
11845: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 11846: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
11847: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
11848: .'</td></tr>';
1.48 raeburn 11849: return $datatable;
11850: }
11851:
11852: sub build_category_rows {
1.49 raeburn 11853: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
11854: my ($text,$name,$item,$chgstr);
1.48 raeburn 11855: if (ref($cats) eq 'ARRAY') {
11856: my $maxdepth = scalar(@{$cats});
11857: if (ref($cats->[$depth]) eq 'HASH') {
11858: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
11859: my $numchildren = @{$cats->[$depth]{$parent}};
11860: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 11861: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 11862: my ($idxnum,$parent_name,$parent_item);
11863: my $higher = $depth - 1;
11864: if ($higher == 0) {
11865: $parent_name = &escape($parent).'::'.$higher;
11866: } else {
11867: if (ref($path) eq 'ARRAY') {
11868: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
11869: }
11870: }
11871: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 11872: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 11873: if ($j < $numchildren) {
1.48 raeburn 11874: $name = $cats->[$depth]{$parent}[$j];
11875: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 11876: $idxnum = $idx->{$item};
11877: } else {
11878: $name = $parent_name;
11879: $item = $parent_item;
1.48 raeburn 11880: }
1.49 raeburn 11881: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
11882: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 11883: for (my $i=0; $i<=$numchildren; $i++) {
11884: my $vpos = $i+1;
11885: my $selstr;
11886: if ($j == $i) {
11887: $selstr = ' selected="selected" ';
11888: }
11889: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
11890: }
11891: $text .= '</select> ';
11892: if ($j < $numchildren) {
11893: my $deeper = $depth+1;
11894: $text .= $name.' '
11895: .'<label><input type="checkbox" name="deletecategory" value="'
11896: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
11897: if(ref($path) eq 'ARRAY') {
11898: push(@{$path},$name);
1.49 raeburn 11899: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 11900: pop(@{$path});
11901: }
11902: } else {
1.330 raeburn 11903: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 11904: if ($j == $numchildren) {
11905: $text .= $name;
11906: } else {
11907: $text .= $item;
11908: }
11909: $text .= '" value="" />';
11910: }
11911: $text .= '</td></tr>';
11912: }
11913: $text .= '</table></td>';
11914: } else {
11915: my $higher = $depth-1;
11916: if ($higher == 0) {
11917: $name = &escape($parent).'::'.$higher;
11918: } else {
11919: if (ref($path) eq 'ARRAY') {
11920: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
11921: }
11922: }
11923: my $colspan;
11924: if ($parent ne 'instcode') {
11925: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 11926: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 11927: }
11928: }
11929: }
11930: }
11931: return $text;
11932: }
11933:
1.33 raeburn 11934: sub modifiable_userdata_row {
1.305 raeburn 11935: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357 raeburn 11936: $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228 raeburn 11937: my ($role,$rolename,$statustype);
11938: $role = $item;
1.224 raeburn 11939: if ($context eq 'cancreate') {
1.305 raeburn 11940: if ($item =~ /^(emailusername)_(.+)$/) {
11941: $role = $1;
11942: $statustype = $2;
1.228 raeburn 11943: if (ref($usertypes) eq 'HASH') {
11944: if ($usertypes->{$statustype}) {
11945: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
11946: } else {
11947: $rolename = &mt('Data provided by user');
11948: }
11949: }
1.224 raeburn 11950: }
11951: } elsif ($context eq 'selfcreate') {
1.63 raeburn 11952: if (ref($usertypes) eq 'HASH') {
11953: $rolename = $usertypes->{$role};
11954: } else {
11955: $rolename = $role;
11956: }
1.325 raeburn 11957: } elsif ($context eq 'lti') {
11958: $rolename = &mt('Institutional data used (if available)');
1.357 raeburn 11959: } elsif ($context eq 'privacy') {
11960: $rolename = $itemdesc;
1.33 raeburn 11961: } else {
1.63 raeburn 11962: if ($role eq 'cr') {
11963: $rolename = &mt('Custom role');
11964: } else {
11965: $rolename = &Apache::lonnet::plaintext($role);
11966: }
1.33 raeburn 11967: }
1.224 raeburn 11968: my (@fields,%fieldtitles);
11969: if (ref($fieldsref) eq 'ARRAY') {
11970: @fields = @{$fieldsref};
11971: } else {
11972: @fields = ('lastname','firstname','middlename','generation',
11973: 'permanentemail','id');
11974: }
11975: if ((ref($titlesref) eq 'HASH')) {
11976: %fieldtitles = %{$titlesref};
11977: } else {
11978: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11979: }
1.33 raeburn 11980: my $output;
1.305 raeburn 11981: my $css_class;
11982: if ($rowcount%2) {
11983: $css_class = 'LC_odd_row';
11984: }
11985: if ($customcss) {
11986: $css_class .= " $customcss";
11987: }
11988: $css_class =~ s/^\s+//;
11989: if ($css_class) {
11990: $css_class = ' class="'.$css_class.'"';
11991: }
11992: if ($rowstyle) {
11993: $css_class .= ' style="'.$rowstyle.'"';
11994: }
11995: if ($rowid) {
11996: $rowid = ' id="'.$rowid.'"';
11997: }
11998: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 11999: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
12000: '<td class="LC_left_item" colspan="2"><table>';
12001: my $rem;
12002: my %checks;
12003: if (ref($settings) eq 'HASH') {
1.325 raeburn 12004: my $hashref;
12005: if ($context eq 'lti') {
12006: if (ref($settings) eq 'HASH') {
12007: $hashref = $settings->{'instdata'};
12008: }
1.357 raeburn 12009: } elsif ($context eq 'privacy') {
12010: my ($key,$inner) = split(/_/,$role);
12011: if (ref($settings) eq 'HASH') {
12012: if (ref($settings->{$key}) eq 'HASH') {
12013: $hashref = $settings->{$key}->{$inner};
12014: }
12015: }
1.325 raeburn 12016: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 12017: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 12018: $hashref = $settings->{'lti_instdata'};
12019: }
12020: if ($role eq 'emailusername') {
12021: if ($statustype) {
12022: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
12023: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 12024: }
1.325 raeburn 12025: }
12026: }
12027: }
1.425 raeburn 12028: if (ref($hashref) eq 'HASH') {
1.325 raeburn 12029: foreach my $field (@fields) {
12030: if ($hashref->{$field}) {
12031: if ($role eq 'emailusername') {
12032: $checks{$field} = $hashref->{$field};
12033: } else {
12034: $checks{$field} = ' checked="checked" ';
1.33 raeburn 12035: }
12036: }
12037: }
12038: }
12039: }
1.305 raeburn 12040: my $total = scalar(@fields);
12041: for (my $i=0; $i<$total; $i++) {
12042: $rem = $i%($numinrow);
1.33 raeburn 12043: if ($rem == 0) {
12044: if ($i > 0) {
12045: $output .= '</tr>';
12046: }
12047: $output .= '<tr>';
12048: }
12049: my $check = ' ';
1.228 raeburn 12050: unless ($role eq 'emailusername') {
12051: if (exists($checks{$fields[$i]})) {
1.354 raeburn 12052: $check = $checks{$fields[$i]};
1.357 raeburn 12053: } elsif ($context eq 'privacy') {
12054: if ($role =~ /^priv_(domain|course)$/) {
12055: if (ref($settings) ne 'HASH') {
12056: $check = ' checked="checked" ';
12057: }
12058: } elsif ($role =~ /^priv_(author|community)$/) {
12059: if (ref($settings) ne 'HASH') {
12060: unless ($fields[$i] eq 'id') {
12061: $check = ' checked="checked" ';
12062: }
12063: }
12064: } elsif ($role =~ /^(unpriv|othdom)_/) {
12065: if (ref($settings) ne 'HASH') {
12066: if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
12067: $check = ' checked="checked" ';
12068: }
12069: }
12070: }
1.325 raeburn 12071: } elsif ($context ne 'lti') {
1.228 raeburn 12072: if ($role eq 'st') {
12073: if (ref($settings) ne 'HASH') {
12074: $check = ' checked="checked" ';
12075: }
1.33 raeburn 12076: }
12077: }
12078: }
12079: $output .= '<td class="LC_left_item">'.
1.228 raeburn 12080: '<span class="LC_nobreak">';
1.325 raeburn 12081: my $prefix = 'canmodify';
1.228 raeburn 12082: if ($role eq 'emailusername') {
12083: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
12084: $checks{$fields[$i]} = 'omit';
12085: }
12086: foreach my $option ('required','optional','omit') {
12087: my $checked='';
12088: if ($checks{$fields[$i]} eq $option) {
12089: $checked='checked="checked" ';
12090: }
12091: $output .= '<label>'.
1.325 raeburn 12092: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 12093: &mt($option).'</label>'.(' ' x2);
12094: }
12095: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
12096: } else {
1.325 raeburn 12097: if ($context eq 'lti') {
12098: $prefix = 'lti';
1.357 raeburn 12099: } elsif ($context eq 'privacy') {
12100: $prefix = 'privacy';
1.325 raeburn 12101: }
1.228 raeburn 12102: $output .= '<label>'.
1.325 raeburn 12103: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 12104: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
12105: '</label>';
12106: }
12107: $output .= '</span></td>';
1.33 raeburn 12108: }
1.305 raeburn 12109: $rem = $total%$numinrow;
12110: my $colsleft;
12111: if ($rem) {
12112: $colsleft = $numinrow - $rem;
12113: }
12114: if ($colsleft > 1) {
1.33 raeburn 12115: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
12116: ' </td>';
12117: } elsif ($colsleft == 1) {
12118: $output .= '<td class="LC_left_item"> </td>';
12119: }
12120: $output .= '</tr></table></td></tr>';
12121: return $output;
12122: }
1.28 raeburn 12123:
1.93 raeburn 12124: sub insttypes_row {
1.305 raeburn 12125: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
12126: $customcss,$rowstyle) = @_;
1.93 raeburn 12127: my %lt = &Apache::lonlocal::texthash (
1.429 raeburn 12128: cansearch => 'Users allowed to search',
1.93 raeburn 12129: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.429 raeburn 12130: lockablenames => 'User preference to lock name',
12131: selfassign => 'Self-reportable affiliations',
12132: overrides => "Override domain's helpdesk settings based on requester's affiliation",
12133: webdav => 'WebDAV access available',
12134: authorquota => 'Authoring Space quota (MB)',
1.93 raeburn 12135: );
1.429 raeburn 12136: my ($showdom,$defaultquota);
1.93 raeburn 12137: if ($context eq 'cansearch') {
12138: $showdom = ' ('.$dom.')';
1.429 raeburn 12139: } elsif ($context eq 'authorquota') {
12140: $defaultquota = 500;
1.93 raeburn 12141: }
1.165 raeburn 12142: my $class = 'LC_left_item';
12143: if ($context eq 'statustocreate') {
12144: $class = 'LC_right_item';
12145: }
1.305 raeburn 12146: my $css_class;
12147: if ($$rowtotal%2) {
12148: $css_class = 'LC_odd_row';
12149: }
12150: if ($customcss) {
12151: $css_class .= ' '.$customcss;
12152: }
12153: $css_class =~ s/^\s+//;
12154: if ($css_class) {
12155: $css_class = ' class="'.$css_class.'"';
12156: }
12157: if ($rowstyle) {
12158: $css_class .= ' style="'.$rowstyle.'"';
12159: }
12160: if ($onclick) {
12161: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 12162: }
12163: my $output = '<tr'.$css_class.'>'.
12164: '<td>'.$lt{$context}.$showdom.
12165: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 12166: my $rem;
12167: if (ref($types) eq 'ARRAY') {
12168: for (my $i=0; $i<@{$types}; $i++) {
12169: if (defined($usertypes->{$types->[$i]})) {
12170: my $rem = $i%($numinrow);
12171: if ($rem == 0) {
12172: if ($i > 0) {
12173: $output .= '</tr>';
12174: }
12175: $output .= '<tr>';
1.23 raeburn 12176: }
1.429 raeburn 12177: if ($context eq 'authorquota') {
12178: my $currquota;
12179: if ($settings->{$context}->{$types->[$i]} =~ /^\d+$/) {
12180: $currquota = $settings->{$context}->{$types->[$i]};
12181: } else {
12182: $currquota = $defaultquota;
12183: }
12184: $output .= '<td class="LC_left_item">'."\n".
12185: '<label><span class="LC_nobreak">'."\n".
12186: $usertypes->{$types->[$i]}.'</span><br />'."\n".
12187: '<input type="text" name="'.$context.'_'.$types->[$i].'" '.
12188: 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
12189: '</label></td>';
12190: } else {
12191: my $check = ' ';
12192: if (ref($settings) eq 'HASH') {
12193: if (ref($settings->{$context}) eq 'ARRAY') {
12194: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
12195: $check = ' checked="checked" ';
12196: }
12197: } elsif (ref($settings->{$context}) eq 'HASH') {
12198: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
12199: $check = ' checked="checked" ';
12200: } elsif ($context eq 'webdav') {
12201: if ($settings->{$context}->{$types->[$i]}) {
12202: $check = ' checked="checked" ';
12203: }
12204: }
12205: } elsif ($context eq 'statustocreate') {
1.315 raeburn 12206: $check = ' checked="checked" ';
12207: }
1.26 raeburn 12208: }
1.429 raeburn 12209: $output .= '<td class="LC_left_item">'.
12210: '<span class="LC_nobreak"><label>'.
12211: '<input type="checkbox" name="'.$context.'" '.
12212: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
12213: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 12214: }
12215: }
12216: }
1.26 raeburn 12217: $rem = @{$types}%($numinrow);
1.23 raeburn 12218: }
12219: my $colsleft = $numinrow - $rem;
1.315 raeburn 12220: if ($context eq 'overrides') {
12221: if ($colsleft > 1) {
12222: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12223: } else {
12224: $output .= '<td class="LC_left_item">';
12225: }
1.425 raeburn 12226: $output .= ' ';
1.23 raeburn 12227: } else {
1.334 raeburn 12228: if ($rem == 0) {
1.315 raeburn 12229: $output .= '<tr>';
12230: }
12231: if ($colsleft > 1) {
12232: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12233: } else {
12234: $output .= '<td class="LC_left_item">';
12235: }
1.429 raeburn 12236: if ($context eq 'authorquota') {
12237: my $currquota = 500;
12238: if ((ref($settings) eq 'HASH') && (ref($settings->{$context}) eq 'HASH')) {
12239: if ($settings->{$context}{'default'} =~ /^\d+$/) {
12240: $currquota = $settings->{$context}{'default'};
12241: }
12242: }
12243: $output .= '<label><span class="LC_nobreak">'.$othertitle.'</span><br />'."\n".
12244: '<input type="text" name="'.$context.'_default" '.
12245: 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
12246: '</label>';
12247: } else {
12248: my $defcheck = ' ';
12249: if (ref($settings) eq 'HASH') {
12250: if (ref($settings->{$context}) eq 'ARRAY') {
12251: if (grep(/^default$/,@{$settings->{$context}})) {
12252: $defcheck = ' checked="checked" ';
12253: }
12254: } elsif (ref($settings->{$context}) eq 'HASH') {
12255: if (ref($settings->{$context}->{'default'}) eq 'HASH') {
12256: $defcheck = ' checked="checked" ';
12257: } elsif ($context eq 'webdav') {
12258: if ($settings->{$context}->{'default'}) {
12259: $defcheck = ' checked="checked" ';
12260: }
12261: }
12262: } elsif ($context eq 'statustocreate') {
1.315 raeburn 12263: $defcheck = ' checked="checked" ';
12264: }
1.99 raeburn 12265: }
1.429 raeburn 12266: $output .= '<span class="LC_nobreak"><label>'.
12267: '<input type="checkbox" name="'.$context.'" '.
12268: 'value="default"'.$defcheck.$onclick.'/>'.
12269: $othertitle.'</label></span>';
1.26 raeburn 12270: }
1.23 raeburn 12271: }
1.315 raeburn 12272: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 12273: return $output;
1.23 raeburn 12274: }
12275:
12276: sub sorted_searchtitles {
12277: my %searchtitles = &Apache::lonlocal::texthash(
12278: 'uname' => 'username',
12279: 'lastname' => 'last name',
12280: 'lastfirst' => 'last name, first name',
12281: );
12282: my @titleorder = ('uname','lastname','lastfirst');
12283: return (\%searchtitles,\@titleorder);
12284: }
12285:
1.25 raeburn 12286: sub sorted_searchtypes {
12287: my %srchtypes_desc = (
12288: exact => 'is exact match',
12289: contains => 'contains ..',
12290: begins => 'begins with ..',
12291: );
12292: my @srchtypeorder = ('exact','begins','contains');
12293: return (\%srchtypes_desc,\@srchtypeorder);
12294: }
12295:
1.3 raeburn 12296: sub usertype_update_row {
12297: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
12298: my $datatable;
12299: my $numinrow = 4;
12300: foreach my $type (@{$types}) {
12301: if (defined($usertypes->{$type})) {
12302: $$rownums ++;
12303: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
12304: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
12305: '</td><td class="LC_left_item"><table>';
12306: for (my $i=0; $i<@{$fields}; $i++) {
12307: my $rem = $i%($numinrow);
12308: if ($rem == 0) {
12309: if ($i > 0) {
12310: $datatable .= '</tr>';
12311: }
12312: $datatable .= '<tr>';
12313: }
12314: my $check = ' ';
1.39 raeburn 12315: if (ref($settings) eq 'HASH') {
12316: if (ref($settings->{'fields'}) eq 'HASH') {
12317: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
12318: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
12319: $check = ' checked="checked" ';
12320: }
1.3 raeburn 12321: }
12322: }
12323: }
12324:
12325: if ($i == @{$fields}-1) {
12326: my $colsleft = $numinrow - $rem;
12327: if ($colsleft > 1) {
12328: $datatable .= '<td colspan="'.$colsleft.'">';
12329: } else {
12330: $datatable .= '<td>';
12331: }
12332: } else {
12333: $datatable .= '<td>';
12334: }
1.8 raeburn 12335: $datatable .= '<span class="LC_nobreak"><label>'.
12336: '<input type="checkbox" name="updateable_'.$type.
12337: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
12338: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 12339: }
12340: $datatable .= '</tr></table></td></tr>';
12341: }
12342: }
12343: return $datatable;
1.1 raeburn 12344: }
12345:
12346: sub modify_login {
1.205 raeburn 12347: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 12348: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.386 raeburn 12349: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
1.412 raeburn 12350: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso);
1.168 raeburn 12351: %title = ( coursecatalog => 'Display course catalog',
12352: adminmail => 'Display administrator E-mail address',
1.188 raeburn 12353: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 12354: newuser => 'Link for visitors to create a user account',
1.386 raeburn 12355: loginheader => 'Log-in box header',
12356: saml => 'Dual SSO and non-SSO login');
1.168 raeburn 12357: @offon = ('off','on');
1.112 raeburn 12358: if (ref($domconfig{login}) eq 'HASH') {
12359: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
12360: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
12361: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
12362: }
12363: }
1.386 raeburn 12364: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
12365: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
12366: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
12367: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
12368: $saml{$lonhost} = 1;
12369: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
12370: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
12371: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
12372: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
12373: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
1.412 raeburn 12374: $samlwindow{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'window'};
1.386 raeburn 12375: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
12376: }
12377: }
12378: }
1.112 raeburn 12379: }
1.9 raeburn 12380: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
12381: \%domconfig,\%loginhash);
1.188 raeburn 12382: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12383: foreach my $item (@toggles) {
12384: $loginhash{login}{$item} = $env{'form.'.$item};
12385: }
1.41 raeburn 12386: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 12387: if (ref($colchanges{'login'}) eq 'HASH') {
12388: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
12389: \%loginhash);
12390: }
1.110 raeburn 12391:
1.149 raeburn 12392: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 12393: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 12394: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 12395: if (keys(%servers) > 1) {
12396: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 12397: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
12398: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
12399: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
12400: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
12401: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
12402: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12403: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12404: $changes{'loginvia'}{$lonhost} = 1;
12405: } else {
12406: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
12407: $changes{'loginvia'}{$lonhost} = 1;
12408: }
12409: } else {
12410: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12411: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12412: $changes{'loginvia'}{$lonhost} = 1;
12413: }
12414: }
12415: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
12416: foreach my $item (@loginvia_attribs) {
12417: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
12418: }
12419: } else {
12420: foreach my $item (@loginvia_attribs) {
12421: my $new = $env{'form.'.$lonhost.'_'.$item};
12422: if (($item eq 'serverpath') && ($new eq 'custom')) {
12423: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
12424: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12425: $new = '/';
12426: }
12427: }
12428: if (($item eq 'custompath') &&
12429: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12430: $new = '';
12431: }
12432: if ($new ne $curr_loginvia{$lonhost}{$item}) {
12433: $changes{'loginvia'}{$lonhost} = 1;
12434: }
12435: if ($item eq 'exempt') {
1.256 raeburn 12436: $new = &check_exempt_addresses($new);
1.128 raeburn 12437: }
12438: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12439: }
12440: }
1.112 raeburn 12441: } else {
1.128 raeburn 12442: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12443: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 12444: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 12445: foreach my $item (@loginvia_attribs) {
12446: my $new = $env{'form.'.$lonhost.'_'.$item};
12447: if (($item eq 'serverpath') && ($new eq 'custom')) {
12448: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12449: $new = '/';
12450: }
12451: }
12452: if (($item eq 'custompath') &&
12453: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12454: $new = '';
12455: }
12456: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12457: }
1.110 raeburn 12458: }
12459: }
12460: }
12461: }
1.119 raeburn 12462:
1.168 raeburn 12463: my $servadm = $r->dir_config('lonAdmEMail');
12464: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
12465: if (ref($domconfig{'login'}) eq 'HASH') {
12466: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
12467: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
12468: if ($lang eq 'nolang') {
12469: push(@currlangs,$lang);
12470: } elsif (defined($langchoices{$lang})) {
12471: push(@currlangs,$lang);
12472: } else {
12473: next;
12474: }
12475: }
12476: }
12477: }
12478: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
12479: if (@currlangs > 0) {
12480: foreach my $lang (@currlangs) {
12481: if (grep(/^\Q$lang\E$/,@delurls)) {
12482: $changes{'helpurl'}{$lang} = 1;
12483: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
12484: $changes{'helpurl'}{$lang} = 1;
12485: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
12486: push(@newlangs,$lang);
12487: } else {
12488: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12489: }
12490: }
12491: }
12492: unless (grep(/^nolang$/,@currlangs)) {
12493: if ($env{'form.loginhelpurl_nolang.filename'}) {
12494: $changes{'helpurl'}{'nolang'} = 1;
12495: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
12496: push(@newlangs,'nolang');
12497: }
12498: }
12499: if ($env{'form.loginhelpurl_add_lang'}) {
12500: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
12501: ($env{'form.loginhelpurl_add_file.filename'})) {
12502: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
12503: $addedfile = $env{'form.loginhelpurl_add_lang'};
12504: }
12505: }
12506: if ((@newlangs > 0) || ($addedfile)) {
12507: my $error;
12508: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12509: if ($configuserok eq 'ok') {
12510: if ($switchserver) {
12511: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
12512: } elsif ($author_ok eq 'ok') {
12513: my @allnew = @newlangs;
12514: if ($addedfile ne '') {
12515: push(@allnew,$addedfile);
12516: }
1.421 raeburn 12517: my $modified = [];
1.168 raeburn 12518: foreach my $lang (@allnew) {
12519: my $formelem = 'loginhelpurl_'.$lang;
12520: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
12521: $formelem = 'loginhelpurl_add_file';
12522: }
1.425 raeburn 12523: (my $result,$newurl{$lang}) =
1.421 raeburn 12524: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12525: "help/$lang",'','',$newfile{$lang},
12526: $modified);
1.168 raeburn 12527: if ($result eq 'ok') {
12528: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
12529: $changes{'helpurl'}{$lang} = 1;
12530: } else {
12531: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
12532: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 12533: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 12534: (!grep(/^\Q$lang\E$/,@delurls))) {
12535: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12536: }
12537: }
12538: }
1.421 raeburn 12539: &update_modify_urls($r,$modified);
1.168 raeburn 12540: } else {
12541: $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);
12542: }
12543: } else {
12544: $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);
12545: }
12546: if ($error) {
12547: &Apache::lonnet::logthis($error);
12548: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12549: }
12550: }
1.256 raeburn 12551:
12552: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
12553: if (ref($domconfig{'login'}) eq 'HASH') {
12554: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
12555: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
12556: if ($domservers{$lonhost}) {
12557: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12558: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 12559: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 12560: }
12561: }
12562: }
12563: }
12564: }
12565: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
12566: foreach my $lonhost (sort(keys(%domservers))) {
12567: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12568: $changes{'headtag'}{$lonhost} = 1;
12569: } else {
12570: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
12571: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
12572: }
12573: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
12574: push(@newhosts,$lonhost);
12575: } elsif ($currheadtagurls{$lonhost}) {
12576: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
12577: if ($currexempt{$lonhost}) {
1.289 raeburn 12578: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 12579: $changes{'headtag'}{$lonhost} = 1;
12580: }
12581: } elsif ($possexempt{$lonhost}) {
12582: $changes{'headtag'}{$lonhost} = 1;
12583: }
12584: if ($possexempt{$lonhost}) {
12585: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12586: }
12587: }
12588: }
12589: }
12590: if (@newhosts) {
12591: my $error;
12592: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12593: if ($configuserok eq 'ok') {
12594: if ($switchserver) {
12595: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
12596: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12597: my $modified = [];
1.256 raeburn 12598: foreach my $lonhost (@newhosts) {
12599: my $formelem = 'loginheadtag_'.$lonhost;
1.425 raeburn 12600: (my $result,$newheadtagurls{$lonhost}) =
1.421 raeburn 12601: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12602: "login/headtag/$lonhost",'','',
12603: $env{'form.loginheadtag_'.$lonhost.'.filename'},
12604: $modified);
1.256 raeburn 12605: if ($result eq 'ok') {
12606: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
12607: $changes{'headtag'}{$lonhost} = 1;
12608: if ($possexempt{$lonhost}) {
12609: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12610: }
12611: } else {
12612: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
12613: $newheadtagurls{$lonhost},$result);
12614: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12615: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
12616: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
12617: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
12618: }
12619: }
12620: }
1.421 raeburn 12621: &update_modify_urls($r,$modified);
1.256 raeburn 12622: } else {
12623: $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);
12624: }
12625: } else {
12626: $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);
12627: }
12628: if ($error) {
12629: &Apache::lonnet::logthis($error);
12630: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12631: }
12632: }
1.386 raeburn 12633: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
12634: my @newsamlimgs;
12635: foreach my $lonhost (keys(%domservers)) {
12636: if ($env{'form.saml_'.$lonhost}) {
12637: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
12638: push(@newsamlimgs,$lonhost);
12639: }
1.412 raeburn 12640: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12641: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
12642: }
12643: if ($saml{$lonhost}) {
1.412 raeburn 12644: if ($env{'form.saml_window_'.$lonhost} ne '1') {
12645: $env{'form.saml_window_'.$lonhost} = '';
12646: }
1.386 raeburn 12647: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
12648: #FIXME Need to obsolete published image
12649: delete($currsaml{$lonhost}{'img'});
12650: $changes{'saml'}{$lonhost} = 1;
12651: }
12652: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
12653: $changes{'saml'}{$lonhost} = 1;
12654: }
12655: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
12656: $changes{'saml'}{$lonhost} = 1;
12657: }
12658: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
12659: $changes{'saml'}{$lonhost} = 1;
12660: }
12661: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
12662: $changes{'saml'}{$lonhost} = 1;
12663: }
1.412 raeburn 12664: if ($env{'form.saml_window_'.$lonhost} ne $samlwindow{$lonhost}) {
12665: $changes{'saml'}{$lonhost} = 1;
12666: }
1.386 raeburn 12667: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
12668: $changes{'saml'}{$lonhost} = 1;
12669: }
12670: } else {
12671: $changes{'saml'}{$lonhost} = 1;
12672: }
1.412 raeburn 12673: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12674: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
12675: }
12676: } else {
1.425 raeburn 12677: if ($saml{$lonhost}) {
1.389 raeburn 12678: $changes{'saml'}{$lonhost} = 1;
12679: delete($currsaml{$lonhost});
12680: }
1.386 raeburn 12681: }
12682: }
12683: foreach my $posshost (keys(%currsaml)) {
1.425 raeburn 12684: unless (exists($domservers{$posshost})) {
12685: delete($currsaml{$posshost});
1.386 raeburn 12686: }
12687: }
12688: %{$loginhash{'login'}{'saml'}} = %currsaml;
12689: if (@newsamlimgs) {
12690: my $error;
12691: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12692: if ($configuserok eq 'ok') {
12693: if ($switchserver) {
12694: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
12695: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12696: my $modified = [];
1.386 raeburn 12697: foreach my $lonhost (@newsamlimgs) {
12698: my $formelem = 'saml_img_'.$lonhost;
1.425 raeburn 12699: my ($result,$imgurl) =
1.421 raeburn 12700: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12701: "login/saml/$lonhost",'','',
12702: $env{'form.saml_img_'.$lonhost.'.filename'},
12703: $modified);
1.386 raeburn 12704: if ($result eq 'ok') {
12705: $currsaml{$lonhost}{'img'} = $imgurl;
12706: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
12707: $changes{'saml'}{$lonhost} = 1;
12708: } else {
12709: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
12710: $lonhost,$result);
12711: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12712: }
12713: }
1.421 raeburn 12714: &update_modify_urls($r,$modified);
1.386 raeburn 12715: } else {
12716: $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);
12717: }
12718: } else {
12719: $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);
12720: }
12721: if ($error) {
12722: &Apache::lonnet::logthis($error);
12723: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12724: }
12725: }
1.169 raeburn 12726: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 12727:
12728: my $defaulthelpfile = '/adm/loginproblems.html';
12729: my $defaulttext = &mt('Default in use');
12730:
1.1 raeburn 12731: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
12732: $dom);
12733: if ($putresult eq 'ok') {
1.188 raeburn 12734: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12735: my %defaultchecked = (
12736: 'coursecatalog' => 'on',
1.188 raeburn 12737: 'helpdesk' => 'on',
1.42 raeburn 12738: 'adminmail' => 'off',
1.43 raeburn 12739: 'newuser' => 'off',
1.42 raeburn 12740: );
1.55 raeburn 12741: if (ref($domconfig{'login'}) eq 'HASH') {
12742: foreach my $item (@toggles) {
12743: if ($defaultchecked{$item} eq 'on') {
12744: if (($domconfig{'login'}{$item} eq '0') &&
12745: ($env{'form.'.$item} eq '1')) {
12746: $changes{$item} = 1;
12747: } elsif (($domconfig{'login'}{$item} eq '' ||
12748: $domconfig{'login'}{$item} eq '1') &&
12749: ($env{'form.'.$item} eq '0')) {
12750: $changes{$item} = 1;
12751: }
12752: } elsif ($defaultchecked{$item} eq 'off') {
12753: if (($domconfig{'login'}{$item} eq '1') &&
12754: ($env{'form.'.$item} eq '0')) {
12755: $changes{$item} = 1;
12756: } elsif (($domconfig{'login'}{$item} eq '' ||
12757: $domconfig{'login'}{$item} eq '0') &&
12758: ($env{'form.'.$item} eq '1')) {
12759: $changes{$item} = 1;
12760: }
1.42 raeburn 12761: }
12762: }
1.41 raeburn 12763: }
1.6 raeburn 12764: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 12765: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.386 raeburn 12766: if (exists($changes{'saml'})) {
12767: my $hostid_in_use;
12768: my @hosts = &Apache::lonnet::current_machine_ids();
12769: if (@hosts > 1) {
12770: foreach my $hostid (@hosts) {
12771: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
12772: $hostid_in_use = $hostid;
12773: last;
12774: }
12775: }
12776: } else {
12777: $hostid_in_use = $r->dir_config('lonHostID');
12778: }
12779: if (($hostid_in_use) &&
12780: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
1.387 raeburn 12781: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
1.386 raeburn 12782: }
12783: if (ref($lastactref) eq 'HASH') {
12784: if (ref($changes{'saml'}) eq 'HASH') {
12785: my %updates;
12786: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
12787: $lastactref->{'samllanding'} = \%updates;
12788: }
12789: }
12790: }
1.212 raeburn 12791: if (ref($lastactref) eq 'HASH') {
12792: $lastactref->{'domainconfig'} = 1;
12793: }
1.1 raeburn 12794: $resulttext = &mt('Changes made:').'<ul>';
12795: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 12796: if ($item eq 'loginvia') {
1.112 raeburn 12797: if (ref($changes{$item}) eq 'HASH') {
12798: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
12799: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 12800: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
12801: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
12802: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
12803: $protocol = 'http' if ($protocol ne 'https');
12804: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
12805:
12806: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
12807: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
12808: } else {
12809: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
12810: }
12811: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
12812: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
12813: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
12814: }
12815: $resulttext .= '</li>';
12816: } else {
12817: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
12818: }
1.112 raeburn 12819: } else {
1.128 raeburn 12820: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 12821: }
12822: }
1.128 raeburn 12823: $resulttext .= '</ul></li>';
1.112 raeburn 12824: }
1.168 raeburn 12825: } elsif ($item eq 'helpurl') {
12826: if (ref($changes{$item}) eq 'HASH') {
12827: foreach my $lang (sort(keys(%{$changes{$item}}))) {
12828: if (grep(/^\Q$lang\E$/,@delurls)) {
12829: my ($chg,$link);
12830: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
12831: if ($lang eq 'nolang') {
12832: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
12833: } else {
12834: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
12835: }
12836: $resulttext .= '<li>'.$chg.'</li>';
12837: } else {
12838: my $chg;
12839: if ($lang eq 'nolang') {
12840: $chg = &mt('custom log-in help file for no preferred language');
12841: } else {
12842: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
12843: }
12844: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
12845: $loginhash{'login'}{'helpurl'}{$lang}.
12846: '?inhibitmenu=yes',$chg,600,500).
12847: '</li>';
12848: }
12849: }
12850: }
1.256 raeburn 12851: } elsif ($item eq 'headtag') {
12852: if (ref($changes{$item}) eq 'HASH') {
12853: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12854: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12855: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
12856: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12857: $resulttext .= '<li><a href="'.
12858: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
12859: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
12860: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
12861: if ($possexempt{$lonhost}) {
12862: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
12863: } else {
12864: $resulttext .= &mt('included for any client IP');
12865: }
12866: $resulttext .= '</li>';
12867: }
12868: }
12869: }
1.386 raeburn 12870: } elsif ($item eq 'saml') {
12871: if (ref($changes{$item}) eq 'HASH') {
12872: my %notlt = (
12873: text => 'Text for log-in by SSO',
12874: img => 'SSO button image',
12875: alt => 'Alt text for button image',
12876: url => 'SSO URL',
12877: title => 'Tooltip for SSO link',
1.412 raeburn 12878: window => 'Pop-up window if iframe',
1.386 raeburn 12879: notsso => 'Text for non-SSO log-in',
12880: );
12881: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12882: if (ref($currsaml{$lonhost}) eq 'HASH') {
12883: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
12884: '<ul>';
1.412 raeburn 12885: foreach my $key ('text','img','alt','url','title','window','notsso') {
1.386 raeburn 12886: if ($currsaml{$lonhost}{$key} eq '') {
12887: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
12888: } else {
12889: my $value = "'$currsaml{$lonhost}{$key}'";
12890: if ($key eq 'img') {
12891: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
1.412 raeburn 12892: } elsif ($key eq 'window') {
12893: $value = 'On';
1.386 raeburn 12894: }
12895: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
12896: $value).'</li>';
12897: }
12898: }
12899: $resulttext .= '</ul></li>';
12900: } else {
12901: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
12902: }
12903: }
12904: }
1.169 raeburn 12905: } elsif ($item eq 'captcha') {
12906: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 12907: my $chgtxt;
1.169 raeburn 12908: if ($loginhash{'login'}{$item} eq 'notused') {
12909: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
12910: } else {
12911: my %captchas = &captcha_phrases();
12912: if ($captchas{$loginhash{'login'}{$item}}) {
12913: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
12914: } else {
12915: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
12916: }
12917: }
12918: $resulttext .= '<li>'.$chgtxt.'</li>';
12919: }
12920: } elsif ($item eq 'recaptchakeys') {
12921: if (ref($loginhash{'login'}) eq 'HASH') {
12922: my ($privkey,$pubkey);
12923: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
12924: $pubkey = $loginhash{'login'}{$item}{'public'};
12925: $privkey = $loginhash{'login'}{$item}{'private'};
12926: }
12927: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
12928: if (!$pubkey) {
12929: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
12930: } else {
12931: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
12932: }
12933: if (!$privkey) {
12934: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
12935: } else {
1.251 raeburn 12936: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 12937: }
12938: $chgtxt .= '</ul>';
12939: $resulttext .= '<li>'.$chgtxt.'</li>';
12940: }
1.269 raeburn 12941: } elsif ($item eq 'recaptchaversion') {
12942: if (ref($loginhash{'login'}) eq 'HASH') {
12943: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 12944: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 12945: '</li>';
12946: }
12947: }
1.41 raeburn 12948: } else {
12949: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
12950: }
1.1 raeburn 12951: }
1.6 raeburn 12952: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 12953: } else {
12954: $resulttext = &mt('No changes made to log-in page settings');
12955: }
12956: } else {
1.11 albertel 12957: $resulttext = '<span class="LC_error">'.
12958: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12959: }
1.6 raeburn 12960: if ($errors) {
1.9 raeburn 12961: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 12962: $errors.'</ul>';
12963: }
12964: return $resulttext;
12965: }
12966:
1.256 raeburn 12967: sub check_exempt_addresses {
12968: my ($iplist) = @_;
12969: $iplist =~ s/^\s+//;
12970: $iplist =~ s/\s+$//;
12971: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
12972: my (@okips,$new);
12973: foreach my $ip (@poss_ips) {
12974: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
12975: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
12976: push(@okips,$ip);
12977: }
12978: }
12979: }
12980: if (@okips > 0) {
12981: $new = join(',',@okips);
12982: } else {
12983: $new = '';
12984: }
12985: return $new;
12986: }
12987:
1.6 raeburn 12988: sub color_font_choices {
12989: my %choices =
12990: &Apache::lonlocal::texthash (
12991: img => "Header",
12992: bgs => "Background colors",
12993: links => "Link colors",
1.55 raeburn 12994: images => "Images",
1.6 raeburn 12995: font => "Font color",
1.201 raeburn 12996: fontmenu => "Font menu",
1.76 raeburn 12997: pgbg => "Page",
1.6 raeburn 12998: tabbg => "Header",
12999: sidebg => "Border",
13000: link => "Link",
13001: alink => "Active link",
13002: vlink => "Visited link",
13003: );
13004: return %choices;
13005: }
13006:
1.394 raeburn 13007: sub modify_ipaccess {
13008: my ($dom,$lastactref,%domconfig) = @_;
13009: my (@allpos,%changes,%confhash,$errors,$resulttext);
13010: my (@items,%deletions,%itemids,@warnings);
13011: my ($typeorder,$types) = &commblocktype_text();
13012: if ($env{'form.ipaccess_add'}) {
13013: my $name = $env{'form.ipaccess_name_add'};
13014: my ($newid,$error) = &get_ipaccess_id($dom,$name);
13015: if ($newid) {
13016: $itemids{'add'} = $newid;
13017: push(@items,'add');
13018: $changes{$newid} = 1;
13019: } else {
13020: $error = &mt('Failed to acquire unique ID for new IP access control item');
13021: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13022: }
13023: }
13024: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
13025: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
13026: if (@todelete) {
13027: map { $deletions{$_} = 1; } @todelete;
13028: }
13029: my $maxnum = $env{'form.ipaccess_maxnum'};
13030: for (my $i=0; $i<$maxnum; $i++) {
13031: my $itemid = $env{'form.ipaccess_id_'.$i};
13032: $itemid =~ s/\D+//g;
13033: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13034: if ($deletions{$itemid}) {
13035: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
13036: } else {
13037: push(@items,$i);
13038: $itemids{$i} = $itemid;
13039: }
13040: }
13041: }
13042: }
13043: foreach my $idx (@items) {
13044: my $itemid = $itemids{$idx};
13045: next unless ($itemid);
13046: my %current;
13047: unless ($idx eq 'add') {
13048: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13049: %current = %{$domconfig{'ipaccess'}{$itemid}};
13050: }
13051: }
13052: my $position = $env{'form.ipaccess_pos_'.$itemid};
13053: $position =~ s/\D+//g;
13054: if ($position ne '') {
13055: $allpos[$position] = $itemid;
13056: }
13057: my $name = $env{'form.ipaccess_name_'.$idx};
13058: $name =~ s/^\s+|\s+$//g;
13059: $confhash{$itemid}{'name'} = $name;
13060: my $possrange = $env{'form.ipaccess_range_'.$idx};
13061: $possrange =~ s/^\s+|\s+$//g;
13062: unless ($possrange eq '') {
13063: $possrange =~ s/[\r\n]+/\s/g;
13064: $possrange =~ s/\s*-\s*/-/g;
13065: $possrange =~ s/\s+/,/g;
13066: $possrange =~ s/,+/,/g;
13067: if ($possrange ne '') {
13068: my (@ok,$count);
1.425 raeburn 13069: $count = 0;
1.394 raeburn 13070: foreach my $poss (split(/\,/,$possrange)) {
13071: $count ++;
13072: $poss = &validate_ip_pattern($poss);
13073: if ($poss ne '') {
13074: push(@ok,$poss);
13075: }
13076: }
13077: my $diff = $count - scalar(@ok);
13078: if ($diff) {
13079: $errors .= '<li><span class="LC_error">'.
13080: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
13081: $diff,$name).
13082: '</span></li>';
13083: }
13084: if (@ok) {
13085: my @cidr_list;
13086: foreach my $item (@ok) {
13087: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
13088: }
13089: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
13090: }
13091: }
13092: }
13093: foreach my $field ('name','ip') {
13094: unless (($idx eq 'add') || ($changes{$itemid})) {
13095: if ($current{$field} ne $confhash{$itemid}{$field}) {
13096: $changes{$itemid} = 1;
13097: last;
13098: }
13099: }
13100: }
13101: $confhash{$itemid}{'commblocks'} = {};
1.425 raeburn 13102:
1.394 raeburn 13103: my %commblocks;
1.425 raeburn 13104: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
1.394 raeburn 13105: foreach my $type (@{$typeorder}) {
13106: if ($commblocks{$type}) {
13107: $confhash{$itemid}{'commblocks'}{$type} = 'on';
13108: }
13109: unless (($idx eq 'add') || ($changes{$itemid})) {
13110: if (ref($current{'commblocks'}) eq 'HASH') {
13111: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
13112: $changes{$itemid} = 1;
13113: }
13114: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
13115: $changes{$itemid} = 1;
13116: }
13117: }
13118: }
13119: $confhash{$itemid}{'courses'} = {};
13120: my %crsdeletions;
13121: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
13122: if (@delcrs) {
13123: map { $crsdeletions{$_} = 1; } @delcrs;
13124: }
13125: if (ref($current{'courses'}) eq 'HASH') {
13126: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
13127: if ($crsdeletions{$cid}) {
13128: $changes{$itemid} = 1;
13129: } else {
13130: $confhash{$itemid}{'courses'}{$cid} = 1;
13131: }
13132: }
13133: }
13134: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
13135: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
1.425 raeburn 13136: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
1.394 raeburn 13137: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
13138: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
13139: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
13140: $errors .= '<li><span class="LC_error">'.
13141: &mt('Invalid courseID [_1] omitted from list of allowed courses',
13142: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
13143: '</span></li>';
13144: } else {
13145: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
13146: $changes{$itemid} = 1;
13147: }
13148: }
13149: }
13150: if (@allpos > 0) {
13151: my $idx = 0;
13152: foreach my $itemid (@allpos) {
13153: if ($itemid ne '') {
13154: $confhash{$itemid}{'order'} = $idx;
13155: unless ($changes{$itemid}) {
13156: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
13157: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13158: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
13159: $changes{$itemid} = 1;
13160: }
13161: }
13162: }
13163: }
13164: $idx ++;
13165: }
13166: }
13167: }
13168: if (keys(%changes)) {
13169: my %defaultshash = (
13170: ipaccess => \%confhash,
13171: );
13172: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13173: $dom);
13174: if ($putresult eq 'ok') {
13175: my $cachetime = 1800;
13176: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
13177: if (ref($lastactref) eq 'HASH') {
13178: $lastactref->{'ipaccess'} = 1;
13179: }
13180: $resulttext = &mt('Changes made:').'<ul>';
13181: my %bynum;
13182: foreach my $itemid (sort(keys(%changes))) {
13183: if (ref($confhash{$itemid}) eq 'HASH') {
13184: my $position = $confhash{$itemid}{'order'};
13185: if ($position =~ /^\d+$/) {
13186: $bynum{$position} = $itemid;
13187: }
13188: }
13189: }
13190: if (keys(%deletions)) {
13191: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
13192: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
13193: }
13194: }
13195: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
13196: my $itemid = $bynum{$pos};
13197: if (ref($confhash{$itemid}) eq 'HASH') {
13198: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
13199: my $position = $pos + 1;
13200: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
13201: if ($confhash{$itemid}{'ip'} eq '') {
13202: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
13203: } else {
13204: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
13205: }
13206: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
13207: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
13208: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
13209: '</li>';
13210: } else {
13211: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
13212: }
13213: if (keys(%{$confhash{$itemid}{'courses'}})) {
13214: my @courses;
13215: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
1.425 raeburn 13216: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1.394 raeburn 13217: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
13218: }
13219: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
13220: join('</li><li>',@courses).'</li></ul>';
13221: } else {
13222: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
13223: }
1.395 raeburn 13224: $resulttext .= '</ul></li>';
1.394 raeburn 13225: }
13226: }
1.395 raeburn 13227: $resulttext .= '</ul>';
1.394 raeburn 13228: } else {
13229: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13230: }
13231: } else {
13232: $resulttext = &mt('No changes made');
13233: }
13234: if ($errors) {
13235: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
13236: $errors.'</ul></p>';
13237: }
13238: return $resulttext;
13239: }
13240:
13241: sub get_ipaccess_id {
13242: my ($domain,$location) = @_;
13243: # get lock on ipaccess db
13244: my $lockhash = {
13245: lock => $env{'user.name'}.
13246: ':'.$env{'user.domain'},
13247: };
13248: my $tries = 0;
13249: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13250: my ($id,$error);
13251:
13252: while (($gotlock ne 'ok') && ($tries<10)) {
13253: $tries ++;
13254: sleep (0.1);
13255: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13256: }
13257: if ($gotlock eq 'ok') {
13258: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
13259: if ($currids{'lock'}) {
13260: delete($currids{'lock'});
13261: if (keys(%currids)) {
13262: my @curr = sort { $a <=> $b } keys(%currids);
13263: if ($curr[-1] =~ /^\d+$/) {
13264: $id = 1 + $curr[-1];
13265: }
13266: } else {
13267: $id = 1;
13268: }
13269: if ($id) {
13270: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
13271: $error = 'nostore';
13272: }
13273: } else {
13274: $error = 'nonumber';
13275: }
13276: }
13277: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
13278: } else {
13279: $error = 'nolock';
13280: }
13281: return ($id,$error);
13282: }
13283:
1.429 raeburn 13284: sub modify_authordefaults {
13285: my ($dom,$lastactref,%domconfig) = @_;
13286: #
13287: # Retrieve current domain configuration for webDAV and Authoring Space quotas from $domconfig{'quotas'}.
13288: #
13289: my (%curr_quotas,%save_quotas,%confhash,%changes,%newvalues);
13290: if (ref($domconfig{'quotas'}) eq 'HASH') {
13291: foreach my $key (keys(%{$domconfig{'quotas'}})) {
13292: if ($key =~ /^webdav|authorquota$/) {
13293: $curr_quotas{$key} = $domconfig{'quotas'}{$key};
13294: } else {
13295: $save_quotas{$key} = $domconfig{'quotas'}{$key};
13296: }
13297: }
13298: }
13299: my %staticdefaults = (
13300: 'copyright' => 'default',
13301: 'sourceavail' => 'closed',
13302: 'nocodemirror' => 'off',
13303: 'domcoordacc' => 'on',
13304: 'editors' => ['edit','xml'].
13305: 'authorquota' => 500,
13306: 'webdav' => 0,
13307: );
13308: my %titles = &authordefaults_titles();
13309: foreach my $item ('nocodemirror','domcoordacc') {
13310: if ($env{'form.'.$item} =~ /^(0|1)$/) {
13311: $confhash{$item} = $env{'form.'.$item};
13312: }
13313: }
13314: if ($env{'form.copyright'} =~ /^(default|domain|public)$/) {
13315: $confhash{'copyright'} = $1;
13316: }
13317: if ($env{'form.sourceavail'} =~ /^(closed|open)$/) {
13318: $confhash{'sourceavail'} = $1;
13319: }
13320: my @posseditors = &Apache::loncommon::get_env_multiple('form.author_editors');
13321: my @okeditors = ('edit','xml','daxe');
13322: my @editors;
13323: foreach my $item (@posseditors) {
13324: if (grep(/^\Q$item\E$/,@okeditors)) {
13325: push(@editors,$item);
13326: }
13327: }
13328: $confhash{'editors'} = \@editors;
13329:
13330: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13331: my @insttypes;
13332: if (ref($types) eq 'ARRAY') {
13333: @insttypes = @{$types};
13334: }
13335: my @webdavon = &Apache::loncommon::get_env_multiple('form.webdav');
13336: my %webdav;
13337: map { $webdav{$_} = 1; } @webdavon;
13338: foreach my $type (@insttypes,'default') {
13339: my $possquota = $env{'form.authorquota_'.$type};
13340: if ($possquota =~ /^\d+$/) {
13341: $save_quotas{'authorquota'}{$type} = $possquota;
13342: }
13343: if ($webdav{$type}) {
13344: $save_quotas{'webdav'}{$type} = 1;
13345: } else {
13346: $save_quotas{'webdav'}{$type} = 0;
13347: }
13348: }
13349: if ($env{'form.webdav_LC_adv'} =~ /^(0|1)$/) {
13350: $save_quotas{'webdav'}{'_LC_adv'} = $env{'form.webdav_LC_adv'};
13351: }
13352: if (ref($domconfig{'authordefaults'}) eq 'HASH') {
13353: foreach my $item ('nocodemirror','domcoordacc','copyright','sourceavail') {
13354: if ($domconfig{'authordefaults'}{$item} ne $confhash{$item}) {
13355: $changes{$item} = 1;
13356: }
13357: }
13358: if (ref($domconfig{'authordefaults'}{'editors'}) eq 'ARRAY') {
13359: my @diffs =
13360: &Apache::loncommon::compare_arrays($confhash{'editors'},
13361: $domconfig{'authordefaults'}{'editors'});
13362: unless (@diffs == 0) {
13363: $changes{'editors'} = 1;
13364: }
13365: } else {
13366: my @diffs =
13367: &Apache::loncommon::compare_arrays($confhash{'editors'},
13368: $staticdefaults{'editors'});
13369: unless (@diffs == 0) {
13370: $changes{'editors'} = 1;
13371: }
13372: }
13373: } else {
13374: my @offon = ('off','on');
13375: foreach my $item ('nocodemirror','domcoordacc') {
13376: if ($offon[$confhash{$item}] ne $staticdefaults{$item}) {
13377: $changes{$item} = 1;
13378: }
13379: }
13380: foreach my $item ('copyright','sourceavail') {
13381: if ($confhash{$item} ne $staticdefaults{$item}) {
13382: $changes{$item} = 1;
13383: }
13384: }
13385: }
13386: foreach my $key ('authorquota','webdav') {
13387: if (ref($curr_quotas{$key}) eq 'HASH') {
13388: foreach my $type (@insttypes,'default') {
13389: if (exists($save_quotas{$key}{$type})) {
13390: if ($save_quotas{$key}{$type} ne $curr_quotas{$key}{$type}) {
13391: $changes{$key}{$type} = 1;
13392: }
13393: } elsif (exists($curr_quotas{$key}{$type})) {
13394: $save_quotas{$key}{$type} = $curr_quotas{$key}{$type};
13395: } else {
13396: $save_quotas{$key}{$type} = $staticdefaults{$key};
13397: }
13398: }
13399: } else {
13400: foreach my $type (@insttypes,'default') {
13401: if (exists($save_quotas{$key}{$type})) {
13402: unless ($save_quotas{$key}{$type} eq $staticdefaults{$key}) {
13403: $changes{$key}{$type} = 1;
13404: }
13405: } else {
13406: $save_quotas{$key}{$type} = $staticdefaults{$key};
13407: }
13408: }
13409: }
13410: }
13411: if (ref($curr_quotas{'webdav'}) eq 'HASH') {
13412: if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
13413: if ($save_quotas{'webdav'}{'_LC_adv'} ne $curr_quotas{'webdav'}{'_LC_adv'}) {
13414: $changes{'webdav_LC_adv'} = 1;
13415: }
13416: } elsif (exists($curr_quotas{'webdav'}{'_LC_adv'})) {
13417: $changes{'webdav_LC_adv'} = 1;
13418: }
13419: } elsif (exists($save_quotas{'webdav'}{'_LC_adv'})) {
13420: $changes{'webdav_LC_adv'} = 1;
13421: }
13422: my %confighash = (
13423: quotas => \%save_quotas,
13424: authordefaults => \%confhash,
13425: );
13426: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,
13427: $dom);
13428: my $resulttext;
13429: if ($putresult eq 'ok') {
13430: if (keys(%changes)) {
1.431 raeburn 13431: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.429 raeburn 13432: if ((exists($changes{'authorquota'})) || (exists($changes{'webdav'})) ||
13433: ($changes{'webdav_LC_adv'})) {
13434: if ((exists($changes{'authorquota'})) && (ref($save_quotas{'authorquota'}) eq 'HASH')) {
13435: $domdefaults{'authorquota'} = $save_quotas{'authorquota'};
13436: }
13437: if (((exists($changes{'webdav'})) || ($changes{'webdav_LC_adv'})) &&
13438: (ref($save_quotas{'webdav'}) eq 'HASH')) {
13439: $domdefaults{'webdav'} = $save_quotas{'webdav'};
13440: }
13441: }
13442: $resulttext = &mt('Changes made:').'<ul>';
13443: my $authoroverride;
13444: foreach my $key ('nocodemirror','domcoordacc','copyright','sourceavail') {
13445: if (exists($changes{$key})) {
1.431 raeburn 13446: $domdefaults{$key} = $confhash{$key};
1.429 raeburn 13447: my $shown;
13448: unless ($authoroverride) {
13449: $resulttext .= '<li>'.&mt('Defaults which can be overridden by Author').'<ul>';
13450: $authoroverride = 1;
13451: }
13452: if (($key eq 'nocodemirror') || ($key eq 'domcoordacc')) {
13453: $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
13454: } elsif ($key eq 'copyright') {
13455: $shown = &Apache::loncommon::copyrightdescription($confhash{$key});
13456: } elsif ($key eq 'sourceavail') {
13457: $shown = &Apache::loncommon::source_copyrightdescription($confhash{$key});
13458: }
13459: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
13460: }
13461: }
13462: if ($authoroverride) {
13463: $resulttext .= '</ul></li>';
13464: }
13465: my $domcoordoverride;
13466: foreach my $key ('editors','authorquota','webdav','webdav_LC_adv') {
13467: if (exists($changes{$key})) {
13468: my $shown;
13469: unless ($domcoordoverride) {
13470: $resulttext .= '<li>'.&mt('Defaults which can be overridden by a Domain Coodinator').'<ul>';
13471: $domcoordoverride = 1;
13472: }
13473: if ($key eq 'editors') {
1.431 raeburn 13474: if (ref($confhash{'editors'}) eq 'ARRAY') {
13475: $domdefaults{'editors'} = join(',',@{$confhash{'editors'}});
13476: if (@{$confhash{'editors'}}) {
13477: $shown = join(', ', map { $titles{$_} } @{$confhash{'editors'}});
13478: } else {
13479: $shown = &mt('None');
13480: }
1.429 raeburn 13481: }
13482: } elsif ($key eq 'authorquota') {
13483: foreach my $type (@insttypes) {
13484: $shown .= $usertypes->{$type}.' -- '.$save_quotas{$key}{$type}.', ';
13485: }
13486: $shown .= $othertitle.' -- '.$save_quotas{$key}{'default'};
13487: } elsif ($key eq 'webdav') {
13488: foreach my $type (@insttypes) {
13489: $shown .= $usertypes->{$type}.' -- '. ($save_quotas{$key}{$type} ? &mt('Yes') : &mt('No')).', ';
13490: }
13491: $shown .= $othertitle.' -- '. ($save_quotas{$key}{'default'} ? &mt('Yes') : &mt('No'));
13492: } elsif ($key eq 'webdav_LC_adv') {
13493: if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
13494: $shown = ($save_quotas{'webdav'}{'_LC_adv'} ? $titles{'overon'} : $titles{'overoff'});
13495: } else {
13496: $shown = $titles{'none'};
13497: }
13498: }
13499: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
13500: }
13501: }
13502: if ($domcoordoverride) {
13503: $resulttext .= '</ul></li>';
13504: }
1.431 raeburn 13505: my $cachetime = 24*60*60;
13506: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13507: if (ref($lastactref) eq 'HASH') {
13508: $lastactref->{'domdefaults'} = 1;
13509: }
1.429 raeburn 13510: } else {
13511: $resulttext = &mt('No changes made to Authoring Space defaults');
13512: }
13513: }
13514: return $resulttext;
13515: }
13516:
1.6 raeburn 13517: sub modify_rolecolors {
1.205 raeburn 13518: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 13519: my ($resulttext,%rolehash);
13520: $rolehash{'rolecolors'} = {};
1.55 raeburn 13521: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
13522: if ($domconfig{'rolecolors'} eq '') {
13523: $domconfig{'rolecolors'} = {};
13524: }
13525: }
1.9 raeburn 13526: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 13527: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
13528: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
13529: $dom);
13530: if ($putresult eq 'ok') {
13531: if (keys(%changes) > 0) {
1.41 raeburn 13532: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 13533: if (ref($lastactref) eq 'HASH') {
13534: $lastactref->{'domainconfig'} = 1;
13535: }
1.6 raeburn 13536: $resulttext = &display_colorchgs($dom,\%changes,$roles,
13537: $rolehash{'rolecolors'});
13538: } else {
13539: $resulttext = &mt('No changes made to default color schemes');
13540: }
13541: } else {
1.11 albertel 13542: $resulttext = '<span class="LC_error">'.
13543: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 13544: }
13545: if ($errors) {
13546: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
13547: $errors.'</ul>';
13548: }
13549: return $resulttext;
13550: }
13551:
13552: sub modify_colors {
1.9 raeburn 13553: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 13554: my (%changes,%choices);
1.51 raeburn 13555: my @bgs;
1.6 raeburn 13556: my @links = ('link','alink','vlink');
1.41 raeburn 13557: my @logintext;
1.6 raeburn 13558: my @images;
13559: my $servadm = $r->dir_config('lonAdmEMail');
13560: my $errors;
1.200 raeburn 13561: my %defaults;
1.6 raeburn 13562: foreach my $role (@{$roles}) {
13563: if ($role eq 'login') {
1.12 raeburn 13564: %choices = &login_choices();
1.41 raeburn 13565: @logintext = ('textcol','bgcol');
1.12 raeburn 13566: } else {
13567: %choices = &color_font_choices();
13568: }
13569: if ($role eq 'login') {
1.41 raeburn 13570: @images = ('img','logo','domlogo','login');
1.51 raeburn 13571: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 13572: } else {
13573: @images = ('img');
1.200 raeburn 13574: @bgs = ('pgbg','tabbg','sidebg');
13575: }
13576: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
13577: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
13578: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
13579: }
13580: if ($role eq 'login') {
13581: foreach my $item (@logintext) {
1.234 raeburn 13582: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13583: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13584: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13585: }
13586: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 13587: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13588: }
13589: }
13590: } else {
1.234 raeburn 13591: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
13592: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
13593: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
13594: }
13595: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 13596: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
13597: }
1.6 raeburn 13598: }
1.200 raeburn 13599: foreach my $item (@bgs) {
1.234 raeburn 13600: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13601: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13602: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13603: }
13604: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 13605: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13606: }
13607: }
13608: foreach my $item (@links) {
1.234 raeburn 13609: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13610: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13611: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13612: }
13613: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 13614: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13615: }
1.6 raeburn 13616: }
1.46 raeburn 13617: my ($configuserok,$author_ok,$switchserver) =
13618: &config_check($dom,$confname,$servadm);
1.9 raeburn 13619: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 13620: if (ref($domconfig->{$role}) ne 'HASH') {
13621: $domconfig->{$role} = {};
13622: }
1.8 raeburn 13623: foreach my $img (@images) {
1.402 raeburn 13624: if ($role eq 'login') {
13625: if (($img eq 'img') || ($img eq 'logo')) {
13626: if (defined($env{'form.login_showlogo_'.$img})) {
13627: $confhash->{$role}{'showlogo'}{$img} = 1;
13628: } else {
13629: $confhash->{$role}{'showlogo'}{$img} = 0;
13630: }
13631: }
13632: if ($env{'form.login_alt_'.$img} ne '') {
13633: $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
1.70 raeburn 13634: }
1.402 raeburn 13635: }
1.18 albertel 13636: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
13637: && !defined($domconfig->{$role}{$img})
13638: && !$env{'form.'.$role.'_del_'.$img}
13639: && $env{'form.'.$role.'_import_'.$img}) {
13640: # import the old configured image from the .tab setting
13641: # if they haven't provided a new one
13642: $domconfig->{$role}{$img} =
13643: $env{'form.'.$role.'_import_'.$img};
13644: }
1.6 raeburn 13645: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 13646: my $error;
1.6 raeburn 13647: if ($configuserok eq 'ok') {
1.9 raeburn 13648: if ($switchserver) {
1.12 raeburn 13649: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 13650: } else {
13651: if ($author_ok eq 'ok') {
1.421 raeburn 13652: my $modified = [];
1.9 raeburn 13653: my ($result,$logourl) =
1.421 raeburn 13654: &Apache::lonconfigsettings::publishlogo($r,'upload',$role.'_'.$img,
13655: $dom,$confname,$img,$width,$height,
13656: '',$modified);
1.9 raeburn 13657: if ($result eq 'ok') {
13658: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 13659: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13660: &update_modify_urls($r,$modified);
1.9 raeburn 13661: } else {
1.12 raeburn 13662: $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 13663: }
13664: } else {
1.46 raeburn 13665: $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 13666: }
13667: }
13668: } else {
1.46 raeburn 13669: $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 13670: }
13671: if ($error) {
1.8 raeburn 13672: &Apache::lonnet::logthis($error);
1.11 albertel 13673: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 13674: }
13675: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 13676: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
13677: my $error;
13678: if ($configuserok eq 'ok') {
13679: # is confname an author?
13680: if ($switchserver eq '') {
13681: if ($author_ok eq 'ok') {
1.421 raeburn 13682: my $modified = [];
1.9 raeburn 13683: my ($result,$logourl) =
1.421 raeburn 13684: &Apache::lonconfigsettings::publishlogo($r,'copy',$domconfig->{$role}{$img},
13685: $dom,$confname,$img,$width,$height,
13686: '',$modified);
1.9 raeburn 13687: if ($result eq 'ok') {
13688: $confhash->{$role}{$img} = $logourl;
1.18 albertel 13689: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13690: &update_modify_urls($r,$modified);
1.9 raeburn 13691: }
13692: }
13693: }
13694: }
1.6 raeburn 13695: }
13696: }
13697: }
13698: if (ref($domconfig) eq 'HASH') {
13699: if (ref($domconfig->{$role}) eq 'HASH') {
13700: foreach my $img (@images) {
13701: if ($domconfig->{$role}{$img} ne '') {
13702: if ($env{'form.'.$role.'_del_'.$img}) {
13703: $confhash->{$role}{$img} = '';
1.12 raeburn 13704: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13705: } else {
1.9 raeburn 13706: if ($confhash->{$role}{$img} eq '') {
13707: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
13708: }
1.6 raeburn 13709: }
13710: } else {
13711: if ($env{'form.'.$role.'_del_'.$img}) {
13712: $confhash->{$role}{$img} = '';
1.12 raeburn 13713: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13714: }
13715: }
1.402 raeburn 13716: if ($role eq 'login') {
13717: if (($img eq 'logo') || ($img eq 'img')) {
13718: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
13719: if ($confhash->{$role}{'showlogo'}{$img} ne
13720: $domconfig->{$role}{'showlogo'}{$img}) {
13721: $changes{$role}{'showlogo'}{$img} = 1;
13722: }
13723: } else {
13724: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13725: $changes{$role}{'showlogo'}{$img} = 1;
13726: }
1.70 raeburn 13727: }
1.402 raeburn 13728: }
13729: if ($img ne 'login') {
13730: if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
13731: if ($confhash->{$role}{'alttext'}{$img} ne
13732: $domconfig->{$role}{'alttext'}{$img}) {
13733: $changes{$role}{'alttext'}{$img} = 1;
13734: }
13735: } else {
13736: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13737: $changes{$role}{'alttext'}{$img} = 1;
13738: }
1.70 raeburn 13739: }
13740: }
13741: }
13742: }
1.6 raeburn 13743: if ($domconfig->{$role}{'font'} ne '') {
13744: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
13745: $changes{$role}{'font'} = 1;
13746: }
13747: } else {
13748: if ($confhash->{$role}{'font'}) {
13749: $changes{$role}{'font'} = 1;
13750: }
13751: }
1.107 raeburn 13752: if ($role ne 'login') {
13753: if ($domconfig->{$role}{'fontmenu'} ne '') {
13754: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
13755: $changes{$role}{'fontmenu'} = 1;
13756: }
13757: } else {
13758: if ($confhash->{$role}{'fontmenu'}) {
13759: $changes{$role}{'fontmenu'} = 1;
13760: }
1.97 tempelho 13761: }
13762: }
1.6 raeburn 13763: foreach my $item (@bgs) {
13764: if ($domconfig->{$role}{$item} ne '') {
13765: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13766: $changes{$role}{'bgs'}{$item} = 1;
13767: }
13768: } else {
13769: if ($confhash->{$role}{$item}) {
13770: $changes{$role}{'bgs'}{$item} = 1;
13771: }
13772: }
13773: }
13774: foreach my $item (@links) {
13775: if ($domconfig->{$role}{$item} ne '') {
13776: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13777: $changes{$role}{'links'}{$item} = 1;
13778: }
13779: } else {
13780: if ($confhash->{$role}{$item}) {
13781: $changes{$role}{'links'}{$item} = 1;
13782: }
13783: }
13784: }
1.41 raeburn 13785: foreach my $item (@logintext) {
13786: if ($domconfig->{$role}{$item} ne '') {
13787: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13788: $changes{$role}{'logintext'}{$item} = 1;
13789: }
13790: } else {
13791: if ($confhash->{$role}{$item}) {
13792: $changes{$role}{'logintext'}{$item} = 1;
13793: }
13794: }
13795: }
1.6 raeburn 13796: } else {
13797: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13798: \@logintext,$confhash,\%changes);
1.6 raeburn 13799: }
13800: } else {
13801: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13802: \@logintext,$confhash,\%changes);
1.6 raeburn 13803: }
13804: }
13805: return ($errors,%changes);
13806: }
13807:
1.46 raeburn 13808: sub config_check {
13809: my ($dom,$confname,$servadm) = @_;
13810: my ($configuserok,$author_ok,$switchserver,%currroles);
13811: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
13812: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
13813: $confname,$servadm);
13814: if ($configuserok eq 'ok') {
13815: $switchserver = &check_switchserver($dom,$confname);
13816: if ($switchserver eq '') {
13817: $author_ok = &check_authorstatus($dom,$confname,%currroles);
13818: }
13819: }
13820: return ($configuserok,$author_ok,$switchserver);
13821: }
13822:
1.6 raeburn 13823: sub default_change_checker {
1.41 raeburn 13824: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 13825: foreach my $item (@{$links}) {
13826: if ($confhash->{$role}{$item}) {
13827: $changes->{$role}{'links'}{$item} = 1;
13828: }
13829: }
13830: foreach my $item (@{$bgs}) {
13831: if ($confhash->{$role}{$item}) {
13832: $changes->{$role}{'bgs'}{$item} = 1;
13833: }
13834: }
1.41 raeburn 13835: foreach my $item (@{$logintext}) {
13836: if ($confhash->{$role}{$item}) {
13837: $changes->{$role}{'logintext'}{$item} = 1;
13838: }
13839: }
1.6 raeburn 13840: foreach my $img (@{$images}) {
13841: if ($env{'form.'.$role.'_del_'.$img}) {
13842: $confhash->{$role}{$img} = '';
1.12 raeburn 13843: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 13844: }
1.70 raeburn 13845: if ($role eq 'login') {
13846: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13847: $changes->{$role}{'showlogo'}{$img} = 1;
13848: }
1.402 raeburn 13849: if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
13850: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13851: $changes->{$role}{'alttext'}{$img} = 1;
13852: }
13853: }
1.70 raeburn 13854: }
1.6 raeburn 13855: }
13856: if ($confhash->{$role}{'font'}) {
13857: $changes->{$role}{'font'} = 1;
13858: }
1.48 raeburn 13859: }
1.6 raeburn 13860:
13861: sub display_colorchgs {
13862: my ($dom,$changes,$roles,$confhash) = @_;
13863: my (%choices,$resulttext);
13864: if (!grep(/^login$/,@{$roles})) {
13865: $resulttext = &mt('Changes made:').'<br />';
13866: }
13867: foreach my $role (@{$roles}) {
13868: if ($role eq 'login') {
13869: %choices = &login_choices();
13870: } else {
13871: %choices = &color_font_choices();
13872: }
13873: if (ref($changes->{$role}) eq 'HASH') {
13874: if ($role ne 'login') {
13875: $resulttext .= '<h4>'.&mt($role).'</h4>';
13876: }
13877: foreach my $key (sort(keys(%{$changes->{$role}}))) {
13878: if ($role ne 'login') {
13879: $resulttext .= '<ul>';
13880: }
13881: if (ref($changes->{$role}{$key}) eq 'HASH') {
13882: if ($role ne 'login') {
13883: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
13884: }
13885: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 13886: if (($role eq 'login') && ($key eq 'showlogo')) {
13887: if ($confhash->{$role}{$key}{$item}) {
13888: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
13889: } else {
13890: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
13891: }
1.402 raeburn 13892: } elsif (($role eq 'login') && ($key eq 'alttext')) {
13893: if ($confhash->{$role}{$key}{$item} ne '') {
1.403 raeburn 13894: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
1.402 raeburn 13895: $confhash->{$role}{$key}{$item}).'</li>';
13896: } else {
13897: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
13898: }
1.70 raeburn 13899: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 13900: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
13901: } else {
1.12 raeburn 13902: my $newitem = $confhash->{$role}{$item};
13903: if ($key eq 'images') {
1.306 raeburn 13904: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 13905: }
13906: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 13907: }
13908: }
13909: if ($role ne 'login') {
13910: $resulttext .= '</ul></li>';
13911: }
13912: } else {
13913: if ($confhash->{$role}{$key} eq '') {
13914: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
13915: } else {
13916: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
13917: }
13918: }
13919: if ($role ne 'login') {
13920: $resulttext .= '</ul>';
13921: }
13922: }
13923: }
13924: }
1.3 raeburn 13925: return $resulttext;
1.1 raeburn 13926: }
13927:
1.9 raeburn 13928: sub thumb_dimensions {
13929: return ('200','50');
13930: }
13931:
1.16 raeburn 13932: sub check_dimensions {
13933: my ($inputfile) = @_;
13934: my ($fullwidth,$fullheight);
13935: if ($inputfile =~ m|^[/\w.\-]+$|) {
13936: if (open(PIPE,"identify $inputfile 2>&1 |")) {
13937: my $imageinfo = <PIPE>;
13938: if (!close(PIPE)) {
13939: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
13940: }
13941: chomp($imageinfo);
13942: my ($fullsize) =
1.21 raeburn 13943: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 13944: if ($fullsize) {
13945: ($fullwidth,$fullheight) = split(/x/,$fullsize);
13946: }
13947: }
13948: }
13949: return ($fullwidth,$fullheight);
13950: }
13951:
1.9 raeburn 13952: sub check_configuser {
13953: my ($uhome,$dom,$confname,$servadm) = @_;
13954: my ($configuserok,%currroles);
13955: if ($uhome eq 'no_host') {
13956: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.361 raeburn 13957: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 13958: $configuserok =
13959: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
13960: $configpass,'','','','','',undef,$servadm);
13961: } else {
13962: $configuserok = 'ok';
13963: %currroles =
13964: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
13965: }
13966: return ($configuserok,%currroles);
13967: }
13968:
13969: sub check_authorstatus {
13970: my ($dom,$confname,%currroles) = @_;
13971: my $author_ok;
1.40 raeburn 13972: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 13973: my $start = time;
13974: my $end = 0;
13975: $author_ok =
13976: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 13977: 'au',$end,$start,'','','domconfig');
1.9 raeburn 13978: } else {
13979: $author_ok = 'ok';
13980: }
13981: return $author_ok;
13982: }
13983:
1.421 raeburn 13984: sub update_modify_urls {
13985: my ($r,$modified) = @_;
13986: if ((ref($modified) eq 'ARRAY') && (@{$modified})) {
13987: push(@{$modified_urls},$modified);
13988: unless ($registered_cleanup) {
13989: my $handlers = $r->get_handlers('PerlCleanupHandler');
13990: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
13991: $registered_cleanup=1;
1.9 raeburn 13992: }
13993: }
1.155 raeburn 13994: }
13995:
13996: sub notifysubscribed {
13997: foreach my $targetsource (@{$modified_urls}){
13998: next unless (ref($targetsource) eq 'ARRAY');
13999: my ($target,$source)=@{$targetsource};
14000: if ($source ne '') {
1.316 raeburn 14001: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 14002: print $logfh "\nCleanup phase: Notifications\n";
14003: my @subscribed=&subscribed_hosts($target);
14004: foreach my $subhost (@subscribed) {
14005: print $logfh "\nNotifying host ".$subhost.':';
14006: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
14007: print $logfh $reply;
14008: }
14009: my @subscribedmeta=&subscribed_hosts("$target.meta");
14010: foreach my $subhost (@subscribedmeta) {
14011: print $logfh "\nNotifying host for metadata only ".$subhost.':';
14012: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
14013: $subhost);
14014: print $logfh $reply;
14015: }
14016: print $logfh "\n============ Done ============\n";
1.160 raeburn 14017: close($logfh);
1.155 raeburn 14018: }
14019: }
14020: }
14021: return OK;
14022: }
14023:
14024: sub subscribed_hosts {
14025: my ($target) = @_;
14026: my @subscribed;
1.316 raeburn 14027: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 14028: while (my $subline=<$fh>) {
14029: if ($subline =~ /^($match_lonid):/) {
14030: my $host = $1;
14031: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
14032: unless (grep(/^\Q$host\E$/,@subscribed)) {
14033: push(@subscribed,$host);
14034: }
14035: }
14036: }
14037: }
14038: }
14039: return @subscribed;
1.9 raeburn 14040: }
14041:
14042: sub check_switchserver {
14043: my ($dom,$confname) = @_;
1.424 raeburn 14044: my ($allowed,$switchserver,$home);
14045: if ($confname eq '') {
1.9 raeburn 14046: $home = &Apache::lonnet::domain($dom,'primary');
1.424 raeburn 14047: } else {
14048: $home = &Apache::lonnet::homeserver($confname,$dom);
14049: if ($home eq 'no_host') {
14050: $home = &Apache::lonnet::domain($dom,'primary');
14051: }
1.9 raeburn 14052: }
14053: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 14054: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
14055: if (!$allowed) {
1.426 raeburn 14056: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
14057: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
14058: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 14059: }
14060: return $switchserver;
14061: }
14062:
1.1 raeburn 14063: sub modify_quotas {
1.216 raeburn 14064: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 14065: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 14066: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 14067: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
14068: $validationfieldsref);
1.86 raeburn 14069: if ($action eq 'quotas') {
1.429 raeburn 14070: $context = 'tools';
1.163 raeburn 14071: } else {
1.86 raeburn 14072: $context = $action;
14073: }
14074: if ($context eq 'requestcourses') {
1.325 raeburn 14075: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 14076: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 14077: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
14078: %titles = &courserequest_titles();
14079: $toolregexp = join('|',@usertools);
14080: %conditions = &courserequest_conditions();
1.216 raeburn 14081: $confname = $dom.'-domainconfig';
14082: my $servadm = $r->dir_config('lonAdmEMail');
14083: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 14084: ($validationitemsref,$validationnamesref,$validationfieldsref) =
14085: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 14086: } elsif ($context eq 'requestauthor') {
14087: @usertools = ('author');
14088: %titles = &authorrequest_titles();
1.86 raeburn 14089: } else {
1.430 raeburn 14090: @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.101 raeburn 14091: %titles = &tool_titles();
1.86 raeburn 14092: }
1.212 raeburn 14093: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 14094: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 14095: foreach my $key (keys(%env)) {
1.101 raeburn 14096: if ($context eq 'requestcourses') {
14097: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
14098: my $item = $1;
14099: my $type = $2;
14100: if ($type =~ /^limit_(.+)/) {
14101: $limithash{$item}{$1} = $env{$key};
14102: } else {
14103: $confhash{$item}{$type} = $env{$key};
14104: }
14105: }
1.163 raeburn 14106: } elsif ($context eq 'requestauthor') {
14107: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
14108: $confhash{$1} = $env{$key};
14109: }
1.101 raeburn 14110: } else {
1.86 raeburn 14111: if ($key =~ /^form\.quota_(.+)$/) {
14112: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 14113: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 14114: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
14115: }
1.72 raeburn 14116: }
14117: }
1.163 raeburn 14118: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 14119: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 14120: @approvalnotify = sort(@approvalnotify);
14121: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 14122: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 14123: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
14124: foreach my $type (@hasuniquecode) {
14125: if (grep(/^\Q$type\E$/,@crstypes)) {
14126: $confhash{'uniquecode'}{$type} = 1;
14127: }
1.216 raeburn 14128: }
1.242 raeburn 14129: my (%newbook,%allpos);
1.216 raeburn 14130: if ($context eq 'requestcourses') {
1.242 raeburn 14131: foreach my $type ('textbooks','templates') {
14132: @{$allpos{$type}} = ();
14133: my $invalid;
14134: if ($type eq 'textbooks') {
14135: $invalid = &mt('Invalid LON-CAPA course for textbook');
14136: } else {
14137: $invalid = &mt('Invalid LON-CAPA course for template');
14138: }
14139: if ($env{'form.'.$type.'_addbook'}) {
14140: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
14141: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
14142: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
14143: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
14144: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
14145: } else {
14146: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
14147: my $position = $env{'form.'.$type.'_addbook_pos'};
14148: $position =~ s/\D+//g;
14149: if ($position ne '') {
14150: $allpos{$type}[$position] = $newbook{$type};
14151: }
1.216 raeburn 14152: }
1.242 raeburn 14153: } else {
14154: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 14155: }
14156: }
1.242 raeburn 14157: }
1.216 raeburn 14158: }
1.102 raeburn 14159: if (ref($domconfig{$action}) eq 'HASH') {
14160: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
14161: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
14162: $changes{'notify'}{'approval'} = 1;
14163: }
14164: } else {
1.144 raeburn 14165: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14166: $changes{'notify'}{'approval'} = 1;
14167: }
14168: }
1.218 raeburn 14169: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
14170: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14171: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
14172: unless ($confhash{'uniquecode'}{$crstype}) {
14173: $changes{'uniquecode'} = 1;
14174: }
14175: }
14176: unless ($changes{'uniquecode'}) {
14177: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
14178: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
14179: $changes{'uniquecode'} = 1;
14180: }
14181: }
14182: }
14183: } else {
14184: $changes{'uniquecode'} = 1;
14185: }
14186: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
14187: $changes{'uniquecode'} = 1;
1.216 raeburn 14188: }
14189: if ($context eq 'requestcourses') {
1.242 raeburn 14190: foreach my $type ('textbooks','templates') {
14191: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14192: my %deletions;
14193: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
14194: if (@todelete) {
14195: map { $deletions{$_} = 1; } @todelete;
14196: }
14197: my %imgdeletions;
14198: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
14199: if (@todeleteimages) {
14200: map { $imgdeletions{$_} = 1; } @todeleteimages;
14201: }
14202: my $maxnum = $env{'form.'.$type.'_maxnum'};
14203: for (my $i=0; $i<=$maxnum; $i++) {
14204: my $itemid = $env{'form.'.$type.'_id_'.$i};
14205: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
14206: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
14207: if ($deletions{$key}) {
14208: if ($domconfig{$action}{$type}{$key}{'image'}) {
14209: #FIXME need to obsolete item in RES space
14210: }
14211: next;
14212: } else {
14213: my $newpos = $env{'form.'.$itemid};
14214: $newpos =~ s/\D+//g;
1.243 raeburn 14215: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 14216: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 14217: ($type eq 'templates'));
1.242 raeburn 14218: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
14219: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
14220: $changes{$type}{$key} = 1;
14221: }
14222: }
14223: $allpos{$type}[$newpos] = $key;
14224: }
14225: if ($imgdeletions{$key}) {
14226: $changes{$type}{$key} = 1;
1.216 raeburn 14227: #FIXME need to obsolete item in RES space
1.242 raeburn 14228: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
14229: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 14230: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14231: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14232: } else {
14233: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
14234: $cdom,$cnum,$type,$configuserok,
14235: $switchserver,$author_ok);
14236: if ($imgurl) {
14237: $confhash{$type}{$key}{'image'} = $imgurl;
14238: $changes{$type}{$key} = 1;
14239: }
14240: if ($error) {
14241: &Apache::lonnet::logthis($error);
14242: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14243: }
14244: }
1.242 raeburn 14245: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
14246: $confhash{$type}{$key}{'image'} =
14247: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 14248: }
14249: }
14250: }
14251: }
14252: }
14253: }
1.102 raeburn 14254: } else {
1.144 raeburn 14255: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14256: $changes{'notify'}{'approval'} = 1;
14257: }
1.218 raeburn 14258: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 14259: $changes{'uniquecode'} = 1;
14260: }
14261: }
14262: if ($context eq 'requestcourses') {
1.242 raeburn 14263: foreach my $type ('textbooks','templates') {
14264: if ($newbook{$type}) {
14265: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 14266: foreach my $item ('subject','title','publisher','author') {
14267: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14268: ($type eq 'template'));
1.242 raeburn 14269: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
14270: if ($env{'form.'.$type.'_addbook_'.$item}) {
14271: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
14272: }
14273: }
14274: if ($type eq 'textbooks') {
14275: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
14276: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 14277: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14278: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14279: } else {
14280: my ($imageurl,$error) =
14281: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
14282: $configuserok,$switchserver,$author_ok);
14283: if ($imageurl) {
14284: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
14285: }
14286: if ($error) {
14287: &Apache::lonnet::logthis($error);
14288: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14289: }
1.242 raeburn 14290: }
14291: }
1.216 raeburn 14292: }
14293: }
1.242 raeburn 14294: if (@{$allpos{$type}} > 0) {
14295: my $idx = 0;
14296: foreach my $item (@{$allpos{$type}}) {
14297: if ($item ne '') {
14298: $confhash{$type}{$item}{'order'} = $idx;
14299: if (ref($domconfig{$action}) eq 'HASH') {
14300: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14301: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
14302: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
14303: $changes{$type}{$item} = 1;
14304: }
1.216 raeburn 14305: }
14306: }
14307: }
1.242 raeburn 14308: $idx ++;
1.216 raeburn 14309: }
14310: }
14311: }
14312: }
1.235 raeburn 14313: if (ref($validationitemsref) eq 'ARRAY') {
14314: foreach my $item (@{$validationitemsref}) {
14315: if ($item eq 'fields') {
14316: my @changed;
14317: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
14318: if (@{$confhash{'validation'}{$item}} > 0) {
14319: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
14320: }
1.266 raeburn 14321: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14322: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14323: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
14324: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
14325: $domconfig{'requestcourses'}{'validation'}{$item});
14326: } else {
14327: @changed = @{$confhash{'validation'}{$item}};
14328: }
1.235 raeburn 14329: } else {
14330: @changed = @{$confhash{'validation'}{$item}};
14331: }
14332: } else {
14333: @changed = @{$confhash{'validation'}{$item}};
14334: }
14335: if (@changed) {
14336: if ($confhash{'validation'}{$item}) {
14337: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
14338: } else {
14339: $changes{'validation'}{$item} = &mt('None');
14340: }
14341: }
14342: } else {
14343: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
14344: if ($item eq 'markup') {
14345: if ($env{'form.requestcourses_validation_'.$item}) {
14346: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
14347: }
14348: }
1.266 raeburn 14349: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14350: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14351: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
14352: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14353: }
14354: } else {
14355: if ($confhash{'validation'}{$item} ne '') {
14356: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14357: }
1.235 raeburn 14358: }
14359: } else {
14360: if ($confhash{'validation'}{$item} ne '') {
14361: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14362: }
14363: }
14364: }
14365: }
14366: }
14367: if ($env{'form.validationdc'}) {
14368: my $newval = $env{'form.validationdc'};
1.285 raeburn 14369: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 14370: if (exists($domcoords{$newval})) {
14371: $confhash{'validation'}{'dc'} = $newval;
14372: }
14373: }
14374: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 14375: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14376: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14377: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14378: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
14379: if ($confhash{'validation'}{'dc'} eq '') {
14380: $changes{'validation'}{'dc'} = &mt('None');
14381: } else {
14382: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14383: }
1.235 raeburn 14384: }
1.266 raeburn 14385: } elsif ($confhash{'validation'}{'dc'} ne '') {
14386: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 14387: }
14388: } elsif ($confhash{'validation'}{'dc'} ne '') {
14389: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14390: }
14391: } elsif ($confhash{'validation'}{'dc'} ne '') {
14392: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 14393: }
1.266 raeburn 14394: } else {
14395: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14396: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14397: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14398: $changes{'validation'}{'dc'} = &mt('None');
14399: }
14400: }
1.235 raeburn 14401: }
14402: }
1.102 raeburn 14403: }
14404: } else {
1.86 raeburn 14405: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
14406: }
1.72 raeburn 14407: foreach my $item (@usertools) {
14408: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 14409: my $unset;
1.101 raeburn 14410: if ($context eq 'requestcourses') {
1.104 raeburn 14411: $unset = '0';
14412: if ($type eq '_LC_adv') {
14413: $unset = '';
14414: }
1.101 raeburn 14415: if ($confhash{$item}{$type} eq 'autolimit') {
14416: $confhash{$item}{$type} .= '=';
14417: unless ($limithash{$item}{$type} =~ /\D/) {
14418: $confhash{$item}{$type} .= $limithash{$item}{$type};
14419: }
14420: }
1.163 raeburn 14421: } elsif ($context eq 'requestauthor') {
14422: $unset = '0';
14423: if ($type eq '_LC_adv') {
14424: $unset = '';
14425: }
1.72 raeburn 14426: } else {
1.101 raeburn 14427: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
14428: $confhash{$item}{$type} = 1;
14429: } else {
14430: $confhash{$item}{$type} = 0;
14431: }
1.72 raeburn 14432: }
1.86 raeburn 14433: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 14434: if ($action eq 'requestauthor') {
14435: if ($domconfig{$action}{$type} ne $confhash{$type}) {
14436: $changes{$type} = 1;
14437: }
14438: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 14439: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
14440: $changes{$item}{$type} = 1;
14441: }
14442: } else {
14443: if ($context eq 'requestcourses') {
1.104 raeburn 14444: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 14445: $changes{$item}{$type} = 1;
14446: }
14447: } else {
14448: if (!$confhash{$item}{$type}) {
14449: $changes{$item}{$type} = 1;
14450: }
14451: }
14452: }
14453: } else {
14454: if ($context eq 'requestcourses') {
1.104 raeburn 14455: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 14456: $changes{$item}{$type} = 1;
14457: }
1.163 raeburn 14458: } elsif ($context eq 'requestauthor') {
14459: if ($confhash{$type} ne $unset) {
14460: $changes{$type} = 1;
14461: }
1.72 raeburn 14462: } else {
14463: if (!$confhash{$item}{$type}) {
14464: $changes{$item}{$type} = 1;
14465: }
14466: }
14467: }
1.1 raeburn 14468: }
14469: }
1.163 raeburn 14470: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 14471: if (ref($domconfig{'quotas'}) eq 'HASH') {
14472: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14473: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
14474: if (exists($confhash{'defaultquota'}{$key})) {
14475: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
14476: $changes{'defaultquota'}{$key} = 1;
14477: }
14478: } else {
14479: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 14480: }
14481: }
1.86 raeburn 14482: } else {
14483: foreach my $key (keys(%{$domconfig{'quotas'}})) {
14484: if (exists($confhash{'defaultquota'}{$key})) {
14485: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
14486: $changes{'defaultquota'}{$key} = 1;
14487: }
14488: } else {
14489: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 14490: }
1.1 raeburn 14491: }
14492: }
1.197 raeburn 14493: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
1.429 raeburn 14494: $confhash{'authorquota'} = $domconfig{'quotas'}{'authorquota'};
14495: }
14496: if (ref($domconfig{'quotas'}{'webdav'}) eq 'HASH') {
14497: $confhash{'webdav'} = $domconfig{'quotas'}{'webdav'};
1.197 raeburn 14498: }
1.1 raeburn 14499: }
1.86 raeburn 14500: if (ref($confhash{'defaultquota'}) eq 'HASH') {
14501: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
14502: if (ref($domconfig{'quotas'}) eq 'HASH') {
14503: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14504: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
14505: $changes{'defaultquota'}{$key} = 1;
14506: }
14507: } else {
14508: if (!exists($domconfig{'quotas'}{$key})) {
14509: $changes{'defaultquota'}{$key} = 1;
14510: }
1.72 raeburn 14511: }
14512: } else {
1.86 raeburn 14513: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 14514: }
1.1 raeburn 14515: }
14516: }
14517: }
1.72 raeburn 14518:
1.163 raeburn 14519: if ($context eq 'requestauthor') {
14520: $domdefaults{'requestauthor'} = \%confhash;
14521: } else {
14522: foreach my $key (keys(%confhash)) {
1.242 raeburn 14523: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 14524: $domdefaults{$key} = $confhash{$key};
14525: }
1.163 raeburn 14526: }
1.72 raeburn 14527: }
1.163 raeburn 14528:
1.1 raeburn 14529: my %quotahash = (
1.86 raeburn 14530: $action => { %confhash }
1.1 raeburn 14531: );
14532: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
14533: $dom);
14534: if ($putresult eq 'ok') {
14535: if (keys(%changes) > 0) {
1.72 raeburn 14536: my $cachetime = 24*60*60;
14537: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 14538: if (ref($lastactref) eq 'HASH') {
14539: $lastactref->{'domdefaults'} = 1;
14540: }
1.1 raeburn 14541: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 14542: unless (($context eq 'requestcourses') ||
1.163 raeburn 14543: ($context eq 'requestauthor')) {
1.86 raeburn 14544: if (ref($changes{'defaultquota'}) eq 'HASH') {
14545: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
14546: foreach my $type (@{$types},'default') {
14547: if (defined($changes{'defaultquota'}{$type})) {
14548: my $typetitle = $usertypes->{$type};
14549: if ($type eq 'default') {
14550: $typetitle = $othertitle;
14551: }
1.213 raeburn 14552: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 14553: }
14554: }
1.86 raeburn 14555: $resulttext .= '</ul></li>';
1.72 raeburn 14556: }
14557: }
1.80 raeburn 14558: my %newenv;
1.72 raeburn 14559: foreach my $item (@usertools) {
1.163 raeburn 14560: my (%haschgs,%inconf);
14561: if ($context eq 'requestauthor') {
14562: %haschgs = %changes;
1.210 raeburn 14563: %inconf = %confhash;
1.163 raeburn 14564: } else {
14565: if (ref($changes{$item}) eq 'HASH') {
14566: %haschgs = %{$changes{$item}};
14567: }
14568: if (ref($confhash{$item}) eq 'HASH') {
14569: %inconf = %{$confhash{$item}};
14570: }
14571: }
14572: if (keys(%haschgs) > 0) {
1.80 raeburn 14573: my $newacc =
14574: &Apache::lonnet::usertools_access($env{'user.name'},
14575: $env{'user.domain'},
1.86 raeburn 14576: $item,'reload',$context);
1.210 raeburn 14577: if (($context eq 'requestcourses') ||
1.163 raeburn 14578: ($context eq 'requestauthor')) {
1.108 raeburn 14579: if ($env{'environment.canrequest.'.$item} ne $newacc) {
14580: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 14581: }
14582: } else {
14583: if ($env{'environment.availabletools.'.$item} ne $newacc) {
14584: $newenv{'environment.availabletools.'.$item} = $newacc;
14585: }
1.80 raeburn 14586: }
1.163 raeburn 14587: unless ($context eq 'requestauthor') {
14588: $resulttext .= '<li>'.$titles{$item}.'<ul>';
14589: }
1.72 raeburn 14590: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 14591: if ($haschgs{$type}) {
1.72 raeburn 14592: my $typetitle = $usertypes->{$type};
14593: if ($type eq 'default') {
14594: $typetitle = $othertitle;
14595: } elsif ($type eq '_LC_adv') {
14596: $typetitle = 'LON-CAPA Advanced Users';
14597: }
1.163 raeburn 14598: if ($inconf{$type}) {
1.101 raeburn 14599: if ($context eq 'requestcourses') {
14600: my $cond;
1.163 raeburn 14601: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 14602: if ($1 eq '') {
14603: $cond = &mt('(Automatic processing of any request).');
14604: } else {
14605: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
14606: }
14607: } else {
1.163 raeburn 14608: $cond = $conditions{$inconf{$type}};
1.101 raeburn 14609: }
14610: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 14611: } elsif ($context eq 'requestauthor') {
14612: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
14613: $titles{$inconf{$type}},$typetitle);
14614:
1.101 raeburn 14615: } else {
14616: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
14617: }
1.72 raeburn 14618: } else {
1.104 raeburn 14619: if ($type eq '_LC_adv') {
1.163 raeburn 14620: if ($inconf{$type} eq '0') {
1.104 raeburn 14621: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14622: } else {
14623: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
14624: }
14625: } else {
14626: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14627: }
1.72 raeburn 14628: }
14629: }
1.26 raeburn 14630: }
1.163 raeburn 14631: unless ($context eq 'requestauthor') {
14632: $resulttext .= '</ul></li>';
14633: }
1.26 raeburn 14634: }
1.1 raeburn 14635: }
1.163 raeburn 14636: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 14637: if (ref($changes{'notify'}) eq 'HASH') {
14638: if ($changes{'notify'}{'approval'}) {
14639: if (ref($confhash{'notify'}) eq 'HASH') {
14640: if ($confhash{'notify'}{'approval'}) {
14641: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
14642: } else {
1.163 raeburn 14643: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 14644: }
14645: }
14646: }
14647: }
14648: }
1.216 raeburn 14649: if ($action eq 'requestcourses') {
14650: my @offon = ('off','on');
14651: if ($changes{'uniquecode'}) {
1.218 raeburn 14652: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14653: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
14654: $resulttext .= '<li>'.
14655: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
14656: '</li>';
14657: } else {
14658: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
14659: '</li>';
14660: }
1.216 raeburn 14661: }
1.242 raeburn 14662: foreach my $type ('textbooks','templates') {
14663: if (ref($changes{$type}) eq 'HASH') {
14664: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
14665: foreach my $key (sort(keys(%{$changes{$type}}))) {
14666: my %coursehash = &Apache::lonnet::coursedescription($key);
14667: my $coursetitle = $coursehash{'description'};
14668: my $position = $confhash{$type}{$key}{'order'} + 1;
14669: $resulttext .= '<li>';
1.243 raeburn 14670: foreach my $item ('subject','title','publisher','author') {
14671: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14672: ($type eq 'templates'));
1.242 raeburn 14673: my $name = $item.':';
14674: $name =~ s/^(\w)/\U$1/;
14675: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
14676: }
14677: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
14678: if ($type eq 'textbooks') {
14679: if ($confhash{$type}{$key}{'image'}) {
14680: $resulttext .= ' '.&mt('Image: [_1]',
14681: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
14682: ' alt="Textbook cover" />').'<br />';
14683: }
14684: }
14685: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 14686: }
1.242 raeburn 14687: $resulttext .= '</ul></li>';
1.216 raeburn 14688: }
14689: }
1.235 raeburn 14690: if (ref($changes{'validation'}) eq 'HASH') {
14691: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
14692: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
14693: foreach my $item (@{$validationitemsref}) {
14694: if (exists($changes{'validation'}{$item})) {
14695: if ($item eq 'markup') {
14696: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14697: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
14698: } else {
14699: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14700: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
14701: }
14702: }
14703: }
14704: if (exists($changes{'validation'}{'dc'})) {
14705: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
14706: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
14707: }
14708: }
14709: }
1.216 raeburn 14710: }
1.1 raeburn 14711: $resulttext .= '</ul>';
1.80 raeburn 14712: if (keys(%newenv)) {
14713: &Apache::lonnet::appenv(\%newenv);
14714: }
1.1 raeburn 14715: } else {
1.86 raeburn 14716: if ($context eq 'requestcourses') {
14717: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 14718: } elsif ($context eq 'requestauthor') {
14719: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 14720: } else {
1.90 weissno 14721: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 14722: }
1.1 raeburn 14723: }
14724: } else {
1.11 albertel 14725: $resulttext = '<span class="LC_error">'.
14726: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14727: }
1.216 raeburn 14728: if ($errors) {
14729: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
14730: '<ul>'.$errors.'</ul></p>';
14731: }
1.3 raeburn 14732: return $resulttext;
1.1 raeburn 14733: }
14734:
1.216 raeburn 14735: sub process_textbook_image {
1.242 raeburn 14736: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 14737: my $filename = $env{'form.'.$caller.'.filename'};
14738: my ($error,$url);
14739: my ($width,$height) = (50,50);
14740: if ($configuserok eq 'ok') {
14741: if ($switchserver) {
14742: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
14743: $switchserver);
14744: } elsif ($author_ok eq 'ok') {
1.421 raeburn 14745: my $modified = [];
1.216 raeburn 14746: my ($result,$imageurl) =
1.421 raeburn 14747: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
14748: "$type/$cdom/$cnum/cover",$width,$height,
14749: '',$modified);
1.216 raeburn 14750: if ($result eq 'ok') {
14751: $url = $imageurl;
1.421 raeburn 14752: &update_modify_urls($r,$modified);
1.216 raeburn 14753: } else {
14754: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14755: }
14756: } else {
14757: $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);
14758: }
14759: } else {
14760: $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);
14761: }
14762: return ($url,$error);
14763: }
14764:
1.267 raeburn 14765: sub modify_ltitools {
14766: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.421 raeburn 14767: my (%currtoolsec,%secchanges,%newtoolsec,%newkeyset);
14768: &fetch_secrets($dom,'toolsec',\%domconfig,\%currtoolsec,\%secchanges,\%newtoolsec,\%newkeyset);
14769:
1.267 raeburn 14770: my $confname = $dom.'-domainconfig';
14771: my $servadm = $r->dir_config('lonAdmEMail');
14772: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.421 raeburn 14773:
14774: my ($resulttext,$ltitoolsoutput,$is_home,$errors,%ltitoolschg,%newtoolsenc,%newltitools);
14775: my $toolserror =
14776: &Apache::courseprefs::process_ltitools($r,$dom,$confname,$domconfig{'ltitools'},\%ltitoolschg,'domain',
14777: $lastactref,$configuserok,$switchserver,$author_ok);
14778:
14779: my $home = &Apache::lonnet::domain($dom,'primary');
14780: unless (($home eq 'no_host') || ($home eq '')) {
14781: my @ids=&Apache::lonnet::current_machine_ids();
14782: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; last; } }
14783: }
14784:
14785: if (keys(%ltitoolschg)) {
14786: foreach my $id (keys(%ltitoolschg)) {
14787: if (ref($ltitoolschg{$id}) eq 'HASH') {
14788: foreach my $inner (keys(%{$ltitoolschg{$id}})) {
14789: if (($inner eq 'secret') || ($inner eq 'key')) {
14790: if ($is_home) {
14791: $newtoolsenc{$id}{$inner} = $ltitoolschg{$id}{$inner};
14792: }
14793: }
14794: }
1.267 raeburn 14795: }
1.421 raeburn 14796: }
14797: $ltitoolsoutput = &Apache::courseprefs::store_ltitools($dom,'','domain',\%ltitoolschg,$domconfig{'ltitools'});
14798: if (keys(%ltitoolschg)) {
14799: %newltitools = %ltitoolschg;
14800: }
14801: }
14802: if (ref($domconfig{'ltitools'}) eq 'HASH') {
14803: foreach my $id (%{$domconfig{'ltitools'}}) {
14804: next if ($id !~ /^\d+$/);
14805: unless (exists($ltitoolschg{$id})) {
14806: if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
14807: foreach my $inner (keys(%{$domconfig{'ltitools'}{$id}})) {
14808: if (($inner eq 'secret') || ($inner eq 'key')) {
14809: if ($is_home) {
14810: $newtoolsenc{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14811: }
14812: } else {
14813: $newltitools{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14814: }
14815: }
14816: } else {
14817: $newltitools{$id} = $domconfig{'ltitools'}{$id};
1.322 raeburn 14818: }
1.421 raeburn 14819: }
14820: }
14821: }
14822: if ($toolserror) {
14823: $errors = '<li>'.$toolserror.'</li>';
14824: }
14825: if ((keys(%ltitoolschg) == 0) && (keys(%secchanges) == 0)) {
14826: $resulttext = &mt('No changes made.');
14827: if ($errors) {
14828: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
14829: $errors.'</ul>';
14830: }
14831: return $resulttext;
14832: }
14833: my %ltitoolshash = (
14834: $action => { %newltitools }
14835: );
14836: if (keys(%secchanges)) {
14837: $ltitoolshash{'toolsec'} = \%newtoolsec;
14838: }
14839: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,$dom);
14840: if ($putresult eq 'ok') {
14841: my %keystore;
14842: if ($is_home) {
14843: my %toolsenchash = (
14844: $action => { %newtoolsenc }
14845: );
14846: &Apache::lonnet::put_dom('encconfig',\%toolsenchash,$dom,undef,1);
1.423 raeburn 14847: my $cachetime = 24*60*60;
14848: &Apache::lonnet::do_cache_new('ltitoolsenc',$dom,\%newtoolsenc,$cachetime);
1.421 raeburn 14849: &store_security($dom,'ltitools',\%secchanges,\%newkeyset,\%keystore,$lastactref);
14850: }
14851: $resulttext = &mt('Changes made:').'<ul>';
14852: if (keys(%secchanges) > 0) {
1.423 raeburn 14853: $resulttext .= <i_security_results($dom,'ltitools',\%secchanges,\%newtoolsec,\%newkeyset,\%keystore);
1.421 raeburn 14854: }
14855: if (keys(%ltitoolschg) > 0) {
14856: $resulttext .= $ltitoolsoutput;
14857: }
1.423 raeburn 14858: my $cachetime = 24*60*60;
14859: &Apache::lonnet::do_cache_new('ltitools',$dom,\%newltitools,$cachetime);
14860: if (ref($lastactref) eq 'HASH') {
14861: $lastactref->{'ltitools'} = 1;
14862: }
1.421 raeburn 14863: } else {
14864: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
14865: }
14866: if ($errors) {
14867: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
14868: $errors.'</ul></p>';
14869: }
14870: return $resulttext;
14871: }
14872:
14873: sub fetch_secrets {
14874: my ($dom,$context,$domconfig,$currsec,$secchanges,$newsec,$newkeyset) = @_;
14875: my %keyset;
14876: %{$currsec} = ();
14877: $newsec->{'private'}{'keys'} = [];
14878: $newsec->{'encrypt'} = {};
14879: $newsec->{'rules'} = {};
14880: if ($context eq 'ltisec') {
14881: $newsec->{'linkprot'} = {};
14882: }
14883: if (ref($domconfig->{$context}) eq 'HASH') {
14884: %{$currsec} = %{$domconfig->{$context}};
14885: if ($context eq 'ltisec') {
14886: if (ref($currsec->{'linkprot'}) eq 'HASH') {
14887: foreach my $id (keys(%{$currsec->{'linkprot'}})) {
14888: unless ($id =~ /^\d+$/) {
14889: delete($currsec->{'linkprot'}{$id});
1.297 raeburn 14890: }
1.267 raeburn 14891: }
14892: }
1.421 raeburn 14893: }
14894: if (ref($currsec->{'private'}) eq 'HASH') {
14895: if (ref($currsec->{'private'}{'keys'}) eq 'ARRAY') {
14896: $newsec->{'private'}{'keys'} = $currsec->{'private'}{'keys'};
14897: map { $keyset{$_} = 1; } @{$currsec->{'private'}{'keys'}};
1.267 raeburn 14898: }
1.421 raeburn 14899: }
14900: }
14901: my @items= ('crs','dom');
14902: if ($context eq 'ltisec') {
14903: push(@items,'consumers');
14904: }
14905: foreach my $item (@items) {
14906: my $formelement;
14907: if (($context eq 'toolsec') || ($item eq 'consumers')) {
14908: $formelement = 'form.'.$context.'_'.$item;
14909: } else {
14910: $formelement = 'form.'.$context.'_'.$item.'linkprot';
14911: }
14912: if ($env{$formelement}) {
14913: $newsec->{'encrypt'}{$item} = 1;
14914: if (ref($currsec->{'encrypt'}) eq 'HASH') {
14915: unless ($currsec->{'encrypt'}{$item}) {
14916: $secchanges->{'encrypt'} = 1;
14917: }
14918: } else {
14919: $secchanges->{'encrypt'} = 1;
1.267 raeburn 14920: }
1.421 raeburn 14921: } elsif (ref($currsec->{'encrypt'}) eq 'HASH') {
14922: if ($currsec->{'encrypt'}{$item}) {
14923: $secchanges->{'encrypt'} = 1;
1.323 raeburn 14924: }
1.421 raeburn 14925: }
14926: }
14927: my $secrets;
14928: if ($context eq 'ltisec') {
14929: $secrets = 'ltisecrets';
14930: } else {
14931: $secrets = 'toolsecrets';
14932: }
14933: unless (exists($currsec->{'rules'})) {
14934: $currsec->{'rules'} = {};
14935: }
14936: &password_rule_changes($secrets,$newsec->{'rules'},$currsec->{'rules'},$secchanges);
14937:
14938: my @ids=&Apache::lonnet::current_machine_ids();
14939: my %servers = &Apache::lonnet::get_servers($dom,'library');
14940:
14941: foreach my $hostid (keys(%servers)) {
14942: if (($hostid ne '') && (grep(/^\Q$hostid\E$/,@ids))) {
14943: my $keyitem = 'form.'.$context.'_privkey_'.$hostid;
14944: if (exists($env{$keyitem})) {
14945: $env{$keyitem} =~ s/(`)/'/g;
14946: if ($keyset{$hostid}) {
14947: if ($env{'form.'.$context.'_changeprivkey_'.$hostid}) {
14948: if ($env{$keyitem} ne '') {
14949: $secchanges->{'private'} = 1;
14950: $newkeyset->{$hostid} = $env{$keyitem};
14951: }
1.296 raeburn 14952: }
1.421 raeburn 14953: } elsif ($env{$keyitem} ne '') {
14954: unless (grep(/^\Q$hostid\E$/,@{$newsec->{'private'}{'keys'}})) {
14955: push(@{$newsec->{'private'}{'keys'}},$hostid);
1.296 raeburn 14956: }
1.421 raeburn 14957: $secchanges->{'private'} = 1;
14958: $newkeyset->{$hostid} = $env{$keyitem};
1.267 raeburn 14959: }
14960: }
1.421 raeburn 14961: }
14962: }
14963: }
14964:
14965: sub store_security {
1.424 raeburn 14966: my ($dom,$context,$secchanges,$newkeyset,$keystore) = @_;
1.421 raeburn 14967: return unless ((ref($secchanges) eq 'HASH') && (ref($newkeyset) eq 'HASH') &&
14968: (ref($keystore) eq 'HASH'));
14969: if (keys(%{$secchanges})) {
14970: if ($secchanges->{'private'}) {
14971: my $who = &escape($env{'user.name'}.':'.$env{'user.domain'});
14972: foreach my $hostid (keys(%{$newkeyset})) {
14973: my $storehash = {
14974: key => $newkeyset->{$hostid},
14975: who => $env{'user.name'}.':'.$env{'user.domain'},
14976: };
14977: $keystore->{$hostid} = &Apache::lonnet::store_dom($storehash,$context,'private',
14978: $dom,$hostid);
14979: }
14980: }
14981: }
14982: }
14983:
14984: sub lti_security_results {
1.423 raeburn 14985: my ($dom,$context,$secchanges,$newsec,$newkeyset,$keystore) = @_;
1.421 raeburn 14986: my $output;
1.423 raeburn 14987: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
14988: my $needs_update;
1.421 raeburn 14989: foreach my $item (keys(%{$secchanges})) {
14990: if ($item eq 'encrypt') {
1.423 raeburn 14991: $needs_update = 1;
1.421 raeburn 14992: my %encrypted;
14993: if ($context eq 'lti') {
14994: %encrypted = (
14995: crs => {
14996: on => &mt('Encryption of stored link protection secrets defined in courses enabled'),
14997: off => &mt('Encryption of stored link protection secrets defined in courses disabled'),
14998: },
14999: dom => {
15000: on => &mt('Encryption of stored link protection secrets defined in domain enabled'),
15001: off => &mt('Encryption of stored link protection secrets defined in domain disabled'),
15002: },
15003: consumers => {
15004: on => &mt('Encryption of stored consumer secrets defined in domain enabled'),
15005: off => &mt('Encryption of stored consumer secrets defined in domain disabled'),
15006: },
15007: );
1.267 raeburn 15008: } else {
1.421 raeburn 15009: %encrypted = (
15010: crs => {
15011: on => &mt('Encryption of stored external tool secrets defined in courses enabled'),
15012: off => &mt('Encryption of stored external tool secrets defined in courses disabled'),
15013: },
15014: dom => {
15015: on => &mt('Encryption of stored external tool secrets defined in domain enabled'),
15016: off => &mt('Encryption of stored external tool secrets defined in domain disabled'),
15017: },
15018: );
15019:
15020: }
15021: my @types= ('crs','dom');
15022: if ($context eq 'lti') {
1.423 raeburn 15023: foreach my $type (@types) {
15024: undef($domdefaults{'linkprotenc_'.$type});
15025: }
1.421 raeburn 15026: push(@types,'consumers');
1.423 raeburn 15027: undef($domdefaults{'ltienc_consumers'});
15028: } elsif ($context eq 'ltitools') {
15029: foreach my $type (@types) {
15030: undef($domdefaults{'toolenc_'.$type});
15031: }
1.267 raeburn 15032: }
1.421 raeburn 15033: foreach my $type (@types) {
15034: my $shown = $encrypted{$type}{'off'};
15035: if (ref($newsec->{$item}) eq 'HASH') {
15036: if ($newsec->{$item}{$type}) {
1.423 raeburn 15037: if ($context eq 'lti') {
15038: if ($type eq 'consumers') {
15039: $domdefaults{'ltienc_consumers'} = 1;
15040: } else {
15041: $domdefaults{'linkprotenc_'.$type} = 1;
15042: }
15043: } elsif ($context eq 'ltitools') {
15044: $domdefaults{'toolenc_'.$type} = 1;
15045: }
1.421 raeburn 15046: $shown = $encrypted{$type}{'on'};
1.319 raeburn 15047: }
1.267 raeburn 15048: }
1.421 raeburn 15049: $output .= '<li>'.$shown.'</li>';
1.267 raeburn 15050: }
1.421 raeburn 15051: } elsif ($item eq 'rules') {
15052: my %titles = &Apache::lonlocal::texthash(
15053: min => 'Minimum password length',
15054: max => 'Maximum password length',
15055: chars => 'Required characters',
15056: );
15057: foreach my $rule ('min','max') {
15058: if ($newsec->{rules}{$rule} eq '') {
15059: if ($rule eq 'min') {
15060: $output .= '<li>'.&mt('[_1] not set.',$titles{$rule});
15061: ' '.&mt('Default of [_1] will be used',
15062: $Apache::lonnet::passwdmin).'</li>';
15063: } else {
15064: $output .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
15065: }
15066: } else {
15067: $output .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$newsec->{rules}{$rule}).'</li>';
15068: }
15069: }
15070: if (ref($newsec->{'rules'}{'chars'}) eq 'ARRAY') {
15071: if (@{$newsec->{'rules'}{'chars'}} > 0) {
15072: my %rulenames = &Apache::lonlocal::texthash(
15073: uc => 'At least one upper case letter',
15074: lc => 'At least one lower case letter',
15075: num => 'At least one number',
15076: spec => 'At least one non-alphanumeric',
15077: );
15078: my $needed = '<ul><li>'.
15079: join('</li><li>',map {$rulenames{$_} } @{$newsec->{'rules'}{'chars'}}).
15080: '</li></ul>';
15081: $output .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
15082: } else {
15083: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 15084: }
1.421 raeburn 15085: } else {
15086: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 15087: }
1.421 raeburn 15088: } elsif ($item eq 'private') {
1.423 raeburn 15089: $needs_update = 1;
15090: if ($context eq 'lti') {
15091: undef($domdefaults{'ltiprivhosts'});
15092: } elsif ($context eq 'ltitools') {
15093: undef($domdefaults{'toolprivhosts'});
15094: }
1.421 raeburn 15095: if (keys(%{$newkeyset})) {
1.423 raeburn 15096: my @privhosts;
1.421 raeburn 15097: foreach my $hostid (sort(keys(%{$newkeyset}))) {
15098: if ($keystore->{$hostid} eq 'ok') {
15099: $output .= '<li>'.&mt('Encryption key for storage of shared secrets saved for [_1]',$hostid).'</li>';
1.423 raeburn 15100: unless (grep(/^\Q$hostid\E$/,@privhosts)) {
15101: push(@privhosts,$hostid);
15102: }
15103: }
15104: }
15105: if (@privhosts) {
15106: if ($context eq 'lti') {
15107: $domdefaults{'ltiprivhosts'} = \@privhosts;
15108: } elsif ($context eq 'ltitools') {
15109: $domdefaults{'toolprivhosts'} = \@privhosts;
1.267 raeburn 15110: }
15111: }
15112: }
1.421 raeburn 15113: } elsif ($item eq 'linkprot') {
15114: next;
1.267 raeburn 15115: }
15116: }
1.423 raeburn 15117: if ($needs_update) {
15118: my $cachetime = 24*60*60;
15119: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15120: }
1.421 raeburn 15121: return $output;
15122: }
15123:
15124: sub modify_proctoring {
15125: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15126: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15127: my (@allpos,%changes,%confhash,%encconfhash,$errors,$resulttext,%imgdeletions);
15128: my $confname = $dom.'-domainconfig';
15129: my $servadm = $r->dir_config('lonAdmEMail');
1.372 raeburn 15130: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
15131: my %providernames = &proctoring_providernames();
15132: my $maxnum = scalar(keys(%providernames));
15133:
15134: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
15135: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
15136: if (ref($requref) eq 'HASH') {
15137: %requserfields = %{$requref};
15138: }
15139: if (ref($opturef) eq 'HASH') {
15140: %optuserfields = %{$opturef};
15141: }
15142: if (ref($defref) eq 'HASH') {
15143: %defaults = %{$defref};
15144: }
15145: if (ref($extref) eq 'HASH') {
15146: %extended = %{$extref};
15147: }
15148: if (ref($crsref) eq 'HASH') {
15149: %crsconf = %{$crsref};
15150: }
15151: if (ref($rolesref) eq 'ARRAY') {
15152: @courseroles = @{$rolesref};
15153: }
15154: if (ref($ltiref) eq 'ARRAY') {
15155: @ltiroles = @{$ltiref};
15156: }
15157:
15158: if (ref($domconfig{$action}) eq 'HASH') {
15159: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.proctoring_image_del');
15160: if (@todeleteimages) {
15161: map { $imgdeletions{$_} = 1; } @todeleteimages;
15162: }
15163: }
15164: my %customadds;
15165: my @newcustom = &Apache::loncommon::get_env_multiple('form.proctoring_customadd');
15166: if (@newcustom) {
15167: map { $customadds{$_} = 1; } @newcustom;
15168: }
15169: foreach my $provider (sort(keys(%providernames))) {
15170: $confhash{$provider} = {};
15171: my $pos = $env{'form.proctoring_pos_'.$provider};
15172: $pos =~ s/\D+//g;
15173: $allpos[$pos] = $provider;
15174: my (%current,%currentenc);
15175: my $showroles = 0;
15176: if (ref($domconfig{$action}) eq 'HASH') {
15177: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15178: %current = %{$domconfig{$action}{$provider}};
15179: foreach my $item ('key','secret') {
15180: $currentenc{$item} = $current{$item};
15181: delete($current{$item});
15182: }
15183: }
15184: }
15185: if ($env{'form.proctoring_available_'.$provider}) {
15186: $confhash{$provider}{'available'} = 1;
15187: unless ($current{'available'}) {
15188: $changes{$provider} = 1;
15189: }
15190: } else {
15191: %{$confhash{$provider}} = %current;
15192: %{$encconfhash{$provider}} = %currentenc;
15193: $confhash{$provider}{'available'} = 0;
15194: if ($current{'available'}) {
15195: $changes{$provider} = 1;
15196: }
15197: }
15198: if ($confhash{$provider}{'available'}) {
15199: foreach my $field ('lifetime','version','sigmethod','url','key','secret') {
15200: my $possval = $env{'form.proctoring_'.$provider.'_'.$field};
15201: if ($field eq 'lifetime') {
15202: if ($possval =~ /^\d+$/) {
15203: $confhash{$provider}{$field} = $possval;
15204: }
15205: } elsif ($field eq 'version') {
15206: if ($possval =~ /^\d+\.\d+$/) {
15207: $confhash{$provider}{$field} = $possval;
15208: }
15209: } elsif ($field eq 'sigmethod') {
15210: if ($possval =~ /^\QHMAC-SHA\E(1|256)$/) {
15211: $confhash{$provider}{$field} = $possval;
15212: }
15213: } elsif ($field eq 'url') {
15214: $confhash{$provider}{$field} = $possval;
15215: } elsif (($field eq 'key') || ($field eq 'secret')) {
15216: $encconfhash{$provider}{$field} = $possval;
15217: unless ($currentenc{$field} eq $possval) {
15218: $changes{$provider} = 1;
15219: }
15220: }
15221: unless (($field eq 'key') || ($field eq 'secret')) {
15222: unless ($current{$field} eq $confhash{$provider}{$field}) {
15223: $changes{$provider} = 1;
15224: }
15225: }
15226: }
15227: if ($imgdeletions{$provider}) {
15228: $changes{$provider} = 1;
15229: } elsif ($env{'form.proctoring_image_'.$provider.'.filename'} ne '') {
15230: my ($imageurl,$error) =
15231: &process_proctoring_image($r,$dom,$confname,'proctoring_image_'.$provider,$provider,
15232: $configuserok,$switchserver,$author_ok);
15233: if ($imageurl) {
15234: $confhash{$provider}{'image'} = $imageurl;
15235: $changes{$provider} = 1;
15236: }
15237: if ($error) {
15238: &Apache::lonnet::logthis($error);
15239: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15240: }
15241: } elsif (exists($current{'image'})) {
15242: $confhash{$provider}{'image'} = $current{'image'};
15243: }
15244: if (ref($requserfields{$provider}) eq 'ARRAY') {
15245: if (@{$requserfields{$provider}} > 0) {
15246: if (grep(/^user$/,@{$requserfields{$provider}})) {
15247: if ($env{'form.proctoring_userincdom_'.$provider}) {
15248: $confhash{$provider}{'incdom'} = 1;
15249: }
15250: unless ($current{'incdom'} eq $confhash{$provider}{'incdom'}) {
15251: $changes{$provider} = 1;
15252: }
15253: }
15254: if (grep(/^roles$/,@{$requserfields{$provider}})) {
15255: $showroles = 1;
15256: }
15257: }
15258: }
15259: $confhash{$provider}{'fields'} = [];
15260: if (ref($optuserfields{$provider}) eq 'ARRAY') {
15261: if (@{$optuserfields{$provider}} > 0) {
15262: my @optfields = &Apache::loncommon::get_env_multiple('form.proctoring_optional_'.$provider);
15263: foreach my $field (@{$optuserfields{$provider}}) {
15264: if (grep(/^\Q$field\E$/,@optfields)) {
15265: push(@{$confhash{$provider}{'fields'}},$field);
15266: }
15267: }
15268: }
15269: if (ref($current{'fields'}) eq 'ARRAY') {
15270: unless ($changes{$provider}) {
15271: my @new = sort(@{$confhash{$provider}{'fields'}});
15272: my @old = sort(@{$current{'fields'}});
15273: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15274: if (@diffs) {
15275: $changes{$provider} = 1;
15276: }
15277: }
15278: } elsif (@{$confhash{$provider}{'fields'}}) {
15279: $changes{$provider} = 1;
15280: }
15281: }
15282: if (ref($defaults{$provider}) eq 'ARRAY') {
15283: if (@{$defaults{$provider}} > 0) {
15284: my %options;
15285: if (ref($extended{$provider}) eq 'HASH') {
15286: %options = %{$extended{$provider}};
15287: }
15288: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_defaults_'.$provider);
15289: foreach my $field (@{$defaults{$provider}}) {
15290: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
15291: my $poss = $env{'form.proctoring_defaults_'.$field.'_'.$provider};
15292: if (grep(/^\Q$poss\E$/,@{$options{$field}})) {
15293: push(@{$confhash{$provider}{'defaults'}},$poss);
15294: }
15295: } elsif ((exists($options{$field})) && (ref($options{$field}) eq 'HASH')) {
15296: foreach my $inner (keys(%{$options{$field}})) {
15297: if (ref($options{$field}{$inner}) eq 'ARRAY') {
15298: my $poss = $env{'form.proctoring_'.$inner.'_'.$provider};
15299: if (grep(/^\Q$poss\E$/,@{$options{$field}{$inner}})) {
15300: $confhash{$provider}{'defaults'}{$inner} = $poss;
15301: }
15302: } else {
15303: $confhash{$provider}{'defaults'}{$inner} = $env{'form.proctoring_'.$inner.'_'.$provider};
15304: }
15305: }
15306: } else {
15307: if (grep(/^\Q$field\E$/,@checked)) {
15308: push(@{$confhash{$provider}{'defaults'}},$field);
15309: }
15310: }
15311: }
15312: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15313: if (ref($current{'defaults'}) eq 'ARRAY') {
15314: unless ($changes{$provider}) {
15315: my @new = sort(@{$confhash{$provider}{'defaults'}});
15316: my @old = sort(@{$current{'defaults'}});
15317: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15318: if (@diffs) {
15319: $changes{$provider} = 1;
15320: }
15321: }
15322: } elsif (ref($current{'defaults'}) eq 'ARRAY') {
15323: if (@{$current{'defaults'}}) {
15324: $changes{$provider} = 1;
15325: }
15326: }
15327: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15328: if (ref($current{'defaults'}) eq 'HASH') {
15329: unless ($changes{$provider}) {
15330: foreach my $key (keys(%{$confhash{$provider}{'defaults'}})) {
15331: unless ($confhash{$provider}{'defaults'}{$key} eq $current{'defaults'}{$key}) {
15332: $changes{$provider} = 1;
15333: last;
15334: }
15335: }
15336: }
15337: unless ($changes{$provider}) {
15338: foreach my $key (keys(%{$current{'defaults'}})) {
15339: unless ($current{'defaults'}{$key} eq $confhash{$provider}{'defaults'}{$key}) {
15340: $changes{$provider} = 1;
15341: last;
15342: }
15343: }
15344: }
15345: } elsif (keys(%{$confhash{$provider}{'defaults'}})) {
15346: $changes{$provider} = 1;
15347: }
15348: }
15349: }
15350: }
15351: if (ref($crsconf{$provider}) eq 'ARRAY') {
15352: if (@{$crsconf{$provider}} > 0) {
15353: $confhash{$provider}{'crsconf'} = [];
15354: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_crsconf_'.$provider);
15355: foreach my $crsfield (@{$crsconf{$provider}}) {
15356: if (grep(/^\Q$crsfield\E$/,@checked)) {
15357: push(@{$confhash{$provider}{'crsconf'}},$crsfield);
15358: }
15359: }
15360: if (ref($current{'crsconf'}) eq 'ARRAY') {
15361: unless ($changes{$provider}) {
15362: my @new = sort(@{$confhash{$provider}{'crsconf'}});
15363: my @old = sort(@{$current{'crsconf'}});
15364: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15365: if (@diffs) {
15366: $changes{$provider} = 1;
15367: }
15368: }
15369: } elsif (@{$confhash{$provider}{'crsconf'}}) {
15370: $changes{$provider} = 1;
15371: }
15372: }
15373: }
15374: if ($showroles) {
15375: $confhash{$provider}{'roles'} = {};
15376: foreach my $role (@courseroles) {
15377: my $poss = $env{'form.proctoring_roles_'.$role.'_'.$provider};
15378: if (grep(/^\Q$poss\E$/,@ltiroles)) {
15379: $confhash{$provider}{'roles'}{$role} = $poss;
15380: }
15381: }
15382: unless ($changes{$provider}) {
15383: if (ref($current{'roles'}) eq 'HASH') {
15384: foreach my $role (keys(%{$current{'roles'}})) {
15385: unless ($current{'roles'}{$role} eq $confhash{$provider}{'roles'}{$role}) {
15386: $changes{$provider} = 1;
15387: last
15388: }
15389: }
15390: unless ($changes{$provider}) {
15391: foreach my $role (keys(%{$confhash{$provider}{'roles'}})) {
15392: unless ($confhash{$provider}{'roles'}{$role} eq $current{'roles'}{$role}) {
15393: $changes{$provider} = 1;
15394: last;
15395: }
15396: }
15397: }
15398: } elsif (keys(%{$confhash{$provider}{'roles'}})) {
15399: $changes{$provider} = 1;
15400: }
15401: }
15402: }
15403: if (ref($current{'custom'}) eq 'HASH') {
15404: my @customdels = &Apache::loncommon::get_env_multiple('form.proctoring_customdel_'.$provider);
15405: foreach my $key (keys(%{$current{'custom'}})) {
15406: if (grep(/^\Q$key\E$/,@customdels)) {
15407: $changes{$provider} = 1;
15408: } else {
15409: $confhash{$provider}{'custom'}{$key} = $env{'form.proctoring_customval_'.$key.'_'.$provider};
15410: if ($confhash{$provider}{'custom'}{$key} ne $current{'custom'}{$key}) {
15411: $changes{$provider} = 1;
15412: }
15413: }
15414: }
15415: }
15416: if ($customadds{$provider}) {
15417: my $name = $env{'form.proctoring_custom_name_'.$provider};
15418: $name =~ s/(`)/'/g;
15419: $name =~ s/^\s+//;
15420: $name =~ s/\s+$//;
15421: my $value = $env{'form.proctoring_custom_value_'.$provider};
15422: $value =~ s/(`)/'/g;
15423: $value =~ s/^\s+//;
15424: $value =~ s/\s+$//;
15425: if ($name ne '') {
15426: $confhash{$provider}{'custom'}{$name} = $value;
15427: $changes{$provider} = 1;
15428: }
15429: }
15430: }
15431: }
15432: if (@allpos > 0) {
15433: my $idx = 0;
15434: foreach my $provider (@allpos) {
15435: if ($provider ne '') {
15436: $confhash{$provider}{'order'} = $idx;
15437: unless ($changes{$provider}) {
15438: if (ref($domconfig{$action}) eq 'HASH') {
15439: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15440: if ($domconfig{$action}{$provider}{'order'} ne $idx) {
15441: $changes{$provider} = 1;
15442: }
15443: }
15444: }
15445: }
15446: $idx ++;
15447: }
15448: }
15449: }
15450: my %proc_hash = (
15451: $action => { %confhash }
15452: );
15453: my $putresult = &Apache::lonnet::put_dom('configuration',\%proc_hash,
15454: $dom);
15455: if ($putresult eq 'ok') {
15456: my %proc_enchash = (
15457: $action => { %encconfhash }
15458: );
1.384 raeburn 15459: &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom,undef,1);
1.372 raeburn 15460: if (keys(%changes) > 0) {
15461: my $cachetime = 24*60*60;
15462: my %procall = %confhash;
15463: foreach my $provider (keys(%procall)) {
15464: if (ref($encconfhash{$provider}) eq 'HASH') {
15465: foreach my $key ('key','secret') {
15466: $procall{$provider}{$key} = $encconfhash{$provider}{$key};
15467: }
15468: }
15469: }
15470: &Apache::lonnet::do_cache_new('proctoring',$dom,\%procall,$cachetime);
15471: if (ref($lastactref) eq 'HASH') {
15472: $lastactref->{'proctoring'} = 1;
15473: }
15474: $resulttext = &mt('Configuration for Provider(s) with changes:').'<ul>';
15475: my %bynum;
15476: foreach my $provider (sort(keys(%changes))) {
15477: my $position = $confhash{$provider}{'order'};
15478: $bynum{$position} = $provider;
15479: }
15480: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
15481: my $provider = $bynum{$pos};
15482: my %lt = &proctoring_titles($provider);
15483: my %fieldtitles = &proctoring_fieldtitles($provider);
15484: if (!$confhash{$provider}{'available'}) {
15485: $resulttext .= '<li>'.&mt('Proctoring integration unavailable for: [_1]','<b>'.$providernames{$provider}.'</b>').'</li>';
15486: } else {
15487: $resulttext .= '<li>'.&mt('Proctoring integration available for: [_1]','<b>'.$providernames{$provider}.'</b>');
15488: if ($confhash{$provider}{'image'}) {
15489: $resulttext .= ' '.
15490: '<img src="'.$confhash{$provider}{'image'}.'"'.
15491: ' alt="'.&mt('Proctoring icon').'" />';
15492: }
15493: $resulttext .= '<ul>';
15494: my $position = $pos + 1;
15495: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
15496: foreach my $key ('version','sigmethod','url','lifetime') {
15497: if ($confhash{$provider}{$key} ne '') {
15498: $resulttext .= '<li>'.$lt{$key}.': '.$confhash{$provider}{$key}.'</li>';
15499: }
15500: }
15501: if ($encconfhash{$provider}{'key'} ne '') {
15502: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfhash{$provider}{'key'}.'</li>';
15503: }
15504: if ($encconfhash{$provider}{'secret'} ne '') {
15505: $resulttext .= '<li>'.$lt{'secret'}.': ';
15506: my $num = length($encconfhash{$provider}{'secret'});
15507: $resulttext .= ('*'x$num).'</li>';
15508: }
15509: my (@fields,$showroles);
15510: if (ref($requserfields{$provider}) eq 'ARRAY') {
15511: push(@fields,@{$requserfields{$provider}});
15512: }
15513: if (ref($confhash{$provider}{'fields'}) eq 'ARRAY') {
15514: push(@fields,@{$confhash{$provider}{'fields'}});
15515: } elsif (ref($confhash{$provider}{'fields'}) eq 'HASH') {
15516: push(@fields,(keys(%{$confhash{$provider}{'fields'}})));
15517: }
15518: if (@fields) {
15519: if (grep(/^roles$/,@fields)) {
15520: $showroles = 1;
15521: }
15522: $resulttext .= '<li>'.$lt{'udsl'}.': "'.
15523: join('", "', map { $lt{$_}; } @fields).'"</li>';
15524: }
15525: if (ref($requserfields{$provider}) eq 'ARRAY') {
15526: if (grep(/^user$/,@{$requserfields{$provider}})) {
15527: if ($confhash{$provider}{'incdom'}) {
15528: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'uname:dom'}).'</li>';
15529: } else {
15530: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'username'}).'</li>';
15531: }
15532: }
15533: }
15534: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15535: if (@{$confhash{$provider}{'defaults'}} > 0) {
15536: $resulttext .= '<li>'.$lt{'defa'};
15537: foreach my $field (@{$confhash{$provider}{'defaults'}}) {
15538: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15539: }
15540: $resulttext =~ s/,$//;
15541: $resulttext .= '</li>';
15542: }
15543: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15544: if (keys(%{$confhash{$provider}{'defaults'}})) {
15545: $resulttext .= '<li>'.$lt{'defa'}.': <ul>';
15546: foreach my $key (sort(keys(%{$confhash{$provider}{'defaults'}}))) {
15547: if ($confhash{$provider}{'defaults'}{$key} ne '') {
15548: $resulttext .= '<li>'.$fieldtitles{$key}.' = '.$confhash{$provider}{'defaults'}{$key}.'</li>';
15549: }
15550: }
15551: $resulttext .= '</ul></li>';
15552: }
15553: }
15554: if (ref($crsconf{$provider}) eq 'ARRAY') {
15555: if (@{$crsconf{$provider}} > 0) {
15556: $resulttext .= '<li>'.&mt('Configurable in course:');
15557: my $numconfig = 0;
15558: if (ref($confhash{$provider}{'crsconf'}) eq 'ARRAY') {
15559: if (@{$confhash{$provider}{'crsconf'}} > 0) {
15560: foreach my $field (@{$confhash{$provider}{'crsconf'}}) {
15561: $numconfig ++;
15562: if ($provider eq 'examity') {
15563: $resulttext .= ' "'.$lt{'crs'.$field}.'",';
15564: } else {
15565: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15566: }
15567: }
15568: $resulttext =~ s/,$//;
15569: }
15570: }
15571: if (!$numconfig) {
15572: $resulttext .= ' '.&mt('None');
15573: }
15574: $resulttext .= '</li>';
15575: }
15576: }
15577: if ($showroles) {
15578: if (ref($confhash{$provider}{'roles'}) eq 'HASH') {
15579: my $rolemaps;
15580: foreach my $role (@courseroles) {
15581: if ($confhash{$provider}{'roles'}{$role}) {
15582: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
15583: $confhash{$provider}{'roles'}{$role}.',';
15584: }
15585: }
15586: if ($rolemaps) {
15587: $rolemaps =~ s/,$//;
15588: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
15589: }
15590: }
15591: }
15592: if (ref($confhash{$provider}{'custom'}) eq 'HASH') {
15593: my $customlist;
15594: if (keys(%{$confhash{$provider}{'custom'}})) {
15595: foreach my $key (sort(keys(%{$confhash{$provider}{'custom'}}))) {
15596: $customlist .= $key.'='.$confhash{$provider}{'custom'}{$key}.', ';
15597: }
15598: $customlist =~ s/,$//;
15599: }
15600: if ($customlist) {
15601: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
15602: }
15603: }
15604: $resulttext .= '</ul></li>';
15605: }
15606: }
15607: $resulttext .= '</ul>';
15608: } else {
15609: $resulttext = &mt('No changes made.');
15610: }
15611: } else {
15612: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15613: }
15614: if ($errors) {
15615: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15616: $errors.'</ul>';
15617: }
15618: return $resulttext;
15619: }
15620:
15621: sub process_proctoring_image {
15622: my ($r,$dom,$confname,$caller,$provider,$configuserok,$switchserver,$author_ok) = @_;
15623: my $filename = $env{'form.'.$caller.'.filename'};
15624: my ($error,$url);
15625: my ($width,$height) = (21,21);
15626: if ($configuserok eq 'ok') {
15627: if ($switchserver) {
15628: $error = &mt('Upload of Remote Proctoring Provider icon is not permitted to this server: [_1]',
15629: $switchserver);
15630: } elsif ($author_ok eq 'ok') {
1.421 raeburn 15631: my $modified = [];
1.372 raeburn 15632: my ($result,$imageurl,$madethumb) =
1.421 raeburn 15633: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
15634: "proctoring/$provider/icon",$width,$height,
15635: '',$modified);
1.372 raeburn 15636: if ($result eq 'ok') {
15637: if ($madethumb) {
15638: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
15639: my $imagethumb = "$path/tn-".$imagefile;
15640: $url = $imagethumb;
15641: } else {
15642: $url = $imageurl;
15643: }
1.421 raeburn 15644: &update_modify_urls($r,$modified);
1.372 raeburn 15645: } else {
15646: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
15647: }
15648: } else {
15649: $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);
15650: }
15651: } else {
15652: $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);
15653: }
15654: return ($url,$error);
15655: }
15656:
1.320 raeburn 15657: sub modify_lti {
15658: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15659: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.424 raeburn 15660: my ($newid,@allpos,%changes,%confhash,%ltienc,$errors,$resulttext);
1.320 raeburn 15661: my (%posslti,%posslticrs,%posscrstype);
15662: my @courseroles = ('cc','in','ta','ep','st');
15663: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
15664: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
1.392 raeburn 15665: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 15666: my %coursetypetitles = &Apache::lonlocal::texthash (
15667: official => 'Official',
15668: unofficial => 'Unofficial',
15669: community => 'Community',
15670: textbook => 'Textbook',
15671: placement => 'Placement Test',
1.392 raeburn 15672: lti => 'LTI Provider',
1.320 raeburn 15673: );
1.325 raeburn 15674: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 15675: my %lt = <i_names();
15676: map { $posslti{$_} = 1; } @ltiroles;
15677: map { $posslticrs{$_} = 1; } @lticourseroles;
15678: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 15679:
1.326 raeburn 15680: my %menutitles = <imenu_titles();
1.421 raeburn 15681: my (%currltisec,%secchanges,%newltisec,%newltienc,%newkeyset);
1.326 raeburn 15682:
1.421 raeburn 15683: &fetch_secrets($dom,'ltisec',\%domconfig,\%currltisec,\%secchanges,\%newltisec,\%newkeyset);
1.405 raeburn 15684:
1.406 raeburn 15685: my (%linkprotchg,$linkprotoutput,$is_home);
15686: my $proterror = &Apache::courseprefs::process_linkprot($dom,'',$currltisec{'linkprot'},
15687: \%linkprotchg,'domain');
15688: my $home = &Apache::lonnet::domain($dom,'primary');
15689: unless (($home eq 'no_host') || ($home eq '')) {
15690: my @ids=&Apache::lonnet::current_machine_ids();
15691: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; } }
15692: }
15693:
15694: if (keys(%linkprotchg)) {
15695: $secchanges{'linkprot'} = 1;
15696: my %oldlinkprot;
15697: if (ref($currltisec{'linkprot'}) eq 'HASH') {
15698: %oldlinkprot = %{$currltisec{'linkprot'}};
15699: }
15700: foreach my $id (keys(%linkprotchg)) {
15701: if (ref($linkprotchg{$id}) eq 'HASH') {
15702: foreach my $inner (keys(%{$linkprotchg{$id}})) {
15703: if (($inner eq 'secret') || ($inner eq 'key')) {
15704: if ($is_home) {
15705: $newltienc{$id}{$inner} = $linkprotchg{$id}{$inner};
15706: }
15707: }
15708: }
15709: } else {
15710: $newltisec{'linkprot'}{$id} = $linkprotchg{$id};
15711: }
15712: }
15713: $linkprotoutput = &Apache::courseprefs::store_linkprot($dom,'','domain',\%linkprotchg,\%oldlinkprot);
15714: if (keys(%linkprotchg)) {
15715: %{$newltisec{'linkprot'}} = %linkprotchg;
15716: }
15717: }
15718: if (ref($currltisec{'linkprot'}) eq 'HASH') {
15719: foreach my $id (%{$currltisec{'linkprot'}}) {
15720: next if ($id !~ /^\d+$/);
15721: unless (exists($linkprotchg{$id})) {
15722: if (ref($currltisec{'linkprot'}{$id}) eq 'HASH') {
15723: foreach my $inner (keys(%{$currltisec{'linkprot'}{$id}})) {
15724: if (($inner eq 'secret') || ($inner eq 'key')) {
15725: if ($is_home) {
15726: $newltienc{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15727: }
15728: } else {
15729: $newltisec{'linkprot'}{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15730: }
15731: }
15732: } else {
15733: $newltisec{'linkprot'}{$id} = $currltisec{'linkprot'}{$id};
15734: }
15735: }
15736: }
15737: }
15738: if ($proterror) {
15739: $errors .= '<li>'.$proterror.'</li>';
15740: }
1.320 raeburn 15741: my (@items,%deletions,%itemids);
15742: if ($env{'form.lti_add'}) {
15743: my $consumer = $env{'form.lti_consumer_add'};
15744: $consumer =~ s/(`)/'/g;
15745: ($newid,my $error) = &get_lti_id($dom,$consumer);
15746: if ($newid) {
15747: $itemids{'add'} = $newid;
15748: push(@items,'add');
15749: $changes{$newid} = 1;
15750: } else {
15751: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
15752: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15753: }
15754: }
15755: if (ref($domconfig{$action}) eq 'HASH') {
15756: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
15757: if (@todelete) {
15758: map { $deletions{$_} = 1; } @todelete;
15759: }
15760: my $maxnum = $env{'form.lti_maxnum'};
1.390 raeburn 15761: for (my $i=0; $i<$maxnum; $i++) {
1.320 raeburn 15762: my $itemid = $env{'form.lti_id_'.$i};
15763: $itemid =~ s/\D+//g;
15764: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
15765: if ($deletions{$itemid}) {
15766: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
15767: } else {
1.390 raeburn 15768: push(@items,$i);
15769: $itemids{$i} = $itemid;
1.320 raeburn 15770: }
15771: }
15772: }
15773: }
1.424 raeburn 15774: my (%keystore,$secstored);
15775: if ($is_home) {
15776: &store_security($dom,'lti',\%secchanges,\%newkeyset,\%keystore);
15777: }
15778:
15779: my ($cipher,$privnum);
15780: if ((@items > 0) && ($is_home)) {
15781: ($cipher,$privnum) = &get_priv_creds($dom,$home,$secchanges{'encrypt'},
15782: $newltisec{'encrypt'},$keystore{$home});
15783: }
1.320 raeburn 15784: foreach my $idx (@items) {
15785: my $itemid = $itemids{$idx};
15786: next unless ($itemid);
1.424 raeburn 15787: my %currlti;
15788: unless ($idx eq 'add') {
15789: if (ref($domconfig{$action}) eq 'HASH') {
15790: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
15791: %currlti = %{$domconfig{$action}{$itemid}};
15792: }
15793: }
15794: }
1.390 raeburn 15795: my $position = $env{'form.lti_pos_'.$itemid};
1.320 raeburn 15796: $position =~ s/\D+//g;
15797: if ($position ne '') {
15798: $allpos[$position] = $itemid;
15799: }
1.424 raeburn 15800: foreach my $item ('consumer','lifetime','requser','crsinc') {
1.320 raeburn 15801: my $formitem = 'form.lti_'.$item.'_'.$idx;
15802: $env{$formitem} =~ s/(`)/'/g;
15803: if ($item eq 'lifetime') {
15804: $env{$formitem} =~ s/[^\d.]//g;
15805: }
15806: if ($env{$formitem} ne '') {
1.424 raeburn 15807: $confhash{$itemid}{$item} = $env{$formitem};
15808: unless (($idx eq 'add') || ($changes{$itemid})) {
15809: if ($currlti{$item} ne $confhash{$itemid}{$item}) {
15810: $changes{$itemid} = 1;
1.320 raeburn 15811: }
15812: }
15813: }
15814: }
15815: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
15816: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
15817: }
1.345 raeburn 15818: if ($confhash{$itemid}{'requser'}) {
15819: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
1.405 raeburn 15820: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
1.345 raeburn 15821: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
15822: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
15823: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
15824: my $mapuser = $env{'form.lti_customuser_'.$idx};
15825: $mapuser =~ s/(`)/'/g;
1.405 raeburn 15826: $mapuser =~ s/^\s+|\s+$//g;
15827: $confhash{$itemid}{'mapuser'} = $mapuser;
1.345 raeburn 15828: }
15829: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
15830: my @makeuser;
15831: foreach my $ltirole (sort(@possmakeuser)) {
15832: if ($posslti{$ltirole}) {
15833: push(@makeuser,$ltirole);
15834: }
15835: }
15836: $confhash{$itemid}{'makeuser'} = \@makeuser;
15837: if (@makeuser) {
15838: my $lcauth = $env{'form.lti_lcauth_'.$idx};
15839: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
15840: $confhash{$itemid}{'lcauth'} = $lcauth;
15841: if ($lcauth ne 'internal') {
15842: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
15843: $lcauthparm =~ s/^(\s+|\s+)$//g;
15844: $lcauthparm =~ s/`//g;
15845: if ($lcauthparm ne '') {
15846: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
15847: }
15848: }
15849: } else {
15850: $confhash{$itemid}{'lcauth'} = 'lti';
15851: }
1.320 raeburn 15852: }
1.345 raeburn 15853: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
15854: if (@possinstdata) {
15855: foreach my $field (@possinstdata) {
15856: if (exists($fieldtitles{$field})) {
15857: push(@{$confhash{$itemid}{'instdata'}});
1.325 raeburn 15858: }
15859: }
15860: }
1.363 raeburn 15861: if ($env{'form.lti_callback_'.$idx}) {
15862: if ($env{'form.lti_callbackparam_'.$idx}) {
15863: my $callback = $env{'form.lti_callbackparam_'.$idx};
15864: $callback =~ s/^\s+|\s+$//g;
15865: $confhash{$itemid}{'callback'} = $callback;
15866: }
15867: }
1.391 raeburn 15868: foreach my $field ('topmenu','inlinemenu') {
1.345 raeburn 15869: if ($env{'form.lti_'.$field.'_'.$idx}) {
15870: $confhash{$itemid}{$field} = 1;
15871: }
1.320 raeburn 15872: }
1.345 raeburn 15873: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
15874: $confhash{$itemid}{lcmenu} = [];
15875: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
15876: foreach my $field (@possmenu) {
15877: if (exists($menutitles{$field})) {
15878: if ($field eq 'grades') {
15879: next unless ($env{'form.lti_inlinemenu_'.$idx});
15880: }
15881: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 15882: }
15883: }
15884: }
1.391 raeburn 15885: if ($confhash{$itemid}{'crsinc'}) {
15886: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
15887: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
15888: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
15889: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
15890: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
15891: $mapcrs =~ s/(`)/'/g;
15892: $mapcrs =~ s/^\s+|\s+$//g;
15893: $confhash{$itemid}{'mapcrs'} = $mapcrs;
15894: }
15895: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
15896: my @crstypes;
15897: foreach my $type (sort(@posstypes)) {
15898: if ($posscrstype{$type}) {
15899: push(@crstypes,$type);
15900: }
15901: }
15902: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
1.392 raeburn 15903: if ($env{'form.lti_storecrs_'.$idx}) {
15904: $confhash{$itemid}{'storecrs'} = 1;
15905: }
1.391 raeburn 15906: if ($env{'form.lti_makecrs_'.$idx}) {
15907: $confhash{$itemid}{'makecrs'} = 1;
15908: }
15909: foreach my $ltirole (@lticourseroles) {
15910: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
15911: if (grep(/^\Q$possrole\E$/,@courseroles)) {
15912: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
15913: }
15914: }
15915: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
15916: my @selfenroll;
15917: foreach my $type (sort(@possenroll)) {
15918: if ($posslticrs{$type}) {
15919: push(@selfenroll,$type);
15920: }
15921: }
15922: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
15923: if ($env{'form.lti_crssec_'.$idx}) {
15924: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
15925: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
15926: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
15927: my $section = $env{'form.lti_customsection_'.$idx};
15928: $section =~ s/(`)/'/g;
15929: $section =~ s/^\s+|\s+$//g;
15930: if ($section ne '') {
15931: $confhash{$itemid}{'section'} = $section;
15932: }
15933: }
15934: }
15935: foreach my $field ('passback','roster') {
15936: if ($env{'form.lti_'.$field.'_'.$idx}) {
15937: $confhash{$itemid}{$field} = 1;
15938: }
15939: }
15940: if ($env{'form.lti_passback_'.$idx}) {
15941: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
15942: $confhash{$itemid}{'passbackformat'} = '1.0';
15943: } else {
15944: $confhash{$itemid}{'passbackformat'} = '1.1';
1.337 raeburn 15945: }
15946: }
1.391 raeburn 15947: }
15948: unless (($idx eq 'add') || ($changes{$itemid})) {
15949: if ($confhash{$itemid}{'crsinc'}) {
1.392 raeburn 15950: foreach my $field ('mapcrs','storecrs','makecrs','section','passback','roster') {
1.424 raeburn 15951: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.320 raeburn 15952: $changes{$itemid} = 1;
15953: }
1.345 raeburn 15954: }
15955: unless ($changes{$itemid}) {
1.424 raeburn 15956: if ($currlti{'passback'} eq $confhash{$itemid}{'passback'}) {
15957: if ($currlti{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 15958: $changes{$itemid} = 1;
15959: }
15960: }
1.345 raeburn 15961: }
1.391 raeburn 15962: foreach my $field ('mapcrstype','selfenroll') {
15963: unless ($changes{$itemid}) {
1.424 raeburn 15964: if (ref($currlti{$field}) eq 'ARRAY') {
1.391 raeburn 15965: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424 raeburn 15966: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391 raeburn 15967: $confhash{$itemid}{$field});
15968: if (@diffs) {
15969: $changes{$itemid} = 1;
15970: }
1.424 raeburn 15971: } elsif (@{$currlti{$field}} > 0) {
1.391 raeburn 15972: $changes{$itemid} = 1;
15973: }
15974: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
15975: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 15976: $changes{$itemid} = 1;
15977: }
15978: }
1.391 raeburn 15979: }
15980: }
15981: unless ($changes{$itemid}) {
1.424 raeburn 15982: if (ref($currlti{'maproles'}) eq 'HASH') {
1.391 raeburn 15983: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
1.424 raeburn 15984: foreach my $ltirole (keys(%{$currlti{'maproles'}})) {
15985: if ($currlti{'maproles'}{$ltirole} ne
1.391 raeburn 15986: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.345 raeburn 15987: $changes{$itemid} = 1;
15988: last;
15989: }
15990: }
1.391 raeburn 15991: unless ($changes{$itemid}) {
15992: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
15993: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
1.424 raeburn 15994: $currlti{'maproles'}{$ltirole}) {
1.391 raeburn 15995: $changes{$itemid} = 1;
15996: last;
15997: }
15998: }
15999: }
1.424 raeburn 16000: } elsif (keys(%{$currlti{'maproles'}}) > 0) {
1.391 raeburn 16001: $changes{$itemid} = 1;
1.345 raeburn 16002: }
1.391 raeburn 16003: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16004: unless ($changes{$itemid}) {
16005: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
16006: $changes{$itemid} = 1;
16007: }
16008: }
16009: }
16010: }
16011: }
16012: unless ($changes{$itemid}) {
16013: foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
1.424 raeburn 16014: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.345 raeburn 16015: $changes{$itemid} = 1;
1.320 raeburn 16016: }
1.391 raeburn 16017: }
16018: unless ($changes{$itemid}) {
16019: foreach my $field ('makeuser','lcmenu') {
1.424 raeburn 16020: if (ref($currlti{$field}) eq 'ARRAY') {
1.391 raeburn 16021: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424 raeburn 16022: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391 raeburn 16023: $confhash{$itemid}{$field});
16024: if (@diffs) {
16025: $changes{$itemid} = 1;
16026: }
1.424 raeburn 16027: } elsif (@{$currlti{$field}} > 0) {
1.391 raeburn 16028: $changes{$itemid} = 1;
16029: }
16030: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
16031: if (@{$confhash{$itemid}{$field}} > 0) {
16032: $changes{$itemid} = 1;
16033: }
1.345 raeburn 16034: }
1.320 raeburn 16035: }
16036: }
16037: }
16038: }
16039: }
1.424 raeburn 16040: if ($is_home) {
16041: my $keyitem = 'form.lti_key_'.$idx;
16042: $env{$keyitem} =~ s/(`)/'/g;
16043: if ($env{$keyitem} ne '') {
16044: $ltienc{$itemid}{'key'} = $env{$keyitem};
16045: unless ($changes{$itemid}) {
16046: if ($currlti{'key'} ne $env{$keyitem}) {
16047: $changes{$itemid} = 1;
16048: }
16049: }
16050: }
16051: my $secretitem = 'form.lti_secret_'.$idx;
16052: $env{$secretitem} =~ s/(`)/'/g;
16053: if ($currlti{'usable'}) {
16054: if ($env{'form.lti_changesecret_'.$idx}) {
16055: if ($env{$secretitem} ne '') {
16056: if ($privnum && $cipher) {
16057: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
16058: $confhash{$itemid}{'cipher'} = $privnum;
16059: } else {
16060: $ltienc{$itemid}{'secret'} = $env{$secretitem};
16061: }
16062: $changes{$itemid} = 1;
16063: }
16064: } else {
16065: $ltienc{$itemid}{'secret'} = $currlti{'secret'};
16066: $confhash{$itemid}{'cipher'} = $currlti{'cipher'};
16067: }
16068: if (ref($ltienc{$itemid}) eq 'HASH') {
16069: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'secret'} ne '')) {
16070: $confhash{$itemid}{'usable'} = 1;
16071: }
16072: }
16073: } elsif ($env{$secretitem} ne '') {
16074: if ($privnum && $cipher) {
16075: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
16076: $confhash{$itemid}{'cipher'} = $privnum;
16077: } else {
16078: $ltienc{$itemid}{'secret'} = $env{$secretitem};
16079: }
16080: if (ref($ltienc{$itemid}) eq 'HASH') {
16081: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'key'} ne '')) {
16082: $confhash{$itemid}{'usable'} = 1;
16083: }
16084: }
16085: $changes{$itemid} = 1;
16086: }
16087: }
16088: unless ($changes{$itemid}) {
16089: foreach my $key (keys(%currlti)) {
16090: if (ref($currlti{$key}) eq 'HASH') {
16091: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
16092: foreach my $innerkey (keys(%{$currlti{$key}})) {
16093: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
16094: $changes{$itemid} = 1;
16095: last;
16096: }
16097: }
16098: } elsif (keys(%{$currlti{$key}}) > 0) {
16099: $changes{$itemid} = 1;
16100: }
16101: }
16102: last if ($changes{$itemid});
16103: }
16104: }
1.320 raeburn 16105: }
16106: if (@allpos > 0) {
16107: my $idx = 0;
16108: foreach my $itemid (@allpos) {
16109: if ($itemid ne '') {
16110: $confhash{$itemid}{'order'} = $idx;
16111: if (ref($domconfig{$action}) eq 'HASH') {
16112: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
16113: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
16114: $changes{$itemid} = 1;
16115: }
16116: }
16117: }
16118: $idx ++;
16119: }
16120: }
16121: }
1.424 raeburn 16122:
16123: if ((keys(%changes) == 0) && (keys(%secchanges) == 0)) {
16124: return &mt('No changes made.');
16125: }
16126:
1.320 raeburn 16127: my %ltihash = (
1.405 raeburn 16128: $action => { %confhash }
16129: );
1.424 raeburn 16130: my %ltienchash;
16131:
16132: if ($is_home) {
16133: %ltienchash = (
16134: $action => { %ltienc }
16135: );
16136: }
1.405 raeburn 16137: if (keys(%secchanges)) {
16138: $ltihash{'ltisec'} = \%newltisec;
1.406 raeburn 16139: if ($secchanges{'linkprot'}) {
16140: if ($is_home) {
16141: $ltienchash{'linkprot'} = \%newltienc;
16142: }
16143: }
1.405 raeburn 16144: }
16145: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,$dom);
1.320 raeburn 16146: if ($putresult eq 'ok') {
1.424 raeburn 16147: if (keys(%ltienchash)) {
16148: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.405 raeburn 16149: }
16150: $resulttext = &mt('Changes made:').'<ul>';
16151: if (keys(%secchanges) > 0) {
1.423 raeburn 16152: $resulttext .= <i_security_results($dom,'lti',\%secchanges,\%newltisec,\%newkeyset,\%keystore);
1.421 raeburn 16153: if (exists($secchanges{'linkprot'})) {
16154: $resulttext .= $linkprotoutput;
1.405 raeburn 16155: }
16156: }
1.320 raeburn 16157: if (keys(%changes) > 0) {
16158: my $cachetime = 24*60*60;
1.424 raeburn 16159: &Apache::lonnet::do_cache_new('lti',$dom,\%confhash,$cachetime);
1.320 raeburn 16160: if (ref($lastactref) eq 'HASH') {
16161: $lastactref->{'lti'} = 1;
16162: }
16163: my %bynum;
16164: foreach my $itemid (sort(keys(%changes))) {
1.424 raeburn 16165: if (ref($confhash{$itemid}) eq 'HASH') {
16166: my $position = $confhash{$itemid}{'order'};
16167: $bynum{$position} = $itemid;
16168: }
1.320 raeburn 16169: }
16170: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
16171: my $itemid = $bynum{$pos};
1.424 raeburn 16172: if (ref($confhash{$itemid}) eq 'HASH') {
1.390 raeburn 16173: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1.320 raeburn 16174: my $position = $pos + 1;
16175: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
16176: foreach my $item ('version','lifetime') {
16177: if ($confhash{$itemid}{$item} ne '') {
16178: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
16179: }
16180: }
1.424 raeburn 16181: if ($ltienc{$itemid}{'key'} ne '') {
16182: $resulttext .= '<li>'.$lt{'key'}.': '.$ltienc{$itemid}{'key'}.'</li>';
1.320 raeburn 16183: }
1.424 raeburn 16184: if ($ltienc{$itemid}{'secret'} ne '') {
16185: $resulttext .= '<li>'.$lt{'secret'}.': ['.&mt('not shown').']</li>';
1.320 raeburn 16186: }
1.345 raeburn 16187: if ($confhash{$itemid}{'requser'}) {
1.391 raeburn 16188: if ($confhash{$itemid}{'callback'}) {
16189: $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
16190: } else {
1.392 raeburn 16191: $resulttext .= '<li>'.&mt('Callback to logout LON-CAPA on log out from Consumer').'</li>';
1.391 raeburn 16192: }
1.345 raeburn 16193: if ($confhash{$itemid}{'mapuser'}) {
16194: my $shownmapuser;
16195: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
16196: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
16197: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
16198: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
16199: } else {
16200: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 16201: }
1.345 raeburn 16202: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 16203: }
1.345 raeburn 16204: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
16205: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
16206: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
16207: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
16208: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
16209: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
16210: } else {
16211: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
16212: $confhash{$itemid}{'lcauth'});
16213: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
16214: $resulttext .= '; '.&mt('a randomly generated password will be created');
16215: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
16216: if ($confhash{$itemid}{'lcauthparm'} ne '') {
16217: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
16218: }
16219: } else {
16220: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
16221: }
16222: }
16223: $resulttext .= '</li>';
16224: } else {
16225: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
16226: }
1.320 raeburn 16227: }
1.345 raeburn 16228: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
16229: if (@{$confhash{$itemid}{'instdata'}} > 0) {
16230: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
16231: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 16232: } else {
1.345 raeburn 16233: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325 raeburn 16234: }
1.320 raeburn 16235: }
1.391 raeburn 16236: foreach my $item ('topmenu','inlinemenu') {
1.345 raeburn 16237: $resulttext .= '<li>'.$lt{$item}.': ';
16238: if ($confhash{$itemid}{$item}) {
16239: $resulttext .= &mt('Yes');
16240: } else {
16241: $resulttext .= &mt('No');
1.337 raeburn 16242: }
1.345 raeburn 16243: $resulttext .= '</li>';
1.320 raeburn 16244: }
1.345 raeburn 16245: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16246: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16247: $resulttext .= '<li>'.&mt('Menu items:').' '.
1.391 raeburn 16248: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16249: } else {
16250: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16251: }
16252: }
16253: if ($confhash{$itemid}{'crsinc'}) {
16254: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16255: my $rolemaps;
16256: foreach my $role (@ltiroles) {
16257: if ($confhash{$itemid}{'maproles'}{$role}) {
16258: $rolemaps .= (' 'x2).$role.'='.
16259: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
16260: 'Course').',';
16261: }
16262: }
16263: if ($rolemaps) {
16264: $rolemaps =~ s/,$//;
16265: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
16266: }
16267: }
16268: if ($confhash{$itemid}{'mapcrs'}) {
16269: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
16270: }
16271: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
16272: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
16273: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
16274: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
16275: '</li>';
16276: } else {
16277: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
16278: }
16279: }
1.392 raeburn 16280: if ($confhash{$itemid}{'storecrs'}) {
16281: $resulttext .= '<li>'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.$confhash{$itemid}{'storecrs'}.'</li>';
16282: }
1.391 raeburn 16283: if ($confhash{$itemid}{'makecrs'}) {
16284: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
16285: } else {
16286: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
16287: }
16288: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
16289: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
16290: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
16291: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
16292: '</li>';
16293: } else {
16294: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
16295: }
16296: }
16297: if ($confhash{$itemid}{'section'}) {
16298: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
16299: $resulttext .= '<li>'.&mt('User section from standard field:').
16300: ' (course_section_sourcedid)'.'</li>';
16301: } else {
16302: $resulttext .= '<li>'.&mt('User section from:').' '.
16303: $confhash{$itemid}{'section'}.'</li>';
16304: }
1.345 raeburn 16305: } else {
1.391 raeburn 16306: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
16307: }
16308: foreach my $item ('passback','roster','topmenu','inlinemenu') {
16309: $resulttext .= '<li>'.$lt{$item}.': ';
16310: if ($confhash{$itemid}{$item}) {
16311: $resulttext .= &mt('Yes');
16312: if ($item eq 'passback') {
16313: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
16314: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
16315: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
16316: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
16317: }
16318: }
16319: } else {
16320: $resulttext .= &mt('No');
16321: }
16322: $resulttext .= '</li>';
16323: }
16324: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16325: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16326: $resulttext .= '<li>'.&mt('Menu items:').' '.
16327: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16328: } else {
16329: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16330: }
1.345 raeburn 16331: }
1.326 raeburn 16332: }
16333: }
1.320 raeburn 16334: $resulttext .= '</ul></li>';
16335: }
16336: }
1.424 raeburn 16337: if (keys(%deletions)) {
16338: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
16339: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
16340: }
16341: }
1.320 raeburn 16342: }
1.405 raeburn 16343: $resulttext .= '</ul>';
1.424 raeburn 16344: if (ref($lastactref) eq 'HASH') {
16345: if (($secchanges{'encrypt'}) || ($secchanges{'private'})) {
16346: $lastactref->{'domdefaults'} = 1;
16347: }
16348: }
1.320 raeburn 16349: } else {
16350: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
16351: }
16352: if ($errors) {
16353: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
16354: $errors.'</ul>';
16355: }
16356: return $resulttext;
16357: }
16358:
1.424 raeburn 16359: sub get_priv_creds {
16360: my ($dom,$home,$encchg,$encrypt,$storedsec) = @_;
16361: my ($needenc,$cipher,$privnum);
16362: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
16363: if (($encchg) && (ref($encrypt) eq 'HASH')) {
16364: $needenc = $encrypt->{'consumers'}
16365: } else {
16366: $needenc = $domdefs{'ltienc_consumers'};
16367: }
16368: if ($needenc) {
16369: if (($storedsec eq 'ok') || ((ref($domdefs{'ltiprivhosts'}) eq 'ARRAY') &&
16370: (grep(/^\Q$home\E$/,@{$domdefs{'ltiprivhosts'}})))) {
16371: my %privhash = &Apache::lonnet::restore_dom('lti','private',$dom,$home,1);
16372: my $privkey = $privhash{'key'};
16373: $privnum = $privhash{'version'};
16374: if (($privnum) && ($privkey ne '')) {
16375: $cipher = Crypt::CBC->new({'key' => $privkey,
16376: 'cipher' => 'DES'});
16377: }
16378: }
16379: }
16380: return ($cipher,$privnum);
16381: }
16382:
1.320 raeburn 16383: sub get_lti_id {
16384: my ($domain,$consumer) = @_;
16385: # get lock on lti db
16386: my $lockhash = {
16387: lock => $env{'user.name'}.
16388: ':'.$env{'user.domain'},
16389: };
16390: my $tries = 0;
16391: my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
16392: my ($id,$error);
16393:
16394: while (($gotlock ne 'ok') && ($tries<10)) {
16395: $tries ++;
16396: sleep (0.1);
16397: $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
16398: }
16399: if ($gotlock eq 'ok') {
16400: my %currids = &Apache::lonnet::dump_dom('lti',$domain);
16401: if ($currids{'lock'}) {
16402: delete($currids{'lock'});
16403: if (keys(%currids)) {
16404: my @curr = sort { $a <=> $b } keys(%currids);
16405: if ($curr[-1] =~ /^\d+$/) {
16406: $id = 1 + $curr[-1];
16407: }
16408: } else {
16409: $id = 1;
16410: }
16411: if ($id) {
16412: unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
16413: $error = 'nostore';
16414: }
16415: } else {
16416: $error = 'nonumber';
16417: }
16418: }
16419: my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
16420: } else {
16421: $error = 'nolock';
16422: }
16423: return ($id,$error);
16424: }
16425:
1.3 raeburn 16426: sub modify_autoenroll {
1.205 raeburn 16427: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 16428: my ($resulttext,%changes);
16429: my %currautoenroll;
16430: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
16431: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
16432: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
16433: }
16434: }
16435: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
16436: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 16437: sender => 'Sender for notification messages',
1.274 raeburn 16438: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.399 raeburn 16439: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 16440: my @offon = ('off','on');
1.17 raeburn 16441: my $sender_uname = $env{'form.sender_uname'};
16442: my $sender_domain = $env{'form.sender_domain'};
16443: if ($sender_domain eq '') {
16444: $sender_uname = '';
16445: } elsif ($sender_uname eq '') {
16446: $sender_domain = '';
16447: }
1.129 raeburn 16448: my $coowners = $env{'form.autoassign_coowners'};
1.399 raeburn 16449: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
16450: $autofailsafe =~ s{^\s+|\s+$}{}g;
16451: if ($autofailsafe =~ /\D/) {
16452: undef($autofailsafe);
16453: }
1.274 raeburn 16454: my $failsafe = $env{'form.autoenroll_failsafe'};
1.399 raeburn 16455: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
16456: $failsafe = 'off';
1.400 raeburn 16457: undef($autofailsafe);
1.274 raeburn 16458: }
1.1 raeburn 16459: my %autoenrollhash = (
1.129 raeburn 16460: autoenroll => { 'run' => $env{'form.autoenroll_run'},
16461: 'sender_uname' => $sender_uname,
16462: 'sender_domain' => $sender_domain,
16463: 'co-owners' => $coowners,
1.399 raeburn 16464: 'autofailsafe' => $autofailsafe,
1.400 raeburn 16465: 'failsafe' => $failsafe,
1.1 raeburn 16466: }
16467: );
1.4 raeburn 16468: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
16469: $dom);
1.1 raeburn 16470: if ($putresult eq 'ok') {
16471: if (exists($currautoenroll{'run'})) {
16472: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
16473: $changes{'run'} = 1;
16474: }
16475: } elsif ($autorun) {
16476: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 16477: $changes{'run'} = 1;
1.1 raeburn 16478: }
16479: }
1.17 raeburn 16480: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 16481: $changes{'sender'} = 1;
16482: }
1.17 raeburn 16483: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 16484: $changes{'sender'} = 1;
16485: }
1.129 raeburn 16486: if ($currautoenroll{'co-owners'} ne '') {
16487: if ($currautoenroll{'co-owners'} ne $coowners) {
16488: $changes{'coowners'} = 1;
16489: }
16490: } elsif ($coowners) {
16491: $changes{'coowners'} = 1;
1.274 raeburn 16492: }
1.399 raeburn 16493: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.274 raeburn 16494: $changes{'autofailsafe'} = 1;
16495: }
1.399 raeburn 16496: if ($currautoenroll{'failsafe'} ne $failsafe) {
16497: $changes{'failsafe'} = 1;
16498: }
1.1 raeburn 16499: if (keys(%changes) > 0) {
16500: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 16501: if ($changes{'run'}) {
1.1 raeburn 16502: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
16503: }
16504: if ($changes{'sender'}) {
1.17 raeburn 16505: if ($sender_uname eq '' || $sender_domain eq '') {
16506: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
16507: } else {
16508: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
16509: }
1.1 raeburn 16510: }
1.129 raeburn 16511: if ($changes{'coowners'}) {
16512: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
16513: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 16514: if (ref($lastactref) eq 'HASH') {
16515: $lastactref->{'domainconfig'} = 1;
16516: }
1.129 raeburn 16517: }
1.274 raeburn 16518: if ($changes{'autofailsafe'}) {
1.399 raeburn 16519: if ($autofailsafe ne '') {
16520: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.274 raeburn 16521: } else {
1.399 raeburn 16522: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.274 raeburn 16523: }
1.399 raeburn 16524: }
16525: if ($changes{'failsafe'}) {
16526: if ($failsafe eq 'off') {
16527: unless ($changes{'autofailsafe'}) {
16528: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
16529: }
16530: } elsif ($failsafe eq 'zero') {
16531: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
16532: } else {
16533: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
16534: }
16535: }
16536: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.274 raeburn 16537: &Apache::lonnet::get_domain_defaults($dom,1);
16538: if (ref($lastactref) eq 'HASH') {
16539: $lastactref->{'domdefaults'} = 1;
16540: }
16541: }
1.1 raeburn 16542: $resulttext .= '</ul>';
16543: } else {
16544: $resulttext = &mt('No changes made to auto-enrollment settings');
16545: }
16546: } else {
1.11 albertel 16547: $resulttext = '<span class="LC_error">'.
16548: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16549: }
1.3 raeburn 16550: return $resulttext;
1.1 raeburn 16551: }
16552:
16553: sub modify_autoupdate {
1.3 raeburn 16554: my ($dom,%domconfig) = @_;
1.1 raeburn 16555: my ($resulttext,%currautoupdate,%fields,%changes);
16556: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
16557: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
16558: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
16559: }
16560: }
16561: my @offon = ('off','on');
16562: my %title = &Apache::lonlocal::texthash (
1.385 raeburn 16563: run => 'Auto-update:',
16564: classlists => 'Updates to user information in classlists?',
16565: unexpired => 'Skip updates for users without active or future roles?',
16566: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 16567: );
1.44 raeburn 16568: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 16569: my %fieldtitles = &Apache::lonlocal::texthash (
16570: id => 'Student/Employee ID',
1.20 raeburn 16571: permanentemail => 'E-mail address',
1.1 raeburn 16572: lastname => 'Last Name',
16573: firstname => 'First Name',
16574: middlename => 'Middle Name',
1.132 raeburn 16575: generation => 'Generation',
1.1 raeburn 16576: );
1.142 raeburn 16577: $othertitle = &mt('All users');
1.1 raeburn 16578: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 16579: $othertitle = &mt('Other users');
1.1 raeburn 16580: }
16581: foreach my $key (keys(%env)) {
16582: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 16583: my ($usertype,$item) = ($1,$2);
16584: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
16585: if ($usertype eq 'default') {
16586: push(@{$fields{$1}},$2);
16587: } elsif (ref($types) eq 'ARRAY') {
16588: if (grep(/^\Q$usertype\E$/,@{$types})) {
16589: push(@{$fields{$1}},$2);
16590: }
16591: }
16592: }
1.1 raeburn 16593: }
16594: }
1.131 raeburn 16595: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
16596: @lockablenames = sort(@lockablenames);
16597: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
16598: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16599: if (@changed) {
16600: $changes{'lockablenames'} = 1;
16601: }
16602: } else {
16603: if (@lockablenames) {
16604: $changes{'lockablenames'} = 1;
16605: }
16606: }
1.1 raeburn 16607: my %updatehash = (
16608: autoupdate => { run => $env{'form.autoupdate_run'},
16609: classlists => $env{'form.classlists'},
1.385 raeburn 16610: unexpired => $env{'form.unexpired'},
1.1 raeburn 16611: fields => {%fields},
1.131 raeburn 16612: lockablenames => \@lockablenames,
1.1 raeburn 16613: }
16614: );
1.385 raeburn 16615: my $lastactivedays;
16616: if ($env{'form.lastactive'}) {
16617: $lastactivedays = $env{'form.lastactivedays'};
16618: $lastactivedays =~ s/^\s+|\s+$//g;
16619: unless ($lastactivedays =~ /^\d+$/) {
16620: undef($lastactivedays);
16621: $env{'form.lastactive'} = 0;
16622: }
16623: }
16624: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 16625: foreach my $key (keys(%currautoupdate)) {
1.385 raeburn 16626: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 16627: if (exists($updatehash{autoupdate}{$key})) {
16628: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
16629: $changes{$key} = 1;
16630: }
16631: }
16632: } elsif ($key eq 'fields') {
16633: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 16634: foreach my $item (@{$types},'default') {
1.1 raeburn 16635: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
16636: my $change = 0;
16637: foreach my $type (@{$currautoupdate{$key}{$item}}) {
16638: if (!exists($fields{$item})) {
16639: $change = 1;
1.132 raeburn 16640: last;
1.1 raeburn 16641: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 16642: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 16643: $change = 1;
1.132 raeburn 16644: last;
1.1 raeburn 16645: }
16646: }
16647: }
16648: if ($change) {
16649: push(@{$changes{$key}},$item);
16650: }
1.26 raeburn 16651: }
1.1 raeburn 16652: }
16653: }
1.131 raeburn 16654: } elsif ($key eq 'lockablenames') {
16655: if (ref($currautoupdate{$key}) eq 'ARRAY') {
16656: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16657: if (@changed) {
16658: $changes{'lockablenames'} = 1;
16659: }
16660: } else {
16661: if (@lockablenames) {
16662: $changes{'lockablenames'} = 1;
16663: }
16664: }
16665: }
16666: }
16667: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
16668: if (@lockablenames) {
16669: $changes{'lockablenames'} = 1;
1.1 raeburn 16670: }
16671: }
1.385 raeburn 16672: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
16673: if ($updatehash{'autoupdate'}{'unexpired'}) {
16674: $changes{'unexpired'} = 1;
16675: }
16676: }
16677: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
16678: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
16679: $changes{'lastactive'} = 1;
16680: }
16681: }
1.26 raeburn 16682: foreach my $item (@{$types},'default') {
16683: if (defined($fields{$item})) {
16684: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 16685: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
16686: my $change = 0;
16687: if (ref($fields{$item}) eq 'ARRAY') {
16688: foreach my $type (@{$fields{$item}}) {
16689: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
16690: $change = 1;
16691: last;
16692: }
16693: }
16694: }
16695: if ($change) {
16696: push(@{$changes{'fields'}},$item);
16697: }
16698: } else {
1.26 raeburn 16699: push(@{$changes{'fields'}},$item);
16700: }
16701: } else {
16702: push(@{$changes{'fields'}},$item);
1.1 raeburn 16703: }
16704: }
16705: }
16706: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
16707: $dom);
16708: if ($putresult eq 'ok') {
16709: if (keys(%changes) > 0) {
16710: $resulttext = &mt('Changes made:').'<ul>';
16711: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 16712: if ($key eq 'lockablenames') {
16713: $resulttext .= '<li>';
16714: if (@lockablenames) {
16715: $usertypes->{'default'} = $othertitle;
16716: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
16717: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
16718: } else {
16719: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
16720: }
16721: $resulttext .= '</li>';
16722: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 16723: foreach my $item (@{$changes{$key}}) {
16724: my @newvalues;
16725: foreach my $type (@{$fields{$item}}) {
16726: push(@newvalues,$fieldtitles{$type});
16727: }
1.3 raeburn 16728: my $newvaluestr;
16729: if (@newvalues > 0) {
16730: $newvaluestr = join(', ',@newvalues);
16731: } else {
16732: $newvaluestr = &mt('none');
1.6 raeburn 16733: }
1.1 raeburn 16734: if ($item eq 'default') {
1.26 raeburn 16735: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 16736: } else {
1.26 raeburn 16737: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 16738: }
16739: }
16740: } else {
16741: my $newvalue;
16742: if ($key eq 'run') {
16743: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.385 raeburn 16744: } elsif ($key eq 'lastactive') {
16745: $newvalue = $offon[$env{'form.lastactive'}];
16746: unless ($lastactivedays eq '') {
16747: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
16748: }
1.1 raeburn 16749: } else {
16750: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 16751: }
1.1 raeburn 16752: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
16753: }
16754: }
16755: $resulttext .= '</ul>';
16756: } else {
1.3 raeburn 16757: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 16758: }
16759: } else {
1.11 albertel 16760: $resulttext = '<span class="LC_error">'.
16761: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16762: }
1.3 raeburn 16763: return $resulttext;
1.1 raeburn 16764: }
16765:
1.125 raeburn 16766: sub modify_autocreate {
16767: my ($dom,%domconfig) = @_;
16768: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
16769: if (ref($domconfig{'autocreate'}) eq 'HASH') {
16770: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
16771: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
16772: }
16773: }
16774: my %title= ( xml => 'Auto-creation of courses in XML course description files',
16775: req => 'Auto-creation of validated requests for official courses',
16776: xmldc => 'Identity of course creator of courses from XML files',
16777: );
16778: my @types = ('xml','req');
16779: foreach my $item (@types) {
16780: $newvals{$item} = $env{'form.autocreate_'.$item};
16781: $newvals{$item} =~ s/\D//g;
16782: $newvals{$item} = 0 if ($newvals{$item} eq '');
16783: }
16784: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 16785: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 16786: unless (exists($domcoords{$newvals{'xmldc'}})) {
16787: $newvals{'xmldc'} = '';
16788: }
16789: %autocreatehash = (
16790: autocreate => { xml => $newvals{'xml'},
16791: req => $newvals{'req'},
16792: }
16793: );
16794: if ($newvals{'xmldc'} ne '') {
16795: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
16796: }
16797: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
16798: $dom);
16799: if ($putresult eq 'ok') {
16800: my @items = @types;
16801: if ($newvals{'xml'}) {
16802: push(@items,'xmldc');
16803: }
16804: foreach my $item (@items) {
16805: if (exists($currautocreate{$item})) {
16806: if ($currautocreate{$item} ne $newvals{$item}) {
16807: $changes{$item} = 1;
16808: }
16809: } elsif ($newvals{$item}) {
16810: $changes{$item} = 1;
16811: }
16812: }
16813: if (keys(%changes) > 0) {
16814: my @offon = ('off','on');
16815: $resulttext = &mt('Changes made:').'<ul>';
16816: foreach my $item (@types) {
16817: if ($changes{$item}) {
16818: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 16819: $resulttext .= '<li>'.
16820: &mt("$title{$item} set to [_1]$newtxt [_2]",
16821: '<b>','</b>').
16822: '</li>';
1.125 raeburn 16823: }
16824: }
16825: if ($changes{'xmldc'}) {
16826: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
16827: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 16828: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 16829: }
16830: $resulttext .= '</ul>';
16831: } else {
16832: $resulttext = &mt('No changes made to auto-creation settings');
16833: }
16834: } else {
16835: $resulttext = '<span class="LC_error">'.
16836: &mt('An error occurred: [_1]',$putresult).'</span>';
16837: }
16838: return $resulttext;
16839: }
16840:
1.23 raeburn 16841: sub modify_directorysrch {
1.295 raeburn 16842: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 16843: my ($resulttext,%changes);
16844: my %currdirsrch;
16845: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
16846: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
16847: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
16848: }
16849: }
1.277 raeburn 16850: my %title = ( available => 'Institutional directory search available',
16851: localonly => 'Other domains can search institution',
16852: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 16853: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 16854: searchby => 'Search types',
16855: searchtypes => 'Search latitude');
16856: my @offon = ('off','on');
1.24 raeburn 16857: my @otherdoms = ('Yes','No');
1.23 raeburn 16858:
1.25 raeburn 16859: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 16860: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
16861: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
16862:
1.44 raeburn 16863: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 16864: if (keys(%{$usertypes}) == 0) {
16865: @cansearch = ('default');
16866: } else {
16867: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
16868: foreach my $type (@{$currdirsrch{'cansearch'}}) {
16869: if (!grep(/^\Q$type\E$/,@cansearch)) {
16870: push(@{$changes{'cansearch'}},$type);
16871: }
1.23 raeburn 16872: }
1.26 raeburn 16873: foreach my $type (@cansearch) {
16874: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
16875: push(@{$changes{'cansearch'}},$type);
16876: }
1.23 raeburn 16877: }
1.26 raeburn 16878: } else {
16879: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 16880: }
16881: }
16882:
16883: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
16884: foreach my $by (@{$currdirsrch{'searchby'}}) {
16885: if (!grep(/^\Q$by\E$/,@searchby)) {
16886: push(@{$changes{'searchby'}},$by);
16887: }
16888: }
16889: foreach my $by (@searchby) {
16890: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
16891: push(@{$changes{'searchby'}},$by);
16892: }
16893: }
16894: } else {
16895: push(@{$changes{'searchby'}},@searchby);
16896: }
1.25 raeburn 16897:
16898: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
16899: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
16900: if (!grep(/^\Q$type\E$/,@searchtypes)) {
16901: push(@{$changes{'searchtypes'}},$type);
16902: }
16903: }
16904: foreach my $type (@searchtypes) {
16905: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
16906: push(@{$changes{'searchtypes'}},$type);
16907: }
16908: }
16909: } else {
16910: if (exists($currdirsrch{'searchtypes'})) {
16911: foreach my $type (@searchtypes) {
16912: if ($type ne $currdirsrch{'searchtypes'}) {
16913: push(@{$changes{'searchtypes'}},$type);
16914: }
16915: }
16916: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
16917: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
16918: }
16919: } else {
16920: push(@{$changes{'searchtypes'}},@searchtypes);
16921: }
16922: }
16923:
1.23 raeburn 16924: my %dirsrch_hash = (
16925: directorysrch => { available => $env{'form.dirsrch_available'},
16926: cansearch => \@cansearch,
1.277 raeburn 16927: localonly => $env{'form.dirsrch_instlocalonly'},
16928: lclocalonly => $env{'form.dirsrch_domlocalonly'},
16929: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 16930: searchby => \@searchby,
1.25 raeburn 16931: searchtypes => \@searchtypes,
1.23 raeburn 16932: }
16933: );
16934: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
16935: $dom);
16936: if ($putresult eq 'ok') {
16937: if (exists($currdirsrch{'available'})) {
16938: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
16939: $changes{'available'} = 1;
16940: }
16941: } else {
16942: if ($env{'form.dirsrch_available'} eq '1') {
16943: $changes{'available'} = 1;
16944: }
16945: }
1.277 raeburn 16946: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 16947: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
16948: $changes{'lcavailable'} = 1;
16949: }
1.277 raeburn 16950: } else {
16951: if ($env{'form.dirsrch_lcavailable'} eq '1') {
16952: $changes{'lcavailable'} = 1;
16953: }
16954: }
1.24 raeburn 16955: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 16956: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
16957: $changes{'localonly'} = 1;
16958: }
1.24 raeburn 16959: } else {
1.277 raeburn 16960: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 16961: $changes{'localonly'} = 1;
16962: }
16963: }
1.277 raeburn 16964: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 16965: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
16966: $changes{'lclocalonly'} = 1;
16967: }
1.277 raeburn 16968: } else {
16969: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
16970: $changes{'lclocalonly'} = 1;
16971: }
16972: }
1.23 raeburn 16973: if (keys(%changes) > 0) {
16974: $resulttext = &mt('Changes made:').'<ul>';
16975: if ($changes{'available'}) {
16976: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
16977: }
1.277 raeburn 16978: if ($changes{'lcavailable'}) {
16979: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
16980: }
1.24 raeburn 16981: if ($changes{'localonly'}) {
1.277 raeburn 16982: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 16983: }
1.277 raeburn 16984: if ($changes{'lclocalonly'}) {
16985: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 16986: }
1.23 raeburn 16987: if (ref($changes{'cansearch'}) eq 'ARRAY') {
16988: my $chgtext;
1.26 raeburn 16989: if (ref($usertypes) eq 'HASH') {
16990: if (keys(%{$usertypes}) > 0) {
16991: foreach my $type (@{$types}) {
16992: if (grep(/^\Q$type\E$/,@cansearch)) {
16993: $chgtext .= $usertypes->{$type}.'; ';
16994: }
16995: }
16996: if (grep(/^default$/,@cansearch)) {
16997: $chgtext .= $othertitle;
16998: } else {
16999: $chgtext =~ s/\; $//;
17000: }
1.210 raeburn 17001: $resulttext .=
1.178 raeburn 17002: '<li>'.
17003: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
17004: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
17005: '</li>';
1.23 raeburn 17006: }
17007: }
17008: }
17009: if (ref($changes{'searchby'}) eq 'ARRAY') {
17010: my ($searchtitles,$titleorder) = &sorted_searchtitles();
17011: my $chgtext;
17012: foreach my $type (@{$titleorder}) {
17013: if (grep(/^\Q$type\E$/,@searchby)) {
17014: if (defined($searchtitles->{$type})) {
17015: $chgtext .= $searchtitles->{$type}.'; ';
17016: }
17017: }
17018: }
17019: $chgtext =~ s/\; $//;
17020: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
17021: }
1.25 raeburn 17022: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
17023: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
17024: my $chgtext;
17025: foreach my $type (@{$srchtypeorder}) {
17026: if (grep(/^\Q$type\E$/,@searchtypes)) {
17027: if (defined($srchtypes_desc->{$type})) {
17028: $chgtext .= $srchtypes_desc->{$type}.'; ';
17029: }
17030: }
17031: }
17032: $chgtext =~ s/\; $//;
1.178 raeburn 17033: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 17034: }
17035: $resulttext .= '</ul>';
1.295 raeburn 17036: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
17037: if (ref($lastactref) eq 'HASH') {
17038: $lastactref->{'directorysrch'} = 1;
17039: }
1.23 raeburn 17040: } else {
1.277 raeburn 17041: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 17042: }
17043: } else {
17044: $resulttext = '<span class="LC_error">'.
1.27 raeburn 17045: &mt('An error occurred: [_1]',$putresult).'</span>';
17046: }
17047: return $resulttext;
17048: }
17049:
1.28 raeburn 17050: sub modify_contacts {
1.205 raeburn 17051: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 17052: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
17053: if (ref($domconfig{'contacts'}) eq 'HASH') {
17054: foreach my $key (keys(%{$domconfig{'contacts'}})) {
17055: $currsetting{$key} = $domconfig{'contacts'}{$key};
17056: }
17057: }
1.286 raeburn 17058: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 17059: my @contacts = ('supportemail','adminemail');
1.286 raeburn 17060: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350 raeburn 17061: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340 raeburn 17062: my @toggles = ('reporterrors','reportupdates','reportstatus');
17063: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 17064: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 17065: foreach my $type (@mailings) {
17066: @{$newsetting{$type}} =
17067: &Apache::loncommon::get_env_multiple('form.'.$type);
17068: foreach my $item (@contacts) {
17069: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
17070: $contacts_hash{contacts}{$type}{$item} = 1;
17071: } else {
17072: $contacts_hash{contacts}{$type}{$item} = 0;
17073: }
1.289 raeburn 17074: }
1.28 raeburn 17075: $others{$type} = $env{'form.'.$type.'_others'};
17076: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 17077: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17078: $bcc{$type} = $env{'form.'.$type.'_bcc'};
17079: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 17080: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
17081: $includestr{$type} = $env{'form.'.$type.'_includestr'};
17082: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
17083: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17084: }
1.134 raeburn 17085: }
1.28 raeburn 17086: }
17087: foreach my $item (@contacts) {
17088: $to{$item} = $env{'form.'.$item};
17089: $contacts_hash{'contacts'}{$item} = $to{$item};
17090: }
1.203 raeburn 17091: foreach my $item (@toggles) {
17092: if ($env{'form.'.$item} =~ /^(0|1)$/) {
17093: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
17094: }
17095: }
1.340 raeburn 17096: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
17097: foreach my $item (@lonstatus) {
17098: if ($item eq 'excluded') {
17099: my (%serverhomes,@excluded);
17100: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
17101: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
17102: if (@possexcluded) {
17103: foreach my $id (sort(@possexcluded)) {
17104: if ($serverhomes{$id}) {
17105: push(@excluded,$id);
17106: }
17107: }
17108: }
17109: if (@excluded) {
17110: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
17111: }
17112: } elsif ($item eq 'weights') {
1.377 raeburn 17113: foreach my $type ('E','W','N','U') {
1.340 raeburn 17114: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
17115: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
17116: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
17117: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
17118: $env{'form.error'.$item.'_'.$type};
17119: }
17120: }
17121: }
17122: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
17123: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
17124: if ($env{'form.error'.$item} =~ /^\d+$/) {
17125: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
17126: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
17127: }
17128: }
17129: }
17130: }
1.286 raeburn 17131: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
17132: foreach my $field (@{$fields}) {
17133: if (ref($possoptions->{$field}) eq 'ARRAY') {
17134: my $value = $env{'form.helpform_'.$field};
17135: $value =~ s/^\s+|\s+$//g;
17136: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 17137: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 17138: if ($field eq 'screenshot') {
17139: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
17140: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 17141: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 17142: }
17143: }
17144: }
17145: }
17146: }
17147: }
1.315 raeburn 17148: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17149: my (@statuses,%usertypeshash,@overrides);
17150: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
17151: @statuses = @{$types};
17152: if (ref($usertypes) eq 'HASH') {
17153: %usertypeshash = %{$usertypes};
17154: }
17155: }
17156: if (@statuses) {
17157: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
17158: foreach my $type (@possoverrides) {
17159: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
17160: push(@overrides,$type);
17161: }
17162: }
17163: if (@overrides) {
17164: foreach my $type (@overrides) {
17165: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
17166: foreach my $item (@contacts) {
17167: if (grep(/^\Q$item\E$/,@standard)) {
17168: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
17169: $newsetting{'override_'.$type}{$item} = 1;
17170: } else {
17171: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
17172: $newsetting{'override_'.$type}{$item} = 0;
17173: }
17174: }
17175: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
17176: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17177: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
17178: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17179: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
17180: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
17181: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
17182: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17183: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
17184: }
1.425 raeburn 17185: }
1.315 raeburn 17186: }
17187: }
1.28 raeburn 17188: if (keys(%currsetting) > 0) {
17189: foreach my $item (@contacts) {
17190: if ($to{$item} ne $currsetting{$item}) {
17191: $changes{$item} = 1;
17192: }
17193: }
17194: foreach my $type (@mailings) {
17195: foreach my $item (@contacts) {
17196: if (ref($currsetting{$type}) eq 'HASH') {
17197: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
17198: push(@{$changes{$type}},$item);
17199: }
17200: } else {
17201: push(@{$changes{$type}},@{$newsetting{$type}});
17202: }
17203: }
17204: if ($others{$type} ne $currsetting{$type}{'others'}) {
17205: push(@{$changes{$type}},'others');
17206: }
1.289 raeburn 17207: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17208: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
17209: push(@{$changes{$type}},'bcc');
17210: }
1.286 raeburn 17211: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
17212: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
17213: push(@{$changes{$type}},'include');
17214: }
17215: }
17216: }
17217: if (ref($fields) eq 'ARRAY') {
17218: if (ref($currsetting{'helpform'}) eq 'HASH') {
17219: foreach my $field (@{$fields}) {
17220: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
17221: push(@{$changes{'helpform'}},$field);
17222: }
17223: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17224: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
17225: push(@{$changes{'helpform'}},'maxsize');
17226: }
17227: }
17228: }
17229: } else {
17230: foreach my $field (@{$fields}) {
17231: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17232: push(@{$changes{'helpform'}},$field);
17233: }
17234: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17235: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17236: push(@{$changes{'helpform'}},'maxsize');
17237: }
17238: }
17239: }
1.134 raeburn 17240: }
1.28 raeburn 17241: }
1.315 raeburn 17242: if (@statuses) {
1.425 raeburn 17243: if (ref($currsetting{'overrides'}) eq 'HASH') {
1.315 raeburn 17244: foreach my $key (keys(%{$currsetting{'overrides'}})) {
17245: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
17246: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
17247: foreach my $item (@contacts,'bcc','others','include') {
1.425 raeburn 17248: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
1.315 raeburn 17249: push(@{$changes{'overrides'}},$key);
17250: last;
17251: }
17252: }
17253: } else {
17254: push(@{$changes{'overrides'}},$key);
17255: }
17256: }
17257: }
17258: foreach my $key (@overrides) {
17259: unless (exists($currsetting{'overrides'}{$key})) {
17260: push(@{$changes{'overrides'}},$key);
17261: }
17262: }
17263: } else {
17264: foreach my $key (@overrides) {
1.425 raeburn 17265: push(@{$changes{'overrides'}},$key);
1.315 raeburn 17266: }
17267: }
17268: }
1.340 raeburn 17269: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
17270: foreach my $key ('excluded','weights','threshold','sysmail') {
17271: if ($key eq 'excluded') {
17272: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17273: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
17274: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17275: (@{$currsetting{'lonstatus'}{$key}})) {
17276: my @diffs =
17277: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
17278: $currsetting{'lonstatus'}{$key});
17279: if (@diffs) {
17280: push(@{$changes{'lonstatus'}},$key);
17281: }
17282: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
17283: push(@{$changes{'lonstatus'}},$key);
17284: }
17285: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17286: (@{$currsetting{'lonstatus'}{$key}})) {
17287: push(@{$changes{'lonstatus'}},$key);
17288: }
17289: } elsif ($key eq 'weights') {
17290: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17291: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
17292: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17293: foreach my $type ('E','W','N','U') {
1.340 raeburn 17294: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
17295: $currsetting{'lonstatus'}{$key}{$type}) {
17296: push(@{$changes{'lonstatus'}},$key);
17297: last;
17298: }
17299: }
17300: } else {
1.341 raeburn 17301: foreach my $type ('E','W','N','U') {
1.340 raeburn 17302: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
17303: push(@{$changes{'lonstatus'}},$key);
17304: last;
17305: }
17306: }
17307: }
17308: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17309: foreach my $type ('E','W','N','U') {
1.340 raeburn 17310: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
17311: push(@{$changes{'lonstatus'}},$key);
17312: last;
17313: }
17314: }
17315: }
17316: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
17317: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17318: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17319: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
17320: push(@{$changes{'lonstatus'}},$key);
17321: }
17322: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
17323: push(@{$changes{'lonstatus'}},$key);
17324: }
17325: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17326: push(@{$changes{'lonstatus'}},$key);
17327: }
17328: }
17329: }
17330: } else {
17331: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17332: foreach my $key ('excluded','weights','threshold','sysmail') {
17333: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17334: push(@{$changes{'lonstatus'}},$key);
17335: }
17336: }
17337: }
17338: }
1.28 raeburn 17339: } else {
17340: my %default;
17341: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
17342: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
17343: $default{'errormail'} = 'adminemail';
17344: $default{'packagesmail'} = 'adminemail';
17345: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 17346: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 17347: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 17348: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 17349: $default{'updatesmail'} = 'adminemail';
1.350 raeburn 17350: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 17351: foreach my $item (@contacts) {
17352: if ($to{$item} ne $default{$item}) {
1.286 raeburn 17353: $changes{$item} = 1;
1.203 raeburn 17354: }
1.28 raeburn 17355: }
17356: foreach my $type (@mailings) {
17357: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
17358: push(@{$changes{$type}},@{$newsetting{$type}});
17359: }
17360: if ($others{$type} ne '') {
17361: push(@{$changes{$type}},'others');
1.134 raeburn 17362: }
1.286 raeburn 17363: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17364: if ($bcc{$type} ne '') {
17365: push(@{$changes{$type}},'bcc');
17366: }
1.286 raeburn 17367: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
17368: push(@{$changes{$type}},'include');
17369: }
1.134 raeburn 17370: }
1.28 raeburn 17371: }
1.286 raeburn 17372: if (ref($fields) eq 'ARRAY') {
17373: foreach my $field (@{$fields}) {
17374: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17375: push(@{$changes{'helpform'}},$field);
17376: }
17377: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17378: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17379: push(@{$changes{'helpform'}},'maxsize');
17380: }
17381: }
17382: }
1.289 raeburn 17383: }
1.340 raeburn 17384: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17385: foreach my $key ('excluded','weights','threshold','sysmail') {
17386: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17387: push(@{$changes{'lonstatus'}},$key);
17388: }
17389: }
17390: }
1.28 raeburn 17391: }
1.203 raeburn 17392: foreach my $item (@toggles) {
17393: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
17394: $changes{$item} = 1;
17395: } elsif ((!$env{'form.'.$item}) &&
17396: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
17397: $changes{$item} = 1;
17398: }
17399: }
1.28 raeburn 17400: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
17401: $dom);
17402: if ($putresult eq 'ok') {
17403: if (keys(%changes) > 0) {
1.205 raeburn 17404: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 17405: if (ref($lastactref) eq 'HASH') {
17406: $lastactref->{'domainconfig'} = 1;
17407: }
1.28 raeburn 17408: my ($titles,$short_titles) = &contact_titles();
17409: $resulttext = &mt('Changes made:').'<ul>';
17410: foreach my $item (@contacts) {
17411: if ($changes{$item}) {
17412: $resulttext .= '<li>'.$titles->{$item}.
17413: &mt(' set to: ').
17414: '<span class="LC_cusr_emph">'.
17415: $to{$item}.'</span></li>';
17416: }
17417: }
17418: foreach my $type (@mailings) {
17419: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 17420: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 17421: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 17422: } else {
17423: $resulttext .= '<li>'.$titles->{$type}.': ';
17424: }
1.28 raeburn 17425: my @text;
17426: foreach my $item (@{$newsetting{$type}}) {
17427: push(@text,$short_titles->{$item});
17428: }
17429: if ($others{$type} ne '') {
17430: push(@text,$others{$type});
17431: }
1.286 raeburn 17432: if (@text) {
17433: $resulttext .= '<span class="LC_cusr_emph">'.
17434: join(', ',@text).'</span>';
17435: }
17436: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17437: if ($bcc{$type} ne '') {
1.286 raeburn 17438: my $bcctext;
17439: if (@text) {
1.289 raeburn 17440: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 17441: } else {
17442: $bcctext = '(Bcc)';
17443: }
17444: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
17445: } elsif (!@text) {
17446: $resulttext .= &mt('No one');
1.425 raeburn 17447: }
1.289 raeburn 17448: if ($includestr{$type} ne '') {
1.286 raeburn 17449: if ($includeloc{$type} eq 'b') {
17450: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
17451: } elsif ($includeloc{$type} eq 's') {
17452: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
17453: }
1.134 raeburn 17454: }
1.286 raeburn 17455: } elsif (!@text) {
17456: $resulttext .= &mt('No recipients');
1.134 raeburn 17457: }
17458: $resulttext .= '</li>';
1.28 raeburn 17459: }
17460: }
1.315 raeburn 17461: if (ref($changes{'overrides'}) eq 'ARRAY') {
17462: my @deletions;
17463: foreach my $type (@{$changes{'overrides'}}) {
17464: if ($usertypeshash{$type}) {
17465: if (grep(/^\Q$type\E/,@overrides)) {
17466: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
17467: $usertypeshash{$type}).'<ul><li>';
17468: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
17469: my @text;
17470: foreach my $item (@contacts) {
1.425 raeburn 17471: if ($newsetting{'override_'.$type}{$item}) {
1.315 raeburn 17472: push(@text,$short_titles->{$item});
17473: }
17474: }
17475: if ($newsetting{'override_'.$type}{'others'} ne '') {
17476: push(@text,$newsetting{'override_'.$type}{'others'});
17477: }
1.425 raeburn 17478:
1.315 raeburn 17479: if (@text) {
17480: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
17481: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
17482: }
17483: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
17484: my $bcctext;
17485: if (@text) {
17486: $bcctext = ' '.&mt('with Bcc to');
17487: } else {
17488: $bcctext = '(Bcc)';
17489: }
17490: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
17491: } elsif (!@text) {
17492: $resulttext .= &mt('Helpdesk e-mail sent to no one');
17493: }
17494: $resulttext .= '</li>';
17495: if ($newsetting{'override_'.$type}{'include'} ne '') {
17496: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
17497: if ($loc eq 'b') {
17498: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
17499: } elsif ($loc eq 's') {
17500: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
17501: }
17502: }
17503: }
17504: $resulttext .= '</li></ul></li>';
17505: } else {
17506: push(@deletions,$usertypeshash{$type});
17507: }
17508: }
17509: }
17510: if (@deletions) {
17511: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
17512: join(', ',@deletions)).'</li>';
17513: }
17514: }
1.203 raeburn 17515: my @offon = ('off','on');
1.340 raeburn 17516: my $corelink = &core_link_msu();
1.203 raeburn 17517: if ($changes{'reporterrors'}) {
17518: $resulttext .= '<li>'.
17519: &mt('E-mail error reports to [_1] set to "'.
17520: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 17521: $corelink).
1.203 raeburn 17522: '</li>';
17523: }
17524: if ($changes{'reportupdates'}) {
17525: $resulttext .= '<li>'.
17526: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
17527: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 17528: $corelink).
1.203 raeburn 17529: '</li>';
17530: }
1.340 raeburn 17531: if ($changes{'reportstatus'}) {
17532: $resulttext .= '<li>'.
17533: &mt('E-mail status if errors above threshold to [_1] set to "'.
17534: $offon[$env{'form.reportstatus'}].'".',
17535: $corelink).
17536: '</li>';
17537: }
17538: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
17539: $resulttext .= '<li>'.
17540: &mt('Nightly status check e-mail settings').':<ul>';
17541: my (%defval,%use_def,%shown);
17542: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
17543: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
17544: $defval{'weights'} =
1.341 raeburn 17545: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 17546: $defval{'excluded'} = &mt('None');
17547: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
17548: foreach my $item ('threshold','sysmail','weights','excluded') {
17549: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
17550: if (($item eq 'threshold') || ($item eq 'sysmail')) {
17551: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
17552: } elsif ($item eq 'weights') {
17553: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 17554: foreach my $type ('E','W','N','U') {
1.340 raeburn 17555: $shown{$item} .= $lonstatus_names->{$type}.'=';
17556: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
17557: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
17558: } else {
17559: $shown{$item} .= $lonstatus_defs->{$type};
17560: }
17561: $shown{$item} .= ', ';
17562: }
17563: $shown{$item} =~ s/, $//;
17564: } else {
17565: $shown{$item} = $defval{$item};
17566: }
17567: } elsif ($item eq 'excluded') {
17568: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
17569: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
17570: } else {
17571: $shown{$item} = $defval{$item};
17572: }
17573: }
17574: } else {
17575: $shown{$item} = $defval{$item};
17576: }
17577: }
17578: } else {
17579: foreach my $item ('threshold','weights','excluded','sysmail') {
17580: $shown{$item} = $defval{$item};
17581: }
17582: }
17583: foreach my $item ('threshold','weights','excluded','sysmail') {
17584: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
17585: $shown{$item}).'</li>';
17586: }
17587: $resulttext .= '</ul></li>';
17588: }
1.286 raeburn 17589: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
17590: my (@optional,@required,@unused,$maxsizechg);
17591: foreach my $field (@{$changes{'helpform'}}) {
17592: if ($field eq 'maxsize') {
17593: $maxsizechg = 1;
17594: next;
17595: }
17596: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 17597: push(@optional,$field);
1.286 raeburn 17598: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
17599: push(@unused,$field);
17600: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 17601: push(@required,$field);
1.286 raeburn 17602: }
17603: }
17604: if (@optional) {
17605: $resulttext .= '<li>'.
17606: &mt('Help form fields changed to "Optional": [_1].',
17607: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
17608: '</li>';
17609: }
17610: if (@required) {
17611: $resulttext .= '<li>'.
17612: &mt('Help form fields changed to "Required": [_1].',
17613: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
17614: '</li>';
17615: }
17616: if (@unused) {
17617: $resulttext .= '<li>'.
17618: &mt('Help form fields changed to "Not shown": [_1].',
17619: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
17620: '</li>';
17621: }
17622: if ($maxsizechg) {
17623: $resulttext .= '<li>'.
17624: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
17625: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
17626: '</li>';
17627: }
17628: }
1.28 raeburn 17629: $resulttext .= '</ul>';
17630: } else {
1.288 raeburn 17631: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 17632: }
17633: } else {
17634: $resulttext = '<span class="LC_error">'.
17635: &mt('An error occurred: [_1].',$putresult).'</span>';
17636: }
17637: return $resulttext;
17638: }
17639:
1.357 raeburn 17640: sub modify_privacy {
1.427 raeburn 17641: my ($dom,$lastactref,%domconfig) = @_;
1.357 raeburn 17642: my ($resulttext,%current,%changes);
17643: if (ref($domconfig{'privacy'}) eq 'HASH') {
17644: %current = %{$domconfig{'privacy'}};
17645: }
17646: my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
17647: my @items = ('domain','author','course','community');
17648: my %names = &Apache::lonlocal::texthash (
17649: domain => 'Assigned domain role(s)',
17650: author => 'Assigned co-author role(s)',
17651: course => 'Assigned course role(s)',
1.416 raeburn 17652: community => 'Assigned community role(s)',
1.357 raeburn 17653: );
17654: my %roles = &Apache::lonlocal::texthash (
17655: domain => 'Domain role',
17656: author => 'Co-author role',
17657: course => 'Course role',
17658: community => 'Community role',
17659: );
17660: my %titles = &Apache::lonlocal::texthash (
17661: approval => 'Approval for role in different domain',
17662: othdom => 'User information available in other domain',
17663: priv => 'Information viewable by privileged user in same domain',
17664: unpriv => 'Information viewable by unprivileged user in same domain',
17665: instdom => 'Other domain shares institution/provider',
17666: extdom => 'Other domain has different institution/provider',
17667: none => 'Not allowed',
17668: user => 'User authorizes',
17669: domain => 'Domain Coordinator authorizes',
17670: auto => 'Unrestricted',
1.418 raeburn 17671: notify => 'Notify when role needs authorization',
1.357 raeburn 17672: );
17673: my %fieldnames = &Apache::lonlocal::texthash (
17674: id => 'Student/Employee ID',
17675: permanentemail => 'E-mail address',
17676: lastname => 'Last Name',
17677: firstname => 'First Name',
17678: middlename => 'Middle Name',
17679: generation => 'Generation',
17680: );
17681: my ($othertitle,$usertypes,$types) =
17682: &Apache::loncommon::sorted_inst_types($dom);
17683: my (%by_ip,%by_location,@intdoms,@instdoms);
17684: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
17685:
17686: my %privacyhash = (
17687: 'approval' => {
17688: instdom => {},
17689: extdom => {},
17690: },
17691: 'othdom' => {},
17692: 'priv' => {},
17693: 'unpriv' => {},
17694: );
17695: foreach my $item (@items) {
17696: if (@instdoms > 1) {
1.416 raeburn 17697: if ($env{'form.privacy_approval_instdom_'.$item} =~ /^(none|user|domain|auto)$/) {
1.357 raeburn 17698: $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
17699: }
17700: if (ref($current{'approval'}) eq 'HASH') {
17701: if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
17702: unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
17703: $changes{'approval'} = 1;
17704: }
17705: }
17706: } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
17707: $changes{'approval'} = 1;
17708: }
17709: }
17710: if (keys(%by_location) > 0) {
17711: if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
17712: $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
17713: }
17714: if (ref($current{'approval'}) eq 'HASH') {
17715: if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
17716: unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
17717: $changes{'approval'} = 1;
17718: }
17719: }
17720: } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
17721: $changes{'approval'} = 1;
17722: }
17723: }
17724: foreach my $status ('priv','unpriv') {
17725: my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
17726: my @newvalues;
17727: foreach my $field (@possibles) {
17728: if (grep(/^\Q$field\E$/,@fields)) {
17729: $privacyhash{$status}{$item}{$field} = 1;
17730: push(@newvalues,$field);
17731: }
17732: }
17733: @newvalues = sort(@newvalues);
17734: if (ref($current{$status}) eq 'HASH') {
17735: if (ref($current{$status}{$item}) eq 'HASH') {
17736: my @currvalues = sort(keys(%{$current{$status}{$item}}));
17737: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
17738: if (@diffs > 0) {
17739: $changes{$status} = 1;
17740: }
17741: }
17742: } else {
17743: my @stdfields;
17744: foreach my $field (@fields) {
17745: if ($field eq 'id') {
17746: next if ($status eq 'unpriv');
17747: next if (($status eq 'priv') && ($item eq 'community'));
17748: }
17749: push(@stdfields,$field);
17750: }
17751: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
17752: if (@diffs > 0) {
17753: $changes{$status} = 1;
17754: }
17755: }
17756: }
17757: }
17758: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
17759: my @statuses;
17760: if (ref($types) eq 'ARRAY') {
17761: @statuses = @{$types};
17762: }
17763: foreach my $type (@statuses,'default') {
17764: my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
17765: my @newvalues;
17766: foreach my $field (sort(@possfields)) {
17767: if (grep(/^\Q$field\E$/,@fields)) {
17768: $privacyhash{'othdom'}{$type}{$field} = 1;
17769: push(@newvalues,$field);
17770: }
17771: }
17772: @newvalues = sort(@newvalues);
17773: if (ref($current{'othdom'}) eq 'HASH') {
17774: if (ref($current{'othdom'}{$type}) eq 'HASH') {
17775: my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
17776: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
17777: if (@diffs > 0) {
17778: $changes{'othdom'} = 1;
17779: }
17780: }
17781: } else {
17782: my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
17783: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
17784: if (@diffs > 0) {
17785: $changes{'othdom'} = 1;
17786: }
17787: }
17788: }
1.417 raeburn 17789: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
17790: my %notify;
17791: foreach my $possdc (&Apache::loncommon::get_env_multiple('form.privacy_notify')) {
17792: if (exists($domcoords{$possdc})) {
17793: $notify{$possdc} = 1;
17794: }
17795: }
17796: my $notify = join(',',sort(keys(%notify)));
17797: if ($current{'notify'} ne $notify) {
17798: $changes{'notify'} = 1;
17799: }
17800: $privacyhash{'notify'} = $notify;
1.357 raeburn 17801: }
17802: my %confighash = (
17803: privacy => \%privacyhash,
17804: );
17805: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
17806: if ($putresult eq 'ok') {
17807: if (keys(%changes) > 0) {
17808: $resulttext = &mt('Changes made: ').'<ul>';
1.417 raeburn 17809: foreach my $key ('approval','notify','othdom','priv','unpriv') {
1.357 raeburn 17810: if ($changes{$key}) {
17811: $resulttext .= '<li>'.$titles{$key}.':<ul>';
17812: if ($key eq 'approval') {
17813: if (keys(%{$privacyhash{$key}{instdom}})) {
17814: $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
17815: foreach my $item (@items) {
17816: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
17817: }
17818: $resulttext .= '</ul></li>';
17819: }
17820: if (keys(%{$privacyhash{$key}{extdom}})) {
17821: $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
17822: foreach my $item (@items) {
17823: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
17824: }
17825: $resulttext .= '</ul></li>';
17826: }
1.417 raeburn 17827: } elsif ($key eq 'notify') {
17828: if ($privacyhash{$key}) {
17829: foreach my $dc (split(/,/,$privacyhash{$key})) {
17830: my ($dcname,$dcdom) = split(/:/,$dc);
17831: $resulttext .= '<li>'.&Apache::loncommon::plainname($dcname,$dcdom).'</li>';
17832: }
17833: } else {
17834: $resulttext .= '<li>'.&mt('No DCs to notify').'</li>';
17835: }
1.357 raeburn 17836: } elsif ($key eq 'othdom') {
17837: my @statuses;
17838: if (ref($types) eq 'ARRAY') {
17839: @statuses = @{$types};
17840: }
17841: if (ref($privacyhash{$key}) eq 'HASH') {
17842: foreach my $status (@statuses,'default') {
17843: if ($status eq 'default') {
17844: $resulttext .= '<li>'.$othertitle.': ';
17845: } elsif (ref($usertypes) eq 'HASH') {
17846: $resulttext .= '<li>'.$usertypes->{$status}.': ';
17847: } else {
17848: next;
17849: }
17850: if (ref($privacyhash{$key}{$status}) eq 'HASH') {
17851: if (keys(%{$privacyhash{$key}{$status}})) {
17852: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
17853: } else {
17854: $resulttext .= &mt('none');
17855: }
17856: }
17857: $resulttext .= '</li>';
17858: }
17859: }
17860: } else {
17861: foreach my $item (@items) {
17862: if (ref($privacyhash{$key}{$item}) eq 'HASH') {
17863: $resulttext .= '<li>'.$names{$item}.': ';
17864: if (keys(%{$privacyhash{$key}{$item}})) {
17865: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
17866: } else {
17867: $resulttext .= &mt('none');
17868: }
17869: $resulttext .= '</li>';
17870: }
17871: }
17872: }
17873: $resulttext .= '</ul></li>';
17874: }
17875: }
1.421 raeburn 17876: $resulttext .= '</ul>';
1.427 raeburn 17877: if ($changes{'approval'}) {
17878: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
17879: delete($domdefaults{'userapprovals'});
17880: if (ref($privacyhash{'approval'}) eq 'HASH') {
17881: foreach my $domtype ('instdom','extdom') {
17882: if (ref($privacyhash{'approval'}{$domtype}) eq 'HASH') {
17883: foreach my $roletype ('domain','author','course','community') {
17884: if ($privacyhash{'approval'}{$domtype}{$roletype} eq 'user') {
17885: $domdefaults{'userapprovals'} = 1;
17886: last;
17887: }
17888: }
17889: }
17890: last if ($domdefaults{'userapprovals'});
17891: }
17892: }
17893: my $cachetime = 24*60*60;
17894: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17895: if (ref($lastactref) eq 'HASH') {
17896: $lastactref->{'domdefaults'} = 1;
17897: }
17898: }
1.357 raeburn 17899: } else {
17900: $resulttext = &mt('No changes made to user information settings');
17901: }
17902: } else {
17903: $resulttext = '<span class="LC_error">'.
17904: &mt('An error occurred: [_1]',$putresult).'</span>';
17905: }
17906: return $resulttext;
17907: }
17908:
1.354 raeburn 17909: sub modify_passwords {
17910: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 raeburn 17911: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
17912: $updatedefaults,$updateconf);
1.354 raeburn 17913: my $customfn = 'resetpw.html';
17914: if (ref($domconfig{'passwords'}) eq 'HASH') {
17915: %current = %{$domconfig{'passwords'}};
17916: }
17917: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
17918: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17919: if (ref($types) eq 'ARRAY') {
17920: @oktypes = @{$types};
17921: }
17922: push(@oktypes,'default');
17923:
17924: my %titles = &Apache::lonlocal::texthash (
17925: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
17926: intauth_check => 'Check bcrypt cost if authenticated',
17927: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
17928: permanent => 'Permanent e-mail address',
17929: critical => 'Critical notification address',
17930: notify => 'Notification address',
17931: min => 'Minimum password length',
17932: max => 'Maximum password length',
17933: chars => 'Required characters',
17934: expire => 'Password expiration (days)',
1.356 raeburn 17935: numsaved => 'Number of previous passwords to save',
1.354 raeburn 17936: reset => 'Resetting Forgotten Password',
17937: intauth => 'Encryption of Stored Passwords (Internal Auth)',
17938: rules => 'Rules for LON-CAPA Passwords',
17939: crsownerchg => 'Course Owner Changing Student Passwords',
17940: username => 'Username',
17941: email => 'E-mail address',
17942: );
17943:
17944: #
17945: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
17946: #
17947: my (%curr_defaults,%save_defaults);
17948: if (ref($domconfig{'defaults'}) eq 'HASH') {
17949: foreach my $key (keys(%{$domconfig{'defaults'}})) {
17950: if ($key =~ /^intauth_(cost|check|switch)$/) {
17951: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
17952: } else {
17953: $save_defaults{$key} = $domconfig{'defaults'}{$key};
17954: }
17955: }
17956: }
17957: my %staticdefaults = (
17958: 'resetlink' => 2,
17959: 'resetcase' => \@oktypes,
17960: 'resetprelink' => 'both',
17961: 'resetemail' => ['critical','notify','permanent'],
17962: 'intauth_cost' => 10,
17963: 'intauth_check' => 0,
17964: 'intauth_switch' => 0,
17965: );
1.365 raeburn 17966: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354 raeburn 17967: foreach my $type (@oktypes) {
17968: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
17969: }
17970: my $linklife = $env{'form.passwords_link'};
17971: $linklife =~ s/^\s+|\s+$//g;
17972: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
17973: $newvalues{'resetlink'} = $linklife;
17974: if ($current{'resetlink'}) {
17975: if ($current{'resetlink'} ne $linklife) {
17976: $changes{'reset'} = 1;
17977: }
1.368 raeburn 17978: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 17979: if ($staticdefaults{'resetlink'} ne $linklife) {
17980: $changes{'reset'} = 1;
17981: }
17982: }
17983: } elsif ($current{'resetlink'}) {
17984: $changes{'reset'} = 1;
17985: }
17986: my @casesens;
17987: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
17988: foreach my $case (sort(@posscase)) {
17989: if (grep(/^\Q$case\E$/,@oktypes)) {
17990: push(@casesens,$case);
17991: }
17992: }
17993: $newvalues{'resetcase'} = \@casesens;
17994: if (ref($current{'resetcase'}) eq 'ARRAY') {
17995: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
17996: if (@diffs > 0) {
17997: $changes{'reset'} = 1;
17998: }
1.368 raeburn 17999: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18000: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
18001: if (@diffs > 0) {
18002: $changes{'reset'} = 1;
18003: }
18004: }
18005: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
18006: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
18007: if (exists($current{'resetprelink'})) {
18008: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
18009: $changes{'reset'} = 1;
18010: }
1.368 raeburn 18011: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18012: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
18013: $changes{'reset'} = 1;
18014: }
18015: }
18016: } elsif ($current{'resetprelink'}) {
18017: $changes{'reset'} = 1;
18018: }
18019: foreach my $type (@oktypes) {
18020: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
18021: my @postlink;
18022: foreach my $item (sort(@possplink)) {
18023: if ($item =~ /^(email|username)$/) {
18024: push(@postlink,$item);
18025: }
18026: }
18027: $newvalues{'resetpostlink'}{$type} = \@postlink;
18028: unless ($changes{'reset'}) {
18029: if (ref($current{'resetpostlink'}) eq 'HASH') {
18030: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
18031: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
18032: if (@diffs > 0) {
18033: $changes{'reset'} = 1;
18034: }
18035: } else {
18036: $changes{'reset'} = 1;
18037: }
1.368 raeburn 18038: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18039: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
18040: if (@diffs > 0) {
18041: $changes{'reset'} = 1;
18042: }
18043: }
18044: }
18045: }
18046: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
18047: my @resetemail;
18048: foreach my $item (sort(@possemailsrc)) {
18049: if ($item =~ /^(permanent|critical|notify)$/) {
18050: push(@resetemail,$item);
18051: }
18052: }
18053: $newvalues{'resetemail'} = \@resetemail;
18054: unless ($changes{'reset'}) {
18055: if (ref($current{'resetemail'}) eq 'ARRAY') {
18056: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
18057: if (@diffs > 0) {
18058: $changes{'reset'} = 1;
18059: }
1.368 raeburn 18060: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18061: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
18062: if (@diffs > 0) {
18063: $changes{'reset'} = 1;
18064: }
18065: }
18066: }
18067: if ($env{'form.passwords_stdtext'} == 0) {
18068: $newvalues{'resetremove'} = 1;
18069: unless ($current{'resetremove'}) {
18070: $changes{'reset'} = 1;
18071: }
18072: } elsif ($current{'resetremove'}) {
18073: $changes{'reset'} = 1;
18074: }
18075: if ($env{'form.passwords_customfile.filename'} ne '') {
18076: my $servadm = $r->dir_config('lonAdmEMail');
18077: my ($configuserok,$author_ok,$switchserver) =
18078: &config_check($dom,$confname,$servadm);
18079: my $error;
18080: if ($configuserok eq 'ok') {
18081: if ($switchserver) {
18082: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
18083: } else {
18084: if ($author_ok eq 'ok') {
1.421 raeburn 18085: my $modified = [];
1.354 raeburn 18086: my ($result,$customurl) =
1.421 raeburn 18087: &Apache::lonconfigsettings::publishlogo($r,'upload','passwords_customfile',$dom,
18088: $confname,'customtext/resetpw','','',$customfn,
18089: $modified);
1.354 raeburn 18090: if ($result eq 'ok') {
18091: $newvalues{'resetcustom'} = $customurl;
18092: $changes{'reset'} = 1;
1.421 raeburn 18093: &update_modify_urls($r,$modified);
1.354 raeburn 18094: } else {
18095: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
18096: }
18097: } else {
18098: $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);
18099: }
18100: }
18101: } else {
18102: $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);
18103: }
18104: if ($error) {
18105: &Apache::lonnet::logthis($error);
18106: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
18107: }
18108: } elsif ($current{'resetcustom'}) {
18109: if ($env{'form.passwords_custom_del'}) {
18110: $changes{'reset'} = 1;
18111: } else {
18112: $newvalues{'resetcustom'} = $current{'resetcustom'};
18113: }
18114: }
18115: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
18116: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
18117: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
18118: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
18119: $changes{'intauth'} = 1;
18120: }
18121: } else {
18122: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
18123: }
18124: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
18125: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
18126: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
18127: $changes{'intauth'} = 1;
18128: }
18129: } else {
18130: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18131: }
18132: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
18133: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
18134: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
18135: $changes{'intauth'} = 1;
18136: }
18137: } else {
18138: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18139: }
18140: foreach my $item ('cost','check','switch') {
18141: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
18142: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
18143: $updatedefaults = 1;
18144: }
18145: }
1.405 raeburn 18146: &password_rule_changes('passwords',\%newvalues,\%current,\%changes);
1.359 raeburn 18147: my %crsownerchg = (
18148: by => [],
18149: for => [],
18150: );
18151: foreach my $item ('by','for') {
18152: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
18153: foreach my $type (sort(@posstypes)) {
18154: if (grep(/^\Q$type\E$/,@oktypes)) {
18155: push(@{$crsownerchg{$item}},$type);
18156: }
18157: }
18158: }
18159: $newvalues{'crsownerchg'} = \%crsownerchg;
18160: if (ref($current{'crsownerchg'}) eq 'HASH') {
18161: foreach my $item ('by','for') {
18162: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
18163: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
18164: if (@diffs > 0) {
18165: $changes{'crsownerchg'} = 1;
18166: last;
18167: }
18168: }
18169: }
1.368 raeburn 18170: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359 raeburn 18171: foreach my $item ('by','for') {
18172: if (@{$crsownerchg{$item}} > 0) {
18173: $changes{'crsownerchg'} = 1;
18174: last;
18175: }
1.354 raeburn 18176: }
18177: }
18178:
18179: my %confighash = (
18180: defaults => \%save_defaults,
18181: passwords => \%newvalues,
18182: );
18183: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
18184:
18185: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
18186: if ($putresult eq 'ok') {
18187: if (keys(%changes) > 0) {
18188: $resulttext = &mt('Changes made: ').'<ul>';
18189: foreach my $key ('reset','intauth','rules','crsownerchg') {
18190: if ($changes{$key}) {
1.355 raeburn 18191: unless ($key eq 'intauth') {
18192: $updateconf = 1;
18193: }
1.354 raeburn 18194: $resulttext .= '<li>'.$titles{$key}.':<ul>';
18195: if ($key eq 'reset') {
18196: if ($confighash{'passwords'}{'captcha'} eq 'original') {
18197: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
18198: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
18199: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369 raeburn 18200: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
18201: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
18202: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
18203: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
18204: }
1.354 raeburn 18205: } else {
18206: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
18207: }
18208: if ($confighash{'passwords'}{'resetlink'}) {
18209: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
18210: } else {
18211: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
18212: &mt('Will default to 2 hours').'</li>';
18213: }
18214: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
18215: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
18216: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
18217: } else {
18218: my $casesens;
18219: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
18220: if ($type eq 'default') {
18221: $casesens .= $othertitle.', ';
18222: } elsif ($usertypes->{$type} ne '') {
18223: $casesens .= $usertypes->{$type}.', ';
18224: }
18225: }
18226: $casesens =~ s/\Q, \E$//;
18227: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
18228: }
18229: } else {
18230: $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>';
18231: }
18232: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
18233: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
18234: } else {
18235: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
18236: }
18237: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
18238: my $output;
18239: if (ref($types) eq 'ARRAY') {
18240: foreach my $type (@{$types}) {
18241: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
18242: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
18243: $output .= $usertypes->{$type}.' -- '.&mt('none');
18244: } else {
18245: $output .= $usertypes->{$type}.' -- '.
18246: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
18247: }
18248: }
18249: }
18250: }
18251: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
18252: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
18253: $output .= $othertitle.' -- '.&mt('none');
18254: } else {
18255: $output .= $othertitle.' -- '.
18256: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
18257: }
18258: }
18259: if ($output) {
18260: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
18261: } else {
18262: $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>';
18263: }
18264: } else {
18265: $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>';
18266: }
18267: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
18268: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
18269: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
18270: } else {
18271: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
18272: }
18273: } else {
1.379 raeburn 18274: $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 18275: }
18276: if ($confighash{'passwords'}{'resetremove'}) {
18277: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
18278: } else {
18279: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
18280: }
18281: if ($confighash{'passwords'}{'resetcustom'}) {
18282: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369 raeburn 18283: &mt('custom text'),600,500,undef,undef,
18284: undef,undef,'background-color:#ffffff');
18285: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354 raeburn 18286: } else {
18287: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
18288: }
18289: } elsif ($key eq 'intauth') {
18290: foreach my $item ('cost','switch','check') {
18291: my $value = $save_defaults{$key.'_'.$item};
18292: if ($item eq 'switch') {
18293: my %optiondesc = &Apache::lonlocal::texthash (
18294: 0 => 'No',
18295: 1 => 'Yes',
18296: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
18297: );
18298: if ($value =~ /^(0|1|2)$/) {
18299: $value = $optiondesc{$value};
18300: } else {
18301: $value = &mt('none -- defaults to No');
18302: }
18303: } elsif ($item eq 'check') {
18304: my %optiondesc = &Apache::lonlocal::texthash (
18305: 0 => 'No',
18306: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
18307: 2 => 'Yes, disallow login if stored cost is less than domain default',
18308: );
18309: if ($value =~ /^(0|1|2)$/) {
18310: $value = $optiondesc{$value};
18311: } else {
18312: $value = &mt('none -- defaults to No');
18313: }
18314: }
18315: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
18316: }
18317: } elsif ($key eq 'rules') {
1.356 raeburn 18318: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 18319: if ($confighash{'passwords'}{$rule} eq '') {
18320: if ($rule eq 'min') {
1.356 raeburn 18321: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365 raeburn 18322: ' '.&mt('Default of [_1] will be used',
18323: $Apache::lonnet::passwdmin).'</li>';
1.356 raeburn 18324: } else {
18325: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354 raeburn 18326: }
18327: } else {
18328: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
18329: }
18330: }
1.370 raeburn 18331: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
18332: if (@{$confighash{'passwords'}{'chars'}} > 0) {
18333: my %rulenames = &Apache::lonlocal::texthash(
18334: uc => 'At least one upper case letter',
18335: lc => 'At least one lower case letter',
18336: num => 'At least one number',
18337: spec => 'At least one non-alphanumeric',
18338: );
18339: my $needed = '<ul><li>'.
18340: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
1.425 raeburn 18341: '</li></ul>';
1.370 raeburn 18342: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
18343: } else {
18344: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18345: }
18346: } else {
18347: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18348: }
1.354 raeburn 18349: } elsif ($key eq 'crsownerchg') {
1.359 raeburn 18350: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
18351: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
18352: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
18353: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
18354: } else {
18355: my %crsownerstr;
18356: foreach my $item ('by','for') {
18357: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
18358: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
18359: if ($type eq 'default') {
18360: $crsownerstr{$item} .= $othertitle.', ';
18361: } elsif ($usertypes->{$type} ne '') {
18362: $crsownerstr{$item} .= $usertypes->{$type}.', ';
18363: }
18364: }
18365: $crsownerstr{$item} =~ s/\Q, \E$//;
18366: }
18367: }
18368: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
18369: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
18370: }
1.354 raeburn 18371: } else {
1.359 raeburn 18372: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354 raeburn 18373: }
18374: }
18375: $resulttext .= '</ul></li>';
18376: }
18377: }
18378: $resulttext .= '</ul>';
18379: } else {
18380: $resulttext = &mt('No changes made to password settings');
18381: }
1.355 raeburn 18382: my $cachetime = 24*60*60;
1.354 raeburn 18383: if ($updatedefaults) {
18384: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18385: if (ref($lastactref) eq 'HASH') {
18386: $lastactref->{'domdefaults'} = 1;
18387: }
18388: }
1.355 raeburn 18389: if ($updateconf) {
18390: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
18391: if (ref($lastactref) eq 'HASH') {
18392: $lastactref->{'passwdconf'} = 1;
18393: }
18394: }
1.354 raeburn 18395: } else {
18396: $resulttext = '<span class="LC_error">'.
18397: &mt('An error occurred: [_1]',$putresult).'</span>';
18398: }
18399: if ($errors) {
18400: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
18401: $errors.'</ul></p>';
18402: }
18403: return $resulttext;
18404: }
18405:
1.405 raeburn 18406: sub password_rule_changes {
18407: my ($prefix,$newvalues,$current,$changes) = @_;
18408: return unless ((ref($newvalues) eq 'HASH') &&
18409: (ref($current) eq 'HASH') &&
18410: (ref($changes) eq 'HASH'));
18411: my (@rules,%staticdefaults);
18412: if ($prefix eq 'passwords') {
18413: @rules = ('min','max','expire','numsaved');
1.421 raeburn 18414: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 18415: @rules = ('min','max');
18416: }
18417: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
18418: foreach my $rule (@rules) {
18419: $env{'form.'.$prefix.'_'.$rule} =~ s/^\s+|\s+$//g;
18420: my $ruleok;
18421: if ($rule eq 'expire') {
18422: if (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+(|\.\d*)$/) &&
18423: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18424: $ruleok = 1;
18425: }
18426: } elsif ($rule eq 'min') {
18427: if ($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) {
18428: if ($env{'form.'.$prefix.'_'.$rule} >= $staticdefaults{$rule}) {
18429: $ruleok = 1;
18430: }
18431: }
18432: } elsif (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) &&
18433: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18434: $ruleok = 1;
18435: }
18436: if ($ruleok) {
18437: $newvalues->{$rule} = $env{'form.'.$prefix.'_'.$rule};
18438: if (exists($current->{$rule})) {
18439: if ($newvalues->{$rule} ne $current->{$rule}) {
18440: $changes->{'rules'} = 1;
18441: }
18442: } elsif ($rule eq 'min') {
18443: if ($staticdefaults{$rule} ne $newvalues->{$rule}) {
18444: $changes->{'rules'} = 1;
18445: }
18446: } else {
18447: $changes->{'rules'} = 1;
18448: }
18449: } elsif (exists($current->{$rule})) {
18450: $changes->{'rules'} = 1;
18451: }
18452: }
18453: my @posschars = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_chars');
18454: my @chars;
18455: foreach my $item (sort(@posschars)) {
18456: if ($item =~ /^(uc|lc|num|spec)$/) {
18457: push(@chars,$item);
18458: }
18459: }
18460: $newvalues->{'chars'} = \@chars;
18461: unless ($changes->{'rules'}) {
18462: if (ref($current->{'chars'}) eq 'ARRAY') {
18463: my @diffs = &Apache::loncommon::compare_arrays($current->{'chars'},\@chars);
18464: if (@diffs > 0) {
18465: $changes->{'rules'} = 1;
18466: }
18467: } else {
18468: if (@chars > 0) {
18469: $changes->{'rules'} = 1;
18470: }
18471: }
18472: }
18473: return;
18474: }
18475:
1.28 raeburn 18476: sub modify_usercreation {
1.27 raeburn 18477: my ($dom,%domconfig) = @_;
1.224 raeburn 18478: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 18479: my $warningmsg;
1.27 raeburn 18480: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18481: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 18482: if ($key eq 'cancreate') {
18483: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18484: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 18485: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
18486: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18487: } else {
1.224 raeburn 18488: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18489: }
18490: }
18491: }
18492: } elsif ($key eq 'email_rule') {
18493: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18494: } else {
18495: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18496: }
1.27 raeburn 18497: }
18498: }
18499: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 18500: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 18501: my @contexts = ('author','course','requestcrs');
1.34 raeburn 18502: foreach my $item(@contexts) {
1.224 raeburn 18503: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 18504: }
1.34 raeburn 18505: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
18506: foreach my $item (@contexts) {
1.224 raeburn 18507: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
18508: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 18509: }
1.27 raeburn 18510: }
1.34 raeburn 18511: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
18512: foreach my $item (@contexts) {
1.43 raeburn 18513: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 18514: if ($cancreate{$item} ne 'any') {
18515: push(@{$changes{'cancreate'}},$item);
18516: }
18517: } else {
18518: if ($cancreate{$item} ne 'none') {
18519: push(@{$changes{'cancreate'}},$item);
18520: }
1.27 raeburn 18521: }
18522: }
18523: } else {
1.43 raeburn 18524: foreach my $item (@contexts) {
1.34 raeburn 18525: push(@{$changes{'cancreate'}},$item);
18526: }
1.27 raeburn 18527: }
1.34 raeburn 18528:
1.27 raeburn 18529: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
18530: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
18531: if (!grep(/^\Q$type\E$/,@username_rule)) {
18532: push(@{$changes{'username_rule'}},$type);
18533: }
18534: }
18535: foreach my $type (@username_rule) {
18536: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
18537: push(@{$changes{'username_rule'}},$type);
18538: }
18539: }
18540: } else {
18541: push(@{$changes{'username_rule'}},@username_rule);
18542: }
18543:
1.32 raeburn 18544: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
18545: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
18546: if (!grep(/^\Q$type\E$/,@id_rule)) {
18547: push(@{$changes{'id_rule'}},$type);
18548: }
18549: }
18550: foreach my $type (@id_rule) {
18551: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
18552: push(@{$changes{'id_rule'}},$type);
18553: }
18554: }
18555: } else {
18556: push(@{$changes{'id_rule'}},@id_rule);
18557: }
18558:
1.43 raeburn 18559: my @authen_contexts = ('author','course','domain');
1.325 raeburn 18560: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 18561: my %authhash;
1.43 raeburn 18562: foreach my $item (@authen_contexts) {
1.28 raeburn 18563: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
18564: foreach my $auth (@authtypes) {
18565: if (grep(/^\Q$auth\E$/,@authallowed)) {
18566: $authhash{$item}{$auth} = 1;
18567: } else {
18568: $authhash{$item}{$auth} = 0;
18569: }
18570: }
18571: }
18572: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 18573: foreach my $item (@authen_contexts) {
1.28 raeburn 18574: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
18575: foreach my $auth (@authtypes) {
18576: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
18577: push(@{$changes{'authtypes'}},$item);
18578: last;
18579: }
18580: }
18581: }
18582: }
18583: } else {
1.43 raeburn 18584: foreach my $item (@authen_contexts) {
1.28 raeburn 18585: push(@{$changes{'authtypes'}},$item);
18586: }
18587: }
18588:
1.224 raeburn 18589: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
18590: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
18591: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
18592: $save_usercreate{'id_rule'} = \@id_rule;
18593: $save_usercreate{'username_rule'} = \@username_rule,
18594: $save_usercreate{'authtypes'} = \%authhash;
18595:
1.27 raeburn 18596: my %usercreation_hash = (
1.224 raeburn 18597: usercreation => \%save_usercreate,
18598: );
1.27 raeburn 18599:
18600: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
18601: $dom);
1.50 raeburn 18602:
1.224 raeburn 18603: if ($putresult eq 'ok') {
18604: if (keys(%changes) > 0) {
18605: $resulttext = &mt('Changes made:').'<ul>';
18606: if (ref($changes{'cancreate'}) eq 'ARRAY') {
18607: my %lt = &usercreation_types();
18608: foreach my $type (@{$changes{'cancreate'}}) {
18609: my $chgtext = $lt{$type}.', ';
18610: if ($cancreate{$type} eq 'none') {
18611: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
18612: } elsif ($cancreate{$type} eq 'any') {
18613: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
18614: } elsif ($cancreate{$type} eq 'official') {
18615: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
18616: } elsif ($cancreate{$type} eq 'unofficial') {
18617: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
18618: }
18619: $resulttext .= '<li>'.$chgtext.'</li>';
18620: }
18621: }
18622: if (ref($changes{'username_rule'}) eq 'ARRAY') {
18623: my ($rules,$ruleorder) =
18624: &Apache::lonnet::inst_userrules($dom,'username');
18625: my $chgtext = '<ul>';
18626: foreach my $type (@username_rule) {
18627: if (ref($rules->{$type}) eq 'HASH') {
18628: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
18629: }
18630: }
18631: $chgtext .= '</ul>';
18632: if (@username_rule > 0) {
18633: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18634: } else {
18635: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
18636: }
18637: }
18638: if (ref($changes{'id_rule'}) eq 'ARRAY') {
18639: my ($idrules,$idruleorder) =
18640: &Apache::lonnet::inst_userrules($dom,'id');
18641: my $chgtext = '<ul>';
18642: foreach my $type (@id_rule) {
18643: if (ref($idrules->{$type}) eq 'HASH') {
18644: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
18645: }
18646: }
18647: $chgtext .= '</ul>';
18648: if (@id_rule > 0) {
18649: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18650: } else {
18651: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
18652: }
18653: }
18654: my %authname = &authtype_names();
18655: my %context_title = &context_names();
18656: if (ref($changes{'authtypes'}) eq 'ARRAY') {
18657: my $chgtext = '<ul>';
18658: foreach my $type (@{$changes{'authtypes'}}) {
18659: my @allowed;
18660: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
18661: foreach my $auth (@authtypes) {
18662: if ($authhash{$type}{$auth}) {
18663: push(@allowed,$authname{$auth});
18664: }
18665: }
18666: if (@allowed > 0) {
18667: $chgtext .= join(', ',@allowed).'</li>';
18668: } else {
18669: $chgtext .= &mt('none').'</li>';
18670: }
18671: }
18672: $chgtext .= '</ul>';
18673: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
18674: $resulttext .= '</li>';
18675: }
18676: $resulttext .= '</ul>';
18677: } else {
18678: $resulttext = &mt('No changes made to user creation settings');
18679: }
18680: } else {
18681: $resulttext = '<span class="LC_error">'.
18682: &mt('An error occurred: [_1]',$putresult).'</span>';
18683: }
18684: if ($warningmsg ne '') {
18685: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
18686: }
18687: return $resulttext;
18688: }
18689:
18690: sub modify_selfcreation {
1.305 raeburn 18691: my ($dom,$lastactref,%domconfig) = @_;
18692: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
18693: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
18694: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 18695: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
18696: if (ref($typesref) eq 'ARRAY') {
18697: @types = @{$typesref};
18698: }
18699: if (ref($usertypesref) eq 'HASH') {
18700: %usertypes = %{$usertypesref};
1.228 raeburn 18701: }
1.303 raeburn 18702: $usertypes{'default'} = $othertitle;
1.224 raeburn 18703: #
18704: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
18705: #
18706: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18707: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
18708: if ($key eq 'cancreate') {
18709: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18710: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
18711: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 18712: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
18713: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
18714: ($item eq 'emailusername') || ($item eq 'shibenv') ||
18715: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 18716: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 18717: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18718: } else {
18719: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18720: }
18721: }
18722: }
18723: } elsif ($key eq 'email_rule') {
18724: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18725: } else {
18726: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18727: }
18728: }
18729: }
18730: #
18731: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
18732: #
18733: if (ref($domconfig{'usermodification'}) eq 'HASH') {
18734: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
18735: if ($key eq 'selfcreate') {
18736: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
18737: } else {
18738: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
18739: }
18740: }
18741: }
1.305 raeburn 18742: #
18743: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
18744: #
18745: if (ref($domconfig{'inststatus'}) eq 'HASH') {
18746: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
18747: if ($key eq 'inststatusguest') {
18748: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
18749: } else {
18750: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
18751: }
18752: }
18753: }
1.224 raeburn 18754:
18755: my @contexts = ('selfcreate');
18756: @{$cancreate{'selfcreate'}} = ();
18757: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 18758: if (@types) {
18759: @{$cancreate{'statustocreate'}} = ();
18760: }
1.236 raeburn 18761: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 18762: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 18763: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 18764: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 18765: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 18766: my %selfcreatetypes = (
18767: sso => 'users authenticated by institutional single sign on',
18768: login => 'users authenticated by institutional log-in',
1.303 raeburn 18769: email => 'users verified by e-mail',
1.50 raeburn 18770: );
1.224 raeburn 18771: #
18772: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
18773: # is permitted.
18774: #
1.305 raeburn 18775: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 18776:
1.305 raeburn 18777: my (@statuses,%email_rule);
1.228 raeburn 18778: foreach my $item ('login','sso','email') {
1.224 raeburn 18779: if ($item eq 'email') {
1.236 raeburn 18780: if ($env{'form.cancreate_email'}) {
1.305 raeburn 18781: if (@types) {
18782: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
18783: foreach my $status (@poss_statuses) {
18784: if (grep(/^\Q$status\E$/,(@types,'default'))) {
18785: push(@statuses,$status);
18786: }
18787: }
18788: $save_inststatus{'inststatusguest'} = \@statuses;
18789: } else {
18790: push(@statuses,'default');
18791: }
18792: if (@statuses) {
18793: my %curr_rule;
18794: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
18795: foreach my $type (@statuses) {
18796: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 18797: }
1.305 raeburn 18798: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
18799: foreach my $type (@statuses) {
18800: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
18801: }
18802: }
18803: push(@{$cancreate{'selfcreate'}},'email');
18804: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
18805: my %curremaildom;
18806: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
18807: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
18808: }
18809: foreach my $type (@statuses) {
18810: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
18811: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
18812: }
18813: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
18814: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
18815: }
18816: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
18817: #
18818: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
18819: #
18820: my $chosen = $1;
18821: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
18822: my $emaildom;
18823: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
1.425 raeburn 18824: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
1.305 raeburn 18825: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
18826: if (ref($curremaildom{$type}) eq 'HASH') {
18827: if (exists($curremaildom{$type}{$chosen})) {
18828: if ($curremaildom{$type}{$chosen} ne $emaildom) {
18829: push(@{$changes{'cancreate'}},'emaildomain');
18830: }
18831: } elsif ($emaildom ne '') {
18832: push(@{$changes{'cancreate'}},'emaildomain');
18833: }
18834: } elsif ($emaildom ne '') {
18835: push(@{$changes{'cancreate'}},'emaildomain');
1.425 raeburn 18836: }
1.305 raeburn 18837: }
18838: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
18839: } elsif ($chosen eq 'custom') {
18840: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
18841: $email_rule{$type} = [];
18842: if (ref($emailrules) eq 'HASH') {
18843: foreach my $rule (@possemail_rules) {
18844: if (exists($emailrules->{$rule})) {
18845: push(@{$email_rule{$type}},$rule);
18846: }
18847: }
18848: }
18849: if (@{$email_rule{$type}}) {
18850: $cancreate{'emailoptions'}{$type} = 'custom';
18851: if (ref($curr_rule{$type}) eq 'ARRAY') {
18852: if (@{$curr_rule{$type}} > 0) {
18853: foreach my $rule (@{$curr_rule{$type}}) {
18854: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
18855: push(@{$changes{'email_rule'}},$type);
18856: }
18857: }
18858: }
18859: foreach my $type (@{$email_rule{$type}}) {
18860: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
18861: push(@{$changes{'email_rule'}},$type);
18862: }
18863: }
18864: } else {
18865: push(@{$changes{'email_rule'}},$type);
18866: }
18867: }
18868: } else {
18869: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
18870: }
18871: }
18872: }
18873: if (@types) {
18874: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
18875: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
18876: if (@changed) {
18877: push(@{$changes{'inststatus'}},'inststatusguest');
18878: }
18879: } else {
18880: push(@{$changes{'inststatus'}},'inststatusguest');
18881: }
18882: }
18883: } else {
18884: delete($env{'form.cancreate_email'});
18885: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
18886: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
18887: push(@{$changes{'inststatus'}},'inststatusguest');
18888: }
18889: }
18890: }
18891: } else {
18892: $save_inststatus{'inststatusguest'} = [];
18893: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
18894: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
18895: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 18896: }
18897: }
1.224 raeburn 18898: }
18899: } else {
18900: if ($env{'form.cancreate_'.$item}) {
18901: push(@{$cancreate{'selfcreate'}},$item);
18902: }
18903: }
18904: }
1.305 raeburn 18905: my (%userinfo,%savecaptcha);
1.224 raeburn 18906: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
18907: #
1.228 raeburn 18908: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
18909: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 18910: #
1.236 raeburn 18911:
1.244 raeburn 18912: if ($env{'form.cancreate_email'}) {
1.228 raeburn 18913: push(@contexts,'emailusername');
1.305 raeburn 18914: if (@statuses) {
18915: foreach my $type (@statuses) {
1.228 raeburn 18916: if (ref($infofields) eq 'ARRAY') {
18917: foreach my $field (@{$infofields}) {
18918: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
18919: $cancreate{'emailusername'}{$type}{$field} = $1;
18920: }
18921: }
1.224 raeburn 18922: }
18923: }
18924: }
18925: #
18926: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 18927: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 18928: #
18929:
18930: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
18931: @approvalnotify = sort(@approvalnotify);
18932: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
18933: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
18934: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
18935: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
18936: push(@{$changes{'cancreate'}},'notify');
18937: }
18938: } else {
18939: if ($cancreate{'notify'}{'approval'}) {
18940: push(@{$changes{'cancreate'}},'notify');
18941: }
18942: }
18943: } elsif ($cancreate{'notify'}{'approval'}) {
18944: push(@{$changes{'cancreate'}},'notify');
18945: }
18946:
18947: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
18948: }
18949: #
1.236 raeburn 18950: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 18951: # institutional log-in.
18952: #
18953: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
18954: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
18955: ($domdefaults{'auth_def'} eq 'localauth'))) {
18956: $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.').' '.
18957: &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.');
18958: }
18959: }
18960: my @fields = ('lastname','firstname','middlename','generation',
18961: 'permanentemail','id');
1.240 raeburn 18962: my @shibfields = (@fields,'inststatus');
1.224 raeburn 18963: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
18964: #
18965: # Where usernames may created for institutional log-in and/or institutional single sign on:
18966: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
18967: # may self-create accounts
18968: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
18969: # which the user may supply, if institutional data is unavailable.
18970: #
18971: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 18972: if (@types) {
1.305 raeburn 18973: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
18974: push(@contexts,'statustocreate');
1.303 raeburn 18975: foreach my $type (@types) {
1.224 raeburn 18976: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
18977: foreach my $field (@fields) {
18978: if (grep(/^\Q$field\E$/,@modifiable)) {
18979: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
18980: } else {
18981: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
18982: }
18983: }
18984: }
18985: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 18986: foreach my $type (@types) {
1.224 raeburn 18987: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
18988: foreach my $field (@fields) {
18989: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
18990: $curr_usermodify{'selfcreate'}{$type}{$field}) {
18991: push(@{$changes{'selfcreate'}},$type);
18992: last;
18993: }
18994: }
18995: }
18996: }
18997: } else {
1.303 raeburn 18998: foreach my $type (@types) {
1.224 raeburn 18999: push(@{$changes{'selfcreate'}},$type);
19000: }
19001: }
19002: }
1.240 raeburn 19003: foreach my $field (@shibfields) {
19004: if ($env{'form.shibenv_'.$field} ne '') {
19005: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
19006: }
19007: }
19008: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
19009: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
19010: foreach my $field (@shibfields) {
19011: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
19012: push(@{$changes{'cancreate'}},'shibenv');
19013: }
19014: }
19015: } else {
19016: foreach my $field (@shibfields) {
19017: if ($env{'form.shibenv_'.$field}) {
19018: push(@{$changes{'cancreate'}},'shibenv');
19019: last;
19020: }
19021: }
19022: }
19023: }
1.224 raeburn 19024: }
19025: foreach my $item (@contexts) {
19026: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
19027: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
19028: if (ref($cancreate{$item}) eq 'ARRAY') {
19029: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
19030: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19031: push(@{$changes{'cancreate'}},$item);
19032: }
19033: }
19034: }
19035: }
19036: if (ref($cancreate{$item}) eq 'ARRAY') {
19037: foreach my $type (@{$cancreate{$item}}) {
19038: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
19039: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19040: push(@{$changes{'cancreate'}},$item);
19041: }
19042: }
19043: }
19044: }
19045: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
19046: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 19047: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
19048: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19049: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
19050: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19051: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19052: push(@{$changes{'cancreate'}},$item);
19053: }
19054: }
19055: }
1.305 raeburn 19056: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19057: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19058: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19059: push(@{$changes{'cancreate'}},$item);
19060: }
1.224 raeburn 19061: }
19062: }
19063: }
1.305 raeburn 19064: foreach my $type (keys(%{$cancreate{$item}})) {
19065: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19066: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19067: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19068: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19069: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19070: push(@{$changes{'cancreate'}},$item);
19071: }
19072: }
19073: } else {
19074: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19075: push(@{$changes{'cancreate'}},$item);
19076: }
19077: }
19078: }
1.305 raeburn 19079: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19080: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19081: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19082: push(@{$changes{'cancreate'}},$item);
19083: }
1.224 raeburn 19084: }
19085: }
19086: }
19087: }
19088: } elsif ($curr_usercreation{'cancreate'}{$item}) {
19089: if (ref($cancreate{$item}) eq 'ARRAY') {
19090: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
19091: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19092: push(@{$changes{'cancreate'}},$item);
19093: }
19094: }
1.305 raeburn 19095: }
19096: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19097: if (ref($cancreate{$item}) eq 'HASH') {
19098: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19099: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 19100: }
19101: }
19102: } elsif ($item eq 'emailusername') {
1.228 raeburn 19103: if (ref($cancreate{$item}) eq 'HASH') {
19104: foreach my $type (keys(%{$cancreate{$item}})) {
19105: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19106: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19107: if ($cancreate{$item}{$type}{$field}) {
19108: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19109: push(@{$changes{'cancreate'}},$item);
19110: }
19111: last;
19112: }
19113: }
19114: }
19115: }
1.224 raeburn 19116: }
19117: }
19118: }
19119: #
19120: # Populate %save_usercreate hash with updates to self-creation configuration.
19121: #
19122: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
19123: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 19124: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 19125: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
19126: if (ref($cancreate{'notify'}) eq 'HASH') {
19127: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
19128: }
1.236 raeburn 19129: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
19130: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
19131: }
1.303 raeburn 19132: if (ref($cancreate{'emailverified'}) eq 'HASH') {
19133: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
19134: }
1.305 raeburn 19135: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
19136: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
19137: }
1.303 raeburn 19138: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
19139: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
19140: }
1.224 raeburn 19141: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19142: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
19143: }
1.240 raeburn 19144: if (ref($cancreate{'shibenv'}) eq 'HASH') {
19145: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
19146: }
1.224 raeburn 19147: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 19148: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 19149:
19150: my %userconfig_hash = (
19151: usercreation => \%save_usercreate,
19152: usermodification => \%save_usermodify,
1.305 raeburn 19153: inststatus => \%save_inststatus,
1.224 raeburn 19154: );
1.305 raeburn 19155:
1.224 raeburn 19156: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
19157: $dom);
19158: #
1.305 raeburn 19159: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 19160: #
1.27 raeburn 19161: if ($putresult eq 'ok') {
19162: if (keys(%changes) > 0) {
19163: $resulttext = &mt('Changes made:').'<ul>';
19164: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 19165: my %lt = &selfcreation_types();
1.34 raeburn 19166: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 19167: my $chgtext = '';
1.45 raeburn 19168: if ($type eq 'selfcreate') {
1.50 raeburn 19169: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 19170: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 19171: } else {
1.224 raeburn 19172: $chgtext .= &mt('Self-creation of a new account is permitted for:').
19173: '<ul>';
1.50 raeburn 19174: foreach my $case (@{$cancreate{$type}}) {
19175: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
19176: }
19177: $chgtext .= '</ul>';
1.100 raeburn 19178: if (ref($cancreate{$type}) eq 'ARRAY') {
19179: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
19180: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19181: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 19182: $chgtext .= '<span class="LC_warning">'.
19183: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
19184: '</span><br />';
19185: }
19186: }
19187: }
19188: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 19189: if (!@statuses) {
19190: $chgtext .= '<span class="LC_warning">'.
19191: &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.").
19192: '</span><br />';
1.303 raeburn 19193:
1.100 raeburn 19194: }
19195: }
19196: }
1.43 raeburn 19197: }
1.240 raeburn 19198: } elsif ($type eq 'shibenv') {
19199: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 19200: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 19201: } else {
19202: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
19203: '<ul>';
19204: foreach my $field (@shibfields) {
19205: next if ($cancreate{$type}{$field} eq '');
19206: if ($field eq 'inststatus') {
19207: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
19208: } else {
19209: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
19210: }
19211: }
19212: $chgtext .= '</ul>';
1.303 raeburn 19213: }
1.93 raeburn 19214: } elsif ($type eq 'statustocreate') {
1.96 raeburn 19215: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
19216: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
19217: if (@{$cancreate{'selfcreate'}} > 0) {
19218: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 19219: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 19220: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 19221: $chgtext .= '<br />'.
19222: '<span class="LC_warning">'.
19223: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
19224: '</span>';
19225: }
1.303 raeburn 19226: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 19227: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 19228: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
19229: } else {
19230: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
19231: }
19232: $chgtext .= '<ul>';
19233: foreach my $case (@{$cancreate{$type}}) {
19234: if ($case eq 'default') {
19235: $chgtext .= '<li>'.$othertitle.'</li>';
19236: } else {
1.303 raeburn 19237: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 19238: }
19239: }
1.100 raeburn 19240: $chgtext .= '</ul>';
19241: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 19242: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 19243: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
19244: '</span>';
1.100 raeburn 19245: }
19246: }
19247: } else {
19248: if (@{$cancreate{$type}} == 0) {
19249: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
19250: } else {
19251: $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 19252: }
19253: }
1.303 raeburn 19254: $chgtext .= '<br />';
1.93 raeburn 19255: }
1.236 raeburn 19256: } elsif ($type eq 'selfcreateprocessing') {
19257: my %choices = &Apache::lonlocal::texthash (
19258: automatic => 'Automatic approval',
19259: approval => 'Queued for approval',
19260: );
1.305 raeburn 19261: if (@types) {
19262: if (@statuses) {
1.425 raeburn 19263: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 19264: '<ul>';
1.305 raeburn 19265: foreach my $status (@statuses) {
19266: if ($status eq 'default') {
19267: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19268: } else {
1.305 raeburn 19269: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19270: }
19271: }
19272: $chgtext .= '</ul>';
19273: }
19274: } else {
19275: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
19276: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
19277: }
19278: } elsif ($type eq 'emailverified') {
19279: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 19280: all => 'Same as e-mail',
19281: first => 'Omit @domain',
19282: free => 'Free to choose',
1.303 raeburn 19283: );
1.305 raeburn 19284: if (@types) {
19285: if (@statuses) {
1.303 raeburn 19286: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
19287: '<ul>';
1.305 raeburn 19288: foreach my $status (@statuses) {
1.362 raeburn 19289: if ($status eq 'default') {
1.305 raeburn 19290: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19291: } else {
1.305 raeburn 19292: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19293: }
19294: }
19295: $chgtext .= '</ul>';
19296: }
19297: } else {
1.305 raeburn 19298: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 19299: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 19300: }
1.305 raeburn 19301: } elsif ($type eq 'emailoptions') {
19302: my %options = &Apache::lonlocal::texthash (
19303: any => 'Any e-mail',
19304: inst => 'Institutional only',
19305: noninst => 'Non-institutional only',
19306: custom => 'Custom restrictions',
19307: );
19308: if (@types) {
19309: if (@statuses) {
19310: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
19311: '<ul>';
19312: foreach my $status (@statuses) {
19313: if ($type eq 'default') {
19314: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
19315: } else {
19316: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 19317: }
19318: }
1.305 raeburn 19319: $chgtext .= '</ul>';
19320: }
19321: } else {
19322: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
19323: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
19324: } else {
19325: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
19326: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 19327: }
1.305 raeburn 19328: }
19329: } elsif ($type eq 'emaildomain') {
19330: my $output;
19331: if (@statuses) {
19332: foreach my $type (@statuses) {
19333: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
19334: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
19335: if ($type eq 'default') {
19336: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19337: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19338: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19339: } else {
19340: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
19341: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
19342: }
1.303 raeburn 19343: } else {
1.305 raeburn 19344: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19345: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19346: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19347: } else {
19348: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
1.421 raeburn 19349: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
1.305 raeburn 19350: }
1.303 raeburn 19351: }
1.305 raeburn 19352: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
19353: if ($type eq 'default') {
19354: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19355: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19356: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19357: } else {
19358: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
19359: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
19360: }
1.303 raeburn 19361: } else {
1.305 raeburn 19362: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19363: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19364: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19365: } else {
19366: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
1.421 raeburn 19367: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
1.305 raeburn 19368: }
1.303 raeburn 19369: }
19370: }
19371: }
19372: }
1.305 raeburn 19373: }
19374: if ($output ne '') {
19375: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
19376: '<ul>'.$output.'</ul>';
1.236 raeburn 19377: }
1.165 raeburn 19378: } elsif ($type eq 'captcha') {
1.224 raeburn 19379: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 19380: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
19381: } else {
19382: my %captchas = &captcha_phrases();
1.224 raeburn 19383: if ($captchas{$savecaptcha{$type}}) {
19384: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 19385: } else {
1.210 raeburn 19386: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 19387: }
19388: }
19389: } elsif ($type eq 'recaptchakeys') {
19390: my ($privkey,$pubkey);
1.224 raeburn 19391: if (ref($savecaptcha{$type}) eq 'HASH') {
19392: $pubkey = $savecaptcha{$type}{'public'};
19393: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 19394: }
19395: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
19396: if (!$pubkey) {
19397: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
19398: } else {
19399: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
19400: }
19401: if (!$privkey) {
19402: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
19403: } else {
19404: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
19405: }
19406: $chgtext .= '</ul>';
1.269 raeburn 19407: } elsif ($type eq 'recaptchaversion') {
19408: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 19409: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 19410: }
1.224 raeburn 19411: } elsif ($type eq 'emailusername') {
19412: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 19413: if (@statuses) {
19414: foreach my $type (@statuses) {
1.228 raeburn 19415: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
19416: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 19417: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 19418: '<ul>';
19419: foreach my $field (@{$infofields}) {
19420: if ($cancreate{'emailusername'}{$type}{$field}) {
19421: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
19422: }
19423: }
1.245 raeburn 19424: $chgtext .= '</ul>';
19425: } else {
1.303 raeburn 19426: $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 19427: }
19428: } else {
1.303 raeburn 19429: $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 19430: }
19431: }
19432: }
19433: }
19434: } elsif ($type eq 'notify') {
1.303 raeburn 19435: my $numapprove = 0;
1.224 raeburn 19436: if (ref($changes{'cancreate'}) eq 'ARRAY') {
19437: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
19438: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 19439: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
19440: $numapprove ++;
1.224 raeburn 19441: }
19442: }
1.43 raeburn 19443: }
1.303 raeburn 19444: unless ($numapprove) {
19445: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
19446: }
1.34 raeburn 19447: }
1.224 raeburn 19448: if ($chgtext) {
19449: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 19450: }
19451: }
19452: }
1.305 raeburn 19453: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 19454: my ($emailrules,$emailruleorder) =
19455: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 19456: foreach my $type (@{$changes{'email_rule'}}) {
19457: if (ref($email_rule{$type}) eq 'ARRAY') {
19458: my $chgtext = '<ul>';
19459: foreach my $rule (@{$email_rule{$type}}) {
19460: if (ref($emailrules->{$rule}) eq 'HASH') {
19461: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
19462: }
19463: }
19464: $chgtext .= '</ul>';
1.310 raeburn 19465: my $typename;
1.305 raeburn 19466: if (@types) {
19467: if ($type eq 'default') {
19468: $typename = $othertitle;
19469: } else {
19470: $typename = $usertypes{$type};
1.425 raeburn 19471: }
1.305 raeburn 19472: $chgtext .= &mt('(Affiliation: [_1])',$typename);
19473: }
19474: if (@{$email_rule{$type}} > 0) {
19475: $resulttext .= '<li>'.
19476: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
19477: $usertypes{$type}).
19478: $chgtext.
19479: '</li>';
19480: } else {
19481: $resulttext .= '<li>'.
1.310 raeburn 19482: &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 19483: '</li>'.
1.310 raeburn 19484: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 19485: }
1.43 raeburn 19486: }
19487: }
1.305 raeburn 19488: }
19489: if (ref($changes{'inststatus'}) eq 'ARRAY') {
19490: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
19491: if (@{$save_inststatus{'inststatusguest'}} > 0) {
19492: my $chgtext = '<ul>';
19493: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
19494: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
19495: }
19496: $chgtext .= '</ul>';
19497: $resulttext .= '<li>'.
19498: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
19499: $chgtext.
19500: '</li>';
19501: } else {
19502: $resulttext .= '<li>'.
19503: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
19504: '</li>';
19505: }
1.43 raeburn 19506: }
19507: }
1.224 raeburn 19508: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
19509: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
19510: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19511: foreach my $type (@{$changes{'selfcreate'}}) {
19512: my $typename = $type;
1.303 raeburn 19513: if (keys(%usertypes) > 0) {
19514: if ($usertypes{$type} ne '') {
19515: $typename = $usertypes{$type};
1.224 raeburn 19516: }
19517: }
19518: my @modifiable;
19519: $resulttext .= '<li>'.
19520: &mt('Self-creation of account by users with status: [_1]',
19521: '<span class="LC_cusr_emph">'.$typename.'</span>').
19522: ' - '.&mt('modifiable fields (if institutional data blank): ');
19523: foreach my $field (@fields) {
19524: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
19525: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 19526: }
19527: }
1.224 raeburn 19528: if (@modifiable > 0) {
19529: $resulttext .= join(', ',@modifiable);
1.43 raeburn 19530: } else {
1.224 raeburn 19531: $resulttext .= &mt('none');
1.43 raeburn 19532: }
1.224 raeburn 19533: $resulttext .= '</li>';
1.28 raeburn 19534: }
1.224 raeburn 19535: $resulttext .= '</ul></li>';
1.28 raeburn 19536: }
1.27 raeburn 19537: $resulttext .= '</ul>';
1.305 raeburn 19538: my $cachetime = 24*60*60;
19539: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
19540: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19541: if (ref($lastactref) eq 'HASH') {
19542: $lastactref->{'domdefaults'} = 1;
19543: }
1.27 raeburn 19544: } else {
1.224 raeburn 19545: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 19546: }
19547: } else {
19548: $resulttext = '<span class="LC_error">'.
1.23 raeburn 19549: &mt('An error occurred: [_1]',$putresult).'</span>';
19550: }
1.43 raeburn 19551: if ($warningmsg ne '') {
19552: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
19553: }
1.23 raeburn 19554: return $resulttext;
19555: }
19556:
1.165 raeburn 19557: sub process_captcha {
1.369 raeburn 19558: my ($container,$changes,$newsettings,$currsettings) = @_;
19559: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165 raeburn 19560: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
19561: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
19562: $newsettings->{'captcha'} = 'original';
19563: }
1.369 raeburn 19564: my %current;
19565: if (ref($currsettings) eq 'HASH') {
19566: %current = %{$currsettings};
19567: }
19568: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 19569: if ($container eq 'cancreate') {
1.169 raeburn 19570: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19571: push(@{$changes->{'cancreate'}},'captcha');
19572: } elsif (!defined($changes->{'cancreate'})) {
19573: $changes->{'cancreate'} = ['captcha'];
19574: }
1.368 raeburn 19575: } elsif ($container eq 'passwords') {
19576: $changes->{'reset'} = 1;
1.169 raeburn 19577: } else {
19578: $changes->{'captcha'} = 1;
1.165 raeburn 19579: }
19580: }
1.269 raeburn 19581: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 19582: if ($newsettings->{'captcha'} eq 'recaptcha') {
19583: $newpub = $env{'form.'.$container.'_recaptchapub'};
19584: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 19585: $newpub =~ s/[^\w\-]//g;
19586: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 19587: $newsettings->{'recaptchakeys'} = {
19588: public => $newpub,
19589: private => $newpriv,
19590: };
1.269 raeburn 19591: $newversion = $env{'form.'.$container.'_recaptchaversion'};
19592: $newversion =~ s/\D//g;
19593: if ($newversion ne '2') {
19594: $newversion = 1;
19595: }
19596: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 19597: }
1.369 raeburn 19598: if (ref($current{'recaptchakeys'}) eq 'HASH') {
19599: $currpub = $current{'recaptchakeys'}{'public'};
19600: $currpriv = $current{'recaptchakeys'}{'private'};
1.179 raeburn 19601: unless ($newsettings->{'captcha'} eq 'recaptcha') {
19602: $newsettings->{'recaptchakeys'} = {
19603: public => '',
19604: private => '',
19605: }
19606: }
1.165 raeburn 19607: }
1.369 raeburn 19608: if ($current{'captcha'} eq 'recaptcha') {
19609: $currversion = $current{'recaptchaversion'};
1.269 raeburn 19610: if ($currversion ne '2') {
19611: $currversion = 1;
19612: }
19613: }
19614: if ($currversion ne $newversion) {
19615: if ($container eq 'cancreate') {
19616: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19617: push(@{$changes->{'cancreate'}},'recaptchaversion');
19618: } elsif (!defined($changes->{'cancreate'})) {
19619: $changes->{'cancreate'} = ['recaptchaversion'];
19620: }
1.368 raeburn 19621: } elsif ($container eq 'passwords') {
19622: $changes->{'reset'} = 1;
1.269 raeburn 19623: } else {
19624: $changes->{'recaptchaversion'} = 1;
19625: }
19626: }
1.165 raeburn 19627: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 19628: if ($container eq 'cancreate') {
19629: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19630: push(@{$changes->{'cancreate'}},'recaptchakeys');
19631: } elsif (!defined($changes->{'cancreate'})) {
19632: $changes->{'cancreate'} = ['recaptchakeys'];
19633: }
1.368 raeburn 19634: } elsif ($container eq 'passwords') {
19635: $changes->{'reset'} = 1;
1.169 raeburn 19636: } else {
1.210 raeburn 19637: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 19638: }
19639: }
19640: return;
19641: }
19642:
1.33 raeburn 19643: sub modify_usermodification {
19644: my ($dom,%domconfig) = @_;
1.224 raeburn 19645: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 19646: if (ref($domconfig{'usermodification'}) eq 'HASH') {
19647: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 19648: if ($key eq 'selfcreate') {
19649: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
19650: } else {
19651: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
19652: }
1.33 raeburn 19653: }
19654: }
1.224 raeburn 19655: my @contexts = ('author','course');
1.33 raeburn 19656: my %context_title = (
19657: author => 'In author context',
19658: course => 'In course context',
19659: );
19660: my @fields = ('lastname','firstname','middlename','generation',
19661: 'permanentemail','id');
19662: my %roles = (
19663: author => ['ca','aa'],
19664: course => ['st','ep','ta','in','cr'],
19665: );
19666: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19667: foreach my $context (@contexts) {
19668: foreach my $role (@{$roles{$context}}) {
19669: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
19670: foreach my $item (@fields) {
19671: if (grep(/^\Q$item\E$/,@modifiable)) {
19672: $modifyhash{$context}{$role}{$item} = 1;
19673: } else {
19674: $modifyhash{$context}{$role}{$item} = 0;
19675: }
19676: }
19677: }
19678: if (ref($curr_usermodification{$context}) eq 'HASH') {
19679: foreach my $role (@{$roles{$context}}) {
19680: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
19681: foreach my $field (@fields) {
19682: if ($modifyhash{$context}{$role}{$field} ne
19683: $curr_usermodification{$context}{$role}{$field}) {
19684: push(@{$changes{$context}},$role);
19685: last;
19686: }
19687: }
19688: }
19689: }
19690: } else {
19691: foreach my $context (@contexts) {
19692: foreach my $role (@{$roles{$context}}) {
19693: push(@{$changes{$context}},$role);
19694: }
19695: }
19696: }
19697: }
19698: my %usermodification_hash = (
19699: usermodification => \%modifyhash,
19700: );
19701: my $putresult = &Apache::lonnet::put_dom('configuration',
19702: \%usermodification_hash,$dom);
19703: if ($putresult eq 'ok') {
19704: if (keys(%changes) > 0) {
19705: $resulttext = &mt('Changes made: ').'<ul>';
19706: foreach my $context (@contexts) {
19707: if (ref($changes{$context}) eq 'ARRAY') {
19708: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
19709: if (ref($changes{$context}) eq 'ARRAY') {
19710: foreach my $role (@{$changes{$context}}) {
19711: my $rolename;
1.224 raeburn 19712: if ($role eq 'cr') {
19713: $rolename = &mt('Custom');
1.33 raeburn 19714: } else {
1.224 raeburn 19715: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 19716: }
19717: my @modifiable;
1.224 raeburn 19718: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 19719: foreach my $field (@fields) {
19720: if ($modifyhash{$context}{$role}{$field}) {
19721: push(@modifiable,$fieldtitles{$field});
19722: }
19723: }
19724: if (@modifiable > 0) {
19725: $resulttext .= join(', ',@modifiable);
19726: } else {
19727: $resulttext .= &mt('none');
19728: }
19729: $resulttext .= '</li>';
19730: }
19731: $resulttext .= '</ul></li>';
19732: }
19733: }
19734: }
19735: $resulttext .= '</ul>';
19736: } else {
19737: $resulttext = &mt('No changes made to user modification settings');
19738: }
19739: } else {
19740: $resulttext = '<span class="LC_error">'.
19741: &mt('An error occurred: [_1]',$putresult).'</span>';
19742: }
19743: return $resulttext;
19744: }
19745:
1.43 raeburn 19746: sub modify_defaults {
1.212 raeburn 19747: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 19748: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 19749: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 19750: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 19751: 'portal_def');
1.325 raeburn 19752: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 19753: foreach my $item (@items) {
19754: $newvalues{$item} = $env{'form.'.$item};
19755: if ($item eq 'auth_def') {
19756: if ($newvalues{$item} ne '') {
19757: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
19758: push(@errors,$item);
19759: }
19760: }
19761: } elsif ($item eq 'lang_def') {
19762: if ($newvalues{$item} ne '') {
19763: if ($newvalues{$item} =~ /^(\w+)/) {
19764: my $langcode = $1;
1.103 raeburn 19765: if ($langcode ne 'x_chef') {
19766: if (code2language($langcode) eq '') {
19767: push(@errors,$item);
19768: }
1.43 raeburn 19769: }
19770: } else {
19771: push(@errors,$item);
19772: }
19773: }
1.54 raeburn 19774: } elsif ($item eq 'timezone_def') {
19775: if ($newvalues{$item} ne '') {
1.62 raeburn 19776: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 19777: push(@errors,$item);
19778: }
19779: }
1.68 raeburn 19780: } elsif ($item eq 'datelocale_def') {
19781: if ($newvalues{$item} ne '') {
19782: my @datelocale_ids = DateTime::Locale->ids();
19783: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
19784: push(@errors,$item);
19785: }
19786: }
1.141 raeburn 19787: } elsif ($item eq 'portal_def') {
19788: if ($newvalues{$item} ne '') {
1.414 raeburn 19789: 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])\/?$/) {
19790: foreach my $field ('email','web') {
19791: if ($env{'form.'.$item.'_'.$field}) {
19792: $newvalues{$item.'_'.$field} = $env{'form.'.$item.'_'.$field};
19793: }
19794: }
19795: } else {
1.141 raeburn 19796: push(@errors,$item);
19797: }
19798: }
1.43 raeburn 19799: }
19800: if (grep(/^\Q$item\E$/,@errors)) {
19801: $newvalues{$item} = $domdefaults{$item};
1.414 raeburn 19802: if ($item eq 'portal_def') {
19803: if ($domdefaults{$item}) {
19804: foreach my $field ('email','web') {
19805: if (exists($domdefaults{$item.'_'.$field})) {
19806: $newvalues{$item.'_'.$field} = $domdefaults{$item.'_'.$field};
19807: }
19808: }
19809: }
19810: }
1.43 raeburn 19811: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
19812: $changes{$item} = 1;
19813: }
1.414 raeburn 19814: if ($item eq 'portal_def') {
19815: unless (grep(/^\Q$item\E$/,@errors)) {
1.425 raeburn 19816: if ($newvalues{$item} eq '') {
1.414 raeburn 19817: foreach my $field ('email','web') {
19818: if (exists($domdefaults{$item.'_'.$field})) {
19819: delete($domdefaults{$item.'_'.$field});
19820: }
19821: }
19822: } else {
19823: unless ($changes{$item}) {
19824: foreach my $field ('email','web') {
19825: if ($domdefaults{$item.'_'.$field} ne $newvalues{$item.'_'.$field}) {
19826: $changes{$item} = 1;
19827: last;
19828: }
19829: }
19830: }
19831: foreach my $field ('email','web') {
19832: if ($newvalues{$item.'_'.$field}) {
19833: $domdefaults{$item.'_'.$field} = $newvalues{$item.'_'.$field};
19834: } elsif (exists($domdefaults{$item.'_'.$field})) {
19835: delete($domdefaults{$item.'_'.$field});
19836: }
19837: }
19838: }
19839: }
19840: }
1.72 raeburn 19841: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 19842: }
1.354 raeburn 19843: my %staticdefaults = (
19844: 'intauth_cost' => 10,
19845: 'intauth_check' => 0,
19846: 'intauth_switch' => 0,
19847: );
19848: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
19849: if (exists($domdefaults{$item})) {
19850: $newvalues{$item} = $domdefaults{$item};
19851: } else {
19852: $newvalues{$item} = $staticdefaults{$item};
19853: }
19854: }
1.409 raeburn 19855: my ($unamemaprules,$ruleorder);
19856: my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
19857: if (@possunamemaprules) {
19858: ($unamemaprules,$ruleorder) =
19859: &Apache::lonnet::inst_userrules($dom,'unamemap');
19860: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
19861: if (@{$ruleorder} > 0) {
19862: my %possrules;
19863: map { $possrules{$_} = 1; } @possunamemaprules;
19864: foreach my $rule (@{$ruleorder}) {
19865: if ($possrules{$rule}) {
19866: push(@{$newvalues{'unamemap_rule'}},$rule);
19867: }
19868: }
19869: }
19870: }
19871: }
19872: if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
19873: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
19874: my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
19875: $newvalues{'unamemap_rule'});
19876: if (@rulediffs) {
19877: $changes{'unamemap_rule'} = 1;
19878: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
19879: }
19880: } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
19881: $changes{'unamemap_rule'} = 1;
19882: delete($domdefaults{'unamemap_rule'});
19883: }
19884: } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
19885: if (@{$newvalues{'unamemap_rule'}} > 0) {
19886: $changes{'unamemap_rule'} = 1;
19887: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
19888: }
19889: }
1.43 raeburn 19890: my %defaults_hash = (
1.72 raeburn 19891: defaults => \%newvalues,
19892: );
1.43 raeburn 19893: my $title = &defaults_titles();
1.236 raeburn 19894:
19895: my $currinststatus;
19896: if (ref($domconfig{'inststatus'}) eq 'HASH') {
19897: $currinststatus = $domconfig{'inststatus'};
19898: } else {
19899: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
19900: $currinststatus = {
19901: inststatustypes => $usertypes,
19902: inststatusorder => $types,
19903: inststatusguest => [],
19904: };
19905: }
19906: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
19907: my @allpos;
19908: my %alltypes;
1.305 raeburn 19909: my @inststatusguest;
19910: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
19911: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
19912: unless (grep(/^\Q$type\E$/,@todelete)) {
19913: push(@inststatusguest,$type);
19914: }
19915: }
19916: }
19917: my ($currtitles,$currorder);
1.236 raeburn 19918: if (ref($currinststatus) eq 'HASH') {
19919: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
19920: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
19921: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
19922: if ($currinststatus->{inststatustypes}->{$type} ne '') {
19923: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
19924: }
19925: }
19926: unless (grep(/^\Q$type\E$/,@todelete)) {
19927: my $position = $env{'form.inststatus_pos_'.$type};
19928: $position =~ s/\D+//g;
19929: $allpos[$position] = $type;
19930: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
19931: $alltypes{$type} =~ s/`//g;
19932: }
19933: }
19934: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
19935: $currtitles =~ s/,$//;
19936: }
19937: }
19938: if ($env{'form.addinststatus'}) {
19939: my $newtype = $env{'form.addinststatus'};
19940: $newtype =~ s/\W//g;
19941: unless (exists($alltypes{$newtype})) {
19942: $alltypes{$newtype} = $env{'form.addinststatus_title'};
19943: $alltypes{$newtype} =~ s/`//g;
19944: my $position = $env{'form.addinststatus_pos'};
19945: $position =~ s/\D+//g;
19946: if ($position ne '') {
19947: $allpos[$position] = $newtype;
19948: }
19949: }
19950: }
1.305 raeburn 19951: my @orderedstatus;
1.236 raeburn 19952: foreach my $type (@allpos) {
19953: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
19954: push(@orderedstatus,$type);
19955: }
19956: }
19957: foreach my $type (keys(%alltypes)) {
19958: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
19959: delete($alltypes{$type});
19960: }
19961: }
19962: $defaults_hash{'inststatus'} = {
19963: inststatustypes => \%alltypes,
19964: inststatusorder => \@orderedstatus,
1.305 raeburn 19965: inststatusguest => \@inststatusguest,
1.236 raeburn 19966: };
19967: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
19968: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
19969: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
19970: }
19971: }
19972: if ($currorder ne join(',',@orderedstatus)) {
19973: $changes{'inststatus'}{'inststatusorder'} = 1;
19974: }
19975: my $newtitles;
19976: foreach my $item (@orderedstatus) {
19977: $newtitles .= $alltypes{$item}.',';
19978: }
19979: $newtitles =~ s/,$//;
19980: if ($currtitles ne $newtitles) {
19981: $changes{'inststatus'}{'inststatustypes'} = 1;
19982: }
1.43 raeburn 19983: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
19984: $dom);
19985: if ($putresult eq 'ok') {
19986: if (keys(%changes) > 0) {
19987: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 19988: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 19989: 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";
19990: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 19991: if ($item eq 'inststatus') {
19992: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 19993: if (@orderedstatus) {
1.236 raeburn 19994: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
19995: foreach my $type (@orderedstatus) {
19996: $resulttext .= $alltypes{$type}.', ';
19997: }
19998: $resulttext =~ s/, $//;
19999: $resulttext .= '</li>';
1.305 raeburn 20000: } else {
1.425 raeburn 20001: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 20002: }
20003: }
1.409 raeburn 20004: } elsif ($item eq 'unamemap_rule') {
20005: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20006: my @rulenames;
20007: if (ref($unamemaprules) eq 'HASH') {
20008: foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
20009: if (ref($unamemaprules->{$rule}) eq 'HASH') {
20010: push(@rulenames,$unamemaprules->{$rule}->{'name'});
20011: }
20012: }
20013: }
20014: if (@rulenames) {
20015: $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
20016: '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
20017: '</li>';
20018: } else {
20019: $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
20020: }
20021: } else {
20022: $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
20023: }
1.236 raeburn 20024: } else {
20025: my $value = $env{'form.'.$item};
20026: if ($value eq '') {
20027: $value = &mt('none');
20028: } elsif ($item eq 'auth_def') {
20029: my %authnames = &authtype_names();
20030: my %shortauth = (
20031: internal => 'int',
20032: krb4 => 'krb4',
20033: krb5 => 'krb5',
20034: localauth => 'loc',
1.325 raeburn 20035: lti => 'lti',
1.236 raeburn 20036: );
20037: $value = $authnames{$shortauth{$value}};
20038: }
20039: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
1.414 raeburn 20040: $mailmsgtext .= "$title->{$item} set to $value\n";
20041: if ($item eq 'portal_def') {
20042: if ($env{'form.'.$item} ne '') {
20043: foreach my $field ('email','web') {
20044: $value = $env{'form.'.$item.'_'.$field};
20045: if ($value) {
20046: $value = &mt('Yes');
20047: } else {
20048: $value = &mt('No');
20049: }
20050: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$field},$value).'</li>';
20051: }
20052: }
20053: }
1.43 raeburn 20054: }
20055: }
20056: $resulttext .= '</ul>';
20057: $mailmsgtext .= "\n";
20058: my $cachetime = 24*60*60;
1.72 raeburn 20059: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 20060: if (ref($lastactref) eq 'HASH') {
20061: $lastactref->{'domdefaults'} = 1;
20062: }
1.68 raeburn 20063: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 20064: my $notify = 1;
20065: if (ref($domconfig{'contacts'}) eq 'HASH') {
20066: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
20067: $notify = 0;
20068: }
20069: }
20070: if ($notify) {
20071: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
20072: "LON-CAPA Domain Settings Change - $dom",
20073: $mailmsgtext);
20074: }
1.54 raeburn 20075: }
1.43 raeburn 20076: } else {
1.54 raeburn 20077: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 20078: }
20079: } else {
20080: $resulttext = '<span class="LC_error">'.
20081: &mt('An error occurred: [_1]',$putresult).'</span>';
20082: }
20083: if (@errors > 0) {
20084: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
20085: foreach my $item (@errors) {
20086: $resulttext .= ' "'.$title->{$item}.'",';
20087: }
20088: $resulttext =~ s/,$//;
20089: }
20090: return $resulttext;
20091: }
20092:
1.46 raeburn 20093: sub modify_scantron {
1.205 raeburn 20094: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 20095: my ($resulttext,%confhash,%changes,$errors);
20096: my $custom = 'custom.tab';
20097: my $default = 'default.tab';
20098: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 20099: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 20100: &config_check($dom,$confname,$servadm);
20101: if ($env{'form.scantronformat.filename'} ne '') {
20102: my $error;
20103: if ($configuserok eq 'ok') {
20104: if ($switchserver) {
1.130 raeburn 20105: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 20106: } else {
20107: if ($author_ok eq 'ok') {
1.421 raeburn 20108: my $modified = [];
1.46 raeburn 20109: my ($result,$scantronurl) =
1.421 raeburn 20110: &Apache::lonconfigsettings::publishlogo($r,'upload','scantronformat',$dom,
20111: $confname,'scantron','','',$custom,
20112: $modified);
1.46 raeburn 20113: if ($result eq 'ok') {
20114: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 20115: $changes{'scantronformat'} = 1;
1.421 raeburn 20116: &update_modify_urls($r,$modified);
1.46 raeburn 20117: } else {
20118: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
20119: }
20120: } else {
20121: $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);
20122: }
20123: }
20124: } else {
20125: $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);
20126: }
20127: if ($error) {
20128: &Apache::lonnet::logthis($error);
20129: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
20130: }
20131: }
1.48 raeburn 20132: if (ref($domconfig{'scantron'}) eq 'HASH') {
20133: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
20134: if ($env{'form.scantronformat_del'}) {
20135: $confhash{'scantron'}{'scantronformat'} = '';
20136: $changes{'scantronformat'} = 1;
1.347 raeburn 20137: } else {
20138: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 20139: }
20140: }
20141: }
1.347 raeburn 20142: my @options = ('hdr','pad','rem');
1.346 raeburn 20143: my @fields = &scantroncsv_fields();
20144: my %titles = &scantronconfig_titles();
1.347 raeburn 20145: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 20146: my ($newdat,$currdat,%newcol,%currcol);
20147: if (grep(/^dat$/,@formats)) {
20148: $confhash{'scantron'}{config}{dat} = 1;
20149: $newdat = 1;
20150: } else {
20151: $newdat = 0;
20152: }
20153: if (grep(/^csv$/,@formats)) {
20154: my %bynum;
20155: foreach my $field (@fields) {
20156: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
20157: my $posscol = $1;
20158: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 20159: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 20160: $bynum{$posscol} = $field;
20161: $newcol{$field} = $posscol;
20162: }
20163: }
20164: }
1.347 raeburn 20165: if (keys(%newcol)) {
20166: foreach my $option (@options) {
20167: if ($env{'form.scantroncsv_'.$option}) {
20168: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
20169: }
20170: }
20171: }
1.346 raeburn 20172: }
20173: $currdat = 1;
20174: if (ref($domconfig{'scantron'}) eq 'HASH') {
20175: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 20176: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 20177: $currdat = 0;
20178: }
20179: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20180: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20181: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
20182: }
1.346 raeburn 20183: }
20184: }
20185: }
20186: if ($currdat != $newdat) {
20187: $changes{'config'} = 1;
20188: } else {
20189: foreach my $field (@fields) {
20190: if ($currcol{$field} ne '') {
20191: if ($currcol{$field} ne $newcol{$field}) {
20192: $changes{'config'} = 1;
20193: last;
1.347 raeburn 20194: }
1.346 raeburn 20195: } elsif ($newcol{$field} ne '') {
20196: $changes{'config'} = 1;
20197: last;
20198: }
20199: }
20200: }
1.46 raeburn 20201: if (keys(%confhash) > 0) {
20202: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
20203: $dom);
20204: if ($putresult eq 'ok') {
20205: if (keys(%changes) > 0) {
1.48 raeburn 20206: if (ref($confhash{'scantron'}) eq 'HASH') {
20207: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 20208: if ($changes{'scantronformat'}) {
20209: if ($confhash{'scantron'}{'scantronformat'} eq '') {
20210: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
20211: } else {
20212: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
20213: }
20214: }
1.347 raeburn 20215: if ($changes{'config'}) {
1.346 raeburn 20216: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
20217: if ($confhash{'scantron'}{'config'}{'dat'}) {
20218: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
20219: }
20220: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20221: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20222: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
20223: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
20224: foreach my $field (@fields) {
20225: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
20226: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
20227: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
20228: }
20229: }
20230: $resulttext .= '</ul></li>';
20231: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
20232: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
20233: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
20234: foreach my $option (@options) {
20235: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
20236: $resulttext .= '<li>'.$titles{$option}.'</li>';
20237: }
20238: }
20239: $resulttext .= '</ul></li>';
20240: }
1.346 raeburn 20241: }
20242: }
20243: }
20244: }
20245: } else {
20246: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
20247: }
1.46 raeburn 20248: }
1.48 raeburn 20249: $resulttext .= '</ul>';
20250: } else {
1.130 raeburn 20251: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 20252: }
20253: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 20254: if (ref($lastactref) eq 'HASH') {
20255: $lastactref->{'domainconfig'} = 1;
20256: }
1.46 raeburn 20257: } else {
1.346 raeburn 20258: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 20259: }
20260: } else {
20261: $resulttext = '<span class="LC_error">'.
20262: &mt('An error occurred: [_1]',$putresult).'</span>';
20263: }
20264: } else {
1.130 raeburn 20265: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 20266: }
20267: if ($errors) {
1.353 raeburn 20268: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
20269: $errors.'</ul></p>';
1.46 raeburn 20270: }
20271: return $resulttext;
20272: }
20273:
1.48 raeburn 20274: sub modify_coursecategories {
1.239 raeburn 20275: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 20276: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
20277: $cathash);
1.48 raeburn 20278: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 20279: my @catitems = ('unauth','auth');
20280: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 20281: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 20282: $cathash = $domconfig{'coursecategories'}{'cats'};
20283: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
20284: $changes{'togglecats'} = 1;
20285: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
20286: }
20287: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
20288: $changes{'categorize'} = 1;
20289: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
20290: }
1.120 raeburn 20291: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
20292: $changes{'togglecatscomm'} = 1;
20293: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
20294: }
20295: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
20296: $changes{'categorizecomm'} = 1;
20297: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 20298:
20299: }
20300: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
20301: $changes{'togglecatsplace'} = 1;
20302: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
20303: }
20304: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
20305: $changes{'categorizeplace'} = 1;
20306: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 20307: }
1.238 raeburn 20308: foreach my $item (@catitems) {
20309: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20310: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
20311: $changes{$item} = 1;
20312: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20313: }
20314: }
20315: }
1.57 raeburn 20316: } else {
20317: $changes{'togglecats'} = 1;
20318: $changes{'categorize'} = 1;
1.124 raeburn 20319: $changes{'togglecatscomm'} = 1;
20320: $changes{'categorizecomm'} = 1;
1.272 raeburn 20321: $changes{'togglecatsplace'} = 1;
20322: $changes{'categorizeplace'} = 1;
1.87 raeburn 20323: $domconfig{'coursecategories'} = {
20324: togglecats => $env{'form.togglecats'},
20325: categorize => $env{'form.categorize'},
1.124 raeburn 20326: togglecatscomm => $env{'form.togglecatscomm'},
20327: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 20328: togglecatsplace => $env{'form.togglecatsplace'},
20329: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 20330: };
1.238 raeburn 20331: foreach my $item (@catitems) {
20332: if ($env{'form.coursecat_'.$item} ne 'std') {
20333: $changes{$item} = 1;
20334: }
20335: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20336: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20337: }
20338: }
1.57 raeburn 20339: }
20340: if (ref($cathash) eq 'HASH') {
20341: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 20342: push (@deletecategory,'instcode::0');
20343: }
1.120 raeburn 20344: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
20345: push(@deletecategory,'communities::0');
20346: }
1.272 raeburn 20347: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
20348: push(@deletecategory,'placement::0');
20349: }
1.48 raeburn 20350: }
1.57 raeburn 20351: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
20352: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20353: if (@deletecategory > 0) {
20354: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 20355: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 20356: foreach my $item (@deletecategory) {
1.57 raeburn 20357: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
20358: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 20359: $deletions{$item} = 1;
1.57 raeburn 20360: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 20361: }
20362: }
20363: }
1.57 raeburn 20364: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 20365: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 20366: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 20367: $reorderings{$item} = 1;
1.57 raeburn 20368: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 20369: }
20370: if ($env{'form.addcategory_name_'.$item} ne '') {
20371: my $newcat = $env{'form.addcategory_name_'.$item};
20372: my $newdepth = $depth+1;
20373: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20374: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 20375: $adds{$newitem} = 1;
20376: }
20377: if ($env{'form.subcat_'.$item} ne '') {
20378: my $newcat = $env{'form.subcat_'.$item};
20379: my $newdepth = $depth+1;
20380: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20381: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 20382: $adds{$newitem} = 1;
20383: }
20384: }
20385: }
20386: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 20387: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20388: my $newitem = 'instcode::0';
1.57 raeburn 20389: if ($cathash->{$newitem} eq '') {
20390: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20391: $adds{$newitem} = 1;
20392: }
20393: } else {
20394: my $newitem = 'instcode::0';
1.57 raeburn 20395: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20396: $adds{$newitem} = 1;
20397: }
20398: }
1.120 raeburn 20399: if ($env{'form.communities'} eq '1') {
20400: if (ref($cathash) eq 'HASH') {
20401: my $newitem = 'communities::0';
20402: if ($cathash->{$newitem} eq '') {
20403: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20404: $adds{$newitem} = 1;
20405: }
20406: } else {
20407: my $newitem = 'communities::0';
20408: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20409: $adds{$newitem} = 1;
20410: }
20411: }
1.272 raeburn 20412: if ($env{'form.placement'} eq '1') {
20413: if (ref($cathash) eq 'HASH') {
20414: my $newitem = 'placement::0';
20415: if ($cathash->{$newitem} eq '') {
20416: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20417: $adds{$newitem} = 1;
20418: }
20419: } else {
20420: my $newitem = 'placement::0';
20421: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20422: $adds{$newitem} = 1;
20423: }
20424: }
1.48 raeburn 20425: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 20426: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 20427: ($env{'form.addcategory_name'} ne 'communities') &&
20428: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 20429: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
20430: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
20431: $adds{$newitem} = 1;
20432: }
1.48 raeburn 20433: }
1.57 raeburn 20434: my $putresult;
1.48 raeburn 20435: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20436: if (keys(%deletions) > 0) {
20437: foreach my $key (keys(%deletions)) {
20438: if ($predelallitems{$key} ne '') {
20439: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
20440: }
20441: }
20442: }
20443: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 20444: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 20445: if (ref($chkcats[0]) eq 'ARRAY') {
20446: my $depth = 0;
20447: my $chg = 0;
20448: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
20449: my $name = $chkcats[0][$i];
20450: my $item;
20451: if ($name eq '') {
20452: $chg ++;
20453: } else {
20454: $item = &escape($name).'::0';
20455: if ($chg) {
1.57 raeburn 20456: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 20457: }
20458: $depth ++;
1.57 raeburn 20459: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 20460: $depth --;
20461: }
20462: }
20463: }
1.57 raeburn 20464: }
20465: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20466: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 20467: if ($putresult eq 'ok') {
1.57 raeburn 20468: my %title = (
1.120 raeburn 20469: togglecats => 'Show/Hide a course in catalog',
20470: categorize => 'Assign a category to a course',
20471: togglecatscomm => 'Show/Hide a community in catalog',
20472: categorizecomm => 'Assign a category to a community',
1.57 raeburn 20473: );
20474: my %level = (
1.120 raeburn 20475: dom => 'set in Domain ("Modify Course/Community")',
20476: crs => 'set in Course ("Course Configuration")',
20477: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 20478: none => 'No catalog',
20479: std => 'Standard catalog',
20480: domonly => 'Domain-only catalog',
20481: codesrch => 'Code search form',
1.57 raeburn 20482: );
1.48 raeburn 20483: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 20484: if ($changes{'togglecats'}) {
20485: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
20486: }
20487: if ($changes{'categorize'}) {
20488: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 20489: }
1.120 raeburn 20490: if ($changes{'togglecatscomm'}) {
20491: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
20492: }
20493: if ($changes{'categorizecomm'}) {
20494: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
20495: }
1.238 raeburn 20496: if ($changes{'unauth'}) {
20497: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
20498: }
20499: if ($changes{'auth'}) {
20500: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
20501: }
1.57 raeburn 20502: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20503: my $cathash;
20504: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
20505: $cathash = $domconfig{'coursecategories'}{'cats'};
20506: } else {
20507: $cathash = {};
20508: }
20509: my (@cats,@trails,%allitems);
20510: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
20511: if (keys(%deletions) > 0) {
20512: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
20513: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
20514: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
20515: }
20516: $resulttext .= '</ul></li>';
20517: }
20518: if (keys(%reorderings) > 0) {
20519: my %sort_by_trail;
20520: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
20521: foreach my $key (keys(%reorderings)) {
20522: if ($allitems{$key} ne '') {
20523: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20524: }
1.48 raeburn 20525: }
1.57 raeburn 20526: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20527: $resulttext .= '<li>'.$trails[$trail].'</li>';
20528: }
20529: $resulttext .= '</ul></li>';
1.48 raeburn 20530: }
1.57 raeburn 20531: if (keys(%adds) > 0) {
20532: my %sort_by_trail;
20533: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
20534: foreach my $key (keys(%adds)) {
20535: if ($allitems{$key} ne '') {
20536: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20537: }
20538: }
20539: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20540: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 20541: }
1.57 raeburn 20542: $resulttext .= '</ul></li>';
1.48 raeburn 20543: }
1.364 raeburn 20544: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
20545: if (ref($lastactref) eq 'HASH') {
20546: $lastactref->{'cats'} = 1;
20547: }
1.48 raeburn 20548: }
20549: $resulttext .= '</ul>';
1.239 raeburn 20550: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 20551: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
20552: if ($changes{'auth'}) {
20553: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
20554: }
20555: if ($changes{'unauth'}) {
20556: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
20557: }
20558: my $cachetime = 24*60*60;
20559: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 20560: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 20561: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 20562: }
20563: }
1.48 raeburn 20564: } else {
20565: $resulttext = '<span class="LC_error">'.
1.57 raeburn 20566: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 20567: }
20568: } else {
1.120 raeburn 20569: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 20570: }
20571: return $resulttext;
20572: }
20573:
1.69 raeburn 20574: sub modify_serverstatuses {
20575: my ($dom,%domconfig) = @_;
20576: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
20577: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
20578: %currserverstatus = %{$domconfig{'serverstatuses'}};
20579: }
20580: my @pages = &serverstatus_pages();
20581: foreach my $type (@pages) {
20582: $newserverstatus{$type}{'namedusers'} = '';
20583: $newserverstatus{$type}{'machines'} = '';
20584: if (defined($env{'form.'.$type.'_namedusers'})) {
20585: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
20586: my @okusers;
20587: foreach my $user (@users) {
20588: my ($uname,$udom) = split(/:/,$user);
20589: if (($udom =~ /^$match_domain$/) &&
20590: (&Apache::lonnet::domain($udom)) &&
20591: ($uname =~ /^$match_username$/)) {
20592: if (!grep(/^\Q$user\E/,@okusers)) {
20593: push(@okusers,$user);
20594: }
20595: }
20596: }
20597: if (@okusers > 0) {
20598: @okusers = sort(@okusers);
20599: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
20600: }
20601: }
20602: if (defined($env{'form.'.$type.'_machines'})) {
20603: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
20604: my @okmachines;
20605: foreach my $ip (@machines) {
20606: my @parts = split(/\./,$ip);
20607: next if (@parts < 4);
20608: my $badip = 0;
20609: for (my $i=0; $i<4; $i++) {
20610: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
20611: $badip = 1;
20612: last;
20613: }
20614: }
20615: if (!$badip) {
20616: push(@okmachines,$ip);
20617: }
20618: }
20619: @okmachines = sort(@okmachines);
20620: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
20621: }
20622: }
20623: my %serverstatushash = (
20624: serverstatuses => \%newserverstatus,
20625: );
20626: foreach my $type (@pages) {
1.83 raeburn 20627: foreach my $setting ('namedusers','machines') {
1.84 raeburn 20628: my (@current,@new);
1.83 raeburn 20629: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 20630: if ($currserverstatus{$type}{$setting} ne '') {
20631: @current = split(/,/,$currserverstatus{$type}{$setting});
20632: }
20633: }
20634: if ($newserverstatus{$type}{$setting} ne '') {
20635: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 20636: }
20637: if (@current > 0) {
20638: if (@new > 0) {
20639: foreach my $item (@current) {
20640: if (!grep(/^\Q$item\E$/,@new)) {
20641: $changes{$type}{$setting} = 1;
1.82 raeburn 20642: last;
20643: }
20644: }
1.84 raeburn 20645: foreach my $item (@new) {
20646: if (!grep(/^\Q$item\E$/,@current)) {
20647: $changes{$type}{$setting} = 1;
20648: last;
1.82 raeburn 20649: }
20650: }
20651: } else {
1.83 raeburn 20652: $changes{$type}{$setting} = 1;
1.69 raeburn 20653: }
1.83 raeburn 20654: } elsif (@new > 0) {
20655: $changes{$type}{$setting} = 1;
1.69 raeburn 20656: }
20657: }
20658: }
20659: if (keys(%changes) > 0) {
1.81 raeburn 20660: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 20661: my $putresult = &Apache::lonnet::put_dom('configuration',
20662: \%serverstatushash,$dom);
20663: if ($putresult eq 'ok') {
20664: $resulttext .= &mt('Changes made:').'<ul>';
20665: foreach my $type (@pages) {
1.84 raeburn 20666: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 20667: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 20668: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 20669: if ($newserverstatus{$type}{'namedusers'} eq '') {
20670: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
20671: } else {
20672: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
20673: }
1.84 raeburn 20674: }
20675: if ($changes{$type}{'machines'}) {
1.69 raeburn 20676: if ($newserverstatus{$type}{'machines'} eq '') {
20677: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
20678: } else {
20679: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
20680: }
20681:
20682: }
20683: $resulttext .= '</ul></li>';
20684: }
20685: }
20686: $resulttext .= '</ul>';
20687: } else {
20688: $resulttext = '<span class="LC_error">'.
20689: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
20690:
20691: }
20692: } else {
20693: $resulttext = &mt('No changes made to access to server status pages');
20694: }
20695: return $resulttext;
20696: }
20697:
1.118 jms 20698: sub modify_helpsettings {
1.285 raeburn 20699: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 20700: my ($resulttext,$errors,%changes,%helphash);
20701: my %defaultchecked = ('submitbugs' => 'on');
20702: my @offon = ('off','on');
1.118 jms 20703: my @toggles = ('submitbugs');
1.285 raeburn 20704: my %current = ('submitbugs' => '',
20705: 'adhoc' => {},
20706: );
1.118 jms 20707: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 20708: %current = %{$domconfig{'helpsettings'}};
20709: }
1.285 raeburn 20710: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 20711: foreach my $item (@toggles) {
20712: if ($defaultchecked{$item} eq 'on') {
20713: if ($current{$item} eq '') {
20714: if ($env{'form.'.$item} eq '0') {
20715: $changes{$item} = 1;
20716: }
20717: } elsif ($current{$item} ne $env{'form.'.$item}) {
20718: $changes{$item} = 1;
20719: }
20720: } elsif ($defaultchecked{$item} eq 'off') {
20721: if ($current{$item} eq '') {
20722: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 20723: $changes{$item} = 1;
20724: }
1.282 raeburn 20725: } elsif ($current{$item} ne $env{'form.'.$item}) {
20726: $changes{$item} = 1;
20727: }
20728: }
20729: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
20730: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
20731: }
20732: }
1.285 raeburn 20733: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 20734: my $confname = $dom.'-domainconfig';
20735: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 20736: my (@allpos,%newsettings,%changedprivs,$newrole);
20737: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 20738: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 20739: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 20740: my %lt = &Apache::lonlocal::texthash(
20741: s => 'system',
20742: d => 'domain',
20743: order => 'Display order',
20744: access => 'Role usage',
1.291 raeburn 20745: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 20746: dh => 'All with domain helpdesk role',
20747: da => 'All with domain helpdesk assistant role',
1.285 raeburn 20748: none => 'None',
20749: status => 'Determined based on institutional status',
20750: inc => 'Include all, but exclude specific personnel',
20751: exc => 'Exclude all, but include specific personnel',
20752: );
20753: for (my $num=0; $num<=$maxnum; $num++) {
20754: my ($prefix,$identifier,$rolename,%curr);
20755: if ($num == $maxnum) {
20756: next unless ($env{'form.newcusthelp'} == $maxnum);
20757: $identifier = 'custhelp'.$num;
20758: $prefix = 'helproles_'.$num;
20759: $rolename = $env{'form.custhelpname'.$num};
20760: $rolename=~s/[^A-Za-z0-9]//gs;
20761: next if ($rolename eq '');
20762: next if (exists($existing{'rolesdef_'.$rolename}));
20763: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
20764: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
20765: $newprivs{'c'},$confname,$dom);
20766: if ($result ne 'ok') {
20767: $errors .= '<li><span class="LC_error">'.
20768: &mt('An error occurred storing the new custom role: [_1]',
20769: $result).'</span></li>';
20770: next;
20771: } else {
20772: $changedprivs{$rolename} = \%newprivs;
20773: $newrole = $rolename;
20774: }
20775: } else {
20776: $prefix = 'helproles_'.$num;
20777: $rolename = $env{'form.'.$prefix};
20778: next if ($rolename eq '');
20779: next unless (exists($existing{'rolesdef_'.$rolename}));
20780: $identifier = 'custhelp'.$num;
20781: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
20782: my %currprivs;
1.289 raeburn 20783: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 20784: split(/\_/,$existing{'rolesdef_'.$rolename});
20785: foreach my $level ('c','d','s') {
20786: if ($newprivs{$level} ne $currprivs{$level}) {
20787: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
20788: $newprivs{'c'},$confname,$dom);
20789: if ($result ne 'ok') {
20790: $errors .= '<li><span class="LC_error">'.
20791: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
20792: $rolename,$result).'</span></li>';
20793: } else {
20794: $changedprivs{$rolename} = \%newprivs;
20795: }
20796: last;
20797: }
20798: }
20799: if (ref($current{'adhoc'}) eq 'HASH') {
20800: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
20801: %curr = %{$current{'adhoc'}{$rolename}};
20802: }
20803: }
20804: }
20805: my $newpos = $env{'form.'.$prefix.'_pos'};
20806: $newpos =~ s/\D+//g;
20807: $allpos[$newpos] = $rolename;
20808: my $newdesc = $env{'form.'.$prefix.'_desc'};
20809: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
20810: if ($curr{'desc'}) {
20811: if ($curr{'desc'} ne $newdesc) {
20812: $changes{'customrole'}{$rolename}{'desc'} = 1;
20813: $newsettings{$rolename}{'desc'} = $newdesc;
20814: }
20815: } elsif ($newdesc ne '') {
20816: $changes{'customrole'}{$rolename}{'desc'} = 1;
20817: $newsettings{$rolename}{'desc'} = $newdesc;
20818: }
20819: my $access = $env{'form.'.$prefix.'_access'};
20820: if (grep(/^\Q$access\E$/,@accesstypes)) {
20821: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
20822: if ($access eq 'status') {
20823: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
20824: if (scalar(@statuses) == 0) {
1.289 raeburn 20825: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 20826: } else {
20827: my (@shownstatus,$numtypes);
20828: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
20829: if (ref($types) eq 'ARRAY') {
20830: $numtypes = scalar(@{$types});
20831: foreach my $type (sort(@statuses)) {
20832: if ($type eq 'default') {
20833: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
20834: } elsif (grep(/^\Q$type\E$/,@{$types})) {
20835: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
20836: push(@shownstatus,$usertypes->{$type});
20837: }
20838: }
20839: }
20840: if (grep(/^default$/,@statuses)) {
20841: push(@shownstatus,$othertitle);
20842: }
20843: if (scalar(@shownstatus) == 1+$numtypes) {
20844: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
20845: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
20846: } else {
20847: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
20848: if (ref($curr{'status'}) eq 'ARRAY') {
20849: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
20850: if (@diffs) {
20851: $changes{'customrole'}{$rolename}{$access} = 1;
20852: }
20853: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
20854: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 20855: }
1.166 raeburn 20856: }
20857: }
1.285 raeburn 20858: } elsif (($access eq 'inc') || ($access eq 'exc')) {
20859: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
20860: my @newspecstaff;
20861: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
20862: foreach my $person (sort(@personnel)) {
20863: if ($domhelpdesk{$person}) {
20864: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
20865: }
20866: }
20867: if (ref($curr{$access}) eq 'ARRAY') {
20868: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
20869: if (@diffs) {
20870: $changes{'customrole'}{$rolename}{$access} = 1;
20871: }
20872: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
20873: $changes{'customrole'}{$rolename}{$access} = 1;
20874: }
20875: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
20876: my ($uname,$udom) = split(/:/,$person);
20877: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
20878: }
20879: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 20880: }
1.285 raeburn 20881: } else {
20882: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
20883: }
20884: unless ($curr{'access'} eq $access) {
20885: $changes{'customrole'}{$rolename}{'access'} = 1;
20886: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 20887: }
20888: }
1.285 raeburn 20889: if (@allpos > 0) {
20890: my $idx = 0;
20891: foreach my $rolename (@allpos) {
20892: if ($rolename ne '') {
20893: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
20894: if (ref($current{'adhoc'}) eq 'HASH') {
20895: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
20896: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
20897: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 20898: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 20899: }
20900: }
1.282 raeburn 20901: }
1.285 raeburn 20902: $idx ++;
1.166 raeburn 20903: }
20904: }
1.118 jms 20905: }
1.123 jms 20906: my $putresult;
20907: if (keys(%changes) > 0) {
1.166 raeburn 20908: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 20909: if ($putresult eq 'ok') {
1.285 raeburn 20910: if (ref($helphash{'helpsettings'}) eq 'HASH') {
20911: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
20912: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
20913: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
20914: }
20915: }
20916: my $cachetime = 24*60*60;
20917: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
20918: if (ref($lastactref) eq 'HASH') {
20919: $lastactref->{'domdefaults'} = 1;
20920: }
20921: } else {
20922: $errors .= '<li><span class="LC_error">'.
20923: &mt('An error occurred storing the settings: [_1]',
20924: $putresult).'</span></li>';
20925: }
20926: }
20927: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
20928: $resulttext = &mt('Changes made:').'<ul>';
20929: my (%shownprivs,@levelorder);
20930: @levelorder = ('c','d','s');
20931: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 20932: foreach my $item (sort(keys(%changes))) {
20933: if ($item eq 'submitbugs') {
20934: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
20935: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
20936: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 20937: } elsif ($item eq 'customrole') {
20938: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 20939: my @keyorder = ('order','desc','access','status','exc','inc');
20940: my %keytext = &Apache::lonlocal::texthash(
20941: order => 'Order',
20942: desc => 'Role description',
20943: access => 'Role usage',
1.300 droeschl 20944: status => 'Allowed institutional types',
1.285 raeburn 20945: exc => 'Allowed personnel',
20946: inc => 'Disallowed personnel',
20947: );
1.282 raeburn 20948: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 20949: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
20950: if ($role eq $newrole) {
20951: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
20952: $role).'<ul>';
20953: } else {
20954: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
20955: $role).'<ul>';
20956: }
20957: foreach my $key (@keyorder) {
20958: if ($changes{'customrole'}{$role}{$key}) {
20959: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
20960: $keytext{$key},$newsettings{$role}{$key}).
20961: '</li>';
20962: }
20963: }
20964: if (ref($changedprivs{$role}) eq 'HASH') {
20965: $shownprivs{$role} = 1;
20966: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
20967: foreach my $level (@levelorder) {
20968: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
20969: next if ($item eq '');
20970: my ($priv) = split(/\&/,$item,2);
20971: if (&Apache::lonnet::plaintext($priv)) {
20972: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
20973: unless ($level eq 'c') {
20974: $resulttext .= ' ('.$lt{$level}.')';
20975: }
20976: $resulttext .= '</li>';
20977: }
20978: }
20979: }
20980: $resulttext .= '</ul>';
20981: }
20982: $resulttext .= '</ul></li>';
20983: }
20984: }
20985: }
20986: }
20987: }
20988: }
20989: if (keys(%changedprivs)) {
20990: foreach my $role (sort(keys(%changedprivs))) {
20991: unless ($shownprivs{$role}) {
20992: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
20993: $role).'<ul>'.
20994: '<li>'.&mt('Privileges set to :').'<ul>';
20995: foreach my $level (@levelorder) {
20996: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
20997: next if ($item eq '');
20998: my ($priv) = split(/\&/,$item,2);
20999: if (&Apache::lonnet::plaintext($priv)) {
21000: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
21001: unless ($level eq 'c') {
21002: $resulttext .= ' ('.$lt{$level}.')';
21003: }
21004: $resulttext .= '</li>';
21005: }
1.282 raeburn 21006: }
21007: }
1.285 raeburn 21008: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 21009: }
21010: }
21011: }
1.285 raeburn 21012: $resulttext .= '</ul>';
21013: } else {
21014: $resulttext = &mt('No changes made to help settings');
1.118 jms 21015: }
21016: if ($errors) {
1.168 raeburn 21017: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 21018: $errors.'</ul>';
1.118 jms 21019: }
21020: return $resulttext;
21021: }
21022:
1.121 raeburn 21023: sub modify_coursedefaults {
1.212 raeburn 21024: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 21025: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 21026: my %defaultchecked = (
21027: 'canuse_pdfforms' => 'off',
21028: 'uselcmath' => 'on',
1.398 raeburn 21029: 'usejsme' => 'on',
21030: 'inline_chem' => 'on',
1.404 raeburn 21031: 'ltiauth' => 'off',
1.257 raeburn 21032: );
1.404 raeburn 21033: my @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem','ltiauth');
1.198 raeburn 21034: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 21035: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
1.428 raeburn 21036: 'coursequota_official','coursequota_unofficial','coursequota_community',
21037: 'coursequota_textbook','coursequota_placement','mysqltables_official',
21038: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook',
21039: 'mysqltables_placement');
1.271 raeburn 21040: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 21041: my %staticdefaults = (
21042: anonsurvey_threshold => 10,
21043: uploadquota => 500,
1.428 raeburn 21044: coursequota => 20,
1.257 raeburn 21045: postsubmit => 60,
1.276 raeburn 21046: mysqltables => 172800,
1.422 raeburn 21047: domexttool => 1,
1.432 raeburn 21048: crsauthor => 1,
1.198 raeburn 21049: );
1.314 raeburn 21050: my %texoptions = (
21051: MathJax => 'MathJax',
21052: mimetex => &mt('Convert to Images'),
21053: tth => &mt('TeX to HTML'),
21054: );
1.121 raeburn 21055: $defaultshash{'coursedefaults'} = {};
21056:
21057: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
21058: if ($domconfig{'coursedefaults'} eq '') {
21059: $domconfig{'coursedefaults'} = {};
21060: }
21061: }
21062:
21063: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
21064: foreach my $item (@toggles) {
21065: if ($defaultchecked{$item} eq 'on') {
21066: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21067: ($env{'form.'.$item} eq '0')) {
21068: $changes{$item} = 1;
1.192 raeburn 21069: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 21070: $changes{$item} = 1;
21071: }
21072: } elsif ($defaultchecked{$item} eq 'off') {
21073: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21074: ($env{'form.'.$item} eq '1')) {
21075: $changes{$item} = 1;
21076: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
21077: $changes{$item} = 1;
21078: }
21079: }
21080: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
21081: }
1.198 raeburn 21082: foreach my $item (@numbers) {
21083: my ($currdef,$newdef);
1.208 raeburn 21084: $newdef = $env{'form.'.$item};
1.198 raeburn 21085: if ($item eq 'anonsurvey_threshold') {
21086: $currdef = $domconfig{'coursedefaults'}{$item};
21087: $newdef =~ s/\D//g;
21088: if ($newdef eq '' || $newdef < 1) {
21089: $newdef = 1;
21090: }
21091: $defaultshash{'coursedefaults'}{$item} = $newdef;
21092: } else {
1.428 raeburn 21093: my ($setting,$type) = ($item =~ /^(uploadquota|coursequota|mysqltables)_(\w+)$/);
1.276 raeburn 21094: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
21095: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 21096: }
21097: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 21098: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 21099: }
21100: if ($currdef ne $newdef) {
21101: if ($item eq 'anonsurvey_threshold') {
21102: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
21103: $changes{$item} = 1;
21104: }
1.428 raeburn 21105: } elsif ($item =~ /^(uploadquota|coursequota|mysqltables)_/) {
1.289 raeburn 21106: my $setting = $1;
1.276 raeburn 21107: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
21108: $changes{$setting} = 1;
1.198 raeburn 21109: }
21110: }
1.139 raeburn 21111: }
21112: }
1.314 raeburn 21113: my $texengine;
21114: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
21115: $texengine = $env{'form.texengine'};
1.349 raeburn 21116: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
21117: if ($currdef eq '') {
21118: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 21119: $changes{'texengine'} = 1;
21120: }
1.349 raeburn 21121: } elsif ($currdef ne $texengine) {
1.314 raeburn 21122: $changes{'texengine'} = 1;
21123: }
21124: }
21125: if ($texengine ne '') {
21126: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
21127: }
1.264 raeburn 21128: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
21129: my @currclonecode;
21130: if (ref($currclone) eq 'HASH') {
21131: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
21132: @currclonecode = @{$currclone->{'instcode'}};
21133: }
21134: }
21135: my $newclone;
1.289 raeburn 21136: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 21137: $newclone = $env{'form.canclone'};
21138: }
21139: if ($newclone eq 'instcode') {
21140: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
21141: my (%codedefaults,@code_order,@clonecode);
21142: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
21143: \@code_order);
21144: foreach my $item (@code_order) {
21145: if (grep(/^\Q$item\E$/,@newcodes)) {
21146: push(@clonecode,$item);
21147: }
21148: }
21149: if (@clonecode) {
21150: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
21151: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
21152: if (@diffs) {
21153: $changes{'canclone'} = 1;
21154: }
21155: } else {
21156: $newclone eq '';
21157: }
21158: } elsif ($newclone ne '') {
1.289 raeburn 21159: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
21160: }
1.264 raeburn 21161: if ($newclone ne $currclone) {
21162: $changes{'canclone'} = 1;
21163: }
1.257 raeburn 21164: my %credits;
21165: foreach my $type (@types) {
21166: unless ($type eq 'community') {
21167: $credits{$type} = $env{'form.'.$type.'_credits'};
21168: $credits{$type} =~ s/[^\d.]+//g;
21169: }
21170: }
21171: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
21172: ($env{'form.coursecredits'} eq '1')) {
21173: $changes{'coursecredits'} = 1;
21174: foreach my $type (keys(%credits)) {
21175: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21176: }
21177: } else {
1.289 raeburn 21178: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 21179: foreach my $type (@types) {
21180: unless ($type eq 'community') {
1.289 raeburn 21181: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 21182: $changes{'coursecredits'} = 1;
21183: }
21184: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21185: }
21186: }
21187: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21188: foreach my $type (@types) {
21189: unless ($type eq 'community') {
21190: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
21191: $changes{'coursecredits'} = 1;
21192: last;
21193: }
21194: }
21195: }
21196: }
21197: }
21198: if ($env{'form.postsubmit'} eq '1') {
21199: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
21200: my %currtimeout;
21201: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21202: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
21203: $changes{'postsubmit'} = 1;
21204: }
21205: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21206: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
21207: }
21208: } else {
21209: $changes{'postsubmit'} = 1;
21210: }
21211: foreach my $type (@types) {
21212: my $timeout = $env{'form.'.$type.'_timeout'};
21213: $timeout =~ s/\D//g;
21214: if ($timeout == $staticdefaults{'postsubmit'}) {
21215: $timeout = '';
21216: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
21217: $timeout = '0';
21218: }
21219: unless ($timeout eq '') {
21220: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
21221: }
21222: if (exists($currtimeout{$type})) {
21223: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 21224: $changes{'postsubmit'} = 1;
1.257 raeburn 21225: }
21226: } elsif ($timeout ne '') {
21227: $changes{'postsubmit'} = 1;
21228: }
21229: }
21230: } else {
21231: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
21232: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21233: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
21234: $changes{'postsubmit'} = 1;
21235: }
21236: } else {
21237: $changes{'postsubmit'} = 1;
21238: }
1.192 raeburn 21239: }
1.432 raeburn 21240: my (%newdomexttool,%newexttool,%newcrsauthor,%olddomexttool,%oldexttool,%oldcrsauthor);
1.422 raeburn 21241: map { $newdomexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.domexttool');
1.425 raeburn 21242: map { $newexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.exttool');
1.432 raeburn 21243: map { $newcrsauthor{$_} = 1; } &Apache::loncommon::get_env_multiple('form.crsauthor');
1.422 raeburn 21244: if (ref($domconfig{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21245: %olddomexttool = %{$domconfig{'coursedefaults'}{'domexttool'}};
21246: } else {
21247: foreach my $type (@types) {
21248: if ($staticdefaults{'domexttool'}) {
21249: $olddomexttool{$type} = 1;
21250: } else {
21251: $olddomexttool{$type} = 0;
21252: }
21253: }
21254: }
21255: if (ref($domconfig{'coursedefaults'}{'exttool'}) eq 'HASH') {
1.425 raeburn 21256: %oldexttool = %{$domconfig{'coursedefaults'}{'exttool'}};
1.422 raeburn 21257: } else {
21258: foreach my $type (@types) {
21259: if ($staticdefaults{'exttool'}) {
21260: $oldexttool{$type} = 1;
21261: } else {
21262: $oldexttool{$type} = 0;
21263: }
21264: }
21265: }
1.432 raeburn 21266: if (ref($domconfig{'coursedefaults'}{'crsauthor'}) eq 'HASH') {
21267: %oldcrsauthor = %{$domconfig{'coursedefaults'}{'crsauthor'}};
21268: } else {
21269: foreach my $type (@types) {
21270: if ($staticdefaults{'crsauthor'}) {
21271: $oldcrsauthor{$type} = 1;
21272: } else {
21273: $oldcrsauthor{$type} = 0;
21274: }
21275: }
21276: }
1.422 raeburn 21277: foreach my $type (@types) {
21278: unless ($newdomexttool{$type}) {
21279: $newdomexttool{$type} = 0;
21280: }
21281: unless ($newexttool{$type}) {
21282: $newexttool{$type} = 0;
21283: }
1.432 raeburn 21284: unless ($newcrsauthor{$type}) {
21285: $newcrsauthor{$type} = 0;
21286: }
1.422 raeburn 21287: if ($newdomexttool{$type} != $olddomexttool{$type}) {
21288: $changes{'domexttool'} = 1;
21289: }
21290: if ($newexttool{$type} != $oldexttool{$type}) {
21291: $changes{'exttool'} = 1;
21292: }
1.432 raeburn 21293: if ($newcrsauthor{$type} != $oldcrsauthor{$type}) {
21294: $changes{'crsauthor'} = 1;
21295: }
1.422 raeburn 21296: }
21297: $defaultshash{'coursedefaults'}{'domexttool'} = \%newdomexttool;
21298: $defaultshash{'coursedefaults'}{'exttool'} = \%newexttool;
1.432 raeburn 21299: $defaultshash{'coursedefaults'}{'crsauthor'} = \%newcrsauthor;
1.121 raeburn 21300: }
21301: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21302: $dom);
21303: if ($putresult eq 'ok') {
21304: if (keys(%changes) > 0) {
1.213 raeburn 21305: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 21306: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 21307: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.398 raeburn 21308: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
1.422 raeburn 21309: ($changes{'inline_chem'}) || ($changes{'ltiauth'}) || ($changes{'domexttool'}) ||
1.432 raeburn 21310: ($changes{'exttool'}) || ($changes{'coursequota'}) || ($changes{'crsauthor'})) {
1.422 raeburn 21311: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','inline_chem','texengine',
21312: 'ltiauth') {
1.257 raeburn 21313: if ($changes{$item}) {
21314: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
21315: }
1.289 raeburn 21316: }
1.192 raeburn 21317: if ($changes{'coursecredits'}) {
21318: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 21319: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
21320: $domdefaults{$type.'credits'} =
21321: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
21322: }
21323: }
21324: }
21325: if ($changes{'postsubmit'}) {
21326: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21327: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
21328: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21329: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
21330: $domdefaults{$type.'postsubtimeout'} =
21331: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21332: }
21333: }
1.192 raeburn 21334: }
21335: }
1.198 raeburn 21336: if ($changes{'uploadquota'}) {
21337: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21338: foreach my $type (@types) {
21339: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
21340: }
21341: }
21342: }
1.428 raeburn 21343: if ($changes{'coursequota'}) {
21344: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
21345: foreach my $type (@types) {
21346: $domdefaults{$type.'coursequota'}=$defaultshash{'coursedefaults'}{'coursequota'}{$type};
21347: }
21348: }
21349: }
1.264 raeburn 21350: if ($changes{'canclone'}) {
21351: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21352: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21353: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
21354: if (@clonecodes) {
21355: $domdefaults{'canclone'} = join('+',@clonecodes);
21356: }
21357: }
21358: } else {
21359: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
21360: }
21361: }
1.422 raeburn 21362: if ($changes{'domexttool'}) {
21363: if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21364: foreach my $type (@types) {
21365: $domdefaults{$type.'domexttool'}=$defaultshash{'coursedefaults'}{'domexttool'}{$type};
21366: }
21367: }
21368: }
21369: if ($changes{'exttool'}) {
21370: if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
21371: foreach my $type (@types) {
21372: $domdefaults{$type.'exttool'}=$defaultshash{'coursedefaults'}{'exttool'}{$type};
21373: }
21374: }
21375: }
1.432 raeburn 21376: if ($changes{'crsauthor'}) {
21377: if (ref($defaultshash{'coursedefaults'}{'crsauthor'}) eq 'HASH') {
21378: foreach my $type (@types) {
21379: $domdefaults{$type.'crsauthor'}=$defaultshash{'coursedefaults'}{'crsauthor'}{$type};
21380: }
21381: }
21382: }
1.121 raeburn 21383: my $cachetime = 24*60*60;
21384: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 21385: if (ref($lastactref) eq 'HASH') {
21386: $lastactref->{'domdefaults'} = 1;
21387: }
1.121 raeburn 21388: }
21389: $resulttext = &mt('Changes made:').'<ul>';
21390: foreach my $item (sort(keys(%changes))) {
21391: if ($item eq 'canuse_pdfforms') {
21392: if ($env{'form.'.$item} eq '1') {
21393: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
21394: } else {
21395: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
21396: }
1.257 raeburn 21397: } elsif ($item eq 'uselcmath') {
21398: if ($env{'form.'.$item} eq '1') {
21399: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
21400: } else {
21401: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
21402: }
21403: } elsif ($item eq 'usejsme') {
21404: if ($env{'form.'.$item} eq '1') {
21405: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
21406: } else {
1.289 raeburn 21407: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 21408: }
1.398 raeburn 21409: } elsif ($item eq 'inline_chem') {
21410: if ($env{'form.'.$item} eq '1') {
21411: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
21412: } else {
21413: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
21414: }
1.314 raeburn 21415: } elsif ($item eq 'texengine') {
21416: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
21417: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
21418: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
21419: }
1.139 raeburn 21420: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 21421: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 21422: } elsif ($item eq 'uploadquota') {
21423: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21424: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
21425: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
21426: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 21427: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 21428: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 21429: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
21430: '</ul>'.
21431: '</li>';
21432: } else {
21433: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
21434: }
1.428 raeburn 21435: } elsif ($item eq 'coursequota') {
21436: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
21437: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course set as follows:').'<ul>'.
21438: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'official'}.'</b>').'</li>'.
21439: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'unofficial'}.'</b>').'</li>'.
21440: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'textbook'}.'</b>').'</li>'.
21441: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'placement'}.'</b>').'</li>'.
21442: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'community'}.'</b>').'</li>'.
21443: '</ul>'.
21444: '</li>';
21445: } else {
21446: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course remains default: [_1] MB',$staticdefaults{'coursequota'}).'</li>';
21447: }
1.276 raeburn 21448: } elsif ($item eq 'mysqltables') {
21449: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
21450: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
21451: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
21452: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
21453: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
21454: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
21455: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
21456: '</ul>'.
21457: '</li>';
21458: } else {
21459: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
21460: }
1.257 raeburn 21461: } elsif ($item eq 'postsubmit') {
21462: if ($domdefaults{'postsubmit'} eq 'off') {
21463: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
21464: } else {
21465: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 21466: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 21467: $resulttext .= &mt('durations:').'<ul>';
21468: foreach my $type (@types) {
21469: $resulttext .= '<li>';
21470: my $timeout;
21471: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21472: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21473: }
21474: my $display;
21475: if ($timeout eq '0') {
21476: $display = &mt('unlimited');
21477: } elsif ($timeout eq '') {
21478: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
21479: } else {
21480: $display = &mt('[quant,_1,second]',$timeout);
21481: }
21482: if ($type eq 'community') {
21483: $resulttext .= &mt('Communities');
21484: } elsif ($type eq 'official') {
21485: $resulttext .= &mt('Official courses');
21486: } elsif ($type eq 'unofficial') {
21487: $resulttext .= &mt('Unofficial courses');
21488: } elsif ($type eq 'textbook') {
21489: $resulttext .= &mt('Textbook courses');
1.271 raeburn 21490: } elsif ($type eq 'placement') {
21491: $resulttext .= &mt('Placement tests');
1.257 raeburn 21492: }
21493: $resulttext .= ' -- '.$display.'</li>';
21494: }
21495: $resulttext .= '</ul>';
21496: }
1.289 raeburn 21497: $resulttext .= '</li>';
1.257 raeburn 21498: }
1.192 raeburn 21499: } elsif ($item eq 'coursecredits') {
21500: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21501: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 21502: ($domdefaults{'unofficialcredits'} eq '') &&
21503: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 21504: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21505: } else {
21506: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
21507: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
21508: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 21509: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 21510: '</ul>'.
21511: '</li>';
21512: }
21513: } else {
21514: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21515: }
1.264 raeburn 21516: } elsif ($item eq 'canclone') {
21517: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21518: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21519: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
21520: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
21521: }
21522: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
21523: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
21524: } else {
1.289 raeburn 21525: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 21526: }
1.404 raeburn 21527: } elsif ($item eq 'ltiauth') {
21528: if ($env{'form.'.$item} eq '1') {
21529: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
21530: } else {
21531: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
21532: }
1.432 raeburn 21533: } elsif (($item eq 'domexttool') || ($item eq 'exttool') || ($item eq 'crsauthor')) {
1.422 raeburn 21534: my @noyes = (&mt('no'),&mt('yes'));
1.432 raeburn 21535: my %status = (
21536: domexttool => {
21537: ishash => &mt('External Tools defined in the domain may be used as follows:'),
21538: default => &mt('External Tools defined in the domain may be used in all course types, by default'),
21539: },
21540: exttool => {
21541: ishash => &mt('External Tools can be defined and configured in course containers as follows:'),
21542: default => &mt('External Tools can not be defined in any course types, by default'),
21543: },
21544: crsauthor => {
21545: ishash => &mt('Standard Problems can be created within course containers as follows:'),
21546: default => &mt('Standard Problems can be created within any course type, by default'),
21547: },
21548: );
21549:
21550: if (ref($defaultshash{'coursedefaults'}{$item}) eq 'HASH') {
21551: $resulttext .= '<li>'.$status{$item}{'ishash'}.'<ul>'.
21552: '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'official'}].'</b>').'</li>'.
21553: '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'unofficial'}].'</b>').'</li>'.
21554: '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'textbook'}].'</b>').'</li>'.
21555: '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'placement'}].'</b>').'</li>'.
21556: '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'community'}].'</b>').'</li>'.
1.422 raeburn 21557: '</ul>'.
21558: '</li>';
21559: } else {
1.432 raeburn 21560: $resulttext .= '<li>'.$status{$item}{'default'}.'</li>';
1.422 raeburn 21561: }
1.140 raeburn 21562: }
1.121 raeburn 21563: }
21564: $resulttext .= '</ul>';
21565: } else {
21566: $resulttext = &mt('No changes made to course defaults');
21567: }
21568: } else {
21569: $resulttext = '<span class="LC_error">'.
21570: &mt('An error occurred: [_1]',$putresult).'</span>';
21571: }
21572: return $resulttext;
21573: }
21574:
1.231 raeburn 21575: sub modify_selfenrollment {
21576: my ($dom,$lastactref,%domconfig) = @_;
21577: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 21578: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 21579: my %titles = &tool_titles();
1.232 raeburn 21580: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
21581: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 21582: $ordered{'default'} = ['types','registered','approval','limit'];
21583:
21584: my (%roles,%shown,%toplevel);
21585: $roles{'0'} = &Apache::lonnet::plaintext('dc');
21586:
21587: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
21588: if ($domconfig{'selfenrollment'} eq '') {
21589: $domconfig{'selfenrollment'} = {};
21590: }
21591: }
21592: %toplevel = (
21593: admin => 'Configuration Rights',
21594: default => 'Default settings',
21595: validation => 'Validation of self-enrollment requests',
21596: );
1.233 raeburn 21597: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 21598:
21599: if (ref($ordered{'admin'}) eq 'ARRAY') {
21600: foreach my $item (@{$ordered{'admin'}}) {
21601: foreach my $type (@types) {
21602: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
21603: $selfenrollhash{'admin'}{$type}{$item} = 1;
21604: } else {
21605: $selfenrollhash{'admin'}{$type}{$item} = 0;
21606: }
21607: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
21608: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
21609: if ($selfenrollhash{'admin'}{$type}{$item} ne
21610: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
21611: push(@{$changes{'admin'}{$type}},$item);
21612: }
21613: } else {
21614: if (!$selfenrollhash{'admin'}{$type}{$item}) {
21615: push(@{$changes{'admin'}{$type}},$item);
21616: }
21617: }
21618: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
21619: push(@{$changes{'admin'}{$type}},$item);
21620: }
21621: }
21622: }
21623: }
21624:
21625: foreach my $item (@{$ordered{'default'}}) {
21626: foreach my $type (@types) {
21627: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
21628: if ($item eq 'types') {
21629: unless (($value eq 'all') || ($value eq 'dom')) {
21630: $value = '';
21631: }
21632: } elsif ($item eq 'registered') {
21633: unless ($value eq '1') {
21634: $value = 0;
21635: }
21636: } elsif ($item eq 'approval') {
21637: unless ($value =~ /^[012]$/) {
21638: $value = 0;
21639: }
21640: } else {
21641: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21642: $value = 'none';
21643: }
21644: }
21645: $selfenrollhash{'default'}{$type}{$item} = $value;
21646: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
21647: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21648: if ($selfenrollhash{'default'}{$type}{$item} ne
21649: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
21650: push(@{$changes{'default'}{$type}},$item);
21651: }
21652: } else {
21653: push(@{$changes{'default'}{$type}},$item);
21654: }
21655: } else {
21656: push(@{$changes{'default'}{$type}},$item);
21657: }
21658: if ($item eq 'limit') {
21659: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21660: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
21661: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
21662: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
21663: }
21664: } else {
21665: $selfenrollhash{'default'}{$type}{'cap'} = '';
21666: }
21667: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21668: if ($selfenrollhash{'default'}{$type}{'cap'} ne
21669: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
21670: push(@{$changes{'default'}{$type}},'cap');
21671: }
21672: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
21673: push(@{$changes{'default'}{$type}},'cap');
21674: }
21675: }
21676: }
21677: }
21678:
21679: foreach my $item (@{$itemsref}) {
21680: if ($item eq 'fields') {
21681: my @changed;
21682: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
21683: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
21684: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
21685: }
21686: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21687: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
21688: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
21689: $domconfig{'selfenrollment'}{'validation'}{$item});
21690: } else {
21691: @changed = @{$selfenrollhash{'validation'}{$item}};
21692: }
21693: } else {
21694: @changed = @{$selfenrollhash{'validation'}{$item}};
21695: }
21696: if (@changed) {
21697: if ($selfenrollhash{'validation'}{$item}) {
21698: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
21699: } else {
21700: $changes{'validation'}{$item} = &mt('None');
21701: }
21702: }
21703: } else {
21704: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
21705: if ($item eq 'markup') {
21706: if ($env{'form.selfenroll_validation_'.$item}) {
21707: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
21708: }
21709: }
21710: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21711: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
21712: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
21713: }
21714: }
21715: }
21716: }
21717:
21718: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
21719: $dom);
21720: if ($putresult eq 'ok') {
21721: if (keys(%changes) > 0) {
21722: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
21723: $resulttext = &mt('Changes made:').'<ul>';
21724: foreach my $key ('admin','default','validation') {
21725: if (ref($changes{$key}) eq 'HASH') {
21726: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
21727: if ($key eq 'validation') {
21728: foreach my $item (@{$itemsref}) {
21729: if (exists($changes{$key}{$item})) {
21730: if ($item eq 'markup') {
21731: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
21732: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
21733: } else {
21734: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
21735: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
21736: }
21737: }
21738: }
21739: } else {
21740: foreach my $type (@types) {
21741: if ($type eq 'community') {
21742: $roles{'1'} = &mt('Community personnel');
21743: } else {
21744: $roles{'1'} = &mt('Course personnel');
21745: }
21746: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 21747: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
21748: if ($key eq 'admin') {
21749: my @mgrdc = ();
21750: if (ref($ordered{$key}) eq 'ARRAY') {
21751: foreach my $item (@{$ordered{'admin'}}) {
21752: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
21753: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
21754: push(@mgrdc,$item);
21755: }
21756: }
21757: }
21758: if (@mgrdc) {
21759: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
21760: } else {
21761: delete($domdefaults{$type.'selfenrolladmdc'});
21762: }
21763: }
21764: } else {
21765: if (ref($ordered{$key}) eq 'ARRAY') {
21766: foreach my $item (@{$ordered{$key}}) {
21767: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
21768: $domdefaults{$type.'selfenroll'.$item} =
21769: $selfenrollhash{$key}{$type}{$item};
21770: }
21771: }
21772: }
21773: }
21774: }
1.231 raeburn 21775: $resulttext .= '<li>'.$titles{$type}.'<ul>';
21776: foreach my $item (@{$ordered{$key}}) {
21777: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
21778: $resulttext .= '<li>';
21779: if ($key eq 'admin') {
21780: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
21781: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
21782: } else {
21783: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
21784: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
21785: }
21786: $resulttext .= '</li>';
21787: }
21788: }
21789: $resulttext .= '</ul></li>';
21790: }
21791: }
21792: $resulttext .= '</ul></li>';
21793: }
21794: }
1.305 raeburn 21795: }
21796: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
21797: my $cachetime = 24*60*60;
21798: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21799: if (ref($lastactref) eq 'HASH') {
21800: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 21801: }
1.231 raeburn 21802: }
21803: $resulttext .= '</ul>';
21804: } else {
21805: $resulttext = &mt('No changes made to self-enrollment settings');
21806: }
21807: } else {
21808: $resulttext = '<span class="LC_error">'.
21809: &mt('An error occurred: [_1]',$putresult).'</span>';
21810: }
21811: return $resulttext;
21812: }
21813:
1.373 raeburn 21814: sub modify_wafproxy {
21815: my ($dom,$action,$lastactref,%domconfig) = @_;
21816: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 21817: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
21818: %wafproxy,%changes,%expirecache,%expiresaml);
1.373 raeburn 21819: foreach my $server (sort(keys(%servers))) {
21820: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
21821: if ($serverhome eq $server) {
21822: my $serverdom = &Apache::lonnet::host_domain($server);
21823: if ($serverdom eq $dom) {
21824: $canset{$server} = 1;
21825: }
21826: }
21827: }
1.381 raeburn 21828: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
21829: %{$values{$dom}} = ();
21830: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
21831: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
21832: }
1.388 raeburn 21833: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
21834: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
21835: }
1.382 raeburn 21836: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.381 raeburn 21837: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
21838: }
21839: }
1.373 raeburn 21840: my $output;
21841: if (keys(%canset)) {
21842: %{$wafproxy{'alias'}} = ();
1.388 raeburn 21843: %{$wafproxy{'saml'}} = ();
1.373 raeburn 21844: foreach my $key (sort(keys(%canset))) {
1.381 raeburn 21845: if ($env{'form.wafproxy_'.$dom}) {
21846: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
21847: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
21848: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
21849: $changes{'alias'} = 1;
21850: }
1.388 raeburn 21851: if ($env{'form.wafproxy_alias_saml_'.$key}) {
21852: $wafproxy{'saml'}{$key} = 1;
21853: }
21854: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
21855: $changes{'saml'} = 1;
21856: }
1.381 raeburn 21857: } else {
21858: $wafproxy{'alias'}{$key} = '';
1.388 raeburn 21859: $wafproxy{'saml'}{$key} = '';
1.381 raeburn 21860: if ($curralias{$key}) {
21861: $changes{'alias'} = 1;
21862: }
1.388 raeburn 21863: if ($currsaml{$key}) {
21864: $changes{'saml'} = 1;
21865: }
1.373 raeburn 21866: }
21867: if ($wafproxy{'alias'}{$key} eq '') {
21868: if ($curralias{$key}) {
21869: $expirecache{$key} = 1;
21870: }
21871: delete($wafproxy{'alias'}{$key});
21872: }
1.388 raeburn 21873: if ($wafproxy{'saml'}{$key} eq '') {
21874: if ($currsaml{$key}) {
21875: $expiresaml{$key} = 1;
21876: }
21877: delete($wafproxy{'saml'}{$key});
21878: }
1.373 raeburn 21879: }
21880: unless (keys(%{$wafproxy{'alias'}})) {
21881: delete($wafproxy{'alias'});
21882: }
1.388 raeburn 21883: unless (keys(%{$wafproxy{'saml'}})) {
21884: delete($wafproxy{'saml'});
21885: }
21886: # Localization for values in %warn occurs in &mt() calls separately.
1.373 raeburn 21887: my %warn = (
21888: trusted => 'trusted IP range(s)',
1.381 raeburn 21889: vpnint => 'internal IP range(s) for VPN sessions(s)',
21890: vpnext => 'IP range(s) for backend WAF connections',
1.373 raeburn 21891: );
1.382 raeburn 21892: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 21893: my $possible = $env{'form.wafproxy_'.$item};
21894: $possible =~ s/^\s+|\s+$//g;
21895: if ($possible ne '') {
1.381 raeburn 21896: if ($item eq 'remoteip') {
21897: if ($possible =~ /^[mhn]$/) {
21898: $wafproxy{$item} = $possible;
21899: }
21900: } elsif ($item eq 'ipheader') {
21901: if ($wafproxy{'remoteip'} eq 'h') {
21902: $wafproxy{$item} = $possible;
21903: }
1.382 raeburn 21904: } elsif ($item eq 'sslopt') {
21905: if ($possible =~ /^0|1$/) {
21906: $wafproxy{$item} = $possible;
21907: }
1.373 raeburn 21908: } else {
21909: my (@ok,$count);
1.381 raeburn 21910: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
21911: unless ($env{'form.wafproxy_vpnaccess'}) {
21912: $possible = '';
21913: }
21914: } elsif ($item eq 'trusted') {
21915: unless ($wafproxy{'remoteip'} eq 'h') {
21916: $possible = '';
21917: }
21918: }
21919: unless ($possible eq '') {
21920: $possible =~ s/[\r\n]+/\s/g;
21921: $possible =~ s/\s*-\s*/-/g;
21922: $possible =~ s/\s+/,/g;
1.393 raeburn 21923: $possible =~ s/,+/,/g;
1.381 raeburn 21924: }
1.373 raeburn 21925: $count = 0;
1.381 raeburn 21926: if ($possible ne '') {
1.373 raeburn 21927: foreach my $poss (split(/\,/,$possible)) {
21928: $count ++;
1.393 raeburn 21929: $poss = &validate_ip_pattern($poss);
21930: if ($poss ne '') {
1.373 raeburn 21931: push(@ok,$poss);
21932: }
21933: }
21934: my $diff = $count - scalar(@ok);
21935: if ($diff) {
21936: push(@warnings,'<li>'.
21937: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
21938: $diff,$warn{$item}).
21939: '</li>');
21940: }
1.393 raeburn 21941: if (@ok) {
21942: my @cidr_list;
21943: foreach my $item (@ok) {
21944: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
21945: }
21946: $wafproxy{$item} = join(',',@cidr_list);
21947: }
1.373 raeburn 21948: }
21949: }
1.381 raeburn 21950: if ($wafproxy{$item} ne $currvalue{$item}) {
1.373 raeburn 21951: $changes{$item} = 1;
21952: }
1.381 raeburn 21953: } elsif ($currvalue{$item}) {
21954: $changes{$item} = 1;
1.425 raeburn 21955: }
1.381 raeburn 21956: }
21957: } else {
21958: if (keys(%curralias)) {
21959: $changes{'alias'} = 1;
1.388 raeburn 21960: }
21961: if (keys(%currsaml)) {
21962: $changes{'saml'} = 1;
1.425 raeburn 21963: }
1.381 raeburn 21964: if (keys(%currvalue)) {
21965: foreach my $key (keys(%currvalue)) {
21966: $changes{$key} = 1;
1.373 raeburn 21967: }
21968: }
21969: }
21970: if (keys(%changes)) {
21971: my %defaultshash = (
21972: wafproxy => \%wafproxy,
1.425 raeburn 21973: );
1.373 raeburn 21974: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21975: $dom);
21976: if ($putresult eq 'ok') {
21977: my $cachetime = 24*60*60;
21978: my (%domdefaults,$updatedomdefs);
1.382 raeburn 21979: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 21980: if ($changes{$item}) {
21981: unless ($updatedomdefs) {
21982: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
21983: $updatedomdefs = 1;
21984: }
21985: if ($wafproxy{$item}) {
21986: $domdefaults{'waf_'.$item} = $wafproxy{$item};
21987: } elsif (exists($domdefaults{'waf_'.$item})) {
21988: delete($domdefaults{'waf_'.$item});
1.425 raeburn 21989: }
1.373 raeburn 21990: }
21991: }
21992: if ($updatedomdefs) {
21993: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21994: if (ref($lastactref) eq 'HASH') {
21995: $lastactref->{'domdefaults'} = 1;
21996: }
21997: }
21998: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
21999: my %updates = %expirecache;
22000: foreach my $key (keys(%expirecache)) {
22001: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
22002: }
22003: if (ref($wafproxy{'alias'}) eq 'HASH') {
22004: my $cachetime = 24*60*60;
22005: foreach my $key (keys(%{$wafproxy{'alias'}})) {
22006: $updates{$key} = 1;
22007: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
22008: $cachetime);
22009: }
22010: }
22011: if (ref($lastactref) eq 'HASH') {
22012: $lastactref->{'proxyalias'} = \%updates;
22013: }
22014: }
1.388 raeburn 22015: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
22016: my %samlupdates = %expiresaml;
22017: foreach my $key (keys(%expiresaml)) {
22018: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
22019: }
22020: if (ref($wafproxy{'saml'}) eq 'HASH') {
22021: my $cachetime = 24*60*60;
22022: foreach my $key (keys(%{$wafproxy{'saml'}})) {
22023: $samlupdates{$key} = 1;
22024: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
22025: $cachetime);
22026: }
22027: }
22028: if (ref($lastactref) eq 'HASH') {
22029: $lastactref->{'proxysaml'} = \%samlupdates;
22030: }
22031: }
1.373 raeburn 22032: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.401 raeburn 22033: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22034: if ($changes{$item}) {
22035: if ($item eq 'alias') {
22036: my $numaliased = 0;
22037: if (ref($wafproxy{'alias'}) eq 'HASH') {
22038: my $shown;
22039: if (keys(%{$wafproxy{'alias'}})) {
22040: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
22041: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
22042: &Apache::lonnet::hostname($server),
22043: $wafproxy{'alias'}{$server}).'</li>';
22044: $numaliased ++;
22045: }
22046: if ($numaliased) {
22047: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
22048: '<ul>'.$shown.'</ul>').'</li>';
22049: }
22050: }
22051: }
22052: unless ($numaliased) {
22053: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
22054: }
1.388 raeburn 22055: } elsif ($item eq 'saml') {
1.425 raeburn 22056: my $shown;
1.388 raeburn 22057: if (ref($wafproxy{'saml'}) eq 'HASH') {
22058: if (keys(%{$wafproxy{'saml'}})) {
22059: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
22060: }
22061: }
22062: if ($shown) {
1.396 raeburn 22063: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
1.388 raeburn 22064: $shown).'</li>';
22065: } else {
1.396 raeburn 22066: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
1.388 raeburn 22067: }
1.373 raeburn 22068: } else {
1.381 raeburn 22069: if ($item eq 'remoteip') {
22070: my %ip_methods = &remoteip_methods();
22071: if ($wafproxy{$item} =~ /^[mh]$/) {
22072: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
22073: $ip_methods{$wafproxy{$item}}).'</li>';
22074: } else {
22075: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
22076: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
22077: '</li>';
22078: } else {
22079: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
22080: }
22081: }
22082: } elsif ($item eq 'ipheader') {
1.373 raeburn 22083: if ($wafproxy{$item}) {
1.381 raeburn 22084: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
1.373 raeburn 22085: $wafproxy{$item}).'</li>';
22086: } else {
1.381 raeburn 22087: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
1.373 raeburn 22088: }
22089: } elsif ($item eq 'trusted') {
22090: if ($wafproxy{$item}) {
1.381 raeburn 22091: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
1.373 raeburn 22092: $wafproxy{$item}).'</li>';
22093: } else {
22094: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
22095: }
1.381 raeburn 22096: } elsif ($item eq 'vpnint') {
22097: if ($wafproxy{$item}) {
22098: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
22099: $wafproxy{$item}).'</li>';
22100: } else {
22101: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
22102: }
22103: } elsif ($item eq 'vpnext') {
1.373 raeburn 22104: if ($wafproxy{$item}) {
1.381 raeburn 22105: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
1.373 raeburn 22106: $wafproxy{$item}).'</li>';
22107: } else {
1.381 raeburn 22108: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
1.373 raeburn 22109: }
1.382 raeburn 22110: } elsif ($item eq 'sslopt') {
22111: if ($wafproxy{$item}) {
22112: $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>';
22113: } else {
22114: $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>';
22115: }
1.373 raeburn 22116: }
22117: }
22118: }
22119: }
1.420 raeburn 22120: $output .= '</ul>';
1.373 raeburn 22121: } else {
22122: $output = '<span class="LC_error">'.
22123: &mt('An error occurred: [_1]',$putresult).'</span>';
22124: }
22125: } elsif (keys(%canset)) {
22126: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
22127: }
22128: if (@warnings) {
22129: $output .= '<br />'.&mt('Warnings:').'<ul>'.
22130: join("\n",@warnings).'</ul>';
22131: }
22132: return $output;
22133: }
22134:
22135: sub validate_ip_pattern {
22136: my ($pattern) = @_;
22137: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
22138: my ($start,$end) = ($1,$2);
22139: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
1.393 raeburn 22140: if (($start !~ m{/}) && ($end !~ m{/})) {
22141: return $start.'-'.$end;
22142: }
22143: }
22144: } elsif ($pattern ne '') {
22145: $pattern = &Net::CIDR::cidrvalidate($pattern);
22146: if ($pattern ne '') {
22147: return $pattern;
1.373 raeburn 22148: }
22149: }
1.393 raeburn 22150: return;
1.373 raeburn 22151: }
22152:
1.137 raeburn 22153: sub modify_usersessions {
1.212 raeburn 22154: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 22155: my @hostingtypes = ('version','excludedomain','includedomain');
22156: my @offloadtypes = ('primary','default');
22157: my %types = (
22158: remote => \@hostingtypes,
22159: hosted => \@hostingtypes,
22160: spares => \@offloadtypes,
22161: );
22162: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 22163: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 22164: my (%by_ip,%by_location,@intdoms,@instdoms);
22165: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 22166: my @locations = sort(keys(%by_location));
1.137 raeburn 22167: my (%defaultshash,%changes);
22168: foreach my $prefix (@prefixes) {
22169: $defaultshash{'usersessions'}{$prefix} = {};
22170: }
1.212 raeburn 22171: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 22172: my $resulttext;
1.138 raeburn 22173: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 22174: foreach my $prefix (@prefixes) {
1.145 raeburn 22175: next if ($prefix eq 'spares');
22176: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 22177: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22178: if ($type eq 'version') {
22179: my $value = $env{'form.'.$prefix.'_'.$type};
22180: my $okvalue;
22181: if ($value ne '') {
22182: if (grep(/^\Q$value\E$/,@lcversions)) {
22183: $okvalue = $value;
22184: }
22185: }
22186: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22187: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22188: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
22189: if ($inuse == 0) {
22190: $changes{$prefix}{$type} = 1;
22191: } else {
22192: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
22193: $changes{$prefix}{$type} = 1;
22194: }
22195: if ($okvalue ne '') {
22196: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22197: }
22198: }
22199: } else {
22200: if (($inuse == 1) && ($okvalue ne '')) {
22201: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22202: $changes{$prefix}{$type} = 1;
22203: }
22204: }
22205: } else {
22206: if (($inuse == 1) && ($okvalue ne '')) {
22207: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22208: $changes{$prefix}{$type} = 1;
22209: }
22210: }
22211: } else {
22212: if (($inuse == 1) && ($okvalue ne '')) {
22213: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22214: $changes{$prefix}{$type} = 1;
22215: }
22216: }
22217: } else {
22218: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22219: my @okvals;
22220: foreach my $val (@vals) {
1.138 raeburn 22221: if ($val =~ /:/) {
22222: my @items = split(/:/,$val);
22223: foreach my $item (@items) {
22224: if (ref($by_location{$item}) eq 'ARRAY') {
22225: push(@okvals,$item);
22226: }
22227: }
22228: } else {
22229: if (ref($by_location{$val}) eq 'ARRAY') {
22230: push(@okvals,$val);
22231: }
1.137 raeburn 22232: }
22233: }
22234: @okvals = sort(@okvals);
22235: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22236: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22237: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22238: if ($inuse == 0) {
22239: $changes{$prefix}{$type} = 1;
22240: } else {
22241: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22242: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
22243: if (@changed > 0) {
22244: $changes{$prefix}{$type} = 1;
22245: }
22246: }
22247: } else {
22248: if ($inuse == 1) {
22249: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22250: $changes{$prefix}{$type} = 1;
22251: }
22252: }
22253: } else {
22254: if ($inuse == 1) {
22255: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22256: $changes{$prefix}{$type} = 1;
22257: }
22258: }
22259: } else {
22260: if ($inuse == 1) {
22261: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22262: $changes{$prefix}{$type} = 1;
22263: }
22264: }
22265: }
22266: }
22267: }
1.145 raeburn 22268:
22269: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 22270: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 22271: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
22272: my $savespares;
22273:
22274: foreach my $lonhost (sort(keys(%servers))) {
22275: my $serverhomeID =
22276: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 22277: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 22278: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
22279: my %spareschg;
22280: foreach my $type (@{$types{'spares'}}) {
22281: my @okspares;
22282: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
22283: foreach my $server (@checked) {
1.152 raeburn 22284: if (&Apache::lonnet::hostname($server) ne '') {
22285: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
22286: unless (grep(/^\Q$server\E$/,@okspares)) {
22287: push(@okspares,$server);
22288: }
1.145 raeburn 22289: }
22290: }
22291: }
22292: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
22293: my $newspare;
1.152 raeburn 22294: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
22295: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 22296: $newspare = $new;
22297: }
22298: }
1.152 raeburn 22299: my @spares;
22300: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
22301: @spares = sort(@okspares,$newspare);
22302: } else {
22303: @spares = sort(@okspares);
22304: }
22305: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 22306: if (ref($spareid{$lonhost}) eq 'HASH') {
22307: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 22308: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 22309: if (@diffs > 0) {
22310: $spareschg{$type} = 1;
22311: }
22312: }
22313: }
22314: }
22315: if (keys(%spareschg) > 0) {
22316: $changes{'spares'}{$lonhost} = \%spareschg;
22317: }
22318: }
1.261 raeburn 22319: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371 raeburn 22320: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261 raeburn 22321: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
22322: my @okoffload;
22323: if (@offloadnow) {
22324: foreach my $server (@offloadnow) {
22325: if (&Apache::lonnet::hostname($server) ne '') {
22326: unless (grep(/^\Q$server\E$/,@okoffload)) {
22327: push(@okoffload,$server);
22328: }
22329: }
22330: }
22331: if (@okoffload) {
22332: foreach my $lonhost (@okoffload) {
22333: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
22334: }
22335: }
22336: }
1.371 raeburn 22337: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
22338: my @okoffloadoth;
22339: if (@offloadoth) {
22340: foreach my $server (@offloadoth) {
22341: if (&Apache::lonnet::hostname($server) ne '') {
22342: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
22343: push(@okoffloadoth,$server);
22344: }
22345: }
22346: }
22347: if (@okoffloadoth) {
22348: foreach my $lonhost (@okoffloadoth) {
22349: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
22350: }
22351: }
22352: }
1.145 raeburn 22353: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22354: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
22355: if (ref($changes{'spares'}) eq 'HASH') {
22356: if (keys(%{$changes{'spares'}}) > 0) {
22357: $savespares = 1;
22358: }
22359: }
22360: } else {
22361: $savespares = 1;
22362: }
1.371 raeburn 22363: foreach my $offload ('offloadnow','offloadoth') {
22364: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
22365: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
22366: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
22367: $changes{$offload} = 1;
22368: last;
22369: }
1.261 raeburn 22370: }
1.371 raeburn 22371: unless ($changes{$offload}) {
22372: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
22373: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
22374: $changes{$offload} = 1;
22375: last;
22376: }
1.261 raeburn 22377: }
22378: }
1.371 raeburn 22379: } else {
22380: if (($offload eq 'offloadnow') && (@okoffload)) {
22381: $changes{'offloadnow'} = 1;
22382: }
22383: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
22384: $changes{'offloadoth'} = 1;
22385: }
1.425 raeburn 22386: }
1.371 raeburn 22387: }
22388: } else {
22389: if (@okoffload) {
1.261 raeburn 22390: $changes{'offloadnow'} = 1;
22391: }
1.371 raeburn 22392: if (@okoffloadoth) {
22393: $changes{'offloadoth'} = 1;
22394: }
1.145 raeburn 22395: }
1.147 raeburn 22396: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
22397: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 22398: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22399: $dom);
22400: if ($putresult eq 'ok') {
22401: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22402: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
22403: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
22404: }
22405: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
22406: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
22407: }
1.261 raeburn 22408: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22409: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
22410: }
1.371 raeburn 22411: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22412: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
22413: }
1.137 raeburn 22414: }
22415: my $cachetime = 24*60*60;
22416: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 22417: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 22418: if (ref($lastactref) eq 'HASH') {
22419: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 22420: $lastactref->{'usersessions'} = 1;
1.212 raeburn 22421: }
1.147 raeburn 22422: if (keys(%changes) > 0) {
22423: my %lt = &usersession_titles();
22424: $resulttext = &mt('Changes made:').'<ul>';
22425: foreach my $prefix (@prefixes) {
22426: if (ref($changes{$prefix}) eq 'HASH') {
22427: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
22428: if ($prefix eq 'spares') {
22429: if (ref($changes{$prefix}) eq 'HASH') {
22430: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
22431: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 22432: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 22433: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
22434: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 22435: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
22436: foreach my $type (@{$types{$prefix}}) {
22437: if ($changes{$prefix}{$lonhost}{$type}) {
22438: my $offloadto = &mt('None');
22439: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
22440: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
22441: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
22442: }
1.145 raeburn 22443: }
1.147 raeburn 22444: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 22445: }
1.137 raeburn 22446: }
22447: }
1.147 raeburn 22448: $resulttext .= '</li>';
1.137 raeburn 22449: }
22450: }
1.147 raeburn 22451: } else {
22452: foreach my $type (@{$types{$prefix}}) {
22453: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22454: my ($newvalue,$notinuse);
1.147 raeburn 22455: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22456: if (ref($defaultshash{'usersessions'}{$prefix})) {
22457: if ($type eq 'version') {
22458: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 22459: } else {
22460: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22461: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
22462: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
22463: }
22464: } else {
22465: $notinuse = 1;
1.147 raeburn 22466: }
1.145 raeburn 22467: }
22468: }
22469: }
1.147 raeburn 22470: if ($newvalue eq '') {
22471: if ($type eq 'version') {
22472: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 22473: } elsif ($notinuse) {
22474: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 22475: } else {
22476: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
22477: }
1.145 raeburn 22478: } else {
1.147 raeburn 22479: if ($type eq 'version') {
1.344 raeburn 22480: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 22481: }
22482: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 22483: }
1.137 raeburn 22484: }
22485: }
22486: }
1.147 raeburn 22487: $resulttext .= '</ul>';
1.137 raeburn 22488: }
22489: }
1.261 raeburn 22490: if ($changes{'offloadnow'}) {
22491: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22492: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371 raeburn 22493: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261 raeburn 22494: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
22495: $resulttext .= '<li>'.$lonhost.'</li>';
22496: }
22497: $resulttext .= '</ul>';
22498: } else {
1.371 raeburn 22499: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
22500: }
22501: } else {
22502: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
22503: }
22504: }
22505: if ($changes{'offloadoth'}) {
22506: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22507: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
22508: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
22509: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
22510: $resulttext .= '<li>'.$lonhost.'</li>';
22511: }
22512: $resulttext .= '</ul>';
22513: } else {
22514: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261 raeburn 22515: }
22516: } else {
1.371 raeburn 22517: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261 raeburn 22518: }
22519: }
1.147 raeburn 22520: $resulttext .= '</ul>';
22521: } else {
22522: $resulttext = $nochgmsg;
1.137 raeburn 22523: }
22524: } else {
22525: $resulttext = '<span class="LC_error">'.
22526: &mt('An error occurred: [_1]',$putresult).'</span>';
22527: }
22528: } else {
1.147 raeburn 22529: $resulttext = $nochgmsg;
1.137 raeburn 22530: }
22531: return $resulttext;
22532: }
22533:
1.275 raeburn 22534: sub modify_ssl {
22535: my ($dom,$lastactref,%domconfig) = @_;
22536: my (%by_ip,%by_location,@intdoms,@instdoms);
22537: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
22538: my @locations = sort(keys(%by_location));
22539: my %servers = &Apache::lonnet::internet_dom_servers($dom);
22540: my (%defaultshash,%changes);
22541: my $action = 'ssl';
1.293 raeburn 22542: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 22543: foreach my $prefix (@prefixes) {
22544: $defaultshash{$action}{$prefix} = {};
22545: }
22546: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22547: my $resulttext;
22548: my %iphost = &Apache::lonnet::get_iphost();
22549: my @reptypes = ('certreq','nocertreq');
22550: my @connecttypes = ('dom','intdom','other');
22551: my %types = (
1.293 raeburn 22552: connto => \@connecttypes,
22553: connfrom => \@connecttypes,
22554: replication => \@reptypes,
1.275 raeburn 22555: );
22556: foreach my $prefix (sort(keys(%types))) {
22557: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 22558: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22559: my $value = 'yes';
22560: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
22561: $value = $env{'form.'.$prefix.'_'.$type};
22562: }
1.335 raeburn 22563: if (ref($domconfig{$action}) eq 'HASH') {
22564: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22565: if ($domconfig{$action}{$prefix}{$type} ne '') {
22566: if ($value ne $domconfig{$action}{$prefix}{$type}) {
22567: $changes{$prefix}{$type} = 1;
22568: }
22569: $defaultshash{$action}{$prefix}{$type} = $value;
22570: } else {
22571: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 22572: $changes{$prefix}{$type} = 1;
22573: }
22574: } else {
22575: $defaultshash{$action}{$prefix}{$type} = $value;
22576: $changes{$prefix}{$type} = 1;
22577: }
22578: } else {
22579: $defaultshash{$action}{$prefix}{$type} = $value;
22580: $changes{$prefix}{$type} = 1;
22581: }
22582: if (($type eq 'dom') && (keys(%servers) == 1)) {
22583: delete($changes{$prefix}{$type});
22584: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
22585: delete($changes{$prefix}{$type});
22586: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
22587: delete($changes{$prefix}{$type});
22588: }
22589: } elsif ($prefix eq 'replication') {
22590: if (@locations > 0) {
22591: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22592: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22593: my @okvals;
22594: foreach my $val (@vals) {
22595: if ($val =~ /:/) {
22596: my @items = split(/:/,$val);
22597: foreach my $item (@items) {
22598: if (ref($by_location{$item}) eq 'ARRAY') {
22599: push(@okvals,$item);
22600: }
22601: }
22602: } else {
22603: if (ref($by_location{$val}) eq 'ARRAY') {
22604: push(@okvals,$val);
22605: }
22606: }
22607: }
22608: @okvals = sort(@okvals);
22609: if (ref($domconfig{$action}) eq 'HASH') {
22610: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22611: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
22612: if ($inuse == 0) {
22613: $changes{$prefix}{$type} = 1;
22614: } else {
22615: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22616: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
22617: if (@changed > 0) {
22618: $changes{$prefix}{$type} = 1;
22619: }
22620: }
22621: } else {
22622: if ($inuse == 1) {
22623: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22624: $changes{$prefix}{$type} = 1;
22625: }
22626: }
22627: } else {
22628: if ($inuse == 1) {
22629: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22630: $changes{$prefix}{$type} = 1;
22631: }
22632: }
22633: } else {
22634: if ($inuse == 1) {
22635: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22636: $changes{$prefix}{$type} = 1;
22637: }
22638: }
22639: }
22640: }
22641: }
22642: }
1.336 raeburn 22643: if (keys(%changes)) {
22644: foreach my $prefix (keys(%changes)) {
22645: if (ref($changes{$prefix}) eq 'HASH') {
22646: if (scalar(keys(%{$changes{$prefix}})) == 0) {
22647: delete($changes{$prefix});
22648: }
22649: } else {
22650: delete($changes{$prefix});
22651: }
22652: }
22653: }
1.275 raeburn 22654: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
22655: if (keys(%changes) > 0) {
22656: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22657: $dom);
22658: if ($putresult eq 'ok') {
22659: if (ref($defaultshash{$action}) eq 'HASH') {
22660: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
22661: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
22662: }
1.293 raeburn 22663: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 22664: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 22665: }
22666: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 22667: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 22668: }
22669: }
22670: my $cachetime = 24*60*60;
22671: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22672: if (ref($lastactref) eq 'HASH') {
22673: $lastactref->{'domdefaults'} = 1;
22674: }
22675: if (keys(%changes) > 0) {
22676: my %titles = &ssl_titles();
22677: $resulttext = &mt('Changes made:').'<ul>';
22678: foreach my $prefix (@prefixes) {
22679: if (ref($changes{$prefix}) eq 'HASH') {
22680: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
22681: foreach my $type (@{$types{$prefix}}) {
22682: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22683: my ($newvalue,$notinuse);
1.275 raeburn 22684: if (ref($defaultshash{$action}) eq 'HASH') {
22685: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 22686: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22687: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 22688: } else {
22689: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
22690: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
22691: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
22692: }
22693: } else {
22694: $notinuse = 1;
1.275 raeburn 22695: }
22696: }
22697: }
1.344 raeburn 22698: if ($notinuse) {
22699: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
22700: } elsif ($newvalue eq '') {
1.275 raeburn 22701: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
22702: } else {
22703: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
22704: }
22705: }
22706: }
22707: }
22708: $resulttext .= '</ul>';
22709: }
22710: }
22711: } else {
22712: $resulttext = $nochgmsg;
22713: }
22714: } else {
22715: $resulttext = '<span class="LC_error">'.
22716: &mt('An error occurred: [_1]',$putresult).'</span>';
22717: }
22718: } else {
22719: $resulttext = $nochgmsg;
22720: }
22721: return $resulttext;
22722: }
22723:
1.279 raeburn 22724: sub modify_trust {
22725: my ($dom,$lastactref,%domconfig) = @_;
22726: my (%by_ip,%by_location,@intdoms,@instdoms);
22727: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
22728: my @locations = sort(keys(%by_location));
22729: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
22730: my @types = ('exc','inc');
22731: my (%defaultshash,%changes);
22732: foreach my $prefix (@prefixes) {
22733: $defaultshash{'trust'}{$prefix} = {};
22734: }
22735: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22736: my $resulttext;
22737: foreach my $prefix (@prefixes) {
22738: foreach my $type (@types) {
22739: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22740: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22741: my @okvals;
22742: foreach my $val (@vals) {
22743: if ($val =~ /:/) {
22744: my @items = split(/:/,$val);
22745: foreach my $item (@items) {
22746: if (ref($by_location{$item}) eq 'ARRAY') {
22747: push(@okvals,$item);
22748: }
22749: }
22750: } else {
22751: if (ref($by_location{$val}) eq 'ARRAY') {
22752: push(@okvals,$val);
22753: }
22754: }
22755: }
22756: @okvals = sort(@okvals);
22757: if (ref($domconfig{'trust'}) eq 'HASH') {
22758: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
22759: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
22760: if ($inuse == 0) {
22761: $changes{$prefix}{$type} = 1;
22762: } else {
22763: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22764: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
22765: if (@changed > 0) {
22766: $changes{$prefix}{$type} = 1;
22767: }
22768: }
22769: } else {
22770: if ($inuse == 1) {
22771: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22772: $changes{$prefix}{$type} = 1;
22773: }
22774: }
22775: } else {
22776: if ($inuse == 1) {
22777: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22778: $changes{$prefix}{$type} = 1;
22779: }
22780: }
22781: } else {
22782: if ($inuse == 1) {
22783: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22784: $changes{$prefix}{$type} = 1;
22785: }
22786: }
22787: }
22788: }
22789: my $nochgmsg = &mt('No changes made to trust settings.');
22790: if (keys(%changes) > 0) {
22791: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22792: $dom);
22793: if ($putresult eq 'ok') {
22794: if (ref($defaultshash{'trust'}) eq 'HASH') {
22795: foreach my $prefix (@prefixes) {
22796: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
22797: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
22798: }
22799: }
22800: }
22801: my $cachetime = 24*60*60;
22802: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.410 raeburn 22803: &Apache::lonnet::do_cache_new('trust',$dom,$defaultshash{'trust'},3600);
1.279 raeburn 22804: if (ref($lastactref) eq 'HASH') {
22805: $lastactref->{'domdefaults'} = 1;
1.410 raeburn 22806: $lastactref->{'trust'} = 1;
1.279 raeburn 22807: }
22808: if (keys(%changes) > 0) {
22809: my %lt = &trust_titles();
22810: $resulttext = &mt('Changes made:').'<ul>';
22811: foreach my $prefix (@prefixes) {
22812: if (ref($changes{$prefix}) eq 'HASH') {
22813: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
22814: foreach my $type (@types) {
22815: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22816: my ($newvalue,$notinuse);
1.279 raeburn 22817: if (ref($defaultshash{'trust'}) eq 'HASH') {
22818: if (ref($defaultshash{'trust'}{$prefix})) {
22819: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
22820: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
22821: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
22822: }
1.344 raeburn 22823: } else {
22824: $notinuse = 1;
1.279 raeburn 22825: }
22826: }
22827: }
1.344 raeburn 22828: if ($notinuse) {
22829: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
22830: } elsif ($newvalue eq '') {
1.279 raeburn 22831: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
22832: } else {
22833: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
22834: }
22835: }
22836: }
22837: $resulttext .= '</ul>';
22838: }
22839: }
22840: $resulttext .= '</ul>';
22841: } else {
22842: $resulttext = $nochgmsg;
22843: }
22844: } else {
22845: $resulttext = '<span class="LC_error">'.
22846: &mt('An error occurred: [_1]',$putresult).'</span>';
22847: }
22848: } else {
22849: $resulttext = $nochgmsg;
22850: }
22851: return $resulttext;
22852: }
22853:
1.150 raeburn 22854: sub modify_loadbalancing {
22855: my ($dom,%domconfig) = @_;
22856: my $primary_id = &Apache::lonnet::domain($dom,'primary');
22857: my $intdom = &Apache::lonnet::internet_dom($primary_id);
22858: my ($othertitle,$usertypes,$types) =
22859: &Apache::loncommon::sorted_inst_types($dom);
22860: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 22861: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 22862: my @sparestypes = ('primary','default');
22863: my %typetitles = &sparestype_titles();
22864: my $resulttext;
1.342 raeburn 22865: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 22866: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
22867: %existing = %{$domconfig{'loadbalancing'}};
22868: }
22869: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 22870: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 22871: my ($saveloadbalancing,%defaultshash,%changes);
22872: my ($alltypes,$othertypes,$titles) =
22873: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
22874: my %ruletitles = &offloadtype_text();
22875: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
22876: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
22877: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
22878: if ($balancer eq '') {
22879: next;
22880: }
1.210 raeburn 22881: if (!exists($servers{$balancer})) {
1.171 raeburn 22882: if (exists($currbalancer{$balancer})) {
22883: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 22884: }
1.171 raeburn 22885: next;
22886: }
22887: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
22888: push(@{$changes{'delete'}},$balancer);
22889: next;
22890: }
22891: if (!exists($currbalancer{$balancer})) {
22892: push(@{$changes{'add'}},$balancer);
22893: }
22894: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
22895: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
22896: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
22897: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
22898: $saveloadbalancing = 1;
22899: }
22900: foreach my $sparetype (@sparestypes) {
22901: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
22902: my @offloadto;
22903: foreach my $target (@targets) {
22904: if (($servers{$target}) && ($target ne $balancer)) {
22905: if ($sparetype eq 'default') {
22906: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
22907: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 22908: }
22909: }
1.171 raeburn 22910: unless(grep(/^\Q$target\E$/,@offloadto)) {
22911: push(@offloadto,$target);
22912: }
1.150 raeburn 22913: }
22914: }
1.284 raeburn 22915: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
22916: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
22917: push(@offloadto,$balancer);
22918: }
22919: }
22920: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 22921: }
1.342 raeburn 22922: if ($env{'form.loadbalancing_cookie_'.$i}) {
22923: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
1.425 raeburn 22924: if (exists($currbalancer{$balancer})) {
1.342 raeburn 22925: unless ($currcookies{$balancer}) {
22926: $changes{'curr'}{$balancer}{'cookie'} = 1;
22927: }
22928: }
22929: } elsif (exists($currbalancer{$balancer})) {
22930: if ($currcookies{$balancer}) {
22931: $changes{'curr'}{$balancer}{'cookie'} = 1;
22932: }
22933: }
1.171 raeburn 22934: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 22935: foreach my $sparetype (@sparestypes) {
1.171 raeburn 22936: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
22937: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 22938: if (@targetdiffs > 0) {
1.171 raeburn 22939: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 22940: }
1.171 raeburn 22941: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
22942: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
22943: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 22944: }
22945: }
22946: }
22947: } else {
1.171 raeburn 22948: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 22949: foreach my $sparetype (@sparestypes) {
1.171 raeburn 22950: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
22951: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
22952: $changes{'curr'}{$balancer}{'targets'} = 1;
22953: }
1.150 raeburn 22954: }
22955: }
1.210 raeburn 22956: }
1.150 raeburn 22957: }
22958: my $ishomedom;
1.171 raeburn 22959: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
22960: $ishomedom = 1;
1.150 raeburn 22961: }
22962: if (ref($alltypes) eq 'ARRAY') {
22963: foreach my $type (@{$alltypes}) {
22964: my $rule;
1.210 raeburn 22965: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 22966: (!$ishomedom)) {
1.171 raeburn 22967: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
22968: }
22969: if ($rule eq 'specific') {
1.255 raeburn 22970: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 22971: if (exists($servers{$specifiedhost})) {
1.255 raeburn 22972: $rule = $specifiedhost;
22973: }
1.150 raeburn 22974: }
1.171 raeburn 22975: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
22976: if (ref($currrules{$balancer}) eq 'HASH') {
22977: if ($rule ne $currrules{$balancer}{$type}) {
22978: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 22979: }
22980: } elsif ($rule ne '') {
1.171 raeburn 22981: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 22982: }
22983: }
22984: }
1.171 raeburn 22985: }
22986: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
22987: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
22988: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
22989: $defaultshash{'loadbalancing'} = {};
22990: }
22991: my $putresult = &Apache::lonnet::put_dom('configuration',
22992: \%defaultshash,$dom);
22993: if ($putresult eq 'ok') {
22994: if (keys(%changes) > 0) {
1.252 raeburn 22995: my %toupdate;
1.171 raeburn 22996: if (ref($changes{'delete'}) eq 'ARRAY') {
22997: foreach my $balancer (sort(@{$changes{'delete'}})) {
22998: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 22999: $toupdate{$balancer} = 1;
1.150 raeburn 23000: }
1.171 raeburn 23001: }
23002: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 23003: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 23004: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 23005: $toupdate{$balancer} = 1;
1.171 raeburn 23006: }
23007: }
23008: if (ref($changes{'curr'}) eq 'HASH') {
23009: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 23010: $toupdate{$balancer} = 1;
1.171 raeburn 23011: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
23012: if ($changes{'curr'}{$balancer}{'targets'}) {
23013: my %offloadstr;
23014: foreach my $sparetype (@sparestypes) {
23015: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23016: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23017: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
23018: }
23019: }
1.150 raeburn 23020: }
1.171 raeburn 23021: if (keys(%offloadstr) == 0) {
23022: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 23023: } else {
1.171 raeburn 23024: my $showoffload;
23025: foreach my $sparetype (@sparestypes) {
23026: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
23027: if (defined($offloadstr{$sparetype})) {
23028: $showoffload .= $offloadstr{$sparetype};
23029: } else {
23030: $showoffload .= &mt('None');
23031: }
23032: $showoffload .= (' 'x3);
23033: }
23034: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 23035: }
23036: }
23037: }
1.171 raeburn 23038: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
23039: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
23040: foreach my $type (@{$alltypes}) {
23041: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
23042: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23043: my $balancetext;
23044: if ($rule eq '') {
23045: $balancetext = $ruletitles{'default'};
1.209 raeburn 23046: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 23047: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 23048: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 23049: foreach my $sparetype (@sparestypes) {
23050: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23051: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
23052: }
23053: }
1.253 raeburn 23054: foreach my $item (@{$alltypes}) {
23055: next if ($item =~ /^_LC_ipchange/);
23056: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
23057: if ($hasrule eq 'homeserver') {
23058: map { $toupdate{$_} = 1; } (keys(%libraryservers));
23059: } else {
23060: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
23061: if ($servers{$hasrule}) {
23062: $toupdate{$hasrule} = 1;
23063: }
23064: }
23065: }
23066: }
1.254 raeburn 23067: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
23068: $balancetext = $ruletitles{$rule};
23069: } else {
23070: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23071: $balancetext = $ruletitles{'particular'}.' '.$receiver;
23072: if ($receiver) {
23073: $toupdate{$receiver};
23074: }
23075: }
23076: } else {
23077: $balancetext = $ruletitles{$rule};
1.252 raeburn 23078: }
1.171 raeburn 23079: } else {
23080: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
23081: }
1.210 raeburn 23082: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 23083: }
23084: }
23085: }
23086: }
1.342 raeburn 23087: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.389 raeburn 23088: if ($currcookies{$balancer}) {
23089: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
23090: $balancer).'</li>';
23091: } else {
23092: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
23093: $balancer).'</li>';
23094: }
1.342 raeburn 23095: }
1.375 raeburn 23096: }
23097: }
23098: if (keys(%toupdate)) {
23099: my %thismachine;
23100: my $updatedhere;
23101: my $cachetime = 60*60*24;
23102: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
23103: foreach my $lonhost (keys(%toupdate)) {
23104: if ($thismachine{$lonhost}) {
23105: unless ($updatedhere) {
23106: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
23107: $defaultshash{'loadbalancing'},
23108: $cachetime);
23109: $updatedhere = 1;
1.252 raeburn 23110: }
1.375 raeburn 23111: } else {
23112: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
23113: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.252 raeburn 23114: }
1.150 raeburn 23115: }
1.171 raeburn 23116: }
23117: if ($resulttext ne '') {
23118: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 23119: } else {
23120: $resulttext = $nochgmsg;
23121: }
23122: } else {
1.171 raeburn 23123: $resulttext = $nochgmsg;
1.150 raeburn 23124: }
23125: } else {
1.171 raeburn 23126: $resulttext = '<span class="LC_error">'.
23127: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 23128: }
23129: } else {
1.171 raeburn 23130: $resulttext = $nochgmsg;
1.150 raeburn 23131: }
23132: return $resulttext;
23133: }
23134:
1.48 raeburn 23135: sub recurse_check {
23136: my ($chkcats,$categories,$depth,$name) = @_;
23137: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
23138: my $chg = 0;
23139: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
23140: my $category = $chkcats->[$depth]{$name}[$j];
23141: my $item;
23142: if ($category eq '') {
23143: $chg ++;
23144: } else {
23145: my $deeper = $depth + 1;
23146: $item = &escape($category).':'.&escape($name).':'.$depth;
23147: if ($chg) {
23148: $categories->{$item} -= $chg;
23149: }
23150: &recurse_check($chkcats,$categories,$deeper,$category);
23151: $deeper --;
23152: }
23153: }
23154: }
23155: return;
23156: }
23157:
23158: sub recurse_cat_deletes {
23159: my ($item,$coursecategories,$deletions) = @_;
23160: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
23161: my $subdepth = $depth + 1;
23162: if (ref($coursecategories) eq 'HASH') {
23163: foreach my $subitem (keys(%{$coursecategories})) {
23164: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
23165: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
23166: delete($coursecategories->{$subitem});
23167: $deletions->{$subitem} = 1;
23168: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 23169: }
1.48 raeburn 23170: }
23171: }
23172: return;
23173: }
23174:
1.125 raeburn 23175: sub active_dc_picker {
1.191 raeburn 23176: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 23177: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 23178: my @domcoord = keys(%domcoords);
23179: if (keys(%currhash)) {
23180: foreach my $dc (keys(%currhash)) {
23181: unless (exists($domcoords{$dc})) {
23182: push(@domcoord,$dc);
23183: }
23184: }
23185: }
23186: @domcoord = sort(@domcoord);
1.210 raeburn 23187: my $numdcs = scalar(@domcoord);
1.191 raeburn 23188: my $rows = 0;
23189: my $table;
1.125 raeburn 23190: if ($numdcs > 1) {
1.191 raeburn 23191: $table = '<table>';
23192: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 23193: my $rem = $i%($numinrow);
23194: if ($rem == 0) {
23195: if ($i > 0) {
1.191 raeburn 23196: $table .= '</tr>';
1.125 raeburn 23197: }
1.191 raeburn 23198: $table .= '<tr>';
23199: $rows ++;
1.125 raeburn 23200: }
1.191 raeburn 23201: my $check = '';
23202: if ($inputtype eq 'radio') {
23203: if (keys(%currhash) == 0) {
23204: if (!$i) {
23205: $check = ' checked="checked"';
23206: }
23207: } elsif (exists($currhash{$domcoord[$i]})) {
23208: $check = ' checked="checked"';
23209: }
23210: } else {
23211: if (exists($currhash{$domcoord[$i]})) {
23212: $check = ' checked="checked"';
1.125 raeburn 23213: }
23214: }
1.191 raeburn 23215: if ($i == @domcoord - 1) {
1.125 raeburn 23216: my $colsleft = $numinrow - $rem;
23217: if ($colsleft > 1) {
1.191 raeburn 23218: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 23219: } else {
1.191 raeburn 23220: $table .= '<td class="LC_left_item">';
1.125 raeburn 23221: }
23222: } else {
1.191 raeburn 23223: $table .= '<td class="LC_left_item">';
23224: }
23225: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
23226: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
23227: $table .= '<span class="LC_nobreak"><label>'.
23228: '<input type="'.$inputtype.'" name="'.$name.'"'.
23229: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
23230: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 23231: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 23232: }
1.219 raeburn 23233: $table .= '</label></span></td>';
1.191 raeburn 23234: }
23235: $table .= '</tr></table>';
23236: } elsif ($numdcs == 1) {
1.219 raeburn 23237: my ($dcname,$dcdom) = split(':',$domcoord[0]);
23238: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 23239: if ($inputtype eq 'radio') {
1.247 raeburn 23240: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 23241: if ($user ne $dcname.':'.$dcdom) {
23242: $table .= ' ('.$dcname.':'.$dcdom.')';
23243: }
1.191 raeburn 23244: } else {
23245: my $check;
23246: if (exists($currhash{$domcoord[0]})) {
23247: $check = ' checked="checked"';
1.125 raeburn 23248: }
1.247 raeburn 23249: $table = '<span class="LC_nobreak"><label>'.
23250: '<input type="checkbox" name="'.$name.'" '.
23251: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 23252: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 23253: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 23254: }
1.220 raeburn 23255: $table .= '</label></span>';
1.191 raeburn 23256: $rows ++;
1.125 raeburn 23257: }
23258: }
1.191 raeburn 23259: return ($numdcs,$table,$rows);
1.125 raeburn 23260: }
23261:
1.137 raeburn 23262: sub usersession_titles {
23263: return &Apache::lonlocal::texthash(
23264: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
23265: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 23266: spares => 'Servers offloaded to, when busy',
1.137 raeburn 23267: version => 'LON-CAPA version requirement',
1.138 raeburn 23268: excludedomain => 'Allow all, but exclude specific domains',
23269: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 23270: primary => 'Primary (checked first)',
1.154 raeburn 23271: default => 'Default',
1.137 raeburn 23272: );
23273: }
23274:
1.152 raeburn 23275: sub id_for_thisdom {
23276: my (%servers) = @_;
23277: my %altids;
23278: foreach my $server (keys(%servers)) {
23279: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
23280: if ($serverhome ne $server) {
23281: $altids{$serverhome} = $server;
23282: }
23283: }
23284: return %altids;
23285: }
23286:
1.150 raeburn 23287: sub count_servers {
23288: my ($currbalancer,%servers) = @_;
23289: my (@spares,$numspares);
23290: foreach my $lonhost (sort(keys(%servers))) {
23291: next if ($currbalancer eq $lonhost);
23292: push(@spares,$lonhost);
23293: }
23294: if ($currbalancer) {
23295: $numspares = scalar(@spares);
23296: } else {
23297: $numspares = scalar(@spares) - 1;
23298: }
23299: return ($numspares,@spares);
23300: }
23301:
23302: sub lonbalance_targets_js {
1.171 raeburn 23303: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 23304: my $select = &mt('Select');
23305: my ($alltargets,$allishome,$allinsttypes,@alltypes);
23306: if (ref($servers) eq 'HASH') {
23307: $alltargets = join("','",sort(keys(%{$servers})));
23308: my @homedoms;
23309: foreach my $server (sort(keys(%{$servers}))) {
23310: if (&Apache::lonnet::host_domain($server) eq $dom) {
23311: push(@homedoms,'1');
23312: } else {
23313: push(@homedoms,'0');
23314: }
23315: }
23316: $allishome = join("','",@homedoms);
23317: }
23318: if (ref($types) eq 'ARRAY') {
23319: if (@{$types} > 0) {
23320: @alltypes = @{$types};
23321: }
23322: }
23323: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
23324: $allinsttypes = join("','",@alltypes);
1.342 raeburn 23325: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 23326: if (ref($settings) eq 'HASH') {
23327: %existing = %{$settings};
23328: }
23329: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 23330: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 23331: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 23332: return <<"END";
23333:
23334: <script type="text/javascript">
23335: // <![CDATA[
23336:
1.171 raeburn 23337: currBalancers = new Array('$balancers');
23338:
23339: function toggleTargets(balnum) {
23340: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23341: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
23342: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
23343: var prevbalancer = prevhostitem.value;
23344: var baltotal = document.getElementById('loadbalancing_total').value;
23345: prevhostitem.value = balancer;
23346: if (prevbalancer != '') {
23347: var prevIdx = currBalancers.indexOf(prevbalancer);
23348: if (prevIdx != -1) {
23349: currBalancers.splice(prevIdx,1);
23350: }
23351: }
1.150 raeburn 23352: if (balancer == '') {
1.171 raeburn 23353: hideSpares(balnum);
1.150 raeburn 23354: } else {
1.171 raeburn 23355: var currIdx = currBalancers.indexOf(balancer);
23356: if (currIdx == -1) {
23357: currBalancers.push(balancer);
23358: }
1.150 raeburn 23359: var homedoms = new Array('$allishome');
1.171 raeburn 23360: var ishomedom = homedoms[lonhostitem.selectedIndex];
23361: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 23362: }
1.171 raeburn 23363: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 23364: return;
23365: }
23366:
1.171 raeburn 23367: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 23368: var alltargets = new Array('$alltargets');
23369: var insttypes = new Array('$allinsttypes');
1.151 raeburn 23370: var offloadtypes = new Array('primary','default');
23371:
1.171 raeburn 23372: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
23373: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 23374:
1.151 raeburn 23375: for (var i=0; i<offloadtypes.length; i++) {
23376: var count = 0;
23377: for (var j=0; j<alltargets.length; j++) {
23378: if (alltargets[j] != balancer) {
1.171 raeburn 23379: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
23380: item.value = alltargets[j];
23381: item.style.textAlign='left';
23382: item.style.textFace='normal';
23383: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
23384: if (currBalancers.indexOf(alltargets[j]) == -1) {
23385: item.disabled = '';
23386: } else {
23387: item.disabled = 'disabled';
23388: item.checked = false;
23389: }
1.151 raeburn 23390: count ++;
23391: }
1.150 raeburn 23392: }
23393: }
1.151 raeburn 23394: for (var k=0; k<insttypes.length; k++) {
23395: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 23396: if (ishomedom == 1) {
1.171 raeburn 23397: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23398: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23399: } else {
1.171 raeburn 23400: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23401: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 23402: }
23403: } else {
1.171 raeburn 23404: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23405: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23406: }
1.151 raeburn 23407: if ((insttypes[k] != '_LC_external') &&
23408: ((insttypes[k] != '_LC_internetdom') ||
23409: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 23410: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
23411: item.options.length = 0;
23412: item.options[0] = new Option("","",true,true);
1.210 raeburn 23413: var idx = 0;
1.151 raeburn 23414: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 23415: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
23416: idx ++;
23417: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 23418: }
23419: }
23420: }
23421: }
23422: return;
23423: }
23424:
1.171 raeburn 23425: function hideSpares(balnum) {
1.150 raeburn 23426: var alltargets = new Array('$alltargets');
23427: var insttypes = new Array('$allinsttypes');
23428: var offloadtypes = new Array('primary','default');
23429:
1.171 raeburn 23430: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
23431: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 23432:
23433: var total = alltargets.length - 1;
23434: for (var i=0; i<offloadtypes; i++) {
23435: for (var j=0; j<total; j++) {
1.171 raeburn 23436: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
23437: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
23438: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 23439: }
1.150 raeburn 23440: }
23441: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 23442: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23443: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 23444: if (insttypes[k] != '_LC_external') {
1.171 raeburn 23445: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
23446: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 23447: }
23448: }
23449: return;
23450: }
23451:
1.171 raeburn 23452: function checkOffloads(item,balnum,type) {
1.150 raeburn 23453: var alltargets = new Array('$alltargets');
23454: var offloadtypes = new Array('primary','default');
23455: if (item.checked) {
23456: var total = alltargets.length - 1;
23457: var other;
23458: if (type == offloadtypes[0]) {
1.151 raeburn 23459: other = offloadtypes[1];
1.150 raeburn 23460: } else {
1.151 raeburn 23461: other = offloadtypes[0];
1.150 raeburn 23462: }
23463: for (var i=0; i<total; i++) {
1.171 raeburn 23464: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 23465: if (server == item.value) {
1.171 raeburn 23466: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
23467: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 23468: }
23469: }
23470: }
23471: }
23472: return;
23473: }
23474:
1.171 raeburn 23475: function singleServerToggle(balnum,type) {
23476: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 23477: if (offloadtoSelIdx == 0) {
1.171 raeburn 23478: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
23479: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23480:
23481: } else {
1.171 raeburn 23482: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
23483: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 23484: }
23485: return;
23486: }
23487:
1.171 raeburn 23488: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 23489: if (type == '_LC_external') {
1.171 raeburn 23490: return;
1.150 raeburn 23491: }
1.171 raeburn 23492: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 23493: for (var i=0; i<typesRules.length; i++) {
23494: if (formname.elements[typesRules[i]].checked) {
23495: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 23496: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
23497: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23498: } else {
1.171 raeburn 23499: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
23500: }
23501: }
23502: }
23503: return;
23504: }
23505:
23506: function balancerDeleteChange(balnum) {
23507: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23508: var baltotal = document.getElementById('loadbalancing_total').value;
23509: var addtarget;
23510: var removetarget;
23511: var action = 'delete';
23512: if (document.getElementById('loadbalancing_delete_'+balnum)) {
23513: var lonhost = hostitem.value;
23514: var currIdx = currBalancers.indexOf(lonhost);
23515: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
23516: if (currIdx != -1) {
23517: currBalancers.splice(currIdx,1);
23518: }
23519: addtarget = lonhost;
23520: } else {
23521: if (currIdx == -1) {
23522: currBalancers.push(lonhost);
23523: }
23524: removetarget = lonhost;
23525: action = 'undelete';
23526: }
23527: balancerChange(balnum,baltotal,action,addtarget,removetarget);
23528: }
23529: return;
23530: }
23531:
23532: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
23533: if (baltotal > 1) {
23534: var offloadtypes = new Array('primary','default');
23535: var alltargets = new Array('$alltargets');
23536: var insttypes = new Array('$allinsttypes');
23537: for (var i=0; i<baltotal; i++) {
23538: if (i != balnum) {
23539: for (var j=0; j<offloadtypes.length; j++) {
23540: var total = alltargets.length - 1;
23541: for (var k=0; k<total; k++) {
23542: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
23543: var server = serveritem.value;
23544: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23545: if (server == addtarget) {
23546: serveritem.disabled = '';
23547: }
23548: }
23549: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23550: if (server == removetarget) {
23551: serveritem.disabled = 'disabled';
23552: serveritem.checked = false;
23553: }
23554: }
23555: }
23556: }
23557: for (var j=0; j<insttypes.length; j++) {
23558: if (insttypes[j] != '_LC_external') {
23559: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
23560: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
23561: var currSel = singleserver.selectedIndex;
23562: var currVal = singleserver.options[currSel].value;
23563: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23564: var numoptions = singleserver.options.length;
23565: var needsnew = 1;
23566: for (var k=0; k<numoptions; k++) {
23567: if (singleserver.options[k] == addtarget) {
23568: needsnew = 0;
23569: break;
23570: }
23571: }
23572: if (needsnew == 1) {
23573: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
23574: }
23575: }
23576: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23577: singleserver.options.length = 0;
23578: if ((currVal) && (currVal != removetarget)) {
23579: singleserver.options[0] = new Option("","",false,false);
23580: } else {
23581: singleserver.options[0] = new Option("","",true,true);
23582: }
23583: var idx = 0;
23584: for (var m=0; m<alltargets.length; m++) {
23585: if (currBalancers.indexOf(alltargets[m]) == -1) {
23586: idx ++;
23587: if (currVal == alltargets[m]) {
23588: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
23589: } else {
23590: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
23591: }
23592: }
23593: }
23594: }
23595: }
23596: }
23597: }
1.150 raeburn 23598: }
23599: }
23600: }
23601: return;
23602: }
23603:
1.152 raeburn 23604: // ]]>
23605: </script>
23606:
23607: END
23608: }
23609:
23610: sub new_spares_js {
23611: my @sparestypes = ('primary','default');
23612: my $types = join("','",@sparestypes);
23613: my $select = &mt('Select');
23614: return <<"END";
23615:
23616: <script type="text/javascript">
23617: // <![CDATA[
23618:
23619: function updateNewSpares(formname,lonhost) {
23620: var types = new Array('$types');
23621: var include = new Array();
23622: var exclude = new Array();
23623: for (var i=0; i<types.length; i++) {
23624: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
23625: for (var j=0; j<spareboxes.length; j++) {
23626: if (formname.elements[spareboxes[j]].checked) {
23627: exclude.push(formname.elements[spareboxes[j]].value);
23628: } else {
23629: include.push(formname.elements[spareboxes[j]].value);
23630: }
23631: }
23632: }
23633: for (var i=0; i<types.length; i++) {
23634: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
23635: var selIdx = newSpare.selectedIndex;
23636: var currnew = newSpare.options[selIdx].value;
23637: var okSpares = new Array();
23638: for (var j=0; j<newSpare.options.length; j++) {
23639: var possible = newSpare.options[j].value;
23640: if (possible != '') {
23641: if (exclude.indexOf(possible) == -1) {
23642: okSpares.push(possible);
23643: } else {
23644: if (currnew == possible) {
23645: selIdx = 0;
23646: }
23647: }
23648: }
23649: }
23650: for (var k=0; k<include.length; k++) {
23651: if (okSpares.indexOf(include[k]) == -1) {
23652: okSpares.push(include[k]);
23653: }
23654: }
23655: okSpares.sort();
23656: newSpare.options.length = 0;
23657: if (selIdx == 0) {
23658: newSpare.options[0] = new Option("$select","",true,true);
23659: } else {
23660: newSpare.options[0] = new Option("$select","",false,false);
23661: }
23662: for (var m=0; m<okSpares.length; m++) {
23663: var idx = m+1;
23664: var selThis = 0;
23665: if (selIdx != 0) {
23666: if (okSpares[m] == currnew) {
23667: selThis = 1;
23668: }
23669: }
23670: if (selThis == 1) {
23671: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
23672: } else {
23673: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
23674: }
23675: }
23676: }
23677: return;
23678: }
23679:
23680: function checkNewSpares(lonhost,type) {
23681: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
23682: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.372 raeburn 23683: if (chosen != '') {
1.152 raeburn 23684: var othertype;
23685: var othernewSpare;
23686: if (type == 'primary') {
23687: othernewSpare = document.getElementById('newspare_default_'+lonhost);
23688: }
23689: if (type == 'default') {
23690: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
23691: }
23692: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
23693: othernewSpare.selectedIndex = 0;
23694: }
23695: }
23696: return;
23697: }
23698:
23699: // ]]>
23700: </script>
23701:
23702: END
23703:
23704: }
23705:
23706: sub common_domprefs_js {
23707: return <<"END";
23708:
23709: <script type="text/javascript">
23710: // <![CDATA[
23711:
1.150 raeburn 23712: function getIndicesByName(formname,item) {
1.152 raeburn 23713: var group = new Array();
1.150 raeburn 23714: for (var i=0;i<formname.elements.length;i++) {
23715: if (formname.elements[i].name == item) {
1.152 raeburn 23716: group.push(formname.elements[i].id);
1.150 raeburn 23717: }
23718: }
1.152 raeburn 23719: return group;
1.150 raeburn 23720: }
23721:
23722: // ]]>
23723: </script>
23724:
23725: END
1.152 raeburn 23726:
1.150 raeburn 23727: }
23728:
1.165 raeburn 23729: sub recaptcha_js {
23730: my %lt = &captcha_phrases();
23731: return <<"END";
23732:
23733: <script type="text/javascript">
23734: // <![CDATA[
23735:
23736: function updateCaptcha(caller,context) {
23737: var privitem;
23738: var pubitem;
23739: var privtext;
23740: var pubtext;
1.269 raeburn 23741: var versionitem;
23742: var versiontext;
1.165 raeburn 23743: if (document.getElementById(context+'_recaptchapub')) {
23744: pubitem = document.getElementById(context+'_recaptchapub');
23745: } else {
23746: return;
23747: }
23748: if (document.getElementById(context+'_recaptchapriv')) {
23749: privitem = document.getElementById(context+'_recaptchapriv');
23750: } else {
23751: return;
23752: }
23753: if (document.getElementById(context+'_recaptchapubtxt')) {
23754: pubtext = document.getElementById(context+'_recaptchapubtxt');
23755: } else {
23756: return;
23757: }
23758: if (document.getElementById(context+'_recaptchaprivtxt')) {
23759: privtext = document.getElementById(context+'_recaptchaprivtxt');
23760: } else {
23761: return;
23762: }
1.269 raeburn 23763: if (document.getElementById(context+'_recaptchaversion')) {
23764: versionitem = document.getElementById(context+'_recaptchaversion');
23765: } else {
23766: return;
23767: }
23768: if (document.getElementById(context+'_recaptchavertxt')) {
23769: versiontext = document.getElementById(context+'_recaptchavertxt');
23770: } else {
23771: return;
23772: }
1.165 raeburn 23773: if (caller.checked) {
23774: if (caller.value == 'recaptcha') {
23775: pubitem.type = 'text';
23776: privitem.type = 'text';
23777: pubitem.size = '40';
23778: privitem.size = '40';
23779: pubtext.innerHTML = "$lt{'pub'}";
23780: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 23781: versionitem.type = 'text';
23782: versionitem.size = '3';
1.289 raeburn 23783: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 23784: } else {
23785: pubitem.type = 'hidden';
23786: privitem.type = 'hidden';
1.269 raeburn 23787: versionitem.type = 'hidden';
1.165 raeburn 23788: pubtext.innerHTML = '';
23789: privtext.innerHTML = '';
1.269 raeburn 23790: versiontext.innerHTML = '';
1.165 raeburn 23791: }
23792: }
23793: return;
23794: }
23795:
23796: // ]]>
23797: </script>
23798:
23799: END
23800:
23801: }
23802:
1.236 raeburn 23803: sub toggle_display_js {
1.192 raeburn 23804: return <<"END";
23805:
23806: <script type="text/javascript">
23807: // <![CDATA[
23808:
1.236 raeburn 23809: function toggleDisplay(domForm,caller) {
23810: if (document.getElementById(caller)) {
23811: var divitem = document.getElementById(caller);
23812: var optionsElement = domForm.coursecredits;
1.264 raeburn 23813: var checkval = 1;
23814: var dispval = 'block';
1.303 raeburn 23815: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 23816: if (caller == 'emailoptions') {
1.372 raeburn 23817: optionsElement = domForm.cancreate_email;
1.236 raeburn 23818: }
1.257 raeburn 23819: if (caller == 'studentsubmission') {
23820: optionsElement = domForm.postsubmit;
23821: }
1.264 raeburn 23822: if (caller == 'cloneinstcode') {
23823: optionsElement = domForm.canclone;
23824: checkval = 'instcode';
23825: }
1.303 raeburn 23826: if (selfcreateRegExp.test(caller)) {
23827: optionsElement = domForm.elements[caller];
23828: checkval = 'other';
23829: dispval = 'inline'
23830: }
1.236 raeburn 23831: if (optionsElement.length) {
1.192 raeburn 23832: var currval;
1.236 raeburn 23833: for (var i=0; i<optionsElement.length; i++) {
23834: if (optionsElement[i].checked) {
23835: currval = optionsElement[i].value;
1.192 raeburn 23836: }
23837: }
1.264 raeburn 23838: if (currval == checkval) {
23839: divitem.style.display = dispval;
1.192 raeburn 23840: } else {
1.236 raeburn 23841: divitem.style.display = 'none';
1.192 raeburn 23842: }
23843: }
23844: }
23845: return;
23846: }
23847:
23848: // ]]>
23849: </script>
23850:
23851: END
23852:
23853: }
23854:
1.165 raeburn 23855: sub captcha_phrases {
23856: return &Apache::lonlocal::texthash (
23857: priv => 'Private key',
23858: pub => 'Public key',
23859: original => 'original (CAPTCHA)',
23860: recaptcha => 'successor (ReCAPTCHA)',
23861: notused => 'unused',
1.289 raeburn 23862: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 23863: );
23864: }
23865:
1.205 raeburn 23866: sub devalidate_remote_domconfs {
1.212 raeburn 23867: my ($dom,$cachekeys) = @_;
23868: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 23869: my %servers = &Apache::lonnet::internet_dom_servers($dom);
23870: my %thismachine;
23871: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 raeburn 23872: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.394 raeburn 23873: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
1.410 raeburn 23874: 'ipaccess','trust');
1.386 raeburn 23875: my %cache_by_lonhost;
23876: if (exists($cachekeys->{'samllanding'})) {
23877: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
23878: my %landing = %{$cachekeys->{'samllanding'}};
23879: my %domservers = &Apache::lonnet::get_servers($dom);
23880: if (keys(%domservers)) {
23881: foreach my $server (keys(%domservers)) {
23882: my @cached;
23883: next if ($thismachine{$server});
23884: if ($landing{$server}) {
23885: push(@cached,&escape('samllanding').':'.&escape($server));
23886: }
23887: if (@cached) {
23888: $cache_by_lonhost{$server} = \@cached;
23889: }
23890: }
23891: }
23892: }
23893: }
1.260 raeburn 23894: if (keys(%servers)) {
1.205 raeburn 23895: foreach my $server (keys(%servers)) {
23896: next if ($thismachine{$server});
1.212 raeburn 23897: my @cached;
23898: foreach my $name (@posscached) {
23899: if ($cachekeys->{$name}) {
1.388 raeburn 23900: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
1.386 raeburn 23901: if (ref($cachekeys->{$name}) eq 'HASH') {
1.373 raeburn 23902: foreach my $key (keys(%{$cachekeys->{$name}})) {
23903: push(@cached,&escape($name).':'.&escape($key));
23904: }
23905: }
23906: } else {
23907: push(@cached,&escape($name).':'.&escape($dom));
23908: }
1.212 raeburn 23909: }
23910: }
1.386 raeburn 23911: if ((exists($cache_by_lonhost{$server})) &&
23912: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
23913: push(@cached,@{$cache_by_lonhost{$server}});
23914: }
1.212 raeburn 23915: if (@cached) {
23916: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
23917: }
1.205 raeburn 23918: }
23919: }
23920: return;
23921: }
23922:
1.3 raeburn 23923: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>