Annotation of loncom/interface/domainprefs.pm, revision 1.431
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.431 ! raeburn 4: # $Id: domainprefs.pm,v 1.430 2023/11/03 01:12:15 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
1.286 raeburn 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
1.1 raeburn 24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: ###############################################################
1.297 raeburn 30: ###############################################################
1.1 raeburn 31:
1.101 raeburn 32: =pod
33:
34: =head1 NAME
35:
36: Apache::domainprefs.pm
37:
38: =head1 SYNOPSIS
39:
40: Handles configuration of a LON-CAPA domain.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
45:
46: =head1 OVERVIEW
47:
48: Each institution using LON-CAPA will typically have a single domain designated
1.183 bisitz 49: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 50: may define a default set of logos and a color scheme which can be used to "brand"
51: the LON-CAPA instance. In addition, an institution will typically have a language
52: and timezone which are used for the majority of courses.
53:
54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
55: host of other domain-wide settings which determine the types of functionality
56: available to users and courses in the domain.
57:
58: There is also a mechanism to configure cataloging of courses in the domain, and
59: controls on the operation of automated processes which govern such things as
60: roster updates, user directory updates and processing of course requests.
61:
62: The domain coordination manual which is built dynamically on install/update of
63: LON-CAPA from the relevant help items provides more information about domain
64: configuration.
65:
66: Most of the domain settings are stored in the configuration.db GDBM file which is
67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
68: where $dom is the domain. The configuration.db stores settings in a number of
69: frozen hashes of hashes. In a few cases, domain information must be uploaded to
70: the domain as files (e.g., image files for logos etc., or plain text files for
71: bubblesheet formats). In this case the domainprefs.pm must be running in a user
72: session hosted on the primary library server in the domain, as these files are
73: stored in author space belonging to a special $dom-domainconfig user.
74:
75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
76: the current settings, and provides an interface to make modifications.
77:
78: =head1 SUBROUTINES
79:
80: =over
81:
82: =item print_quotas()
83:
84: Inputs: 4
85:
86: $dom,$settings,$rowtotal,$action.
87:
88: $dom is the domain, $settings is a reference to a hash of current settings for
89: the current context, $rowtotal is a reference to the scalar used to record the
1.210 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.163 raeburn 91: requestcourses or requestauthor).
1.101 raeburn 92:
93: The print_quotas routine was orginally created to display/store information
94: about default quota sizes for portfolio spaces for the different types of
95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
96: but is now also used to manage availability of user tools:
97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.429 raeburn 98: used by course owners to request creation of a course.
1.101 raeburn 99:
100: Outputs: 1
101:
102: $datatable - HTML containing form elements which allow settings to be changed.
103:
104: In the case of course requests, radio buttons are displayed for each institutional
105: affiliate type (and also default, and _LC_adv) for each of the course types
1.325 raeburn 106: (official, unofficial, community, textbook, placement, and lti).
1.425 raeburn 107: In each case the radio buttons allow the selection of one of four values:
1.101 raeburn 108:
1.104 raeburn 109: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 110: which have the following effects:
111:
112: 0
113:
114: =over
115:
116: - course requests are not allowed for this course types/affiliation
117:
118: =back
119:
1.104 raeburn 120: approval
1.101 raeburn 121:
122: =over
123:
124: - course requests must be approved by a Doman Coordinator in the
125: course's domain
126:
127: =back
128:
129: validate
130:
131: =over
132:
133: - an institutional validation (e.g., check requestor is instructor
134: of record) needs to be passed before the course will be created. The required
135: validation is in localenroll.pm on the primary library server for the course
136: domain.
137:
138: =back
139:
140: autolimit
141:
142: =over
143:
1.143 raeburn 144: - course requests will be processed automatically up to a limit of
1.101 raeburn 145: N requests for the course type for the particular requestor.
146: If N is undefined, there is no limit to the number of course requests
147: which a course owner may submit and have processed automatically.
148:
149: =back
150:
151: =item modify_quotas()
152:
153: =back
154:
155: =cut
156:
1.1 raeburn 157: package Apache::domainprefs;
158:
159: use strict;
160: use Apache::Constants qw(:common :http);
161: use Apache::lonnet;
162: use Apache::loncommon();
163: use Apache::lonhtmlcommon();
164: use Apache::lonlocal;
1.43 raeburn 165: use Apache::lonmsg();
1.91 raeburn 166: use Apache::lonconfigsettings;
1.232 raeburn 167: use Apache::lonuserutils();
1.235 raeburn 168: use Apache::loncoursequeueadmin();
1.419 raeburn 169: use Apache::courseprefs();
1.69 raeburn 170: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 171: use LONCAPA::Enrollment;
1.81 raeburn 172: use LONCAPA::lonauthcgi();
1.275 raeburn 173: use LONCAPA::SSL;
1.9 raeburn 174: use File::Copy;
1.43 raeburn 175: use Locale::Language;
1.62 raeburn 176: use DateTime::TimeZone;
1.68 raeburn 177: use DateTime::Locale;
1.267 raeburn 178: use Time::HiRes qw( sleep );
1.373 raeburn 179: use Net::CIDR;
1.424 raeburn 180: use Crypt::CBC;
1.1 raeburn 181:
1.155 raeburn 182: my $registered_cleanup;
183: my $modified_urls;
184:
1.1 raeburn 185: sub handler {
186: my $r=shift;
187: if ($r->header_only) {
188: &Apache::loncommon::content_type($r,'text/html');
189: $r->send_http_header;
190: return OK;
191: }
192:
1.91 raeburn 193: my $context = 'domain';
1.1 raeburn 194: my $dom = $env{'request.role.domain'};
1.5 albertel 195: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 196: if (&Apache::lonnet::allowed('mau',$dom)) {
197: &Apache::loncommon::content_type($r,'text/html');
198: $r->send_http_header;
199: } else {
200: $env{'user.error.msg'}=
201: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
202: return HTTP_NOT_ACCEPTABLE;
203: }
1.155 raeburn 204:
205: $registered_cleanup=0;
206: @{$modified_urls}=();
207:
1.1 raeburn 208: &Apache::lonhtmlcommon::clear_breadcrumbs();
209: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 210: ['phase','actions']);
1.30 raeburn 211: my $phase = 'pickactions';
1.3 raeburn 212: if ( exists($env{'form.phase'}) ) {
213: $phase = $env{'form.phase'};
214: }
1.150 raeburn 215: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 216: my %domconfig =
1.6 raeburn 217: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 218: 'quotas','autoenroll','autoupdate','autocreate',
219: 'directorysrch','usercreation','usermodification',
220: 'contacts','defaults','scantron','coursecategories',
221: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 222: 'coursedefaults','usersessions','loadbalancing',
1.267 raeburn 223: 'requestauthor','selfenrollment','inststatus',
1.421 raeburn 224: 'ltitools','toolsec','ssl','trust','lti','ltisec',
1.429 raeburn 225: 'privacy','passwords','proctoring','wafproxy',
226: 'ipaccess','authordefaults'],$dom);
1.320 raeburn 227: my %encconfig =
1.405 raeburn 228: &Apache::lonnet::get_dom('encconfig',['ltitools','lti','proctoring','linkprot'],$dom,undef,1);
1.424 raeburn 229: my ($checked_is_home,$is_home);
1.297 raeburn 230: if (ref($domconfig{'ltitools'}) eq 'HASH') {
231: if (ref($encconfig{'ltitools'}) eq 'HASH') {
1.423 raeburn 232: my $home = &Apache::lonnet::domain($dom,'primary');
233: unless (($home eq 'no_host') || ($home eq '')) {
234: my @ids=&Apache::lonnet::current_machine_ids();
235: if (grep(/^\Q$home\E$/,@ids)) {
236: $is_home = 1;
237: }
238: }
1.425 raeburn 239: $checked_is_home = 1;
1.297 raeburn 240: foreach my $id (keys(%{$domconfig{'ltitools'}})) {
1.320 raeburn 241: if ((ref($domconfig{'ltitools'}{$id}) eq 'HASH') &&
242: (ref($encconfig{'ltitools'}{$id}) eq 'HASH')) {
1.421 raeburn 243: $domconfig{'ltitools'}{$id}{'key'} = $encconfig{'ltitools'}{$id}{'key'};
1.423 raeburn 244: if (($is_home) && ($phase eq 'process')) {
245: $domconfig{'ltitools'}{$id}{'secret'} = $encconfig{'ltitools'}{$id}{'secret'};
246: }
1.297 raeburn 247: }
248: }
249: }
250: }
1.320 raeburn 251: if (ref($domconfig{'lti'}) eq 'HASH') {
252: if (ref($encconfig{'lti'}) eq 'HASH') {
1.424 raeburn 253: unless ($checked_is_home) {
254: my $home = &Apache::lonnet::domain($dom,'primary');
255: unless (($home eq 'no_host') || ($home eq '')) {
256: my @ids=&Apache::lonnet::current_machine_ids();
257: if (grep(/^\Q$home\E$/,@ids)) {
258: $is_home = 1;
259: }
260: }
261: $checked_is_home = 1;
262: }
1.320 raeburn 263: foreach my $id (keys(%{$domconfig{'lti'}})) {
264: if ((ref($domconfig{'lti'}{$id}) eq 'HASH') &&
265: (ref($encconfig{'lti'}{$id}) eq 'HASH')) {
1.424 raeburn 266: $domconfig{'lti'}{$id}{'key'} = $encconfig{'lti'}{$id}{'key'};
267: if (($is_home) && ($phase eq 'process')) {
268: $domconfig{'lti'}{$id}{'secret'} = $encconfig{'lti'}{$id}{'secret'};
1.320 raeburn 269: }
270: }
271: }
272: }
273: }
1.405 raeburn 274: if (ref($domconfig{'ltisec'}) eq 'HASH') {
1.406 raeburn 275: if (ref($domconfig{'ltisec'}{'linkprot'}) eq 'HASH') {
1.405 raeburn 276: if (ref($encconfig{'linkprot'}) eq 'HASH') {
1.406 raeburn 277: foreach my $id (keys(%{$domconfig{'ltisec'}{'linkprot'}})) {
278: unless ($id =~ /^\d+$/) {
279: delete($domconfig{'ltisec'}{'linkprot'}{$id});
280: }
281: if ((ref($domconfig{'ltisec'}{'linkprot'}{$id}) eq 'HASH') &&
1.405 raeburn 282: (ref($encconfig{'linkprot'}{$id}) eq 'HASH')) {
283: foreach my $item ('key','secret') {
1.406 raeburn 284: $domconfig{'ltisec'}{'linkprot'}{$id}{$item} = $encconfig{'linkprot'}{$id}{$item};
1.405 raeburn 285: }
286: }
287: }
288: }
289: }
290: }
1.372 raeburn 291: if (ref($domconfig{'proctoring'}) eq 'HASH') {
292: if (ref($encconfig{'proctoring'}) eq 'HASH') {
293: foreach my $provider (keys(%{$domconfig{'proctoring'}})) {
294: if ((ref($domconfig{'proctoring'}{$provider}) eq 'HASH') &&
295: (ref($encconfig{'proctoring'}{$provider}) eq 'HASH')) {
296: foreach my $item ('key','secret') {
297: $domconfig{'proctoring'}{$provider}{$item} = $encconfig{'proctoring'}{$provider}{$item};
298: }
299: }
300: }
301: }
302: }
1.394 raeburn 303: my @prefs_order = ('rolecolors','login','ipaccess','defaults','wafproxy','passwords',
304: 'quotas','autoenroll','autoupdate','autocreate','directorysrch',
1.373 raeburn 305: 'contacts','privacy','usercreation','selfcreation',
1.374 raeburn 306: 'usermodification','scantron','requestcourses','requestauthor',
1.373 raeburn 307: 'coursecategories','serverstatuses','helpsettings','coursedefaults',
1.429 raeburn 308: 'authordefaults','ltitools','proctoring','selfenrollment',
309: 'usersessions','ssl','trust','lti');
1.171 raeburn 310: my %existing;
311: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
312: %existing = %{$domconfig{'loadbalancing'}};
313: }
314: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 315: push(@prefs_order,'loadbalancing');
316: }
1.30 raeburn 317: my %prefs = (
318: 'rolecolors' =>
319: { text => 'Default color schemes',
1.67 raeburn 320: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 321: header => [{col1 => 'Student Settings',
322: col2 => '',},
323: {col1 => 'Coordinator Settings',
324: col2 => '',},
325: {col1 => 'Author Settings',
326: col2 => '',},
327: {col1 => 'Administrator Settings',
328: col2 => '',}],
1.230 raeburn 329: print => \&print_rolecolors,
330: modify => \&modify_rolecolors,
1.30 raeburn 331: },
1.110 raeburn 332: 'login' =>
1.30 raeburn 333: { text => 'Log-in page options',
1.67 raeburn 334: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 335: header => [{col1 => 'Log-in Page Items',
336: col2 => '',},
337: {col1 => 'Log-in Help',
1.256 raeburn 338: col2 => 'Value'},
339: {col1 => 'Custom HTML in document head',
1.386 raeburn 340: col2 => 'Value'},
341: {col1 => 'SSO',
342: col2 => 'Dual login: SSO and non-SSO options'},
343: ],
1.230 raeburn 344: print => \&print_login,
345: modify => \&modify_login,
1.30 raeburn 346: },
1.43 raeburn 347: 'defaults' =>
1.236 raeburn 348: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 349: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 350: header => [{col1 => 'Setting',
1.236 raeburn 351: col2 => 'Value'},
352: {col1 => 'Institutional user types',
1.409 raeburn 353: col2 => 'Name displayed'},
354: {col1 => 'Mapping for missing usernames via standard log-in',
355: col2 => 'Rules in use'}],
1.230 raeburn 356: print => \&print_defaults,
357: modify => \&modify_defaults,
1.43 raeburn 358: },
1.381 raeburn 359: 'wafproxy' =>
360: { text => 'Web Application Firewall/Reverse Proxy',
1.373 raeburn 361: help => 'Domain_Configuration_WAF_Proxy',
1.381 raeburn 362: header => [{col1 => 'Domain(s)',
363: col2 => 'Servers and WAF/Reverse Proxy alias(es)',
1.373 raeburn 364: },
1.381 raeburn 365: {col1 => 'Domain(s)',
366: col2 => 'WAF Configuration',}],
1.373 raeburn 367: print => \&print_wafproxy,
1.381 raeburn 368: modify => \&modify_wafproxy,
1.373 raeburn 369: },
1.354 raeburn 370: 'passwords' =>
371: { text => 'Passwords (Internal authentication)',
372: help => 'Domain_Configuration_Passwords',
373: header => [{col1 => 'Resetting Forgotten Password',
374: col2 => 'Settings'},
375: {col1 => 'Encryption of Stored Passwords (Internal Auth)',
376: col2 => 'Settings'},
377: {col1 => 'Rules for LON-CAPA Passwords',
378: col2 => 'Settings'},
379: {col1 => 'Course Owner Changing Student Passwords',
380: col2 => 'Settings'}],
381: print => \&print_passwords,
382: modify => \&modify_passwords,
383: },
1.30 raeburn 384: 'quotas' =>
1.429 raeburn 385: { text => 'Blogs, personal pages/timezones, portfolio/quotas',
1.67 raeburn 386: help => 'Domain_Configuration_Quotas',
1.77 raeburn 387: header => [{col1 => 'User affiliation',
1.72 raeburn 388: col2 => 'Available tools',
1.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.428 raeburn 6825: coursequota => 'Default cumulative quota for all group portfolio spaces in course',
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.192 raeburn 6838: );
1.198 raeburn 6839: my %staticdefaults = (
6840: anonsurvey_threshold => 10,
6841: uploadquota => 500,
1.428 raeburn 6842: coursequota => 20,
1.257 raeburn 6843: postsubmit => 60,
1.276 raeburn 6844: mysqltables => 172800,
1.422 raeburn 6845: domexttool => 1,
6846: exttool => 0,
1.198 raeburn 6847: );
1.139 raeburn 6848: if ($position eq 'top') {
1.257 raeburn 6849: %defaultchecked = (
6850: 'canuse_pdfforms' => 'off',
6851: 'uselcmath' => 'on',
6852: 'usejsme' => 'on',
1.398 raeburn 6853: 'inline_chem' => 'on',
1.289 raeburn 6854: 'canclone' => 'none',
1.257 raeburn 6855: );
1.398 raeburn 6856: @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem');
1.349 raeburn 6857: my $deftex = $Apache::lonnet::deftex;
1.314 raeburn 6858: if (ref($settings) eq 'HASH') {
6859: if ($settings->{'texengine'}) {
6860: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
6861: $deftex = $settings->{'texengine'};
6862: }
6863: }
6864: }
6865: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6866: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
6867: '<span class="LC_nobreak">'.$choices{'texengine'}.
6868: '</span></td><td class="LC_right_item">'.
6869: '<select name="texengine">'."\n";
6870: my %texoptions = (
6871: MathJax => 'MathJax',
6872: mimetex => &mt('Convert to Images'),
6873: tth => &mt('TeX to HTML'),
6874: );
6875: foreach my $renderer ('MathJax','mimetex','tth') {
6876: my $selected = '';
6877: if ($renderer eq $deftex) {
6878: $selected = ' selected="selected"';
6879: }
6880: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
6881: }
6882: $mathdisp .= '</select></td></tr>'."\n";
6883: $itemcount ++;
1.139 raeburn 6884: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 6885: \%choices,$itemcount);
1.314 raeburn 6886: $datatable = $mathdisp.$datatable;
1.264 raeburn 6887: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6888: $datatable .=
1.306 raeburn 6889: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 6890: '<span class="LC_nobreak">'.$choices{'canclone'}.
6891: '</span></td><td class="LC_left_item">';
6892: my $currcanclone = 'none';
6893: my $onclick;
6894: my @cloneoptions = ('none','domain');
1.380 raeburn 6895: my %clonetitles = &Apache::lonlocal::texthash (
1.264 raeburn 6896: none => 'No additional course requesters',
6897: domain => "Any course requester in course's domain",
6898: instcode => 'Course requests for official courses ...',
6899: );
6900: my (%codedefaults,@code_order,@posscodes);
6901: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
6902: \@code_order) eq 'ok') {
6903: if (@code_order > 0) {
6904: push(@cloneoptions,'instcode');
6905: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
6906: }
6907: }
6908: if (ref($settings) eq 'HASH') {
6909: if ($settings->{'canclone'}) {
6910: if (ref($settings->{'canclone'}) eq 'HASH') {
6911: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
6912: if (@code_order > 0) {
6913: $currcanclone = 'instcode';
6914: @posscodes = @{$settings->{'canclone'}{'instcode'}};
6915: }
6916: }
6917: } elsif ($settings->{'canclone'} eq 'domain') {
6918: $currcanclone = $settings->{'canclone'};
6919: }
6920: }
1.289 raeburn 6921: }
1.264 raeburn 6922: foreach my $option (@cloneoptions) {
6923: my ($checked,$additional);
6924: if ($currcanclone eq $option) {
6925: $checked = ' checked="checked"';
6926: }
6927: if ($option eq 'instcode') {
6928: if (@code_order) {
6929: my $show = 'none';
6930: if ($checked) {
6931: $show = 'block';
6932: }
1.317 raeburn 6933: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 6934: &mt('Institutional codes for new and cloned course have identical:').
6935: '<br />';
6936: foreach my $item (@code_order) {
6937: my $codechk;
6938: if ($checked) {
6939: if (grep(/^\Q$item\E$/,@posscodes)) {
6940: $codechk = ' checked="checked"';
6941: }
6942: }
6943: $additional .= '<label>'.
6944: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
6945: $item.'</label>';
6946: }
6947: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
6948: }
6949: }
6950: $datatable .=
6951: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
6952: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
6953: '</label> '.$additional.'</span><br />';
6954: }
6955: $datatable .= '</td>'.
6956: '</tr>';
6957: $itemcount ++;
1.139 raeburn 6958: } else {
6959: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.428 raeburn 6960: my ($currdefresponder,%defcredits,%curruploadquota,%currcoursequota,
6961: %deftimeout,%currmysql);
1.192 raeburn 6962: my $currusecredits = 0;
1.257 raeburn 6963: my $postsubmitclient = 1;
1.405 raeburn 6964: my $ltiauth = 0;
1.422 raeburn 6965: my %domexttool;
6966: my %exttool;
1.271 raeburn 6967: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 6968: if (ref($settings) eq 'HASH') {
1.404 raeburn 6969: if ($settings->{'ltiauth'}) {
6970: $ltiauth = 1;
1.405 raeburn 6971: }
1.422 raeburn 6972: if (ref($settings->{'domexttool'}) eq 'HASH') {
6973: foreach my $type (@types) {
6974: if ($settings->{'domexttool'}->{$type}) {
6975: $domexttool{$type} = ' checked="checked"';
6976: }
6977: }
6978: } else {
6979: foreach my $type (@types) {
6980: if ($staticdefaults{'domexttool'}) {
6981: $domexttool{$type} = ' checked="checked"';
6982: }
6983: }
6984: }
6985: if (ref($settings->{'exttool'}) eq 'HASH') {
6986: foreach my $type (@types) {
6987: if ($settings->{'exttool'}->{$type}) {
6988: $exttool{$type} = ' checked="checked"';
6989: }
6990: }
6991: }
1.139 raeburn 6992: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 6993: if (ref($settings->{'uploadquota'}) eq 'HASH') {
6994: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
6995: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
6996: }
6997: }
1.428 raeburn 6998: if (ref($settings->{'coursequota'}) eq 'HASH') {
6999: foreach my $type (keys(%{$settings->{'coursequota'}})) {
7000: $currcoursequota{$type} = $settings->{'coursequota'}{$type};
7001: }
7002: }
1.192 raeburn 7003: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 7004: foreach my $type (@types) {
7005: next if ($type eq 'community');
7006: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
7007: if ($defcredits{$type} ne '') {
7008: $currusecredits = 1;
7009: }
7010: }
7011: }
7012: if (ref($settings->{'postsubmit'}) eq 'HASH') {
7013: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
7014: $postsubmitclient = 0;
7015: foreach my $type (@types) {
7016: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7017: }
7018: } else {
7019: foreach my $type (@types) {
7020: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
7021: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 7022: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 7023: } else {
7024: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7025: }
7026: } else {
7027: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7028: }
7029: }
7030: }
7031: } else {
7032: foreach my $type (@types) {
7033: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 7034: }
7035: }
1.276 raeburn 7036: if (ref($settings->{'mysqltables'}) eq 'HASH') {
7037: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
7038: $currmysql{$type} = $settings->{'mysqltables'}{$type};
7039: }
7040: } else {
7041: foreach my $type (@types) {
7042: $currmysql{$type} = $staticdefaults{'mysqltables'};
7043: }
7044: }
1.258 raeburn 7045: } else {
7046: foreach my $type (@types) {
7047: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.422 raeburn 7048: if ($staticdefaults{'domexttool'}) {
7049: $domexttool{$type} = ' checked="checked"';
7050: }
1.258 raeburn 7051: }
1.139 raeburn 7052: }
7053: if (!$currdefresponder) {
1.198 raeburn 7054: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 7055: } elsif ($currdefresponder < 1) {
7056: $currdefresponder = 1;
7057: }
1.198 raeburn 7058: foreach my $type (@types) {
7059: if ($curruploadquota{$type} eq '') {
7060: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
7061: }
1.428 raeburn 7062: if ($currcoursequota{$type} eq '') {
7063: $currcoursequota{$type} = $staticdefaults{'coursequota'};
7064: }
1.198 raeburn 7065: }
1.139 raeburn 7066: $datatable .=
1.192 raeburn 7067: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7068: $choices{'anonsurvey_threshold'}.
1.139 raeburn 7069: '</span></td>'.
7070: '<td class="LC_right_item"><span class="LC_nobreak">'.
7071: '<input type="text" name="anonsurvey_threshold"'.
7072: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 7073: '</td></tr>'."\n";
7074: $itemcount ++;
7075: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7076: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7077: $choices{'uploadquota'}.
7078: '</span></td>'.
1.306 raeburn 7079: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 7080: '<table><tr>';
1.198 raeburn 7081: foreach my $type (@types) {
1.306 raeburn 7082: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 7083: '<input type="text" name="uploadquota_'.$type.'"'.
7084: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
7085: }
7086: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 7087: $itemcount ++;
1.428 raeburn 7088: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7089: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7090: $choices{'coursequota'}.
7091: '</span></td>'.
7092: '<td style="text-align: right" class="LC_right_item">'.
7093: '<table><tr>';
7094: foreach my $type (@types) {
7095: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
7096: '<input type="text" name="coursequota_'.$type.'"'.
7097: ' value="'.$currcoursequota{$type}.'" size="5" /></td>';
7098: }
7099: $datatable .= '</tr></table></td></tr>'."\n";
7100: $itemcount ++;
1.236 raeburn 7101: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 7102: my $display = 'none';
1.192 raeburn 7103: if ($currusecredits) {
7104: $display = 'block';
7105: }
7106: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 7107: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
7108: foreach my $type (@types) {
7109: next if ($type eq 'community');
1.306 raeburn 7110: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7111: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 7112: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 7113: }
7114: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 7115: %defaultchecked = ('coursecredits' => 'off');
7116: @toggles = ('coursecredits');
7117: my $current = {
7118: 'coursecredits' => $currusecredits,
7119: };
7120: (my $table,$itemcount) =
7121: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 7122: \%choices,$itemcount,$onclick,$additional,'left');
7123: $datatable .= $table;
7124: $onclick = "toggleDisplay(this.form,'studentsubmission');";
7125: my $display = 'none';
7126: if ($postsubmitclient) {
7127: $display = 'block';
7128: }
7129: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 7130: &mt('Number of seconds submit is disabled').'<br />'.
7131: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
7132: '<table><tr>';
1.257 raeburn 7133: foreach my $type (@types) {
1.306 raeburn 7134: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7135: '<input type="text" name="'.$type.'_timeout" value="'.
7136: $deftimeout{$type}.'" size="5" /></td>';
7137: }
7138: $additional .= '</tr></table></div>'."\n";
7139: %defaultchecked = ('postsubmit' => 'on');
7140: @toggles = ('postsubmit');
1.280 raeburn 7141: $current = {
7142: 'postsubmit' => $postsubmitclient,
7143: };
1.257 raeburn 7144: ($table,$itemcount) =
7145: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7146: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 7147: $datatable .= $table;
1.276 raeburn 7148: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7149: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7150: $choices{'mysqltables'}.
7151: '</span></td>'.
1.306 raeburn 7152: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 7153: '<table><tr>';
7154: foreach my $type (@types) {
1.306 raeburn 7155: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 7156: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 7157: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 7158: }
7159: $datatable .= '</tr></table></td></tr>'."\n";
7160: $itemcount ++;
1.404 raeburn 7161: %defaultchecked = ('ltiauth' => 'off');
7162: @toggles = ('ltiauth');
7163: $current = {
7164: 'ltiauth' => $ltiauth,
7165: };
7166: ($table,$itemcount) =
7167: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7168: \%choices,$itemcount,undef,undef,'left');
7169: $datatable .= $table;
1.422 raeburn 7170: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7171: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7172: $choices{'domexttool'}.
7173: '</span></td>'.
7174: '<td style="text-align: right" class="LC_right_item">'.
7175: '<table><tr>';
7176: foreach my $type (@types) {
7177: $datatable .= '<td style="text-align: left">'.
7178: '<span class="LC_nobreak">'.
7179: '<input type="checkbox" name="domexttool"'.
7180: ' value="'.$type.'"'.$domexttool{$type}.' />'.
7181: &mt($type).'</span></td>'."\n";
7182: }
7183: $datatable .= '</tr></table></td></tr>'."\n";
1.404 raeburn 7184: $itemcount ++;
1.422 raeburn 7185: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7186: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7187: $choices{'exttool'}.
7188: '</span></td>'.
7189: '<td style="text-align: right" class="LC_right_item">'.
7190: '<table><tr>';
7191: foreach my $type (@types) {
7192: $datatable .= '<td style="text-align: left">'.
7193: '<span class="LC_nobreak">'.
7194: '<input type="checkbox" name="exttool"'.
7195: ' value="'.$type.'"'.$exttool{$type}.' />'.
7196: &mt($type).'</span></td>'."\n";
7197: }
7198: $datatable .= '</tr></table></td></tr>'."\n";
1.139 raeburn 7199: }
1.192 raeburn 7200: $$rowtotal += $itemcount;
1.121 raeburn 7201: return $datatable;
1.118 jms 7202: }
7203:
1.429 raeburn 7204: sub print_authordefaults {
7205: my ($position,$dom,$settings,$rowtotal) = @_;
7206: my ($css_class,$datatable,%checkedon,%checkedoff);
7207: my $itemcount = 1;
7208: my %titles = &authordefaults_titles();
7209: if ($position eq 'top') {
7210: my %defaultchecked = (
7211: 'nocodemirror' => 'off',
7212: 'domcoordacc' => 'on',
7213: );
7214: my @toggles = ('nocodemirror','domcoordacc');
7215: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
7216: \%titles,$itemcount);
7217: my %staticdefaults = (
7218: 'copyright' => 'default',
7219: 'sourceavail' => 'closed',
7220: );
7221: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7222: my %currrights;
7223: foreach my $item ('copyright','sourceavail') {
7224: $currrights{$item} = $staticdefaults{$item};
7225: if (ref($settings) eq 'HASH') {
7226: if (exists($settings->{$item})) {
7227: $currrights{$item} = $settings->{$item};
7228: }
7229: }
7230: }
7231: $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
7232: '<span class="LC_nobreak">'.$titles{'copyright'}.
7233: '</span></td><td class="LC_right_item">'.
7234: &selectbox('copyright',$currrights{'copyright'},'',
7235: \&Apache::loncommon::copyrightdescription,
7236: (grep !/^priv|custom$/,(&Apache::loncommon::copyrightids))).
7237: '</td></tr>'."\n";
7238: $itemcount ++;
7239: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7240: $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
7241: '<span class="LC_nobreak">'.$titles{'sourceavail'}.
7242: '</span></td><td class="LC_right_item">'.
7243: &selectbox('sourceavail',$currrights{'sourceavail'},'',
7244: \&Apache::loncommon::source_copyrightdescription,
7245: (&Apache::loncommon::source_copyrightids)).
7246: '</td></tr>'."\n";
7247: } else {
7248: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7249: my $curreditors;
7250: my %staticdefaults = (
7251: editors => ['edit','xml'],
7252: authorquota => 500,
7253: webdav => 0,
7254: );
7255: my $curreditors = $staticdefaults{'editors'};
7256: if ((ref($settings) eq 'HASH') &&
7257: (ref($settings->{'editors'}) eq 'ARRAY')) {
7258: $curreditors = $settings->{'editors'};
7259: } else {
7260: $curreditors = $staticdefaults{'editors'};
7261: }
7262: my @editors = ('edit','xml','daxe');
7263: $datatable = '<tr'.$css_class.'>'."\n".
7264: '<td>'.$titles{'editors'}.'</td>'."\n".
7265: '<td class="LC_left_item">'."\n".
7266: '<span class="LC_nobreak">';
7267: foreach my $editor (@editors) {
7268: my $checked;
7269: if (grep(/^\Q$editor\E$/,@{$curreditors})) {
7270: $checked = ' checked="checked"';
7271: }
7272: $datatable .= '<label>'.
7273: '<input type="checkbox" name="author_editors" '.
7274: $checked.' value="'.$editor.'" '.
7275: 'onclick="javascript:checkEditors(this.form,'."'author_editors'".',this);" />'.
7276: $titles{$editor}.'</label> ';
7277: }
7278: $datatable .= '</span>'."\n".'</td>'."\n".'</tr>'."\n";
7279: $itemcount ++;
7280: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7281: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7282: my @insttypes;
7283: if (ref($types) eq 'ARRAY') {
7284: @insttypes = @{$types};
7285: }
7286: my $typecount = 0;
7287: my %domconf = &Apache::lonnet::get_dom('configuration',['quotas'],$dom);
7288: my @items = ('webdav','authorquota');
7289: my %quotas;
7290: if (ref($domconf{'quotas'}) eq 'HASH') {
7291: %quotas = %{$domconf{'quotas'}};
7292: foreach my $item (@items) {
7293: if (ref($quotas{$item}) eq 'HASH') {
7294: foreach my $type (@insttypes,'default') {
7295: if ($item eq 'authorquota') {
7296: if ($quotas{$item}{$type} !~ /^\d+$/) {
7297: $quotas{$item}{$type} = $staticdefaults{$item};
7298: }
7299: } elsif ($item eq 'webdav') {
7300: if ($quotas{$item}{$type} !~ /^(0|1)$/) {
7301: $quotas{$item}{$type} = $staticdefaults{$item};
7302: }
7303: }
7304: }
7305: } else {
7306: foreach my $type (@insttypes,'default') {
7307: $quotas{$item}{$type} = $staticdefaults{$item};
7308: }
7309: }
7310: }
7311: } else {
7312: foreach my $item (@items) {
7313: foreach my $type (@insttypes,'default') {
7314: $quotas{$item}{$type} = $staticdefaults{$item};
7315: }
7316: }
7317: }
7318: if (ref($usertypes) eq 'HASH') {
7319: my $numinrow = 4;
7320: my $onclick = '';
7321: $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
7322: $numinrow,$othertitle,'authorquota',
7323: \$itemcount,$onclick);
7324: $itemcount ++;
7325: $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
7326: $numinrow,$othertitle,'webdav',
7327: \$itemcount);
7328: $itemcount ++;
7329: }
7330: my $checkedno = ' checked="checked"';
7331: my ($checkedon,$checkedoff);
7332: if (ref($quotas{'webdav'}) eq 'HASH') {
7333: if ($quotas{'webdav'}{'_LC_adv'} =~ /^0|1$/) {
7334: if ($quotas{'webdav'}{'_LC_adv'}) {
7335: $checkedon = $checkedno;
7336: } else {
7337: $checkedoff = $checkedno;
7338: }
7339: undef($checkedno);
7340: }
7341: }
7342: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7343: $datatable .= '<tr'.$css_class.'>'.
7344: '<td>'.$titles{'webdav_LC_adv'}.'<br />'.
7345: $titles{'webdav_LC_adv_over'}.
7346: '</td>'.
7347: '<td class="LC_left_item">';
7348: foreach my $option ('none','off','on') {
7349: my ($text,$val,$checked);
7350: if ($option eq 'none') {
7351: $text = $titles{'none'};
7352: $val = '';
7353: $checked = $checkedno;
7354: } elsif ($option eq 'off') {
7355: $text = $titles{'overoff'};
7356: $val = 0;
7357: $checked = $checkedoff;
7358: } elsif ($option eq 'on') {
7359: $text = $titles{'overon'};
7360: $val = 1;
7361: $checked = $checkedon;
7362: }
7363: $datatable .= '<span class="LC_nobreak"><label>'.
7364: '<input type="radio" name="webdav_LC_adv"'.
7365: ' value="'.$val.'"'.$checked.' />'.
7366: $text.'</label></span> ';
7367: }
7368: $datatable .= '</td></tr>';
7369: $itemcount ++;
7370: }
7371: $$rowtotal += $itemcount;
7372: return $datatable;
7373: }
7374:
7375: sub authordefaults_titles {
7376: return &Apache::lonlocal::texthash(
7377: copyright => 'Copyright/Distribution',
7378: sourceavail => ' Source Available',
7379: editors => 'Available Editors',
7380: webdav => 'WebDAV',
7381: authorquota => 'Authoring Space quotas (MB)',
7382: nocodemirror => 'Deactivate CodeMirror for EditXML editor',
7383: domcoordacc => 'Dom. Coords. can enter Authoring Spaces in domain',
7384: edit => 'Standard editor (Edit)',
7385: xml => 'Text editor (EditXML)',
7386: daxe => 'Daxe editor (Daxe)',
7387: webdav_LC_adv => 'WebDAV access for LON-CAPA "advanced" users',
7388: webdav_LC_adv_over => '(overrides access based on affiliation, if set)',
7389: none => 'No override set',
7390: overon => 'Override -- webDAV on',
7391: overoff => 'Override -- webDAV off',
7392: );
7393: }
7394:
7395: sub selectbox {
7396: my ($name,$value,$readonly,$functionref,@idlist)=@_;
7397: my $selout = '<select name="'.$name.'">';
7398: foreach my $id (@idlist) {
7399: $selout.='<option value="'.$id.'"';
7400: if ($id eq $value) {
7401: $selout.=' selected="selected"';
7402: }
7403: if ($readonly) {
7404: $selout .= ' disabled="disabled"';
7405: }
7406: $selout.='>'.&{$functionref}($id).'</option>';
7407: }
7408: $selout.='</select>';
7409: return $selout;
7410: }
7411:
1.231 raeburn 7412: sub print_selfenrollment {
7413: my ($position,$dom,$settings,$rowtotal) = @_;
7414: my ($css_class,$datatable);
7415: my $itemcount = 1;
1.271 raeburn 7416: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 7417: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 7418: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
7419: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 7420: my @rows;
7421: my $key;
7422: if ($position eq 'top') {
7423: $key = 'admin';
7424: if (ref($rowsref) eq 'ARRAY') {
7425: @rows = @{$rowsref};
7426: }
7427: } elsif ($position eq 'middle') {
7428: $key = 'default';
7429: @rows = ('types','registered','approval','limit');
7430: }
7431: foreach my $row (@rows) {
7432: if (defined($titlesref->{$row})) {
7433: $itemcount ++;
7434: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7435: $datatable .= '<tr'.$css_class.'>'.
7436: '<td>'.$titlesref->{$row}.'</td>'.
7437: '<td class="LC_left_item">'.
7438: '<table><tr>';
7439: my (%current,%currentcap);
7440: if (ref($settings) eq 'HASH') {
7441: if (ref($settings->{$key}) eq 'HASH') {
7442: foreach my $type (@types) {
7443: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7444: $current{$type} = $settings->{$key}->{$type}->{$row};
7445: }
7446: if (($row eq 'limit') && ($key eq 'default')) {
7447: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7448: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
7449: }
7450: }
7451: }
7452: }
7453: }
7454: my %roles = (
7455: '0' => &Apache::lonnet::plaintext('dc'),
7456: );
7457:
7458: foreach my $type (@types) {
7459: unless (($row eq 'registered') && ($key eq 'default')) {
7460: $datatable .= '<th>'.&mt($type).'</th>';
7461: }
7462: }
7463: unless (($row eq 'registered') && ($key eq 'default')) {
7464: $datatable .= '</tr><tr>';
7465: }
7466: foreach my $type (@types) {
7467: if ($type eq 'community') {
7468: $roles{'1'} = &mt('Community personnel');
7469: } else {
7470: $roles{'1'} = &mt('Course personnel');
7471: }
7472: $datatable .= '<td style="vertical-align: top">';
7473: if ($position eq 'top') {
7474: my %checked;
7475: if ($current{$type} eq '0') {
7476: $checked{'0'} = ' checked="checked"';
7477: } else {
7478: $checked{'1'} = ' checked="checked"';
7479: }
7480: foreach my $role ('1','0') {
7481: $datatable .= '<span class="LC_nobreak"><label>'.
7482: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
7483: 'value="'.$role.'"'.$checked{$role}.' />'.
7484: $roles{$role}.'</label></span> ';
7485: }
7486: } else {
7487: if ($row eq 'types') {
7488: my %checked;
7489: if ($current{$type} =~ /^(all|dom)$/) {
7490: $checked{$1} = ' checked="checked"';
7491: } else {
7492: $checked{''} = ' checked="checked"';
7493: }
7494: foreach my $val ('','dom','all') {
7495: $datatable .= '<span class="LC_nobreak"><label>'.
7496: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7497: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7498: }
7499: } elsif ($row eq 'registered') {
7500: my %checked;
7501: if ($current{$type} eq '1') {
7502: $checked{'1'} = ' checked="checked"';
7503: } else {
7504: $checked{'0'} = ' checked="checked"';
7505: }
7506: foreach my $val ('0','1') {
7507: $datatable .= '<span class="LC_nobreak"><label>'.
7508: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7509: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7510: }
7511: } elsif ($row eq 'approval') {
7512: my %checked;
7513: if ($current{$type} =~ /^([12])$/) {
7514: $checked{$1} = ' checked="checked"';
7515: } else {
7516: $checked{'0'} = ' checked="checked"';
7517: }
7518: for my $val (0..2) {
7519: $datatable .= '<span class="LC_nobreak"><label>'.
7520: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7521: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7522: }
7523: } elsif ($row eq 'limit') {
7524: my %checked;
7525: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
7526: $checked{$1} = ' checked="checked"';
7527: } else {
7528: $checked{'none'} = ' checked="checked"';
7529: }
7530: my $cap;
7531: if ($currentcap{$type} =~ /^\d+$/) {
7532: $cap = $currentcap{$type};
7533: }
7534: foreach my $val ('none','allstudents','selfenrolled') {
7535: $datatable .= '<span class="LC_nobreak"><label>'.
7536: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7537: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7538: }
7539: $datatable .= '<br />'.
7540: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
7541: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
7542: '</span>';
7543: }
7544: }
7545: $datatable .= '</td>';
7546: }
7547: $datatable .= '</tr>';
7548: }
7549: $datatable .= '</table></td></tr>';
7550: }
7551: } elsif ($position eq 'bottom') {
1.235 raeburn 7552: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
7553: }
7554: $$rowtotal += $itemcount;
7555: return $datatable;
7556: }
7557:
7558: sub print_validation_rows {
7559: my ($caller,$dom,$settings,$rowtotal) = @_;
7560: my ($itemsref,$namesref,$fieldsref);
7561: if ($caller eq 'selfenroll') {
7562: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
7563: } elsif ($caller eq 'requestcourses') {
7564: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
7565: }
7566: my %currvalidation;
7567: if (ref($settings) eq 'HASH') {
7568: if (ref($settings->{'validation'}) eq 'HASH') {
7569: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 7570: }
1.235 raeburn 7571: }
7572: my $datatable;
7573: my $itemcount = 0;
7574: foreach my $item (@{$itemsref}) {
7575: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7576: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7577: $namesref->{$item}.
7578: '</span></td>'.
7579: '<td class="LC_left_item">';
7580: if (($item eq 'url') || ($item eq 'button')) {
7581: $datatable .= '<span class="LC_nobreak">'.
7582: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
7583: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
7584: } elsif ($item eq 'fields') {
7585: my @currfields;
7586: if (ref($currvalidation{$item}) eq 'ARRAY') {
7587: @currfields = @{$currvalidation{$item}};
7588: }
7589: foreach my $field (@{$fieldsref}) {
7590: my $check = '';
7591: if (grep(/^\Q$field\E$/,@currfields)) {
7592: $check = ' checked="checked"';
7593: }
7594: $datatable .= '<span class="LC_nobreak"><label>'.
7595: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
7596: ' value="'.$field.'"'.$check.' />'.$field.
7597: '</label></span> ';
7598: }
7599: } elsif ($item eq 'markup') {
1.334 raeburn 7600: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 7601: $currvalidation{$item}.
1.231 raeburn 7602: '</textarea>';
1.235 raeburn 7603: }
7604: $datatable .= '</td></tr>'."\n";
7605: if (ref($rowtotal)) {
1.231 raeburn 7606: $itemcount ++;
7607: }
7608: }
1.235 raeburn 7609: if ($caller eq 'requestcourses') {
7610: my %currhash;
1.248 raeburn 7611: if (ref($settings) eq 'HASH') {
7612: if (ref($settings->{'validation'}) eq 'HASH') {
7613: if ($settings->{'validation'}{'dc'} ne '') {
7614: $currhash{$settings->{'validation'}{'dc'}} = 1;
7615: }
1.235 raeburn 7616: }
7617: }
7618: my $numinrow = 2;
7619: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
7620: 'validationdc',%currhash);
1.247 raeburn 7621: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 7622: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 7623: if ($numdc > 1) {
1.247 raeburn 7624: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 7625: } else {
1.247 raeburn 7626: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 7627: }
1.247 raeburn 7628: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 7629: $itemcount ++;
7630: }
7631: if (ref($rowtotal)) {
7632: $$rowtotal += $itemcount;
7633: }
1.231 raeburn 7634: return $datatable;
7635: }
7636:
1.357 raeburn 7637: sub print_privacy {
7638: my ($position,$dom,$settings,$rowtotal) = @_;
7639: my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
7640: my $itemcount = 0;
1.417 raeburn 7641: if ($position eq 'top') {
7642: $numinrow = 2;
7643: } else {
1.357 raeburn 7644: @items = ('domain','author','course','community');
7645: %names = &Apache::lonlocal::texthash (
7646: domain => 'Assigned domain role(s)',
7647: author => 'Assigned co-author role(s)',
7648: course => 'Assigned course role(s)',
1.416 raeburn 7649: community => 'Assigned community role(s)',
1.357 raeburn 7650: );
7651: $numinrow = 4;
7652: ($othertitle,$usertypes,$types) =
7653: &Apache::loncommon::sorted_inst_types($dom);
7654: }
7655: if (($position eq 'top') || ($position eq 'middle')) {
7656: my (%by_ip,%by_location,@intdoms,@instdoms);
7657: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
7658: if ($position eq 'top') {
7659: my %curr;
7660: my @options = ('none','user','domain','auto');
7661: my %titles = &Apache::lonlocal::texthash (
7662: none => 'Not allowed',
7663: user => 'User authorizes',
7664: domain => 'DC authorizes',
7665: auto => 'Unrestricted',
7666: instdom => 'Other domain shares institution/provider',
7667: extdom => 'Other domain has different institution/provider',
1.418 raeburn 7668: notify => 'Notify when role needs authorization',
1.357 raeburn 7669: );
7670: my %names = &Apache::lonlocal::texthash (
7671: domain => 'Domain role',
7672: author => 'Co-author role',
7673: course => 'Course role',
7674: community => 'Community role',
7675: );
7676: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7677: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7678: foreach my $domtype ('instdom','extdom') {
7679: my (%checked,$skip);
7680: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7681: $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
7682: '<td class="LC_left_item">';
7683: if ($domtype eq 'instdom') {
7684: unless (@instdoms > 1) {
7685: $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
7686: $skip = 1;
7687: }
7688: } elsif ($domtype eq 'extdom') {
7689: if (keys(%by_location) == 0) {
7690: $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
7691: $skip = 1;
7692: }
7693: }
7694: unless ($skip) {
7695: foreach my $roletype ('domain','author','course','community') {
7696: $checked{'auto'} = ' checked="checked"';
7697: if (ref($settings) eq 'HASH') {
7698: if (ref($settings->{approval}) eq 'HASH') {
7699: if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
7700: if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
7701: $checked{$1} = ' checked="checked"';
7702: $checked{'auto'} = '';
7703: }
7704: }
7705: }
7706: }
7707: $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
7708: foreach my $option (@options) {
7709: $datatable .= '<span class="LC_nobreak"><label>'.
7710: '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
7711: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
7712: '</label></span> ';
7713: }
7714: $datatable .= '</fieldset>';
7715: }
7716: }
7717: $datatable .= '</td></tr>';
7718: $itemcount ++;
7719: }
1.417 raeburn 7720: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7721: $datatable .= '<tr'.$css_class.'><td>'.$titles{'notify'}.'</td>'.
7722: '<td class="LC_left_item">';
7723: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7724: my %curr;
7725: if (ref($settings) eq 'HASH') {
7726: if ($settings->{'notify'} ne '') {
7727: map {$curr{$_}=1;} split(/,/,$settings->{'notify'});
7728: }
7729: }
7730: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7731: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
7732: 'privacy_notify',%curr);
7733: if ($numdc > 0) {
7734: $datatable .= $table;
7735: } else {
7736: $datatable .= &mt('There are no active Domain Coordinators');
7737: }
7738: } else {
7739: $datatable .= &mt('Nothing to set here, as there are no other domains');
7740: }
7741: $datatable .='</td></tr>';
1.357 raeburn 7742: } elsif ($position eq 'middle') {
7743: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7744: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7745: foreach my $item (@{$types}) {
7746: $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
7747: $numinrow,$itemcount,'','','','','',
7748: '',$usertypes->{$item});
7749: $itemcount ++;
7750: }
7751: }
7752: $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
7753: $numinrow,$itemcount,'','','','','',
7754: '',$othertitle);
7755: $itemcount ++;
7756: } else {
1.360 raeburn 7757: my (@insttypes,%insttitles);
7758: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7759: @insttypes = @{$types};
7760: %insttitles = %{$usertypes};
7761: }
7762: foreach my $item (@insttypes,'default') {
7763: my $title;
7764: if ($item eq 'default') {
7765: $title = $othertitle;
7766: } else {
7767: $title = $insttitles{$item};
7768: }
7769: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7770: $datatable .= '<tr'.$css_class.'>'.
7771: '<td class="LC_left_item">'.$title.'</td>'.
7772: '<td class="LC_left_item">'.
7773: &mt('Nothing to set here, as there are no other domains').
7774: '</td></tr>';
7775: $itemcount ++;
7776: }
1.357 raeburn 7777: }
7778: }
7779: } else {
7780: my $prefix;
7781: if ($position eq 'lower') {
7782: $prefix = 'priv';
7783: } else {
7784: $prefix = 'unpriv';
7785: }
7786: foreach my $item (@items) {
7787: $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
7788: $numinrow,$itemcount,'','','','','',
7789: '',$names{$item});
7790: $itemcount ++;
7791: }
7792: }
7793: if (ref($rowtotal)) {
7794: $$rowtotal += $itemcount;
7795: }
7796: return $datatable;
7797: }
7798:
1.354 raeburn 7799: sub print_passwords {
7800: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
7801: my ($datatable,$css_class);
7802: my $itemcount = 0;
7803: my %titles = &Apache::lonlocal::texthash (
7804: captcha => '"Forgot Password" CAPTCHA validation',
7805: link => 'Reset link expiration (hours)',
7806: case => 'Case-sensitive usernames/e-mail',
7807: prelink => 'Information required (form 1)',
7808: postlink => 'Information required (form 2)',
7809: emailsrc => 'LON-CAPA e-mail address type(s)',
7810: customtext => 'Domain specific text (HTML)',
7811: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
7812: intauth_check => 'Check bcrypt cost if authenticated',
7813: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
7814: permanent => 'Permanent e-mail address',
7815: critical => 'Critical notification address',
7816: notify => 'Notification address',
7817: min => 'Minimum password length',
7818: max => 'Maximum password length',
7819: chars => 'Required characters',
7820: expire => 'Password expiration (days)',
1.356 raeburn 7821: numsaved => 'Number of previous passwords to save and disallow reuse',
1.354 raeburn 7822: );
7823: if ($position eq 'top') {
7824: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7825: my $shownlinklife = 2;
7826: my $prelink = 'both';
7827: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
7828: if (ref($settings) eq 'HASH') {
7829: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
7830: $shownlinklife = $settings->{resetlink};
7831: }
7832: if (ref($settings->{resetcase}) eq 'ARRAY') {
7833: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
7834: }
7835: if ($settings->{resetprelink} =~ /^(both|either)$/) {
7836: $prelink = $settings->{resetprelink};
7837: }
7838: if (ref($settings->{resetpostlink}) eq 'HASH') {
7839: %postlink = %{$settings->{resetpostlink}};
7840: }
7841: if (ref($settings->{resetemail}) eq 'ARRAY') {
7842: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
7843: }
7844: if ($settings->{resetremove}) {
7845: $nostdtext = 1;
7846: }
7847: if ($settings->{resetcustom}) {
7848: $customurl = $settings->{resetcustom};
7849: }
7850: } else {
7851: if (ref($types) eq 'ARRAY') {
7852: foreach my $item (@{$types}) {
7853: $casesens{$item} = 1;
7854: $postlink{$item} = ['username','email'];
7855: }
7856: }
7857: $casesens{'default'} = 1;
7858: $postlink{'default'} = ['username','email'];
7859: $prelink = 'both';
7860: %emailsrc = (
7861: permanent => 1,
7862: critical => 1,
7863: notify => 1,
7864: );
7865: }
7866: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
7867: $itemcount ++;
7868: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7869: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
7870: '<td class="LC_left_item">'.
7871: '<input type="textbox" value="'.$shownlinklife.'" '.
7872: 'name="passwords_link" size="3" /></td></tr>';
7873: $itemcount ++;
7874: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7875: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
7876: '<td class="LC_left_item">';
7877: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7878: foreach my $item (@{$types}) {
7879: my $checkedcase;
7880: if ($casesens{$item}) {
7881: $checkedcase = ' checked="checked"';
7882: }
7883: $datatable .= '<span class="LC_nobreak"><label>'.
7884: '<input type="checkbox" name="passwords_case_sensitive" value="'.
7885: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369 raeburn 7886: '</span> ';
1.354 raeburn 7887: }
7888: }
7889: my $checkedcase;
7890: if ($casesens{'default'}) {
7891: $checkedcase = ' checked="checked"';
7892: }
7893: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
7894: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
7895: $othertitle.'</label></span></td>';
7896: $itemcount ++;
7897: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7898: my %checkedpre = (
7899: both => ' checked="checked"',
7900: either => '',
7901: );
7902: if ($prelink eq 'either') {
7903: $checkedpre{either} = ' checked="checked"';
7904: $checkedpre{both} = '';
7905: }
7906: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
7907: '<td class="LC_left_item"><span class="LC_nobreak">'.
7908: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
7909: &mt('Both username and e-mail address').'</label></span> '.
7910: '<span class="LC_nobreak"><label>'.
7911: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
7912: &mt('Either username or e-mail address').'</label></span></td></tr>';
7913: $itemcount ++;
7914: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7915: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
7916: '<td class="LC_left_item">';
7917: my %postlinked;
7918: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7919: foreach my $item (@{$types}) {
7920: undef(%postlinked);
7921: $datatable .= '<fieldset style="display: inline-block;">'.
7922: '<legend>'.$usertypes->{$item}.'</legend>';
7923: if (ref($postlink{$item}) eq 'ARRAY') {
7924: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
7925: }
7926: foreach my $field ('email','username') {
7927: my $checked;
7928: if ($postlinked{$field}) {
7929: $checked = ' checked="checked"';
7930: }
7931: $datatable .= '<span class="LC_nobreak"><label>'.
7932: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
7933: $field.'"'.$checked.' />'.$field.'</label>'.
7934: '<span> ';
7935: }
7936: $datatable .= '</fieldset>';
7937: }
7938: }
7939: if (ref($postlink{'default'}) eq 'ARRAY') {
7940: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
7941: }
7942: $datatable .= '<fieldset style="display: inline-block;">'.
7943: '<legend>'.$othertitle.'</legend>';
7944: foreach my $field ('email','username') {
7945: my $checked;
7946: if ($postlinked{$field}) {
7947: $checked = ' checked="checked"';
7948: }
7949: $datatable .= '<span class="LC_nobreak"><label>'.
7950: '<input type="checkbox" name="passwords_postlink_default" value="'.
7951: $field.'"'.$checked.' />'.$field.'</label>'.
7952: '<span> ';
7953: }
7954: $datatable .= '</fieldset></td></tr>';
7955: $itemcount ++;
7956: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7957: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
7958: '<td class="LC_left_item">';
7959: foreach my $type ('permanent','critical','notify') {
7960: my $checkedemail;
7961: if ($emailsrc{$type}) {
7962: $checkedemail = ' checked="checked"';
7963: }
7964: $datatable .= '<span class="LC_nobreak"><label>'.
7965: '<input type="checkbox" name="passwords_emailsrc" value="'.
7966: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
7967: '<span> ';
7968: }
7969: $datatable .= '</td></tr>';
7970: $itemcount ++;
7971: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7972: my $switchserver = &check_switchserver($dom,$confname);
7973: my ($showstd,$noshowstd);
7974: if ($nostdtext) {
7975: $noshowstd = ' checked="checked"';
7976: } else {
7977: $showstd = ' checked="checked"';
7978: }
7979: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
7980: '<td class="LC_left_item"><span class="LC_nobreak">'.
7981: &mt('Retain standard text:').
7982: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
7983: &mt('Yes').'</label>'.' '.
7984: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
7985: &mt('No').'</label></span><br />'.
7986: '<span class="LC_fontsize_small">'.
7987: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
7988: &mt('Include custom text:');
7989: if ($customurl) {
1.369 raeburn 7990: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354 raeburn 7991: undef,undef,undef,undef,'background-color:#ffffff');
7992: $datatable .= '<span class="LC_nobreak"> '.$link.
7993: '<label><input type="checkbox" name="passwords_custom_del"'.
7994: ' value="1" />'.&mt('Delete?').'</label></span>'.
7995: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
7996: }
7997: if ($switchserver) {
7998: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
7999: } else {
8000: $datatable .='<span class="LC_nobreak"> '.
8001: '<input type="file" name="passwords_customfile" /></span>';
8002: }
8003: $datatable .= '</td></tr>';
8004: } elsif ($position eq 'middle') {
8005: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
8006: my @items = ('intauth_cost','intauth_check','intauth_switch');
8007: my %defaults;
8008: if (ref($domconf{'defaults'}) eq 'HASH') {
8009: %defaults = %{$domconf{'defaults'}};
8010: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
8011: $defaults{'intauth_cost'} = 10;
8012: }
8013: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
8014: $defaults{'intauth_check'} = 0;
8015: }
8016: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
8017: $defaults{'intauth_switch'} = 0;
8018: }
8019: } else {
8020: %defaults = (
8021: 'intauth_cost' => 10,
8022: 'intauth_check' => 0,
8023: 'intauth_switch' => 0,
8024: );
8025: }
8026: foreach my $item (@items) {
8027: if ($itemcount%2) {
8028: $css_class = '';
8029: } else {
8030: $css_class = ' class="LC_odd_row" ';
8031: }
8032: $datatable .= '<tr'.$css_class.'>'.
8033: '<td><span class="LC_nobreak">'.$titles{$item}.
8034: '</span></td><td class="LC_left_item" colspan="3">';
8035: if ($item eq 'intauth_switch') {
8036: my @options = (0,1,2);
8037: my %optiondesc = &Apache::lonlocal::texthash (
8038: 0 => 'No',
8039: 1 => 'Yes',
8040: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
8041: );
8042: $datatable .= '<table width="100%">';
8043: foreach my $option (@options) {
8044: my $checked = ' ';
8045: if ($defaults{$item} eq $option) {
8046: $checked = ' checked="checked"';
8047: }
8048: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8049: '<label><input type="radio" name="'.$item.
8050: '" value="'.$option.'"'.$checked.' />'.
8051: $optiondesc{$option}.'</label></span></td></tr>';
8052: }
8053: $datatable .= '</table>';
8054: } elsif ($item eq 'intauth_check') {
8055: my @options = (0,1,2);
8056: my %optiondesc = &Apache::lonlocal::texthash (
8057: 0 => 'No',
8058: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
8059: 2 => 'Yes, disallow login if stored cost is less than domain default',
8060: );
8061: $datatable .= '<table width="100%">';
8062: foreach my $option (@options) {
8063: my $checked = ' ';
8064: my $onclick;
8065: if ($defaults{$item} eq $option) {
8066: $checked = ' checked="checked"';
8067: }
8068: if ($option == 2) {
8069: $onclick = ' onclick="javascript:warnIntAuth(this);"';
8070: }
8071: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8072: '<label><input type="radio" name="'.$item.
8073: '" value="'.$option.'"'.$checked.$onclick.' />'.
8074: $optiondesc{$option}.'</label></span></td></tr>';
8075: }
8076: $datatable .= '</table>';
8077: } else {
8078: $datatable .= '<input type="text" name="'.$item.'" value="'.
8079: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
8080: }
8081: $datatable .= '</td></tr>';
8082: $itemcount ++;
8083: }
8084: } elsif ($position eq 'lower') {
1.405 raeburn 8085: $datatable .= &password_rules('passwords',\$itemcount,$settings);
1.354 raeburn 8086: } else {
1.359 raeburn 8087: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8088: my %ownerchg = (
8089: by => {},
8090: for => {},
8091: );
8092: my %ownertitles = &Apache::lonlocal::texthash (
8093: by => 'Course owner status(es) allowed',
8094: for => 'Student status(es) allowed',
8095: );
1.354 raeburn 8096: if (ref($settings) eq 'HASH') {
1.359 raeburn 8097: if (ref($settings->{crsownerchg}) eq 'HASH') {
8098: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
8099: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
8100: }
8101: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
8102: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
8103: }
1.354 raeburn 8104: }
8105: }
8106: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8107: $datatable .= '<tr '.$css_class.'>'.
8108: '<td>'.
8109: &mt('Requirements').'<ul>'.
1.359 raeburn 8110: '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354 raeburn 8111: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
8112: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359 raeburn 8113: '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354 raeburn 8114: '</ul>'.
8115: '</td>'.
1.359 raeburn 8116: '<td class="LC_left_item">';
8117: foreach my $item ('by','for') {
8118: $datatable .= '<fieldset style="display: inline-block;">'.
8119: '<legend>'.$ownertitles{$item}.'</legend>';
8120: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8121: foreach my $type (@{$types}) {
8122: my $checked;
8123: if ($ownerchg{$item}{$type}) {
8124: $checked = ' checked="checked"';
8125: }
8126: $datatable .= '<span class="LC_nobreak"><label>'.
8127: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
8128: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369 raeburn 8129: '</span> ';
1.359 raeburn 8130: }
8131: }
8132: my $checked;
8133: if ($ownerchg{$item}{'default'}) {
8134: $checked = ' checked="checked"';
8135: }
8136: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
8137: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
8138: $othertitle.'</label></span></fieldset>';
8139: }
8140: $datatable .= '</td></tr>';
1.354 raeburn 8141: }
8142: return $datatable;
8143: }
8144:
1.405 raeburn 8145: sub password_rules {
8146: my ($prefix,$itemcountref,$settings) = @_;
8147: my ($min,$max,%chars,$expire,$numsaved,$numinrow);
8148: my %titles;
8149: if ($prefix eq 'passwords') {
8150: %titles = &Apache::lonlocal::texthash (
8151: min => 'Minimum password length',
8152: max => 'Maximum password length',
8153: chars => 'Required characters',
8154: );
1.421 raeburn 8155: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 8156: %titles = &Apache::lonlocal::texthash (
8157: min => 'Minimum secret length',
8158: max => 'Maximum secret length',
8159: chars => 'Required characters',
8160: );
8161: }
8162: $min = $Apache::lonnet::passwdmin;
8163: my $datatable;
8164: my $itemcount;
8165: if (ref($itemcountref)) {
8166: $itemcount = $$itemcountref;
8167: }
8168: if (ref($settings) eq 'HASH') {
8169: if ($settings->{min}) {
8170: $min = $settings->{min};
8171: }
8172: if ($settings->{max}) {
8173: $max = $settings->{max};
8174: }
8175: if (ref($settings->{chars}) eq 'ARRAY') {
8176: map { $chars{$_} = 1; } (@{$settings->{chars}});
8177: }
1.425 raeburn 8178: if ($prefix eq 'passwords') {
1.405 raeburn 8179: if ($settings->{expire}) {
8180: $expire = $settings->{expire};
8181: }
8182: if ($settings->{numsaved}) {
8183: $numsaved = $settings->{numsaved};
8184: }
8185: }
8186: }
8187: my %rulenames = &Apache::lonlocal::texthash(
8188: uc => 'At least one upper case letter',
8189: lc => 'At least one lower case letter',
8190: num => 'At least one number',
8191: spec => 'At least one non-alphanumeric',
8192: );
8193: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
8194: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
8195: '<td class="LC_left_item"><span class="LC_nobreak">'.
8196: '<input type="text" name="'.$prefix.'_min" value="'.$min.'" size="3" '.
8197: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8198: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
8199: '</span></td></tr>';
8200: $itemcount ++;
8201: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8202: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
8203: '<td class="LC_left_item"><span class="LC_nobreak">'.
8204: '<input type="text" name="'.$prefix.'_max" value="'.$max.'" size="3" '.
8205: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8206: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
8207: '</span></td></tr>';
8208: $itemcount ++;
8209: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8210: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
8211: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
8212: '</span></td>';
8213: my $numinrow = 2;
8214: my @possrules = ('uc','lc','num','spec');
8215: $datatable .= '<td class="LC_left_item"><table>';
8216: for (my $i=0; $i<@possrules; $i++) {
8217: my ($rem,$checked);
8218: if ($chars{$possrules[$i]}) {
8219: $checked = ' checked="checked"';
8220: }
8221: $rem = $i%($numinrow);
8222: if ($rem == 0) {
8223: if ($i > 0) {
8224: $datatable .= '</tr>';
8225: }
8226: $datatable .= '<tr>';
8227: }
8228: $datatable .= '<td><span class="LC_nobreak"><label>'.
8229: '<input type="checkbox" name="'.$prefix.'_chars" value="'.$possrules[$i].'"'.$checked.' />'.
8230: $rulenames{$possrules[$i]}.'</label></span></td>';
8231: }
8232: my $rem = @possrules%($numinrow);
8233: my $colsleft = $numinrow - $rem;
8234: if ($colsleft > 1 ) {
8235: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8236: ' </td>';
8237: } elsif ($colsleft == 1) {
8238: $datatable .= '<td class="LC_left_item"> </td>';
8239: }
8240: $datatable .='</table></td></tr>';
8241: $itemcount ++;
8242: if ($prefix eq 'passwords') {
8243: $titles{'expire'} = &mt('Password expiration (days)');
8244: $titles{'numsaved'} = &mt('Number of previous passwords to save and disallow reuse');
8245: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8246: $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
8247: '<td class="LC_left_item"><span class="LC_nobreak">'.
8248: '<input type="text" name="'.$prefix.'_expire" value="'.$expire.'" size="4" '.
8249: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8250: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
8251: '</span></td></tr>';
8252: $itemcount ++;
8253: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8254: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
8255: '<td class="LC_left_item"><span class="LC_nobreak">'.
8256: '<input type="text" name="'.$prefix.'_numsaved" value="'.$numsaved.'" size="3" '.
8257: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8258: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
8259: '</span></td></tr>';
8260: $itemcount ++;
8261: }
8262: if (ref($itemcountref)) {
8263: $$itemcountref += $itemcount;
8264: }
8265: return $datatable;
8266: }
8267:
1.373 raeburn 8268: sub print_wafproxy {
8269: my ($position,$dom,$settings,$rowtotal) = @_;
8270: my $css_class;
8271: my $itemcount = 0;
8272: my $datatable;
8273: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 8274: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
1.374 raeburn 8275: my %lt = &wafproxy_titles();
1.373 raeburn 8276: foreach my $server (sort(keys(%servers))) {
8277: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
1.381 raeburn 8278: next if ($serverhome eq '');
1.373 raeburn 8279: my $serverdom;
8280: if ($serverhome ne $server) {
8281: $serverdom = &Apache::lonnet::host_domain($serverhome);
1.381 raeburn 8282: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
8283: $othercontrol{$server} = $serverdom;
8284: }
1.373 raeburn 8285: } else {
8286: $serverdom = &Apache::lonnet::host_domain($server);
1.381 raeburn 8287: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
1.373 raeburn 8288: if ($serverdom ne $dom) {
8289: $othercontrol{$server} = $serverdom;
8290: } else {
8291: $setdom = 1;
8292: if (ref($settings) eq 'HASH') {
8293: if (ref($settings->{'alias'}) eq 'HASH') {
8294: $aliases{$dom} = $settings->{'alias'};
1.381 raeburn 8295: if ($aliases{$dom} ne '') {
8296: $showdom = 1;
8297: }
1.373 raeburn 8298: }
1.388 raeburn 8299: if (ref($settings->{'saml'}) eq 'HASH') {
8300: $saml{$dom} = $settings->{'saml'};
8301: }
1.373 raeburn 8302: }
8303: }
8304: }
8305: }
1.381 raeburn 8306: if ($setdom) {
8307: %{$values{$dom}} = ();
8308: if (ref($settings) eq 'HASH') {
8309: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8310: $values{$dom}{$item} = $settings->{$item};
8311: }
8312: }
8313: }
1.373 raeburn 8314: if (keys(%othercontrol)) {
8315: %otherdoms = reverse(%othercontrol);
8316: foreach my $domain (keys(%otherdoms)) {
8317: %{$values{$domain}} = ();
8318: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
1.383 raeburn 8319: if (ref($config{'wafproxy'}) eq 'HASH') {
8320: $aliases{$domain} = $config{'wafproxy'}{'alias'};
1.425 raeburn 8321: if (exists($config{'wafproxy'}{'saml'})) {
1.388 raeburn 8322: $saml{$domain} = $config{'wafproxy'}{'saml'};
8323: }
1.383 raeburn 8324: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8325: $values{$domain}{$item} = $config{'wafproxy'}{$item};
1.373 raeburn 8326: }
8327: }
8328: }
8329: }
8330: if ($position eq 'top') {
8331: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.381 raeburn 8332: my %aliasinfo;
1.373 raeburn 8333: foreach my $server (sort(keys(%servers))) {
1.381 raeburn 8334: $itemcount ++;
8335: my $dom_in_effect;
8336: my $aliasrows = '<tr>'.
1.383 raeburn 8337: '<td class="LC_left_item" style="vertical-align: baseline;">'.
8338: &mt('Hostname').': '.
8339: '<i>'.&Apache::lonnet::hostname($server).'</i></td><td> </td>';
1.373 raeburn 8340: if ($othercontrol{$server}) {
1.381 raeburn 8341: $dom_in_effect = $othercontrol{$server};
1.388 raeburn 8342: my ($current,$forsaml);
1.383 raeburn 8343: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
8344: $current = $aliases{$dom_in_effect}{$server};
1.373 raeburn 8345: }
1.388 raeburn 8346: if (ref($saml{$dom_in_effect}) eq 'HASH') {
8347: if ($saml{$dom_in_effect}{$server}) {
8348: $forsaml = 1;
8349: }
8350: }
1.383 raeburn 8351: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8352: &mt('Alias').': ';
1.373 raeburn 8353: if ($current) {
1.381 raeburn 8354: $aliasrows .= $current;
1.388 raeburn 8355: if ($forsaml) {
1.396 raeburn 8356: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
1.388 raeburn 8357: }
1.373 raeburn 8358: } else {
1.383 raeburn 8359: $aliasrows .= &mt('None');
1.373 raeburn 8360: }
1.383 raeburn 8361: $aliasrows .= ' <span class="LC_small">('.
8362: &mt('controlled by domain: [_1]',
8363: '<b>'.$dom_in_effect.'</b>').')</span></td>';
1.373 raeburn 8364: } else {
1.381 raeburn 8365: $dom_in_effect = $dom;
1.388 raeburn 8366: my ($current,$samlon,$samloff);
8367: $samloff = ' checked="checked"';
1.373 raeburn 8368: if (ref($aliases{$dom}) eq 'HASH') {
8369: if ($aliases{$dom}{$server}) {
8370: $current = $aliases{$dom}{$server};
8371: }
8372: }
1.388 raeburn 8373: if (ref($saml{$dom}) eq 'HASH') {
8374: if ($saml{$dom}{$server}) {
8375: $samlon = $samloff;
8376: undef($samloff);
8377: }
8378: }
1.383 raeburn 8379: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8380: &mt('Alias').': '.
1.381 raeburn 8381: '<input type="text" name="wafproxy_alias_'.$server.'" '.
1.388 raeburn 8382: 'value="'.$current.'" size="30" />'.
8383: (' 'x2).'<span class="LC_nobreak">'.
1.396 raeburn 8384: &mt('Alias used for SSO Auth').': <label>'.
1.388 raeburn 8385: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
1.425 raeburn 8386: &mt('No').'</label> <label>'.
1.388 raeburn 8387: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
8388: &mt('Yes').'</label></span>'.
1.425 raeburn 8389: '</td>';
1.381 raeburn 8390: }
8391: $aliasrows .= '</tr>';
8392: $aliasinfo{$dom_in_effect} .= $aliasrows;
8393: }
8394: if ($aliasinfo{$dom}) {
8395: my ($onclick,$wafon,$wafoff,$showtable);
8396: $onclick = ' onclick="javascript:toggleWAF();"';
8397: $wafoff = ' checked="checked"';
8398: $showtable = ' style="display:none";';
8399: if ($showdom) {
8400: $wafon = $wafoff;
8401: $wafoff = '';
8402: $showtable = ' style="display:inline;"';
8403: }
8404: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8405: $datatable = '<tr'.$css_class.'>'.
8406: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
8407: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
8408: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
8409: &mt('Yes').'</label>'.(' 'x2).'<label>'.
8410: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
8411: &mt('No').'</label></span></td>'.
8412: '<td class="LC_left_item">'.
8413: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
8414: '</table></td></tr>';
8415: $itemcount++;
8416: }
1.383 raeburn 8417: if (keys(%otherdoms)) {
8418: foreach my $key (sort(keys(%otherdoms))) {
1.381 raeburn 8419: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.383 raeburn 8420: $datatable .= '<tr'.$css_class.'>'.
8421: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
8422: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
8423: '</table></td></tr>';
1.381 raeburn 8424: $itemcount++;
1.373 raeburn 8425: }
8426: }
8427: } else {
1.383 raeburn 8428: my %ip_methods = &remoteip_methods();
1.373 raeburn 8429: if ($setdom) {
8430: $itemcount ++;
8431: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.381 raeburn 8432: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
1.382 raeburn 8433: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
1.381 raeburn 8434: $wafstyle = ' style="display:none;"';
8435: $nowafstyle = ' style="display:table-row;"';
8436: $currwafdisplay = ' style="display: none"';
8437: $wafrangestyle = ' style="display: none"';
8438: $curr_remotip = 'n';
1.382 raeburn 8439: $ssltossl = ' checked="checked"';
1.381 raeburn 8440: if ($showdom) {
8441: $wafstyle = ' style="display:table-row;"';
8442: $nowafstyle = ' style="display:none;"';
8443: if (keys(%{$values{$dom}})) {
8444: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
8445: $curr_remotip = $values{$dom}{remoteip};
8446: }
8447: if ($curr_remotip eq 'h') {
8448: $currwafdisplay = ' style="display:table-row"';
8449: $wafrangestyle = ' style="display:inline-block;"';
8450: }
1.382 raeburn 8451: if ($values{$dom}{'sslopt'}) {
8452: $alltossl = ' checked="checked"';
8453: $ssltossl = '';
8454: }
1.381 raeburn 8455: }
8456: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
8457: $vpndircheck = ' checked="checked"';
8458: $currwafvpn = ' style="display:table-row;"';
8459: $wafrangestyle = ' style="display:inline-block;"';
8460: } else {
8461: $vpnaliascheck = ' checked="checked"';
8462: $currwafvpn = ' style="display:none;"';
8463: }
8464: }
8465: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
8466: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
8467: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
8468: '</tr>'.
8469: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
1.374 raeburn 8470: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
1.381 raeburn 8471: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
1.393 raeburn 8472: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
8473: &mt('Range(s) stored in CIDR notation').'</div></td>'.
1.381 raeburn 8474: '<td class="LC_left_item"><table>'.
8475: '<tr>'.
8476: '<td valign="top">'.$lt{'remoteip'}.': '.
8477: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
8478: foreach my $option ('m','h','n') {
8479: my $sel;
8480: if ($option eq $curr_remotip) {
8481: $sel = ' selected="selected"';
8482: }
8483: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
8484: $ip_methods{$option}.'</option>';
8485: }
8486: $datatable .= '</select></td></tr>'."\n".
8487: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
8488: $lt{'ipheader'}.': '.
8489: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
8490: 'name="wafproxy_ipheader" />'.
8491: '</td></tr>'."\n".
8492: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
1.382 raeburn 8493: $lt{'trusted'}.':<br />'.
1.381 raeburn 8494: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
8495: $values{$dom}{'trusted'}.'</textarea>'.
8496: '</td></tr>'."\n".
8497: '<tr><td><hr /></td></tr>'."\n".
8498: '<tr>'.
8499: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
8500: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
8501: $lt{'vpndirect'}.'</label>'.(' 'x2).
8502: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
8503: $lt{'vpnaliased'}.'</label></span></td></tr>';
8504: foreach my $item ('vpnint','vpnext') {
8505: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
1.382 raeburn 8506: '<td valign="top">'.$lt{$item}.':<br />'.
1.381 raeburn 8507: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
8508: $values{$dom}{$item}.'</textarea>'.
8509: '</td></tr>'."\n";
1.373 raeburn 8510: }
1.382 raeburn 8511: $datatable .= '<tr><td><hr /></td></tr>'."\n".
8512: '<tr>'.
8513: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
8514: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
8515: $lt{'alltossl'}.'</label>'.(' 'x2).
8516: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
8517: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
8518: '</table></td></tr>';
1.373 raeburn 8519: }
8520: if (keys(%otherdoms)) {
8521: foreach my $domain (sort(keys(%otherdoms))) {
8522: $itemcount ++;
8523: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8524: $datatable .= '<tr'.$css_class.'>'.
1.383 raeburn 8525: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
1.374 raeburn 8526: '<td class="LC_left_item"><table>';
1.382 raeburn 8527: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 8528: my $showval = &mt('None');
1.382 raeburn 8529: if ($item eq 'ssl') {
8530: $showval = $lt{'ssltossl'};
8531: }
1.373 raeburn 8532: if ($values{$domain}{$item}) {
1.381 raeburn 8533: $showval = $values{$domain}{$item};
1.382 raeburn 8534: if ($item eq 'ssl') {
8535: $showval = $lt{'alltossl'};
1.383 raeburn 8536: } elsif ($item eq 'remoteip') {
8537: $showval = $ip_methods{$values{$domain}{$item}};
1.382 raeburn 8538: }
1.373 raeburn 8539: }
8540: $datatable .= '<tr>'.
8541: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
8542: }
1.381 raeburn 8543: $datatable .= '</table></td></tr>';
1.373 raeburn 8544: }
8545: }
8546: }
8547: $$rowtotal += $itemcount;
8548: return $datatable;
8549: }
8550:
8551: sub wafproxy_titles {
8552: return &Apache::lonlocal::texthash(
1.381 raeburn 8553: remoteip => "Method for determining user's IP",
8554: ipheader => 'Request header containing remote IP',
8555: trusted => 'Trusted IP range(s)',
8556: vpnaccess => 'Access from institutional VPN',
8557: vpndirect => 'via regular hostname (no WAF)',
8558: vpnaliased => 'via aliased hostname (WAF)',
8559: vpnint => 'Internal IP Range(s) for VPN sessions',
8560: vpnext => 'IP Range(s) for backend WAF connections',
1.382 raeburn 8561: sslopt => 'Forwarding http/https',
1.381 raeburn 8562: alltossl => 'WAF forwards both http and https requests to https',
8563: ssltossl => 'WAF forwards http requests to http and https to https',
8564: );
8565: }
8566:
8567: sub remoteip_methods {
8568: return &Apache::lonlocal::texthash(
8569: m => 'Use Apache mod_remoteip',
8570: h => 'Use headers parsed by LON-CAPA',
8571: n => 'Not in use',
1.373 raeburn 8572: );
8573: }
8574:
1.137 raeburn 8575: sub print_usersessions {
8576: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 8577: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 8578: my (%by_ip,%by_location,@intdoms,@instdoms);
8579: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 8580:
8581: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 8582: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 8583: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 8584: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 8585: if ($position eq 'top') {
1.152 raeburn 8586: if (keys(%serverhomes) > 1) {
1.145 raeburn 8587: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.371 raeburn 8588: my ($curroffloadnow,$curroffloadoth);
1.261 raeburn 8589: if (ref($settings) eq 'HASH') {
8590: if (ref($settings->{'offloadnow'}) eq 'HASH') {
8591: $curroffloadnow = $settings->{'offloadnow'};
8592: }
1.371 raeburn 8593: if (ref($settings->{'offloadoth'}) eq 'HASH') {
8594: $curroffloadoth = $settings->{'offloadoth'};
8595: }
1.261 raeburn 8596: }
1.371 raeburn 8597: my $other_insts = scalar(keys(%by_location));
8598: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
8599: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 8600: } else {
1.140 raeburn 8601: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 8602: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
8603: '</td></tr>';
1.140 raeburn 8604: }
1.137 raeburn 8605: } else {
1.279 raeburn 8606: my %titles = &usersession_titles();
8607: my ($prefix,@types);
8608: if ($position eq 'bottom') {
8609: $prefix = 'remote';
8610: @types = ('version','excludedomain','includedomain');
1.145 raeburn 8611: } else {
1.279 raeburn 8612: $prefix = 'hosted';
8613: @types = ('excludedomain','includedomain');
8614: }
8615: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8616: }
8617: $$rowtotal += $itemcount;
8618: return $datatable;
8619: }
8620:
8621: sub rules_by_location {
8622: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
8623: my ($datatable,$itemcount,$css_class);
8624: if (keys(%{$by_location}) == 0) {
8625: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8626: $datatable = '<tr'.$css_class.'><td colspan="2">'.
8627: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
8628: '</td></tr>';
8629: $itemcount = 1;
8630: } else {
8631: $itemcount = 0;
8632: my $numinrow = 5;
8633: my (%current,%checkedon,%checkedoff);
8634: my @locations = sort(keys(%{$by_location}));
8635: foreach my $type (@{$types}) {
8636: $checkedon{$type} = '';
8637: $checkedoff{$type} = ' checked="checked"';
8638: }
8639: if (ref($settings) eq 'HASH') {
8640: if (ref($settings->{$prefix}) eq 'HASH') {
8641: foreach my $key (keys(%{$settings->{$prefix}})) {
8642: $current{$key} = $settings->{$prefix}{$key};
8643: if ($key eq 'version') {
8644: if ($current{$key} ne '') {
1.145 raeburn 8645: $checkedon{$key} = ' checked="checked"';
8646: $checkedoff{$key} = '';
8647: }
1.279 raeburn 8648: } elsif (ref($current{$key}) eq 'ARRAY') {
8649: $checkedon{$key} = ' checked="checked"';
8650: $checkedoff{$key} = '';
1.137 raeburn 8651: }
8652: }
8653: }
1.279 raeburn 8654: }
8655: foreach my $type (@{$types}) {
8656: next if ($type ne 'version' && !@locations);
8657: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8658: $datatable .= '<tr'.$css_class.'>
8659: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
8660: <span class="LC_nobreak">
8661: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
8662: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
8663: if ($type eq 'version') {
8664: my @lcversions = &Apache::lonnet::all_loncaparevs();
8665: my $selector = '<select name="'.$prefix.'_version">';
8666: foreach my $version (@lcversions) {
8667: my $selected = '';
8668: if ($current{'version'} eq $version) {
8669: $selected = ' selected="selected"';
1.145 raeburn 8670: }
1.279 raeburn 8671: $selector .= ' <option value="'.$version.'"'.
8672: $selected.'>'.$version.'</option>';
8673: }
8674: $selector .= '</select> ';
8675: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
8676: } else {
8677: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
8678: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
8679: ' />'.(' 'x2).
8680: '<input type="button" value="'.&mt('uncheck all').'" '.
8681: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
8682: "\n".
8683: '</div><div><table>';
8684: my $rem;
8685: for (my $i=0; $i<@locations; $i++) {
8686: my ($showloc,$value,$checkedtype);
8687: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
8688: my $ip = $by_location->{$locations[$i]}->[0];
8689: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8690: $value = join(':',@{$by_ip->{$ip}});
8691: $showloc = join(', ',@{$by_ip->{$ip}});
8692: if (ref($current{$type}) eq 'ARRAY') {
8693: foreach my $loc (@{$by_ip->{$ip}}) {
8694: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
8695: $checkedtype = ' checked="checked"';
8696: last;
1.145 raeburn 8697: }
1.138 raeburn 8698: }
8699: }
8700: }
1.137 raeburn 8701: }
1.279 raeburn 8702: $rem = $i%($numinrow);
8703: if ($rem == 0) {
8704: if ($i > 0) {
8705: $datatable .= '</tr>';
8706: }
8707: $datatable .= '<tr>';
8708: }
8709: $datatable .= '<td class="LC_left_item">'.
8710: '<span class="LC_nobreak"><label>'.
8711: '<input type="checkbox" name="'.$prefix.'_'.$type.
8712: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
8713: '</label></span></td>';
8714: }
8715: $rem = @locations%($numinrow);
8716: my $colsleft = $numinrow - $rem;
8717: if ($colsleft > 1 ) {
8718: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8719: ' </td>';
8720: } elsif ($colsleft == 1) {
8721: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 8722: }
1.279 raeburn 8723: $datatable .= '</tr></table>';
1.137 raeburn 8724: }
1.279 raeburn 8725: $datatable .= '</td></tr>';
8726: $itemcount ++;
1.137 raeburn 8727: }
8728: }
1.279 raeburn 8729: return ($datatable,$itemcount);
1.137 raeburn 8730: }
8731:
1.275 raeburn 8732: sub print_ssl {
8733: my ($position,$dom,$settings,$rowtotal) = @_;
8734: my ($css_class,$datatable);
8735: my $itemcount = 1;
8736: if ($position eq 'top') {
1.281 raeburn 8737: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8738: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8739: my $same_institution;
8740: if ($intdom ne '') {
8741: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
8742: if (ref($internet_names) eq 'ARRAY') {
8743: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
8744: $same_institution = 1;
8745: }
8746: }
8747: }
1.275 raeburn 8748: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 8749: $datatable = '<tr'.$css_class.'><td colspan="2">';
8750: if ($same_institution) {
8751: my %domservers = &Apache::lonnet::get_servers($dom);
8752: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
8753: } else {
8754: $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.");
8755: }
8756: $datatable .= '</td></tr>';
1.275 raeburn 8757: $itemcount ++;
8758: } else {
8759: my %titles = &ssl_titles();
8760: my (%by_ip,%by_location,@intdoms,@instdoms);
8761: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8762: my @alldoms = &Apache::lonnet::all_domains();
8763: my %serverhomes = %Apache::lonnet::serverhomeIDs;
8764: my @domservers = &Apache::lonnet::get_servers($dom);
8765: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8766: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 8767: if (($position eq 'connto') || ($position eq 'connfrom')) {
8768: my $legacy;
8769: unless (ref($settings) eq 'HASH') {
8770: my $name;
8771: if ($position eq 'connto') {
8772: $name = 'loncAllowInsecure';
8773: } else {
8774: $name = 'londAllowInsecure';
8775: }
8776: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
8777: my @ids=&Apache::lonnet::current_machine_ids();
8778: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
8779: my %what = (
8780: $name => 1,
8781: );
8782: my ($result,$returnhash) =
8783: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
8784: if ($result eq 'ok') {
8785: if (ref($returnhash) eq 'HASH') {
8786: $legacy = $returnhash->{$name};
8787: }
8788: }
8789: } else {
8790: $legacy = $Apache::lonnet::perlvar{$name};
8791: }
8792: }
1.275 raeburn 8793: foreach my $type ('dom','intdom','other') {
8794: my %checked;
8795: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8796: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
8797: '<td class="LC_right_item">';
8798: my $skip;
8799: if ($type eq 'dom') {
8800: unless (keys(%servers) > 1) {
8801: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
8802: $skip = 1;
8803: }
8804: }
8805: if ($type eq 'intdom') {
8806: unless (@instdoms > 1) {
8807: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
8808: $skip = 1;
8809: }
8810: } elsif ($type eq 'other') {
8811: if (keys(%by_location) == 0) {
8812: $datatable .= &mt('Nothing to set here, as there are no other institutions');
8813: $skip = 1;
8814: }
8815: }
8816: unless ($skip) {
8817: $checked{'yes'} = ' checked="checked"';
8818: if (ref($settings) eq 'HASH') {
1.293 raeburn 8819: if (ref($settings->{$position}) eq 'HASH') {
8820: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 8821: $checked{$1} = $checked{'yes'};
8822: delete($checked{'yes'});
8823: }
8824: }
1.293 raeburn 8825: } else {
8826: if ($legacy == 0) {
8827: $checked{'req'} = $checked{'yes'};
8828: delete($checked{'yes'});
8829: }
1.275 raeburn 8830: }
8831: foreach my $option ('no','yes','req') {
8832: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 8833: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 8834: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
8835: '</label></span>'.(' 'x2);
8836: }
8837: }
8838: $datatable .= '</td></tr>';
8839: $itemcount ++;
8840: }
8841: } else {
8842: my $prefix = 'replication';
8843: my @types = ('certreq','nocertreq');
1.279 raeburn 8844: if (keys(%by_location) == 0) {
8845: $datatable .= '<tr'.$css_class.'><td>'.
8846: &mt('Nothing to set here, as there are no other institutions').
8847: '</td></tr>';
8848: $itemcount ++;
1.275 raeburn 8849: } else {
1.279 raeburn 8850: ($datatable,$itemcount) =
8851: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 8852: }
8853: }
8854: }
8855: $$rowtotal += $itemcount;
8856: return $datatable;
8857: }
8858:
8859: sub ssl_titles {
8860: return &Apache::lonlocal::texthash (
8861: dom => 'LON-CAPA servers/VMs from same domain',
8862: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
8863: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 8864: connto => 'Connections to other servers',
8865: connfrom => 'Connections from other servers',
1.275 raeburn 8866: replication => 'Replicating content to other institutions',
8867: certreq => 'Client certificate required, but specific domains exempt',
8868: nocertreq => 'No client certificate required, except for specific domains',
8869: no => 'SSL not used',
8870: yes => 'SSL Optional (used if available)',
8871: req => 'SSL Required',
8872: );
1.279 raeburn 8873: }
8874:
8875: sub print_trust {
8876: my ($prefix,$dom,$settings,$rowtotal) = @_;
8877: my ($css_class,$datatable,%checked,%choices);
8878: my (%by_ip,%by_location,@intdoms,@instdoms);
8879: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8880: my $itemcount = 1;
8881: my %titles = &trust_titles();
8882: my @types = ('exc','inc');
8883: if ($prefix eq 'top') {
8884: $prefix = 'content';
8885: } elsif ($prefix eq 'bottom') {
8886: $prefix = 'msg';
8887: }
8888: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8889: $$rowtotal += $itemcount;
8890: return $datatable;
8891: }
8892:
8893: sub trust_titles {
8894: return &Apache::lonlocal::texthash(
8895: content => "Access to this domain's content by others",
8896: shared => "Access to other domain's content by this domain",
8897: enroll => "Enrollment in this domain's courses by others",
8898: othcoau => "Co-author roles in this domain for others",
8899: coaurem => "Co-author roles for this domain's users elsewhere",
8900: domroles => "Domain roles in this domain assignable to others",
8901: catalog => "Course Catalog for this domain displayed elsewhere",
8902: reqcrs => "Requests for creation of courses in this domain by others",
8903: msg => "Users in other domains can send messages to this domain",
8904: exc => "Allow all, but exclude specific domains",
8905: inc => "Deny all, but include specific domains",
8906: );
1.275 raeburn 8907: }
8908:
1.138 raeburn 8909: sub build_location_hashes {
1.275 raeburn 8910: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 8911: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 8912: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 8913: my %iphost = &Apache::lonnet::get_iphost();
8914: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
8915: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
8916: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
8917: foreach my $id (@{$iphost{$primary_ip}}) {
8918: my $intdom = &Apache::lonnet::internet_dom($id);
8919: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
8920: push(@{$intdoms},$intdom);
8921: }
8922: }
8923: }
8924: foreach my $ip (keys(%iphost)) {
8925: if (ref($iphost{$ip}) eq 'ARRAY') {
8926: foreach my $id (@{$iphost{$ip}}) {
8927: my $location = &Apache::lonnet::internet_dom($id);
8928: if ($location) {
1.275 raeburn 8929: if (grep(/^\Q$location\E$/,@{$intdoms})) {
8930: my $dom = &Apache::lonnet::host_domain($id);
8931: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
8932: push(@{$instdoms},$dom);
8933: }
8934: next;
8935: }
1.138 raeburn 8936: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8937: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
8938: push(@{$by_ip->{$ip}},$location);
8939: }
8940: } else {
8941: $by_ip->{$ip} = [$location];
8942: }
8943: }
8944: }
8945: }
8946: }
8947: foreach my $ip (sort(keys(%{$by_ip}))) {
8948: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8949: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
8950: my $first = $by_ip->{$ip}->[0];
8951: if (ref($by_location->{$first}) eq 'ARRAY') {
8952: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
8953: push(@{$by_location->{$first}},$ip);
8954: }
8955: } else {
8956: $by_location->{$first} = [$ip];
8957: }
8958: }
8959: }
8960: return;
8961: }
8962:
1.145 raeburn 8963: sub current_offloads_to {
8964: my ($dom,$settings,$servers) = @_;
8965: my (%spareid,%otherdomconfigs);
1.152 raeburn 8966: if (ref($servers) eq 'HASH') {
1.145 raeburn 8967: foreach my $lonhost (sort(keys(%{$servers}))) {
8968: my $gotspares;
1.152 raeburn 8969: if (ref($settings) eq 'HASH') {
8970: if (ref($settings->{'spares'}) eq 'HASH') {
8971: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
8972: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
8973: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
8974: $gotspares = 1;
8975: }
1.145 raeburn 8976: }
8977: }
8978: unless ($gotspares) {
8979: my $gotspares;
8980: my $serverhomeID =
8981: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
8982: my $serverhomedom =
8983: &Apache::lonnet::host_domain($serverhomeID);
8984: if ($serverhomedom ne $dom) {
8985: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
8986: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
8987: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
8988: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
8989: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
8990: $gotspares = 1;
8991: }
8992: }
8993: } else {
8994: $otherdomconfigs{$serverhomedom} =
8995: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
8996: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
8997: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
8998: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
8999: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
9000: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
9001: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
9002: $gotspares = 1;
9003: }
9004: }
9005: }
9006: }
9007: }
9008: }
9009: }
9010: unless ($gotspares) {
9011: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
9012: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9013: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9014: } else {
9015: my $server_hostname = &Apache::lonnet::hostname($lonhost);
9016: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
9017: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
9018: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9019: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9020: } else {
1.150 raeburn 9021: my %what = (
9022: spareid => 1,
9023: );
9024: my ($result,$returnhash) =
9025: &Apache::lonnet::get_remote_globals($lonhost,\%what);
9026: if ($result eq 'ok') {
9027: if (ref($returnhash) eq 'HASH') {
9028: if (ref($returnhash->{'spareid'}) eq 'HASH') {
9029: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
9030: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
9031: }
9032: }
1.145 raeburn 9033: }
9034: }
9035: }
9036: }
9037: }
9038: }
9039: return %spareid;
9040: }
9041:
9042: sub spares_row {
1.371 raeburn 9043: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
9044: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 9045: my $css_class;
9046: my $numinrow = 4;
9047: my $itemcount = 1;
9048: my $datatable;
1.152 raeburn 9049: my %typetitles = &sparestype_titles();
9050: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 9051: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 9052: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
9053: my ($othercontrol,$serverdom);
9054: if ($serverhome ne $server) {
9055: $serverdom = &Apache::lonnet::host_domain($serverhome);
9056: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9057: } else {
9058: $serverdom = &Apache::lonnet::host_domain($server);
9059: if ($serverdom ne $dom) {
9060: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9061: }
9062: }
9063: next unless (ref($spareid->{$server}) eq 'HASH');
1.371 raeburn 9064: my ($checkednow,$checkedoth);
1.261 raeburn 9065: if (ref($curroffloadnow) eq 'HASH') {
9066: if ($curroffloadnow->{$server}) {
9067: $checkednow = ' checked="checked"';
9068: }
9069: }
1.371 raeburn 9070: if (ref($curroffloadoth) eq 'HASH') {
9071: if ($curroffloadoth->{$server}) {
9072: $checkedoth = ' checked="checked"';
9073: }
9074: }
1.145 raeburn 9075: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
9076: $datatable .= '<tr'.$css_class.'>
9077: <td rowspan="2">
1.183 bisitz 9078: <span class="LC_nobreak">'.
9079: &mt('[_1] when busy, offloads to:'
1.261 raeburn 9080: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 9081: '<span class="LC_nobreak">'."\n".
1.261 raeburn 9082: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.371 raeburn 9083: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.183 bisitz 9084: "\n";
1.371 raeburn 9085: if ($other_insts) {
9086: $datatable .= '<br />'.
9087: '<span class="LC_nobreak">'."\n".
9088: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
9089: ' '.&mt('Switch other institutions on next access').'</label></span>'.
9090: "\n";
9091: }
1.145 raeburn 9092: my (%current,%canselect);
1.152 raeburn 9093: my @choices =
9094: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
9095: foreach my $type ('primary','default') {
9096: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 9097: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
9098: my @spares = @{$spareid->{$server}{$type}};
9099: if (@spares > 0) {
1.152 raeburn 9100: if ($othercontrol) {
9101: $current{$type} = join(', ',@spares);
9102: } else {
9103: $current{$type} .= '<table>';
9104: my $numspares = scalar(@spares);
9105: for (my $i=0; $i<@spares; $i++) {
9106: my $rem = $i%($numinrow);
9107: if ($rem == 0) {
9108: if ($i > 0) {
9109: $current{$type} .= '</tr>';
9110: }
9111: $current{$type} .= '<tr>';
1.145 raeburn 9112: }
1.152 raeburn 9113: $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'".');" /> '.
9114: $spareid->{$server}{$type}[$i].
9115: '</label></td>'."\n";
9116: }
9117: my $rem = @spares%($numinrow);
9118: my $colsleft = $numinrow - $rem;
9119: if ($colsleft > 1 ) {
9120: $current{$type} .= '<td colspan="'.$colsleft.
9121: '" class="LC_left_item">'.
9122: ' </td>';
9123: } elsif ($colsleft == 1) {
9124: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 9125: }
1.152 raeburn 9126: $current{$type} .= '</tr></table>';
1.150 raeburn 9127: }
1.145 raeburn 9128: }
9129: }
9130: if ($current{$type} eq '') {
9131: $current{$type} = &mt('None specified');
9132: }
1.152 raeburn 9133: if ($othercontrol) {
9134: if ($type eq 'primary') {
9135: $canselect{$type} = $othercontrol;
9136: }
9137: } else {
9138: $canselect{$type} =
9139: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
9140: '<select name="newspare_'.$type.'_'.$server.'" '.
9141: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
9142: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
9143: if (@choices > 0) {
9144: foreach my $lonhost (@choices) {
9145: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
9146: }
9147: }
9148: $canselect{$type} .= '</select>'."\n";
9149: }
9150: } else {
9151: $current{$type} = &mt('Could not be determined');
9152: if ($type eq 'primary') {
9153: $canselect{$type} = $othercontrol;
9154: }
1.145 raeburn 9155: }
1.152 raeburn 9156: if ($type eq 'default') {
9157: $datatable .= '<tr'.$css_class.'>';
9158: }
9159: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
9160: '<td>'.$current{$type}.'</td>'."\n".
9161: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 9162: }
9163: $itemcount ++;
9164: }
9165: }
9166: $$rowtotal += $itemcount;
9167: return $datatable;
9168: }
9169:
1.152 raeburn 9170: sub possible_newspares {
9171: my ($server,$currspares,$serverhomes,$altids) = @_;
9172: my $serverhostname = &Apache::lonnet::hostname($server);
9173: my %excluded;
9174: if ($serverhostname ne '') {
9175: %excluded = (
9176: $serverhostname => 1,
9177: );
9178: }
9179: if (ref($currspares) eq 'HASH') {
9180: foreach my $type (keys(%{$currspares})) {
9181: if (ref($currspares->{$type}) eq 'ARRAY') {
9182: if (@{$currspares->{$type}} > 0) {
9183: foreach my $curr (@{$currspares->{$type}}) {
9184: my $hostname = &Apache::lonnet::hostname($curr);
9185: $excluded{$hostname} = 1;
9186: }
9187: }
9188: }
9189: }
9190: }
9191: my @choices;
9192: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
9193: if (keys(%{$serverhomes}) > 1) {
9194: foreach my $name (sort(keys(%{$serverhomes}))) {
9195: unless ($excluded{$name}) {
9196: if (exists($altids->{$serverhomes->{$name}})) {
9197: push(@choices,$altids->{$serverhomes->{$name}});
9198: } else {
9199: push(@choices,$serverhomes->{$name});
1.145 raeburn 9200: }
9201: }
9202: }
9203: }
9204: }
1.152 raeburn 9205: return sort(@choices);
1.145 raeburn 9206: }
9207:
1.150 raeburn 9208: sub print_loadbalancing {
9209: my ($dom,$settings,$rowtotal) = @_;
9210: my $primary_id = &Apache::lonnet::domain($dom,'primary');
9211: my $intdom = &Apache::lonnet::internet_dom($primary_id);
9212: my $numinrow = 1;
9213: my $datatable;
9214: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 9215: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 9216: if (ref($settings) eq 'HASH') {
9217: %existing = %{$settings};
9218: }
9219: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
9220: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 9221: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 9222: } else {
9223: return;
9224: }
9225: my ($othertitle,$usertypes,$types) =
9226: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 9227: my $rownum = 8;
1.150 raeburn 9228: if (ref($types) eq 'ARRAY') {
9229: $rownum += scalar(@{$types});
9230: }
1.171 raeburn 9231: my @css_class = ('LC_odd_row','LC_even_row');
9232: my $balnum = 0;
9233: my $islast;
9234: my (@toshow,$disabledtext);
9235: if (keys(%currbalancer) > 0) {
9236: @toshow = sort(keys(%currbalancer));
9237: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
9238: push(@toshow,'');
9239: }
9240: } else {
9241: @toshow = ('');
9242: $disabledtext = &mt('No existing load balancer');
9243: }
9244: foreach my $lonhost (@toshow) {
9245: if ($balnum == scalar(@toshow)-1) {
9246: $islast = 1;
9247: } else {
9248: $islast = 0;
9249: }
9250: my $cssidx = $balnum%2;
9251: my $targets_div_style = 'display: none';
9252: my $disabled_div_style = 'display: block';
9253: my $homedom_div_style = 'display: none';
9254: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 9255: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9256: '<p>';
9257: if ($lonhost eq '') {
1.210 raeburn 9258: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 9259: if (keys(%currbalancer) > 0) {
9260: $datatable .= &mt('Add balancer:');
9261: } else {
9262: $datatable .= &mt('Enable balancer:');
9263: }
9264: $datatable .= ' '.
9265: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
9266: ' id="loadbalancing_lonhost_'.$balnum.'"'.
9267: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
9268: '<option value="" selected="selected">'.&mt('None').
9269: '</option>'."\n";
9270: foreach my $server (sort(keys(%servers))) {
9271: next if ($currbalancer{$server});
9272: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
9273: }
1.210 raeburn 9274: $datatable .=
1.171 raeburn 9275: '</select>'."\n".
9276: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
9277: } else {
9278: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
9279: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
9280: &mt('Stop balancing').'</label>'.
9281: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
9282: $targets_div_style = 'display: block';
9283: $disabled_div_style = 'display: none';
9284: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
9285: $homedom_div_style = 'display: block';
9286: }
9287: }
1.306 raeburn 9288: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9289: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
9290: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
9291: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
9292: my ($numspares,@spares) = &count_servers($lonhost,%servers);
9293: my @sparestypes = ('primary','default');
9294: my %typetitles = &sparestype_titles();
1.284 raeburn 9295: my %hostherechecked = (
9296: no => ' checked="checked"',
9297: );
1.342 raeburn 9298: my %balcookiechecked = (
1.425 raeburn 9299: no => ' checked="checked"',
1.342 raeburn 9300: );
1.171 raeburn 9301: foreach my $sparetype (@sparestypes) {
9302: my $targettable;
9303: for (my $i=0; $i<$numspares; $i++) {
9304: my $checked;
9305: if (ref($currtargets{$lonhost}) eq 'HASH') {
9306: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9307: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9308: $checked = ' checked="checked"';
9309: }
9310: }
9311: }
9312: my ($chkboxval,$disabled);
9313: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
9314: $chkboxval = $spares[$i];
9315: }
9316: if (exists($currbalancer{$spares[$i]})) {
9317: $disabled = ' disabled="disabled"';
9318: }
1.210 raeburn 9319: $targettable .=
1.253 raeburn 9320: '<td><span class="LC_nobreak"><label>'.
9321: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 9322: $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 9323: '</span></label></span></td>';
1.171 raeburn 9324: my $rem = $i%($numinrow);
9325: if ($rem == 0) {
9326: if (($i > 0) && ($i < $numspares-1)) {
9327: $targettable .= '</tr>';
9328: }
9329: if ($i < $numspares-1) {
9330: $targettable .= '<tr>';
1.150 raeburn 9331: }
9332: }
9333: }
1.171 raeburn 9334: if ($targettable ne '') {
9335: my $rem = $numspares%($numinrow);
9336: my $colsleft = $numinrow - $rem;
9337: if ($colsleft > 1 ) {
9338: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9339: ' </td>';
9340: } elsif ($colsleft == 1) {
9341: $targettable .= '<td class="LC_left_item"> </td>';
9342: }
9343: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
9344: '<table><tr>'.$targettable.'</tr></table><br />';
9345: }
1.284 raeburn 9346: $hostherechecked{$sparetype} = '';
9347: if (ref($currtargets{$lonhost}) eq 'HASH') {
9348: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9349: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9350: $hostherechecked{$sparetype} = ' checked="checked"';
9351: $hostherechecked{'no'} = '';
9352: }
9353: }
9354: }
9355: }
1.342 raeburn 9356: if ($currcookies{$lonhost}) {
9357: %balcookiechecked = (
9358: yes => ' checked="checked"',
9359: );
9360: }
1.284 raeburn 9361: $datatable .= &mt('Hosting on balancer itself').'<br />'.
9362: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
9363: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
9364: foreach my $sparetype (@sparestypes) {
9365: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
9366: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
9367: '</i></label><br />';
1.171 raeburn 9368: }
1.342 raeburn 9369: $datatable .= &mt('Use balancer cookie').'<br />'.
9370: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
9371: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
9372: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
9373: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
9374: '</div></td></tr>'.
1.171 raeburn 9375: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
9376: $othertitle,$usertypes,$types,\%servers,
9377: \%currbalancer,$lonhost,
9378: $targets_div_style,$homedom_div_style,
9379: $css_class[$cssidx],$balnum,$islast);
9380: $$rowtotal += $rownum;
9381: $balnum ++;
9382: }
9383: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
9384: return $datatable;
9385: }
9386:
9387: sub get_loadbalancers_config {
1.342 raeburn 9388: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 9389: return unless ((ref($servers) eq 'HASH') &&
9390: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 9391: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
9392: (ref($currcookies) eq 'HASH'));
1.171 raeburn 9393: if (keys(%{$existing}) > 0) {
9394: my $oldlonhost;
9395: foreach my $key (sort(keys(%{$existing}))) {
9396: if ($key eq 'lonhost') {
9397: $oldlonhost = $existing->{'lonhost'};
9398: $currbalancer->{$oldlonhost} = 1;
9399: } elsif ($key eq 'targets') {
9400: if ($oldlonhost) {
9401: $currtargets->{$oldlonhost} = $existing->{'targets'};
9402: }
9403: } elsif ($key eq 'rules') {
9404: if ($oldlonhost) {
9405: $currrules->{$oldlonhost} = $existing->{'rules'};
9406: }
9407: } elsif (ref($existing->{$key}) eq 'HASH') {
9408: $currbalancer->{$key} = 1;
9409: $currtargets->{$key} = $existing->{$key}{'targets'};
9410: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 9411: if ($existing->{$key}{'cookie'}) {
9412: $currcookies->{$key} = 1;
9413: }
1.150 raeburn 9414: }
9415: }
1.171 raeburn 9416: } else {
9417: my ($balancerref,$targetsref) =
9418: &Apache::lonnet::get_lonbalancer_config($servers);
9419: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
9420: foreach my $server (sort(keys(%{$balancerref}))) {
9421: $currbalancer->{$server} = 1;
9422: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 9423: }
9424: }
9425: }
1.171 raeburn 9426: return;
1.150 raeburn 9427: }
9428:
9429: sub loadbalancing_rules {
9430: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 9431: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
9432: $css_class,$balnum,$islast) = @_;
1.150 raeburn 9433: my $output;
1.171 raeburn 9434: my $num = 0;
1.210 raeburn 9435: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 9436: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
9437: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
9438: foreach my $type (@{$alltypes}) {
1.171 raeburn 9439: $num ++;
1.150 raeburn 9440: my $current;
9441: if (ref($currrules) eq 'HASH') {
9442: $current = $currrules->{$type};
9443: }
1.253 raeburn 9444: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 9445: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 9446: $current = '';
9447: }
9448: }
9449: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 9450: $servers,$currbalancer,$lonhost,$dom,
9451: $targets_div_style,$homedom_div_style,
9452: $css_class,$balnum,$num,$islast);
1.150 raeburn 9453: }
9454: }
9455: return $output;
9456: }
9457:
9458: sub loadbalancing_titles {
9459: my ($dom,$intdom,$usertypes,$types) = @_;
9460: my %othertypes = (
9461: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
9462: '_LC_author' => &mt('Users from [_1] with author role',$dom),
9463: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
9464: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 9465: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
9466: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 9467: );
1.209 raeburn 9468: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 9469: my @available;
1.150 raeburn 9470: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9471: @available = @{$types};
1.150 raeburn 9472: }
1.302 raeburn 9473: unless (grep(/^default$/,@available)) {
9474: push(@available,'default');
9475: }
9476: unshift(@alltypes,@available);
1.150 raeburn 9477: my %titles;
9478: foreach my $type (@alltypes) {
9479: if ($type =~ /^_LC_/) {
9480: $titles{$type} = $othertypes{$type};
9481: } elsif ($type eq 'default') {
9482: $titles{$type} = &mt('All users from [_1]',$dom);
9483: if (ref($types) eq 'ARRAY') {
9484: if (@{$types} > 0) {
9485: $titles{$type} = &mt('Other users from [_1]',$dom);
9486: }
9487: }
9488: } elsif (ref($usertypes) eq 'HASH') {
9489: $titles{$type} = $usertypes->{$type};
9490: }
9491: }
9492: return (\@alltypes,\%othertypes,\%titles);
9493: }
9494:
9495: sub loadbalance_rule_row {
1.171 raeburn 9496: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
9497: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 9498: my @rulenames;
1.150 raeburn 9499: my %ruletitles = &offloadtype_text();
1.209 raeburn 9500: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 9501: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 9502: } else {
1.209 raeburn 9503: @rulenames = ('default','homeserver');
9504: if ($type eq '_LC_external') {
9505: push(@rulenames,'externalbalancer');
9506: } else {
9507: push(@rulenames,'specific');
9508: }
9509: push(@rulenames,'none');
1.150 raeburn 9510: }
9511: my $style = $targets_div_style;
1.253 raeburn 9512: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 9513: $style = $homedom_div_style;
9514: }
1.171 raeburn 9515: my $space;
9516: if ($islast && $num == 1) {
1.317 raeburn 9517: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 9518: }
1.210 raeburn 9519: my $output =
1.306 raeburn 9520: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 9521: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
9522: '<td valaign="top">'.$space.
9523: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 9524: for (my $i=0; $i<@rulenames; $i++) {
9525: my $rule = $rulenames[$i];
9526: my ($checked,$extra);
9527: if ($rulenames[$i] eq 'default') {
9528: $rule = '';
9529: }
9530: if ($rulenames[$i] eq 'specific') {
9531: if (ref($servers) eq 'HASH') {
9532: my $default;
9533: if (($current ne '') && (exists($servers->{$current}))) {
9534: $checked = ' checked="checked"';
9535: }
9536: unless ($checked) {
9537: $default = ' selected="selected"';
9538: }
1.210 raeburn 9539: $extra =
1.171 raeburn 9540: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
9541: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
9542: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
9543: '<option value=""'.$default.'></option>'."\n";
9544: foreach my $server (sort(keys(%{$servers}))) {
9545: if (ref($currbalancer) eq 'HASH') {
9546: next if (exists($currbalancer->{$server}));
9547: }
1.150 raeburn 9548: my $selected;
1.171 raeburn 9549: if ($server eq $current) {
1.150 raeburn 9550: $selected = ' selected="selected"';
9551: }
1.171 raeburn 9552: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 9553: }
9554: $extra .= '</select>';
9555: }
9556: } elsif ($rule eq $current) {
9557: $checked = ' checked="checked"';
9558: }
9559: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 9560: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
9561: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
9562: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 9563: ')"'.$checked.' /> ';
9564: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
9565: $output .= $ruletitles{'particular'};
9566: } else {
9567: $output .= $ruletitles{$rulenames[$i]};
9568: }
9569: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 9570: }
9571: $output .= '</div></td></tr>'."\n";
9572: return $output;
9573: }
9574:
9575: sub offloadtype_text {
9576: my %ruletitles = &Apache::lonlocal::texthash (
9577: 'default' => 'Offloads to default destinations',
9578: 'homeserver' => "Offloads to user's home server",
9579: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
9580: 'specific' => 'Offloads to specific server',
1.161 raeburn 9581: 'none' => 'No offload',
1.209 raeburn 9582: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
9583: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 9584: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 9585: );
9586: return %ruletitles;
9587: }
9588:
9589: sub sparestype_titles {
9590: my %typestitles = &Apache::lonlocal::texthash (
9591: 'primary' => 'primary',
9592: 'default' => 'default',
9593: );
9594: return %typestitles;
9595: }
9596:
1.28 raeburn 9597: sub contact_titles {
9598: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 9599: 'supportemail' => 'Support E-mail address',
9600: 'adminemail' => 'Default Server Admin E-mail address',
9601: 'errormail' => 'Error reports to be e-mailed to',
9602: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 9603: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
9604: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 9605: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
9606: 'requestsmail' => 'E-mail from course requests requiring approval',
9607: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 9608: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350 raeburn 9609: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.378 raeburn 9610: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
9611: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.340 raeburn 9612: 'errorweights' => 'Weights used to compute error count',
9613: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 9614: );
9615: my %short_titles = &Apache::lonlocal::texthash (
9616: adminemail => 'Admin E-mail address',
9617: supportemail => 'Support E-mail',
9618: );
9619: return (\%titles,\%short_titles);
9620: }
9621:
1.286 raeburn 9622: sub helpform_fields {
9623: my %titles = &Apache::lonlocal::texthash (
9624: 'username' => 'Name',
9625: 'user' => 'Username/domain',
9626: 'phone' => 'Phone',
9627: 'cc' => 'Cc e-mail',
9628: 'course' => 'Course Details',
9629: 'section' => 'Sections',
1.289 raeburn 9630: 'screenshot' => 'File upload',
1.286 raeburn 9631: );
9632: my @fields = ('username','phone','user','course','section','cc','screenshot');
9633: my %possoptions = (
9634: username => ['yes','no','req'],
1.289 raeburn 9635: phone => ['yes','no','req'],
1.286 raeburn 9636: user => ['yes','no'],
1.289 raeburn 9637: cc => ['yes','no'],
1.286 raeburn 9638: course => ['yes','no'],
9639: section => ['yes','no'],
9640: screenshot => ['yes','no'],
9641: );
9642: my %fieldoptions = &Apache::lonlocal::texthash (
9643: 'yes' => 'Optional',
9644: 'req' => 'Required',
9645: 'no' => "Not shown",
9646: );
9647: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
9648: }
9649:
1.72 raeburn 9650: sub tool_titles {
9651: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 9652: aboutme => 'Personal web page',
1.86 raeburn 9653: blog => 'Blog',
9654: portfolio => 'Portfolio',
1.430 raeburn 9655: portaccess => 'Share portfolio files',
1.413 raeburn 9656: timezone => 'Can set time zone',
1.88 bisitz 9657: official => 'Official courses (with institutional codes)',
9658: unofficial => 'Unofficial courses',
1.98 raeburn 9659: community => 'Communities',
1.216 raeburn 9660: textbook => 'Textbook courses',
1.271 raeburn 9661: placement => 'Placement tests',
1.86 raeburn 9662: );
1.72 raeburn 9663: return %titles;
9664: }
9665:
1.101 raeburn 9666: sub courserequest_titles {
9667: my %titles = &Apache::lonlocal::texthash (
9668: official => 'Official',
9669: unofficial => 'Unofficial',
9670: community => 'Communities',
1.216 raeburn 9671: textbook => 'Textbook',
1.271 raeburn 9672: placement => 'Placement tests',
1.325 raeburn 9673: lti => 'LTI Provider',
1.101 raeburn 9674: norequest => 'Not allowed',
1.325 raeburn 9675: approval => 'Approval by DC',
1.101 raeburn 9676: validate => 'With validation',
9677: autolimit => 'Numerical limit',
1.103 raeburn 9678: unlimited => '(blank for unlimited)',
1.101 raeburn 9679: );
9680: return %titles;
9681: }
9682:
1.163 raeburn 9683: sub authorrequest_titles {
9684: my %titles = &Apache::lonlocal::texthash (
9685: norequest => 'Not allowed',
9686: approval => 'Approval by Dom. Coord.',
9687: automatic => 'Automatic approval',
9688: );
9689: return %titles;
1.210 raeburn 9690: }
1.163 raeburn 9691:
1.101 raeburn 9692: sub courserequest_conditions {
9693: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 9694: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 9695: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 9696: );
9697: return %conditions;
9698: }
9699:
9700:
1.27 raeburn 9701: sub print_usercreation {
1.30 raeburn 9702: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 9703: my $numinrow = 4;
1.28 raeburn 9704: my $datatable;
9705: if ($position eq 'top') {
1.30 raeburn 9706: $$rowtotal ++;
1.34 raeburn 9707: my $rowcount = 0;
1.32 raeburn 9708: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 9709: if (ref($rules) eq 'HASH') {
9710: if (keys(%{$rules}) > 0) {
1.32 raeburn 9711: $datatable .= &user_formats_row('username',$settings,$rules,
9712: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 9713: $$rowtotal ++;
1.32 raeburn 9714: $rowcount ++;
9715: }
9716: }
9717: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
9718: if (ref($idrules) eq 'HASH') {
9719: if (keys(%{$idrules}) > 0) {
9720: $datatable .= &user_formats_row('id',$settings,$idrules,
9721: $idruleorder,$numinrow,$rowcount);
9722: $$rowtotal ++;
9723: $rowcount ++;
1.28 raeburn 9724: }
9725: }
1.39 raeburn 9726: if ($rowcount == 0) {
9727: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
9728: $$rowtotal ++;
9729: $rowcount ++;
9730: }
1.34 raeburn 9731: } elsif ($position eq 'middle') {
1.224 raeburn 9732: my @creators = ('author','course','requestcrs');
1.37 raeburn 9733: my ($rules,$ruleorder) =
9734: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 9735: my %lt = &usercreation_types();
9736: my %checked;
9737: if (ref($settings) eq 'HASH') {
9738: if (ref($settings->{'cancreate'}) eq 'HASH') {
9739: foreach my $item (@creators) {
9740: $checked{$item} = $settings->{'cancreate'}{$item};
9741: }
9742: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
9743: foreach my $item (@creators) {
9744: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
9745: $checked{$item} = 'none';
9746: }
9747: }
9748: }
9749: }
9750: my $rownum = 0;
9751: foreach my $item (@creators) {
9752: $rownum ++;
1.224 raeburn 9753: if ($checked{$item} eq '') {
9754: $checked{$item} = 'any';
1.34 raeburn 9755: }
9756: my $css_class;
9757: if ($rownum%2) {
9758: $css_class = '';
9759: } else {
9760: $css_class = ' class="LC_odd_row" ';
9761: }
9762: $datatable .= '<tr'.$css_class.'>'.
9763: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 9764: '</span></td><td style="text-align: right">';
1.224 raeburn 9765: my @options = ('any');
9766: if (ref($rules) eq 'HASH') {
9767: if (keys(%{$rules}) > 0) {
9768: push(@options,('official','unofficial'));
1.37 raeburn 9769: }
9770: }
1.224 raeburn 9771: push(@options,'none');
1.37 raeburn 9772: foreach my $option (@options) {
1.50 raeburn 9773: my $type = 'radio';
1.34 raeburn 9774: my $check = ' ';
1.224 raeburn 9775: if ($checked{$item} eq $option) {
9776: $check = ' checked="checked" ';
1.34 raeburn 9777: }
9778: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 9779: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 9780: $item.'" value="'.$option.'"'.$check.'/> '.
9781: $lt{$option}.'</label> </span>';
9782: }
9783: $datatable .= '</td></tr>';
9784: }
1.28 raeburn 9785: } else {
9786: my @contexts = ('author','course','domain');
1.325 raeburn 9787: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 9788: my %checked;
9789: if (ref($settings) eq 'HASH') {
9790: if (ref($settings->{'authtypes'}) eq 'HASH') {
9791: foreach my $item (@contexts) {
9792: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
9793: foreach my $auth (@authtypes) {
9794: if ($settings->{'authtypes'}{$item}{$auth}) {
9795: $checked{$item}{$auth} = ' checked="checked" ';
9796: }
9797: }
9798: }
9799: }
1.27 raeburn 9800: }
1.35 raeburn 9801: } else {
9802: foreach my $item (@contexts) {
1.36 raeburn 9803: foreach my $auth (@authtypes) {
1.35 raeburn 9804: $checked{$item}{$auth} = ' checked="checked" ';
9805: }
9806: }
1.27 raeburn 9807: }
1.28 raeburn 9808: my %title = &context_names();
9809: my %authname = &authtype_names();
9810: my $rownum = 0;
9811: my $css_class;
9812: foreach my $item (@contexts) {
9813: if ($rownum%2) {
9814: $css_class = '';
9815: } else {
9816: $css_class = ' class="LC_odd_row" ';
9817: }
1.30 raeburn 9818: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 9819: '<td>'.$title{$item}.
9820: '</td><td class="LC_left_item">'.
9821: '<span class="LC_nobreak">';
9822: foreach my $auth (@authtypes) {
9823: $datatable .= '<label>'.
9824: '<input type="checkbox" name="'.$item.'_auth" '.
9825: $checked{$item}{$auth}.' value="'.$auth.'" />'.
9826: $authname{$auth}.'</label> ';
9827: }
9828: $datatable .= '</span></td></tr>';
9829: $rownum ++;
1.27 raeburn 9830: }
1.30 raeburn 9831: $$rowtotal += $rownum;
1.27 raeburn 9832: }
9833: return $datatable;
9834: }
9835:
1.224 raeburn 9836: sub print_selfcreation {
9837: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 9838: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
9839: $emaildomain,$datatable);
1.224 raeburn 9840: if (ref($settings) eq 'HASH') {
9841: if (ref($settings->{'cancreate'}) eq 'HASH') {
9842: $createsettings = $settings->{'cancreate'};
1.236 raeburn 9843: if (ref($createsettings) eq 'HASH') {
9844: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
9845: @selfcreate = @{$createsettings->{'selfcreate'}};
9846: } elsif ($createsettings->{'selfcreate'} ne '') {
9847: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
9848: @selfcreate = ('email','login','sso');
9849: } elsif ($createsettings->{'selfcreate'} ne 'none') {
9850: @selfcreate = ($createsettings->{'selfcreate'});
9851: }
9852: }
9853: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
9854: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 9855: }
1.305 raeburn 9856: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
9857: $emailoptions = $createsettings->{'emailoptions'};
9858: }
1.303 raeburn 9859: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
9860: $emailverified = $createsettings->{'emailverified'};
9861: }
9862: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
9863: $emaildomain = $createsettings->{'emaildomain'};
9864: }
1.224 raeburn 9865: }
9866: }
9867: }
9868: my %radiohash;
9869: my $numinrow = 4;
9870: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 9871: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 9872: if ($position eq 'top') {
9873: my %choices = &Apache::lonlocal::texthash (
9874: cancreate_login => 'Institutional Login',
9875: cancreate_sso => 'Institutional Single Sign On',
9876: );
9877: my @toggles = sort(keys(%choices));
9878: my %defaultchecked = (
9879: 'cancreate_login' => 'off',
9880: 'cancreate_sso' => 'off',
9881: );
1.228 raeburn 9882: my ($onclick,$itemcount);
1.224 raeburn 9883: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
9884: \%choices,$itemcount,$onclick);
1.228 raeburn 9885: $$rowtotal += $itemcount;
1.425 raeburn 9886:
1.224 raeburn 9887: if (ref($usertypes) eq 'HASH') {
9888: if (keys(%{$usertypes}) > 0) {
9889: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
9890: $dom,$numinrow,$othertitle,
1.305 raeburn 9891: 'statustocreate',$rowtotal);
1.224 raeburn 9892: $$rowtotal ++;
9893: }
9894: }
1.240 raeburn 9895: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
9896: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9897: $fieldtitles{'inststatus'} = &mt('Institutional status');
9898: my $rem;
9899: my $numperrow = 2;
9900: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
9901: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 9902: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 9903: '<td class="LC_left_item">'."\n".
1.334 raeburn 9904: '<table>'."\n";
1.240 raeburn 9905: for (my $i=0; $i<@fields; $i++) {
9906: $rem = $i%($numperrow);
9907: if ($rem == 0) {
9908: if ($i > 0) {
9909: $datatable .= '</tr>';
9910: }
9911: $datatable .= '<tr>';
9912: }
9913: my $currval;
1.248 raeburn 9914: if (ref($createsettings) eq 'HASH') {
9915: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
9916: $currval = $createsettings->{'shibenv'}{$fields[$i]};
9917: }
1.240 raeburn 9918: }
9919: $datatable .= '<td class="LC_left_item">'.
9920: '<span class="LC_nobreak">'.
9921: '<input type="text" name="shibenv_'.$fields[$i].'" '.
9922: 'value="'.$currval.'" size="10" /> '.
9923: $fieldtitles{$fields[$i]}.'</span></td>';
9924: }
9925: my $colsleft = $numperrow - $rem;
9926: if ($colsleft > 1 ) {
9927: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9928: ' </td>';
9929: } elsif ($colsleft == 1) {
9930: $datatable .= '<td class="LC_left_item"> </td>';
9931: }
9932: $datatable .= '</tr></table></td></tr>';
9933: $$rowtotal ++;
1.224 raeburn 9934: } elsif ($position eq 'middle') {
9935: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 9936: my @posstypes;
1.224 raeburn 9937: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9938: @posstypes = @{$types};
9939: }
9940: unless (grep(/^default$/,@posstypes)) {
9941: push(@posstypes,'default');
9942: }
9943: my %usertypeshash;
9944: if (ref($usertypes) eq 'HASH') {
9945: %usertypeshash = %{$usertypes};
9946: }
9947: $usertypeshash{'default'} = $othertitle;
9948: foreach my $status (@posstypes) {
9949: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
9950: $numinrow,$$rowtotal,\%usertypeshash);
9951: $$rowtotal ++;
1.224 raeburn 9952: }
9953: } else {
1.236 raeburn 9954: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 9955: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 9956: );
9957: my @toggles = sort(keys(%choices));
9958: my %defaultchecked = (
9959: 'cancreate_email' => 'off',
9960: );
1.305 raeburn 9961: my $customclass = 'LC_selfcreate_email';
9962: my $classprefix = 'LC_canmodify_emailusername_';
9963: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 9964: my $display = 'none';
1.305 raeburn 9965: my $rowstyle = 'display:none';
1.236 raeburn 9966: if (grep(/^\Qemail\E$/,@selfcreate)) {
9967: $display = 'block';
1.305 raeburn 9968: $rowstyle = 'display:table-row';
1.236 raeburn 9969: }
1.305 raeburn 9970: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
9971: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
9972: \%choices,$$rowtotal,$onclick);
9973: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
9974: $rowstyle);
9975: $$rowtotal ++;
9976: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
9977: $rowstyle);
9978: $$rowtotal ++;
9979: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 9980: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 9981: my ($emailrules,$emailruleorder) =
9982: &Apache::lonnet::inst_userrules($dom,'email');
9983: my $primary_id = &Apache::lonnet::domain($dom,'primary');
9984: my $intdom = &Apache::lonnet::internet_dom($primary_id);
9985: if (ref($types) eq 'ARRAY') {
9986: @posstypes = @{$types};
9987: }
9988: if (@posstypes) {
9989: unless (grep(/^default$/,@posstypes)) {
9990: push(@posstypes,'default');
1.302 raeburn 9991: }
9992: if (ref($usertypes) eq 'HASH') {
9993: %usertypeshash = %{$usertypes};
9994: }
1.305 raeburn 9995: my $currassign;
9996: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
9997: $currassign = {
9998: selfassign => $domdefaults{'inststatusguest'},
9999: };
10000: @ordered = @{$domdefaults{'inststatusguest'}};
10001: } else {
10002: $currassign = { selfassign => [] };
10003: }
10004: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
10005: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
10006: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
10007: $numinrow,$othertitle,'selfassign',
10008: $rowtotal,$onclicktypes,$customclass,
10009: $rowstyle);
10010: $$rowtotal ++;
1.302 raeburn 10011: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10012: foreach my $status (@posstypes) {
10013: my $css_class;
10014: if ($$rowtotal%2) {
10015: $css_class = 'LC_odd_row ';
10016: }
10017: $css_class .= $customclass;
10018: my $rowid = $optionsprefix.$status;
10019: my $hidden = 1;
10020: my $currstyle = 'display:none';
10021: if (grep(/^\Q$status\E$/,@ordered)) {
10022: $currstyle = $rowstyle;
1.425 raeburn 10023: $hidden = 0;
1.305 raeburn 10024: }
10025: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10026: $emailrules,$emailruleorder,$settings,$status,$rowid,
10027: $usertypeshash{$status},$css_class,$currstyle,$intdom);
10028: unless ($hidden) {
10029: $$rowtotal ++;
10030: }
1.224 raeburn 10031: }
1.302 raeburn 10032: } else {
1.305 raeburn 10033: my $css_class;
10034: if ($$rowtotal%2) {
10035: $css_class = 'LC_odd_row ';
10036: }
10037: $css_class .= $customclass;
1.302 raeburn 10038: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10039: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10040: $emailrules,$emailruleorder,$settings,'default','',
10041: $othertitle,$css_class,$rowstyle,$intdom);
10042: $$rowtotal ++;
1.224 raeburn 10043: }
10044: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 10045: $numinrow = 1;
1.305 raeburn 10046: if (@posstypes) {
10047: foreach my $status (@posstypes) {
10048: my $rowid = $classprefix.$status;
10049: my $datarowstyle = 'display:none';
1.425 raeburn 10050: if (grep(/^\Q$status\E$/,@ordered)) {
10051: $datarowstyle = $rowstyle;
1.305 raeburn 10052: }
10053: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
10054: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10055: $infotitles,$rowid,$customclass,$datarowstyle);
10056: unless ($datarowstyle eq 'display:none') {
10057: $$rowtotal ++;
10058: }
1.224 raeburn 10059: }
1.305 raeburn 10060: } else {
10061: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
10062: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10063: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 10064: }
10065: }
10066: return $datatable;
10067: }
10068:
1.305 raeburn 10069: sub selfcreate_javascript {
10070: return <<"ENDSCRIPT";
10071:
10072: <script type="text/javascript">
10073: // <![CDATA[
10074:
10075: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
10076: var x = document.getElementsByClassName(target);
10077: var insttypes = 0;
10078: var insttypeRegExp = new RegExp(prefix);
10079: if ((x.length != undefined) && (x.length > 0)) {
10080: if (form.elements[radio].length != undefined) {
10081: for (var i=0; i<form.elements[radio].length; i++) {
10082: if (form.elements[radio][i].checked) {
10083: if (form.elements[radio][i].value == 1) {
10084: for (var j=0; j<x.length; j++) {
10085: if (x[j].id == 'undefined') {
10086: x[j].style.display = 'table-row';
10087: } else if (insttypeRegExp.test(x[j].id)) {
10088: insttypes ++;
10089: } else {
10090: x[j].style.display = 'table-row';
10091: }
10092: }
10093: } else {
10094: for (var j=0; j<x.length; j++) {
10095: x[j].style.display = 'none';
10096: }
1.236 raeburn 10097: }
1.305 raeburn 10098: break;
10099: }
10100: }
10101: if (insttypes > 0) {
10102: toggleDataRow(form,checkbox,target,altprefix);
10103: toggleDataRow(form,checkbox,target,prefix,1);
10104: }
10105: }
10106: }
10107: return;
10108: }
10109:
10110: function toggleDataRow(form,checkbox,target,prefix,docount) {
10111: if (form.elements[checkbox].length != undefined) {
10112: var count = 0;
10113: if (docount) {
10114: for (var i=0; i<form.elements[checkbox].length; i++) {
10115: if (form.elements[checkbox][i].checked) {
10116: count ++;
1.236 raeburn 10117: }
1.305 raeburn 10118: }
10119: }
10120: for (var i=0; i<form.elements[checkbox].length; i++) {
10121: var type = form.elements[checkbox][i].value;
10122: if (document.getElementById(prefix+type)) {
10123: if (form.elements[checkbox][i].checked) {
10124: document.getElementById(prefix+type).style.display = 'table-row';
10125: if (count % 2 == 1) {
10126: document.getElementById(prefix+type).className = target+' LC_odd_row';
10127: } else {
10128: document.getElementById(prefix+type).className = target;
1.236 raeburn 10129: }
1.305 raeburn 10130: count ++;
1.236 raeburn 10131: } else {
1.305 raeburn 10132: document.getElementById(prefix+type).style.display = 'none';
10133: }
10134: }
10135: }
10136: }
10137: return;
10138: }
10139:
10140: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
10141: var caller = radio+'_'+status;
10142: if (form.elements[caller].length != undefined) {
10143: for (var i=0; i<form.elements[caller].length; i++) {
10144: if (form.elements[caller][i].checked) {
10145: if (document.getElementById(altprefix+'_inst_'+status)) {
10146: var curr = form.elements[caller][i].value;
10147: if (prefix) {
10148: document.getElementById(prefix+'_'+status).style.display = 'none';
10149: }
10150: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
10151: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
10152: if (curr == 'custom') {
1.425 raeburn 10153: if (prefix) {
1.305 raeburn 10154: document.getElementById(prefix+'_'+status).style.display = 'inline';
10155: }
10156: } else if (curr == 'inst') {
10157: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
10158: } else if (curr == 'noninst') {
10159: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 10160: }
1.305 raeburn 10161: break;
1.236 raeburn 10162: }
10163: }
10164: }
10165: }
10166: }
10167:
1.305 raeburn 10168: // ]]>
10169: </script>
10170:
10171: ENDSCRIPT
10172: }
10173:
10174: sub noninst_users {
10175: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
1.425 raeburn 10176: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
1.305 raeburn 10177: my $class = 'LC_left_item';
10178: if ($css_class) {
1.425 raeburn 10179: $css_class = ' class="'.$css_class.'"';
1.305 raeburn 10180: }
10181: if ($rowid) {
10182: $rowid = ' id="'.$rowid.'"';
10183: }
10184: if ($rowstyle) {
10185: $rowstyle = ' style="'.$rowstyle.'"';
10186: }
10187: my ($output,$description);
10188: if ($type eq 'default') {
10189: $description = &mt('Requests for: [_1]',$typetitle);
10190: } else {
10191: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
10192: }
10193: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
1.425 raeburn 10194: "<td>$description</td>\n".
1.305 raeburn 10195: '<td class="'.$class.'" colspan="2">'.
10196: '<table><tr>';
1.425 raeburn 10197: my %headers = &Apache::lonlocal::texthash(
1.305 raeburn 10198: approve => 'Processing',
10199: email => 'E-mail',
10200: username => 'Username',
10201: );
10202: foreach my $item ('approve','email','username') {
10203: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 10204: }
1.305 raeburn 10205: $output .= '</tr><tr>';
10206: foreach my $item ('approve','email','username') {
1.306 raeburn 10207: $output .= '<td style="vertical-align: top">';
1.305 raeburn 10208: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
10209: if ($item eq 'approve') {
10210: %choices = &Apache::lonlocal::texthash (
10211: automatic => 'Automatically approved',
10212: approval => 'Queued for approval',
10213: );
10214: @options = ('automatic','approval');
10215: $hashref = $processing;
10216: $defoption = 'automatic';
10217: $name = 'cancreate_emailprocess_'.$type;
10218: } elsif ($item eq 'email') {
10219: %choices = &Apache::lonlocal::texthash (
10220: any => 'Any e-mail',
10221: inst => 'Institutional only',
10222: noninst => 'Non-institutional only',
10223: custom => 'Custom restrictions',
10224: );
10225: @options = ('any','inst','noninst');
10226: my $showcustom;
10227: if (ref($emailrules) eq 'HASH') {
10228: if (keys(%{$emailrules}) > 0) {
10229: push(@options,'custom');
10230: $showcustom = 'cancreate_emailrule';
10231: if (ref($settings) eq 'HASH') {
10232: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
10233: foreach my $rule (@{$settings->{'email_rule'}}) {
10234: if (exists($emailrules->{$rule})) {
10235: $hascustom ++;
10236: }
10237: }
10238: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
10239: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
10240: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
10241: if (exists($emailrules->{$rule})) {
10242: $hascustom ++;
10243: }
10244: }
10245: }
10246: }
10247: }
10248: }
10249: }
10250: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
10251: "'cancreate_emaildomain','$type'".');"';
10252: $hashref = $emailoptions;
10253: $defoption = 'any';
10254: $name = 'cancreate_emailoptions_'.$type;
10255: } elsif ($item eq 'username') {
10256: %choices = &Apache::lonlocal::texthash (
10257: all => 'Same as e-mail',
10258: first => 'Omit @domain',
10259: free => 'Free to choose',
10260: );
10261: @options = ('all','first','free');
10262: $hashref = $emailverified;
10263: $defoption = 'all';
10264: $name = 'cancreate_usernameoptions_'.$type;
10265: }
10266: foreach my $option (@options) {
10267: my $checked;
10268: if (ref($hashref) eq 'HASH') {
10269: if ($type eq '') {
10270: if (!exists($hashref->{'default'})) {
10271: if ($option eq $defoption) {
10272: $checked = ' checked="checked"';
10273: }
10274: } else {
10275: if ($hashref->{'default'} eq $option) {
10276: $checked = ' checked="checked"';
10277: }
1.303 raeburn 10278: }
10279: } else {
1.305 raeburn 10280: if (!exists($hashref->{$type})) {
10281: if ($option eq $defoption) {
10282: $checked = ' checked="checked"';
10283: }
10284: } else {
10285: if ($hashref->{$type} eq $option) {
10286: $checked = ' checked="checked"';
10287: }
1.303 raeburn 10288: }
10289: }
1.305 raeburn 10290: } elsif (($item eq 'email') && ($hascustom)) {
10291: if ($option eq 'custom') {
10292: $checked = ' checked="checked"';
10293: }
10294: } elsif ($option eq $defoption) {
10295: $checked = ' checked="checked"';
10296: }
10297: $output .= '<span class="LC_nobreak"><label>'.
10298: '<input type="radio" name="'.$name.'"'.
10299: $checked.' value="'.$option.'"'.$onclick.' />'.
10300: $choices{$option}.'</label></span><br />';
10301: if ($item eq 'email') {
10302: if ($option eq 'custom') {
10303: my $id = 'cancreate_emailrule_'.$type;
10304: my $display = 'none';
10305: if ($checked) {
10306: $display = 'inline';
1.303 raeburn 10307: }
1.305 raeburn 10308: my $numinrow = 2;
10309: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
10310: '<legend>'.&mt('Disallow').'</legend><table>'.
10311: &user_formats_row('email',$settings,$emailrules,
10312: $emailruleorder,$numinrow,'',$type);
10313: '</table></fieldset>';
10314: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
10315: my %text = &Apache::lonlocal::texthash (
10316: inst => 'must end:',
10317: noninst => 'cannot end:',
10318: );
10319: my $value;
10320: if (ref($emaildomain) eq 'HASH') {
10321: if (ref($emaildomain->{$type}) eq 'HASH') {
1.425 raeburn 10322: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 10323: }
10324: }
1.305 raeburn 10325: if ($value eq '') {
10326: $value = '@'.$intdom;
10327: }
10328: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
10329: my $display = 'none';
10330: if ($checked) {
10331: $display = 'inline';
10332: }
10333: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
10334: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
10335: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
10336: '</div>';
1.303 raeburn 10337: }
10338: }
10339: }
1.305 raeburn 10340: $output .= '</td>'."\n";
1.303 raeburn 10341: }
1.305 raeburn 10342: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 10343: return $output;
10344: }
10345:
1.165 raeburn 10346: sub captcha_choice {
1.305 raeburn 10347: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 10348: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
10349: $vertext,$currver);
1.165 raeburn 10350: my %lt = &captcha_phrases();
10351: $keyentry = 'hidden';
1.354 raeburn 10352: my $colspan=2;
1.165 raeburn 10353: if ($context eq 'cancreate') {
1.224 raeburn 10354: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 10355: } elsif ($context eq 'login') {
10356: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.354 raeburn 10357: } elsif ($context eq 'passwords') {
10358: $rowname = &mt('"Forgot Password" CAPTCHA validation');
10359: $colspan=1;
1.165 raeburn 10360: }
10361: if (ref($settings) eq 'HASH') {
10362: if ($settings->{'captcha'}) {
10363: $checked{$settings->{'captcha'}} = ' checked="checked"';
10364: } else {
10365: $checked{'original'} = ' checked="checked"';
10366: }
10367: if ($settings->{'captcha'} eq 'recaptcha') {
10368: $pubtext = $lt{'pub'};
10369: $privtext = $lt{'priv'};
10370: $keyentry = 'text';
1.269 raeburn 10371: $vertext = $lt{'ver'};
10372: $currver = $settings->{'recaptchaversion'};
10373: if ($currver ne '2') {
10374: $currver = 1;
10375: }
1.165 raeburn 10376: }
10377: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
10378: $currpub = $settings->{'recaptchakeys'}{'public'};
10379: $currpriv = $settings->{'recaptchakeys'}{'private'};
10380: }
10381: } else {
10382: $checked{'original'} = ' checked="checked"';
10383: }
1.305 raeburn 10384: my $css_class;
10385: if ($itemcount%2) {
10386: $css_class = 'LC_odd_row';
10387: }
10388: if ($customcss) {
10389: $css_class .= " $customcss";
10390: }
10391: $css_class =~ s/^\s+//;
10392: if ($css_class) {
10393: $css_class = ' class="'.$css_class.'"';
10394: }
10395: if ($rowstyle) {
10396: $css_class .= ' style="'.$rowstyle.'"';
10397: }
1.169 raeburn 10398: my $output = '<tr'.$css_class.'>'.
1.354 raeburn 10399: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165 raeburn 10400: '<table><tr><td>'."\n";
10401: foreach my $option ('original','recaptcha','notused') {
10402: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
10403: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
10404: $lt{$option}.'</label></span>';
10405: unless ($option eq 'notused') {
10406: $output .= (' 'x2)."\n";
10407: }
10408: }
10409: #
10410: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
10411: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 10412: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 10413: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 10414: #
1.165 raeburn 10415: $output .= '</td></tr>'."\n".
1.305 raeburn 10416: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 10417: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
10418: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
10419: $currpub.'" size="40" /></span><br />'."\n".
10420: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
10421: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 10422: $currpriv.'" size="40" /></span><br />'.
10423: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
10424: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
10425: $currver.'" size="3" /></span><br />'.
10426: '</td></tr></table>'."\n".
1.165 raeburn 10427: '</td></tr>';
10428: return $output;
10429: }
10430:
1.32 raeburn 10431: sub user_formats_row {
1.305 raeburn 10432: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 10433: my $output;
10434: my %text = (
10435: 'username' => 'new usernames',
10436: 'id' => 'IDs',
10437: );
1.409 raeburn 10438: unless (($type eq 'email') || ($type eq 'unamemap')) {
1.305 raeburn 10439: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
10440: $output = '<tr '.$css_class.'>'.
10441: '<td><span class="LC_nobreak">'.
10442: &mt("Format rules to check for $text{$type}: ").
10443: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 10444: }
1.27 raeburn 10445: my $rem;
10446: if (ref($ruleorder) eq 'ARRAY') {
10447: for (my $i=0; $i<@{$ruleorder}; $i++) {
10448: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
10449: my $rem = $i%($numinrow);
10450: if ($rem == 0) {
10451: if ($i > 0) {
10452: $output .= '</tr>';
10453: }
10454: $output .= '<tr>';
10455: }
10456: my $check = ' ';
1.39 raeburn 10457: if (ref($settings) eq 'HASH') {
10458: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
10459: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
10460: $check = ' checked="checked" ';
10461: }
1.305 raeburn 10462: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
10463: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
10464: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
10465: $check = ' checked="checked" ';
10466: }
10467: }
1.27 raeburn 10468: }
10469: }
1.305 raeburn 10470: my $name = $type.'_rule';
10471: if ($type eq 'email') {
10472: $name .= '_'.$status;
10473: }
1.27 raeburn 10474: $output .= '<td class="LC_left_item">'.
10475: '<span class="LC_nobreak"><label>'.
1.311 raeburn 10476: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 10477: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
10478: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
10479: }
10480: }
10481: $rem = @{$ruleorder}%($numinrow);
10482: }
1.305 raeburn 10483: my $colsleft;
10484: if ($rem) {
10485: $colsleft = $numinrow - $rem;
10486: }
1.27 raeburn 10487: if ($colsleft > 1 ) {
10488: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10489: ' </td>';
10490: } elsif ($colsleft == 1) {
10491: $output .= '<td class="LC_left_item"> </td>';
10492: }
1.409 raeburn 10493: $output .= '</tr>';
10494: unless (($type eq 'email') || ($type eq 'unamemap')) {
10495: $output .= '</table></td></tr>';
1.305 raeburn 10496: }
1.27 raeburn 10497: return $output;
10498: }
10499:
1.34 raeburn 10500: sub usercreation_types {
10501: my %lt = &Apache::lonlocal::texthash (
10502: author => 'When adding a co-author',
10503: course => 'When adding a user to a course',
1.100 raeburn 10504: requestcrs => 'When requesting a course',
1.34 raeburn 10505: any => 'Any',
10506: official => 'Institutional only ',
10507: unofficial => 'Non-institutional only',
10508: none => 'None',
10509: );
10510: return %lt;
1.48 raeburn 10511: }
1.34 raeburn 10512:
1.224 raeburn 10513: sub selfcreation_types {
10514: my %lt = &Apache::lonlocal::texthash (
10515: selfcreate => 'User creates own account',
10516: any => 'Any',
10517: official => 'Institutional only ',
10518: unofficial => 'Non-institutional only',
10519: email => 'E-mail address',
10520: login => 'Institutional Login',
10521: sso => 'SSO',
10522: );
10523: }
10524:
1.28 raeburn 10525: sub authtype_names {
10526: my %lt = &Apache::lonlocal::texthash(
10527: int => 'Internal',
10528: krb4 => 'Kerberos 4',
10529: krb5 => 'Kerberos 5',
10530: loc => 'Local',
1.325 raeburn 10531: lti => 'LTI',
1.28 raeburn 10532: );
10533: return %lt;
10534: }
10535:
10536: sub context_names {
10537: my %context_title = &Apache::lonlocal::texthash(
10538: author => 'Creating users when an Author',
10539: course => 'Creating users when in a course',
10540: domain => 'Creating users when a Domain Coordinator',
10541: );
10542: return %context_title;
10543: }
10544:
1.33 raeburn 10545: sub print_usermodification {
10546: my ($position,$dom,$settings,$rowtotal) = @_;
10547: my $numinrow = 4;
10548: my ($context,$datatable,$rowcount);
10549: if ($position eq 'top') {
10550: $rowcount = 0;
10551: $context = 'author';
10552: foreach my $role ('ca','aa') {
10553: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10554: $numinrow,$rowcount);
10555: $$rowtotal ++;
10556: $rowcount ++;
10557: }
1.230 raeburn 10558: } elsif ($position eq 'bottom') {
1.33 raeburn 10559: $context = 'course';
10560: $rowcount = 0;
10561: foreach my $role ('st','ep','ta','in','cr') {
10562: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10563: $numinrow,$rowcount);
10564: $$rowtotal ++;
10565: $rowcount ++;
10566: }
10567: }
10568: return $datatable;
10569: }
10570:
1.43 raeburn 10571: sub print_defaults {
1.236 raeburn 10572: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 10573: my $rownum = 0;
1.294 raeburn 10574: my ($datatable,$css_class,$titles);
10575: unless ($position eq 'bottom') {
10576: $titles = &defaults_titles($dom);
10577: }
1.236 raeburn 10578: if ($position eq 'top') {
10579: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
10580: 'datelocale_def','portal_def');
10581: my %defaults;
10582: if (ref($settings) eq 'HASH') {
10583: %defaults = %{$settings};
1.43 raeburn 10584: } else {
1.236 raeburn 10585: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10586: foreach my $item (@items) {
10587: $defaults{$item} = $domdefaults{$item};
10588: }
1.43 raeburn 10589: }
1.236 raeburn 10590: foreach my $item (@items) {
10591: if ($rownum%2) {
10592: $css_class = '';
10593: } else {
10594: $css_class = ' class="LC_odd_row" ';
10595: }
10596: $datatable .= '<tr'.$css_class.'>'.
10597: '<td><span class="LC_nobreak">'.$titles->{$item}.
10598: '</span></td><td class="LC_right_item" colspan="3">';
10599: if ($item eq 'auth_def') {
1.325 raeburn 10600: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 10601: my %shortauth = (
10602: internal => 'int',
10603: krb4 => 'krb4',
10604: krb5 => 'krb5',
1.325 raeburn 10605: localauth => 'loc',
10606: lti => 'lti',
1.236 raeburn 10607: );
10608: my %authnames = &authtype_names();
10609: foreach my $auth (@authtypes) {
10610: my $checked = ' ';
10611: if ($defaults{$item} eq $auth) {
10612: $checked = ' checked="checked" ';
10613: }
10614: $datatable .= '<label><input type="radio" name="'.$item.
10615: '" value="'.$auth.'"'.$checked.'/>'.
10616: $authnames{$shortauth{$auth}}.'</label> ';
10617: }
10618: } elsif ($item eq 'timezone_def') {
10619: my $includeempty = 1;
10620: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
10621: } elsif ($item eq 'datelocale_def') {
10622: my $includeempty = 1;
10623: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
10624: } elsif ($item eq 'lang_def') {
1.263 raeburn 10625: my $includeempty = 1;
10626: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.414 raeburn 10627: } elsif ($item eq 'portal_def') {
10628: $datatable .= '<input type="text" name="'.$item.'" value="'.
10629: $defaults{$item}.'" size="25" onkeyup="portalExtras(this);" />';
10630: my $portalsty = 'none';
10631: if ($defaults{$item}) {
10632: $portalsty = 'block';
10633: }
10634: foreach my $field ('email','web') {
10635: my $checkedoff = ' checked="checked"';
10636: my $checkedon;
10637: if ($defaults{$item.'_'.$field}) {
10638: $checkedon = $checkedoff;
10639: $checkedoff = '';
1.425 raeburn 10640: }
1.414 raeburn 10641: $datatable .= '<div id="'.$item.'_'.$field.'_div" style="display:'.$portalsty.'">'.
10642: '<span class="LC_nobreak">'.$titles->{$field}.' '.
10643: '<label><input type="radio" name="'.$item.'_'.$field.'" value="1"'.$checkedon.'/>'.&mt('Yes').'</label>'.
10644: (' 'x2).
10645: '<label><input type="radio" name="'.$item.'_'.$field.'" value="0"'.$checkedoff.'/>'.&mt('No').'</label>'.
10646: '</div>';
10647: }
1.236 raeburn 10648: } else {
1.414 raeburn 10649: $datatable .= '<input type="text" name="'.$item.'" value="'.$defaults{$item}.'" />';
1.43 raeburn 10650: }
1.236 raeburn 10651: $datatable .= '</td></tr>';
10652: $rownum ++;
10653: }
1.409 raeburn 10654: } elsif ($position eq 'middle') {
1.294 raeburn 10655: my %defaults;
10656: if (ref($settings) eq 'HASH') {
1.354 raeburn 10657: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
10658: my $maxnum = @{$settings->{'inststatusorder'}};
10659: for (my $i=0; $i<$maxnum; $i++) {
10660: $css_class = $rownum%2?' class="LC_odd_row"':'';
10661: my $item = $settings->{'inststatusorder'}->[$i];
10662: my $title = $settings->{'inststatustypes'}->{$item};
10663: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
10664: $datatable .= '<tr'.$css_class.'>'.
10665: '<td><span class="LC_nobreak">'.
10666: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
10667: for (my $k=0; $k<=$maxnum; $k++) {
10668: my $vpos = $k+1;
10669: my $selstr;
10670: if ($k == $i) {
10671: $selstr = ' selected="selected" ';
10672: }
10673: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10674: }
10675: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
10676: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
10677: &mt('delete').'</span></td>'.
1.380 raeburn 10678: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.354 raeburn 10679: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
10680: '</span></td></tr>';
10681: }
10682: $css_class = $rownum%2?' class="LC_odd_row"':'';
10683: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
10684: $datatable .= '<tr '.$css_class.'>'.
10685: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
10686: for (my $k=0; $k<=$maxnum; $k++) {
10687: my $vpos = $k+1;
10688: my $selstr;
10689: if ($k == $maxnum) {
10690: $selstr = ' selected="selected" ';
10691: }
10692: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10693: }
10694: $datatable .= '</select> '.&mt('Internal ID:').
10695: '<input type="text" size="10" name="addinststatus" value="" />'.
10696: ' '.&mt('(new)').
10697: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.380 raeburn 10698: &mt('Name displayed').':'.
1.354 raeburn 10699: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
10700: '</tr>'."\n";
10701: $rownum ++;
1.294 raeburn 10702: }
1.354 raeburn 10703: }
1.409 raeburn 10704: } else {
10705: my ($unamemaprules,$ruleorder) =
10706: &Apache::lonnet::inst_userrules($dom,'unamemap');
10707: $css_class = $rownum%2?' class="LC_odd_row"':'';
10708: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10709: my $numinrow = 2;
10710: $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
10711: &user_formats_row('unamemap',$settings,$unamemaprules,
10712: $ruleorder,$numinrow).
10713: '</table></td></tr>';
10714: }
10715: if ($datatable eq '') {
10716: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
10717: &mt('No rules set for domain in customized localenroll.pm').
10718: '</td></tr>';
10719: }
1.354 raeburn 10720: }
10721: $$rowtotal += $rownum;
1.43 raeburn 10722: return $datatable;
10723: }
10724:
1.168 raeburn 10725: sub get_languages_hash {
10726: my %langchoices;
10727: foreach my $id (&Apache::loncommon::languageids()) {
10728: my $code = &Apache::loncommon::supportedlanguagecode($id);
10729: if ($code ne '') {
10730: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
10731: }
10732: }
10733: return %langchoices;
10734: }
10735:
1.43 raeburn 10736: sub defaults_titles {
1.141 raeburn 10737: my ($dom) = @_;
1.43 raeburn 10738: my %titles = &Apache::lonlocal::texthash (
10739: 'auth_def' => 'Default authentication type',
10740: 'auth_arg_def' => 'Default authentication argument',
10741: 'lang_def' => 'Default language',
1.54 raeburn 10742: 'timezone_def' => 'Default timezone',
1.68 raeburn 10743: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 10744: 'portal_def' => 'Portal/Default URL',
1.414 raeburn 10745: 'email' => 'Email links use portal URL',
10746: 'web' => 'Public web links use portal URL',
1.294 raeburn 10747: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
10748: 'intauth_check' => 'Check bcrypt cost if authenticated',
10749: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 10750: );
1.141 raeburn 10751: if ($dom) {
10752: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
10753: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
10754: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
10755: $protocol = 'http' if ($protocol ne 'https');
10756: if ($uint_dom) {
10757: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
10758: $uint_dom);
10759: }
10760: }
1.43 raeburn 10761: return (\%titles);
10762: }
10763:
1.346 raeburn 10764: sub print_scantron {
10765: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
10766: if ($position eq 'top') {
10767: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
10768: } else {
10769: return &print_scantronconfig($dom,$settings,\$rowtotal);
10770: }
10771: }
10772:
10773: sub scantron_javascript {
10774: return <<"ENDSCRIPT";
10775:
10776: <script type="text/javascript">
10777: // <![CDATA[
10778:
10779: function toggleScantron(form) {
1.347 raeburn 10780: var csvfieldset = new Array();
1.346 raeburn 10781: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 10782: csvfieldset.push(document.getElementById('scantroncsv_cols'));
10783: }
10784: if (document.getElementById('scantroncsv_options')) {
10785: csvfieldset.push(document.getElementById('scantroncsv_options'));
10786: }
10787: if (csvfieldset.length) {
1.346 raeburn 10788: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 10789: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 10790: if (scantroncsv.checked) {
1.347 raeburn 10791: for (var i=0; i<csvfieldset.length; i++) {
10792: csvfieldset[i].style.display = 'block';
10793: }
1.346 raeburn 10794: } else {
1.347 raeburn 10795: for (var i=0; i<csvfieldset.length; i++) {
10796: csvfieldset[i].style.display = 'none';
10797: }
1.346 raeburn 10798: var csvselects = document.getElementsByClassName('scantronconfig_csv');
10799: if (csvselects.length) {
10800: for (var j=0; j<csvselects.length; j++) {
10801: csvselects[j].selectedIndex = 0;
10802: }
10803: }
10804: }
10805: }
10806: }
10807: return;
10808: }
10809: // ]]>
10810: </script>
10811:
10812: ENDSCRIPT
10813:
10814: }
10815:
1.46 raeburn 10816: sub print_scantronformat {
10817: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
10818: my $itemcount = 1;
1.60 raeburn 10819: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
10820: %confhash);
1.46 raeburn 10821: my $switchserver = &check_switchserver($dom,$confname);
10822: my %lt = &Apache::lonlocal::texthash (
1.95 www 10823: default => 'Default bubblesheet format file error',
10824: custom => 'Custom bubblesheet format file error',
1.46 raeburn 10825: );
10826: my %scantronfiles = (
10827: default => 'default.tab',
10828: custom => 'custom.tab',
10829: );
10830: foreach my $key (keys(%scantronfiles)) {
10831: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
10832: .$scantronfiles{$key};
10833: }
10834: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
10835: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
10836: if (!$switchserver) {
10837: my $servadm = $r->dir_config('lonAdmEMail');
10838: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
10839: if ($configuserok eq 'ok') {
10840: if ($author_ok eq 'ok') {
10841: my %legacyfile = (
1.346 raeburn 10842: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
10843: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 10844: );
10845: my %md5chk;
10846: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 10847: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
10848: chomp($md5chk{$type});
1.46 raeburn 10849: }
10850: if ($md5chk{'default'} ne $md5chk{'custom'}) {
10851: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 10852: ($scantronurls{$type},my $error) =
1.46 raeburn 10853: &legacy_scantronformat($r,$dom,$confname,
10854: $type,$legacyfile{$type},
10855: $scantronurls{$type},
10856: $scantronfiles{$type});
1.60 raeburn 10857: if ($error ne '') {
10858: $error{$type} = $error;
10859: }
10860: }
10861: if (keys(%error) == 0) {
10862: $is_custom = 1;
1.346 raeburn 10863: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 10864: $scantronurls{'custom'};
1.346 raeburn 10865: my $putresult =
1.60 raeburn 10866: &Apache::lonnet::put_dom('configuration',
10867: \%confhash,$dom);
10868: if ($putresult ne 'ok') {
1.346 raeburn 10869: $error{'custom'} =
1.60 raeburn 10870: '<span class="LC_error">'.
10871: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
10872: }
1.46 raeburn 10873: }
10874: } else {
1.60 raeburn 10875: ($scantronurls{'default'},my $error) =
1.46 raeburn 10876: &legacy_scantronformat($r,$dom,$confname,
10877: 'default',$legacyfile{'default'},
10878: $scantronurls{'default'},
10879: $scantronfiles{'default'});
1.60 raeburn 10880: if ($error eq '') {
10881: $confhash{'scantron'}{'scantronformat'} = '';
10882: my $putresult =
10883: &Apache::lonnet::put_dom('configuration',
10884: \%confhash,$dom);
10885: if ($putresult ne 'ok') {
10886: $error{'default'} =
10887: '<span class="LC_error">'.
10888: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
10889: }
10890: } else {
10891: $error{'default'} = $error;
10892: }
1.46 raeburn 10893: }
10894: }
10895: }
10896: } else {
1.95 www 10897: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 10898: }
10899: }
10900: if (ref($settings) eq 'HASH') {
10901: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
10902: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
10903: if ((!@info) || ($info[0] eq 'no_such_dir')) {
10904: $scantronurl = '';
10905: } else {
10906: $scantronurl = $settings->{'scantronformat'};
10907: }
10908: $is_custom = 1;
10909: } else {
10910: $scantronurl = $scantronurls{'default'};
10911: }
10912: } else {
1.60 raeburn 10913: if ($is_custom) {
10914: $scantronurl = $scantronurls{'custom'};
10915: } else {
10916: $scantronurl = $scantronurls{'default'};
10917: }
1.46 raeburn 10918: }
10919: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10920: $datatable .= '<tr'.$css_class.'>';
10921: if (!$is_custom) {
1.65 raeburn 10922: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
10923: '<span class="LC_nobreak">';
1.46 raeburn 10924: if ($scantronurl) {
1.199 raeburn 10925: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
10926: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 10927: } else {
10928: $datatable = &mt('File unavailable for display');
10929: }
1.65 raeburn 10930: $datatable .= '</span></td>';
1.60 raeburn 10931: if (keys(%error) == 0) {
1.306 raeburn 10932: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 10933: if (!$switchserver) {
10934: $datatable .= &mt('Upload:').'<br />';
10935: }
10936: } else {
10937: my $errorstr;
10938: foreach my $key (sort(keys(%error))) {
10939: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
10940: }
10941: $datatable .= '<td>'.$errorstr;
10942: }
1.46 raeburn 10943: } else {
10944: if (keys(%error) > 0) {
10945: my $errorstr;
10946: foreach my $key (sort(keys(%error))) {
10947: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
10948: }
1.60 raeburn 10949: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 10950: } elsif ($scantronurl) {
1.199 raeburn 10951: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
10952: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 10953: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 10954: $link.
10955: '<label><input type="checkbox" name="scantronformat_del"'.
10956: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 10957: '<td><span class="LC_nobreak"> '.
10958: &mt('Replace:').'</span><br />';
1.46 raeburn 10959: }
10960: }
10961: if (keys(%error) == 0) {
10962: if ($switchserver) {
10963: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
10964: } else {
1.65 raeburn 10965: $datatable .='<span class="LC_nobreak"> '.
10966: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 10967: }
10968: }
10969: $datatable .= '</td></tr>';
10970: $$rowtotal ++;
10971: return $datatable;
10972: }
10973:
10974: sub legacy_scantronformat {
10975: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
10976: my ($url,$error);
10977: my @statinfo = &Apache::lonnet::stat_file($newurl);
10978: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
1.421 raeburn 10979: my $modified = [];
1.46 raeburn 10980: (my $result,$url) =
1.421 raeburn 10981: &Apache::lonconfigsettings::publishlogo($r,'copy',$legacyfile,$dom,$confname,
10982: 'scantron','','',$newfile,$modified);
10983: if ($result eq 'ok') {
10984: &update_modify_urls($r,$modified);
10985: } else {
1.130 raeburn 10986: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 10987: }
10988: }
10989: return ($url,$error);
10990: }
1.43 raeburn 10991:
1.346 raeburn 10992: sub print_scantronconfig {
10993: my ($dom,$settings,$rowtotal) = @_;
10994: my $itemcount = 2;
10995: my $is_checked = ' checked="checked"';
1.347 raeburn 10996: my %optionson = (
10997: hdr => ' checked="checked"',
10998: pad => ' checked="checked"',
10999: rem => ' checked="checked"',
11000: );
11001: my %optionsoff = (
11002: hdr => '',
11003: pad => '',
11004: rem => '',
11005: );
1.346 raeburn 11006: my $currcsvsty = 'none';
1.347 raeburn 11007: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 11008: my @fields = &scantroncsv_fields();
11009: my %titles = &scantronconfig_titles();
11010: if (ref($settings) eq 'HASH') {
11011: if (ref($settings->{config}) eq 'HASH') {
11012: if ($settings->{config}->{dat}) {
11013: $checked{'dat'} = $is_checked;
11014: }
11015: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 11016: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
11017: %csvfields = %{$settings->{config}->{csv}->{fields}};
11018: if (keys(%csvfields) > 0) {
11019: $checked{'csv'} = $is_checked;
11020: $currcsvsty = 'block';
11021: }
11022: }
11023: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
11024: %csvoptions = %{$settings->{config}->{csv}->{options}};
11025: foreach my $option (keys(%optionson)) {
11026: unless ($csvoptions{$option}) {
11027: $optionsoff{$option} = $optionson{$option};
11028: $optionson{$option} = '';
11029: }
11030: }
1.346 raeburn 11031: }
11032: }
11033: } else {
11034: $checked{'dat'} = $is_checked;
11035: }
11036: } else {
11037: $checked{'dat'} = $is_checked;
11038: }
11039: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
11040: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11041: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
11042: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
11043: foreach my $item ('dat','csv') {
11044: my $id;
11045: if ($item eq 'csv') {
11046: $id = 'id="scantronconfcsv" ';
1.347 raeburn 11047: }
1.346 raeburn 11048: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
11049: $titles{$item}.'</label>'.(' 'x3);
11050: if ($item eq 'csv') {
11051: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
11052: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
11053: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
11054: foreach my $col (@fields) {
11055: my $selnone;
11056: if ($csvfields{$col} eq '') {
11057: $selnone = ' selected="selected"';
11058: }
11059: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
11060: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
11061: '<option value=""'.$selnone.'></option>';
11062: for (my $i=0; $i<20; $i++) {
11063: my $shown = $i+1;
11064: my $sel;
11065: unless ($selnone) {
11066: if (exists($csvfields{$col})) {
11067: if ($csvfields{$col} == $i) {
11068: $sel = ' selected="selected"';
11069: }
11070: }
11071: }
11072: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
11073: }
11074: $datatable .= '</select></td></tr>';
11075: }
1.347 raeburn 11076: $datatable .= '</table></fieldset>'.
11077: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
11078: '<legend>'.&mt('CSV Options').'</legend>';
11079: foreach my $option ('hdr','pad','rem') {
11080: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
11081: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
11082: &mt('Yes').'</label>'.(' 'x2)."\n".
11083: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
11084: }
11085: $datatable .= '</fieldset>';
1.346 raeburn 11086: $itemcount ++;
11087: }
11088: }
11089: $datatable .= '</td></tr>';
11090: $$rowtotal ++;
11091: return $datatable;
11092: }
11093:
11094: sub scantronconfig_titles {
11095: return &Apache::lonlocal::texthash(
11096: dat => 'Standard format (.dat)',
11097: csv => 'Comma separated values (.csv)',
1.347 raeburn 11098: hdr => 'Remove first line in file (contains column titles)',
11099: pad => 'Prepend 0s to PaperID',
1.348 raeburn 11100: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 11101: CODE => 'CODE',
11102: ID => 'Student ID',
11103: PaperID => 'Paper ID',
11104: FirstName => 'First Name',
11105: LastName => 'Last Name',
11106: FirstQuestion => 'First Question Response',
11107: Section => 'Section',
11108: );
11109: }
11110:
11111: sub scantroncsv_fields {
11112: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
11113: }
11114:
1.49 raeburn 11115: sub print_coursecategories {
1.57 raeburn 11116: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
11117: my $datatable;
11118: if ($position eq 'top') {
1.238 raeburn 11119: my (%checked);
11120: my @catitems = ('unauth','auth');
11121: my @cattypes = ('std','domonly','codesrch','none');
11122: $checked{'unauth'} = 'std';
11123: $checked{'auth'} = 'std';
11124: if (ref($settings) eq 'HASH') {
11125: foreach my $type (@cattypes) {
11126: if ($type eq $settings->{'unauth'}) {
11127: $checked{'unauth'} = $type;
11128: }
11129: if ($type eq $settings->{'auth'}) {
11130: $checked{'auth'} = $type;
11131: }
11132: }
11133: }
11134: my %lt = &Apache::lonlocal::texthash (
11135: unauth => 'Catalog type for unauthenticated users',
11136: auth => 'Catalog type for authenticated users',
11137: none => 'No catalog',
11138: std => 'Standard catalog',
11139: domonly => 'Domain-only catalog',
11140: codesrch => "Code search form",
11141: );
11142: my $itemcount = 0;
11143: foreach my $item (@catitems) {
11144: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11145: $datatable .= '<tr '.$css_class.'>'.
11146: '<td>'.$lt{$item}.'</td>'.
11147: '<td class="LC_right_item"><span class="LC_nobreak">';
11148: foreach my $type (@cattypes) {
11149: my $ischecked;
11150: if ($checked{$item} eq $type) {
11151: $ischecked=' checked="checked"';
11152: }
11153: $datatable .= '<label>'.
11154: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
11155: ' />'.$lt{$type}.'</label> ';
11156: }
1.327 raeburn 11157: $datatable .= '</span></td></tr>';
1.238 raeburn 11158: $itemcount ++;
11159: }
11160: $$rowtotal += $itemcount;
11161: } elsif ($position eq 'middle') {
1.57 raeburn 11162: my $toggle_cats_crs = ' ';
11163: my $toggle_cats_dom = ' checked="checked" ';
11164: my $can_cat_crs = ' ';
11165: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 11166: my $toggle_catscomm_comm = ' ';
11167: my $toggle_catscomm_dom = ' checked="checked" ';
11168: my $can_catcomm_comm = ' ';
11169: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 11170: my $toggle_catsplace_place = ' ';
11171: my $toggle_catsplace_dom = ' checked="checked" ';
11172: my $can_catplace_place = ' ';
11173: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 11174:
1.57 raeburn 11175: if (ref($settings) eq 'HASH') {
11176: if ($settings->{'togglecats'} eq 'crs') {
11177: $toggle_cats_crs = $toggle_cats_dom;
11178: $toggle_cats_dom = ' ';
11179: }
11180: if ($settings->{'categorize'} eq 'crs') {
11181: $can_cat_crs = $can_cat_dom;
11182: $can_cat_dom = ' ';
11183: }
1.120 raeburn 11184: if ($settings->{'togglecatscomm'} eq 'comm') {
11185: $toggle_catscomm_comm = $toggle_catscomm_dom;
11186: $toggle_catscomm_dom = ' ';
11187: }
11188: if ($settings->{'categorizecomm'} eq 'comm') {
11189: $can_catcomm_comm = $can_catcomm_dom;
11190: $can_catcomm_dom = ' ';
11191: }
1.272 raeburn 11192: if ($settings->{'togglecatsplace'} eq 'place') {
11193: $toggle_catsplace_place = $toggle_catsplace_dom;
11194: $toggle_catsplace_dom = ' ';
11195: }
11196: if ($settings->{'categorizeplace'} eq 'place') {
11197: $can_catplace_place = $can_catplace_dom;
11198: $can_catplace_dom = ' ';
11199: }
1.57 raeburn 11200: }
11201: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 11202: togglecats => 'Show/Hide a course in catalog',
11203: togglecatscomm => 'Show/Hide a community in catalog',
11204: togglecatsplace => 'Show/Hide a placement test in catalog',
11205: categorize => 'Assign a category to a course',
11206: categorizecomm => 'Assign a category to a community',
11207: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 11208: );
11209: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 11210: dom => 'Set in Domain',
11211: crs => 'Set in Course',
11212: comm => 'Set in Community',
11213: place => 'Set in Placement Test',
1.57 raeburn 11214: );
11215: $datatable = '<tr class="LC_odd_row">'.
11216: '<td>'.$title{'togglecats'}.'</td>'.
11217: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11218: '<input type="radio" name="togglecats"'.
11219: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11220: '<label><input type="radio" name="togglecats"'.
11221: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
11222: '</tr><tr>'.
11223: '<td>'.$title{'categorize'}.'</td>'.
11224: '<td class="LC_right_item"><span class="LC_nobreak">'.
11225: '<label><input type="radio" name="categorize"'.
11226: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11227: '<label><input type="radio" name="categorize"'.
11228: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 11229: '</tr><tr class="LC_odd_row">'.
11230: '<td>'.$title{'togglecatscomm'}.'</td>'.
11231: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11232: '<input type="radio" name="togglecatscomm"'.
11233: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11234: '<label><input type="radio" name="togglecatscomm"'.
11235: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
11236: '</tr><tr>'.
11237: '<td>'.$title{'categorizecomm'}.'</td>'.
11238: '<td class="LC_right_item"><span class="LC_nobreak">'.
11239: '<label><input type="radio" name="categorizecomm"'.
11240: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11241: '<label><input type="radio" name="categorizecomm"'.
11242: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 11243: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 11244: '<td>'.$title{'togglecatsplace'}.'</td>'.
11245: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11246: '<input type="radio" name="togglecatsplace"'.
11247: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11248: '<label><input type="radio" name="togglecatscomm"'.
11249: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
11250: '</tr><tr>'.
11251: '<td>'.$title{'categorizeplace'}.'</td>'.
11252: '<td class="LC_right_item"><span class="LC_nobreak">'.
11253: '<label><input type="radio" name="categorizeplace"'.
11254: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11255: '<label><input type="radio" name="categorizeplace"'.
11256: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 11257: '</tr>';
1.272 raeburn 11258: $$rowtotal += 6;
1.57 raeburn 11259: } else {
11260: my $css_class;
11261: my $itemcount = 1;
11262: my $cathash;
11263: if (ref($settings) eq 'HASH') {
11264: $cathash = $settings->{'cats'};
11265: }
11266: if (ref($cathash) eq 'HASH') {
11267: my (@cats,@trails,%allitems,%idx,@jsarray);
11268: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
11269: \%allitems,\%idx,\@jsarray);
11270: my $maxdepth = scalar(@cats);
11271: my $colattrib = '';
11272: if ($maxdepth > 2) {
11273: $colattrib = ' colspan="2" ';
11274: }
11275: my @path;
11276: if (@cats > 0) {
11277: if (ref($cats[0]) eq 'ARRAY') {
11278: my $numtop = @{$cats[0]};
11279: my $maxnum = $numtop;
1.120 raeburn 11280: my %default_names = (
11281: instcode => &mt('Official courses'),
11282: communities => &mt('Communities'),
1.272 raeburn 11283: placement => &mt('Placement Tests'),
1.120 raeburn 11284: );
11285:
11286: if ((!grep(/^instcode$/,@{$cats[0]})) ||
11287: ($cathash->{'instcode::0'} eq '') ||
11288: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 11289: ($cathash->{'communities::0'} eq '') ||
11290: (!grep(/^placement$/,@{$cats[0]})) ||
11291: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 11292: $maxnum ++;
11293: }
11294: my $lastidx;
11295: for (my $i=0; $i<$numtop; $i++) {
11296: my $parent = $cats[0][$i];
11297: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11298: my $item = &escape($parent).'::0';
11299: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
11300: $lastidx = $idx{$item};
11301: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
11302: .'<select name="'.$item.'"'.$chgstr.'>';
11303: for (my $k=0; $k<=$maxnum; $k++) {
11304: my $vpos = $k+1;
11305: my $selstr;
11306: if ($k == $i) {
11307: $selstr = ' selected="selected" ';
11308: }
11309: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11310: }
1.214 raeburn 11311: $datatable .= '</select></span></td><td>';
1.272 raeburn 11312: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 11313: $datatable .= '<span class="LC_nobreak">'
11314: .$default_names{$parent}.'</span>';
11315: if ($parent eq 'instcode') {
11316: $datatable .= '<br /><span class="LC_nobreak">('
11317: .&mt('with institutional codes')
11318: .')</span></td><td'.$colattrib.'>';
11319: } else {
11320: $datatable .= '<table><tr><td>';
11321: }
11322: $datatable .= '<span class="LC_nobreak">'
11323: .'<label><input type="radio" name="'
11324: .$parent.'" value="1" checked="checked" />'
11325: .&mt('Display').'</label>';
11326: if ($parent eq 'instcode') {
11327: $datatable .= ' ';
11328: } else {
11329: $datatable .= '</span></td></tr><tr><td>'
11330: .'<span class="LC_nobreak">';
11331: }
11332: $datatable .= '<label><input type="radio" name="'
11333: .$parent.'" value="0" />'
11334: .&mt('Do not display').'</label></span>';
1.272 raeburn 11335: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 11336: $datatable .= '</td></tr></table>';
11337: }
11338: $datatable .= '</td>';
1.57 raeburn 11339: } else {
11340: $datatable .= $parent
1.214 raeburn 11341: .' <span class="LC_nobreak"><label>'
11342: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 11343: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
11344: }
11345: my $depth = 1;
11346: push(@path,$parent);
11347: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
11348: pop(@path);
11349: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
11350: $itemcount ++;
11351: }
1.48 raeburn 11352: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 11353: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
11354: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 11355: for (my $k=0; $k<=$maxnum; $k++) {
11356: my $vpos = $k+1;
11357: my $selstr;
1.57 raeburn 11358: if ($k == $numtop) {
1.48 raeburn 11359: $selstr = ' selected="selected" ';
11360: }
11361: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11362: }
1.59 bisitz 11363: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 11364: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
11365: .'</tr>'."\n";
1.48 raeburn 11366: $itemcount ++;
1.272 raeburn 11367: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11368: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
11369: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11370: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
11371: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
11372: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
11373: for (my $k=0; $k<=$maxnum; $k++) {
11374: my $vpos = $k+1;
11375: my $selstr;
11376: if ($k == $maxnum) {
11377: $selstr = ' selected="selected" ';
11378: }
11379: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 11380: }
1.120 raeburn 11381: $datatable .= '</select></span></td>'.
11382: '<td><span class="LC_nobreak">'.
11383: $default_names{$default}.'</span>';
11384: if ($default eq 'instcode') {
11385: $datatable .= '<br /><span class="LC_nobreak">('
11386: .&mt('with institutional codes').')</span>';
11387: }
11388: $datatable .= '</td>'
11389: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
11390: .&mt('Display').'</label> '
11391: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
11392: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 11393: }
11394: }
11395: }
1.57 raeburn 11396: } else {
11397: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 11398: }
11399: } else {
1.327 raeburn 11400: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 11401: .&initialize_categories($itemcount);
1.48 raeburn 11402: }
1.57 raeburn 11403: $$rowtotal += $itemcount;
1.48 raeburn 11404: }
11405: return $datatable;
11406: }
11407:
1.69 raeburn 11408: sub print_serverstatuses {
11409: my ($dom,$settings,$rowtotal) = @_;
11410: my $datatable;
11411: my @pages = &serverstatus_pages();
11412: my (%namedaccess,%machineaccess);
11413: foreach my $type (@pages) {
11414: $namedaccess{$type} = '';
11415: $machineaccess{$type}= '';
11416: }
11417: if (ref($settings) eq 'HASH') {
11418: foreach my $type (@pages) {
11419: if (exists($settings->{$type})) {
11420: if (ref($settings->{$type}) eq 'HASH') {
11421: foreach my $key (keys(%{$settings->{$type}})) {
11422: if ($key eq 'namedusers') {
11423: $namedaccess{$type} = $settings->{$type}->{$key};
11424: } elsif ($key eq 'machines') {
11425: $machineaccess{$type} = $settings->{$type}->{$key};
11426: }
11427: }
11428: }
11429: }
11430: }
11431: }
1.81 raeburn 11432: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11433: my $rownum = 0;
11434: my $css_class;
11435: foreach my $type (@pages) {
11436: $rownum ++;
11437: $css_class = $rownum%2?' class="LC_odd_row"':'';
11438: $datatable .= '<tr'.$css_class.'>'.
11439: '<td><span class="LC_nobreak">'.
11440: $titles->{$type}.'</span></td>'.
11441: '<td class="LC_left_item">'.
11442: '<input type="text" name="'.$type.'_namedusers" '.
11443: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
11444: '<td class="LC_right_item">'.
11445: '<span class="LC_nobreak">'.
11446: '<input type="text" name="'.$type.'_machines" '.
11447: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 11448: '</span></td></tr>'."\n";
1.69 raeburn 11449: }
11450: $$rowtotal += $rownum;
11451: return $datatable;
11452: }
11453:
11454: sub serverstatus_pages {
11455: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 11456: 'checksums','clusterstatus','certstatus','metadata_keywords',
11457: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
11458: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 11459: }
11460:
1.236 raeburn 11461: sub defaults_javascript {
11462: my ($settings) = @_;
1.354 raeburn 11463: return unless (ref($settings) eq 'HASH');
1.414 raeburn 11464: my $portal_js = <<"ENDPORTAL";
11465:
11466: function portalExtras(caller) {
11467: var x = caller.value;
11468: var y = new Array('email','web');
1.425 raeburn 11469: for (var i=0; i<y.length; i++) {
1.414 raeburn 11470: if (document.getElementById('portal_def_'+y[i]+'_div')) {
11471: var z = document.getElementById('portal_def_'+y[i]+'_div');
11472: if (x.length > 0) {
11473: z.style.display = 'block';
11474: } else {
11475: z.style.display = 'none';
11476: }
11477: }
11478: }
11479: }
11480: ENDPORTAL
1.236 raeburn 11481: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
11482: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
11483: if ($maxnum eq '') {
11484: $maxnum = 0;
11485: }
11486: $maxnum ++;
1.249 raeburn 11487: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 11488: return <<"ENDSCRIPT";
11489: <script type="text/javascript">
11490: // <![CDATA[
11491: function reorderTypes(form,caller) {
11492: var changedVal;
11493: $jstext
11494: var newpos = 'addinststatus_pos';
11495: var current = new Array;
11496: var maxh = $maxnum;
11497: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11498: var oldVal;
11499: if (caller == newpos) {
11500: changedVal = newitemVal;
11501: } else {
11502: var curritem = 'inststatus_pos_'+caller;
11503: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
11504: current[newitemVal] = newpos;
11505: }
11506: for (var i=0; i<inststatuses.length; i++) {
11507: if (inststatuses[i] != caller) {
11508: var elementName = 'inststatus_pos_'+inststatuses[i];
11509: if (form.elements[elementName]) {
11510: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11511: current[currVal] = elementName;
11512: }
11513: }
11514: }
11515: for (var j=0; j<maxh; j++) {
11516: if (current[j] == undefined) {
11517: oldVal = j;
11518: }
11519: }
11520: if (oldVal < changedVal) {
11521: for (var k=oldVal+1; k<=changedVal ; k++) {
11522: var elementName = current[k];
11523: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11524: }
11525: } else {
11526: for (var k=changedVal; k<oldVal; k++) {
11527: var elementName = current[k];
11528: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11529: }
11530: }
11531: return;
11532: }
11533:
1.414 raeburn 11534: $portal_js
11535:
11536: // ]]>
11537: </script>
11538:
11539: ENDSCRIPT
11540: } else {
11541: return <<"ENDSCRIPT";
11542: <script type="text/javascript">
11543: // <![CDATA[
11544: $portal_js
1.236 raeburn 11545: // ]]>
11546: </script>
11547:
11548: ENDSCRIPT
11549: }
1.354 raeburn 11550: return;
11551: }
11552:
11553: sub passwords_javascript {
1.405 raeburn 11554: my ($prefix) = @_;
11555: my %intalert;
11556: if ($prefix eq 'passwords') {
11557: %intalert = &Apache::lonlocal::texthash (
11558: 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.',
11559: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
11560: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
11561: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
11562: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
11563: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
11564: );
1.421 raeburn 11565: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 11566: %intalert = &Apache::lonlocal::texthash (
11567: passmin => 'Warning: minimum secret length must be a positive integer greater than 6.',
11568: passmax => 'Warning: maximum secret length must be a positive integer (or blank).',
11569: );
11570: }
1.365 raeburn 11571: &js_escape(\%intalert);
11572: my $defmin = $Apache::lonnet::passwdmin;
1.425 raeburn 11573: my $intauthjs;
1.405 raeburn 11574: if ($prefix eq 'passwords') { $intauthjs = <<"ENDSCRIPT";
1.354 raeburn 11575:
11576: function warnIntAuth(field) {
11577: if (field.name == 'intauth_check') {
11578: if (field.value == '2') {
1.365 raeburn 11579: alert('$intalert{authcheck}');
1.354 raeburn 11580: }
11581: }
11582: if (field.name == 'intauth_cost') {
11583: field.value.replace(/\s/g,'');
11584: if (field.value != '') {
11585: var regexdigit=/^\\d+\$/;
11586: if (!regexdigit.test(field.value)) {
1.365 raeburn 11587: alert('$intalert{authcost}');
11588: }
11589: }
11590: }
11591: return;
11592: }
11593:
1.405 raeburn 11594: ENDSCRIPT
11595:
11596: }
11597:
11598: $intauthjs .= <<"ENDSCRIPT";
11599:
11600: function warnInt$prefix(field) {
1.365 raeburn 11601: field.value.replace(/^\s+/,'');
11602: field.value.replace(/\s+\$/,'');
11603: var regexdigit=/^\\d+\$/;
1.408 raeburn 11604: if (field.name == '${prefix}_min') {
1.365 raeburn 11605: if (field.value == '') {
11606: alert('$intalert{passmin}');
11607: field.value = '$defmin';
11608: } else {
11609: if (!regexdigit.test(field.value)) {
11610: alert('$intalert{passmin}');
11611: field.value = '$defmin';
11612: }
1.366 raeburn 11613: var minval = parseInt(field.value,10);
1.365 raeburn 11614: if (minval < $defmin) {
11615: alert('$intalert{passmin}');
11616: field.value = '$defmin';
11617: }
11618: }
11619: } else {
11620: if (field.value == '0') {
11621: field.value = '';
11622: }
11623: if (field.value != '') {
1.408 raeburn 11624: if (field.name == '${prefix}_expire') {
1.365 raeburn 11625: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
11626: if (!regexpposnum.test(field.value)) {
11627: alert('$intalert{passexp}');
11628: field.value = '';
11629: } else {
11630: var expval = parseFloat(field.value);
11631: if (expval == 0) {
11632: alert('$intalert{passexp}');
11633: field.value = '';
11634: }
11635: }
11636: } else {
11637: if (!regexdigit.test(field.value)) {
1.408 raeburn 11638: if (field.name == '${prefix}_max') {
1.365 raeburn 11639: alert('$intalert{passmax}');
11640: } else {
1.408 raeburn 11641: if (field.name == '${prefix}_numsaved') {
1.365 raeburn 11642: alert('$intalert{passnum}');
11643: }
11644: }
1.370 raeburn 11645: field.value = '';
1.365 raeburn 11646: }
1.354 raeburn 11647: }
11648: }
11649: }
11650: return;
11651: }
11652:
11653: ENDSCRIPT
11654: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 11655: }
11656:
1.49 raeburn 11657: sub coursecategories_javascript {
11658: my ($settings) = @_;
1.57 raeburn 11659: my ($output,$jstext,$cathash);
1.49 raeburn 11660: if (ref($settings) eq 'HASH') {
1.57 raeburn 11661: $cathash = $settings->{'cats'};
11662: }
11663: if (ref($cathash) eq 'HASH') {
1.49 raeburn 11664: my (@cats,@jsarray,%idx);
1.57 raeburn 11665: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 11666: if (@jsarray > 0) {
11667: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
11668: for (my $i=0; $i<@jsarray; $i++) {
11669: if (ref($jsarray[$i]) eq 'ARRAY') {
11670: my $catstr = join('","',@{$jsarray[$i]});
11671: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
11672: }
11673: }
11674: }
11675: } else {
11676: $jstext = ' var categories = Array(1);'."\n".
11677: ' categories[0] = Array("instcode_pos");'."\n";
11678: }
1.237 bisitz 11679: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
11680: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 11681: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 11682: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
11683: &js_escape(\$instcode_reserved);
11684: &js_escape(\$communities_reserved);
1.272 raeburn 11685: &js_escape(\$placement_reserved);
1.265 damieng 11686: &js_escape(\$choose_again);
1.49 raeburn 11687: $output = <<"ENDSCRIPT";
11688: <script type="text/javascript">
1.109 raeburn 11689: // <![CDATA[
1.49 raeburn 11690: function reorderCats(form,parent,item,idx) {
11691: var changedVal;
11692: $jstext
11693: var newpos = 'addcategory_pos';
11694: if (parent == '') {
11695: var has_instcode = 0;
11696: var maxtop = categories[idx].length;
11697: for (var j=0; j<maxtop; j++) {
11698: if (categories[idx][j] == 'instcode::0') {
11699: has_instcode == 1;
11700: }
11701: }
11702: if (has_instcode == 0) {
11703: categories[idx][maxtop] = 'instcode_pos';
11704: }
11705: } else {
11706: newpos += '_'+parent;
11707: }
11708: var maxh = 1 + categories[idx].length;
11709: var current = new Array;
11710: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11711: if (item == newpos) {
11712: changedVal = newitemVal;
11713: } else {
11714: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
11715: current[newitemVal] = newpos;
11716: }
11717: for (var i=0; i<categories[idx].length; i++) {
11718: var elementName = categories[idx][i];
11719: if (elementName != item) {
11720: if (form.elements[elementName]) {
11721: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11722: current[currVal] = elementName;
11723: }
11724: }
11725: }
11726: var oldVal;
11727: for (var j=0; j<maxh; j++) {
11728: if (current[j] == undefined) {
11729: oldVal = j;
11730: }
11731: }
11732: if (oldVal < changedVal) {
11733: for (var k=oldVal+1; k<=changedVal ; k++) {
11734: var elementName = current[k];
11735: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11736: }
11737: } else {
11738: for (var k=changedVal; k<oldVal; k++) {
11739: var elementName = current[k];
11740: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11741: }
11742: }
11743: return;
11744: }
1.120 raeburn 11745:
11746: function categoryCheck(form) {
11747: if (form.elements['addcategory_name'].value == 'instcode') {
11748: alert('$instcode_reserved\\n$choose_again');
11749: return false;
11750: }
11751: if (form.elements['addcategory_name'].value == 'communities') {
11752: alert('$communities_reserved\\n$choose_again');
11753: return false;
11754: }
1.272 raeburn 11755: if (form.elements['addcategory_name'].value == 'placement') {
11756: alert('$placement_reserved\\n$choose_again');
11757: return false;
11758: }
1.120 raeburn 11759: return true;
11760: }
11761:
1.109 raeburn 11762: // ]]>
1.49 raeburn 11763: </script>
11764:
11765: ENDSCRIPT
11766: return $output;
11767: }
11768:
1.48 raeburn 11769: sub initialize_categories {
11770: my ($itemcount) = @_;
1.120 raeburn 11771: my ($datatable,$css_class,$chgstr);
1.380 raeburn 11772: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 11773: instcode => 'Official courses (with institutional codes)',
11774: communities => 'Communities',
1.272 raeburn 11775: placement => 'Placement Tests',
1.120 raeburn 11776: );
1.328 raeburn 11777: my %selnum = (
11778: instcode => '0',
11779: communities => '1',
11780: placement => '2',
11781: );
11782: my %selected;
1.272 raeburn 11783: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11784: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 11785: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 11786: map { $selected{$selnum{$_}} = '' } keys(%selnum);
11787: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 11788: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 11789: .'<select name="'.$default.'_pos"'.$chgstr.'>'
11790: .'<option value="0"'.$selected{'0'}.'>1</option>'
11791: .'<option value="1"'.$selected{'1'}.'>2</option>'
11792: .'<option value="2"'.$selected{'2'}.'>3</option>'
11793: .'<option value="3">4</option></select> '
1.120 raeburn 11794: .$default_names{$default}
11795: .'</span></td><td><span class="LC_nobreak">'
11796: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
11797: .&mt('Display').'</label> <label>'
11798: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 11799: .'</label></span></td></tr>';
1.120 raeburn 11800: $itemcount ++;
11801: }
1.48 raeburn 11802: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 11803: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 11804: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 11805: .'<select name="addcategory_pos"'.$chgstr.'>'
11806: .'<option value="0">1</option>'
11807: .'<option value="1">2</option>'
1.328 raeburn 11808: .'<option value="2">3</option>'
11809: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 11810: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
11811: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
11812: .'</td></tr>';
1.48 raeburn 11813: return $datatable;
11814: }
11815:
11816: sub build_category_rows {
1.49 raeburn 11817: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
11818: my ($text,$name,$item,$chgstr);
1.48 raeburn 11819: if (ref($cats) eq 'ARRAY') {
11820: my $maxdepth = scalar(@{$cats});
11821: if (ref($cats->[$depth]) eq 'HASH') {
11822: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
11823: my $numchildren = @{$cats->[$depth]{$parent}};
11824: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 11825: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 11826: my ($idxnum,$parent_name,$parent_item);
11827: my $higher = $depth - 1;
11828: if ($higher == 0) {
11829: $parent_name = &escape($parent).'::'.$higher;
11830: } else {
11831: if (ref($path) eq 'ARRAY') {
11832: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
11833: }
11834: }
11835: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 11836: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 11837: if ($j < $numchildren) {
1.48 raeburn 11838: $name = $cats->[$depth]{$parent}[$j];
11839: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 11840: $idxnum = $idx->{$item};
11841: } else {
11842: $name = $parent_name;
11843: $item = $parent_item;
1.48 raeburn 11844: }
1.49 raeburn 11845: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
11846: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 11847: for (my $i=0; $i<=$numchildren; $i++) {
11848: my $vpos = $i+1;
11849: my $selstr;
11850: if ($j == $i) {
11851: $selstr = ' selected="selected" ';
11852: }
11853: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
11854: }
11855: $text .= '</select> ';
11856: if ($j < $numchildren) {
11857: my $deeper = $depth+1;
11858: $text .= $name.' '
11859: .'<label><input type="checkbox" name="deletecategory" value="'
11860: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
11861: if(ref($path) eq 'ARRAY') {
11862: push(@{$path},$name);
1.49 raeburn 11863: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 11864: pop(@{$path});
11865: }
11866: } else {
1.330 raeburn 11867: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 11868: if ($j == $numchildren) {
11869: $text .= $name;
11870: } else {
11871: $text .= $item;
11872: }
11873: $text .= '" value="" />';
11874: }
11875: $text .= '</td></tr>';
11876: }
11877: $text .= '</table></td>';
11878: } else {
11879: my $higher = $depth-1;
11880: if ($higher == 0) {
11881: $name = &escape($parent).'::'.$higher;
11882: } else {
11883: if (ref($path) eq 'ARRAY') {
11884: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
11885: }
11886: }
11887: my $colspan;
11888: if ($parent ne 'instcode') {
11889: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 11890: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 11891: }
11892: }
11893: }
11894: }
11895: return $text;
11896: }
11897:
1.33 raeburn 11898: sub modifiable_userdata_row {
1.305 raeburn 11899: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357 raeburn 11900: $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228 raeburn 11901: my ($role,$rolename,$statustype);
11902: $role = $item;
1.224 raeburn 11903: if ($context eq 'cancreate') {
1.305 raeburn 11904: if ($item =~ /^(emailusername)_(.+)$/) {
11905: $role = $1;
11906: $statustype = $2;
1.228 raeburn 11907: if (ref($usertypes) eq 'HASH') {
11908: if ($usertypes->{$statustype}) {
11909: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
11910: } else {
11911: $rolename = &mt('Data provided by user');
11912: }
11913: }
1.224 raeburn 11914: }
11915: } elsif ($context eq 'selfcreate') {
1.63 raeburn 11916: if (ref($usertypes) eq 'HASH') {
11917: $rolename = $usertypes->{$role};
11918: } else {
11919: $rolename = $role;
11920: }
1.325 raeburn 11921: } elsif ($context eq 'lti') {
11922: $rolename = &mt('Institutional data used (if available)');
1.357 raeburn 11923: } elsif ($context eq 'privacy') {
11924: $rolename = $itemdesc;
1.33 raeburn 11925: } else {
1.63 raeburn 11926: if ($role eq 'cr') {
11927: $rolename = &mt('Custom role');
11928: } else {
11929: $rolename = &Apache::lonnet::plaintext($role);
11930: }
1.33 raeburn 11931: }
1.224 raeburn 11932: my (@fields,%fieldtitles);
11933: if (ref($fieldsref) eq 'ARRAY') {
11934: @fields = @{$fieldsref};
11935: } else {
11936: @fields = ('lastname','firstname','middlename','generation',
11937: 'permanentemail','id');
11938: }
11939: if ((ref($titlesref) eq 'HASH')) {
11940: %fieldtitles = %{$titlesref};
11941: } else {
11942: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11943: }
1.33 raeburn 11944: my $output;
1.305 raeburn 11945: my $css_class;
11946: if ($rowcount%2) {
11947: $css_class = 'LC_odd_row';
11948: }
11949: if ($customcss) {
11950: $css_class .= " $customcss";
11951: }
11952: $css_class =~ s/^\s+//;
11953: if ($css_class) {
11954: $css_class = ' class="'.$css_class.'"';
11955: }
11956: if ($rowstyle) {
11957: $css_class .= ' style="'.$rowstyle.'"';
11958: }
11959: if ($rowid) {
11960: $rowid = ' id="'.$rowid.'"';
11961: }
11962: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 11963: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
11964: '<td class="LC_left_item" colspan="2"><table>';
11965: my $rem;
11966: my %checks;
11967: if (ref($settings) eq 'HASH') {
1.325 raeburn 11968: my $hashref;
11969: if ($context eq 'lti') {
11970: if (ref($settings) eq 'HASH') {
11971: $hashref = $settings->{'instdata'};
11972: }
1.357 raeburn 11973: } elsif ($context eq 'privacy') {
11974: my ($key,$inner) = split(/_/,$role);
11975: if (ref($settings) eq 'HASH') {
11976: if (ref($settings->{$key}) eq 'HASH') {
11977: $hashref = $settings->{$key}->{$inner};
11978: }
11979: }
1.325 raeburn 11980: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 11981: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 11982: $hashref = $settings->{'lti_instdata'};
11983: }
11984: if ($role eq 'emailusername') {
11985: if ($statustype) {
11986: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
11987: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 11988: }
1.325 raeburn 11989: }
11990: }
11991: }
1.425 raeburn 11992: if (ref($hashref) eq 'HASH') {
1.325 raeburn 11993: foreach my $field (@fields) {
11994: if ($hashref->{$field}) {
11995: if ($role eq 'emailusername') {
11996: $checks{$field} = $hashref->{$field};
11997: } else {
11998: $checks{$field} = ' checked="checked" ';
1.33 raeburn 11999: }
12000: }
12001: }
12002: }
12003: }
1.305 raeburn 12004: my $total = scalar(@fields);
12005: for (my $i=0; $i<$total; $i++) {
12006: $rem = $i%($numinrow);
1.33 raeburn 12007: if ($rem == 0) {
12008: if ($i > 0) {
12009: $output .= '</tr>';
12010: }
12011: $output .= '<tr>';
12012: }
12013: my $check = ' ';
1.228 raeburn 12014: unless ($role eq 'emailusername') {
12015: if (exists($checks{$fields[$i]})) {
1.354 raeburn 12016: $check = $checks{$fields[$i]};
1.357 raeburn 12017: } elsif ($context eq 'privacy') {
12018: if ($role =~ /^priv_(domain|course)$/) {
12019: if (ref($settings) ne 'HASH') {
12020: $check = ' checked="checked" ';
12021: }
12022: } elsif ($role =~ /^priv_(author|community)$/) {
12023: if (ref($settings) ne 'HASH') {
12024: unless ($fields[$i] eq 'id') {
12025: $check = ' checked="checked" ';
12026: }
12027: }
12028: } elsif ($role =~ /^(unpriv|othdom)_/) {
12029: if (ref($settings) ne 'HASH') {
12030: if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
12031: $check = ' checked="checked" ';
12032: }
12033: }
12034: }
1.325 raeburn 12035: } elsif ($context ne 'lti') {
1.228 raeburn 12036: if ($role eq 'st') {
12037: if (ref($settings) ne 'HASH') {
12038: $check = ' checked="checked" ';
12039: }
1.33 raeburn 12040: }
12041: }
12042: }
12043: $output .= '<td class="LC_left_item">'.
1.228 raeburn 12044: '<span class="LC_nobreak">';
1.325 raeburn 12045: my $prefix = 'canmodify';
1.228 raeburn 12046: if ($role eq 'emailusername') {
12047: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
12048: $checks{$fields[$i]} = 'omit';
12049: }
12050: foreach my $option ('required','optional','omit') {
12051: my $checked='';
12052: if ($checks{$fields[$i]} eq $option) {
12053: $checked='checked="checked" ';
12054: }
12055: $output .= '<label>'.
1.325 raeburn 12056: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 12057: &mt($option).'</label>'.(' ' x2);
12058: }
12059: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
12060: } else {
1.325 raeburn 12061: if ($context eq 'lti') {
12062: $prefix = 'lti';
1.357 raeburn 12063: } elsif ($context eq 'privacy') {
12064: $prefix = 'privacy';
1.325 raeburn 12065: }
1.228 raeburn 12066: $output .= '<label>'.
1.325 raeburn 12067: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 12068: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
12069: '</label>';
12070: }
12071: $output .= '</span></td>';
1.33 raeburn 12072: }
1.305 raeburn 12073: $rem = $total%$numinrow;
12074: my $colsleft;
12075: if ($rem) {
12076: $colsleft = $numinrow - $rem;
12077: }
12078: if ($colsleft > 1) {
1.33 raeburn 12079: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
12080: ' </td>';
12081: } elsif ($colsleft == 1) {
12082: $output .= '<td class="LC_left_item"> </td>';
12083: }
12084: $output .= '</tr></table></td></tr>';
12085: return $output;
12086: }
1.28 raeburn 12087:
1.93 raeburn 12088: sub insttypes_row {
1.305 raeburn 12089: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
12090: $customcss,$rowstyle) = @_;
1.93 raeburn 12091: my %lt = &Apache::lonlocal::texthash (
1.429 raeburn 12092: cansearch => 'Users allowed to search',
1.93 raeburn 12093: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.429 raeburn 12094: lockablenames => 'User preference to lock name',
12095: selfassign => 'Self-reportable affiliations',
12096: overrides => "Override domain's helpdesk settings based on requester's affiliation",
12097: webdav => 'WebDAV access available',
12098: authorquota => 'Authoring Space quota (MB)',
1.93 raeburn 12099: );
1.429 raeburn 12100: my ($showdom,$defaultquota);
1.93 raeburn 12101: if ($context eq 'cansearch') {
12102: $showdom = ' ('.$dom.')';
1.429 raeburn 12103: } elsif ($context eq 'authorquota') {
12104: $defaultquota = 500;
1.93 raeburn 12105: }
1.165 raeburn 12106: my $class = 'LC_left_item';
12107: if ($context eq 'statustocreate') {
12108: $class = 'LC_right_item';
12109: }
1.305 raeburn 12110: my $css_class;
12111: if ($$rowtotal%2) {
12112: $css_class = 'LC_odd_row';
12113: }
12114: if ($customcss) {
12115: $css_class .= ' '.$customcss;
12116: }
12117: $css_class =~ s/^\s+//;
12118: if ($css_class) {
12119: $css_class = ' class="'.$css_class.'"';
12120: }
12121: if ($rowstyle) {
12122: $css_class .= ' style="'.$rowstyle.'"';
12123: }
12124: if ($onclick) {
12125: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 12126: }
12127: my $output = '<tr'.$css_class.'>'.
12128: '<td>'.$lt{$context}.$showdom.
12129: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 12130: my $rem;
12131: if (ref($types) eq 'ARRAY') {
12132: for (my $i=0; $i<@{$types}; $i++) {
12133: if (defined($usertypes->{$types->[$i]})) {
12134: my $rem = $i%($numinrow);
12135: if ($rem == 0) {
12136: if ($i > 0) {
12137: $output .= '</tr>';
12138: }
12139: $output .= '<tr>';
1.23 raeburn 12140: }
1.429 raeburn 12141: if ($context eq 'authorquota') {
12142: my $currquota;
12143: if ($settings->{$context}->{$types->[$i]} =~ /^\d+$/) {
12144: $currquota = $settings->{$context}->{$types->[$i]};
12145: } else {
12146: $currquota = $defaultquota;
12147: }
12148: $output .= '<td class="LC_left_item">'."\n".
12149: '<label><span class="LC_nobreak">'."\n".
12150: $usertypes->{$types->[$i]}.'</span><br />'."\n".
12151: '<input type="text" name="'.$context.'_'.$types->[$i].'" '.
12152: 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
12153: '</label></td>';
12154: } else {
12155: my $check = ' ';
12156: if (ref($settings) eq 'HASH') {
12157: if (ref($settings->{$context}) eq 'ARRAY') {
12158: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
12159: $check = ' checked="checked" ';
12160: }
12161: } elsif (ref($settings->{$context}) eq 'HASH') {
12162: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
12163: $check = ' checked="checked" ';
12164: } elsif ($context eq 'webdav') {
12165: if ($settings->{$context}->{$types->[$i]}) {
12166: $check = ' checked="checked" ';
12167: }
12168: }
12169: } elsif ($context eq 'statustocreate') {
1.315 raeburn 12170: $check = ' checked="checked" ';
12171: }
1.26 raeburn 12172: }
1.429 raeburn 12173: $output .= '<td class="LC_left_item">'.
12174: '<span class="LC_nobreak"><label>'.
12175: '<input type="checkbox" name="'.$context.'" '.
12176: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
12177: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 12178: }
12179: }
12180: }
1.26 raeburn 12181: $rem = @{$types}%($numinrow);
1.23 raeburn 12182: }
12183: my $colsleft = $numinrow - $rem;
1.315 raeburn 12184: if ($context eq 'overrides') {
12185: if ($colsleft > 1) {
12186: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12187: } else {
12188: $output .= '<td class="LC_left_item">';
12189: }
1.425 raeburn 12190: $output .= ' ';
1.23 raeburn 12191: } else {
1.334 raeburn 12192: if ($rem == 0) {
1.315 raeburn 12193: $output .= '<tr>';
12194: }
12195: if ($colsleft > 1) {
12196: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12197: } else {
12198: $output .= '<td class="LC_left_item">';
12199: }
1.429 raeburn 12200: if ($context eq 'authorquota') {
12201: my $currquota = 500;
12202: if ((ref($settings) eq 'HASH') && (ref($settings->{$context}) eq 'HASH')) {
12203: if ($settings->{$context}{'default'} =~ /^\d+$/) {
12204: $currquota = $settings->{$context}{'default'};
12205: }
12206: }
12207: $output .= '<label><span class="LC_nobreak">'.$othertitle.'</span><br />'."\n".
12208: '<input type="text" name="'.$context.'_default" '.
12209: 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
12210: '</label>';
12211: } else {
12212: my $defcheck = ' ';
12213: if (ref($settings) eq 'HASH') {
12214: if (ref($settings->{$context}) eq 'ARRAY') {
12215: if (grep(/^default$/,@{$settings->{$context}})) {
12216: $defcheck = ' checked="checked" ';
12217: }
12218: } elsif (ref($settings->{$context}) eq 'HASH') {
12219: if (ref($settings->{$context}->{'default'}) eq 'HASH') {
12220: $defcheck = ' checked="checked" ';
12221: } elsif ($context eq 'webdav') {
12222: if ($settings->{$context}->{'default'}) {
12223: $defcheck = ' checked="checked" ';
12224: }
12225: }
12226: } elsif ($context eq 'statustocreate') {
1.315 raeburn 12227: $defcheck = ' checked="checked" ';
12228: }
1.99 raeburn 12229: }
1.429 raeburn 12230: $output .= '<span class="LC_nobreak"><label>'.
12231: '<input type="checkbox" name="'.$context.'" '.
12232: 'value="default"'.$defcheck.$onclick.'/>'.
12233: $othertitle.'</label></span>';
1.26 raeburn 12234: }
1.23 raeburn 12235: }
1.315 raeburn 12236: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 12237: return $output;
1.23 raeburn 12238: }
12239:
12240: sub sorted_searchtitles {
12241: my %searchtitles = &Apache::lonlocal::texthash(
12242: 'uname' => 'username',
12243: 'lastname' => 'last name',
12244: 'lastfirst' => 'last name, first name',
12245: );
12246: my @titleorder = ('uname','lastname','lastfirst');
12247: return (\%searchtitles,\@titleorder);
12248: }
12249:
1.25 raeburn 12250: sub sorted_searchtypes {
12251: my %srchtypes_desc = (
12252: exact => 'is exact match',
12253: contains => 'contains ..',
12254: begins => 'begins with ..',
12255: );
12256: my @srchtypeorder = ('exact','begins','contains');
12257: return (\%srchtypes_desc,\@srchtypeorder);
12258: }
12259:
1.3 raeburn 12260: sub usertype_update_row {
12261: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
12262: my $datatable;
12263: my $numinrow = 4;
12264: foreach my $type (@{$types}) {
12265: if (defined($usertypes->{$type})) {
12266: $$rownums ++;
12267: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
12268: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
12269: '</td><td class="LC_left_item"><table>';
12270: for (my $i=0; $i<@{$fields}; $i++) {
12271: my $rem = $i%($numinrow);
12272: if ($rem == 0) {
12273: if ($i > 0) {
12274: $datatable .= '</tr>';
12275: }
12276: $datatable .= '<tr>';
12277: }
12278: my $check = ' ';
1.39 raeburn 12279: if (ref($settings) eq 'HASH') {
12280: if (ref($settings->{'fields'}) eq 'HASH') {
12281: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
12282: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
12283: $check = ' checked="checked" ';
12284: }
1.3 raeburn 12285: }
12286: }
12287: }
12288:
12289: if ($i == @{$fields}-1) {
12290: my $colsleft = $numinrow - $rem;
12291: if ($colsleft > 1) {
12292: $datatable .= '<td colspan="'.$colsleft.'">';
12293: } else {
12294: $datatable .= '<td>';
12295: }
12296: } else {
12297: $datatable .= '<td>';
12298: }
1.8 raeburn 12299: $datatable .= '<span class="LC_nobreak"><label>'.
12300: '<input type="checkbox" name="updateable_'.$type.
12301: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
12302: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 12303: }
12304: $datatable .= '</tr></table></td></tr>';
12305: }
12306: }
12307: return $datatable;
1.1 raeburn 12308: }
12309:
12310: sub modify_login {
1.205 raeburn 12311: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 12312: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.386 raeburn 12313: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
1.412 raeburn 12314: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso);
1.168 raeburn 12315: %title = ( coursecatalog => 'Display course catalog',
12316: adminmail => 'Display administrator E-mail address',
1.188 raeburn 12317: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 12318: newuser => 'Link for visitors to create a user account',
1.386 raeburn 12319: loginheader => 'Log-in box header',
12320: saml => 'Dual SSO and non-SSO login');
1.168 raeburn 12321: @offon = ('off','on');
1.112 raeburn 12322: if (ref($domconfig{login}) eq 'HASH') {
12323: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
12324: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
12325: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
12326: }
12327: }
1.386 raeburn 12328: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
12329: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
12330: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
12331: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
12332: $saml{$lonhost} = 1;
12333: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
12334: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
12335: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
12336: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
12337: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
1.412 raeburn 12338: $samlwindow{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'window'};
1.386 raeburn 12339: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
12340: }
12341: }
12342: }
1.112 raeburn 12343: }
1.9 raeburn 12344: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
12345: \%domconfig,\%loginhash);
1.188 raeburn 12346: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12347: foreach my $item (@toggles) {
12348: $loginhash{login}{$item} = $env{'form.'.$item};
12349: }
1.41 raeburn 12350: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 12351: if (ref($colchanges{'login'}) eq 'HASH') {
12352: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
12353: \%loginhash);
12354: }
1.110 raeburn 12355:
1.149 raeburn 12356: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 12357: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 12358: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 12359: if (keys(%servers) > 1) {
12360: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 12361: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
12362: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
12363: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
12364: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
12365: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
12366: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12367: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12368: $changes{'loginvia'}{$lonhost} = 1;
12369: } else {
12370: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
12371: $changes{'loginvia'}{$lonhost} = 1;
12372: }
12373: } else {
12374: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12375: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12376: $changes{'loginvia'}{$lonhost} = 1;
12377: }
12378: }
12379: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
12380: foreach my $item (@loginvia_attribs) {
12381: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
12382: }
12383: } else {
12384: foreach my $item (@loginvia_attribs) {
12385: my $new = $env{'form.'.$lonhost.'_'.$item};
12386: if (($item eq 'serverpath') && ($new eq 'custom')) {
12387: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
12388: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12389: $new = '/';
12390: }
12391: }
12392: if (($item eq 'custompath') &&
12393: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12394: $new = '';
12395: }
12396: if ($new ne $curr_loginvia{$lonhost}{$item}) {
12397: $changes{'loginvia'}{$lonhost} = 1;
12398: }
12399: if ($item eq 'exempt') {
1.256 raeburn 12400: $new = &check_exempt_addresses($new);
1.128 raeburn 12401: }
12402: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12403: }
12404: }
1.112 raeburn 12405: } else {
1.128 raeburn 12406: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12407: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 12408: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 12409: foreach my $item (@loginvia_attribs) {
12410: my $new = $env{'form.'.$lonhost.'_'.$item};
12411: if (($item eq 'serverpath') && ($new eq 'custom')) {
12412: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12413: $new = '/';
12414: }
12415: }
12416: if (($item eq 'custompath') &&
12417: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12418: $new = '';
12419: }
12420: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12421: }
1.110 raeburn 12422: }
12423: }
12424: }
12425: }
1.119 raeburn 12426:
1.168 raeburn 12427: my $servadm = $r->dir_config('lonAdmEMail');
12428: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
12429: if (ref($domconfig{'login'}) eq 'HASH') {
12430: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
12431: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
12432: if ($lang eq 'nolang') {
12433: push(@currlangs,$lang);
12434: } elsif (defined($langchoices{$lang})) {
12435: push(@currlangs,$lang);
12436: } else {
12437: next;
12438: }
12439: }
12440: }
12441: }
12442: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
12443: if (@currlangs > 0) {
12444: foreach my $lang (@currlangs) {
12445: if (grep(/^\Q$lang\E$/,@delurls)) {
12446: $changes{'helpurl'}{$lang} = 1;
12447: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
12448: $changes{'helpurl'}{$lang} = 1;
12449: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
12450: push(@newlangs,$lang);
12451: } else {
12452: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12453: }
12454: }
12455: }
12456: unless (grep(/^nolang$/,@currlangs)) {
12457: if ($env{'form.loginhelpurl_nolang.filename'}) {
12458: $changes{'helpurl'}{'nolang'} = 1;
12459: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
12460: push(@newlangs,'nolang');
12461: }
12462: }
12463: if ($env{'form.loginhelpurl_add_lang'}) {
12464: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
12465: ($env{'form.loginhelpurl_add_file.filename'})) {
12466: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
12467: $addedfile = $env{'form.loginhelpurl_add_lang'};
12468: }
12469: }
12470: if ((@newlangs > 0) || ($addedfile)) {
12471: my $error;
12472: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12473: if ($configuserok eq 'ok') {
12474: if ($switchserver) {
12475: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
12476: } elsif ($author_ok eq 'ok') {
12477: my @allnew = @newlangs;
12478: if ($addedfile ne '') {
12479: push(@allnew,$addedfile);
12480: }
1.421 raeburn 12481: my $modified = [];
1.168 raeburn 12482: foreach my $lang (@allnew) {
12483: my $formelem = 'loginhelpurl_'.$lang;
12484: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
12485: $formelem = 'loginhelpurl_add_file';
12486: }
1.425 raeburn 12487: (my $result,$newurl{$lang}) =
1.421 raeburn 12488: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12489: "help/$lang",'','',$newfile{$lang},
12490: $modified);
1.168 raeburn 12491: if ($result eq 'ok') {
12492: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
12493: $changes{'helpurl'}{$lang} = 1;
12494: } else {
12495: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
12496: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 12497: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 12498: (!grep(/^\Q$lang\E$/,@delurls))) {
12499: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12500: }
12501: }
12502: }
1.421 raeburn 12503: &update_modify_urls($r,$modified);
1.168 raeburn 12504: } else {
12505: $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);
12506: }
12507: } else {
12508: $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);
12509: }
12510: if ($error) {
12511: &Apache::lonnet::logthis($error);
12512: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12513: }
12514: }
1.256 raeburn 12515:
12516: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
12517: if (ref($domconfig{'login'}) eq 'HASH') {
12518: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
12519: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
12520: if ($domservers{$lonhost}) {
12521: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12522: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 12523: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 12524: }
12525: }
12526: }
12527: }
12528: }
12529: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
12530: foreach my $lonhost (sort(keys(%domservers))) {
12531: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12532: $changes{'headtag'}{$lonhost} = 1;
12533: } else {
12534: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
12535: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
12536: }
12537: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
12538: push(@newhosts,$lonhost);
12539: } elsif ($currheadtagurls{$lonhost}) {
12540: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
12541: if ($currexempt{$lonhost}) {
1.289 raeburn 12542: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 12543: $changes{'headtag'}{$lonhost} = 1;
12544: }
12545: } elsif ($possexempt{$lonhost}) {
12546: $changes{'headtag'}{$lonhost} = 1;
12547: }
12548: if ($possexempt{$lonhost}) {
12549: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12550: }
12551: }
12552: }
12553: }
12554: if (@newhosts) {
12555: my $error;
12556: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12557: if ($configuserok eq 'ok') {
12558: if ($switchserver) {
12559: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
12560: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12561: my $modified = [];
1.256 raeburn 12562: foreach my $lonhost (@newhosts) {
12563: my $formelem = 'loginheadtag_'.$lonhost;
1.425 raeburn 12564: (my $result,$newheadtagurls{$lonhost}) =
1.421 raeburn 12565: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12566: "login/headtag/$lonhost",'','',
12567: $env{'form.loginheadtag_'.$lonhost.'.filename'},
12568: $modified);
1.256 raeburn 12569: if ($result eq 'ok') {
12570: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
12571: $changes{'headtag'}{$lonhost} = 1;
12572: if ($possexempt{$lonhost}) {
12573: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12574: }
12575: } else {
12576: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
12577: $newheadtagurls{$lonhost},$result);
12578: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12579: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
12580: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
12581: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
12582: }
12583: }
12584: }
1.421 raeburn 12585: &update_modify_urls($r,$modified);
1.256 raeburn 12586: } else {
12587: $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);
12588: }
12589: } else {
12590: $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);
12591: }
12592: if ($error) {
12593: &Apache::lonnet::logthis($error);
12594: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12595: }
12596: }
1.386 raeburn 12597: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
12598: my @newsamlimgs;
12599: foreach my $lonhost (keys(%domservers)) {
12600: if ($env{'form.saml_'.$lonhost}) {
12601: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
12602: push(@newsamlimgs,$lonhost);
12603: }
1.412 raeburn 12604: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12605: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
12606: }
12607: if ($saml{$lonhost}) {
1.412 raeburn 12608: if ($env{'form.saml_window_'.$lonhost} ne '1') {
12609: $env{'form.saml_window_'.$lonhost} = '';
12610: }
1.386 raeburn 12611: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
12612: #FIXME Need to obsolete published image
12613: delete($currsaml{$lonhost}{'img'});
12614: $changes{'saml'}{$lonhost} = 1;
12615: }
12616: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
12617: $changes{'saml'}{$lonhost} = 1;
12618: }
12619: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
12620: $changes{'saml'}{$lonhost} = 1;
12621: }
12622: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
12623: $changes{'saml'}{$lonhost} = 1;
12624: }
12625: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
12626: $changes{'saml'}{$lonhost} = 1;
12627: }
1.412 raeburn 12628: if ($env{'form.saml_window_'.$lonhost} ne $samlwindow{$lonhost}) {
12629: $changes{'saml'}{$lonhost} = 1;
12630: }
1.386 raeburn 12631: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
12632: $changes{'saml'}{$lonhost} = 1;
12633: }
12634: } else {
12635: $changes{'saml'}{$lonhost} = 1;
12636: }
1.412 raeburn 12637: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12638: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
12639: }
12640: } else {
1.425 raeburn 12641: if ($saml{$lonhost}) {
1.389 raeburn 12642: $changes{'saml'}{$lonhost} = 1;
12643: delete($currsaml{$lonhost});
12644: }
1.386 raeburn 12645: }
12646: }
12647: foreach my $posshost (keys(%currsaml)) {
1.425 raeburn 12648: unless (exists($domservers{$posshost})) {
12649: delete($currsaml{$posshost});
1.386 raeburn 12650: }
12651: }
12652: %{$loginhash{'login'}{'saml'}} = %currsaml;
12653: if (@newsamlimgs) {
12654: my $error;
12655: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12656: if ($configuserok eq 'ok') {
12657: if ($switchserver) {
12658: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
12659: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12660: my $modified = [];
1.386 raeburn 12661: foreach my $lonhost (@newsamlimgs) {
12662: my $formelem = 'saml_img_'.$lonhost;
1.425 raeburn 12663: my ($result,$imgurl) =
1.421 raeburn 12664: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12665: "login/saml/$lonhost",'','',
12666: $env{'form.saml_img_'.$lonhost.'.filename'},
12667: $modified);
1.386 raeburn 12668: if ($result eq 'ok') {
12669: $currsaml{$lonhost}{'img'} = $imgurl;
12670: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
12671: $changes{'saml'}{$lonhost} = 1;
12672: } else {
12673: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
12674: $lonhost,$result);
12675: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12676: }
12677: }
1.421 raeburn 12678: &update_modify_urls($r,$modified);
1.386 raeburn 12679: } else {
12680: $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);
12681: }
12682: } else {
12683: $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);
12684: }
12685: if ($error) {
12686: &Apache::lonnet::logthis($error);
12687: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12688: }
12689: }
1.169 raeburn 12690: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 12691:
12692: my $defaulthelpfile = '/adm/loginproblems.html';
12693: my $defaulttext = &mt('Default in use');
12694:
1.1 raeburn 12695: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
12696: $dom);
12697: if ($putresult eq 'ok') {
1.188 raeburn 12698: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12699: my %defaultchecked = (
12700: 'coursecatalog' => 'on',
1.188 raeburn 12701: 'helpdesk' => 'on',
1.42 raeburn 12702: 'adminmail' => 'off',
1.43 raeburn 12703: 'newuser' => 'off',
1.42 raeburn 12704: );
1.55 raeburn 12705: if (ref($domconfig{'login'}) eq 'HASH') {
12706: foreach my $item (@toggles) {
12707: if ($defaultchecked{$item} eq 'on') {
12708: if (($domconfig{'login'}{$item} eq '0') &&
12709: ($env{'form.'.$item} eq '1')) {
12710: $changes{$item} = 1;
12711: } elsif (($domconfig{'login'}{$item} eq '' ||
12712: $domconfig{'login'}{$item} eq '1') &&
12713: ($env{'form.'.$item} eq '0')) {
12714: $changes{$item} = 1;
12715: }
12716: } elsif ($defaultchecked{$item} eq 'off') {
12717: if (($domconfig{'login'}{$item} eq '1') &&
12718: ($env{'form.'.$item} eq '0')) {
12719: $changes{$item} = 1;
12720: } elsif (($domconfig{'login'}{$item} eq '' ||
12721: $domconfig{'login'}{$item} eq '0') &&
12722: ($env{'form.'.$item} eq '1')) {
12723: $changes{$item} = 1;
12724: }
1.42 raeburn 12725: }
12726: }
1.41 raeburn 12727: }
1.6 raeburn 12728: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 12729: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.386 raeburn 12730: if (exists($changes{'saml'})) {
12731: my $hostid_in_use;
12732: my @hosts = &Apache::lonnet::current_machine_ids();
12733: if (@hosts > 1) {
12734: foreach my $hostid (@hosts) {
12735: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
12736: $hostid_in_use = $hostid;
12737: last;
12738: }
12739: }
12740: } else {
12741: $hostid_in_use = $r->dir_config('lonHostID');
12742: }
12743: if (($hostid_in_use) &&
12744: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
1.387 raeburn 12745: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
1.386 raeburn 12746: }
12747: if (ref($lastactref) eq 'HASH') {
12748: if (ref($changes{'saml'}) eq 'HASH') {
12749: my %updates;
12750: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
12751: $lastactref->{'samllanding'} = \%updates;
12752: }
12753: }
12754: }
1.212 raeburn 12755: if (ref($lastactref) eq 'HASH') {
12756: $lastactref->{'domainconfig'} = 1;
12757: }
1.1 raeburn 12758: $resulttext = &mt('Changes made:').'<ul>';
12759: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 12760: if ($item eq 'loginvia') {
1.112 raeburn 12761: if (ref($changes{$item}) eq 'HASH') {
12762: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
12763: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 12764: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
12765: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
12766: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
12767: $protocol = 'http' if ($protocol ne 'https');
12768: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
12769:
12770: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
12771: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
12772: } else {
12773: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
12774: }
12775: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
12776: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
12777: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
12778: }
12779: $resulttext .= '</li>';
12780: } else {
12781: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
12782: }
1.112 raeburn 12783: } else {
1.128 raeburn 12784: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 12785: }
12786: }
1.128 raeburn 12787: $resulttext .= '</ul></li>';
1.112 raeburn 12788: }
1.168 raeburn 12789: } elsif ($item eq 'helpurl') {
12790: if (ref($changes{$item}) eq 'HASH') {
12791: foreach my $lang (sort(keys(%{$changes{$item}}))) {
12792: if (grep(/^\Q$lang\E$/,@delurls)) {
12793: my ($chg,$link);
12794: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
12795: if ($lang eq 'nolang') {
12796: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
12797: } else {
12798: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
12799: }
12800: $resulttext .= '<li>'.$chg.'</li>';
12801: } else {
12802: my $chg;
12803: if ($lang eq 'nolang') {
12804: $chg = &mt('custom log-in help file for no preferred language');
12805: } else {
12806: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
12807: }
12808: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
12809: $loginhash{'login'}{'helpurl'}{$lang}.
12810: '?inhibitmenu=yes',$chg,600,500).
12811: '</li>';
12812: }
12813: }
12814: }
1.256 raeburn 12815: } elsif ($item eq 'headtag') {
12816: if (ref($changes{$item}) eq 'HASH') {
12817: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12818: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12819: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
12820: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12821: $resulttext .= '<li><a href="'.
12822: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
12823: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
12824: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
12825: if ($possexempt{$lonhost}) {
12826: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
12827: } else {
12828: $resulttext .= &mt('included for any client IP');
12829: }
12830: $resulttext .= '</li>';
12831: }
12832: }
12833: }
1.386 raeburn 12834: } elsif ($item eq 'saml') {
12835: if (ref($changes{$item}) eq 'HASH') {
12836: my %notlt = (
12837: text => 'Text for log-in by SSO',
12838: img => 'SSO button image',
12839: alt => 'Alt text for button image',
12840: url => 'SSO URL',
12841: title => 'Tooltip for SSO link',
1.412 raeburn 12842: window => 'Pop-up window if iframe',
1.386 raeburn 12843: notsso => 'Text for non-SSO log-in',
12844: );
12845: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12846: if (ref($currsaml{$lonhost}) eq 'HASH') {
12847: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
12848: '<ul>';
1.412 raeburn 12849: foreach my $key ('text','img','alt','url','title','window','notsso') {
1.386 raeburn 12850: if ($currsaml{$lonhost}{$key} eq '') {
12851: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
12852: } else {
12853: my $value = "'$currsaml{$lonhost}{$key}'";
12854: if ($key eq 'img') {
12855: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
1.412 raeburn 12856: } elsif ($key eq 'window') {
12857: $value = 'On';
1.386 raeburn 12858: }
12859: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
12860: $value).'</li>';
12861: }
12862: }
12863: $resulttext .= '</ul></li>';
12864: } else {
12865: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
12866: }
12867: }
12868: }
1.169 raeburn 12869: } elsif ($item eq 'captcha') {
12870: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 12871: my $chgtxt;
1.169 raeburn 12872: if ($loginhash{'login'}{$item} eq 'notused') {
12873: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
12874: } else {
12875: my %captchas = &captcha_phrases();
12876: if ($captchas{$loginhash{'login'}{$item}}) {
12877: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
12878: } else {
12879: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
12880: }
12881: }
12882: $resulttext .= '<li>'.$chgtxt.'</li>';
12883: }
12884: } elsif ($item eq 'recaptchakeys') {
12885: if (ref($loginhash{'login'}) eq 'HASH') {
12886: my ($privkey,$pubkey);
12887: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
12888: $pubkey = $loginhash{'login'}{$item}{'public'};
12889: $privkey = $loginhash{'login'}{$item}{'private'};
12890: }
12891: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
12892: if (!$pubkey) {
12893: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
12894: } else {
12895: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
12896: }
12897: if (!$privkey) {
12898: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
12899: } else {
1.251 raeburn 12900: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 12901: }
12902: $chgtxt .= '</ul>';
12903: $resulttext .= '<li>'.$chgtxt.'</li>';
12904: }
1.269 raeburn 12905: } elsif ($item eq 'recaptchaversion') {
12906: if (ref($loginhash{'login'}) eq 'HASH') {
12907: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 12908: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 12909: '</li>';
12910: }
12911: }
1.41 raeburn 12912: } else {
12913: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
12914: }
1.1 raeburn 12915: }
1.6 raeburn 12916: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 12917: } else {
12918: $resulttext = &mt('No changes made to log-in page settings');
12919: }
12920: } else {
1.11 albertel 12921: $resulttext = '<span class="LC_error">'.
12922: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12923: }
1.6 raeburn 12924: if ($errors) {
1.9 raeburn 12925: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 12926: $errors.'</ul>';
12927: }
12928: return $resulttext;
12929: }
12930:
1.256 raeburn 12931: sub check_exempt_addresses {
12932: my ($iplist) = @_;
12933: $iplist =~ s/^\s+//;
12934: $iplist =~ s/\s+$//;
12935: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
12936: my (@okips,$new);
12937: foreach my $ip (@poss_ips) {
12938: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
12939: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
12940: push(@okips,$ip);
12941: }
12942: }
12943: }
12944: if (@okips > 0) {
12945: $new = join(',',@okips);
12946: } else {
12947: $new = '';
12948: }
12949: return $new;
12950: }
12951:
1.6 raeburn 12952: sub color_font_choices {
12953: my %choices =
12954: &Apache::lonlocal::texthash (
12955: img => "Header",
12956: bgs => "Background colors",
12957: links => "Link colors",
1.55 raeburn 12958: images => "Images",
1.6 raeburn 12959: font => "Font color",
1.201 raeburn 12960: fontmenu => "Font menu",
1.76 raeburn 12961: pgbg => "Page",
1.6 raeburn 12962: tabbg => "Header",
12963: sidebg => "Border",
12964: link => "Link",
12965: alink => "Active link",
12966: vlink => "Visited link",
12967: );
12968: return %choices;
12969: }
12970:
1.394 raeburn 12971: sub modify_ipaccess {
12972: my ($dom,$lastactref,%domconfig) = @_;
12973: my (@allpos,%changes,%confhash,$errors,$resulttext);
12974: my (@items,%deletions,%itemids,@warnings);
12975: my ($typeorder,$types) = &commblocktype_text();
12976: if ($env{'form.ipaccess_add'}) {
12977: my $name = $env{'form.ipaccess_name_add'};
12978: my ($newid,$error) = &get_ipaccess_id($dom,$name);
12979: if ($newid) {
12980: $itemids{'add'} = $newid;
12981: push(@items,'add');
12982: $changes{$newid} = 1;
12983: } else {
12984: $error = &mt('Failed to acquire unique ID for new IP access control item');
12985: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12986: }
12987: }
12988: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
12989: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
12990: if (@todelete) {
12991: map { $deletions{$_} = 1; } @todelete;
12992: }
12993: my $maxnum = $env{'form.ipaccess_maxnum'};
12994: for (my $i=0; $i<$maxnum; $i++) {
12995: my $itemid = $env{'form.ipaccess_id_'.$i};
12996: $itemid =~ s/\D+//g;
12997: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
12998: if ($deletions{$itemid}) {
12999: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
13000: } else {
13001: push(@items,$i);
13002: $itemids{$i} = $itemid;
13003: }
13004: }
13005: }
13006: }
13007: foreach my $idx (@items) {
13008: my $itemid = $itemids{$idx};
13009: next unless ($itemid);
13010: my %current;
13011: unless ($idx eq 'add') {
13012: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13013: %current = %{$domconfig{'ipaccess'}{$itemid}};
13014: }
13015: }
13016: my $position = $env{'form.ipaccess_pos_'.$itemid};
13017: $position =~ s/\D+//g;
13018: if ($position ne '') {
13019: $allpos[$position] = $itemid;
13020: }
13021: my $name = $env{'form.ipaccess_name_'.$idx};
13022: $name =~ s/^\s+|\s+$//g;
13023: $confhash{$itemid}{'name'} = $name;
13024: my $possrange = $env{'form.ipaccess_range_'.$idx};
13025: $possrange =~ s/^\s+|\s+$//g;
13026: unless ($possrange eq '') {
13027: $possrange =~ s/[\r\n]+/\s/g;
13028: $possrange =~ s/\s*-\s*/-/g;
13029: $possrange =~ s/\s+/,/g;
13030: $possrange =~ s/,+/,/g;
13031: if ($possrange ne '') {
13032: my (@ok,$count);
1.425 raeburn 13033: $count = 0;
1.394 raeburn 13034: foreach my $poss (split(/\,/,$possrange)) {
13035: $count ++;
13036: $poss = &validate_ip_pattern($poss);
13037: if ($poss ne '') {
13038: push(@ok,$poss);
13039: }
13040: }
13041: my $diff = $count - scalar(@ok);
13042: if ($diff) {
13043: $errors .= '<li><span class="LC_error">'.
13044: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
13045: $diff,$name).
13046: '</span></li>';
13047: }
13048: if (@ok) {
13049: my @cidr_list;
13050: foreach my $item (@ok) {
13051: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
13052: }
13053: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
13054: }
13055: }
13056: }
13057: foreach my $field ('name','ip') {
13058: unless (($idx eq 'add') || ($changes{$itemid})) {
13059: if ($current{$field} ne $confhash{$itemid}{$field}) {
13060: $changes{$itemid} = 1;
13061: last;
13062: }
13063: }
13064: }
13065: $confhash{$itemid}{'commblocks'} = {};
1.425 raeburn 13066:
1.394 raeburn 13067: my %commblocks;
1.425 raeburn 13068: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
1.394 raeburn 13069: foreach my $type (@{$typeorder}) {
13070: if ($commblocks{$type}) {
13071: $confhash{$itemid}{'commblocks'}{$type} = 'on';
13072: }
13073: unless (($idx eq 'add') || ($changes{$itemid})) {
13074: if (ref($current{'commblocks'}) eq 'HASH') {
13075: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
13076: $changes{$itemid} = 1;
13077: }
13078: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
13079: $changes{$itemid} = 1;
13080: }
13081: }
13082: }
13083: $confhash{$itemid}{'courses'} = {};
13084: my %crsdeletions;
13085: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
13086: if (@delcrs) {
13087: map { $crsdeletions{$_} = 1; } @delcrs;
13088: }
13089: if (ref($current{'courses'}) eq 'HASH') {
13090: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
13091: if ($crsdeletions{$cid}) {
13092: $changes{$itemid} = 1;
13093: } else {
13094: $confhash{$itemid}{'courses'}{$cid} = 1;
13095: }
13096: }
13097: }
13098: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
13099: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
1.425 raeburn 13100: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
1.394 raeburn 13101: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
13102: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
13103: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
13104: $errors .= '<li><span class="LC_error">'.
13105: &mt('Invalid courseID [_1] omitted from list of allowed courses',
13106: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
13107: '</span></li>';
13108: } else {
13109: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
13110: $changes{$itemid} = 1;
13111: }
13112: }
13113: }
13114: if (@allpos > 0) {
13115: my $idx = 0;
13116: foreach my $itemid (@allpos) {
13117: if ($itemid ne '') {
13118: $confhash{$itemid}{'order'} = $idx;
13119: unless ($changes{$itemid}) {
13120: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
13121: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13122: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
13123: $changes{$itemid} = 1;
13124: }
13125: }
13126: }
13127: }
13128: $idx ++;
13129: }
13130: }
13131: }
13132: if (keys(%changes)) {
13133: my %defaultshash = (
13134: ipaccess => \%confhash,
13135: );
13136: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13137: $dom);
13138: if ($putresult eq 'ok') {
13139: my $cachetime = 1800;
13140: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
13141: if (ref($lastactref) eq 'HASH') {
13142: $lastactref->{'ipaccess'} = 1;
13143: }
13144: $resulttext = &mt('Changes made:').'<ul>';
13145: my %bynum;
13146: foreach my $itemid (sort(keys(%changes))) {
13147: if (ref($confhash{$itemid}) eq 'HASH') {
13148: my $position = $confhash{$itemid}{'order'};
13149: if ($position =~ /^\d+$/) {
13150: $bynum{$position} = $itemid;
13151: }
13152: }
13153: }
13154: if (keys(%deletions)) {
13155: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
13156: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
13157: }
13158: }
13159: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
13160: my $itemid = $bynum{$pos};
13161: if (ref($confhash{$itemid}) eq 'HASH') {
13162: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
13163: my $position = $pos + 1;
13164: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
13165: if ($confhash{$itemid}{'ip'} eq '') {
13166: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
13167: } else {
13168: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
13169: }
13170: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
13171: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
13172: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
13173: '</li>';
13174: } else {
13175: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
13176: }
13177: if (keys(%{$confhash{$itemid}{'courses'}})) {
13178: my @courses;
13179: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
1.425 raeburn 13180: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1.394 raeburn 13181: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
13182: }
13183: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
13184: join('</li><li>',@courses).'</li></ul>';
13185: } else {
13186: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
13187: }
1.395 raeburn 13188: $resulttext .= '</ul></li>';
1.394 raeburn 13189: }
13190: }
1.395 raeburn 13191: $resulttext .= '</ul>';
1.394 raeburn 13192: } else {
13193: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13194: }
13195: } else {
13196: $resulttext = &mt('No changes made');
13197: }
13198: if ($errors) {
13199: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
13200: $errors.'</ul></p>';
13201: }
13202: return $resulttext;
13203: }
13204:
13205: sub get_ipaccess_id {
13206: my ($domain,$location) = @_;
13207: # get lock on ipaccess db
13208: my $lockhash = {
13209: lock => $env{'user.name'}.
13210: ':'.$env{'user.domain'},
13211: };
13212: my $tries = 0;
13213: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13214: my ($id,$error);
13215:
13216: while (($gotlock ne 'ok') && ($tries<10)) {
13217: $tries ++;
13218: sleep (0.1);
13219: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13220: }
13221: if ($gotlock eq 'ok') {
13222: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
13223: if ($currids{'lock'}) {
13224: delete($currids{'lock'});
13225: if (keys(%currids)) {
13226: my @curr = sort { $a <=> $b } keys(%currids);
13227: if ($curr[-1] =~ /^\d+$/) {
13228: $id = 1 + $curr[-1];
13229: }
13230: } else {
13231: $id = 1;
13232: }
13233: if ($id) {
13234: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
13235: $error = 'nostore';
13236: }
13237: } else {
13238: $error = 'nonumber';
13239: }
13240: }
13241: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
13242: } else {
13243: $error = 'nolock';
13244: }
13245: return ($id,$error);
13246: }
13247:
1.429 raeburn 13248: sub modify_authordefaults {
13249: my ($dom,$lastactref,%domconfig) = @_;
13250: #
13251: # Retrieve current domain configuration for webDAV and Authoring Space quotas from $domconfig{'quotas'}.
13252: #
13253: my (%curr_quotas,%save_quotas,%confhash,%changes,%newvalues);
13254: if (ref($domconfig{'quotas'}) eq 'HASH') {
13255: foreach my $key (keys(%{$domconfig{'quotas'}})) {
13256: if ($key =~ /^webdav|authorquota$/) {
13257: $curr_quotas{$key} = $domconfig{'quotas'}{$key};
13258: } else {
13259: $save_quotas{$key} = $domconfig{'quotas'}{$key};
13260: }
13261: }
13262: }
13263: my %staticdefaults = (
13264: 'copyright' => 'default',
13265: 'sourceavail' => 'closed',
13266: 'nocodemirror' => 'off',
13267: 'domcoordacc' => 'on',
13268: 'editors' => ['edit','xml'].
13269: 'authorquota' => 500,
13270: 'webdav' => 0,
13271: );
13272: my %titles = &authordefaults_titles();
13273: foreach my $item ('nocodemirror','domcoordacc') {
13274: if ($env{'form.'.$item} =~ /^(0|1)$/) {
13275: $confhash{$item} = $env{'form.'.$item};
13276: }
13277: }
13278: if ($env{'form.copyright'} =~ /^(default|domain|public)$/) {
13279: $confhash{'copyright'} = $1;
13280: }
13281: if ($env{'form.sourceavail'} =~ /^(closed|open)$/) {
13282: $confhash{'sourceavail'} = $1;
13283: }
13284: my @posseditors = &Apache::loncommon::get_env_multiple('form.author_editors');
13285: my @okeditors = ('edit','xml','daxe');
13286: my @editors;
13287: foreach my $item (@posseditors) {
13288: if (grep(/^\Q$item\E$/,@okeditors)) {
13289: push(@editors,$item);
13290: }
13291: }
13292: $confhash{'editors'} = \@editors;
13293:
13294: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13295: my @insttypes;
13296: if (ref($types) eq 'ARRAY') {
13297: @insttypes = @{$types};
13298: }
13299: my @webdavon = &Apache::loncommon::get_env_multiple('form.webdav');
13300: my %webdav;
13301: map { $webdav{$_} = 1; } @webdavon;
13302: foreach my $type (@insttypes,'default') {
13303: my $possquota = $env{'form.authorquota_'.$type};
13304: if ($possquota =~ /^\d+$/) {
13305: $save_quotas{'authorquota'}{$type} = $possquota;
13306: }
13307: if ($webdav{$type}) {
13308: $save_quotas{'webdav'}{$type} = 1;
13309: } else {
13310: $save_quotas{'webdav'}{$type} = 0;
13311: }
13312: }
13313: if ($env{'form.webdav_LC_adv'} =~ /^(0|1)$/) {
13314: $save_quotas{'webdav'}{'_LC_adv'} = $env{'form.webdav_LC_adv'};
13315: }
13316: if (ref($domconfig{'authordefaults'}) eq 'HASH') {
13317: foreach my $item ('nocodemirror','domcoordacc','copyright','sourceavail') {
13318: if ($domconfig{'authordefaults'}{$item} ne $confhash{$item}) {
13319: $changes{$item} = 1;
13320: }
13321: }
13322: if (ref($domconfig{'authordefaults'}{'editors'}) eq 'ARRAY') {
13323: my @diffs =
13324: &Apache::loncommon::compare_arrays($confhash{'editors'},
13325: $domconfig{'authordefaults'}{'editors'});
13326: unless (@diffs == 0) {
13327: $changes{'editors'} = 1;
13328: }
13329: } else {
13330: my @diffs =
13331: &Apache::loncommon::compare_arrays($confhash{'editors'},
13332: $staticdefaults{'editors'});
13333: unless (@diffs == 0) {
13334: $changes{'editors'} = 1;
13335: }
13336: }
13337: } else {
13338: my @offon = ('off','on');
13339: foreach my $item ('nocodemirror','domcoordacc') {
13340: if ($offon[$confhash{$item}] ne $staticdefaults{$item}) {
13341: $changes{$item} = 1;
13342: }
13343: }
13344: foreach my $item ('copyright','sourceavail') {
13345: if ($confhash{$item} ne $staticdefaults{$item}) {
13346: $changes{$item} = 1;
13347: }
13348: }
13349: }
13350: foreach my $key ('authorquota','webdav') {
13351: if (ref($curr_quotas{$key}) eq 'HASH') {
13352: foreach my $type (@insttypes,'default') {
13353: if (exists($save_quotas{$key}{$type})) {
13354: if ($save_quotas{$key}{$type} ne $curr_quotas{$key}{$type}) {
13355: $changes{$key}{$type} = 1;
13356: }
13357: } elsif (exists($curr_quotas{$key}{$type})) {
13358: $save_quotas{$key}{$type} = $curr_quotas{$key}{$type};
13359: } else {
13360: $save_quotas{$key}{$type} = $staticdefaults{$key};
13361: }
13362: }
13363: } else {
13364: foreach my $type (@insttypes,'default') {
13365: if (exists($save_quotas{$key}{$type})) {
13366: unless ($save_quotas{$key}{$type} eq $staticdefaults{$key}) {
13367: $changes{$key}{$type} = 1;
13368: }
13369: } else {
13370: $save_quotas{$key}{$type} = $staticdefaults{$key};
13371: }
13372: }
13373: }
13374: }
13375: if (ref($curr_quotas{'webdav'}) eq 'HASH') {
13376: if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
13377: if ($save_quotas{'webdav'}{'_LC_adv'} ne $curr_quotas{'webdav'}{'_LC_adv'}) {
13378: $changes{'webdav_LC_adv'} = 1;
13379: }
13380: } elsif (exists($curr_quotas{'webdav'}{'_LC_adv'})) {
13381: $changes{'webdav_LC_adv'} = 1;
13382: }
13383: } elsif (exists($save_quotas{'webdav'}{'_LC_adv'})) {
13384: $changes{'webdav_LC_adv'} = 1;
13385: }
13386: my %confighash = (
13387: quotas => \%save_quotas,
13388: authordefaults => \%confhash,
13389: );
13390: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,
13391: $dom);
13392: my $resulttext;
13393: if ($putresult eq 'ok') {
13394: if (keys(%changes)) {
1.431 ! raeburn 13395: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.429 raeburn 13396: if ((exists($changes{'authorquota'})) || (exists($changes{'webdav'})) ||
13397: ($changes{'webdav_LC_adv'})) {
13398: if ((exists($changes{'authorquota'})) && (ref($save_quotas{'authorquota'}) eq 'HASH')) {
13399: $domdefaults{'authorquota'} = $save_quotas{'authorquota'};
13400: }
13401: if (((exists($changes{'webdav'})) || ($changes{'webdav_LC_adv'})) &&
13402: (ref($save_quotas{'webdav'}) eq 'HASH')) {
13403: $domdefaults{'webdav'} = $save_quotas{'webdav'};
13404: }
13405: }
13406: $resulttext = &mt('Changes made:').'<ul>';
13407: my $authoroverride;
13408: foreach my $key ('nocodemirror','domcoordacc','copyright','sourceavail') {
13409: if (exists($changes{$key})) {
1.431 ! raeburn 13410: $domdefaults{$key} = $confhash{$key};
1.429 raeburn 13411: my $shown;
13412: unless ($authoroverride) {
13413: $resulttext .= '<li>'.&mt('Defaults which can be overridden by Author').'<ul>';
13414: $authoroverride = 1;
13415: }
13416: if (($key eq 'nocodemirror') || ($key eq 'domcoordacc')) {
13417: $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
13418: } elsif ($key eq 'copyright') {
13419: $shown = &Apache::loncommon::copyrightdescription($confhash{$key});
13420: } elsif ($key eq 'sourceavail') {
13421: $shown = &Apache::loncommon::source_copyrightdescription($confhash{$key});
13422: }
13423: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
13424: }
13425: }
13426: if ($authoroverride) {
13427: $resulttext .= '</ul></li>';
13428: }
13429: my $domcoordoverride;
13430: foreach my $key ('editors','authorquota','webdav','webdav_LC_adv') {
13431: if (exists($changes{$key})) {
13432: my $shown;
13433: unless ($domcoordoverride) {
13434: $resulttext .= '<li>'.&mt('Defaults which can be overridden by a Domain Coodinator').'<ul>';
13435: $domcoordoverride = 1;
13436: }
13437: if ($key eq 'editors') {
1.431 ! raeburn 13438: if (ref($confhash{'editors'}) eq 'ARRAY') {
! 13439: $domdefaults{'editors'} = join(',',@{$confhash{'editors'}});
! 13440: if (@{$confhash{'editors'}}) {
! 13441: $shown = join(', ', map { $titles{$_} } @{$confhash{'editors'}});
! 13442: } else {
! 13443: $shown = &mt('None');
! 13444: }
1.429 raeburn 13445: }
13446: } elsif ($key eq 'authorquota') {
13447: foreach my $type (@insttypes) {
13448: $shown .= $usertypes->{$type}.' -- '.$save_quotas{$key}{$type}.', ';
13449: }
13450: $shown .= $othertitle.' -- '.$save_quotas{$key}{'default'};
13451: } elsif ($key eq 'webdav') {
13452: foreach my $type (@insttypes) {
13453: $shown .= $usertypes->{$type}.' -- '. ($save_quotas{$key}{$type} ? &mt('Yes') : &mt('No')).', ';
13454: }
13455: $shown .= $othertitle.' -- '. ($save_quotas{$key}{'default'} ? &mt('Yes') : &mt('No'));
13456: } elsif ($key eq 'webdav_LC_adv') {
13457: if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
13458: $shown = ($save_quotas{'webdav'}{'_LC_adv'} ? $titles{'overon'} : $titles{'overoff'});
13459: } else {
13460: $shown = $titles{'none'};
13461: }
13462: }
13463: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
13464: }
13465: }
13466: if ($domcoordoverride) {
13467: $resulttext .= '</ul></li>';
13468: }
1.431 ! raeburn 13469: my $cachetime = 24*60*60;
! 13470: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
! 13471: if (ref($lastactref) eq 'HASH') {
! 13472: $lastactref->{'domdefaults'} = 1;
! 13473: }
1.429 raeburn 13474: } else {
13475: $resulttext = &mt('No changes made to Authoring Space defaults');
13476: }
13477: }
13478: return $resulttext;
13479: }
13480:
1.6 raeburn 13481: sub modify_rolecolors {
1.205 raeburn 13482: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 13483: my ($resulttext,%rolehash);
13484: $rolehash{'rolecolors'} = {};
1.55 raeburn 13485: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
13486: if ($domconfig{'rolecolors'} eq '') {
13487: $domconfig{'rolecolors'} = {};
13488: }
13489: }
1.9 raeburn 13490: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 13491: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
13492: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
13493: $dom);
13494: if ($putresult eq 'ok') {
13495: if (keys(%changes) > 0) {
1.41 raeburn 13496: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 13497: if (ref($lastactref) eq 'HASH') {
13498: $lastactref->{'domainconfig'} = 1;
13499: }
1.6 raeburn 13500: $resulttext = &display_colorchgs($dom,\%changes,$roles,
13501: $rolehash{'rolecolors'});
13502: } else {
13503: $resulttext = &mt('No changes made to default color schemes');
13504: }
13505: } else {
1.11 albertel 13506: $resulttext = '<span class="LC_error">'.
13507: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 13508: }
13509: if ($errors) {
13510: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
13511: $errors.'</ul>';
13512: }
13513: return $resulttext;
13514: }
13515:
13516: sub modify_colors {
1.9 raeburn 13517: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 13518: my (%changes,%choices);
1.51 raeburn 13519: my @bgs;
1.6 raeburn 13520: my @links = ('link','alink','vlink');
1.41 raeburn 13521: my @logintext;
1.6 raeburn 13522: my @images;
13523: my $servadm = $r->dir_config('lonAdmEMail');
13524: my $errors;
1.200 raeburn 13525: my %defaults;
1.6 raeburn 13526: foreach my $role (@{$roles}) {
13527: if ($role eq 'login') {
1.12 raeburn 13528: %choices = &login_choices();
1.41 raeburn 13529: @logintext = ('textcol','bgcol');
1.12 raeburn 13530: } else {
13531: %choices = &color_font_choices();
13532: }
13533: if ($role eq 'login') {
1.41 raeburn 13534: @images = ('img','logo','domlogo','login');
1.51 raeburn 13535: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 13536: } else {
13537: @images = ('img');
1.200 raeburn 13538: @bgs = ('pgbg','tabbg','sidebg');
13539: }
13540: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
13541: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
13542: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
13543: }
13544: if ($role eq 'login') {
13545: foreach my $item (@logintext) {
1.234 raeburn 13546: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13547: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13548: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13549: }
13550: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 13551: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13552: }
13553: }
13554: } else {
1.234 raeburn 13555: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
13556: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
13557: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
13558: }
13559: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 13560: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
13561: }
1.6 raeburn 13562: }
1.200 raeburn 13563: foreach my $item (@bgs) {
1.234 raeburn 13564: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13565: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13566: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13567: }
13568: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 13569: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13570: }
13571: }
13572: foreach my $item (@links) {
1.234 raeburn 13573: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13574: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13575: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13576: }
13577: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 13578: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13579: }
1.6 raeburn 13580: }
1.46 raeburn 13581: my ($configuserok,$author_ok,$switchserver) =
13582: &config_check($dom,$confname,$servadm);
1.9 raeburn 13583: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 13584: if (ref($domconfig->{$role}) ne 'HASH') {
13585: $domconfig->{$role} = {};
13586: }
1.8 raeburn 13587: foreach my $img (@images) {
1.402 raeburn 13588: if ($role eq 'login') {
13589: if (($img eq 'img') || ($img eq 'logo')) {
13590: if (defined($env{'form.login_showlogo_'.$img})) {
13591: $confhash->{$role}{'showlogo'}{$img} = 1;
13592: } else {
13593: $confhash->{$role}{'showlogo'}{$img} = 0;
13594: }
13595: }
13596: if ($env{'form.login_alt_'.$img} ne '') {
13597: $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
1.70 raeburn 13598: }
1.402 raeburn 13599: }
1.18 albertel 13600: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
13601: && !defined($domconfig->{$role}{$img})
13602: && !$env{'form.'.$role.'_del_'.$img}
13603: && $env{'form.'.$role.'_import_'.$img}) {
13604: # import the old configured image from the .tab setting
13605: # if they haven't provided a new one
13606: $domconfig->{$role}{$img} =
13607: $env{'form.'.$role.'_import_'.$img};
13608: }
1.6 raeburn 13609: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 13610: my $error;
1.6 raeburn 13611: if ($configuserok eq 'ok') {
1.9 raeburn 13612: if ($switchserver) {
1.12 raeburn 13613: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 13614: } else {
13615: if ($author_ok eq 'ok') {
1.421 raeburn 13616: my $modified = [];
1.9 raeburn 13617: my ($result,$logourl) =
1.421 raeburn 13618: &Apache::lonconfigsettings::publishlogo($r,'upload',$role.'_'.$img,
13619: $dom,$confname,$img,$width,$height,
13620: '',$modified);
1.9 raeburn 13621: if ($result eq 'ok') {
13622: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 13623: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13624: &update_modify_urls($r,$modified);
1.9 raeburn 13625: } else {
1.12 raeburn 13626: $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 13627: }
13628: } else {
1.46 raeburn 13629: $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 13630: }
13631: }
13632: } else {
1.46 raeburn 13633: $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 13634: }
13635: if ($error) {
1.8 raeburn 13636: &Apache::lonnet::logthis($error);
1.11 albertel 13637: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 13638: }
13639: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 13640: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
13641: my $error;
13642: if ($configuserok eq 'ok') {
13643: # is confname an author?
13644: if ($switchserver eq '') {
13645: if ($author_ok eq 'ok') {
1.421 raeburn 13646: my $modified = [];
1.9 raeburn 13647: my ($result,$logourl) =
1.421 raeburn 13648: &Apache::lonconfigsettings::publishlogo($r,'copy',$domconfig->{$role}{$img},
13649: $dom,$confname,$img,$width,$height,
13650: '',$modified);
1.9 raeburn 13651: if ($result eq 'ok') {
13652: $confhash->{$role}{$img} = $logourl;
1.18 albertel 13653: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13654: &update_modify_urls($r,$modified);
1.9 raeburn 13655: }
13656: }
13657: }
13658: }
1.6 raeburn 13659: }
13660: }
13661: }
13662: if (ref($domconfig) eq 'HASH') {
13663: if (ref($domconfig->{$role}) eq 'HASH') {
13664: foreach my $img (@images) {
13665: if ($domconfig->{$role}{$img} ne '') {
13666: if ($env{'form.'.$role.'_del_'.$img}) {
13667: $confhash->{$role}{$img} = '';
1.12 raeburn 13668: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13669: } else {
1.9 raeburn 13670: if ($confhash->{$role}{$img} eq '') {
13671: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
13672: }
1.6 raeburn 13673: }
13674: } else {
13675: if ($env{'form.'.$role.'_del_'.$img}) {
13676: $confhash->{$role}{$img} = '';
1.12 raeburn 13677: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13678: }
13679: }
1.402 raeburn 13680: if ($role eq 'login') {
13681: if (($img eq 'logo') || ($img eq 'img')) {
13682: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
13683: if ($confhash->{$role}{'showlogo'}{$img} ne
13684: $domconfig->{$role}{'showlogo'}{$img}) {
13685: $changes{$role}{'showlogo'}{$img} = 1;
13686: }
13687: } else {
13688: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13689: $changes{$role}{'showlogo'}{$img} = 1;
13690: }
1.70 raeburn 13691: }
1.402 raeburn 13692: }
13693: if ($img ne 'login') {
13694: if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
13695: if ($confhash->{$role}{'alttext'}{$img} ne
13696: $domconfig->{$role}{'alttext'}{$img}) {
13697: $changes{$role}{'alttext'}{$img} = 1;
13698: }
13699: } else {
13700: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13701: $changes{$role}{'alttext'}{$img} = 1;
13702: }
1.70 raeburn 13703: }
13704: }
13705: }
13706: }
1.6 raeburn 13707: if ($domconfig->{$role}{'font'} ne '') {
13708: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
13709: $changes{$role}{'font'} = 1;
13710: }
13711: } else {
13712: if ($confhash->{$role}{'font'}) {
13713: $changes{$role}{'font'} = 1;
13714: }
13715: }
1.107 raeburn 13716: if ($role ne 'login') {
13717: if ($domconfig->{$role}{'fontmenu'} ne '') {
13718: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
13719: $changes{$role}{'fontmenu'} = 1;
13720: }
13721: } else {
13722: if ($confhash->{$role}{'fontmenu'}) {
13723: $changes{$role}{'fontmenu'} = 1;
13724: }
1.97 tempelho 13725: }
13726: }
1.6 raeburn 13727: foreach my $item (@bgs) {
13728: if ($domconfig->{$role}{$item} ne '') {
13729: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13730: $changes{$role}{'bgs'}{$item} = 1;
13731: }
13732: } else {
13733: if ($confhash->{$role}{$item}) {
13734: $changes{$role}{'bgs'}{$item} = 1;
13735: }
13736: }
13737: }
13738: foreach my $item (@links) {
13739: if ($domconfig->{$role}{$item} ne '') {
13740: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13741: $changes{$role}{'links'}{$item} = 1;
13742: }
13743: } else {
13744: if ($confhash->{$role}{$item}) {
13745: $changes{$role}{'links'}{$item} = 1;
13746: }
13747: }
13748: }
1.41 raeburn 13749: foreach my $item (@logintext) {
13750: if ($domconfig->{$role}{$item} ne '') {
13751: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13752: $changes{$role}{'logintext'}{$item} = 1;
13753: }
13754: } else {
13755: if ($confhash->{$role}{$item}) {
13756: $changes{$role}{'logintext'}{$item} = 1;
13757: }
13758: }
13759: }
1.6 raeburn 13760: } else {
13761: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13762: \@logintext,$confhash,\%changes);
1.6 raeburn 13763: }
13764: } else {
13765: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13766: \@logintext,$confhash,\%changes);
1.6 raeburn 13767: }
13768: }
13769: return ($errors,%changes);
13770: }
13771:
1.46 raeburn 13772: sub config_check {
13773: my ($dom,$confname,$servadm) = @_;
13774: my ($configuserok,$author_ok,$switchserver,%currroles);
13775: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
13776: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
13777: $confname,$servadm);
13778: if ($configuserok eq 'ok') {
13779: $switchserver = &check_switchserver($dom,$confname);
13780: if ($switchserver eq '') {
13781: $author_ok = &check_authorstatus($dom,$confname,%currroles);
13782: }
13783: }
13784: return ($configuserok,$author_ok,$switchserver);
13785: }
13786:
1.6 raeburn 13787: sub default_change_checker {
1.41 raeburn 13788: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 13789: foreach my $item (@{$links}) {
13790: if ($confhash->{$role}{$item}) {
13791: $changes->{$role}{'links'}{$item} = 1;
13792: }
13793: }
13794: foreach my $item (@{$bgs}) {
13795: if ($confhash->{$role}{$item}) {
13796: $changes->{$role}{'bgs'}{$item} = 1;
13797: }
13798: }
1.41 raeburn 13799: foreach my $item (@{$logintext}) {
13800: if ($confhash->{$role}{$item}) {
13801: $changes->{$role}{'logintext'}{$item} = 1;
13802: }
13803: }
1.6 raeburn 13804: foreach my $img (@{$images}) {
13805: if ($env{'form.'.$role.'_del_'.$img}) {
13806: $confhash->{$role}{$img} = '';
1.12 raeburn 13807: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 13808: }
1.70 raeburn 13809: if ($role eq 'login') {
13810: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13811: $changes->{$role}{'showlogo'}{$img} = 1;
13812: }
1.402 raeburn 13813: if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
13814: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13815: $changes->{$role}{'alttext'}{$img} = 1;
13816: }
13817: }
1.70 raeburn 13818: }
1.6 raeburn 13819: }
13820: if ($confhash->{$role}{'font'}) {
13821: $changes->{$role}{'font'} = 1;
13822: }
1.48 raeburn 13823: }
1.6 raeburn 13824:
13825: sub display_colorchgs {
13826: my ($dom,$changes,$roles,$confhash) = @_;
13827: my (%choices,$resulttext);
13828: if (!grep(/^login$/,@{$roles})) {
13829: $resulttext = &mt('Changes made:').'<br />';
13830: }
13831: foreach my $role (@{$roles}) {
13832: if ($role eq 'login') {
13833: %choices = &login_choices();
13834: } else {
13835: %choices = &color_font_choices();
13836: }
13837: if (ref($changes->{$role}) eq 'HASH') {
13838: if ($role ne 'login') {
13839: $resulttext .= '<h4>'.&mt($role).'</h4>';
13840: }
13841: foreach my $key (sort(keys(%{$changes->{$role}}))) {
13842: if ($role ne 'login') {
13843: $resulttext .= '<ul>';
13844: }
13845: if (ref($changes->{$role}{$key}) eq 'HASH') {
13846: if ($role ne 'login') {
13847: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
13848: }
13849: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 13850: if (($role eq 'login') && ($key eq 'showlogo')) {
13851: if ($confhash->{$role}{$key}{$item}) {
13852: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
13853: } else {
13854: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
13855: }
1.402 raeburn 13856: } elsif (($role eq 'login') && ($key eq 'alttext')) {
13857: if ($confhash->{$role}{$key}{$item} ne '') {
1.403 raeburn 13858: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
1.402 raeburn 13859: $confhash->{$role}{$key}{$item}).'</li>';
13860: } else {
13861: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
13862: }
1.70 raeburn 13863: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 13864: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
13865: } else {
1.12 raeburn 13866: my $newitem = $confhash->{$role}{$item};
13867: if ($key eq 'images') {
1.306 raeburn 13868: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 13869: }
13870: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 13871: }
13872: }
13873: if ($role ne 'login') {
13874: $resulttext .= '</ul></li>';
13875: }
13876: } else {
13877: if ($confhash->{$role}{$key} eq '') {
13878: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
13879: } else {
13880: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
13881: }
13882: }
13883: if ($role ne 'login') {
13884: $resulttext .= '</ul>';
13885: }
13886: }
13887: }
13888: }
1.3 raeburn 13889: return $resulttext;
1.1 raeburn 13890: }
13891:
1.9 raeburn 13892: sub thumb_dimensions {
13893: return ('200','50');
13894: }
13895:
1.16 raeburn 13896: sub check_dimensions {
13897: my ($inputfile) = @_;
13898: my ($fullwidth,$fullheight);
13899: if ($inputfile =~ m|^[/\w.\-]+$|) {
13900: if (open(PIPE,"identify $inputfile 2>&1 |")) {
13901: my $imageinfo = <PIPE>;
13902: if (!close(PIPE)) {
13903: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
13904: }
13905: chomp($imageinfo);
13906: my ($fullsize) =
1.21 raeburn 13907: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 13908: if ($fullsize) {
13909: ($fullwidth,$fullheight) = split(/x/,$fullsize);
13910: }
13911: }
13912: }
13913: return ($fullwidth,$fullheight);
13914: }
13915:
1.9 raeburn 13916: sub check_configuser {
13917: my ($uhome,$dom,$confname,$servadm) = @_;
13918: my ($configuserok,%currroles);
13919: if ($uhome eq 'no_host') {
13920: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.361 raeburn 13921: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 13922: $configuserok =
13923: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
13924: $configpass,'','','','','',undef,$servadm);
13925: } else {
13926: $configuserok = 'ok';
13927: %currroles =
13928: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
13929: }
13930: return ($configuserok,%currroles);
13931: }
13932:
13933: sub check_authorstatus {
13934: my ($dom,$confname,%currroles) = @_;
13935: my $author_ok;
1.40 raeburn 13936: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 13937: my $start = time;
13938: my $end = 0;
13939: $author_ok =
13940: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 13941: 'au',$end,$start,'','','domconfig');
1.9 raeburn 13942: } else {
13943: $author_ok = 'ok';
13944: }
13945: return $author_ok;
13946: }
13947:
1.421 raeburn 13948: sub update_modify_urls {
13949: my ($r,$modified) = @_;
13950: if ((ref($modified) eq 'ARRAY') && (@{$modified})) {
13951: push(@{$modified_urls},$modified);
13952: unless ($registered_cleanup) {
13953: my $handlers = $r->get_handlers('PerlCleanupHandler');
13954: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
13955: $registered_cleanup=1;
1.9 raeburn 13956: }
13957: }
1.155 raeburn 13958: }
13959:
13960: sub notifysubscribed {
13961: foreach my $targetsource (@{$modified_urls}){
13962: next unless (ref($targetsource) eq 'ARRAY');
13963: my ($target,$source)=@{$targetsource};
13964: if ($source ne '') {
1.316 raeburn 13965: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 13966: print $logfh "\nCleanup phase: Notifications\n";
13967: my @subscribed=&subscribed_hosts($target);
13968: foreach my $subhost (@subscribed) {
13969: print $logfh "\nNotifying host ".$subhost.':';
13970: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
13971: print $logfh $reply;
13972: }
13973: my @subscribedmeta=&subscribed_hosts("$target.meta");
13974: foreach my $subhost (@subscribedmeta) {
13975: print $logfh "\nNotifying host for metadata only ".$subhost.':';
13976: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
13977: $subhost);
13978: print $logfh $reply;
13979: }
13980: print $logfh "\n============ Done ============\n";
1.160 raeburn 13981: close($logfh);
1.155 raeburn 13982: }
13983: }
13984: }
13985: return OK;
13986: }
13987:
13988: sub subscribed_hosts {
13989: my ($target) = @_;
13990: my @subscribed;
1.316 raeburn 13991: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 13992: while (my $subline=<$fh>) {
13993: if ($subline =~ /^($match_lonid):/) {
13994: my $host = $1;
13995: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
13996: unless (grep(/^\Q$host\E$/,@subscribed)) {
13997: push(@subscribed,$host);
13998: }
13999: }
14000: }
14001: }
14002: }
14003: return @subscribed;
1.9 raeburn 14004: }
14005:
14006: sub check_switchserver {
14007: my ($dom,$confname) = @_;
1.424 raeburn 14008: my ($allowed,$switchserver,$home);
14009: if ($confname eq '') {
1.9 raeburn 14010: $home = &Apache::lonnet::domain($dom,'primary');
1.424 raeburn 14011: } else {
14012: $home = &Apache::lonnet::homeserver($confname,$dom);
14013: if ($home eq 'no_host') {
14014: $home = &Apache::lonnet::domain($dom,'primary');
14015: }
1.9 raeburn 14016: }
14017: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 14018: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
14019: if (!$allowed) {
1.426 raeburn 14020: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
14021: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
14022: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 14023: }
14024: return $switchserver;
14025: }
14026:
1.1 raeburn 14027: sub modify_quotas {
1.216 raeburn 14028: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 14029: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 14030: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 14031: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
14032: $validationfieldsref);
1.86 raeburn 14033: if ($action eq 'quotas') {
1.429 raeburn 14034: $context = 'tools';
1.163 raeburn 14035: } else {
1.86 raeburn 14036: $context = $action;
14037: }
14038: if ($context eq 'requestcourses') {
1.325 raeburn 14039: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 14040: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 14041: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
14042: %titles = &courserequest_titles();
14043: $toolregexp = join('|',@usertools);
14044: %conditions = &courserequest_conditions();
1.216 raeburn 14045: $confname = $dom.'-domainconfig';
14046: my $servadm = $r->dir_config('lonAdmEMail');
14047: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 14048: ($validationitemsref,$validationnamesref,$validationfieldsref) =
14049: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 14050: } elsif ($context eq 'requestauthor') {
14051: @usertools = ('author');
14052: %titles = &authorrequest_titles();
1.86 raeburn 14053: } else {
1.430 raeburn 14054: @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.101 raeburn 14055: %titles = &tool_titles();
1.86 raeburn 14056: }
1.212 raeburn 14057: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 14058: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 14059: foreach my $key (keys(%env)) {
1.101 raeburn 14060: if ($context eq 'requestcourses') {
14061: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
14062: my $item = $1;
14063: my $type = $2;
14064: if ($type =~ /^limit_(.+)/) {
14065: $limithash{$item}{$1} = $env{$key};
14066: } else {
14067: $confhash{$item}{$type} = $env{$key};
14068: }
14069: }
1.163 raeburn 14070: } elsif ($context eq 'requestauthor') {
14071: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
14072: $confhash{$1} = $env{$key};
14073: }
1.101 raeburn 14074: } else {
1.86 raeburn 14075: if ($key =~ /^form\.quota_(.+)$/) {
14076: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 14077: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 14078: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
14079: }
1.72 raeburn 14080: }
14081: }
1.163 raeburn 14082: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 14083: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 14084: @approvalnotify = sort(@approvalnotify);
14085: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 14086: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 14087: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
14088: foreach my $type (@hasuniquecode) {
14089: if (grep(/^\Q$type\E$/,@crstypes)) {
14090: $confhash{'uniquecode'}{$type} = 1;
14091: }
1.216 raeburn 14092: }
1.242 raeburn 14093: my (%newbook,%allpos);
1.216 raeburn 14094: if ($context eq 'requestcourses') {
1.242 raeburn 14095: foreach my $type ('textbooks','templates') {
14096: @{$allpos{$type}} = ();
14097: my $invalid;
14098: if ($type eq 'textbooks') {
14099: $invalid = &mt('Invalid LON-CAPA course for textbook');
14100: } else {
14101: $invalid = &mt('Invalid LON-CAPA course for template');
14102: }
14103: if ($env{'form.'.$type.'_addbook'}) {
14104: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
14105: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
14106: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
14107: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
14108: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
14109: } else {
14110: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
14111: my $position = $env{'form.'.$type.'_addbook_pos'};
14112: $position =~ s/\D+//g;
14113: if ($position ne '') {
14114: $allpos{$type}[$position] = $newbook{$type};
14115: }
1.216 raeburn 14116: }
1.242 raeburn 14117: } else {
14118: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 14119: }
14120: }
1.242 raeburn 14121: }
1.216 raeburn 14122: }
1.102 raeburn 14123: if (ref($domconfig{$action}) eq 'HASH') {
14124: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
14125: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
14126: $changes{'notify'}{'approval'} = 1;
14127: }
14128: } else {
1.144 raeburn 14129: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14130: $changes{'notify'}{'approval'} = 1;
14131: }
14132: }
1.218 raeburn 14133: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
14134: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14135: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
14136: unless ($confhash{'uniquecode'}{$crstype}) {
14137: $changes{'uniquecode'} = 1;
14138: }
14139: }
14140: unless ($changes{'uniquecode'}) {
14141: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
14142: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
14143: $changes{'uniquecode'} = 1;
14144: }
14145: }
14146: }
14147: } else {
14148: $changes{'uniquecode'} = 1;
14149: }
14150: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
14151: $changes{'uniquecode'} = 1;
1.216 raeburn 14152: }
14153: if ($context eq 'requestcourses') {
1.242 raeburn 14154: foreach my $type ('textbooks','templates') {
14155: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14156: my %deletions;
14157: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
14158: if (@todelete) {
14159: map { $deletions{$_} = 1; } @todelete;
14160: }
14161: my %imgdeletions;
14162: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
14163: if (@todeleteimages) {
14164: map { $imgdeletions{$_} = 1; } @todeleteimages;
14165: }
14166: my $maxnum = $env{'form.'.$type.'_maxnum'};
14167: for (my $i=0; $i<=$maxnum; $i++) {
14168: my $itemid = $env{'form.'.$type.'_id_'.$i};
14169: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
14170: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
14171: if ($deletions{$key}) {
14172: if ($domconfig{$action}{$type}{$key}{'image'}) {
14173: #FIXME need to obsolete item in RES space
14174: }
14175: next;
14176: } else {
14177: my $newpos = $env{'form.'.$itemid};
14178: $newpos =~ s/\D+//g;
1.243 raeburn 14179: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 14180: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 14181: ($type eq 'templates'));
1.242 raeburn 14182: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
14183: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
14184: $changes{$type}{$key} = 1;
14185: }
14186: }
14187: $allpos{$type}[$newpos] = $key;
14188: }
14189: if ($imgdeletions{$key}) {
14190: $changes{$type}{$key} = 1;
1.216 raeburn 14191: #FIXME need to obsolete item in RES space
1.242 raeburn 14192: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
14193: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 14194: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14195: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14196: } else {
14197: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
14198: $cdom,$cnum,$type,$configuserok,
14199: $switchserver,$author_ok);
14200: if ($imgurl) {
14201: $confhash{$type}{$key}{'image'} = $imgurl;
14202: $changes{$type}{$key} = 1;
14203: }
14204: if ($error) {
14205: &Apache::lonnet::logthis($error);
14206: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14207: }
14208: }
1.242 raeburn 14209: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
14210: $confhash{$type}{$key}{'image'} =
14211: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 14212: }
14213: }
14214: }
14215: }
14216: }
14217: }
1.102 raeburn 14218: } else {
1.144 raeburn 14219: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14220: $changes{'notify'}{'approval'} = 1;
14221: }
1.218 raeburn 14222: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 14223: $changes{'uniquecode'} = 1;
14224: }
14225: }
14226: if ($context eq 'requestcourses') {
1.242 raeburn 14227: foreach my $type ('textbooks','templates') {
14228: if ($newbook{$type}) {
14229: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 14230: foreach my $item ('subject','title','publisher','author') {
14231: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14232: ($type eq 'template'));
1.242 raeburn 14233: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
14234: if ($env{'form.'.$type.'_addbook_'.$item}) {
14235: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
14236: }
14237: }
14238: if ($type eq 'textbooks') {
14239: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
14240: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 14241: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14242: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14243: } else {
14244: my ($imageurl,$error) =
14245: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
14246: $configuserok,$switchserver,$author_ok);
14247: if ($imageurl) {
14248: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
14249: }
14250: if ($error) {
14251: &Apache::lonnet::logthis($error);
14252: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14253: }
1.242 raeburn 14254: }
14255: }
1.216 raeburn 14256: }
14257: }
1.242 raeburn 14258: if (@{$allpos{$type}} > 0) {
14259: my $idx = 0;
14260: foreach my $item (@{$allpos{$type}}) {
14261: if ($item ne '') {
14262: $confhash{$type}{$item}{'order'} = $idx;
14263: if (ref($domconfig{$action}) eq 'HASH') {
14264: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14265: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
14266: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
14267: $changes{$type}{$item} = 1;
14268: }
1.216 raeburn 14269: }
14270: }
14271: }
1.242 raeburn 14272: $idx ++;
1.216 raeburn 14273: }
14274: }
14275: }
14276: }
1.235 raeburn 14277: if (ref($validationitemsref) eq 'ARRAY') {
14278: foreach my $item (@{$validationitemsref}) {
14279: if ($item eq 'fields') {
14280: my @changed;
14281: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
14282: if (@{$confhash{'validation'}{$item}} > 0) {
14283: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
14284: }
1.266 raeburn 14285: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14286: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14287: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
14288: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
14289: $domconfig{'requestcourses'}{'validation'}{$item});
14290: } else {
14291: @changed = @{$confhash{'validation'}{$item}};
14292: }
1.235 raeburn 14293: } else {
14294: @changed = @{$confhash{'validation'}{$item}};
14295: }
14296: } else {
14297: @changed = @{$confhash{'validation'}{$item}};
14298: }
14299: if (@changed) {
14300: if ($confhash{'validation'}{$item}) {
14301: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
14302: } else {
14303: $changes{'validation'}{$item} = &mt('None');
14304: }
14305: }
14306: } else {
14307: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
14308: if ($item eq 'markup') {
14309: if ($env{'form.requestcourses_validation_'.$item}) {
14310: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
14311: }
14312: }
1.266 raeburn 14313: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14314: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14315: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
14316: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14317: }
14318: } else {
14319: if ($confhash{'validation'}{$item} ne '') {
14320: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14321: }
1.235 raeburn 14322: }
14323: } else {
14324: if ($confhash{'validation'}{$item} ne '') {
14325: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14326: }
14327: }
14328: }
14329: }
14330: }
14331: if ($env{'form.validationdc'}) {
14332: my $newval = $env{'form.validationdc'};
1.285 raeburn 14333: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 14334: if (exists($domcoords{$newval})) {
14335: $confhash{'validation'}{'dc'} = $newval;
14336: }
14337: }
14338: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 14339: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14340: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14341: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14342: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
14343: if ($confhash{'validation'}{'dc'} eq '') {
14344: $changes{'validation'}{'dc'} = &mt('None');
14345: } else {
14346: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14347: }
1.235 raeburn 14348: }
1.266 raeburn 14349: } elsif ($confhash{'validation'}{'dc'} ne '') {
14350: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 14351: }
14352: } elsif ($confhash{'validation'}{'dc'} ne '') {
14353: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14354: }
14355: } elsif ($confhash{'validation'}{'dc'} ne '') {
14356: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 14357: }
1.266 raeburn 14358: } else {
14359: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14360: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14361: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14362: $changes{'validation'}{'dc'} = &mt('None');
14363: }
14364: }
1.235 raeburn 14365: }
14366: }
1.102 raeburn 14367: }
14368: } else {
1.86 raeburn 14369: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
14370: }
1.72 raeburn 14371: foreach my $item (@usertools) {
14372: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 14373: my $unset;
1.101 raeburn 14374: if ($context eq 'requestcourses') {
1.104 raeburn 14375: $unset = '0';
14376: if ($type eq '_LC_adv') {
14377: $unset = '';
14378: }
1.101 raeburn 14379: if ($confhash{$item}{$type} eq 'autolimit') {
14380: $confhash{$item}{$type} .= '=';
14381: unless ($limithash{$item}{$type} =~ /\D/) {
14382: $confhash{$item}{$type} .= $limithash{$item}{$type};
14383: }
14384: }
1.163 raeburn 14385: } elsif ($context eq 'requestauthor') {
14386: $unset = '0';
14387: if ($type eq '_LC_adv') {
14388: $unset = '';
14389: }
1.72 raeburn 14390: } else {
1.101 raeburn 14391: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
14392: $confhash{$item}{$type} = 1;
14393: } else {
14394: $confhash{$item}{$type} = 0;
14395: }
1.72 raeburn 14396: }
1.86 raeburn 14397: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 14398: if ($action eq 'requestauthor') {
14399: if ($domconfig{$action}{$type} ne $confhash{$type}) {
14400: $changes{$type} = 1;
14401: }
14402: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 14403: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
14404: $changes{$item}{$type} = 1;
14405: }
14406: } else {
14407: if ($context eq 'requestcourses') {
1.104 raeburn 14408: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 14409: $changes{$item}{$type} = 1;
14410: }
14411: } else {
14412: if (!$confhash{$item}{$type}) {
14413: $changes{$item}{$type} = 1;
14414: }
14415: }
14416: }
14417: } else {
14418: if ($context eq 'requestcourses') {
1.104 raeburn 14419: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 14420: $changes{$item}{$type} = 1;
14421: }
1.163 raeburn 14422: } elsif ($context eq 'requestauthor') {
14423: if ($confhash{$type} ne $unset) {
14424: $changes{$type} = 1;
14425: }
1.72 raeburn 14426: } else {
14427: if (!$confhash{$item}{$type}) {
14428: $changes{$item}{$type} = 1;
14429: }
14430: }
14431: }
1.1 raeburn 14432: }
14433: }
1.163 raeburn 14434: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 14435: if (ref($domconfig{'quotas'}) eq 'HASH') {
14436: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14437: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
14438: if (exists($confhash{'defaultquota'}{$key})) {
14439: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
14440: $changes{'defaultquota'}{$key} = 1;
14441: }
14442: } else {
14443: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 14444: }
14445: }
1.86 raeburn 14446: } else {
14447: foreach my $key (keys(%{$domconfig{'quotas'}})) {
14448: if (exists($confhash{'defaultquota'}{$key})) {
14449: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
14450: $changes{'defaultquota'}{$key} = 1;
14451: }
14452: } else {
14453: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 14454: }
1.1 raeburn 14455: }
14456: }
1.197 raeburn 14457: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
1.429 raeburn 14458: $confhash{'authorquota'} = $domconfig{'quotas'}{'authorquota'};
14459: }
14460: if (ref($domconfig{'quotas'}{'webdav'}) eq 'HASH') {
14461: $confhash{'webdav'} = $domconfig{'quotas'}{'webdav'};
1.197 raeburn 14462: }
1.1 raeburn 14463: }
1.86 raeburn 14464: if (ref($confhash{'defaultquota'}) eq 'HASH') {
14465: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
14466: if (ref($domconfig{'quotas'}) eq 'HASH') {
14467: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14468: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
14469: $changes{'defaultquota'}{$key} = 1;
14470: }
14471: } else {
14472: if (!exists($domconfig{'quotas'}{$key})) {
14473: $changes{'defaultquota'}{$key} = 1;
14474: }
1.72 raeburn 14475: }
14476: } else {
1.86 raeburn 14477: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 14478: }
1.1 raeburn 14479: }
14480: }
14481: }
1.72 raeburn 14482:
1.163 raeburn 14483: if ($context eq 'requestauthor') {
14484: $domdefaults{'requestauthor'} = \%confhash;
14485: } else {
14486: foreach my $key (keys(%confhash)) {
1.242 raeburn 14487: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 14488: $domdefaults{$key} = $confhash{$key};
14489: }
1.163 raeburn 14490: }
1.72 raeburn 14491: }
1.163 raeburn 14492:
1.1 raeburn 14493: my %quotahash = (
1.86 raeburn 14494: $action => { %confhash }
1.1 raeburn 14495: );
14496: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
14497: $dom);
14498: if ($putresult eq 'ok') {
14499: if (keys(%changes) > 0) {
1.72 raeburn 14500: my $cachetime = 24*60*60;
14501: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 14502: if (ref($lastactref) eq 'HASH') {
14503: $lastactref->{'domdefaults'} = 1;
14504: }
1.1 raeburn 14505: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 14506: unless (($context eq 'requestcourses') ||
1.163 raeburn 14507: ($context eq 'requestauthor')) {
1.86 raeburn 14508: if (ref($changes{'defaultquota'}) eq 'HASH') {
14509: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
14510: foreach my $type (@{$types},'default') {
14511: if (defined($changes{'defaultquota'}{$type})) {
14512: my $typetitle = $usertypes->{$type};
14513: if ($type eq 'default') {
14514: $typetitle = $othertitle;
14515: }
1.213 raeburn 14516: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 14517: }
14518: }
1.86 raeburn 14519: $resulttext .= '</ul></li>';
1.72 raeburn 14520: }
14521: }
1.80 raeburn 14522: my %newenv;
1.72 raeburn 14523: foreach my $item (@usertools) {
1.163 raeburn 14524: my (%haschgs,%inconf);
14525: if ($context eq 'requestauthor') {
14526: %haschgs = %changes;
1.210 raeburn 14527: %inconf = %confhash;
1.163 raeburn 14528: } else {
14529: if (ref($changes{$item}) eq 'HASH') {
14530: %haschgs = %{$changes{$item}};
14531: }
14532: if (ref($confhash{$item}) eq 'HASH') {
14533: %inconf = %{$confhash{$item}};
14534: }
14535: }
14536: if (keys(%haschgs) > 0) {
1.80 raeburn 14537: my $newacc =
14538: &Apache::lonnet::usertools_access($env{'user.name'},
14539: $env{'user.domain'},
1.86 raeburn 14540: $item,'reload',$context);
1.210 raeburn 14541: if (($context eq 'requestcourses') ||
1.163 raeburn 14542: ($context eq 'requestauthor')) {
1.108 raeburn 14543: if ($env{'environment.canrequest.'.$item} ne $newacc) {
14544: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 14545: }
14546: } else {
14547: if ($env{'environment.availabletools.'.$item} ne $newacc) {
14548: $newenv{'environment.availabletools.'.$item} = $newacc;
14549: }
1.80 raeburn 14550: }
1.163 raeburn 14551: unless ($context eq 'requestauthor') {
14552: $resulttext .= '<li>'.$titles{$item}.'<ul>';
14553: }
1.72 raeburn 14554: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 14555: if ($haschgs{$type}) {
1.72 raeburn 14556: my $typetitle = $usertypes->{$type};
14557: if ($type eq 'default') {
14558: $typetitle = $othertitle;
14559: } elsif ($type eq '_LC_adv') {
14560: $typetitle = 'LON-CAPA Advanced Users';
14561: }
1.163 raeburn 14562: if ($inconf{$type}) {
1.101 raeburn 14563: if ($context eq 'requestcourses') {
14564: my $cond;
1.163 raeburn 14565: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 14566: if ($1 eq '') {
14567: $cond = &mt('(Automatic processing of any request).');
14568: } else {
14569: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
14570: }
14571: } else {
1.163 raeburn 14572: $cond = $conditions{$inconf{$type}};
1.101 raeburn 14573: }
14574: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 14575: } elsif ($context eq 'requestauthor') {
14576: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
14577: $titles{$inconf{$type}},$typetitle);
14578:
1.101 raeburn 14579: } else {
14580: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
14581: }
1.72 raeburn 14582: } else {
1.104 raeburn 14583: if ($type eq '_LC_adv') {
1.163 raeburn 14584: if ($inconf{$type} eq '0') {
1.104 raeburn 14585: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14586: } else {
14587: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
14588: }
14589: } else {
14590: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14591: }
1.72 raeburn 14592: }
14593: }
1.26 raeburn 14594: }
1.163 raeburn 14595: unless ($context eq 'requestauthor') {
14596: $resulttext .= '</ul></li>';
14597: }
1.26 raeburn 14598: }
1.1 raeburn 14599: }
1.163 raeburn 14600: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 14601: if (ref($changes{'notify'}) eq 'HASH') {
14602: if ($changes{'notify'}{'approval'}) {
14603: if (ref($confhash{'notify'}) eq 'HASH') {
14604: if ($confhash{'notify'}{'approval'}) {
14605: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
14606: } else {
1.163 raeburn 14607: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 14608: }
14609: }
14610: }
14611: }
14612: }
1.216 raeburn 14613: if ($action eq 'requestcourses') {
14614: my @offon = ('off','on');
14615: if ($changes{'uniquecode'}) {
1.218 raeburn 14616: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14617: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
14618: $resulttext .= '<li>'.
14619: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
14620: '</li>';
14621: } else {
14622: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
14623: '</li>';
14624: }
1.216 raeburn 14625: }
1.242 raeburn 14626: foreach my $type ('textbooks','templates') {
14627: if (ref($changes{$type}) eq 'HASH') {
14628: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
14629: foreach my $key (sort(keys(%{$changes{$type}}))) {
14630: my %coursehash = &Apache::lonnet::coursedescription($key);
14631: my $coursetitle = $coursehash{'description'};
14632: my $position = $confhash{$type}{$key}{'order'} + 1;
14633: $resulttext .= '<li>';
1.243 raeburn 14634: foreach my $item ('subject','title','publisher','author') {
14635: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14636: ($type eq 'templates'));
1.242 raeburn 14637: my $name = $item.':';
14638: $name =~ s/^(\w)/\U$1/;
14639: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
14640: }
14641: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
14642: if ($type eq 'textbooks') {
14643: if ($confhash{$type}{$key}{'image'}) {
14644: $resulttext .= ' '.&mt('Image: [_1]',
14645: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
14646: ' alt="Textbook cover" />').'<br />';
14647: }
14648: }
14649: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 14650: }
1.242 raeburn 14651: $resulttext .= '</ul></li>';
1.216 raeburn 14652: }
14653: }
1.235 raeburn 14654: if (ref($changes{'validation'}) eq 'HASH') {
14655: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
14656: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
14657: foreach my $item (@{$validationitemsref}) {
14658: if (exists($changes{'validation'}{$item})) {
14659: if ($item eq 'markup') {
14660: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14661: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
14662: } else {
14663: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14664: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
14665: }
14666: }
14667: }
14668: if (exists($changes{'validation'}{'dc'})) {
14669: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
14670: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
14671: }
14672: }
14673: }
1.216 raeburn 14674: }
1.1 raeburn 14675: $resulttext .= '</ul>';
1.80 raeburn 14676: if (keys(%newenv)) {
14677: &Apache::lonnet::appenv(\%newenv);
14678: }
1.1 raeburn 14679: } else {
1.86 raeburn 14680: if ($context eq 'requestcourses') {
14681: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 14682: } elsif ($context eq 'requestauthor') {
14683: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 14684: } else {
1.90 weissno 14685: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 14686: }
1.1 raeburn 14687: }
14688: } else {
1.11 albertel 14689: $resulttext = '<span class="LC_error">'.
14690: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14691: }
1.216 raeburn 14692: if ($errors) {
14693: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
14694: '<ul>'.$errors.'</ul></p>';
14695: }
1.3 raeburn 14696: return $resulttext;
1.1 raeburn 14697: }
14698:
1.216 raeburn 14699: sub process_textbook_image {
1.242 raeburn 14700: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 14701: my $filename = $env{'form.'.$caller.'.filename'};
14702: my ($error,$url);
14703: my ($width,$height) = (50,50);
14704: if ($configuserok eq 'ok') {
14705: if ($switchserver) {
14706: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
14707: $switchserver);
14708: } elsif ($author_ok eq 'ok') {
1.421 raeburn 14709: my $modified = [];
1.216 raeburn 14710: my ($result,$imageurl) =
1.421 raeburn 14711: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
14712: "$type/$cdom/$cnum/cover",$width,$height,
14713: '',$modified);
1.216 raeburn 14714: if ($result eq 'ok') {
14715: $url = $imageurl;
1.421 raeburn 14716: &update_modify_urls($r,$modified);
1.216 raeburn 14717: } else {
14718: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14719: }
14720: } else {
14721: $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);
14722: }
14723: } else {
14724: $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);
14725: }
14726: return ($url,$error);
14727: }
14728:
1.267 raeburn 14729: sub modify_ltitools {
14730: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.421 raeburn 14731: my (%currtoolsec,%secchanges,%newtoolsec,%newkeyset);
14732: &fetch_secrets($dom,'toolsec',\%domconfig,\%currtoolsec,\%secchanges,\%newtoolsec,\%newkeyset);
14733:
1.267 raeburn 14734: my $confname = $dom.'-domainconfig';
14735: my $servadm = $r->dir_config('lonAdmEMail');
14736: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.421 raeburn 14737:
14738: my ($resulttext,$ltitoolsoutput,$is_home,$errors,%ltitoolschg,%newtoolsenc,%newltitools);
14739: my $toolserror =
14740: &Apache::courseprefs::process_ltitools($r,$dom,$confname,$domconfig{'ltitools'},\%ltitoolschg,'domain',
14741: $lastactref,$configuserok,$switchserver,$author_ok);
14742:
14743: my $home = &Apache::lonnet::domain($dom,'primary');
14744: unless (($home eq 'no_host') || ($home eq '')) {
14745: my @ids=&Apache::lonnet::current_machine_ids();
14746: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; last; } }
14747: }
14748:
14749: if (keys(%ltitoolschg)) {
14750: foreach my $id (keys(%ltitoolschg)) {
14751: if (ref($ltitoolschg{$id}) eq 'HASH') {
14752: foreach my $inner (keys(%{$ltitoolschg{$id}})) {
14753: if (($inner eq 'secret') || ($inner eq 'key')) {
14754: if ($is_home) {
14755: $newtoolsenc{$id}{$inner} = $ltitoolschg{$id}{$inner};
14756: }
14757: }
14758: }
1.267 raeburn 14759: }
1.421 raeburn 14760: }
14761: $ltitoolsoutput = &Apache::courseprefs::store_ltitools($dom,'','domain',\%ltitoolschg,$domconfig{'ltitools'});
14762: if (keys(%ltitoolschg)) {
14763: %newltitools = %ltitoolschg;
14764: }
14765: }
14766: if (ref($domconfig{'ltitools'}) eq 'HASH') {
14767: foreach my $id (%{$domconfig{'ltitools'}}) {
14768: next if ($id !~ /^\d+$/);
14769: unless (exists($ltitoolschg{$id})) {
14770: if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
14771: foreach my $inner (keys(%{$domconfig{'ltitools'}{$id}})) {
14772: if (($inner eq 'secret') || ($inner eq 'key')) {
14773: if ($is_home) {
14774: $newtoolsenc{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14775: }
14776: } else {
14777: $newltitools{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14778: }
14779: }
14780: } else {
14781: $newltitools{$id} = $domconfig{'ltitools'}{$id};
1.322 raeburn 14782: }
1.421 raeburn 14783: }
14784: }
14785: }
14786: if ($toolserror) {
14787: $errors = '<li>'.$toolserror.'</li>';
14788: }
14789: if ((keys(%ltitoolschg) == 0) && (keys(%secchanges) == 0)) {
14790: $resulttext = &mt('No changes made.');
14791: if ($errors) {
14792: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
14793: $errors.'</ul>';
14794: }
14795: return $resulttext;
14796: }
14797: my %ltitoolshash = (
14798: $action => { %newltitools }
14799: );
14800: if (keys(%secchanges)) {
14801: $ltitoolshash{'toolsec'} = \%newtoolsec;
14802: }
14803: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,$dom);
14804: if ($putresult eq 'ok') {
14805: my %keystore;
14806: if ($is_home) {
14807: my %toolsenchash = (
14808: $action => { %newtoolsenc }
14809: );
14810: &Apache::lonnet::put_dom('encconfig',\%toolsenchash,$dom,undef,1);
1.423 raeburn 14811: my $cachetime = 24*60*60;
14812: &Apache::lonnet::do_cache_new('ltitoolsenc',$dom,\%newtoolsenc,$cachetime);
1.421 raeburn 14813: &store_security($dom,'ltitools',\%secchanges,\%newkeyset,\%keystore,$lastactref);
14814: }
14815: $resulttext = &mt('Changes made:').'<ul>';
14816: if (keys(%secchanges) > 0) {
1.423 raeburn 14817: $resulttext .= <i_security_results($dom,'ltitools',\%secchanges,\%newtoolsec,\%newkeyset,\%keystore);
1.421 raeburn 14818: }
14819: if (keys(%ltitoolschg) > 0) {
14820: $resulttext .= $ltitoolsoutput;
14821: }
1.423 raeburn 14822: my $cachetime = 24*60*60;
14823: &Apache::lonnet::do_cache_new('ltitools',$dom,\%newltitools,$cachetime);
14824: if (ref($lastactref) eq 'HASH') {
14825: $lastactref->{'ltitools'} = 1;
14826: }
1.421 raeburn 14827: } else {
14828: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
14829: }
14830: if ($errors) {
14831: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
14832: $errors.'</ul></p>';
14833: }
14834: return $resulttext;
14835: }
14836:
14837: sub fetch_secrets {
14838: my ($dom,$context,$domconfig,$currsec,$secchanges,$newsec,$newkeyset) = @_;
14839: my %keyset;
14840: %{$currsec} = ();
14841: $newsec->{'private'}{'keys'} = [];
14842: $newsec->{'encrypt'} = {};
14843: $newsec->{'rules'} = {};
14844: if ($context eq 'ltisec') {
14845: $newsec->{'linkprot'} = {};
14846: }
14847: if (ref($domconfig->{$context}) eq 'HASH') {
14848: %{$currsec} = %{$domconfig->{$context}};
14849: if ($context eq 'ltisec') {
14850: if (ref($currsec->{'linkprot'}) eq 'HASH') {
14851: foreach my $id (keys(%{$currsec->{'linkprot'}})) {
14852: unless ($id =~ /^\d+$/) {
14853: delete($currsec->{'linkprot'}{$id});
1.297 raeburn 14854: }
1.267 raeburn 14855: }
14856: }
1.421 raeburn 14857: }
14858: if (ref($currsec->{'private'}) eq 'HASH') {
14859: if (ref($currsec->{'private'}{'keys'}) eq 'ARRAY') {
14860: $newsec->{'private'}{'keys'} = $currsec->{'private'}{'keys'};
14861: map { $keyset{$_} = 1; } @{$currsec->{'private'}{'keys'}};
1.267 raeburn 14862: }
1.421 raeburn 14863: }
14864: }
14865: my @items= ('crs','dom');
14866: if ($context eq 'ltisec') {
14867: push(@items,'consumers');
14868: }
14869: foreach my $item (@items) {
14870: my $formelement;
14871: if (($context eq 'toolsec') || ($item eq 'consumers')) {
14872: $formelement = 'form.'.$context.'_'.$item;
14873: } else {
14874: $formelement = 'form.'.$context.'_'.$item.'linkprot';
14875: }
14876: if ($env{$formelement}) {
14877: $newsec->{'encrypt'}{$item} = 1;
14878: if (ref($currsec->{'encrypt'}) eq 'HASH') {
14879: unless ($currsec->{'encrypt'}{$item}) {
14880: $secchanges->{'encrypt'} = 1;
14881: }
14882: } else {
14883: $secchanges->{'encrypt'} = 1;
1.267 raeburn 14884: }
1.421 raeburn 14885: } elsif (ref($currsec->{'encrypt'}) eq 'HASH') {
14886: if ($currsec->{'encrypt'}{$item}) {
14887: $secchanges->{'encrypt'} = 1;
1.323 raeburn 14888: }
1.421 raeburn 14889: }
14890: }
14891: my $secrets;
14892: if ($context eq 'ltisec') {
14893: $secrets = 'ltisecrets';
14894: } else {
14895: $secrets = 'toolsecrets';
14896: }
14897: unless (exists($currsec->{'rules'})) {
14898: $currsec->{'rules'} = {};
14899: }
14900: &password_rule_changes($secrets,$newsec->{'rules'},$currsec->{'rules'},$secchanges);
14901:
14902: my @ids=&Apache::lonnet::current_machine_ids();
14903: my %servers = &Apache::lonnet::get_servers($dom,'library');
14904:
14905: foreach my $hostid (keys(%servers)) {
14906: if (($hostid ne '') && (grep(/^\Q$hostid\E$/,@ids))) {
14907: my $keyitem = 'form.'.$context.'_privkey_'.$hostid;
14908: if (exists($env{$keyitem})) {
14909: $env{$keyitem} =~ s/(`)/'/g;
14910: if ($keyset{$hostid}) {
14911: if ($env{'form.'.$context.'_changeprivkey_'.$hostid}) {
14912: if ($env{$keyitem} ne '') {
14913: $secchanges->{'private'} = 1;
14914: $newkeyset->{$hostid} = $env{$keyitem};
14915: }
1.296 raeburn 14916: }
1.421 raeburn 14917: } elsif ($env{$keyitem} ne '') {
14918: unless (grep(/^\Q$hostid\E$/,@{$newsec->{'private'}{'keys'}})) {
14919: push(@{$newsec->{'private'}{'keys'}},$hostid);
1.296 raeburn 14920: }
1.421 raeburn 14921: $secchanges->{'private'} = 1;
14922: $newkeyset->{$hostid} = $env{$keyitem};
1.267 raeburn 14923: }
14924: }
1.421 raeburn 14925: }
14926: }
14927: }
14928:
14929: sub store_security {
1.424 raeburn 14930: my ($dom,$context,$secchanges,$newkeyset,$keystore) = @_;
1.421 raeburn 14931: return unless ((ref($secchanges) eq 'HASH') && (ref($newkeyset) eq 'HASH') &&
14932: (ref($keystore) eq 'HASH'));
14933: if (keys(%{$secchanges})) {
14934: if ($secchanges->{'private'}) {
14935: my $who = &escape($env{'user.name'}.':'.$env{'user.domain'});
14936: foreach my $hostid (keys(%{$newkeyset})) {
14937: my $storehash = {
14938: key => $newkeyset->{$hostid},
14939: who => $env{'user.name'}.':'.$env{'user.domain'},
14940: };
14941: $keystore->{$hostid} = &Apache::lonnet::store_dom($storehash,$context,'private',
14942: $dom,$hostid);
14943: }
14944: }
14945: }
14946: }
14947:
14948: sub lti_security_results {
1.423 raeburn 14949: my ($dom,$context,$secchanges,$newsec,$newkeyset,$keystore) = @_;
1.421 raeburn 14950: my $output;
1.423 raeburn 14951: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
14952: my $needs_update;
1.421 raeburn 14953: foreach my $item (keys(%{$secchanges})) {
14954: if ($item eq 'encrypt') {
1.423 raeburn 14955: $needs_update = 1;
1.421 raeburn 14956: my %encrypted;
14957: if ($context eq 'lti') {
14958: %encrypted = (
14959: crs => {
14960: on => &mt('Encryption of stored link protection secrets defined in courses enabled'),
14961: off => &mt('Encryption of stored link protection secrets defined in courses disabled'),
14962: },
14963: dom => {
14964: on => &mt('Encryption of stored link protection secrets defined in domain enabled'),
14965: off => &mt('Encryption of stored link protection secrets defined in domain disabled'),
14966: },
14967: consumers => {
14968: on => &mt('Encryption of stored consumer secrets defined in domain enabled'),
14969: off => &mt('Encryption of stored consumer secrets defined in domain disabled'),
14970: },
14971: );
1.267 raeburn 14972: } else {
1.421 raeburn 14973: %encrypted = (
14974: crs => {
14975: on => &mt('Encryption of stored external tool secrets defined in courses enabled'),
14976: off => &mt('Encryption of stored external tool secrets defined in courses disabled'),
14977: },
14978: dom => {
14979: on => &mt('Encryption of stored external tool secrets defined in domain enabled'),
14980: off => &mt('Encryption of stored external tool secrets defined in domain disabled'),
14981: },
14982: );
14983:
14984: }
14985: my @types= ('crs','dom');
14986: if ($context eq 'lti') {
1.423 raeburn 14987: foreach my $type (@types) {
14988: undef($domdefaults{'linkprotenc_'.$type});
14989: }
1.421 raeburn 14990: push(@types,'consumers');
1.423 raeburn 14991: undef($domdefaults{'ltienc_consumers'});
14992: } elsif ($context eq 'ltitools') {
14993: foreach my $type (@types) {
14994: undef($domdefaults{'toolenc_'.$type});
14995: }
1.267 raeburn 14996: }
1.421 raeburn 14997: foreach my $type (@types) {
14998: my $shown = $encrypted{$type}{'off'};
14999: if (ref($newsec->{$item}) eq 'HASH') {
15000: if ($newsec->{$item}{$type}) {
1.423 raeburn 15001: if ($context eq 'lti') {
15002: if ($type eq 'consumers') {
15003: $domdefaults{'ltienc_consumers'} = 1;
15004: } else {
15005: $domdefaults{'linkprotenc_'.$type} = 1;
15006: }
15007: } elsif ($context eq 'ltitools') {
15008: $domdefaults{'toolenc_'.$type} = 1;
15009: }
1.421 raeburn 15010: $shown = $encrypted{$type}{'on'};
1.319 raeburn 15011: }
1.267 raeburn 15012: }
1.421 raeburn 15013: $output .= '<li>'.$shown.'</li>';
1.267 raeburn 15014: }
1.421 raeburn 15015: } elsif ($item eq 'rules') {
15016: my %titles = &Apache::lonlocal::texthash(
15017: min => 'Minimum password length',
15018: max => 'Maximum password length',
15019: chars => 'Required characters',
15020: );
15021: foreach my $rule ('min','max') {
15022: if ($newsec->{rules}{$rule} eq '') {
15023: if ($rule eq 'min') {
15024: $output .= '<li>'.&mt('[_1] not set.',$titles{$rule});
15025: ' '.&mt('Default of [_1] will be used',
15026: $Apache::lonnet::passwdmin).'</li>';
15027: } else {
15028: $output .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
15029: }
15030: } else {
15031: $output .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$newsec->{rules}{$rule}).'</li>';
15032: }
15033: }
15034: if (ref($newsec->{'rules'}{'chars'}) eq 'ARRAY') {
15035: if (@{$newsec->{'rules'}{'chars'}} > 0) {
15036: my %rulenames = &Apache::lonlocal::texthash(
15037: uc => 'At least one upper case letter',
15038: lc => 'At least one lower case letter',
15039: num => 'At least one number',
15040: spec => 'At least one non-alphanumeric',
15041: );
15042: my $needed = '<ul><li>'.
15043: join('</li><li>',map {$rulenames{$_} } @{$newsec->{'rules'}{'chars'}}).
15044: '</li></ul>';
15045: $output .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
15046: } else {
15047: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 15048: }
1.421 raeburn 15049: } else {
15050: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 15051: }
1.421 raeburn 15052: } elsif ($item eq 'private') {
1.423 raeburn 15053: $needs_update = 1;
15054: if ($context eq 'lti') {
15055: undef($domdefaults{'ltiprivhosts'});
15056: } elsif ($context eq 'ltitools') {
15057: undef($domdefaults{'toolprivhosts'});
15058: }
1.421 raeburn 15059: if (keys(%{$newkeyset})) {
1.423 raeburn 15060: my @privhosts;
1.421 raeburn 15061: foreach my $hostid (sort(keys(%{$newkeyset}))) {
15062: if ($keystore->{$hostid} eq 'ok') {
15063: $output .= '<li>'.&mt('Encryption key for storage of shared secrets saved for [_1]',$hostid).'</li>';
1.423 raeburn 15064: unless (grep(/^\Q$hostid\E$/,@privhosts)) {
15065: push(@privhosts,$hostid);
15066: }
15067: }
15068: }
15069: if (@privhosts) {
15070: if ($context eq 'lti') {
15071: $domdefaults{'ltiprivhosts'} = \@privhosts;
15072: } elsif ($context eq 'ltitools') {
15073: $domdefaults{'toolprivhosts'} = \@privhosts;
1.267 raeburn 15074: }
15075: }
15076: }
1.421 raeburn 15077: } elsif ($item eq 'linkprot') {
15078: next;
1.267 raeburn 15079: }
15080: }
1.423 raeburn 15081: if ($needs_update) {
15082: my $cachetime = 24*60*60;
15083: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15084: }
1.421 raeburn 15085: return $output;
15086: }
15087:
15088: sub modify_proctoring {
15089: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15090: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15091: my (@allpos,%changes,%confhash,%encconfhash,$errors,$resulttext,%imgdeletions);
15092: my $confname = $dom.'-domainconfig';
15093: my $servadm = $r->dir_config('lonAdmEMail');
1.372 raeburn 15094: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
15095: my %providernames = &proctoring_providernames();
15096: my $maxnum = scalar(keys(%providernames));
15097:
15098: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
15099: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
15100: if (ref($requref) eq 'HASH') {
15101: %requserfields = %{$requref};
15102: }
15103: if (ref($opturef) eq 'HASH') {
15104: %optuserfields = %{$opturef};
15105: }
15106: if (ref($defref) eq 'HASH') {
15107: %defaults = %{$defref};
15108: }
15109: if (ref($extref) eq 'HASH') {
15110: %extended = %{$extref};
15111: }
15112: if (ref($crsref) eq 'HASH') {
15113: %crsconf = %{$crsref};
15114: }
15115: if (ref($rolesref) eq 'ARRAY') {
15116: @courseroles = @{$rolesref};
15117: }
15118: if (ref($ltiref) eq 'ARRAY') {
15119: @ltiroles = @{$ltiref};
15120: }
15121:
15122: if (ref($domconfig{$action}) eq 'HASH') {
15123: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.proctoring_image_del');
15124: if (@todeleteimages) {
15125: map { $imgdeletions{$_} = 1; } @todeleteimages;
15126: }
15127: }
15128: my %customadds;
15129: my @newcustom = &Apache::loncommon::get_env_multiple('form.proctoring_customadd');
15130: if (@newcustom) {
15131: map { $customadds{$_} = 1; } @newcustom;
15132: }
15133: foreach my $provider (sort(keys(%providernames))) {
15134: $confhash{$provider} = {};
15135: my $pos = $env{'form.proctoring_pos_'.$provider};
15136: $pos =~ s/\D+//g;
15137: $allpos[$pos] = $provider;
15138: my (%current,%currentenc);
15139: my $showroles = 0;
15140: if (ref($domconfig{$action}) eq 'HASH') {
15141: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15142: %current = %{$domconfig{$action}{$provider}};
15143: foreach my $item ('key','secret') {
15144: $currentenc{$item} = $current{$item};
15145: delete($current{$item});
15146: }
15147: }
15148: }
15149: if ($env{'form.proctoring_available_'.$provider}) {
15150: $confhash{$provider}{'available'} = 1;
15151: unless ($current{'available'}) {
15152: $changes{$provider} = 1;
15153: }
15154: } else {
15155: %{$confhash{$provider}} = %current;
15156: %{$encconfhash{$provider}} = %currentenc;
15157: $confhash{$provider}{'available'} = 0;
15158: if ($current{'available'}) {
15159: $changes{$provider} = 1;
15160: }
15161: }
15162: if ($confhash{$provider}{'available'}) {
15163: foreach my $field ('lifetime','version','sigmethod','url','key','secret') {
15164: my $possval = $env{'form.proctoring_'.$provider.'_'.$field};
15165: if ($field eq 'lifetime') {
15166: if ($possval =~ /^\d+$/) {
15167: $confhash{$provider}{$field} = $possval;
15168: }
15169: } elsif ($field eq 'version') {
15170: if ($possval =~ /^\d+\.\d+$/) {
15171: $confhash{$provider}{$field} = $possval;
15172: }
15173: } elsif ($field eq 'sigmethod') {
15174: if ($possval =~ /^\QHMAC-SHA\E(1|256)$/) {
15175: $confhash{$provider}{$field} = $possval;
15176: }
15177: } elsif ($field eq 'url') {
15178: $confhash{$provider}{$field} = $possval;
15179: } elsif (($field eq 'key') || ($field eq 'secret')) {
15180: $encconfhash{$provider}{$field} = $possval;
15181: unless ($currentenc{$field} eq $possval) {
15182: $changes{$provider} = 1;
15183: }
15184: }
15185: unless (($field eq 'key') || ($field eq 'secret')) {
15186: unless ($current{$field} eq $confhash{$provider}{$field}) {
15187: $changes{$provider} = 1;
15188: }
15189: }
15190: }
15191: if ($imgdeletions{$provider}) {
15192: $changes{$provider} = 1;
15193: } elsif ($env{'form.proctoring_image_'.$provider.'.filename'} ne '') {
15194: my ($imageurl,$error) =
15195: &process_proctoring_image($r,$dom,$confname,'proctoring_image_'.$provider,$provider,
15196: $configuserok,$switchserver,$author_ok);
15197: if ($imageurl) {
15198: $confhash{$provider}{'image'} = $imageurl;
15199: $changes{$provider} = 1;
15200: }
15201: if ($error) {
15202: &Apache::lonnet::logthis($error);
15203: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15204: }
15205: } elsif (exists($current{'image'})) {
15206: $confhash{$provider}{'image'} = $current{'image'};
15207: }
15208: if (ref($requserfields{$provider}) eq 'ARRAY') {
15209: if (@{$requserfields{$provider}} > 0) {
15210: if (grep(/^user$/,@{$requserfields{$provider}})) {
15211: if ($env{'form.proctoring_userincdom_'.$provider}) {
15212: $confhash{$provider}{'incdom'} = 1;
15213: }
15214: unless ($current{'incdom'} eq $confhash{$provider}{'incdom'}) {
15215: $changes{$provider} = 1;
15216: }
15217: }
15218: if (grep(/^roles$/,@{$requserfields{$provider}})) {
15219: $showroles = 1;
15220: }
15221: }
15222: }
15223: $confhash{$provider}{'fields'} = [];
15224: if (ref($optuserfields{$provider}) eq 'ARRAY') {
15225: if (@{$optuserfields{$provider}} > 0) {
15226: my @optfields = &Apache::loncommon::get_env_multiple('form.proctoring_optional_'.$provider);
15227: foreach my $field (@{$optuserfields{$provider}}) {
15228: if (grep(/^\Q$field\E$/,@optfields)) {
15229: push(@{$confhash{$provider}{'fields'}},$field);
15230: }
15231: }
15232: }
15233: if (ref($current{'fields'}) eq 'ARRAY') {
15234: unless ($changes{$provider}) {
15235: my @new = sort(@{$confhash{$provider}{'fields'}});
15236: my @old = sort(@{$current{'fields'}});
15237: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15238: if (@diffs) {
15239: $changes{$provider} = 1;
15240: }
15241: }
15242: } elsif (@{$confhash{$provider}{'fields'}}) {
15243: $changes{$provider} = 1;
15244: }
15245: }
15246: if (ref($defaults{$provider}) eq 'ARRAY') {
15247: if (@{$defaults{$provider}} > 0) {
15248: my %options;
15249: if (ref($extended{$provider}) eq 'HASH') {
15250: %options = %{$extended{$provider}};
15251: }
15252: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_defaults_'.$provider);
15253: foreach my $field (@{$defaults{$provider}}) {
15254: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
15255: my $poss = $env{'form.proctoring_defaults_'.$field.'_'.$provider};
15256: if (grep(/^\Q$poss\E$/,@{$options{$field}})) {
15257: push(@{$confhash{$provider}{'defaults'}},$poss);
15258: }
15259: } elsif ((exists($options{$field})) && (ref($options{$field}) eq 'HASH')) {
15260: foreach my $inner (keys(%{$options{$field}})) {
15261: if (ref($options{$field}{$inner}) eq 'ARRAY') {
15262: my $poss = $env{'form.proctoring_'.$inner.'_'.$provider};
15263: if (grep(/^\Q$poss\E$/,@{$options{$field}{$inner}})) {
15264: $confhash{$provider}{'defaults'}{$inner} = $poss;
15265: }
15266: } else {
15267: $confhash{$provider}{'defaults'}{$inner} = $env{'form.proctoring_'.$inner.'_'.$provider};
15268: }
15269: }
15270: } else {
15271: if (grep(/^\Q$field\E$/,@checked)) {
15272: push(@{$confhash{$provider}{'defaults'}},$field);
15273: }
15274: }
15275: }
15276: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15277: if (ref($current{'defaults'}) eq 'ARRAY') {
15278: unless ($changes{$provider}) {
15279: my @new = sort(@{$confhash{$provider}{'defaults'}});
15280: my @old = sort(@{$current{'defaults'}});
15281: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15282: if (@diffs) {
15283: $changes{$provider} = 1;
15284: }
15285: }
15286: } elsif (ref($current{'defaults'}) eq 'ARRAY') {
15287: if (@{$current{'defaults'}}) {
15288: $changes{$provider} = 1;
15289: }
15290: }
15291: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15292: if (ref($current{'defaults'}) eq 'HASH') {
15293: unless ($changes{$provider}) {
15294: foreach my $key (keys(%{$confhash{$provider}{'defaults'}})) {
15295: unless ($confhash{$provider}{'defaults'}{$key} eq $current{'defaults'}{$key}) {
15296: $changes{$provider} = 1;
15297: last;
15298: }
15299: }
15300: }
15301: unless ($changes{$provider}) {
15302: foreach my $key (keys(%{$current{'defaults'}})) {
15303: unless ($current{'defaults'}{$key} eq $confhash{$provider}{'defaults'}{$key}) {
15304: $changes{$provider} = 1;
15305: last;
15306: }
15307: }
15308: }
15309: } elsif (keys(%{$confhash{$provider}{'defaults'}})) {
15310: $changes{$provider} = 1;
15311: }
15312: }
15313: }
15314: }
15315: if (ref($crsconf{$provider}) eq 'ARRAY') {
15316: if (@{$crsconf{$provider}} > 0) {
15317: $confhash{$provider}{'crsconf'} = [];
15318: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_crsconf_'.$provider);
15319: foreach my $crsfield (@{$crsconf{$provider}}) {
15320: if (grep(/^\Q$crsfield\E$/,@checked)) {
15321: push(@{$confhash{$provider}{'crsconf'}},$crsfield);
15322: }
15323: }
15324: if (ref($current{'crsconf'}) eq 'ARRAY') {
15325: unless ($changes{$provider}) {
15326: my @new = sort(@{$confhash{$provider}{'crsconf'}});
15327: my @old = sort(@{$current{'crsconf'}});
15328: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15329: if (@diffs) {
15330: $changes{$provider} = 1;
15331: }
15332: }
15333: } elsif (@{$confhash{$provider}{'crsconf'}}) {
15334: $changes{$provider} = 1;
15335: }
15336: }
15337: }
15338: if ($showroles) {
15339: $confhash{$provider}{'roles'} = {};
15340: foreach my $role (@courseroles) {
15341: my $poss = $env{'form.proctoring_roles_'.$role.'_'.$provider};
15342: if (grep(/^\Q$poss\E$/,@ltiroles)) {
15343: $confhash{$provider}{'roles'}{$role} = $poss;
15344: }
15345: }
15346: unless ($changes{$provider}) {
15347: if (ref($current{'roles'}) eq 'HASH') {
15348: foreach my $role (keys(%{$current{'roles'}})) {
15349: unless ($current{'roles'}{$role} eq $confhash{$provider}{'roles'}{$role}) {
15350: $changes{$provider} = 1;
15351: last
15352: }
15353: }
15354: unless ($changes{$provider}) {
15355: foreach my $role (keys(%{$confhash{$provider}{'roles'}})) {
15356: unless ($confhash{$provider}{'roles'}{$role} eq $current{'roles'}{$role}) {
15357: $changes{$provider} = 1;
15358: last;
15359: }
15360: }
15361: }
15362: } elsif (keys(%{$confhash{$provider}{'roles'}})) {
15363: $changes{$provider} = 1;
15364: }
15365: }
15366: }
15367: if (ref($current{'custom'}) eq 'HASH') {
15368: my @customdels = &Apache::loncommon::get_env_multiple('form.proctoring_customdel_'.$provider);
15369: foreach my $key (keys(%{$current{'custom'}})) {
15370: if (grep(/^\Q$key\E$/,@customdels)) {
15371: $changes{$provider} = 1;
15372: } else {
15373: $confhash{$provider}{'custom'}{$key} = $env{'form.proctoring_customval_'.$key.'_'.$provider};
15374: if ($confhash{$provider}{'custom'}{$key} ne $current{'custom'}{$key}) {
15375: $changes{$provider} = 1;
15376: }
15377: }
15378: }
15379: }
15380: if ($customadds{$provider}) {
15381: my $name = $env{'form.proctoring_custom_name_'.$provider};
15382: $name =~ s/(`)/'/g;
15383: $name =~ s/^\s+//;
15384: $name =~ s/\s+$//;
15385: my $value = $env{'form.proctoring_custom_value_'.$provider};
15386: $value =~ s/(`)/'/g;
15387: $value =~ s/^\s+//;
15388: $value =~ s/\s+$//;
15389: if ($name ne '') {
15390: $confhash{$provider}{'custom'}{$name} = $value;
15391: $changes{$provider} = 1;
15392: }
15393: }
15394: }
15395: }
15396: if (@allpos > 0) {
15397: my $idx = 0;
15398: foreach my $provider (@allpos) {
15399: if ($provider ne '') {
15400: $confhash{$provider}{'order'} = $idx;
15401: unless ($changes{$provider}) {
15402: if (ref($domconfig{$action}) eq 'HASH') {
15403: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15404: if ($domconfig{$action}{$provider}{'order'} ne $idx) {
15405: $changes{$provider} = 1;
15406: }
15407: }
15408: }
15409: }
15410: $idx ++;
15411: }
15412: }
15413: }
15414: my %proc_hash = (
15415: $action => { %confhash }
15416: );
15417: my $putresult = &Apache::lonnet::put_dom('configuration',\%proc_hash,
15418: $dom);
15419: if ($putresult eq 'ok') {
15420: my %proc_enchash = (
15421: $action => { %encconfhash }
15422: );
1.384 raeburn 15423: &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom,undef,1);
1.372 raeburn 15424: if (keys(%changes) > 0) {
15425: my $cachetime = 24*60*60;
15426: my %procall = %confhash;
15427: foreach my $provider (keys(%procall)) {
15428: if (ref($encconfhash{$provider}) eq 'HASH') {
15429: foreach my $key ('key','secret') {
15430: $procall{$provider}{$key} = $encconfhash{$provider}{$key};
15431: }
15432: }
15433: }
15434: &Apache::lonnet::do_cache_new('proctoring',$dom,\%procall,$cachetime);
15435: if (ref($lastactref) eq 'HASH') {
15436: $lastactref->{'proctoring'} = 1;
15437: }
15438: $resulttext = &mt('Configuration for Provider(s) with changes:').'<ul>';
15439: my %bynum;
15440: foreach my $provider (sort(keys(%changes))) {
15441: my $position = $confhash{$provider}{'order'};
15442: $bynum{$position} = $provider;
15443: }
15444: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
15445: my $provider = $bynum{$pos};
15446: my %lt = &proctoring_titles($provider);
15447: my %fieldtitles = &proctoring_fieldtitles($provider);
15448: if (!$confhash{$provider}{'available'}) {
15449: $resulttext .= '<li>'.&mt('Proctoring integration unavailable for: [_1]','<b>'.$providernames{$provider}.'</b>').'</li>';
15450: } else {
15451: $resulttext .= '<li>'.&mt('Proctoring integration available for: [_1]','<b>'.$providernames{$provider}.'</b>');
15452: if ($confhash{$provider}{'image'}) {
15453: $resulttext .= ' '.
15454: '<img src="'.$confhash{$provider}{'image'}.'"'.
15455: ' alt="'.&mt('Proctoring icon').'" />';
15456: }
15457: $resulttext .= '<ul>';
15458: my $position = $pos + 1;
15459: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
15460: foreach my $key ('version','sigmethod','url','lifetime') {
15461: if ($confhash{$provider}{$key} ne '') {
15462: $resulttext .= '<li>'.$lt{$key}.': '.$confhash{$provider}{$key}.'</li>';
15463: }
15464: }
15465: if ($encconfhash{$provider}{'key'} ne '') {
15466: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfhash{$provider}{'key'}.'</li>';
15467: }
15468: if ($encconfhash{$provider}{'secret'} ne '') {
15469: $resulttext .= '<li>'.$lt{'secret'}.': ';
15470: my $num = length($encconfhash{$provider}{'secret'});
15471: $resulttext .= ('*'x$num).'</li>';
15472: }
15473: my (@fields,$showroles);
15474: if (ref($requserfields{$provider}) eq 'ARRAY') {
15475: push(@fields,@{$requserfields{$provider}});
15476: }
15477: if (ref($confhash{$provider}{'fields'}) eq 'ARRAY') {
15478: push(@fields,@{$confhash{$provider}{'fields'}});
15479: } elsif (ref($confhash{$provider}{'fields'}) eq 'HASH') {
15480: push(@fields,(keys(%{$confhash{$provider}{'fields'}})));
15481: }
15482: if (@fields) {
15483: if (grep(/^roles$/,@fields)) {
15484: $showroles = 1;
15485: }
15486: $resulttext .= '<li>'.$lt{'udsl'}.': "'.
15487: join('", "', map { $lt{$_}; } @fields).'"</li>';
15488: }
15489: if (ref($requserfields{$provider}) eq 'ARRAY') {
15490: if (grep(/^user$/,@{$requserfields{$provider}})) {
15491: if ($confhash{$provider}{'incdom'}) {
15492: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'uname:dom'}).'</li>';
15493: } else {
15494: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'username'}).'</li>';
15495: }
15496: }
15497: }
15498: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15499: if (@{$confhash{$provider}{'defaults'}} > 0) {
15500: $resulttext .= '<li>'.$lt{'defa'};
15501: foreach my $field (@{$confhash{$provider}{'defaults'}}) {
15502: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15503: }
15504: $resulttext =~ s/,$//;
15505: $resulttext .= '</li>';
15506: }
15507: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15508: if (keys(%{$confhash{$provider}{'defaults'}})) {
15509: $resulttext .= '<li>'.$lt{'defa'}.': <ul>';
15510: foreach my $key (sort(keys(%{$confhash{$provider}{'defaults'}}))) {
15511: if ($confhash{$provider}{'defaults'}{$key} ne '') {
15512: $resulttext .= '<li>'.$fieldtitles{$key}.' = '.$confhash{$provider}{'defaults'}{$key}.'</li>';
15513: }
15514: }
15515: $resulttext .= '</ul></li>';
15516: }
15517: }
15518: if (ref($crsconf{$provider}) eq 'ARRAY') {
15519: if (@{$crsconf{$provider}} > 0) {
15520: $resulttext .= '<li>'.&mt('Configurable in course:');
15521: my $numconfig = 0;
15522: if (ref($confhash{$provider}{'crsconf'}) eq 'ARRAY') {
15523: if (@{$confhash{$provider}{'crsconf'}} > 0) {
15524: foreach my $field (@{$confhash{$provider}{'crsconf'}}) {
15525: $numconfig ++;
15526: if ($provider eq 'examity') {
15527: $resulttext .= ' "'.$lt{'crs'.$field}.'",';
15528: } else {
15529: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15530: }
15531: }
15532: $resulttext =~ s/,$//;
15533: }
15534: }
15535: if (!$numconfig) {
15536: $resulttext .= ' '.&mt('None');
15537: }
15538: $resulttext .= '</li>';
15539: }
15540: }
15541: if ($showroles) {
15542: if (ref($confhash{$provider}{'roles'}) eq 'HASH') {
15543: my $rolemaps;
15544: foreach my $role (@courseroles) {
15545: if ($confhash{$provider}{'roles'}{$role}) {
15546: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
15547: $confhash{$provider}{'roles'}{$role}.',';
15548: }
15549: }
15550: if ($rolemaps) {
15551: $rolemaps =~ s/,$//;
15552: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
15553: }
15554: }
15555: }
15556: if (ref($confhash{$provider}{'custom'}) eq 'HASH') {
15557: my $customlist;
15558: if (keys(%{$confhash{$provider}{'custom'}})) {
15559: foreach my $key (sort(keys(%{$confhash{$provider}{'custom'}}))) {
15560: $customlist .= $key.'='.$confhash{$provider}{'custom'}{$key}.', ';
15561: }
15562: $customlist =~ s/,$//;
15563: }
15564: if ($customlist) {
15565: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
15566: }
15567: }
15568: $resulttext .= '</ul></li>';
15569: }
15570: }
15571: $resulttext .= '</ul>';
15572: } else {
15573: $resulttext = &mt('No changes made.');
15574: }
15575: } else {
15576: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15577: }
15578: if ($errors) {
15579: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15580: $errors.'</ul>';
15581: }
15582: return $resulttext;
15583: }
15584:
15585: sub process_proctoring_image {
15586: my ($r,$dom,$confname,$caller,$provider,$configuserok,$switchserver,$author_ok) = @_;
15587: my $filename = $env{'form.'.$caller.'.filename'};
15588: my ($error,$url);
15589: my ($width,$height) = (21,21);
15590: if ($configuserok eq 'ok') {
15591: if ($switchserver) {
15592: $error = &mt('Upload of Remote Proctoring Provider icon is not permitted to this server: [_1]',
15593: $switchserver);
15594: } elsif ($author_ok eq 'ok') {
1.421 raeburn 15595: my $modified = [];
1.372 raeburn 15596: my ($result,$imageurl,$madethumb) =
1.421 raeburn 15597: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
15598: "proctoring/$provider/icon",$width,$height,
15599: '',$modified);
1.372 raeburn 15600: if ($result eq 'ok') {
15601: if ($madethumb) {
15602: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
15603: my $imagethumb = "$path/tn-".$imagefile;
15604: $url = $imagethumb;
15605: } else {
15606: $url = $imageurl;
15607: }
1.421 raeburn 15608: &update_modify_urls($r,$modified);
1.372 raeburn 15609: } else {
15610: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
15611: }
15612: } else {
15613: $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);
15614: }
15615: } else {
15616: $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);
15617: }
15618: return ($url,$error);
15619: }
15620:
1.320 raeburn 15621: sub modify_lti {
15622: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15623: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.424 raeburn 15624: my ($newid,@allpos,%changes,%confhash,%ltienc,$errors,$resulttext);
1.320 raeburn 15625: my (%posslti,%posslticrs,%posscrstype);
15626: my @courseroles = ('cc','in','ta','ep','st');
15627: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
15628: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
1.392 raeburn 15629: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 15630: my %coursetypetitles = &Apache::lonlocal::texthash (
15631: official => 'Official',
15632: unofficial => 'Unofficial',
15633: community => 'Community',
15634: textbook => 'Textbook',
15635: placement => 'Placement Test',
1.392 raeburn 15636: lti => 'LTI Provider',
1.320 raeburn 15637: );
1.325 raeburn 15638: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 15639: my %lt = <i_names();
15640: map { $posslti{$_} = 1; } @ltiroles;
15641: map { $posslticrs{$_} = 1; } @lticourseroles;
15642: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 15643:
1.326 raeburn 15644: my %menutitles = <imenu_titles();
1.421 raeburn 15645: my (%currltisec,%secchanges,%newltisec,%newltienc,%newkeyset);
1.326 raeburn 15646:
1.421 raeburn 15647: &fetch_secrets($dom,'ltisec',\%domconfig,\%currltisec,\%secchanges,\%newltisec,\%newkeyset);
1.405 raeburn 15648:
1.406 raeburn 15649: my (%linkprotchg,$linkprotoutput,$is_home);
15650: my $proterror = &Apache::courseprefs::process_linkprot($dom,'',$currltisec{'linkprot'},
15651: \%linkprotchg,'domain');
15652: my $home = &Apache::lonnet::domain($dom,'primary');
15653: unless (($home eq 'no_host') || ($home eq '')) {
15654: my @ids=&Apache::lonnet::current_machine_ids();
15655: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; } }
15656: }
15657:
15658: if (keys(%linkprotchg)) {
15659: $secchanges{'linkprot'} = 1;
15660: my %oldlinkprot;
15661: if (ref($currltisec{'linkprot'}) eq 'HASH') {
15662: %oldlinkprot = %{$currltisec{'linkprot'}};
15663: }
15664: foreach my $id (keys(%linkprotchg)) {
15665: if (ref($linkprotchg{$id}) eq 'HASH') {
15666: foreach my $inner (keys(%{$linkprotchg{$id}})) {
15667: if (($inner eq 'secret') || ($inner eq 'key')) {
15668: if ($is_home) {
15669: $newltienc{$id}{$inner} = $linkprotchg{$id}{$inner};
15670: }
15671: }
15672: }
15673: } else {
15674: $newltisec{'linkprot'}{$id} = $linkprotchg{$id};
15675: }
15676: }
15677: $linkprotoutput = &Apache::courseprefs::store_linkprot($dom,'','domain',\%linkprotchg,\%oldlinkprot);
15678: if (keys(%linkprotchg)) {
15679: %{$newltisec{'linkprot'}} = %linkprotchg;
15680: }
15681: }
15682: if (ref($currltisec{'linkprot'}) eq 'HASH') {
15683: foreach my $id (%{$currltisec{'linkprot'}}) {
15684: next if ($id !~ /^\d+$/);
15685: unless (exists($linkprotchg{$id})) {
15686: if (ref($currltisec{'linkprot'}{$id}) eq 'HASH') {
15687: foreach my $inner (keys(%{$currltisec{'linkprot'}{$id}})) {
15688: if (($inner eq 'secret') || ($inner eq 'key')) {
15689: if ($is_home) {
15690: $newltienc{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15691: }
15692: } else {
15693: $newltisec{'linkprot'}{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15694: }
15695: }
15696: } else {
15697: $newltisec{'linkprot'}{$id} = $currltisec{'linkprot'}{$id};
15698: }
15699: }
15700: }
15701: }
15702: if ($proterror) {
15703: $errors .= '<li>'.$proterror.'</li>';
15704: }
1.320 raeburn 15705: my (@items,%deletions,%itemids);
15706: if ($env{'form.lti_add'}) {
15707: my $consumer = $env{'form.lti_consumer_add'};
15708: $consumer =~ s/(`)/'/g;
15709: ($newid,my $error) = &get_lti_id($dom,$consumer);
15710: if ($newid) {
15711: $itemids{'add'} = $newid;
15712: push(@items,'add');
15713: $changes{$newid} = 1;
15714: } else {
15715: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
15716: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15717: }
15718: }
15719: if (ref($domconfig{$action}) eq 'HASH') {
15720: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
15721: if (@todelete) {
15722: map { $deletions{$_} = 1; } @todelete;
15723: }
15724: my $maxnum = $env{'form.lti_maxnum'};
1.390 raeburn 15725: for (my $i=0; $i<$maxnum; $i++) {
1.320 raeburn 15726: my $itemid = $env{'form.lti_id_'.$i};
15727: $itemid =~ s/\D+//g;
15728: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
15729: if ($deletions{$itemid}) {
15730: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
15731: } else {
1.390 raeburn 15732: push(@items,$i);
15733: $itemids{$i} = $itemid;
1.320 raeburn 15734: }
15735: }
15736: }
15737: }
1.424 raeburn 15738: my (%keystore,$secstored);
15739: if ($is_home) {
15740: &store_security($dom,'lti',\%secchanges,\%newkeyset,\%keystore);
15741: }
15742:
15743: my ($cipher,$privnum);
15744: if ((@items > 0) && ($is_home)) {
15745: ($cipher,$privnum) = &get_priv_creds($dom,$home,$secchanges{'encrypt'},
15746: $newltisec{'encrypt'},$keystore{$home});
15747: }
1.320 raeburn 15748: foreach my $idx (@items) {
15749: my $itemid = $itemids{$idx};
15750: next unless ($itemid);
1.424 raeburn 15751: my %currlti;
15752: unless ($idx eq 'add') {
15753: if (ref($domconfig{$action}) eq 'HASH') {
15754: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
15755: %currlti = %{$domconfig{$action}{$itemid}};
15756: }
15757: }
15758: }
1.390 raeburn 15759: my $position = $env{'form.lti_pos_'.$itemid};
1.320 raeburn 15760: $position =~ s/\D+//g;
15761: if ($position ne '') {
15762: $allpos[$position] = $itemid;
15763: }
1.424 raeburn 15764: foreach my $item ('consumer','lifetime','requser','crsinc') {
1.320 raeburn 15765: my $formitem = 'form.lti_'.$item.'_'.$idx;
15766: $env{$formitem} =~ s/(`)/'/g;
15767: if ($item eq 'lifetime') {
15768: $env{$formitem} =~ s/[^\d.]//g;
15769: }
15770: if ($env{$formitem} ne '') {
1.424 raeburn 15771: $confhash{$itemid}{$item} = $env{$formitem};
15772: unless (($idx eq 'add') || ($changes{$itemid})) {
15773: if ($currlti{$item} ne $confhash{$itemid}{$item}) {
15774: $changes{$itemid} = 1;
1.320 raeburn 15775: }
15776: }
15777: }
15778: }
15779: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
15780: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
15781: }
1.345 raeburn 15782: if ($confhash{$itemid}{'requser'}) {
15783: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
1.405 raeburn 15784: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
1.345 raeburn 15785: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
15786: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
15787: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
15788: my $mapuser = $env{'form.lti_customuser_'.$idx};
15789: $mapuser =~ s/(`)/'/g;
1.405 raeburn 15790: $mapuser =~ s/^\s+|\s+$//g;
15791: $confhash{$itemid}{'mapuser'} = $mapuser;
1.345 raeburn 15792: }
15793: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
15794: my @makeuser;
15795: foreach my $ltirole (sort(@possmakeuser)) {
15796: if ($posslti{$ltirole}) {
15797: push(@makeuser,$ltirole);
15798: }
15799: }
15800: $confhash{$itemid}{'makeuser'} = \@makeuser;
15801: if (@makeuser) {
15802: my $lcauth = $env{'form.lti_lcauth_'.$idx};
15803: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
15804: $confhash{$itemid}{'lcauth'} = $lcauth;
15805: if ($lcauth ne 'internal') {
15806: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
15807: $lcauthparm =~ s/^(\s+|\s+)$//g;
15808: $lcauthparm =~ s/`//g;
15809: if ($lcauthparm ne '') {
15810: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
15811: }
15812: }
15813: } else {
15814: $confhash{$itemid}{'lcauth'} = 'lti';
15815: }
1.320 raeburn 15816: }
1.345 raeburn 15817: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
15818: if (@possinstdata) {
15819: foreach my $field (@possinstdata) {
15820: if (exists($fieldtitles{$field})) {
15821: push(@{$confhash{$itemid}{'instdata'}});
1.325 raeburn 15822: }
15823: }
15824: }
1.363 raeburn 15825: if ($env{'form.lti_callback_'.$idx}) {
15826: if ($env{'form.lti_callbackparam_'.$idx}) {
15827: my $callback = $env{'form.lti_callbackparam_'.$idx};
15828: $callback =~ s/^\s+|\s+$//g;
15829: $confhash{$itemid}{'callback'} = $callback;
15830: }
15831: }
1.391 raeburn 15832: foreach my $field ('topmenu','inlinemenu') {
1.345 raeburn 15833: if ($env{'form.lti_'.$field.'_'.$idx}) {
15834: $confhash{$itemid}{$field} = 1;
15835: }
1.320 raeburn 15836: }
1.345 raeburn 15837: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
15838: $confhash{$itemid}{lcmenu} = [];
15839: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
15840: foreach my $field (@possmenu) {
15841: if (exists($menutitles{$field})) {
15842: if ($field eq 'grades') {
15843: next unless ($env{'form.lti_inlinemenu_'.$idx});
15844: }
15845: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 15846: }
15847: }
15848: }
1.391 raeburn 15849: if ($confhash{$itemid}{'crsinc'}) {
15850: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
15851: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
15852: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
15853: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
15854: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
15855: $mapcrs =~ s/(`)/'/g;
15856: $mapcrs =~ s/^\s+|\s+$//g;
15857: $confhash{$itemid}{'mapcrs'} = $mapcrs;
15858: }
15859: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
15860: my @crstypes;
15861: foreach my $type (sort(@posstypes)) {
15862: if ($posscrstype{$type}) {
15863: push(@crstypes,$type);
15864: }
15865: }
15866: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
1.392 raeburn 15867: if ($env{'form.lti_storecrs_'.$idx}) {
15868: $confhash{$itemid}{'storecrs'} = 1;
15869: }
1.391 raeburn 15870: if ($env{'form.lti_makecrs_'.$idx}) {
15871: $confhash{$itemid}{'makecrs'} = 1;
15872: }
15873: foreach my $ltirole (@lticourseroles) {
15874: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
15875: if (grep(/^\Q$possrole\E$/,@courseroles)) {
15876: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
15877: }
15878: }
15879: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
15880: my @selfenroll;
15881: foreach my $type (sort(@possenroll)) {
15882: if ($posslticrs{$type}) {
15883: push(@selfenroll,$type);
15884: }
15885: }
15886: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
15887: if ($env{'form.lti_crssec_'.$idx}) {
15888: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
15889: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
15890: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
15891: my $section = $env{'form.lti_customsection_'.$idx};
15892: $section =~ s/(`)/'/g;
15893: $section =~ s/^\s+|\s+$//g;
15894: if ($section ne '') {
15895: $confhash{$itemid}{'section'} = $section;
15896: }
15897: }
15898: }
15899: foreach my $field ('passback','roster') {
15900: if ($env{'form.lti_'.$field.'_'.$idx}) {
15901: $confhash{$itemid}{$field} = 1;
15902: }
15903: }
15904: if ($env{'form.lti_passback_'.$idx}) {
15905: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
15906: $confhash{$itemid}{'passbackformat'} = '1.0';
15907: } else {
15908: $confhash{$itemid}{'passbackformat'} = '1.1';
1.337 raeburn 15909: }
15910: }
1.391 raeburn 15911: }
15912: unless (($idx eq 'add') || ($changes{$itemid})) {
15913: if ($confhash{$itemid}{'crsinc'}) {
1.392 raeburn 15914: foreach my $field ('mapcrs','storecrs','makecrs','section','passback','roster') {
1.424 raeburn 15915: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.320 raeburn 15916: $changes{$itemid} = 1;
15917: }
1.345 raeburn 15918: }
15919: unless ($changes{$itemid}) {
1.424 raeburn 15920: if ($currlti{'passback'} eq $confhash{$itemid}{'passback'}) {
15921: if ($currlti{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 15922: $changes{$itemid} = 1;
15923: }
15924: }
1.345 raeburn 15925: }
1.391 raeburn 15926: foreach my $field ('mapcrstype','selfenroll') {
15927: unless ($changes{$itemid}) {
1.424 raeburn 15928: if (ref($currlti{$field}) eq 'ARRAY') {
1.391 raeburn 15929: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424 raeburn 15930: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391 raeburn 15931: $confhash{$itemid}{$field});
15932: if (@diffs) {
15933: $changes{$itemid} = 1;
15934: }
1.424 raeburn 15935: } elsif (@{$currlti{$field}} > 0) {
1.391 raeburn 15936: $changes{$itemid} = 1;
15937: }
15938: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
15939: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 15940: $changes{$itemid} = 1;
15941: }
15942: }
1.391 raeburn 15943: }
15944: }
15945: unless ($changes{$itemid}) {
1.424 raeburn 15946: if (ref($currlti{'maproles'}) eq 'HASH') {
1.391 raeburn 15947: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
1.424 raeburn 15948: foreach my $ltirole (keys(%{$currlti{'maproles'}})) {
15949: if ($currlti{'maproles'}{$ltirole} ne
1.391 raeburn 15950: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.345 raeburn 15951: $changes{$itemid} = 1;
15952: last;
15953: }
15954: }
1.391 raeburn 15955: unless ($changes{$itemid}) {
15956: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
15957: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
1.424 raeburn 15958: $currlti{'maproles'}{$ltirole}) {
1.391 raeburn 15959: $changes{$itemid} = 1;
15960: last;
15961: }
15962: }
15963: }
1.424 raeburn 15964: } elsif (keys(%{$currlti{'maproles'}}) > 0) {
1.391 raeburn 15965: $changes{$itemid} = 1;
1.345 raeburn 15966: }
1.391 raeburn 15967: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
15968: unless ($changes{$itemid}) {
15969: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
15970: $changes{$itemid} = 1;
15971: }
15972: }
15973: }
15974: }
15975: }
15976: unless ($changes{$itemid}) {
15977: foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
1.424 raeburn 15978: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.345 raeburn 15979: $changes{$itemid} = 1;
1.320 raeburn 15980: }
1.391 raeburn 15981: }
15982: unless ($changes{$itemid}) {
15983: foreach my $field ('makeuser','lcmenu') {
1.424 raeburn 15984: if (ref($currlti{$field}) eq 'ARRAY') {
1.391 raeburn 15985: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424 raeburn 15986: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391 raeburn 15987: $confhash{$itemid}{$field});
15988: if (@diffs) {
15989: $changes{$itemid} = 1;
15990: }
1.424 raeburn 15991: } elsif (@{$currlti{$field}} > 0) {
1.391 raeburn 15992: $changes{$itemid} = 1;
15993: }
15994: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
15995: if (@{$confhash{$itemid}{$field}} > 0) {
15996: $changes{$itemid} = 1;
15997: }
1.345 raeburn 15998: }
1.320 raeburn 15999: }
16000: }
16001: }
16002: }
16003: }
1.424 raeburn 16004: if ($is_home) {
16005: my $keyitem = 'form.lti_key_'.$idx;
16006: $env{$keyitem} =~ s/(`)/'/g;
16007: if ($env{$keyitem} ne '') {
16008: $ltienc{$itemid}{'key'} = $env{$keyitem};
16009: unless ($changes{$itemid}) {
16010: if ($currlti{'key'} ne $env{$keyitem}) {
16011: $changes{$itemid} = 1;
16012: }
16013: }
16014: }
16015: my $secretitem = 'form.lti_secret_'.$idx;
16016: $env{$secretitem} =~ s/(`)/'/g;
16017: if ($currlti{'usable'}) {
16018: if ($env{'form.lti_changesecret_'.$idx}) {
16019: if ($env{$secretitem} ne '') {
16020: if ($privnum && $cipher) {
16021: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
16022: $confhash{$itemid}{'cipher'} = $privnum;
16023: } else {
16024: $ltienc{$itemid}{'secret'} = $env{$secretitem};
16025: }
16026: $changes{$itemid} = 1;
16027: }
16028: } else {
16029: $ltienc{$itemid}{'secret'} = $currlti{'secret'};
16030: $confhash{$itemid}{'cipher'} = $currlti{'cipher'};
16031: }
16032: if (ref($ltienc{$itemid}) eq 'HASH') {
16033: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'secret'} ne '')) {
16034: $confhash{$itemid}{'usable'} = 1;
16035: }
16036: }
16037: } elsif ($env{$secretitem} ne '') {
16038: if ($privnum && $cipher) {
16039: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
16040: $confhash{$itemid}{'cipher'} = $privnum;
16041: } else {
16042: $ltienc{$itemid}{'secret'} = $env{$secretitem};
16043: }
16044: if (ref($ltienc{$itemid}) eq 'HASH') {
16045: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'key'} ne '')) {
16046: $confhash{$itemid}{'usable'} = 1;
16047: }
16048: }
16049: $changes{$itemid} = 1;
16050: }
16051: }
16052: unless ($changes{$itemid}) {
16053: foreach my $key (keys(%currlti)) {
16054: if (ref($currlti{$key}) eq 'HASH') {
16055: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
16056: foreach my $innerkey (keys(%{$currlti{$key}})) {
16057: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
16058: $changes{$itemid} = 1;
16059: last;
16060: }
16061: }
16062: } elsif (keys(%{$currlti{$key}}) > 0) {
16063: $changes{$itemid} = 1;
16064: }
16065: }
16066: last if ($changes{$itemid});
16067: }
16068: }
1.320 raeburn 16069: }
16070: if (@allpos > 0) {
16071: my $idx = 0;
16072: foreach my $itemid (@allpos) {
16073: if ($itemid ne '') {
16074: $confhash{$itemid}{'order'} = $idx;
16075: if (ref($domconfig{$action}) eq 'HASH') {
16076: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
16077: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
16078: $changes{$itemid} = 1;
16079: }
16080: }
16081: }
16082: $idx ++;
16083: }
16084: }
16085: }
1.424 raeburn 16086:
16087: if ((keys(%changes) == 0) && (keys(%secchanges) == 0)) {
16088: return &mt('No changes made.');
16089: }
16090:
1.320 raeburn 16091: my %ltihash = (
1.405 raeburn 16092: $action => { %confhash }
16093: );
1.424 raeburn 16094: my %ltienchash;
16095:
16096: if ($is_home) {
16097: %ltienchash = (
16098: $action => { %ltienc }
16099: );
16100: }
1.405 raeburn 16101: if (keys(%secchanges)) {
16102: $ltihash{'ltisec'} = \%newltisec;
1.406 raeburn 16103: if ($secchanges{'linkprot'}) {
16104: if ($is_home) {
16105: $ltienchash{'linkprot'} = \%newltienc;
16106: }
16107: }
1.405 raeburn 16108: }
16109: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,$dom);
1.320 raeburn 16110: if ($putresult eq 'ok') {
1.424 raeburn 16111: if (keys(%ltienchash)) {
16112: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.405 raeburn 16113: }
16114: $resulttext = &mt('Changes made:').'<ul>';
16115: if (keys(%secchanges) > 0) {
1.423 raeburn 16116: $resulttext .= <i_security_results($dom,'lti',\%secchanges,\%newltisec,\%newkeyset,\%keystore);
1.421 raeburn 16117: if (exists($secchanges{'linkprot'})) {
16118: $resulttext .= $linkprotoutput;
1.405 raeburn 16119: }
16120: }
1.320 raeburn 16121: if (keys(%changes) > 0) {
16122: my $cachetime = 24*60*60;
1.424 raeburn 16123: &Apache::lonnet::do_cache_new('lti',$dom,\%confhash,$cachetime);
1.320 raeburn 16124: if (ref($lastactref) eq 'HASH') {
16125: $lastactref->{'lti'} = 1;
16126: }
16127: my %bynum;
16128: foreach my $itemid (sort(keys(%changes))) {
1.424 raeburn 16129: if (ref($confhash{$itemid}) eq 'HASH') {
16130: my $position = $confhash{$itemid}{'order'};
16131: $bynum{$position} = $itemid;
16132: }
1.320 raeburn 16133: }
16134: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
16135: my $itemid = $bynum{$pos};
1.424 raeburn 16136: if (ref($confhash{$itemid}) eq 'HASH') {
1.390 raeburn 16137: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1.320 raeburn 16138: my $position = $pos + 1;
16139: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
16140: foreach my $item ('version','lifetime') {
16141: if ($confhash{$itemid}{$item} ne '') {
16142: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
16143: }
16144: }
1.424 raeburn 16145: if ($ltienc{$itemid}{'key'} ne '') {
16146: $resulttext .= '<li>'.$lt{'key'}.': '.$ltienc{$itemid}{'key'}.'</li>';
1.320 raeburn 16147: }
1.424 raeburn 16148: if ($ltienc{$itemid}{'secret'} ne '') {
16149: $resulttext .= '<li>'.$lt{'secret'}.': ['.&mt('not shown').']</li>';
1.320 raeburn 16150: }
1.345 raeburn 16151: if ($confhash{$itemid}{'requser'}) {
1.391 raeburn 16152: if ($confhash{$itemid}{'callback'}) {
16153: $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
16154: } else {
1.392 raeburn 16155: $resulttext .= '<li>'.&mt('Callback to logout LON-CAPA on log out from Consumer').'</li>';
1.391 raeburn 16156: }
1.345 raeburn 16157: if ($confhash{$itemid}{'mapuser'}) {
16158: my $shownmapuser;
16159: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
16160: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
16161: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
16162: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
16163: } else {
16164: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 16165: }
1.345 raeburn 16166: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 16167: }
1.345 raeburn 16168: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
16169: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
16170: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
16171: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
16172: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
16173: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
16174: } else {
16175: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
16176: $confhash{$itemid}{'lcauth'});
16177: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
16178: $resulttext .= '; '.&mt('a randomly generated password will be created');
16179: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
16180: if ($confhash{$itemid}{'lcauthparm'} ne '') {
16181: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
16182: }
16183: } else {
16184: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
16185: }
16186: }
16187: $resulttext .= '</li>';
16188: } else {
16189: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
16190: }
1.320 raeburn 16191: }
1.345 raeburn 16192: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
16193: if (@{$confhash{$itemid}{'instdata'}} > 0) {
16194: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
16195: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 16196: } else {
1.345 raeburn 16197: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325 raeburn 16198: }
1.320 raeburn 16199: }
1.391 raeburn 16200: foreach my $item ('topmenu','inlinemenu') {
1.345 raeburn 16201: $resulttext .= '<li>'.$lt{$item}.': ';
16202: if ($confhash{$itemid}{$item}) {
16203: $resulttext .= &mt('Yes');
16204: } else {
16205: $resulttext .= &mt('No');
1.337 raeburn 16206: }
1.345 raeburn 16207: $resulttext .= '</li>';
1.320 raeburn 16208: }
1.345 raeburn 16209: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16210: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16211: $resulttext .= '<li>'.&mt('Menu items:').' '.
1.391 raeburn 16212: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16213: } else {
16214: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16215: }
16216: }
16217: if ($confhash{$itemid}{'crsinc'}) {
16218: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16219: my $rolemaps;
16220: foreach my $role (@ltiroles) {
16221: if ($confhash{$itemid}{'maproles'}{$role}) {
16222: $rolemaps .= (' 'x2).$role.'='.
16223: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
16224: 'Course').',';
16225: }
16226: }
16227: if ($rolemaps) {
16228: $rolemaps =~ s/,$//;
16229: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
16230: }
16231: }
16232: if ($confhash{$itemid}{'mapcrs'}) {
16233: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
16234: }
16235: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
16236: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
16237: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
16238: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
16239: '</li>';
16240: } else {
16241: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
16242: }
16243: }
1.392 raeburn 16244: if ($confhash{$itemid}{'storecrs'}) {
16245: $resulttext .= '<li>'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.$confhash{$itemid}{'storecrs'}.'</li>';
16246: }
1.391 raeburn 16247: if ($confhash{$itemid}{'makecrs'}) {
16248: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
16249: } else {
16250: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
16251: }
16252: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
16253: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
16254: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
16255: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
16256: '</li>';
16257: } else {
16258: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
16259: }
16260: }
16261: if ($confhash{$itemid}{'section'}) {
16262: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
16263: $resulttext .= '<li>'.&mt('User section from standard field:').
16264: ' (course_section_sourcedid)'.'</li>';
16265: } else {
16266: $resulttext .= '<li>'.&mt('User section from:').' '.
16267: $confhash{$itemid}{'section'}.'</li>';
16268: }
1.345 raeburn 16269: } else {
1.391 raeburn 16270: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
16271: }
16272: foreach my $item ('passback','roster','topmenu','inlinemenu') {
16273: $resulttext .= '<li>'.$lt{$item}.': ';
16274: if ($confhash{$itemid}{$item}) {
16275: $resulttext .= &mt('Yes');
16276: if ($item eq 'passback') {
16277: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
16278: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
16279: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
16280: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
16281: }
16282: }
16283: } else {
16284: $resulttext .= &mt('No');
16285: }
16286: $resulttext .= '</li>';
16287: }
16288: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16289: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16290: $resulttext .= '<li>'.&mt('Menu items:').' '.
16291: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16292: } else {
16293: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16294: }
1.345 raeburn 16295: }
1.326 raeburn 16296: }
16297: }
1.320 raeburn 16298: $resulttext .= '</ul></li>';
16299: }
16300: }
1.424 raeburn 16301: if (keys(%deletions)) {
16302: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
16303: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
16304: }
16305: }
1.320 raeburn 16306: }
1.405 raeburn 16307: $resulttext .= '</ul>';
1.424 raeburn 16308: if (ref($lastactref) eq 'HASH') {
16309: if (($secchanges{'encrypt'}) || ($secchanges{'private'})) {
16310: $lastactref->{'domdefaults'} = 1;
16311: }
16312: }
1.320 raeburn 16313: } else {
16314: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
16315: }
16316: if ($errors) {
16317: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
16318: $errors.'</ul>';
16319: }
16320: return $resulttext;
16321: }
16322:
1.424 raeburn 16323: sub get_priv_creds {
16324: my ($dom,$home,$encchg,$encrypt,$storedsec) = @_;
16325: my ($needenc,$cipher,$privnum);
16326: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
16327: if (($encchg) && (ref($encrypt) eq 'HASH')) {
16328: $needenc = $encrypt->{'consumers'}
16329: } else {
16330: $needenc = $domdefs{'ltienc_consumers'};
16331: }
16332: if ($needenc) {
16333: if (($storedsec eq 'ok') || ((ref($domdefs{'ltiprivhosts'}) eq 'ARRAY') &&
16334: (grep(/^\Q$home\E$/,@{$domdefs{'ltiprivhosts'}})))) {
16335: my %privhash = &Apache::lonnet::restore_dom('lti','private',$dom,$home,1);
16336: my $privkey = $privhash{'key'};
16337: $privnum = $privhash{'version'};
16338: if (($privnum) && ($privkey ne '')) {
16339: $cipher = Crypt::CBC->new({'key' => $privkey,
16340: 'cipher' => 'DES'});
16341: }
16342: }
16343: }
16344: return ($cipher,$privnum);
16345: }
16346:
1.320 raeburn 16347: sub get_lti_id {
16348: my ($domain,$consumer) = @_;
16349: # get lock on lti db
16350: my $lockhash = {
16351: lock => $env{'user.name'}.
16352: ':'.$env{'user.domain'},
16353: };
16354: my $tries = 0;
16355: my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
16356: my ($id,$error);
16357:
16358: while (($gotlock ne 'ok') && ($tries<10)) {
16359: $tries ++;
16360: sleep (0.1);
16361: $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
16362: }
16363: if ($gotlock eq 'ok') {
16364: my %currids = &Apache::lonnet::dump_dom('lti',$domain);
16365: if ($currids{'lock'}) {
16366: delete($currids{'lock'});
16367: if (keys(%currids)) {
16368: my @curr = sort { $a <=> $b } keys(%currids);
16369: if ($curr[-1] =~ /^\d+$/) {
16370: $id = 1 + $curr[-1];
16371: }
16372: } else {
16373: $id = 1;
16374: }
16375: if ($id) {
16376: unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
16377: $error = 'nostore';
16378: }
16379: } else {
16380: $error = 'nonumber';
16381: }
16382: }
16383: my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
16384: } else {
16385: $error = 'nolock';
16386: }
16387: return ($id,$error);
16388: }
16389:
1.3 raeburn 16390: sub modify_autoenroll {
1.205 raeburn 16391: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 16392: my ($resulttext,%changes);
16393: my %currautoenroll;
16394: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
16395: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
16396: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
16397: }
16398: }
16399: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
16400: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 16401: sender => 'Sender for notification messages',
1.274 raeburn 16402: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.399 raeburn 16403: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 16404: my @offon = ('off','on');
1.17 raeburn 16405: my $sender_uname = $env{'form.sender_uname'};
16406: my $sender_domain = $env{'form.sender_domain'};
16407: if ($sender_domain eq '') {
16408: $sender_uname = '';
16409: } elsif ($sender_uname eq '') {
16410: $sender_domain = '';
16411: }
1.129 raeburn 16412: my $coowners = $env{'form.autoassign_coowners'};
1.399 raeburn 16413: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
16414: $autofailsafe =~ s{^\s+|\s+$}{}g;
16415: if ($autofailsafe =~ /\D/) {
16416: undef($autofailsafe);
16417: }
1.274 raeburn 16418: my $failsafe = $env{'form.autoenroll_failsafe'};
1.399 raeburn 16419: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
16420: $failsafe = 'off';
1.400 raeburn 16421: undef($autofailsafe);
1.274 raeburn 16422: }
1.1 raeburn 16423: my %autoenrollhash = (
1.129 raeburn 16424: autoenroll => { 'run' => $env{'form.autoenroll_run'},
16425: 'sender_uname' => $sender_uname,
16426: 'sender_domain' => $sender_domain,
16427: 'co-owners' => $coowners,
1.399 raeburn 16428: 'autofailsafe' => $autofailsafe,
1.400 raeburn 16429: 'failsafe' => $failsafe,
1.1 raeburn 16430: }
16431: );
1.4 raeburn 16432: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
16433: $dom);
1.1 raeburn 16434: if ($putresult eq 'ok') {
16435: if (exists($currautoenroll{'run'})) {
16436: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
16437: $changes{'run'} = 1;
16438: }
16439: } elsif ($autorun) {
16440: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 16441: $changes{'run'} = 1;
1.1 raeburn 16442: }
16443: }
1.17 raeburn 16444: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 16445: $changes{'sender'} = 1;
16446: }
1.17 raeburn 16447: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 16448: $changes{'sender'} = 1;
16449: }
1.129 raeburn 16450: if ($currautoenroll{'co-owners'} ne '') {
16451: if ($currautoenroll{'co-owners'} ne $coowners) {
16452: $changes{'coowners'} = 1;
16453: }
16454: } elsif ($coowners) {
16455: $changes{'coowners'} = 1;
1.274 raeburn 16456: }
1.399 raeburn 16457: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.274 raeburn 16458: $changes{'autofailsafe'} = 1;
16459: }
1.399 raeburn 16460: if ($currautoenroll{'failsafe'} ne $failsafe) {
16461: $changes{'failsafe'} = 1;
16462: }
1.1 raeburn 16463: if (keys(%changes) > 0) {
16464: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 16465: if ($changes{'run'}) {
1.1 raeburn 16466: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
16467: }
16468: if ($changes{'sender'}) {
1.17 raeburn 16469: if ($sender_uname eq '' || $sender_domain eq '') {
16470: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
16471: } else {
16472: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
16473: }
1.1 raeburn 16474: }
1.129 raeburn 16475: if ($changes{'coowners'}) {
16476: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
16477: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 16478: if (ref($lastactref) eq 'HASH') {
16479: $lastactref->{'domainconfig'} = 1;
16480: }
1.129 raeburn 16481: }
1.274 raeburn 16482: if ($changes{'autofailsafe'}) {
1.399 raeburn 16483: if ($autofailsafe ne '') {
16484: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.274 raeburn 16485: } else {
1.399 raeburn 16486: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.274 raeburn 16487: }
1.399 raeburn 16488: }
16489: if ($changes{'failsafe'}) {
16490: if ($failsafe eq 'off') {
16491: unless ($changes{'autofailsafe'}) {
16492: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
16493: }
16494: } elsif ($failsafe eq 'zero') {
16495: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
16496: } else {
16497: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
16498: }
16499: }
16500: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.274 raeburn 16501: &Apache::lonnet::get_domain_defaults($dom,1);
16502: if (ref($lastactref) eq 'HASH') {
16503: $lastactref->{'domdefaults'} = 1;
16504: }
16505: }
1.1 raeburn 16506: $resulttext .= '</ul>';
16507: } else {
16508: $resulttext = &mt('No changes made to auto-enrollment settings');
16509: }
16510: } else {
1.11 albertel 16511: $resulttext = '<span class="LC_error">'.
16512: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16513: }
1.3 raeburn 16514: return $resulttext;
1.1 raeburn 16515: }
16516:
16517: sub modify_autoupdate {
1.3 raeburn 16518: my ($dom,%domconfig) = @_;
1.1 raeburn 16519: my ($resulttext,%currautoupdate,%fields,%changes);
16520: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
16521: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
16522: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
16523: }
16524: }
16525: my @offon = ('off','on');
16526: my %title = &Apache::lonlocal::texthash (
1.385 raeburn 16527: run => 'Auto-update:',
16528: classlists => 'Updates to user information in classlists?',
16529: unexpired => 'Skip updates for users without active or future roles?',
16530: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 16531: );
1.44 raeburn 16532: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 16533: my %fieldtitles = &Apache::lonlocal::texthash (
16534: id => 'Student/Employee ID',
1.20 raeburn 16535: permanentemail => 'E-mail address',
1.1 raeburn 16536: lastname => 'Last Name',
16537: firstname => 'First Name',
16538: middlename => 'Middle Name',
1.132 raeburn 16539: generation => 'Generation',
1.1 raeburn 16540: );
1.142 raeburn 16541: $othertitle = &mt('All users');
1.1 raeburn 16542: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 16543: $othertitle = &mt('Other users');
1.1 raeburn 16544: }
16545: foreach my $key (keys(%env)) {
16546: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 16547: my ($usertype,$item) = ($1,$2);
16548: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
16549: if ($usertype eq 'default') {
16550: push(@{$fields{$1}},$2);
16551: } elsif (ref($types) eq 'ARRAY') {
16552: if (grep(/^\Q$usertype\E$/,@{$types})) {
16553: push(@{$fields{$1}},$2);
16554: }
16555: }
16556: }
1.1 raeburn 16557: }
16558: }
1.131 raeburn 16559: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
16560: @lockablenames = sort(@lockablenames);
16561: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
16562: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16563: if (@changed) {
16564: $changes{'lockablenames'} = 1;
16565: }
16566: } else {
16567: if (@lockablenames) {
16568: $changes{'lockablenames'} = 1;
16569: }
16570: }
1.1 raeburn 16571: my %updatehash = (
16572: autoupdate => { run => $env{'form.autoupdate_run'},
16573: classlists => $env{'form.classlists'},
1.385 raeburn 16574: unexpired => $env{'form.unexpired'},
1.1 raeburn 16575: fields => {%fields},
1.131 raeburn 16576: lockablenames => \@lockablenames,
1.1 raeburn 16577: }
16578: );
1.385 raeburn 16579: my $lastactivedays;
16580: if ($env{'form.lastactive'}) {
16581: $lastactivedays = $env{'form.lastactivedays'};
16582: $lastactivedays =~ s/^\s+|\s+$//g;
16583: unless ($lastactivedays =~ /^\d+$/) {
16584: undef($lastactivedays);
16585: $env{'form.lastactive'} = 0;
16586: }
16587: }
16588: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 16589: foreach my $key (keys(%currautoupdate)) {
1.385 raeburn 16590: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 16591: if (exists($updatehash{autoupdate}{$key})) {
16592: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
16593: $changes{$key} = 1;
16594: }
16595: }
16596: } elsif ($key eq 'fields') {
16597: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 16598: foreach my $item (@{$types},'default') {
1.1 raeburn 16599: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
16600: my $change = 0;
16601: foreach my $type (@{$currautoupdate{$key}{$item}}) {
16602: if (!exists($fields{$item})) {
16603: $change = 1;
1.132 raeburn 16604: last;
1.1 raeburn 16605: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 16606: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 16607: $change = 1;
1.132 raeburn 16608: last;
1.1 raeburn 16609: }
16610: }
16611: }
16612: if ($change) {
16613: push(@{$changes{$key}},$item);
16614: }
1.26 raeburn 16615: }
1.1 raeburn 16616: }
16617: }
1.131 raeburn 16618: } elsif ($key eq 'lockablenames') {
16619: if (ref($currautoupdate{$key}) eq 'ARRAY') {
16620: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16621: if (@changed) {
16622: $changes{'lockablenames'} = 1;
16623: }
16624: } else {
16625: if (@lockablenames) {
16626: $changes{'lockablenames'} = 1;
16627: }
16628: }
16629: }
16630: }
16631: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
16632: if (@lockablenames) {
16633: $changes{'lockablenames'} = 1;
1.1 raeburn 16634: }
16635: }
1.385 raeburn 16636: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
16637: if ($updatehash{'autoupdate'}{'unexpired'}) {
16638: $changes{'unexpired'} = 1;
16639: }
16640: }
16641: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
16642: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
16643: $changes{'lastactive'} = 1;
16644: }
16645: }
1.26 raeburn 16646: foreach my $item (@{$types},'default') {
16647: if (defined($fields{$item})) {
16648: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 16649: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
16650: my $change = 0;
16651: if (ref($fields{$item}) eq 'ARRAY') {
16652: foreach my $type (@{$fields{$item}}) {
16653: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
16654: $change = 1;
16655: last;
16656: }
16657: }
16658: }
16659: if ($change) {
16660: push(@{$changes{'fields'}},$item);
16661: }
16662: } else {
1.26 raeburn 16663: push(@{$changes{'fields'}},$item);
16664: }
16665: } else {
16666: push(@{$changes{'fields'}},$item);
1.1 raeburn 16667: }
16668: }
16669: }
16670: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
16671: $dom);
16672: if ($putresult eq 'ok') {
16673: if (keys(%changes) > 0) {
16674: $resulttext = &mt('Changes made:').'<ul>';
16675: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 16676: if ($key eq 'lockablenames') {
16677: $resulttext .= '<li>';
16678: if (@lockablenames) {
16679: $usertypes->{'default'} = $othertitle;
16680: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
16681: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
16682: } else {
16683: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
16684: }
16685: $resulttext .= '</li>';
16686: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 16687: foreach my $item (@{$changes{$key}}) {
16688: my @newvalues;
16689: foreach my $type (@{$fields{$item}}) {
16690: push(@newvalues,$fieldtitles{$type});
16691: }
1.3 raeburn 16692: my $newvaluestr;
16693: if (@newvalues > 0) {
16694: $newvaluestr = join(', ',@newvalues);
16695: } else {
16696: $newvaluestr = &mt('none');
1.6 raeburn 16697: }
1.1 raeburn 16698: if ($item eq 'default') {
1.26 raeburn 16699: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 16700: } else {
1.26 raeburn 16701: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 16702: }
16703: }
16704: } else {
16705: my $newvalue;
16706: if ($key eq 'run') {
16707: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.385 raeburn 16708: } elsif ($key eq 'lastactive') {
16709: $newvalue = $offon[$env{'form.lastactive'}];
16710: unless ($lastactivedays eq '') {
16711: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
16712: }
1.1 raeburn 16713: } else {
16714: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 16715: }
1.1 raeburn 16716: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
16717: }
16718: }
16719: $resulttext .= '</ul>';
16720: } else {
1.3 raeburn 16721: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 16722: }
16723: } else {
1.11 albertel 16724: $resulttext = '<span class="LC_error">'.
16725: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16726: }
1.3 raeburn 16727: return $resulttext;
1.1 raeburn 16728: }
16729:
1.125 raeburn 16730: sub modify_autocreate {
16731: my ($dom,%domconfig) = @_;
16732: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
16733: if (ref($domconfig{'autocreate'}) eq 'HASH') {
16734: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
16735: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
16736: }
16737: }
16738: my %title= ( xml => 'Auto-creation of courses in XML course description files',
16739: req => 'Auto-creation of validated requests for official courses',
16740: xmldc => 'Identity of course creator of courses from XML files',
16741: );
16742: my @types = ('xml','req');
16743: foreach my $item (@types) {
16744: $newvals{$item} = $env{'form.autocreate_'.$item};
16745: $newvals{$item} =~ s/\D//g;
16746: $newvals{$item} = 0 if ($newvals{$item} eq '');
16747: }
16748: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 16749: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 16750: unless (exists($domcoords{$newvals{'xmldc'}})) {
16751: $newvals{'xmldc'} = '';
16752: }
16753: %autocreatehash = (
16754: autocreate => { xml => $newvals{'xml'},
16755: req => $newvals{'req'},
16756: }
16757: );
16758: if ($newvals{'xmldc'} ne '') {
16759: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
16760: }
16761: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
16762: $dom);
16763: if ($putresult eq 'ok') {
16764: my @items = @types;
16765: if ($newvals{'xml'}) {
16766: push(@items,'xmldc');
16767: }
16768: foreach my $item (@items) {
16769: if (exists($currautocreate{$item})) {
16770: if ($currautocreate{$item} ne $newvals{$item}) {
16771: $changes{$item} = 1;
16772: }
16773: } elsif ($newvals{$item}) {
16774: $changes{$item} = 1;
16775: }
16776: }
16777: if (keys(%changes) > 0) {
16778: my @offon = ('off','on');
16779: $resulttext = &mt('Changes made:').'<ul>';
16780: foreach my $item (@types) {
16781: if ($changes{$item}) {
16782: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 16783: $resulttext .= '<li>'.
16784: &mt("$title{$item} set to [_1]$newtxt [_2]",
16785: '<b>','</b>').
16786: '</li>';
1.125 raeburn 16787: }
16788: }
16789: if ($changes{'xmldc'}) {
16790: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
16791: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 16792: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 16793: }
16794: $resulttext .= '</ul>';
16795: } else {
16796: $resulttext = &mt('No changes made to auto-creation settings');
16797: }
16798: } else {
16799: $resulttext = '<span class="LC_error">'.
16800: &mt('An error occurred: [_1]',$putresult).'</span>';
16801: }
16802: return $resulttext;
16803: }
16804:
1.23 raeburn 16805: sub modify_directorysrch {
1.295 raeburn 16806: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 16807: my ($resulttext,%changes);
16808: my %currdirsrch;
16809: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
16810: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
16811: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
16812: }
16813: }
1.277 raeburn 16814: my %title = ( available => 'Institutional directory search available',
16815: localonly => 'Other domains can search institution',
16816: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 16817: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 16818: searchby => 'Search types',
16819: searchtypes => 'Search latitude');
16820: my @offon = ('off','on');
1.24 raeburn 16821: my @otherdoms = ('Yes','No');
1.23 raeburn 16822:
1.25 raeburn 16823: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 16824: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
16825: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
16826:
1.44 raeburn 16827: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 16828: if (keys(%{$usertypes}) == 0) {
16829: @cansearch = ('default');
16830: } else {
16831: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
16832: foreach my $type (@{$currdirsrch{'cansearch'}}) {
16833: if (!grep(/^\Q$type\E$/,@cansearch)) {
16834: push(@{$changes{'cansearch'}},$type);
16835: }
1.23 raeburn 16836: }
1.26 raeburn 16837: foreach my $type (@cansearch) {
16838: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
16839: push(@{$changes{'cansearch'}},$type);
16840: }
1.23 raeburn 16841: }
1.26 raeburn 16842: } else {
16843: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 16844: }
16845: }
16846:
16847: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
16848: foreach my $by (@{$currdirsrch{'searchby'}}) {
16849: if (!grep(/^\Q$by\E$/,@searchby)) {
16850: push(@{$changes{'searchby'}},$by);
16851: }
16852: }
16853: foreach my $by (@searchby) {
16854: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
16855: push(@{$changes{'searchby'}},$by);
16856: }
16857: }
16858: } else {
16859: push(@{$changes{'searchby'}},@searchby);
16860: }
1.25 raeburn 16861:
16862: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
16863: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
16864: if (!grep(/^\Q$type\E$/,@searchtypes)) {
16865: push(@{$changes{'searchtypes'}},$type);
16866: }
16867: }
16868: foreach my $type (@searchtypes) {
16869: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
16870: push(@{$changes{'searchtypes'}},$type);
16871: }
16872: }
16873: } else {
16874: if (exists($currdirsrch{'searchtypes'})) {
16875: foreach my $type (@searchtypes) {
16876: if ($type ne $currdirsrch{'searchtypes'}) {
16877: push(@{$changes{'searchtypes'}},$type);
16878: }
16879: }
16880: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
16881: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
16882: }
16883: } else {
16884: push(@{$changes{'searchtypes'}},@searchtypes);
16885: }
16886: }
16887:
1.23 raeburn 16888: my %dirsrch_hash = (
16889: directorysrch => { available => $env{'form.dirsrch_available'},
16890: cansearch => \@cansearch,
1.277 raeburn 16891: localonly => $env{'form.dirsrch_instlocalonly'},
16892: lclocalonly => $env{'form.dirsrch_domlocalonly'},
16893: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 16894: searchby => \@searchby,
1.25 raeburn 16895: searchtypes => \@searchtypes,
1.23 raeburn 16896: }
16897: );
16898: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
16899: $dom);
16900: if ($putresult eq 'ok') {
16901: if (exists($currdirsrch{'available'})) {
16902: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
16903: $changes{'available'} = 1;
16904: }
16905: } else {
16906: if ($env{'form.dirsrch_available'} eq '1') {
16907: $changes{'available'} = 1;
16908: }
16909: }
1.277 raeburn 16910: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 16911: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
16912: $changes{'lcavailable'} = 1;
16913: }
1.277 raeburn 16914: } else {
16915: if ($env{'form.dirsrch_lcavailable'} eq '1') {
16916: $changes{'lcavailable'} = 1;
16917: }
16918: }
1.24 raeburn 16919: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 16920: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
16921: $changes{'localonly'} = 1;
16922: }
1.24 raeburn 16923: } else {
1.277 raeburn 16924: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 16925: $changes{'localonly'} = 1;
16926: }
16927: }
1.277 raeburn 16928: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 16929: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
16930: $changes{'lclocalonly'} = 1;
16931: }
1.277 raeburn 16932: } else {
16933: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
16934: $changes{'lclocalonly'} = 1;
16935: }
16936: }
1.23 raeburn 16937: if (keys(%changes) > 0) {
16938: $resulttext = &mt('Changes made:').'<ul>';
16939: if ($changes{'available'}) {
16940: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
16941: }
1.277 raeburn 16942: if ($changes{'lcavailable'}) {
16943: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
16944: }
1.24 raeburn 16945: if ($changes{'localonly'}) {
1.277 raeburn 16946: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 16947: }
1.277 raeburn 16948: if ($changes{'lclocalonly'}) {
16949: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 16950: }
1.23 raeburn 16951: if (ref($changes{'cansearch'}) eq 'ARRAY') {
16952: my $chgtext;
1.26 raeburn 16953: if (ref($usertypes) eq 'HASH') {
16954: if (keys(%{$usertypes}) > 0) {
16955: foreach my $type (@{$types}) {
16956: if (grep(/^\Q$type\E$/,@cansearch)) {
16957: $chgtext .= $usertypes->{$type}.'; ';
16958: }
16959: }
16960: if (grep(/^default$/,@cansearch)) {
16961: $chgtext .= $othertitle;
16962: } else {
16963: $chgtext =~ s/\; $//;
16964: }
1.210 raeburn 16965: $resulttext .=
1.178 raeburn 16966: '<li>'.
16967: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
16968: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
16969: '</li>';
1.23 raeburn 16970: }
16971: }
16972: }
16973: if (ref($changes{'searchby'}) eq 'ARRAY') {
16974: my ($searchtitles,$titleorder) = &sorted_searchtitles();
16975: my $chgtext;
16976: foreach my $type (@{$titleorder}) {
16977: if (grep(/^\Q$type\E$/,@searchby)) {
16978: if (defined($searchtitles->{$type})) {
16979: $chgtext .= $searchtitles->{$type}.'; ';
16980: }
16981: }
16982: }
16983: $chgtext =~ s/\; $//;
16984: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
16985: }
1.25 raeburn 16986: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
16987: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
16988: my $chgtext;
16989: foreach my $type (@{$srchtypeorder}) {
16990: if (grep(/^\Q$type\E$/,@searchtypes)) {
16991: if (defined($srchtypes_desc->{$type})) {
16992: $chgtext .= $srchtypes_desc->{$type}.'; ';
16993: }
16994: }
16995: }
16996: $chgtext =~ s/\; $//;
1.178 raeburn 16997: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 16998: }
16999: $resulttext .= '</ul>';
1.295 raeburn 17000: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
17001: if (ref($lastactref) eq 'HASH') {
17002: $lastactref->{'directorysrch'} = 1;
17003: }
1.23 raeburn 17004: } else {
1.277 raeburn 17005: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 17006: }
17007: } else {
17008: $resulttext = '<span class="LC_error">'.
1.27 raeburn 17009: &mt('An error occurred: [_1]',$putresult).'</span>';
17010: }
17011: return $resulttext;
17012: }
17013:
1.28 raeburn 17014: sub modify_contacts {
1.205 raeburn 17015: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 17016: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
17017: if (ref($domconfig{'contacts'}) eq 'HASH') {
17018: foreach my $key (keys(%{$domconfig{'contacts'}})) {
17019: $currsetting{$key} = $domconfig{'contacts'}{$key};
17020: }
17021: }
1.286 raeburn 17022: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 17023: my @contacts = ('supportemail','adminemail');
1.286 raeburn 17024: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350 raeburn 17025: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340 raeburn 17026: my @toggles = ('reporterrors','reportupdates','reportstatus');
17027: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 17028: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 17029: foreach my $type (@mailings) {
17030: @{$newsetting{$type}} =
17031: &Apache::loncommon::get_env_multiple('form.'.$type);
17032: foreach my $item (@contacts) {
17033: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
17034: $contacts_hash{contacts}{$type}{$item} = 1;
17035: } else {
17036: $contacts_hash{contacts}{$type}{$item} = 0;
17037: }
1.289 raeburn 17038: }
1.28 raeburn 17039: $others{$type} = $env{'form.'.$type.'_others'};
17040: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 17041: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17042: $bcc{$type} = $env{'form.'.$type.'_bcc'};
17043: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 17044: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
17045: $includestr{$type} = $env{'form.'.$type.'_includestr'};
17046: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
17047: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17048: }
1.134 raeburn 17049: }
1.28 raeburn 17050: }
17051: foreach my $item (@contacts) {
17052: $to{$item} = $env{'form.'.$item};
17053: $contacts_hash{'contacts'}{$item} = $to{$item};
17054: }
1.203 raeburn 17055: foreach my $item (@toggles) {
17056: if ($env{'form.'.$item} =~ /^(0|1)$/) {
17057: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
17058: }
17059: }
1.340 raeburn 17060: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
17061: foreach my $item (@lonstatus) {
17062: if ($item eq 'excluded') {
17063: my (%serverhomes,@excluded);
17064: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
17065: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
17066: if (@possexcluded) {
17067: foreach my $id (sort(@possexcluded)) {
17068: if ($serverhomes{$id}) {
17069: push(@excluded,$id);
17070: }
17071: }
17072: }
17073: if (@excluded) {
17074: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
17075: }
17076: } elsif ($item eq 'weights') {
1.377 raeburn 17077: foreach my $type ('E','W','N','U') {
1.340 raeburn 17078: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
17079: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
17080: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
17081: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
17082: $env{'form.error'.$item.'_'.$type};
17083: }
17084: }
17085: }
17086: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
17087: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
17088: if ($env{'form.error'.$item} =~ /^\d+$/) {
17089: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
17090: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
17091: }
17092: }
17093: }
17094: }
1.286 raeburn 17095: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
17096: foreach my $field (@{$fields}) {
17097: if (ref($possoptions->{$field}) eq 'ARRAY') {
17098: my $value = $env{'form.helpform_'.$field};
17099: $value =~ s/^\s+|\s+$//g;
17100: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 17101: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 17102: if ($field eq 'screenshot') {
17103: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
17104: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 17105: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 17106: }
17107: }
17108: }
17109: }
17110: }
17111: }
1.315 raeburn 17112: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17113: my (@statuses,%usertypeshash,@overrides);
17114: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
17115: @statuses = @{$types};
17116: if (ref($usertypes) eq 'HASH') {
17117: %usertypeshash = %{$usertypes};
17118: }
17119: }
17120: if (@statuses) {
17121: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
17122: foreach my $type (@possoverrides) {
17123: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
17124: push(@overrides,$type);
17125: }
17126: }
17127: if (@overrides) {
17128: foreach my $type (@overrides) {
17129: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
17130: foreach my $item (@contacts) {
17131: if (grep(/^\Q$item\E$/,@standard)) {
17132: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
17133: $newsetting{'override_'.$type}{$item} = 1;
17134: } else {
17135: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
17136: $newsetting{'override_'.$type}{$item} = 0;
17137: }
17138: }
17139: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
17140: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17141: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
17142: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17143: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
17144: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
17145: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
17146: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17147: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
17148: }
1.425 raeburn 17149: }
1.315 raeburn 17150: }
17151: }
1.28 raeburn 17152: if (keys(%currsetting) > 0) {
17153: foreach my $item (@contacts) {
17154: if ($to{$item} ne $currsetting{$item}) {
17155: $changes{$item} = 1;
17156: }
17157: }
17158: foreach my $type (@mailings) {
17159: foreach my $item (@contacts) {
17160: if (ref($currsetting{$type}) eq 'HASH') {
17161: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
17162: push(@{$changes{$type}},$item);
17163: }
17164: } else {
17165: push(@{$changes{$type}},@{$newsetting{$type}});
17166: }
17167: }
17168: if ($others{$type} ne $currsetting{$type}{'others'}) {
17169: push(@{$changes{$type}},'others');
17170: }
1.289 raeburn 17171: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17172: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
17173: push(@{$changes{$type}},'bcc');
17174: }
1.286 raeburn 17175: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
17176: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
17177: push(@{$changes{$type}},'include');
17178: }
17179: }
17180: }
17181: if (ref($fields) eq 'ARRAY') {
17182: if (ref($currsetting{'helpform'}) eq 'HASH') {
17183: foreach my $field (@{$fields}) {
17184: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
17185: push(@{$changes{'helpform'}},$field);
17186: }
17187: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17188: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
17189: push(@{$changes{'helpform'}},'maxsize');
17190: }
17191: }
17192: }
17193: } else {
17194: foreach my $field (@{$fields}) {
17195: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17196: push(@{$changes{'helpform'}},$field);
17197: }
17198: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17199: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17200: push(@{$changes{'helpform'}},'maxsize');
17201: }
17202: }
17203: }
1.134 raeburn 17204: }
1.28 raeburn 17205: }
1.315 raeburn 17206: if (@statuses) {
1.425 raeburn 17207: if (ref($currsetting{'overrides'}) eq 'HASH') {
1.315 raeburn 17208: foreach my $key (keys(%{$currsetting{'overrides'}})) {
17209: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
17210: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
17211: foreach my $item (@contacts,'bcc','others','include') {
1.425 raeburn 17212: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
1.315 raeburn 17213: push(@{$changes{'overrides'}},$key);
17214: last;
17215: }
17216: }
17217: } else {
17218: push(@{$changes{'overrides'}},$key);
17219: }
17220: }
17221: }
17222: foreach my $key (@overrides) {
17223: unless (exists($currsetting{'overrides'}{$key})) {
17224: push(@{$changes{'overrides'}},$key);
17225: }
17226: }
17227: } else {
17228: foreach my $key (@overrides) {
1.425 raeburn 17229: push(@{$changes{'overrides'}},$key);
1.315 raeburn 17230: }
17231: }
17232: }
1.340 raeburn 17233: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
17234: foreach my $key ('excluded','weights','threshold','sysmail') {
17235: if ($key eq 'excluded') {
17236: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17237: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
17238: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17239: (@{$currsetting{'lonstatus'}{$key}})) {
17240: my @diffs =
17241: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
17242: $currsetting{'lonstatus'}{$key});
17243: if (@diffs) {
17244: push(@{$changes{'lonstatus'}},$key);
17245: }
17246: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
17247: push(@{$changes{'lonstatus'}},$key);
17248: }
17249: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17250: (@{$currsetting{'lonstatus'}{$key}})) {
17251: push(@{$changes{'lonstatus'}},$key);
17252: }
17253: } elsif ($key eq 'weights') {
17254: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17255: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
17256: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17257: foreach my $type ('E','W','N','U') {
1.340 raeburn 17258: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
17259: $currsetting{'lonstatus'}{$key}{$type}) {
17260: push(@{$changes{'lonstatus'}},$key);
17261: last;
17262: }
17263: }
17264: } else {
1.341 raeburn 17265: foreach my $type ('E','W','N','U') {
1.340 raeburn 17266: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
17267: push(@{$changes{'lonstatus'}},$key);
17268: last;
17269: }
17270: }
17271: }
17272: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17273: foreach my $type ('E','W','N','U') {
1.340 raeburn 17274: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
17275: push(@{$changes{'lonstatus'}},$key);
17276: last;
17277: }
17278: }
17279: }
17280: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
17281: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17282: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17283: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
17284: push(@{$changes{'lonstatus'}},$key);
17285: }
17286: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
17287: push(@{$changes{'lonstatus'}},$key);
17288: }
17289: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17290: push(@{$changes{'lonstatus'}},$key);
17291: }
17292: }
17293: }
17294: } else {
17295: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17296: foreach my $key ('excluded','weights','threshold','sysmail') {
17297: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17298: push(@{$changes{'lonstatus'}},$key);
17299: }
17300: }
17301: }
17302: }
1.28 raeburn 17303: } else {
17304: my %default;
17305: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
17306: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
17307: $default{'errormail'} = 'adminemail';
17308: $default{'packagesmail'} = 'adminemail';
17309: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 17310: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 17311: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 17312: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 17313: $default{'updatesmail'} = 'adminemail';
1.350 raeburn 17314: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 17315: foreach my $item (@contacts) {
17316: if ($to{$item} ne $default{$item}) {
1.286 raeburn 17317: $changes{$item} = 1;
1.203 raeburn 17318: }
1.28 raeburn 17319: }
17320: foreach my $type (@mailings) {
17321: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
17322: push(@{$changes{$type}},@{$newsetting{$type}});
17323: }
17324: if ($others{$type} ne '') {
17325: push(@{$changes{$type}},'others');
1.134 raeburn 17326: }
1.286 raeburn 17327: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17328: if ($bcc{$type} ne '') {
17329: push(@{$changes{$type}},'bcc');
17330: }
1.286 raeburn 17331: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
17332: push(@{$changes{$type}},'include');
17333: }
1.134 raeburn 17334: }
1.28 raeburn 17335: }
1.286 raeburn 17336: if (ref($fields) eq 'ARRAY') {
17337: foreach my $field (@{$fields}) {
17338: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17339: push(@{$changes{'helpform'}},$field);
17340: }
17341: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17342: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17343: push(@{$changes{'helpform'}},'maxsize');
17344: }
17345: }
17346: }
1.289 raeburn 17347: }
1.340 raeburn 17348: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17349: foreach my $key ('excluded','weights','threshold','sysmail') {
17350: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17351: push(@{$changes{'lonstatus'}},$key);
17352: }
17353: }
17354: }
1.28 raeburn 17355: }
1.203 raeburn 17356: foreach my $item (@toggles) {
17357: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
17358: $changes{$item} = 1;
17359: } elsif ((!$env{'form.'.$item}) &&
17360: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
17361: $changes{$item} = 1;
17362: }
17363: }
1.28 raeburn 17364: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
17365: $dom);
17366: if ($putresult eq 'ok') {
17367: if (keys(%changes) > 0) {
1.205 raeburn 17368: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 17369: if (ref($lastactref) eq 'HASH') {
17370: $lastactref->{'domainconfig'} = 1;
17371: }
1.28 raeburn 17372: my ($titles,$short_titles) = &contact_titles();
17373: $resulttext = &mt('Changes made:').'<ul>';
17374: foreach my $item (@contacts) {
17375: if ($changes{$item}) {
17376: $resulttext .= '<li>'.$titles->{$item}.
17377: &mt(' set to: ').
17378: '<span class="LC_cusr_emph">'.
17379: $to{$item}.'</span></li>';
17380: }
17381: }
17382: foreach my $type (@mailings) {
17383: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 17384: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 17385: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 17386: } else {
17387: $resulttext .= '<li>'.$titles->{$type}.': ';
17388: }
1.28 raeburn 17389: my @text;
17390: foreach my $item (@{$newsetting{$type}}) {
17391: push(@text,$short_titles->{$item});
17392: }
17393: if ($others{$type} ne '') {
17394: push(@text,$others{$type});
17395: }
1.286 raeburn 17396: if (@text) {
17397: $resulttext .= '<span class="LC_cusr_emph">'.
17398: join(', ',@text).'</span>';
17399: }
17400: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17401: if ($bcc{$type} ne '') {
1.286 raeburn 17402: my $bcctext;
17403: if (@text) {
1.289 raeburn 17404: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 17405: } else {
17406: $bcctext = '(Bcc)';
17407: }
17408: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
17409: } elsif (!@text) {
17410: $resulttext .= &mt('No one');
1.425 raeburn 17411: }
1.289 raeburn 17412: if ($includestr{$type} ne '') {
1.286 raeburn 17413: if ($includeloc{$type} eq 'b') {
17414: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
17415: } elsif ($includeloc{$type} eq 's') {
17416: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
17417: }
1.134 raeburn 17418: }
1.286 raeburn 17419: } elsif (!@text) {
17420: $resulttext .= &mt('No recipients');
1.134 raeburn 17421: }
17422: $resulttext .= '</li>';
1.28 raeburn 17423: }
17424: }
1.315 raeburn 17425: if (ref($changes{'overrides'}) eq 'ARRAY') {
17426: my @deletions;
17427: foreach my $type (@{$changes{'overrides'}}) {
17428: if ($usertypeshash{$type}) {
17429: if (grep(/^\Q$type\E/,@overrides)) {
17430: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
17431: $usertypeshash{$type}).'<ul><li>';
17432: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
17433: my @text;
17434: foreach my $item (@contacts) {
1.425 raeburn 17435: if ($newsetting{'override_'.$type}{$item}) {
1.315 raeburn 17436: push(@text,$short_titles->{$item});
17437: }
17438: }
17439: if ($newsetting{'override_'.$type}{'others'} ne '') {
17440: push(@text,$newsetting{'override_'.$type}{'others'});
17441: }
1.425 raeburn 17442:
1.315 raeburn 17443: if (@text) {
17444: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
17445: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
17446: }
17447: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
17448: my $bcctext;
17449: if (@text) {
17450: $bcctext = ' '.&mt('with Bcc to');
17451: } else {
17452: $bcctext = '(Bcc)';
17453: }
17454: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
17455: } elsif (!@text) {
17456: $resulttext .= &mt('Helpdesk e-mail sent to no one');
17457: }
17458: $resulttext .= '</li>';
17459: if ($newsetting{'override_'.$type}{'include'} ne '') {
17460: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
17461: if ($loc eq 'b') {
17462: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
17463: } elsif ($loc eq 's') {
17464: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
17465: }
17466: }
17467: }
17468: $resulttext .= '</li></ul></li>';
17469: } else {
17470: push(@deletions,$usertypeshash{$type});
17471: }
17472: }
17473: }
17474: if (@deletions) {
17475: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
17476: join(', ',@deletions)).'</li>';
17477: }
17478: }
1.203 raeburn 17479: my @offon = ('off','on');
1.340 raeburn 17480: my $corelink = &core_link_msu();
1.203 raeburn 17481: if ($changes{'reporterrors'}) {
17482: $resulttext .= '<li>'.
17483: &mt('E-mail error reports to [_1] set to "'.
17484: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 17485: $corelink).
1.203 raeburn 17486: '</li>';
17487: }
17488: if ($changes{'reportupdates'}) {
17489: $resulttext .= '<li>'.
17490: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
17491: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 17492: $corelink).
1.203 raeburn 17493: '</li>';
17494: }
1.340 raeburn 17495: if ($changes{'reportstatus'}) {
17496: $resulttext .= '<li>'.
17497: &mt('E-mail status if errors above threshold to [_1] set to "'.
17498: $offon[$env{'form.reportstatus'}].'".',
17499: $corelink).
17500: '</li>';
17501: }
17502: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
17503: $resulttext .= '<li>'.
17504: &mt('Nightly status check e-mail settings').':<ul>';
17505: my (%defval,%use_def,%shown);
17506: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
17507: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
17508: $defval{'weights'} =
1.341 raeburn 17509: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 17510: $defval{'excluded'} = &mt('None');
17511: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
17512: foreach my $item ('threshold','sysmail','weights','excluded') {
17513: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
17514: if (($item eq 'threshold') || ($item eq 'sysmail')) {
17515: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
17516: } elsif ($item eq 'weights') {
17517: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 17518: foreach my $type ('E','W','N','U') {
1.340 raeburn 17519: $shown{$item} .= $lonstatus_names->{$type}.'=';
17520: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
17521: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
17522: } else {
17523: $shown{$item} .= $lonstatus_defs->{$type};
17524: }
17525: $shown{$item} .= ', ';
17526: }
17527: $shown{$item} =~ s/, $//;
17528: } else {
17529: $shown{$item} = $defval{$item};
17530: }
17531: } elsif ($item eq 'excluded') {
17532: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
17533: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
17534: } else {
17535: $shown{$item} = $defval{$item};
17536: }
17537: }
17538: } else {
17539: $shown{$item} = $defval{$item};
17540: }
17541: }
17542: } else {
17543: foreach my $item ('threshold','weights','excluded','sysmail') {
17544: $shown{$item} = $defval{$item};
17545: }
17546: }
17547: foreach my $item ('threshold','weights','excluded','sysmail') {
17548: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
17549: $shown{$item}).'</li>';
17550: }
17551: $resulttext .= '</ul></li>';
17552: }
1.286 raeburn 17553: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
17554: my (@optional,@required,@unused,$maxsizechg);
17555: foreach my $field (@{$changes{'helpform'}}) {
17556: if ($field eq 'maxsize') {
17557: $maxsizechg = 1;
17558: next;
17559: }
17560: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 17561: push(@optional,$field);
1.286 raeburn 17562: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
17563: push(@unused,$field);
17564: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 17565: push(@required,$field);
1.286 raeburn 17566: }
17567: }
17568: if (@optional) {
17569: $resulttext .= '<li>'.
17570: &mt('Help form fields changed to "Optional": [_1].',
17571: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
17572: '</li>';
17573: }
17574: if (@required) {
17575: $resulttext .= '<li>'.
17576: &mt('Help form fields changed to "Required": [_1].',
17577: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
17578: '</li>';
17579: }
17580: if (@unused) {
17581: $resulttext .= '<li>'.
17582: &mt('Help form fields changed to "Not shown": [_1].',
17583: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
17584: '</li>';
17585: }
17586: if ($maxsizechg) {
17587: $resulttext .= '<li>'.
17588: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
17589: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
17590: '</li>';
17591: }
17592: }
1.28 raeburn 17593: $resulttext .= '</ul>';
17594: } else {
1.288 raeburn 17595: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 17596: }
17597: } else {
17598: $resulttext = '<span class="LC_error">'.
17599: &mt('An error occurred: [_1].',$putresult).'</span>';
17600: }
17601: return $resulttext;
17602: }
17603:
1.357 raeburn 17604: sub modify_privacy {
1.427 raeburn 17605: my ($dom,$lastactref,%domconfig) = @_;
1.357 raeburn 17606: my ($resulttext,%current,%changes);
17607: if (ref($domconfig{'privacy'}) eq 'HASH') {
17608: %current = %{$domconfig{'privacy'}};
17609: }
17610: my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
17611: my @items = ('domain','author','course','community');
17612: my %names = &Apache::lonlocal::texthash (
17613: domain => 'Assigned domain role(s)',
17614: author => 'Assigned co-author role(s)',
17615: course => 'Assigned course role(s)',
1.416 raeburn 17616: community => 'Assigned community role(s)',
1.357 raeburn 17617: );
17618: my %roles = &Apache::lonlocal::texthash (
17619: domain => 'Domain role',
17620: author => 'Co-author role',
17621: course => 'Course role',
17622: community => 'Community role',
17623: );
17624: my %titles = &Apache::lonlocal::texthash (
17625: approval => 'Approval for role in different domain',
17626: othdom => 'User information available in other domain',
17627: priv => 'Information viewable by privileged user in same domain',
17628: unpriv => 'Information viewable by unprivileged user in same domain',
17629: instdom => 'Other domain shares institution/provider',
17630: extdom => 'Other domain has different institution/provider',
17631: none => 'Not allowed',
17632: user => 'User authorizes',
17633: domain => 'Domain Coordinator authorizes',
17634: auto => 'Unrestricted',
1.418 raeburn 17635: notify => 'Notify when role needs authorization',
1.357 raeburn 17636: );
17637: my %fieldnames = &Apache::lonlocal::texthash (
17638: id => 'Student/Employee ID',
17639: permanentemail => 'E-mail address',
17640: lastname => 'Last Name',
17641: firstname => 'First Name',
17642: middlename => 'Middle Name',
17643: generation => 'Generation',
17644: );
17645: my ($othertitle,$usertypes,$types) =
17646: &Apache::loncommon::sorted_inst_types($dom);
17647: my (%by_ip,%by_location,@intdoms,@instdoms);
17648: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
17649:
17650: my %privacyhash = (
17651: 'approval' => {
17652: instdom => {},
17653: extdom => {},
17654: },
17655: 'othdom' => {},
17656: 'priv' => {},
17657: 'unpriv' => {},
17658: );
17659: foreach my $item (@items) {
17660: if (@instdoms > 1) {
1.416 raeburn 17661: if ($env{'form.privacy_approval_instdom_'.$item} =~ /^(none|user|domain|auto)$/) {
1.357 raeburn 17662: $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
17663: }
17664: if (ref($current{'approval'}) eq 'HASH') {
17665: if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
17666: unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
17667: $changes{'approval'} = 1;
17668: }
17669: }
17670: } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
17671: $changes{'approval'} = 1;
17672: }
17673: }
17674: if (keys(%by_location) > 0) {
17675: if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
17676: $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
17677: }
17678: if (ref($current{'approval'}) eq 'HASH') {
17679: if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
17680: unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
17681: $changes{'approval'} = 1;
17682: }
17683: }
17684: } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
17685: $changes{'approval'} = 1;
17686: }
17687: }
17688: foreach my $status ('priv','unpriv') {
17689: my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
17690: my @newvalues;
17691: foreach my $field (@possibles) {
17692: if (grep(/^\Q$field\E$/,@fields)) {
17693: $privacyhash{$status}{$item}{$field} = 1;
17694: push(@newvalues,$field);
17695: }
17696: }
17697: @newvalues = sort(@newvalues);
17698: if (ref($current{$status}) eq 'HASH') {
17699: if (ref($current{$status}{$item}) eq 'HASH') {
17700: my @currvalues = sort(keys(%{$current{$status}{$item}}));
17701: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
17702: if (@diffs > 0) {
17703: $changes{$status} = 1;
17704: }
17705: }
17706: } else {
17707: my @stdfields;
17708: foreach my $field (@fields) {
17709: if ($field eq 'id') {
17710: next if ($status eq 'unpriv');
17711: next if (($status eq 'priv') && ($item eq 'community'));
17712: }
17713: push(@stdfields,$field);
17714: }
17715: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
17716: if (@diffs > 0) {
17717: $changes{$status} = 1;
17718: }
17719: }
17720: }
17721: }
17722: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
17723: my @statuses;
17724: if (ref($types) eq 'ARRAY') {
17725: @statuses = @{$types};
17726: }
17727: foreach my $type (@statuses,'default') {
17728: my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
17729: my @newvalues;
17730: foreach my $field (sort(@possfields)) {
17731: if (grep(/^\Q$field\E$/,@fields)) {
17732: $privacyhash{'othdom'}{$type}{$field} = 1;
17733: push(@newvalues,$field);
17734: }
17735: }
17736: @newvalues = sort(@newvalues);
17737: if (ref($current{'othdom'}) eq 'HASH') {
17738: if (ref($current{'othdom'}{$type}) eq 'HASH') {
17739: my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
17740: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
17741: if (@diffs > 0) {
17742: $changes{'othdom'} = 1;
17743: }
17744: }
17745: } else {
17746: my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
17747: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
17748: if (@diffs > 0) {
17749: $changes{'othdom'} = 1;
17750: }
17751: }
17752: }
1.417 raeburn 17753: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
17754: my %notify;
17755: foreach my $possdc (&Apache::loncommon::get_env_multiple('form.privacy_notify')) {
17756: if (exists($domcoords{$possdc})) {
17757: $notify{$possdc} = 1;
17758: }
17759: }
17760: my $notify = join(',',sort(keys(%notify)));
17761: if ($current{'notify'} ne $notify) {
17762: $changes{'notify'} = 1;
17763: }
17764: $privacyhash{'notify'} = $notify;
1.357 raeburn 17765: }
17766: my %confighash = (
17767: privacy => \%privacyhash,
17768: );
17769: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
17770: if ($putresult eq 'ok') {
17771: if (keys(%changes) > 0) {
17772: $resulttext = &mt('Changes made: ').'<ul>';
1.417 raeburn 17773: foreach my $key ('approval','notify','othdom','priv','unpriv') {
1.357 raeburn 17774: if ($changes{$key}) {
17775: $resulttext .= '<li>'.$titles{$key}.':<ul>';
17776: if ($key eq 'approval') {
17777: if (keys(%{$privacyhash{$key}{instdom}})) {
17778: $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
17779: foreach my $item (@items) {
17780: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
17781: }
17782: $resulttext .= '</ul></li>';
17783: }
17784: if (keys(%{$privacyhash{$key}{extdom}})) {
17785: $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
17786: foreach my $item (@items) {
17787: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
17788: }
17789: $resulttext .= '</ul></li>';
17790: }
1.417 raeburn 17791: } elsif ($key eq 'notify') {
17792: if ($privacyhash{$key}) {
17793: foreach my $dc (split(/,/,$privacyhash{$key})) {
17794: my ($dcname,$dcdom) = split(/:/,$dc);
17795: $resulttext .= '<li>'.&Apache::loncommon::plainname($dcname,$dcdom).'</li>';
17796: }
17797: } else {
17798: $resulttext .= '<li>'.&mt('No DCs to notify').'</li>';
17799: }
1.357 raeburn 17800: } elsif ($key eq 'othdom') {
17801: my @statuses;
17802: if (ref($types) eq 'ARRAY') {
17803: @statuses = @{$types};
17804: }
17805: if (ref($privacyhash{$key}) eq 'HASH') {
17806: foreach my $status (@statuses,'default') {
17807: if ($status eq 'default') {
17808: $resulttext .= '<li>'.$othertitle.': ';
17809: } elsif (ref($usertypes) eq 'HASH') {
17810: $resulttext .= '<li>'.$usertypes->{$status}.': ';
17811: } else {
17812: next;
17813: }
17814: if (ref($privacyhash{$key}{$status}) eq 'HASH') {
17815: if (keys(%{$privacyhash{$key}{$status}})) {
17816: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
17817: } else {
17818: $resulttext .= &mt('none');
17819: }
17820: }
17821: $resulttext .= '</li>';
17822: }
17823: }
17824: } else {
17825: foreach my $item (@items) {
17826: if (ref($privacyhash{$key}{$item}) eq 'HASH') {
17827: $resulttext .= '<li>'.$names{$item}.': ';
17828: if (keys(%{$privacyhash{$key}{$item}})) {
17829: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
17830: } else {
17831: $resulttext .= &mt('none');
17832: }
17833: $resulttext .= '</li>';
17834: }
17835: }
17836: }
17837: $resulttext .= '</ul></li>';
17838: }
17839: }
1.421 raeburn 17840: $resulttext .= '</ul>';
1.427 raeburn 17841: if ($changes{'approval'}) {
17842: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
17843: delete($domdefaults{'userapprovals'});
17844: if (ref($privacyhash{'approval'}) eq 'HASH') {
17845: foreach my $domtype ('instdom','extdom') {
17846: if (ref($privacyhash{'approval'}{$domtype}) eq 'HASH') {
17847: foreach my $roletype ('domain','author','course','community') {
17848: if ($privacyhash{'approval'}{$domtype}{$roletype} eq 'user') {
17849: $domdefaults{'userapprovals'} = 1;
17850: last;
17851: }
17852: }
17853: }
17854: last if ($domdefaults{'userapprovals'});
17855: }
17856: }
17857: my $cachetime = 24*60*60;
17858: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17859: if (ref($lastactref) eq 'HASH') {
17860: $lastactref->{'domdefaults'} = 1;
17861: }
17862: }
1.357 raeburn 17863: } else {
17864: $resulttext = &mt('No changes made to user information settings');
17865: }
17866: } else {
17867: $resulttext = '<span class="LC_error">'.
17868: &mt('An error occurred: [_1]',$putresult).'</span>';
17869: }
17870: return $resulttext;
17871: }
17872:
1.354 raeburn 17873: sub modify_passwords {
17874: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 raeburn 17875: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
17876: $updatedefaults,$updateconf);
1.354 raeburn 17877: my $customfn = 'resetpw.html';
17878: if (ref($domconfig{'passwords'}) eq 'HASH') {
17879: %current = %{$domconfig{'passwords'}};
17880: }
17881: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
17882: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17883: if (ref($types) eq 'ARRAY') {
17884: @oktypes = @{$types};
17885: }
17886: push(@oktypes,'default');
17887:
17888: my %titles = &Apache::lonlocal::texthash (
17889: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
17890: intauth_check => 'Check bcrypt cost if authenticated',
17891: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
17892: permanent => 'Permanent e-mail address',
17893: critical => 'Critical notification address',
17894: notify => 'Notification address',
17895: min => 'Minimum password length',
17896: max => 'Maximum password length',
17897: chars => 'Required characters',
17898: expire => 'Password expiration (days)',
1.356 raeburn 17899: numsaved => 'Number of previous passwords to save',
1.354 raeburn 17900: reset => 'Resetting Forgotten Password',
17901: intauth => 'Encryption of Stored Passwords (Internal Auth)',
17902: rules => 'Rules for LON-CAPA Passwords',
17903: crsownerchg => 'Course Owner Changing Student Passwords',
17904: username => 'Username',
17905: email => 'E-mail address',
17906: );
17907:
17908: #
17909: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
17910: #
17911: my (%curr_defaults,%save_defaults);
17912: if (ref($domconfig{'defaults'}) eq 'HASH') {
17913: foreach my $key (keys(%{$domconfig{'defaults'}})) {
17914: if ($key =~ /^intauth_(cost|check|switch)$/) {
17915: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
17916: } else {
17917: $save_defaults{$key} = $domconfig{'defaults'}{$key};
17918: }
17919: }
17920: }
17921: my %staticdefaults = (
17922: 'resetlink' => 2,
17923: 'resetcase' => \@oktypes,
17924: 'resetprelink' => 'both',
17925: 'resetemail' => ['critical','notify','permanent'],
17926: 'intauth_cost' => 10,
17927: 'intauth_check' => 0,
17928: 'intauth_switch' => 0,
17929: );
1.365 raeburn 17930: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354 raeburn 17931: foreach my $type (@oktypes) {
17932: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
17933: }
17934: my $linklife = $env{'form.passwords_link'};
17935: $linklife =~ s/^\s+|\s+$//g;
17936: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
17937: $newvalues{'resetlink'} = $linklife;
17938: if ($current{'resetlink'}) {
17939: if ($current{'resetlink'} ne $linklife) {
17940: $changes{'reset'} = 1;
17941: }
1.368 raeburn 17942: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 17943: if ($staticdefaults{'resetlink'} ne $linklife) {
17944: $changes{'reset'} = 1;
17945: }
17946: }
17947: } elsif ($current{'resetlink'}) {
17948: $changes{'reset'} = 1;
17949: }
17950: my @casesens;
17951: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
17952: foreach my $case (sort(@posscase)) {
17953: if (grep(/^\Q$case\E$/,@oktypes)) {
17954: push(@casesens,$case);
17955: }
17956: }
17957: $newvalues{'resetcase'} = \@casesens;
17958: if (ref($current{'resetcase'}) eq 'ARRAY') {
17959: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
17960: if (@diffs > 0) {
17961: $changes{'reset'} = 1;
17962: }
1.368 raeburn 17963: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 17964: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
17965: if (@diffs > 0) {
17966: $changes{'reset'} = 1;
17967: }
17968: }
17969: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
17970: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
17971: if (exists($current{'resetprelink'})) {
17972: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
17973: $changes{'reset'} = 1;
17974: }
1.368 raeburn 17975: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 17976: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
17977: $changes{'reset'} = 1;
17978: }
17979: }
17980: } elsif ($current{'resetprelink'}) {
17981: $changes{'reset'} = 1;
17982: }
17983: foreach my $type (@oktypes) {
17984: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
17985: my @postlink;
17986: foreach my $item (sort(@possplink)) {
17987: if ($item =~ /^(email|username)$/) {
17988: push(@postlink,$item);
17989: }
17990: }
17991: $newvalues{'resetpostlink'}{$type} = \@postlink;
17992: unless ($changes{'reset'}) {
17993: if (ref($current{'resetpostlink'}) eq 'HASH') {
17994: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
17995: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
17996: if (@diffs > 0) {
17997: $changes{'reset'} = 1;
17998: }
17999: } else {
18000: $changes{'reset'} = 1;
18001: }
1.368 raeburn 18002: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18003: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
18004: if (@diffs > 0) {
18005: $changes{'reset'} = 1;
18006: }
18007: }
18008: }
18009: }
18010: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
18011: my @resetemail;
18012: foreach my $item (sort(@possemailsrc)) {
18013: if ($item =~ /^(permanent|critical|notify)$/) {
18014: push(@resetemail,$item);
18015: }
18016: }
18017: $newvalues{'resetemail'} = \@resetemail;
18018: unless ($changes{'reset'}) {
18019: if (ref($current{'resetemail'}) eq 'ARRAY') {
18020: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
18021: if (@diffs > 0) {
18022: $changes{'reset'} = 1;
18023: }
1.368 raeburn 18024: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18025: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
18026: if (@diffs > 0) {
18027: $changes{'reset'} = 1;
18028: }
18029: }
18030: }
18031: if ($env{'form.passwords_stdtext'} == 0) {
18032: $newvalues{'resetremove'} = 1;
18033: unless ($current{'resetremove'}) {
18034: $changes{'reset'} = 1;
18035: }
18036: } elsif ($current{'resetremove'}) {
18037: $changes{'reset'} = 1;
18038: }
18039: if ($env{'form.passwords_customfile.filename'} ne '') {
18040: my $servadm = $r->dir_config('lonAdmEMail');
18041: my ($configuserok,$author_ok,$switchserver) =
18042: &config_check($dom,$confname,$servadm);
18043: my $error;
18044: if ($configuserok eq 'ok') {
18045: if ($switchserver) {
18046: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
18047: } else {
18048: if ($author_ok eq 'ok') {
1.421 raeburn 18049: my $modified = [];
1.354 raeburn 18050: my ($result,$customurl) =
1.421 raeburn 18051: &Apache::lonconfigsettings::publishlogo($r,'upload','passwords_customfile',$dom,
18052: $confname,'customtext/resetpw','','',$customfn,
18053: $modified);
1.354 raeburn 18054: if ($result eq 'ok') {
18055: $newvalues{'resetcustom'} = $customurl;
18056: $changes{'reset'} = 1;
1.421 raeburn 18057: &update_modify_urls($r,$modified);
1.354 raeburn 18058: } else {
18059: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
18060: }
18061: } else {
18062: $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);
18063: }
18064: }
18065: } else {
18066: $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);
18067: }
18068: if ($error) {
18069: &Apache::lonnet::logthis($error);
18070: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
18071: }
18072: } elsif ($current{'resetcustom'}) {
18073: if ($env{'form.passwords_custom_del'}) {
18074: $changes{'reset'} = 1;
18075: } else {
18076: $newvalues{'resetcustom'} = $current{'resetcustom'};
18077: }
18078: }
18079: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
18080: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
18081: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
18082: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
18083: $changes{'intauth'} = 1;
18084: }
18085: } else {
18086: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
18087: }
18088: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
18089: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
18090: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
18091: $changes{'intauth'} = 1;
18092: }
18093: } else {
18094: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18095: }
18096: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
18097: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
18098: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
18099: $changes{'intauth'} = 1;
18100: }
18101: } else {
18102: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18103: }
18104: foreach my $item ('cost','check','switch') {
18105: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
18106: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
18107: $updatedefaults = 1;
18108: }
18109: }
1.405 raeburn 18110: &password_rule_changes('passwords',\%newvalues,\%current,\%changes);
1.359 raeburn 18111: my %crsownerchg = (
18112: by => [],
18113: for => [],
18114: );
18115: foreach my $item ('by','for') {
18116: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
18117: foreach my $type (sort(@posstypes)) {
18118: if (grep(/^\Q$type\E$/,@oktypes)) {
18119: push(@{$crsownerchg{$item}},$type);
18120: }
18121: }
18122: }
18123: $newvalues{'crsownerchg'} = \%crsownerchg;
18124: if (ref($current{'crsownerchg'}) eq 'HASH') {
18125: foreach my $item ('by','for') {
18126: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
18127: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
18128: if (@diffs > 0) {
18129: $changes{'crsownerchg'} = 1;
18130: last;
18131: }
18132: }
18133: }
1.368 raeburn 18134: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359 raeburn 18135: foreach my $item ('by','for') {
18136: if (@{$crsownerchg{$item}} > 0) {
18137: $changes{'crsownerchg'} = 1;
18138: last;
18139: }
1.354 raeburn 18140: }
18141: }
18142:
18143: my %confighash = (
18144: defaults => \%save_defaults,
18145: passwords => \%newvalues,
18146: );
18147: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
18148:
18149: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
18150: if ($putresult eq 'ok') {
18151: if (keys(%changes) > 0) {
18152: $resulttext = &mt('Changes made: ').'<ul>';
18153: foreach my $key ('reset','intauth','rules','crsownerchg') {
18154: if ($changes{$key}) {
1.355 raeburn 18155: unless ($key eq 'intauth') {
18156: $updateconf = 1;
18157: }
1.354 raeburn 18158: $resulttext .= '<li>'.$titles{$key}.':<ul>';
18159: if ($key eq 'reset') {
18160: if ($confighash{'passwords'}{'captcha'} eq 'original') {
18161: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
18162: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
18163: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369 raeburn 18164: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
18165: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
18166: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
18167: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
18168: }
1.354 raeburn 18169: } else {
18170: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
18171: }
18172: if ($confighash{'passwords'}{'resetlink'}) {
18173: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
18174: } else {
18175: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
18176: &mt('Will default to 2 hours').'</li>';
18177: }
18178: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
18179: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
18180: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
18181: } else {
18182: my $casesens;
18183: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
18184: if ($type eq 'default') {
18185: $casesens .= $othertitle.', ';
18186: } elsif ($usertypes->{$type} ne '') {
18187: $casesens .= $usertypes->{$type}.', ';
18188: }
18189: }
18190: $casesens =~ s/\Q, \E$//;
18191: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
18192: }
18193: } else {
18194: $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>';
18195: }
18196: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
18197: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
18198: } else {
18199: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
18200: }
18201: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
18202: my $output;
18203: if (ref($types) eq 'ARRAY') {
18204: foreach my $type (@{$types}) {
18205: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
18206: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
18207: $output .= $usertypes->{$type}.' -- '.&mt('none');
18208: } else {
18209: $output .= $usertypes->{$type}.' -- '.
18210: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
18211: }
18212: }
18213: }
18214: }
18215: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
18216: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
18217: $output .= $othertitle.' -- '.&mt('none');
18218: } else {
18219: $output .= $othertitle.' -- '.
18220: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
18221: }
18222: }
18223: if ($output) {
18224: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
18225: } else {
18226: $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>';
18227: }
18228: } else {
18229: $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>';
18230: }
18231: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
18232: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
18233: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
18234: } else {
18235: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
18236: }
18237: } else {
1.379 raeburn 18238: $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 18239: }
18240: if ($confighash{'passwords'}{'resetremove'}) {
18241: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
18242: } else {
18243: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
18244: }
18245: if ($confighash{'passwords'}{'resetcustom'}) {
18246: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369 raeburn 18247: &mt('custom text'),600,500,undef,undef,
18248: undef,undef,'background-color:#ffffff');
18249: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354 raeburn 18250: } else {
18251: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
18252: }
18253: } elsif ($key eq 'intauth') {
18254: foreach my $item ('cost','switch','check') {
18255: my $value = $save_defaults{$key.'_'.$item};
18256: if ($item eq 'switch') {
18257: my %optiondesc = &Apache::lonlocal::texthash (
18258: 0 => 'No',
18259: 1 => 'Yes',
18260: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
18261: );
18262: if ($value =~ /^(0|1|2)$/) {
18263: $value = $optiondesc{$value};
18264: } else {
18265: $value = &mt('none -- defaults to No');
18266: }
18267: } elsif ($item eq 'check') {
18268: my %optiondesc = &Apache::lonlocal::texthash (
18269: 0 => 'No',
18270: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
18271: 2 => 'Yes, disallow login if stored cost is less than domain default',
18272: );
18273: if ($value =~ /^(0|1|2)$/) {
18274: $value = $optiondesc{$value};
18275: } else {
18276: $value = &mt('none -- defaults to No');
18277: }
18278: }
18279: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
18280: }
18281: } elsif ($key eq 'rules') {
1.356 raeburn 18282: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 18283: if ($confighash{'passwords'}{$rule} eq '') {
18284: if ($rule eq 'min') {
1.356 raeburn 18285: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365 raeburn 18286: ' '.&mt('Default of [_1] will be used',
18287: $Apache::lonnet::passwdmin).'</li>';
1.356 raeburn 18288: } else {
18289: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354 raeburn 18290: }
18291: } else {
18292: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
18293: }
18294: }
1.370 raeburn 18295: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
18296: if (@{$confighash{'passwords'}{'chars'}} > 0) {
18297: my %rulenames = &Apache::lonlocal::texthash(
18298: uc => 'At least one upper case letter',
18299: lc => 'At least one lower case letter',
18300: num => 'At least one number',
18301: spec => 'At least one non-alphanumeric',
18302: );
18303: my $needed = '<ul><li>'.
18304: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
1.425 raeburn 18305: '</li></ul>';
1.370 raeburn 18306: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
18307: } else {
18308: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18309: }
18310: } else {
18311: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18312: }
1.354 raeburn 18313: } elsif ($key eq 'crsownerchg') {
1.359 raeburn 18314: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
18315: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
18316: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
18317: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
18318: } else {
18319: my %crsownerstr;
18320: foreach my $item ('by','for') {
18321: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
18322: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
18323: if ($type eq 'default') {
18324: $crsownerstr{$item} .= $othertitle.', ';
18325: } elsif ($usertypes->{$type} ne '') {
18326: $crsownerstr{$item} .= $usertypes->{$type}.', ';
18327: }
18328: }
18329: $crsownerstr{$item} =~ s/\Q, \E$//;
18330: }
18331: }
18332: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
18333: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
18334: }
1.354 raeburn 18335: } else {
1.359 raeburn 18336: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354 raeburn 18337: }
18338: }
18339: $resulttext .= '</ul></li>';
18340: }
18341: }
18342: $resulttext .= '</ul>';
18343: } else {
18344: $resulttext = &mt('No changes made to password settings');
18345: }
1.355 raeburn 18346: my $cachetime = 24*60*60;
1.354 raeburn 18347: if ($updatedefaults) {
18348: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18349: if (ref($lastactref) eq 'HASH') {
18350: $lastactref->{'domdefaults'} = 1;
18351: }
18352: }
1.355 raeburn 18353: if ($updateconf) {
18354: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
18355: if (ref($lastactref) eq 'HASH') {
18356: $lastactref->{'passwdconf'} = 1;
18357: }
18358: }
1.354 raeburn 18359: } else {
18360: $resulttext = '<span class="LC_error">'.
18361: &mt('An error occurred: [_1]',$putresult).'</span>';
18362: }
18363: if ($errors) {
18364: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
18365: $errors.'</ul></p>';
18366: }
18367: return $resulttext;
18368: }
18369:
1.405 raeburn 18370: sub password_rule_changes {
18371: my ($prefix,$newvalues,$current,$changes) = @_;
18372: return unless ((ref($newvalues) eq 'HASH') &&
18373: (ref($current) eq 'HASH') &&
18374: (ref($changes) eq 'HASH'));
18375: my (@rules,%staticdefaults);
18376: if ($prefix eq 'passwords') {
18377: @rules = ('min','max','expire','numsaved');
1.421 raeburn 18378: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 18379: @rules = ('min','max');
18380: }
18381: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
18382: foreach my $rule (@rules) {
18383: $env{'form.'.$prefix.'_'.$rule} =~ s/^\s+|\s+$//g;
18384: my $ruleok;
18385: if ($rule eq 'expire') {
18386: if (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+(|\.\d*)$/) &&
18387: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18388: $ruleok = 1;
18389: }
18390: } elsif ($rule eq 'min') {
18391: if ($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) {
18392: if ($env{'form.'.$prefix.'_'.$rule} >= $staticdefaults{$rule}) {
18393: $ruleok = 1;
18394: }
18395: }
18396: } elsif (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) &&
18397: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18398: $ruleok = 1;
18399: }
18400: if ($ruleok) {
18401: $newvalues->{$rule} = $env{'form.'.$prefix.'_'.$rule};
18402: if (exists($current->{$rule})) {
18403: if ($newvalues->{$rule} ne $current->{$rule}) {
18404: $changes->{'rules'} = 1;
18405: }
18406: } elsif ($rule eq 'min') {
18407: if ($staticdefaults{$rule} ne $newvalues->{$rule}) {
18408: $changes->{'rules'} = 1;
18409: }
18410: } else {
18411: $changes->{'rules'} = 1;
18412: }
18413: } elsif (exists($current->{$rule})) {
18414: $changes->{'rules'} = 1;
18415: }
18416: }
18417: my @posschars = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_chars');
18418: my @chars;
18419: foreach my $item (sort(@posschars)) {
18420: if ($item =~ /^(uc|lc|num|spec)$/) {
18421: push(@chars,$item);
18422: }
18423: }
18424: $newvalues->{'chars'} = \@chars;
18425: unless ($changes->{'rules'}) {
18426: if (ref($current->{'chars'}) eq 'ARRAY') {
18427: my @diffs = &Apache::loncommon::compare_arrays($current->{'chars'},\@chars);
18428: if (@diffs > 0) {
18429: $changes->{'rules'} = 1;
18430: }
18431: } else {
18432: if (@chars > 0) {
18433: $changes->{'rules'} = 1;
18434: }
18435: }
18436: }
18437: return;
18438: }
18439:
1.28 raeburn 18440: sub modify_usercreation {
1.27 raeburn 18441: my ($dom,%domconfig) = @_;
1.224 raeburn 18442: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 18443: my $warningmsg;
1.27 raeburn 18444: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18445: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 18446: if ($key eq 'cancreate') {
18447: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18448: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 18449: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
18450: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18451: } else {
1.224 raeburn 18452: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18453: }
18454: }
18455: }
18456: } elsif ($key eq 'email_rule') {
18457: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18458: } else {
18459: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18460: }
1.27 raeburn 18461: }
18462: }
18463: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 18464: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 18465: my @contexts = ('author','course','requestcrs');
1.34 raeburn 18466: foreach my $item(@contexts) {
1.224 raeburn 18467: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 18468: }
1.34 raeburn 18469: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
18470: foreach my $item (@contexts) {
1.224 raeburn 18471: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
18472: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 18473: }
1.27 raeburn 18474: }
1.34 raeburn 18475: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
18476: foreach my $item (@contexts) {
1.43 raeburn 18477: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 18478: if ($cancreate{$item} ne 'any') {
18479: push(@{$changes{'cancreate'}},$item);
18480: }
18481: } else {
18482: if ($cancreate{$item} ne 'none') {
18483: push(@{$changes{'cancreate'}},$item);
18484: }
1.27 raeburn 18485: }
18486: }
18487: } else {
1.43 raeburn 18488: foreach my $item (@contexts) {
1.34 raeburn 18489: push(@{$changes{'cancreate'}},$item);
18490: }
1.27 raeburn 18491: }
1.34 raeburn 18492:
1.27 raeburn 18493: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
18494: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
18495: if (!grep(/^\Q$type\E$/,@username_rule)) {
18496: push(@{$changes{'username_rule'}},$type);
18497: }
18498: }
18499: foreach my $type (@username_rule) {
18500: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
18501: push(@{$changes{'username_rule'}},$type);
18502: }
18503: }
18504: } else {
18505: push(@{$changes{'username_rule'}},@username_rule);
18506: }
18507:
1.32 raeburn 18508: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
18509: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
18510: if (!grep(/^\Q$type\E$/,@id_rule)) {
18511: push(@{$changes{'id_rule'}},$type);
18512: }
18513: }
18514: foreach my $type (@id_rule) {
18515: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
18516: push(@{$changes{'id_rule'}},$type);
18517: }
18518: }
18519: } else {
18520: push(@{$changes{'id_rule'}},@id_rule);
18521: }
18522:
1.43 raeburn 18523: my @authen_contexts = ('author','course','domain');
1.325 raeburn 18524: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 18525: my %authhash;
1.43 raeburn 18526: foreach my $item (@authen_contexts) {
1.28 raeburn 18527: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
18528: foreach my $auth (@authtypes) {
18529: if (grep(/^\Q$auth\E$/,@authallowed)) {
18530: $authhash{$item}{$auth} = 1;
18531: } else {
18532: $authhash{$item}{$auth} = 0;
18533: }
18534: }
18535: }
18536: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 18537: foreach my $item (@authen_contexts) {
1.28 raeburn 18538: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
18539: foreach my $auth (@authtypes) {
18540: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
18541: push(@{$changes{'authtypes'}},$item);
18542: last;
18543: }
18544: }
18545: }
18546: }
18547: } else {
1.43 raeburn 18548: foreach my $item (@authen_contexts) {
1.28 raeburn 18549: push(@{$changes{'authtypes'}},$item);
18550: }
18551: }
18552:
1.224 raeburn 18553: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
18554: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
18555: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
18556: $save_usercreate{'id_rule'} = \@id_rule;
18557: $save_usercreate{'username_rule'} = \@username_rule,
18558: $save_usercreate{'authtypes'} = \%authhash;
18559:
1.27 raeburn 18560: my %usercreation_hash = (
1.224 raeburn 18561: usercreation => \%save_usercreate,
18562: );
1.27 raeburn 18563:
18564: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
18565: $dom);
1.50 raeburn 18566:
1.224 raeburn 18567: if ($putresult eq 'ok') {
18568: if (keys(%changes) > 0) {
18569: $resulttext = &mt('Changes made:').'<ul>';
18570: if (ref($changes{'cancreate'}) eq 'ARRAY') {
18571: my %lt = &usercreation_types();
18572: foreach my $type (@{$changes{'cancreate'}}) {
18573: my $chgtext = $lt{$type}.', ';
18574: if ($cancreate{$type} eq 'none') {
18575: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
18576: } elsif ($cancreate{$type} eq 'any') {
18577: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
18578: } elsif ($cancreate{$type} eq 'official') {
18579: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
18580: } elsif ($cancreate{$type} eq 'unofficial') {
18581: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
18582: }
18583: $resulttext .= '<li>'.$chgtext.'</li>';
18584: }
18585: }
18586: if (ref($changes{'username_rule'}) eq 'ARRAY') {
18587: my ($rules,$ruleorder) =
18588: &Apache::lonnet::inst_userrules($dom,'username');
18589: my $chgtext = '<ul>';
18590: foreach my $type (@username_rule) {
18591: if (ref($rules->{$type}) eq 'HASH') {
18592: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
18593: }
18594: }
18595: $chgtext .= '</ul>';
18596: if (@username_rule > 0) {
18597: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18598: } else {
18599: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
18600: }
18601: }
18602: if (ref($changes{'id_rule'}) eq 'ARRAY') {
18603: my ($idrules,$idruleorder) =
18604: &Apache::lonnet::inst_userrules($dom,'id');
18605: my $chgtext = '<ul>';
18606: foreach my $type (@id_rule) {
18607: if (ref($idrules->{$type}) eq 'HASH') {
18608: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
18609: }
18610: }
18611: $chgtext .= '</ul>';
18612: if (@id_rule > 0) {
18613: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18614: } else {
18615: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
18616: }
18617: }
18618: my %authname = &authtype_names();
18619: my %context_title = &context_names();
18620: if (ref($changes{'authtypes'}) eq 'ARRAY') {
18621: my $chgtext = '<ul>';
18622: foreach my $type (@{$changes{'authtypes'}}) {
18623: my @allowed;
18624: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
18625: foreach my $auth (@authtypes) {
18626: if ($authhash{$type}{$auth}) {
18627: push(@allowed,$authname{$auth});
18628: }
18629: }
18630: if (@allowed > 0) {
18631: $chgtext .= join(', ',@allowed).'</li>';
18632: } else {
18633: $chgtext .= &mt('none').'</li>';
18634: }
18635: }
18636: $chgtext .= '</ul>';
18637: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
18638: $resulttext .= '</li>';
18639: }
18640: $resulttext .= '</ul>';
18641: } else {
18642: $resulttext = &mt('No changes made to user creation settings');
18643: }
18644: } else {
18645: $resulttext = '<span class="LC_error">'.
18646: &mt('An error occurred: [_1]',$putresult).'</span>';
18647: }
18648: if ($warningmsg ne '') {
18649: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
18650: }
18651: return $resulttext;
18652: }
18653:
18654: sub modify_selfcreation {
1.305 raeburn 18655: my ($dom,$lastactref,%domconfig) = @_;
18656: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
18657: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
18658: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 18659: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
18660: if (ref($typesref) eq 'ARRAY') {
18661: @types = @{$typesref};
18662: }
18663: if (ref($usertypesref) eq 'HASH') {
18664: %usertypes = %{$usertypesref};
1.228 raeburn 18665: }
1.303 raeburn 18666: $usertypes{'default'} = $othertitle;
1.224 raeburn 18667: #
18668: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
18669: #
18670: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18671: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
18672: if ($key eq 'cancreate') {
18673: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18674: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
18675: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 18676: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
18677: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
18678: ($item eq 'emailusername') || ($item eq 'shibenv') ||
18679: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 18680: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 18681: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18682: } else {
18683: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18684: }
18685: }
18686: }
18687: } elsif ($key eq 'email_rule') {
18688: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18689: } else {
18690: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18691: }
18692: }
18693: }
18694: #
18695: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
18696: #
18697: if (ref($domconfig{'usermodification'}) eq 'HASH') {
18698: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
18699: if ($key eq 'selfcreate') {
18700: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
18701: } else {
18702: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
18703: }
18704: }
18705: }
1.305 raeburn 18706: #
18707: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
18708: #
18709: if (ref($domconfig{'inststatus'}) eq 'HASH') {
18710: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
18711: if ($key eq 'inststatusguest') {
18712: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
18713: } else {
18714: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
18715: }
18716: }
18717: }
1.224 raeburn 18718:
18719: my @contexts = ('selfcreate');
18720: @{$cancreate{'selfcreate'}} = ();
18721: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 18722: if (@types) {
18723: @{$cancreate{'statustocreate'}} = ();
18724: }
1.236 raeburn 18725: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 18726: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 18727: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 18728: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 18729: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 18730: my %selfcreatetypes = (
18731: sso => 'users authenticated by institutional single sign on',
18732: login => 'users authenticated by institutional log-in',
1.303 raeburn 18733: email => 'users verified by e-mail',
1.50 raeburn 18734: );
1.224 raeburn 18735: #
18736: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
18737: # is permitted.
18738: #
1.305 raeburn 18739: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 18740:
1.305 raeburn 18741: my (@statuses,%email_rule);
1.228 raeburn 18742: foreach my $item ('login','sso','email') {
1.224 raeburn 18743: if ($item eq 'email') {
1.236 raeburn 18744: if ($env{'form.cancreate_email'}) {
1.305 raeburn 18745: if (@types) {
18746: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
18747: foreach my $status (@poss_statuses) {
18748: if (grep(/^\Q$status\E$/,(@types,'default'))) {
18749: push(@statuses,$status);
18750: }
18751: }
18752: $save_inststatus{'inststatusguest'} = \@statuses;
18753: } else {
18754: push(@statuses,'default');
18755: }
18756: if (@statuses) {
18757: my %curr_rule;
18758: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
18759: foreach my $type (@statuses) {
18760: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 18761: }
1.305 raeburn 18762: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
18763: foreach my $type (@statuses) {
18764: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
18765: }
18766: }
18767: push(@{$cancreate{'selfcreate'}},'email');
18768: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
18769: my %curremaildom;
18770: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
18771: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
18772: }
18773: foreach my $type (@statuses) {
18774: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
18775: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
18776: }
18777: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
18778: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
18779: }
18780: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
18781: #
18782: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
18783: #
18784: my $chosen = $1;
18785: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
18786: my $emaildom;
18787: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
1.425 raeburn 18788: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
1.305 raeburn 18789: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
18790: if (ref($curremaildom{$type}) eq 'HASH') {
18791: if (exists($curremaildom{$type}{$chosen})) {
18792: if ($curremaildom{$type}{$chosen} ne $emaildom) {
18793: push(@{$changes{'cancreate'}},'emaildomain');
18794: }
18795: } elsif ($emaildom ne '') {
18796: push(@{$changes{'cancreate'}},'emaildomain');
18797: }
18798: } elsif ($emaildom ne '') {
18799: push(@{$changes{'cancreate'}},'emaildomain');
1.425 raeburn 18800: }
1.305 raeburn 18801: }
18802: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
18803: } elsif ($chosen eq 'custom') {
18804: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
18805: $email_rule{$type} = [];
18806: if (ref($emailrules) eq 'HASH') {
18807: foreach my $rule (@possemail_rules) {
18808: if (exists($emailrules->{$rule})) {
18809: push(@{$email_rule{$type}},$rule);
18810: }
18811: }
18812: }
18813: if (@{$email_rule{$type}}) {
18814: $cancreate{'emailoptions'}{$type} = 'custom';
18815: if (ref($curr_rule{$type}) eq 'ARRAY') {
18816: if (@{$curr_rule{$type}} > 0) {
18817: foreach my $rule (@{$curr_rule{$type}}) {
18818: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
18819: push(@{$changes{'email_rule'}},$type);
18820: }
18821: }
18822: }
18823: foreach my $type (@{$email_rule{$type}}) {
18824: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
18825: push(@{$changes{'email_rule'}},$type);
18826: }
18827: }
18828: } else {
18829: push(@{$changes{'email_rule'}},$type);
18830: }
18831: }
18832: } else {
18833: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
18834: }
18835: }
18836: }
18837: if (@types) {
18838: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
18839: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
18840: if (@changed) {
18841: push(@{$changes{'inststatus'}},'inststatusguest');
18842: }
18843: } else {
18844: push(@{$changes{'inststatus'}},'inststatusguest');
18845: }
18846: }
18847: } else {
18848: delete($env{'form.cancreate_email'});
18849: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
18850: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
18851: push(@{$changes{'inststatus'}},'inststatusguest');
18852: }
18853: }
18854: }
18855: } else {
18856: $save_inststatus{'inststatusguest'} = [];
18857: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
18858: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
18859: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 18860: }
18861: }
1.224 raeburn 18862: }
18863: } else {
18864: if ($env{'form.cancreate_'.$item}) {
18865: push(@{$cancreate{'selfcreate'}},$item);
18866: }
18867: }
18868: }
1.305 raeburn 18869: my (%userinfo,%savecaptcha);
1.224 raeburn 18870: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
18871: #
1.228 raeburn 18872: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
18873: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 18874: #
1.236 raeburn 18875:
1.244 raeburn 18876: if ($env{'form.cancreate_email'}) {
1.228 raeburn 18877: push(@contexts,'emailusername');
1.305 raeburn 18878: if (@statuses) {
18879: foreach my $type (@statuses) {
1.228 raeburn 18880: if (ref($infofields) eq 'ARRAY') {
18881: foreach my $field (@{$infofields}) {
18882: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
18883: $cancreate{'emailusername'}{$type}{$field} = $1;
18884: }
18885: }
1.224 raeburn 18886: }
18887: }
18888: }
18889: #
18890: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 18891: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 18892: #
18893:
18894: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
18895: @approvalnotify = sort(@approvalnotify);
18896: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
18897: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
18898: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
18899: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
18900: push(@{$changes{'cancreate'}},'notify');
18901: }
18902: } else {
18903: if ($cancreate{'notify'}{'approval'}) {
18904: push(@{$changes{'cancreate'}},'notify');
18905: }
18906: }
18907: } elsif ($cancreate{'notify'}{'approval'}) {
18908: push(@{$changes{'cancreate'}},'notify');
18909: }
18910:
18911: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
18912: }
18913: #
1.236 raeburn 18914: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 18915: # institutional log-in.
18916: #
18917: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
18918: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
18919: ($domdefaults{'auth_def'} eq 'localauth'))) {
18920: $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.').' '.
18921: &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.');
18922: }
18923: }
18924: my @fields = ('lastname','firstname','middlename','generation',
18925: 'permanentemail','id');
1.240 raeburn 18926: my @shibfields = (@fields,'inststatus');
1.224 raeburn 18927: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
18928: #
18929: # Where usernames may created for institutional log-in and/or institutional single sign on:
18930: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
18931: # may self-create accounts
18932: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
18933: # which the user may supply, if institutional data is unavailable.
18934: #
18935: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 18936: if (@types) {
1.305 raeburn 18937: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
18938: push(@contexts,'statustocreate');
1.303 raeburn 18939: foreach my $type (@types) {
1.224 raeburn 18940: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
18941: foreach my $field (@fields) {
18942: if (grep(/^\Q$field\E$/,@modifiable)) {
18943: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
18944: } else {
18945: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
18946: }
18947: }
18948: }
18949: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 18950: foreach my $type (@types) {
1.224 raeburn 18951: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
18952: foreach my $field (@fields) {
18953: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
18954: $curr_usermodify{'selfcreate'}{$type}{$field}) {
18955: push(@{$changes{'selfcreate'}},$type);
18956: last;
18957: }
18958: }
18959: }
18960: }
18961: } else {
1.303 raeburn 18962: foreach my $type (@types) {
1.224 raeburn 18963: push(@{$changes{'selfcreate'}},$type);
18964: }
18965: }
18966: }
1.240 raeburn 18967: foreach my $field (@shibfields) {
18968: if ($env{'form.shibenv_'.$field} ne '') {
18969: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
18970: }
18971: }
18972: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
18973: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
18974: foreach my $field (@shibfields) {
18975: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
18976: push(@{$changes{'cancreate'}},'shibenv');
18977: }
18978: }
18979: } else {
18980: foreach my $field (@shibfields) {
18981: if ($env{'form.shibenv_'.$field}) {
18982: push(@{$changes{'cancreate'}},'shibenv');
18983: last;
18984: }
18985: }
18986: }
18987: }
1.224 raeburn 18988: }
18989: foreach my $item (@contexts) {
18990: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
18991: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
18992: if (ref($cancreate{$item}) eq 'ARRAY') {
18993: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
18994: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18995: push(@{$changes{'cancreate'}},$item);
18996: }
18997: }
18998: }
18999: }
19000: if (ref($cancreate{$item}) eq 'ARRAY') {
19001: foreach my $type (@{$cancreate{$item}}) {
19002: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
19003: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19004: push(@{$changes{'cancreate'}},$item);
19005: }
19006: }
19007: }
19008: }
19009: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
19010: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 19011: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
19012: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19013: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
19014: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19015: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19016: push(@{$changes{'cancreate'}},$item);
19017: }
19018: }
19019: }
1.305 raeburn 19020: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19021: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19022: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19023: push(@{$changes{'cancreate'}},$item);
19024: }
1.224 raeburn 19025: }
19026: }
19027: }
1.305 raeburn 19028: foreach my $type (keys(%{$cancreate{$item}})) {
19029: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19030: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19031: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19032: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19033: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19034: push(@{$changes{'cancreate'}},$item);
19035: }
19036: }
19037: } else {
19038: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19039: push(@{$changes{'cancreate'}},$item);
19040: }
19041: }
19042: }
1.305 raeburn 19043: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19044: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19045: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19046: push(@{$changes{'cancreate'}},$item);
19047: }
1.224 raeburn 19048: }
19049: }
19050: }
19051: }
19052: } elsif ($curr_usercreation{'cancreate'}{$item}) {
19053: if (ref($cancreate{$item}) eq 'ARRAY') {
19054: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
19055: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19056: push(@{$changes{'cancreate'}},$item);
19057: }
19058: }
1.305 raeburn 19059: }
19060: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19061: if (ref($cancreate{$item}) eq 'HASH') {
19062: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19063: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 19064: }
19065: }
19066: } elsif ($item eq 'emailusername') {
1.228 raeburn 19067: if (ref($cancreate{$item}) eq 'HASH') {
19068: foreach my $type (keys(%{$cancreate{$item}})) {
19069: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19070: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19071: if ($cancreate{$item}{$type}{$field}) {
19072: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19073: push(@{$changes{'cancreate'}},$item);
19074: }
19075: last;
19076: }
19077: }
19078: }
19079: }
1.224 raeburn 19080: }
19081: }
19082: }
19083: #
19084: # Populate %save_usercreate hash with updates to self-creation configuration.
19085: #
19086: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
19087: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 19088: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 19089: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
19090: if (ref($cancreate{'notify'}) eq 'HASH') {
19091: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
19092: }
1.236 raeburn 19093: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
19094: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
19095: }
1.303 raeburn 19096: if (ref($cancreate{'emailverified'}) eq 'HASH') {
19097: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
19098: }
1.305 raeburn 19099: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
19100: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
19101: }
1.303 raeburn 19102: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
19103: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
19104: }
1.224 raeburn 19105: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19106: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
19107: }
1.240 raeburn 19108: if (ref($cancreate{'shibenv'}) eq 'HASH') {
19109: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
19110: }
1.224 raeburn 19111: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 19112: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 19113:
19114: my %userconfig_hash = (
19115: usercreation => \%save_usercreate,
19116: usermodification => \%save_usermodify,
1.305 raeburn 19117: inststatus => \%save_inststatus,
1.224 raeburn 19118: );
1.305 raeburn 19119:
1.224 raeburn 19120: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
19121: $dom);
19122: #
1.305 raeburn 19123: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 19124: #
1.27 raeburn 19125: if ($putresult eq 'ok') {
19126: if (keys(%changes) > 0) {
19127: $resulttext = &mt('Changes made:').'<ul>';
19128: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 19129: my %lt = &selfcreation_types();
1.34 raeburn 19130: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 19131: my $chgtext = '';
1.45 raeburn 19132: if ($type eq 'selfcreate') {
1.50 raeburn 19133: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 19134: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 19135: } else {
1.224 raeburn 19136: $chgtext .= &mt('Self-creation of a new account is permitted for:').
19137: '<ul>';
1.50 raeburn 19138: foreach my $case (@{$cancreate{$type}}) {
19139: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
19140: }
19141: $chgtext .= '</ul>';
1.100 raeburn 19142: if (ref($cancreate{$type}) eq 'ARRAY') {
19143: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
19144: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19145: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 19146: $chgtext .= '<span class="LC_warning">'.
19147: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
19148: '</span><br />';
19149: }
19150: }
19151: }
19152: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 19153: if (!@statuses) {
19154: $chgtext .= '<span class="LC_warning">'.
19155: &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.").
19156: '</span><br />';
1.303 raeburn 19157:
1.100 raeburn 19158: }
19159: }
19160: }
1.43 raeburn 19161: }
1.240 raeburn 19162: } elsif ($type eq 'shibenv') {
19163: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 19164: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 19165: } else {
19166: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
19167: '<ul>';
19168: foreach my $field (@shibfields) {
19169: next if ($cancreate{$type}{$field} eq '');
19170: if ($field eq 'inststatus') {
19171: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
19172: } else {
19173: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
19174: }
19175: }
19176: $chgtext .= '</ul>';
1.303 raeburn 19177: }
1.93 raeburn 19178: } elsif ($type eq 'statustocreate') {
1.96 raeburn 19179: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
19180: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
19181: if (@{$cancreate{'selfcreate'}} > 0) {
19182: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 19183: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 19184: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 19185: $chgtext .= '<br />'.
19186: '<span class="LC_warning">'.
19187: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
19188: '</span>';
19189: }
1.303 raeburn 19190: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 19191: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 19192: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
19193: } else {
19194: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
19195: }
19196: $chgtext .= '<ul>';
19197: foreach my $case (@{$cancreate{$type}}) {
19198: if ($case eq 'default') {
19199: $chgtext .= '<li>'.$othertitle.'</li>';
19200: } else {
1.303 raeburn 19201: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 19202: }
19203: }
1.100 raeburn 19204: $chgtext .= '</ul>';
19205: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 19206: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 19207: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
19208: '</span>';
1.100 raeburn 19209: }
19210: }
19211: } else {
19212: if (@{$cancreate{$type}} == 0) {
19213: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
19214: } else {
19215: $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 19216: }
19217: }
1.303 raeburn 19218: $chgtext .= '<br />';
1.93 raeburn 19219: }
1.236 raeburn 19220: } elsif ($type eq 'selfcreateprocessing') {
19221: my %choices = &Apache::lonlocal::texthash (
19222: automatic => 'Automatic approval',
19223: approval => 'Queued for approval',
19224: );
1.305 raeburn 19225: if (@types) {
19226: if (@statuses) {
1.425 raeburn 19227: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 19228: '<ul>';
1.305 raeburn 19229: foreach my $status (@statuses) {
19230: if ($status eq 'default') {
19231: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19232: } else {
1.305 raeburn 19233: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19234: }
19235: }
19236: $chgtext .= '</ul>';
19237: }
19238: } else {
19239: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
19240: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
19241: }
19242: } elsif ($type eq 'emailverified') {
19243: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 19244: all => 'Same as e-mail',
19245: first => 'Omit @domain',
19246: free => 'Free to choose',
1.303 raeburn 19247: );
1.305 raeburn 19248: if (@types) {
19249: if (@statuses) {
1.303 raeburn 19250: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
19251: '<ul>';
1.305 raeburn 19252: foreach my $status (@statuses) {
1.362 raeburn 19253: if ($status eq 'default') {
1.305 raeburn 19254: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19255: } else {
1.305 raeburn 19256: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19257: }
19258: }
19259: $chgtext .= '</ul>';
19260: }
19261: } else {
1.305 raeburn 19262: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 19263: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 19264: }
1.305 raeburn 19265: } elsif ($type eq 'emailoptions') {
19266: my %options = &Apache::lonlocal::texthash (
19267: any => 'Any e-mail',
19268: inst => 'Institutional only',
19269: noninst => 'Non-institutional only',
19270: custom => 'Custom restrictions',
19271: );
19272: if (@types) {
19273: if (@statuses) {
19274: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
19275: '<ul>';
19276: foreach my $status (@statuses) {
19277: if ($type eq 'default') {
19278: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
19279: } else {
19280: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 19281: }
19282: }
1.305 raeburn 19283: $chgtext .= '</ul>';
19284: }
19285: } else {
19286: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
19287: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
19288: } else {
19289: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
19290: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 19291: }
1.305 raeburn 19292: }
19293: } elsif ($type eq 'emaildomain') {
19294: my $output;
19295: if (@statuses) {
19296: foreach my $type (@statuses) {
19297: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
19298: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
19299: if ($type eq 'default') {
19300: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19301: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19302: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19303: } else {
19304: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
19305: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
19306: }
1.303 raeburn 19307: } else {
1.305 raeburn 19308: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19309: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19310: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19311: } else {
19312: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
1.421 raeburn 19313: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
1.305 raeburn 19314: }
1.303 raeburn 19315: }
1.305 raeburn 19316: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
19317: if ($type eq 'default') {
19318: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19319: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19320: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19321: } else {
19322: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
19323: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
19324: }
1.303 raeburn 19325: } else {
1.305 raeburn 19326: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19327: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19328: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19329: } else {
19330: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
1.421 raeburn 19331: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
1.305 raeburn 19332: }
1.303 raeburn 19333: }
19334: }
19335: }
19336: }
1.305 raeburn 19337: }
19338: if ($output ne '') {
19339: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
19340: '<ul>'.$output.'</ul>';
1.236 raeburn 19341: }
1.165 raeburn 19342: } elsif ($type eq 'captcha') {
1.224 raeburn 19343: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 19344: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
19345: } else {
19346: my %captchas = &captcha_phrases();
1.224 raeburn 19347: if ($captchas{$savecaptcha{$type}}) {
19348: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 19349: } else {
1.210 raeburn 19350: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 19351: }
19352: }
19353: } elsif ($type eq 'recaptchakeys') {
19354: my ($privkey,$pubkey);
1.224 raeburn 19355: if (ref($savecaptcha{$type}) eq 'HASH') {
19356: $pubkey = $savecaptcha{$type}{'public'};
19357: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 19358: }
19359: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
19360: if (!$pubkey) {
19361: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
19362: } else {
19363: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
19364: }
19365: if (!$privkey) {
19366: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
19367: } else {
19368: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
19369: }
19370: $chgtext .= '</ul>';
1.269 raeburn 19371: } elsif ($type eq 'recaptchaversion') {
19372: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 19373: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 19374: }
1.224 raeburn 19375: } elsif ($type eq 'emailusername') {
19376: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 19377: if (@statuses) {
19378: foreach my $type (@statuses) {
1.228 raeburn 19379: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
19380: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 19381: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 19382: '<ul>';
19383: foreach my $field (@{$infofields}) {
19384: if ($cancreate{'emailusername'}{$type}{$field}) {
19385: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
19386: }
19387: }
1.245 raeburn 19388: $chgtext .= '</ul>';
19389: } else {
1.303 raeburn 19390: $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 19391: }
19392: } else {
1.303 raeburn 19393: $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 19394: }
19395: }
19396: }
19397: }
19398: } elsif ($type eq 'notify') {
1.303 raeburn 19399: my $numapprove = 0;
1.224 raeburn 19400: if (ref($changes{'cancreate'}) eq 'ARRAY') {
19401: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
19402: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 19403: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
19404: $numapprove ++;
1.224 raeburn 19405: }
19406: }
1.43 raeburn 19407: }
1.303 raeburn 19408: unless ($numapprove) {
19409: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
19410: }
1.34 raeburn 19411: }
1.224 raeburn 19412: if ($chgtext) {
19413: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 19414: }
19415: }
19416: }
1.305 raeburn 19417: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 19418: my ($emailrules,$emailruleorder) =
19419: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 19420: foreach my $type (@{$changes{'email_rule'}}) {
19421: if (ref($email_rule{$type}) eq 'ARRAY') {
19422: my $chgtext = '<ul>';
19423: foreach my $rule (@{$email_rule{$type}}) {
19424: if (ref($emailrules->{$rule}) eq 'HASH') {
19425: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
19426: }
19427: }
19428: $chgtext .= '</ul>';
1.310 raeburn 19429: my $typename;
1.305 raeburn 19430: if (@types) {
19431: if ($type eq 'default') {
19432: $typename = $othertitle;
19433: } else {
19434: $typename = $usertypes{$type};
1.425 raeburn 19435: }
1.305 raeburn 19436: $chgtext .= &mt('(Affiliation: [_1])',$typename);
19437: }
19438: if (@{$email_rule{$type}} > 0) {
19439: $resulttext .= '<li>'.
19440: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
19441: $usertypes{$type}).
19442: $chgtext.
19443: '</li>';
19444: } else {
19445: $resulttext .= '<li>'.
1.310 raeburn 19446: &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 19447: '</li>'.
1.310 raeburn 19448: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 19449: }
1.43 raeburn 19450: }
19451: }
1.305 raeburn 19452: }
19453: if (ref($changes{'inststatus'}) eq 'ARRAY') {
19454: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
19455: if (@{$save_inststatus{'inststatusguest'}} > 0) {
19456: my $chgtext = '<ul>';
19457: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
19458: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
19459: }
19460: $chgtext .= '</ul>';
19461: $resulttext .= '<li>'.
19462: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
19463: $chgtext.
19464: '</li>';
19465: } else {
19466: $resulttext .= '<li>'.
19467: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
19468: '</li>';
19469: }
1.43 raeburn 19470: }
19471: }
1.224 raeburn 19472: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
19473: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
19474: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19475: foreach my $type (@{$changes{'selfcreate'}}) {
19476: my $typename = $type;
1.303 raeburn 19477: if (keys(%usertypes) > 0) {
19478: if ($usertypes{$type} ne '') {
19479: $typename = $usertypes{$type};
1.224 raeburn 19480: }
19481: }
19482: my @modifiable;
19483: $resulttext .= '<li>'.
19484: &mt('Self-creation of account by users with status: [_1]',
19485: '<span class="LC_cusr_emph">'.$typename.'</span>').
19486: ' - '.&mt('modifiable fields (if institutional data blank): ');
19487: foreach my $field (@fields) {
19488: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
19489: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 19490: }
19491: }
1.224 raeburn 19492: if (@modifiable > 0) {
19493: $resulttext .= join(', ',@modifiable);
1.43 raeburn 19494: } else {
1.224 raeburn 19495: $resulttext .= &mt('none');
1.43 raeburn 19496: }
1.224 raeburn 19497: $resulttext .= '</li>';
1.28 raeburn 19498: }
1.224 raeburn 19499: $resulttext .= '</ul></li>';
1.28 raeburn 19500: }
1.27 raeburn 19501: $resulttext .= '</ul>';
1.305 raeburn 19502: my $cachetime = 24*60*60;
19503: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
19504: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19505: if (ref($lastactref) eq 'HASH') {
19506: $lastactref->{'domdefaults'} = 1;
19507: }
1.27 raeburn 19508: } else {
1.224 raeburn 19509: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 19510: }
19511: } else {
19512: $resulttext = '<span class="LC_error">'.
1.23 raeburn 19513: &mt('An error occurred: [_1]',$putresult).'</span>';
19514: }
1.43 raeburn 19515: if ($warningmsg ne '') {
19516: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
19517: }
1.23 raeburn 19518: return $resulttext;
19519: }
19520:
1.165 raeburn 19521: sub process_captcha {
1.369 raeburn 19522: my ($container,$changes,$newsettings,$currsettings) = @_;
19523: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165 raeburn 19524: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
19525: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
19526: $newsettings->{'captcha'} = 'original';
19527: }
1.369 raeburn 19528: my %current;
19529: if (ref($currsettings) eq 'HASH') {
19530: %current = %{$currsettings};
19531: }
19532: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 19533: if ($container eq 'cancreate') {
1.169 raeburn 19534: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19535: push(@{$changes->{'cancreate'}},'captcha');
19536: } elsif (!defined($changes->{'cancreate'})) {
19537: $changes->{'cancreate'} = ['captcha'];
19538: }
1.368 raeburn 19539: } elsif ($container eq 'passwords') {
19540: $changes->{'reset'} = 1;
1.169 raeburn 19541: } else {
19542: $changes->{'captcha'} = 1;
1.165 raeburn 19543: }
19544: }
1.269 raeburn 19545: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 19546: if ($newsettings->{'captcha'} eq 'recaptcha') {
19547: $newpub = $env{'form.'.$container.'_recaptchapub'};
19548: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 19549: $newpub =~ s/[^\w\-]//g;
19550: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 19551: $newsettings->{'recaptchakeys'} = {
19552: public => $newpub,
19553: private => $newpriv,
19554: };
1.269 raeburn 19555: $newversion = $env{'form.'.$container.'_recaptchaversion'};
19556: $newversion =~ s/\D//g;
19557: if ($newversion ne '2') {
19558: $newversion = 1;
19559: }
19560: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 19561: }
1.369 raeburn 19562: if (ref($current{'recaptchakeys'}) eq 'HASH') {
19563: $currpub = $current{'recaptchakeys'}{'public'};
19564: $currpriv = $current{'recaptchakeys'}{'private'};
1.179 raeburn 19565: unless ($newsettings->{'captcha'} eq 'recaptcha') {
19566: $newsettings->{'recaptchakeys'} = {
19567: public => '',
19568: private => '',
19569: }
19570: }
1.165 raeburn 19571: }
1.369 raeburn 19572: if ($current{'captcha'} eq 'recaptcha') {
19573: $currversion = $current{'recaptchaversion'};
1.269 raeburn 19574: if ($currversion ne '2') {
19575: $currversion = 1;
19576: }
19577: }
19578: if ($currversion ne $newversion) {
19579: if ($container eq 'cancreate') {
19580: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19581: push(@{$changes->{'cancreate'}},'recaptchaversion');
19582: } elsif (!defined($changes->{'cancreate'})) {
19583: $changes->{'cancreate'} = ['recaptchaversion'];
19584: }
1.368 raeburn 19585: } elsif ($container eq 'passwords') {
19586: $changes->{'reset'} = 1;
1.269 raeburn 19587: } else {
19588: $changes->{'recaptchaversion'} = 1;
19589: }
19590: }
1.165 raeburn 19591: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 19592: if ($container eq 'cancreate') {
19593: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19594: push(@{$changes->{'cancreate'}},'recaptchakeys');
19595: } elsif (!defined($changes->{'cancreate'})) {
19596: $changes->{'cancreate'} = ['recaptchakeys'];
19597: }
1.368 raeburn 19598: } elsif ($container eq 'passwords') {
19599: $changes->{'reset'} = 1;
1.169 raeburn 19600: } else {
1.210 raeburn 19601: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 19602: }
19603: }
19604: return;
19605: }
19606:
1.33 raeburn 19607: sub modify_usermodification {
19608: my ($dom,%domconfig) = @_;
1.224 raeburn 19609: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 19610: if (ref($domconfig{'usermodification'}) eq 'HASH') {
19611: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 19612: if ($key eq 'selfcreate') {
19613: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
19614: } else {
19615: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
19616: }
1.33 raeburn 19617: }
19618: }
1.224 raeburn 19619: my @contexts = ('author','course');
1.33 raeburn 19620: my %context_title = (
19621: author => 'In author context',
19622: course => 'In course context',
19623: );
19624: my @fields = ('lastname','firstname','middlename','generation',
19625: 'permanentemail','id');
19626: my %roles = (
19627: author => ['ca','aa'],
19628: course => ['st','ep','ta','in','cr'],
19629: );
19630: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19631: foreach my $context (@contexts) {
19632: foreach my $role (@{$roles{$context}}) {
19633: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
19634: foreach my $item (@fields) {
19635: if (grep(/^\Q$item\E$/,@modifiable)) {
19636: $modifyhash{$context}{$role}{$item} = 1;
19637: } else {
19638: $modifyhash{$context}{$role}{$item} = 0;
19639: }
19640: }
19641: }
19642: if (ref($curr_usermodification{$context}) eq 'HASH') {
19643: foreach my $role (@{$roles{$context}}) {
19644: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
19645: foreach my $field (@fields) {
19646: if ($modifyhash{$context}{$role}{$field} ne
19647: $curr_usermodification{$context}{$role}{$field}) {
19648: push(@{$changes{$context}},$role);
19649: last;
19650: }
19651: }
19652: }
19653: }
19654: } else {
19655: foreach my $context (@contexts) {
19656: foreach my $role (@{$roles{$context}}) {
19657: push(@{$changes{$context}},$role);
19658: }
19659: }
19660: }
19661: }
19662: my %usermodification_hash = (
19663: usermodification => \%modifyhash,
19664: );
19665: my $putresult = &Apache::lonnet::put_dom('configuration',
19666: \%usermodification_hash,$dom);
19667: if ($putresult eq 'ok') {
19668: if (keys(%changes) > 0) {
19669: $resulttext = &mt('Changes made: ').'<ul>';
19670: foreach my $context (@contexts) {
19671: if (ref($changes{$context}) eq 'ARRAY') {
19672: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
19673: if (ref($changes{$context}) eq 'ARRAY') {
19674: foreach my $role (@{$changes{$context}}) {
19675: my $rolename;
1.224 raeburn 19676: if ($role eq 'cr') {
19677: $rolename = &mt('Custom');
1.33 raeburn 19678: } else {
1.224 raeburn 19679: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 19680: }
19681: my @modifiable;
1.224 raeburn 19682: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 19683: foreach my $field (@fields) {
19684: if ($modifyhash{$context}{$role}{$field}) {
19685: push(@modifiable,$fieldtitles{$field});
19686: }
19687: }
19688: if (@modifiable > 0) {
19689: $resulttext .= join(', ',@modifiable);
19690: } else {
19691: $resulttext .= &mt('none');
19692: }
19693: $resulttext .= '</li>';
19694: }
19695: $resulttext .= '</ul></li>';
19696: }
19697: }
19698: }
19699: $resulttext .= '</ul>';
19700: } else {
19701: $resulttext = &mt('No changes made to user modification settings');
19702: }
19703: } else {
19704: $resulttext = '<span class="LC_error">'.
19705: &mt('An error occurred: [_1]',$putresult).'</span>';
19706: }
19707: return $resulttext;
19708: }
19709:
1.43 raeburn 19710: sub modify_defaults {
1.212 raeburn 19711: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 19712: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 19713: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 19714: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 19715: 'portal_def');
1.325 raeburn 19716: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 19717: foreach my $item (@items) {
19718: $newvalues{$item} = $env{'form.'.$item};
19719: if ($item eq 'auth_def') {
19720: if ($newvalues{$item} ne '') {
19721: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
19722: push(@errors,$item);
19723: }
19724: }
19725: } elsif ($item eq 'lang_def') {
19726: if ($newvalues{$item} ne '') {
19727: if ($newvalues{$item} =~ /^(\w+)/) {
19728: my $langcode = $1;
1.103 raeburn 19729: if ($langcode ne 'x_chef') {
19730: if (code2language($langcode) eq '') {
19731: push(@errors,$item);
19732: }
1.43 raeburn 19733: }
19734: } else {
19735: push(@errors,$item);
19736: }
19737: }
1.54 raeburn 19738: } elsif ($item eq 'timezone_def') {
19739: if ($newvalues{$item} ne '') {
1.62 raeburn 19740: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 19741: push(@errors,$item);
19742: }
19743: }
1.68 raeburn 19744: } elsif ($item eq 'datelocale_def') {
19745: if ($newvalues{$item} ne '') {
19746: my @datelocale_ids = DateTime::Locale->ids();
19747: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
19748: push(@errors,$item);
19749: }
19750: }
1.141 raeburn 19751: } elsif ($item eq 'portal_def') {
19752: if ($newvalues{$item} ne '') {
1.414 raeburn 19753: 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])\/?$/) {
19754: foreach my $field ('email','web') {
19755: if ($env{'form.'.$item.'_'.$field}) {
19756: $newvalues{$item.'_'.$field} = $env{'form.'.$item.'_'.$field};
19757: }
19758: }
19759: } else {
1.141 raeburn 19760: push(@errors,$item);
19761: }
19762: }
1.43 raeburn 19763: }
19764: if (grep(/^\Q$item\E$/,@errors)) {
19765: $newvalues{$item} = $domdefaults{$item};
1.414 raeburn 19766: if ($item eq 'portal_def') {
19767: if ($domdefaults{$item}) {
19768: foreach my $field ('email','web') {
19769: if (exists($domdefaults{$item.'_'.$field})) {
19770: $newvalues{$item.'_'.$field} = $domdefaults{$item.'_'.$field};
19771: }
19772: }
19773: }
19774: }
1.43 raeburn 19775: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
19776: $changes{$item} = 1;
19777: }
1.414 raeburn 19778: if ($item eq 'portal_def') {
19779: unless (grep(/^\Q$item\E$/,@errors)) {
1.425 raeburn 19780: if ($newvalues{$item} eq '') {
1.414 raeburn 19781: foreach my $field ('email','web') {
19782: if (exists($domdefaults{$item.'_'.$field})) {
19783: delete($domdefaults{$item.'_'.$field});
19784: }
19785: }
19786: } else {
19787: unless ($changes{$item}) {
19788: foreach my $field ('email','web') {
19789: if ($domdefaults{$item.'_'.$field} ne $newvalues{$item.'_'.$field}) {
19790: $changes{$item} = 1;
19791: last;
19792: }
19793: }
19794: }
19795: foreach my $field ('email','web') {
19796: if ($newvalues{$item.'_'.$field}) {
19797: $domdefaults{$item.'_'.$field} = $newvalues{$item.'_'.$field};
19798: } elsif (exists($domdefaults{$item.'_'.$field})) {
19799: delete($domdefaults{$item.'_'.$field});
19800: }
19801: }
19802: }
19803: }
19804: }
1.72 raeburn 19805: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 19806: }
1.354 raeburn 19807: my %staticdefaults = (
19808: 'intauth_cost' => 10,
19809: 'intauth_check' => 0,
19810: 'intauth_switch' => 0,
19811: );
19812: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
19813: if (exists($domdefaults{$item})) {
19814: $newvalues{$item} = $domdefaults{$item};
19815: } else {
19816: $newvalues{$item} = $staticdefaults{$item};
19817: }
19818: }
1.409 raeburn 19819: my ($unamemaprules,$ruleorder);
19820: my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
19821: if (@possunamemaprules) {
19822: ($unamemaprules,$ruleorder) =
19823: &Apache::lonnet::inst_userrules($dom,'unamemap');
19824: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
19825: if (@{$ruleorder} > 0) {
19826: my %possrules;
19827: map { $possrules{$_} = 1; } @possunamemaprules;
19828: foreach my $rule (@{$ruleorder}) {
19829: if ($possrules{$rule}) {
19830: push(@{$newvalues{'unamemap_rule'}},$rule);
19831: }
19832: }
19833: }
19834: }
19835: }
19836: if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
19837: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
19838: my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
19839: $newvalues{'unamemap_rule'});
19840: if (@rulediffs) {
19841: $changes{'unamemap_rule'} = 1;
19842: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
19843: }
19844: } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
19845: $changes{'unamemap_rule'} = 1;
19846: delete($domdefaults{'unamemap_rule'});
19847: }
19848: } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
19849: if (@{$newvalues{'unamemap_rule'}} > 0) {
19850: $changes{'unamemap_rule'} = 1;
19851: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
19852: }
19853: }
1.43 raeburn 19854: my %defaults_hash = (
1.72 raeburn 19855: defaults => \%newvalues,
19856: );
1.43 raeburn 19857: my $title = &defaults_titles();
1.236 raeburn 19858:
19859: my $currinststatus;
19860: if (ref($domconfig{'inststatus'}) eq 'HASH') {
19861: $currinststatus = $domconfig{'inststatus'};
19862: } else {
19863: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
19864: $currinststatus = {
19865: inststatustypes => $usertypes,
19866: inststatusorder => $types,
19867: inststatusguest => [],
19868: };
19869: }
19870: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
19871: my @allpos;
19872: my %alltypes;
1.305 raeburn 19873: my @inststatusguest;
19874: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
19875: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
19876: unless (grep(/^\Q$type\E$/,@todelete)) {
19877: push(@inststatusguest,$type);
19878: }
19879: }
19880: }
19881: my ($currtitles,$currorder);
1.236 raeburn 19882: if (ref($currinststatus) eq 'HASH') {
19883: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
19884: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
19885: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
19886: if ($currinststatus->{inststatustypes}->{$type} ne '') {
19887: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
19888: }
19889: }
19890: unless (grep(/^\Q$type\E$/,@todelete)) {
19891: my $position = $env{'form.inststatus_pos_'.$type};
19892: $position =~ s/\D+//g;
19893: $allpos[$position] = $type;
19894: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
19895: $alltypes{$type} =~ s/`//g;
19896: }
19897: }
19898: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
19899: $currtitles =~ s/,$//;
19900: }
19901: }
19902: if ($env{'form.addinststatus'}) {
19903: my $newtype = $env{'form.addinststatus'};
19904: $newtype =~ s/\W//g;
19905: unless (exists($alltypes{$newtype})) {
19906: $alltypes{$newtype} = $env{'form.addinststatus_title'};
19907: $alltypes{$newtype} =~ s/`//g;
19908: my $position = $env{'form.addinststatus_pos'};
19909: $position =~ s/\D+//g;
19910: if ($position ne '') {
19911: $allpos[$position] = $newtype;
19912: }
19913: }
19914: }
1.305 raeburn 19915: my @orderedstatus;
1.236 raeburn 19916: foreach my $type (@allpos) {
19917: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
19918: push(@orderedstatus,$type);
19919: }
19920: }
19921: foreach my $type (keys(%alltypes)) {
19922: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
19923: delete($alltypes{$type});
19924: }
19925: }
19926: $defaults_hash{'inststatus'} = {
19927: inststatustypes => \%alltypes,
19928: inststatusorder => \@orderedstatus,
1.305 raeburn 19929: inststatusguest => \@inststatusguest,
1.236 raeburn 19930: };
19931: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
19932: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
19933: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
19934: }
19935: }
19936: if ($currorder ne join(',',@orderedstatus)) {
19937: $changes{'inststatus'}{'inststatusorder'} = 1;
19938: }
19939: my $newtitles;
19940: foreach my $item (@orderedstatus) {
19941: $newtitles .= $alltypes{$item}.',';
19942: }
19943: $newtitles =~ s/,$//;
19944: if ($currtitles ne $newtitles) {
19945: $changes{'inststatus'}{'inststatustypes'} = 1;
19946: }
1.43 raeburn 19947: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
19948: $dom);
19949: if ($putresult eq 'ok') {
19950: if (keys(%changes) > 0) {
19951: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 19952: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 19953: 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";
19954: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 19955: if ($item eq 'inststatus') {
19956: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 19957: if (@orderedstatus) {
1.236 raeburn 19958: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
19959: foreach my $type (@orderedstatus) {
19960: $resulttext .= $alltypes{$type}.', ';
19961: }
19962: $resulttext =~ s/, $//;
19963: $resulttext .= '</li>';
1.305 raeburn 19964: } else {
1.425 raeburn 19965: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 19966: }
19967: }
1.409 raeburn 19968: } elsif ($item eq 'unamemap_rule') {
19969: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
19970: my @rulenames;
19971: if (ref($unamemaprules) eq 'HASH') {
19972: foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
19973: if (ref($unamemaprules->{$rule}) eq 'HASH') {
19974: push(@rulenames,$unamemaprules->{$rule}->{'name'});
19975: }
19976: }
19977: }
19978: if (@rulenames) {
19979: $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
19980: '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
19981: '</li>';
19982: } else {
19983: $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
19984: }
19985: } else {
19986: $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
19987: }
1.236 raeburn 19988: } else {
19989: my $value = $env{'form.'.$item};
19990: if ($value eq '') {
19991: $value = &mt('none');
19992: } elsif ($item eq 'auth_def') {
19993: my %authnames = &authtype_names();
19994: my %shortauth = (
19995: internal => 'int',
19996: krb4 => 'krb4',
19997: krb5 => 'krb5',
19998: localauth => 'loc',
1.325 raeburn 19999: lti => 'lti',
1.236 raeburn 20000: );
20001: $value = $authnames{$shortauth{$value}};
20002: }
20003: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
1.414 raeburn 20004: $mailmsgtext .= "$title->{$item} set to $value\n";
20005: if ($item eq 'portal_def') {
20006: if ($env{'form.'.$item} ne '') {
20007: foreach my $field ('email','web') {
20008: $value = $env{'form.'.$item.'_'.$field};
20009: if ($value) {
20010: $value = &mt('Yes');
20011: } else {
20012: $value = &mt('No');
20013: }
20014: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$field},$value).'</li>';
20015: }
20016: }
20017: }
1.43 raeburn 20018: }
20019: }
20020: $resulttext .= '</ul>';
20021: $mailmsgtext .= "\n";
20022: my $cachetime = 24*60*60;
1.72 raeburn 20023: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 20024: if (ref($lastactref) eq 'HASH') {
20025: $lastactref->{'domdefaults'} = 1;
20026: }
1.68 raeburn 20027: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 20028: my $notify = 1;
20029: if (ref($domconfig{'contacts'}) eq 'HASH') {
20030: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
20031: $notify = 0;
20032: }
20033: }
20034: if ($notify) {
20035: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
20036: "LON-CAPA Domain Settings Change - $dom",
20037: $mailmsgtext);
20038: }
1.54 raeburn 20039: }
1.43 raeburn 20040: } else {
1.54 raeburn 20041: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 20042: }
20043: } else {
20044: $resulttext = '<span class="LC_error">'.
20045: &mt('An error occurred: [_1]',$putresult).'</span>';
20046: }
20047: if (@errors > 0) {
20048: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
20049: foreach my $item (@errors) {
20050: $resulttext .= ' "'.$title->{$item}.'",';
20051: }
20052: $resulttext =~ s/,$//;
20053: }
20054: return $resulttext;
20055: }
20056:
1.46 raeburn 20057: sub modify_scantron {
1.205 raeburn 20058: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 20059: my ($resulttext,%confhash,%changes,$errors);
20060: my $custom = 'custom.tab';
20061: my $default = 'default.tab';
20062: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 20063: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 20064: &config_check($dom,$confname,$servadm);
20065: if ($env{'form.scantronformat.filename'} ne '') {
20066: my $error;
20067: if ($configuserok eq 'ok') {
20068: if ($switchserver) {
1.130 raeburn 20069: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 20070: } else {
20071: if ($author_ok eq 'ok') {
1.421 raeburn 20072: my $modified = [];
1.46 raeburn 20073: my ($result,$scantronurl) =
1.421 raeburn 20074: &Apache::lonconfigsettings::publishlogo($r,'upload','scantronformat',$dom,
20075: $confname,'scantron','','',$custom,
20076: $modified);
1.46 raeburn 20077: if ($result eq 'ok') {
20078: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 20079: $changes{'scantronformat'} = 1;
1.421 raeburn 20080: &update_modify_urls($r,$modified);
1.46 raeburn 20081: } else {
20082: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
20083: }
20084: } else {
20085: $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);
20086: }
20087: }
20088: } else {
20089: $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);
20090: }
20091: if ($error) {
20092: &Apache::lonnet::logthis($error);
20093: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
20094: }
20095: }
1.48 raeburn 20096: if (ref($domconfig{'scantron'}) eq 'HASH') {
20097: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
20098: if ($env{'form.scantronformat_del'}) {
20099: $confhash{'scantron'}{'scantronformat'} = '';
20100: $changes{'scantronformat'} = 1;
1.347 raeburn 20101: } else {
20102: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 20103: }
20104: }
20105: }
1.347 raeburn 20106: my @options = ('hdr','pad','rem');
1.346 raeburn 20107: my @fields = &scantroncsv_fields();
20108: my %titles = &scantronconfig_titles();
1.347 raeburn 20109: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 20110: my ($newdat,$currdat,%newcol,%currcol);
20111: if (grep(/^dat$/,@formats)) {
20112: $confhash{'scantron'}{config}{dat} = 1;
20113: $newdat = 1;
20114: } else {
20115: $newdat = 0;
20116: }
20117: if (grep(/^csv$/,@formats)) {
20118: my %bynum;
20119: foreach my $field (@fields) {
20120: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
20121: my $posscol = $1;
20122: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 20123: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 20124: $bynum{$posscol} = $field;
20125: $newcol{$field} = $posscol;
20126: }
20127: }
20128: }
1.347 raeburn 20129: if (keys(%newcol)) {
20130: foreach my $option (@options) {
20131: if ($env{'form.scantroncsv_'.$option}) {
20132: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
20133: }
20134: }
20135: }
1.346 raeburn 20136: }
20137: $currdat = 1;
20138: if (ref($domconfig{'scantron'}) eq 'HASH') {
20139: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 20140: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 20141: $currdat = 0;
20142: }
20143: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20144: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20145: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
20146: }
1.346 raeburn 20147: }
20148: }
20149: }
20150: if ($currdat != $newdat) {
20151: $changes{'config'} = 1;
20152: } else {
20153: foreach my $field (@fields) {
20154: if ($currcol{$field} ne '') {
20155: if ($currcol{$field} ne $newcol{$field}) {
20156: $changes{'config'} = 1;
20157: last;
1.347 raeburn 20158: }
1.346 raeburn 20159: } elsif ($newcol{$field} ne '') {
20160: $changes{'config'} = 1;
20161: last;
20162: }
20163: }
20164: }
1.46 raeburn 20165: if (keys(%confhash) > 0) {
20166: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
20167: $dom);
20168: if ($putresult eq 'ok') {
20169: if (keys(%changes) > 0) {
1.48 raeburn 20170: if (ref($confhash{'scantron'}) eq 'HASH') {
20171: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 20172: if ($changes{'scantronformat'}) {
20173: if ($confhash{'scantron'}{'scantronformat'} eq '') {
20174: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
20175: } else {
20176: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
20177: }
20178: }
1.347 raeburn 20179: if ($changes{'config'}) {
1.346 raeburn 20180: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
20181: if ($confhash{'scantron'}{'config'}{'dat'}) {
20182: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
20183: }
20184: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20185: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20186: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
20187: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
20188: foreach my $field (@fields) {
20189: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
20190: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
20191: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
20192: }
20193: }
20194: $resulttext .= '</ul></li>';
20195: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
20196: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
20197: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
20198: foreach my $option (@options) {
20199: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
20200: $resulttext .= '<li>'.$titles{$option}.'</li>';
20201: }
20202: }
20203: $resulttext .= '</ul></li>';
20204: }
1.346 raeburn 20205: }
20206: }
20207: }
20208: }
20209: } else {
20210: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
20211: }
1.46 raeburn 20212: }
1.48 raeburn 20213: $resulttext .= '</ul>';
20214: } else {
1.130 raeburn 20215: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 20216: }
20217: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 20218: if (ref($lastactref) eq 'HASH') {
20219: $lastactref->{'domainconfig'} = 1;
20220: }
1.46 raeburn 20221: } else {
1.346 raeburn 20222: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 20223: }
20224: } else {
20225: $resulttext = '<span class="LC_error">'.
20226: &mt('An error occurred: [_1]',$putresult).'</span>';
20227: }
20228: } else {
1.130 raeburn 20229: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 20230: }
20231: if ($errors) {
1.353 raeburn 20232: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
20233: $errors.'</ul></p>';
1.46 raeburn 20234: }
20235: return $resulttext;
20236: }
20237:
1.48 raeburn 20238: sub modify_coursecategories {
1.239 raeburn 20239: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 20240: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
20241: $cathash);
1.48 raeburn 20242: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 20243: my @catitems = ('unauth','auth');
20244: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 20245: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 20246: $cathash = $domconfig{'coursecategories'}{'cats'};
20247: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
20248: $changes{'togglecats'} = 1;
20249: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
20250: }
20251: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
20252: $changes{'categorize'} = 1;
20253: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
20254: }
1.120 raeburn 20255: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
20256: $changes{'togglecatscomm'} = 1;
20257: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
20258: }
20259: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
20260: $changes{'categorizecomm'} = 1;
20261: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 20262:
20263: }
20264: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
20265: $changes{'togglecatsplace'} = 1;
20266: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
20267: }
20268: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
20269: $changes{'categorizeplace'} = 1;
20270: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 20271: }
1.238 raeburn 20272: foreach my $item (@catitems) {
20273: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20274: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
20275: $changes{$item} = 1;
20276: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20277: }
20278: }
20279: }
1.57 raeburn 20280: } else {
20281: $changes{'togglecats'} = 1;
20282: $changes{'categorize'} = 1;
1.124 raeburn 20283: $changes{'togglecatscomm'} = 1;
20284: $changes{'categorizecomm'} = 1;
1.272 raeburn 20285: $changes{'togglecatsplace'} = 1;
20286: $changes{'categorizeplace'} = 1;
1.87 raeburn 20287: $domconfig{'coursecategories'} = {
20288: togglecats => $env{'form.togglecats'},
20289: categorize => $env{'form.categorize'},
1.124 raeburn 20290: togglecatscomm => $env{'form.togglecatscomm'},
20291: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 20292: togglecatsplace => $env{'form.togglecatsplace'},
20293: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 20294: };
1.238 raeburn 20295: foreach my $item (@catitems) {
20296: if ($env{'form.coursecat_'.$item} ne 'std') {
20297: $changes{$item} = 1;
20298: }
20299: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20300: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20301: }
20302: }
1.57 raeburn 20303: }
20304: if (ref($cathash) eq 'HASH') {
20305: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 20306: push (@deletecategory,'instcode::0');
20307: }
1.120 raeburn 20308: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
20309: push(@deletecategory,'communities::0');
20310: }
1.272 raeburn 20311: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
20312: push(@deletecategory,'placement::0');
20313: }
1.48 raeburn 20314: }
1.57 raeburn 20315: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
20316: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20317: if (@deletecategory > 0) {
20318: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 20319: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 20320: foreach my $item (@deletecategory) {
1.57 raeburn 20321: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
20322: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 20323: $deletions{$item} = 1;
1.57 raeburn 20324: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 20325: }
20326: }
20327: }
1.57 raeburn 20328: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 20329: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 20330: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 20331: $reorderings{$item} = 1;
1.57 raeburn 20332: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 20333: }
20334: if ($env{'form.addcategory_name_'.$item} ne '') {
20335: my $newcat = $env{'form.addcategory_name_'.$item};
20336: my $newdepth = $depth+1;
20337: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20338: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 20339: $adds{$newitem} = 1;
20340: }
20341: if ($env{'form.subcat_'.$item} ne '') {
20342: my $newcat = $env{'form.subcat_'.$item};
20343: my $newdepth = $depth+1;
20344: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20345: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 20346: $adds{$newitem} = 1;
20347: }
20348: }
20349: }
20350: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 20351: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20352: my $newitem = 'instcode::0';
1.57 raeburn 20353: if ($cathash->{$newitem} eq '') {
20354: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20355: $adds{$newitem} = 1;
20356: }
20357: } else {
20358: my $newitem = 'instcode::0';
1.57 raeburn 20359: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20360: $adds{$newitem} = 1;
20361: }
20362: }
1.120 raeburn 20363: if ($env{'form.communities'} eq '1') {
20364: if (ref($cathash) eq 'HASH') {
20365: my $newitem = 'communities::0';
20366: if ($cathash->{$newitem} eq '') {
20367: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20368: $adds{$newitem} = 1;
20369: }
20370: } else {
20371: my $newitem = 'communities::0';
20372: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20373: $adds{$newitem} = 1;
20374: }
20375: }
1.272 raeburn 20376: if ($env{'form.placement'} eq '1') {
20377: if (ref($cathash) eq 'HASH') {
20378: my $newitem = 'placement::0';
20379: if ($cathash->{$newitem} eq '') {
20380: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20381: $adds{$newitem} = 1;
20382: }
20383: } else {
20384: my $newitem = 'placement::0';
20385: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20386: $adds{$newitem} = 1;
20387: }
20388: }
1.48 raeburn 20389: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 20390: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 20391: ($env{'form.addcategory_name'} ne 'communities') &&
20392: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 20393: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
20394: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
20395: $adds{$newitem} = 1;
20396: }
1.48 raeburn 20397: }
1.57 raeburn 20398: my $putresult;
1.48 raeburn 20399: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20400: if (keys(%deletions) > 0) {
20401: foreach my $key (keys(%deletions)) {
20402: if ($predelallitems{$key} ne '') {
20403: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
20404: }
20405: }
20406: }
20407: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 20408: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 20409: if (ref($chkcats[0]) eq 'ARRAY') {
20410: my $depth = 0;
20411: my $chg = 0;
20412: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
20413: my $name = $chkcats[0][$i];
20414: my $item;
20415: if ($name eq '') {
20416: $chg ++;
20417: } else {
20418: $item = &escape($name).'::0';
20419: if ($chg) {
1.57 raeburn 20420: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 20421: }
20422: $depth ++;
1.57 raeburn 20423: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 20424: $depth --;
20425: }
20426: }
20427: }
1.57 raeburn 20428: }
20429: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20430: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 20431: if ($putresult eq 'ok') {
1.57 raeburn 20432: my %title = (
1.120 raeburn 20433: togglecats => 'Show/Hide a course in catalog',
20434: categorize => 'Assign a category to a course',
20435: togglecatscomm => 'Show/Hide a community in catalog',
20436: categorizecomm => 'Assign a category to a community',
1.57 raeburn 20437: );
20438: my %level = (
1.120 raeburn 20439: dom => 'set in Domain ("Modify Course/Community")',
20440: crs => 'set in Course ("Course Configuration")',
20441: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 20442: none => 'No catalog',
20443: std => 'Standard catalog',
20444: domonly => 'Domain-only catalog',
20445: codesrch => 'Code search form',
1.57 raeburn 20446: );
1.48 raeburn 20447: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 20448: if ($changes{'togglecats'}) {
20449: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
20450: }
20451: if ($changes{'categorize'}) {
20452: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 20453: }
1.120 raeburn 20454: if ($changes{'togglecatscomm'}) {
20455: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
20456: }
20457: if ($changes{'categorizecomm'}) {
20458: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
20459: }
1.238 raeburn 20460: if ($changes{'unauth'}) {
20461: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
20462: }
20463: if ($changes{'auth'}) {
20464: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
20465: }
1.57 raeburn 20466: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20467: my $cathash;
20468: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
20469: $cathash = $domconfig{'coursecategories'}{'cats'};
20470: } else {
20471: $cathash = {};
20472: }
20473: my (@cats,@trails,%allitems);
20474: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
20475: if (keys(%deletions) > 0) {
20476: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
20477: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
20478: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
20479: }
20480: $resulttext .= '</ul></li>';
20481: }
20482: if (keys(%reorderings) > 0) {
20483: my %sort_by_trail;
20484: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
20485: foreach my $key (keys(%reorderings)) {
20486: if ($allitems{$key} ne '') {
20487: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20488: }
1.48 raeburn 20489: }
1.57 raeburn 20490: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20491: $resulttext .= '<li>'.$trails[$trail].'</li>';
20492: }
20493: $resulttext .= '</ul></li>';
1.48 raeburn 20494: }
1.57 raeburn 20495: if (keys(%adds) > 0) {
20496: my %sort_by_trail;
20497: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
20498: foreach my $key (keys(%adds)) {
20499: if ($allitems{$key} ne '') {
20500: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20501: }
20502: }
20503: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20504: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 20505: }
1.57 raeburn 20506: $resulttext .= '</ul></li>';
1.48 raeburn 20507: }
1.364 raeburn 20508: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
20509: if (ref($lastactref) eq 'HASH') {
20510: $lastactref->{'cats'} = 1;
20511: }
1.48 raeburn 20512: }
20513: $resulttext .= '</ul>';
1.239 raeburn 20514: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 20515: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
20516: if ($changes{'auth'}) {
20517: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
20518: }
20519: if ($changes{'unauth'}) {
20520: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
20521: }
20522: my $cachetime = 24*60*60;
20523: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 20524: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 20525: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 20526: }
20527: }
1.48 raeburn 20528: } else {
20529: $resulttext = '<span class="LC_error">'.
1.57 raeburn 20530: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 20531: }
20532: } else {
1.120 raeburn 20533: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 20534: }
20535: return $resulttext;
20536: }
20537:
1.69 raeburn 20538: sub modify_serverstatuses {
20539: my ($dom,%domconfig) = @_;
20540: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
20541: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
20542: %currserverstatus = %{$domconfig{'serverstatuses'}};
20543: }
20544: my @pages = &serverstatus_pages();
20545: foreach my $type (@pages) {
20546: $newserverstatus{$type}{'namedusers'} = '';
20547: $newserverstatus{$type}{'machines'} = '';
20548: if (defined($env{'form.'.$type.'_namedusers'})) {
20549: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
20550: my @okusers;
20551: foreach my $user (@users) {
20552: my ($uname,$udom) = split(/:/,$user);
20553: if (($udom =~ /^$match_domain$/) &&
20554: (&Apache::lonnet::domain($udom)) &&
20555: ($uname =~ /^$match_username$/)) {
20556: if (!grep(/^\Q$user\E/,@okusers)) {
20557: push(@okusers,$user);
20558: }
20559: }
20560: }
20561: if (@okusers > 0) {
20562: @okusers = sort(@okusers);
20563: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
20564: }
20565: }
20566: if (defined($env{'form.'.$type.'_machines'})) {
20567: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
20568: my @okmachines;
20569: foreach my $ip (@machines) {
20570: my @parts = split(/\./,$ip);
20571: next if (@parts < 4);
20572: my $badip = 0;
20573: for (my $i=0; $i<4; $i++) {
20574: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
20575: $badip = 1;
20576: last;
20577: }
20578: }
20579: if (!$badip) {
20580: push(@okmachines,$ip);
20581: }
20582: }
20583: @okmachines = sort(@okmachines);
20584: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
20585: }
20586: }
20587: my %serverstatushash = (
20588: serverstatuses => \%newserverstatus,
20589: );
20590: foreach my $type (@pages) {
1.83 raeburn 20591: foreach my $setting ('namedusers','machines') {
1.84 raeburn 20592: my (@current,@new);
1.83 raeburn 20593: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 20594: if ($currserverstatus{$type}{$setting} ne '') {
20595: @current = split(/,/,$currserverstatus{$type}{$setting});
20596: }
20597: }
20598: if ($newserverstatus{$type}{$setting} ne '') {
20599: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 20600: }
20601: if (@current > 0) {
20602: if (@new > 0) {
20603: foreach my $item (@current) {
20604: if (!grep(/^\Q$item\E$/,@new)) {
20605: $changes{$type}{$setting} = 1;
1.82 raeburn 20606: last;
20607: }
20608: }
1.84 raeburn 20609: foreach my $item (@new) {
20610: if (!grep(/^\Q$item\E$/,@current)) {
20611: $changes{$type}{$setting} = 1;
20612: last;
1.82 raeburn 20613: }
20614: }
20615: } else {
1.83 raeburn 20616: $changes{$type}{$setting} = 1;
1.69 raeburn 20617: }
1.83 raeburn 20618: } elsif (@new > 0) {
20619: $changes{$type}{$setting} = 1;
1.69 raeburn 20620: }
20621: }
20622: }
20623: if (keys(%changes) > 0) {
1.81 raeburn 20624: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 20625: my $putresult = &Apache::lonnet::put_dom('configuration',
20626: \%serverstatushash,$dom);
20627: if ($putresult eq 'ok') {
20628: $resulttext .= &mt('Changes made:').'<ul>';
20629: foreach my $type (@pages) {
1.84 raeburn 20630: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 20631: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 20632: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 20633: if ($newserverstatus{$type}{'namedusers'} eq '') {
20634: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
20635: } else {
20636: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
20637: }
1.84 raeburn 20638: }
20639: if ($changes{$type}{'machines'}) {
1.69 raeburn 20640: if ($newserverstatus{$type}{'machines'} eq '') {
20641: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
20642: } else {
20643: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
20644: }
20645:
20646: }
20647: $resulttext .= '</ul></li>';
20648: }
20649: }
20650: $resulttext .= '</ul>';
20651: } else {
20652: $resulttext = '<span class="LC_error">'.
20653: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
20654:
20655: }
20656: } else {
20657: $resulttext = &mt('No changes made to access to server status pages');
20658: }
20659: return $resulttext;
20660: }
20661:
1.118 jms 20662: sub modify_helpsettings {
1.285 raeburn 20663: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 20664: my ($resulttext,$errors,%changes,%helphash);
20665: my %defaultchecked = ('submitbugs' => 'on');
20666: my @offon = ('off','on');
1.118 jms 20667: my @toggles = ('submitbugs');
1.285 raeburn 20668: my %current = ('submitbugs' => '',
20669: 'adhoc' => {},
20670: );
1.118 jms 20671: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 20672: %current = %{$domconfig{'helpsettings'}};
20673: }
1.285 raeburn 20674: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 20675: foreach my $item (@toggles) {
20676: if ($defaultchecked{$item} eq 'on') {
20677: if ($current{$item} eq '') {
20678: if ($env{'form.'.$item} eq '0') {
20679: $changes{$item} = 1;
20680: }
20681: } elsif ($current{$item} ne $env{'form.'.$item}) {
20682: $changes{$item} = 1;
20683: }
20684: } elsif ($defaultchecked{$item} eq 'off') {
20685: if ($current{$item} eq '') {
20686: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 20687: $changes{$item} = 1;
20688: }
1.282 raeburn 20689: } elsif ($current{$item} ne $env{'form.'.$item}) {
20690: $changes{$item} = 1;
20691: }
20692: }
20693: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
20694: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
20695: }
20696: }
1.285 raeburn 20697: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 20698: my $confname = $dom.'-domainconfig';
20699: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 20700: my (@allpos,%newsettings,%changedprivs,$newrole);
20701: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 20702: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 20703: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 20704: my %lt = &Apache::lonlocal::texthash(
20705: s => 'system',
20706: d => 'domain',
20707: order => 'Display order',
20708: access => 'Role usage',
1.291 raeburn 20709: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 20710: dh => 'All with domain helpdesk role',
20711: da => 'All with domain helpdesk assistant role',
1.285 raeburn 20712: none => 'None',
20713: status => 'Determined based on institutional status',
20714: inc => 'Include all, but exclude specific personnel',
20715: exc => 'Exclude all, but include specific personnel',
20716: );
20717: for (my $num=0; $num<=$maxnum; $num++) {
20718: my ($prefix,$identifier,$rolename,%curr);
20719: if ($num == $maxnum) {
20720: next unless ($env{'form.newcusthelp'} == $maxnum);
20721: $identifier = 'custhelp'.$num;
20722: $prefix = 'helproles_'.$num;
20723: $rolename = $env{'form.custhelpname'.$num};
20724: $rolename=~s/[^A-Za-z0-9]//gs;
20725: next if ($rolename eq '');
20726: next if (exists($existing{'rolesdef_'.$rolename}));
20727: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
20728: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
20729: $newprivs{'c'},$confname,$dom);
20730: if ($result ne 'ok') {
20731: $errors .= '<li><span class="LC_error">'.
20732: &mt('An error occurred storing the new custom role: [_1]',
20733: $result).'</span></li>';
20734: next;
20735: } else {
20736: $changedprivs{$rolename} = \%newprivs;
20737: $newrole = $rolename;
20738: }
20739: } else {
20740: $prefix = 'helproles_'.$num;
20741: $rolename = $env{'form.'.$prefix};
20742: next if ($rolename eq '');
20743: next unless (exists($existing{'rolesdef_'.$rolename}));
20744: $identifier = 'custhelp'.$num;
20745: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
20746: my %currprivs;
1.289 raeburn 20747: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 20748: split(/\_/,$existing{'rolesdef_'.$rolename});
20749: foreach my $level ('c','d','s') {
20750: if ($newprivs{$level} ne $currprivs{$level}) {
20751: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
20752: $newprivs{'c'},$confname,$dom);
20753: if ($result ne 'ok') {
20754: $errors .= '<li><span class="LC_error">'.
20755: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
20756: $rolename,$result).'</span></li>';
20757: } else {
20758: $changedprivs{$rolename} = \%newprivs;
20759: }
20760: last;
20761: }
20762: }
20763: if (ref($current{'adhoc'}) eq 'HASH') {
20764: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
20765: %curr = %{$current{'adhoc'}{$rolename}};
20766: }
20767: }
20768: }
20769: my $newpos = $env{'form.'.$prefix.'_pos'};
20770: $newpos =~ s/\D+//g;
20771: $allpos[$newpos] = $rolename;
20772: my $newdesc = $env{'form.'.$prefix.'_desc'};
20773: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
20774: if ($curr{'desc'}) {
20775: if ($curr{'desc'} ne $newdesc) {
20776: $changes{'customrole'}{$rolename}{'desc'} = 1;
20777: $newsettings{$rolename}{'desc'} = $newdesc;
20778: }
20779: } elsif ($newdesc ne '') {
20780: $changes{'customrole'}{$rolename}{'desc'} = 1;
20781: $newsettings{$rolename}{'desc'} = $newdesc;
20782: }
20783: my $access = $env{'form.'.$prefix.'_access'};
20784: if (grep(/^\Q$access\E$/,@accesstypes)) {
20785: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
20786: if ($access eq 'status') {
20787: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
20788: if (scalar(@statuses) == 0) {
1.289 raeburn 20789: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 20790: } else {
20791: my (@shownstatus,$numtypes);
20792: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
20793: if (ref($types) eq 'ARRAY') {
20794: $numtypes = scalar(@{$types});
20795: foreach my $type (sort(@statuses)) {
20796: if ($type eq 'default') {
20797: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
20798: } elsif (grep(/^\Q$type\E$/,@{$types})) {
20799: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
20800: push(@shownstatus,$usertypes->{$type});
20801: }
20802: }
20803: }
20804: if (grep(/^default$/,@statuses)) {
20805: push(@shownstatus,$othertitle);
20806: }
20807: if (scalar(@shownstatus) == 1+$numtypes) {
20808: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
20809: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
20810: } else {
20811: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
20812: if (ref($curr{'status'}) eq 'ARRAY') {
20813: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
20814: if (@diffs) {
20815: $changes{'customrole'}{$rolename}{$access} = 1;
20816: }
20817: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
20818: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 20819: }
1.166 raeburn 20820: }
20821: }
1.285 raeburn 20822: } elsif (($access eq 'inc') || ($access eq 'exc')) {
20823: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
20824: my @newspecstaff;
20825: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
20826: foreach my $person (sort(@personnel)) {
20827: if ($domhelpdesk{$person}) {
20828: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
20829: }
20830: }
20831: if (ref($curr{$access}) eq 'ARRAY') {
20832: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
20833: if (@diffs) {
20834: $changes{'customrole'}{$rolename}{$access} = 1;
20835: }
20836: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
20837: $changes{'customrole'}{$rolename}{$access} = 1;
20838: }
20839: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
20840: my ($uname,$udom) = split(/:/,$person);
20841: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
20842: }
20843: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 20844: }
1.285 raeburn 20845: } else {
20846: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
20847: }
20848: unless ($curr{'access'} eq $access) {
20849: $changes{'customrole'}{$rolename}{'access'} = 1;
20850: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 20851: }
20852: }
1.285 raeburn 20853: if (@allpos > 0) {
20854: my $idx = 0;
20855: foreach my $rolename (@allpos) {
20856: if ($rolename ne '') {
20857: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
20858: if (ref($current{'adhoc'}) eq 'HASH') {
20859: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
20860: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
20861: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 20862: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 20863: }
20864: }
1.282 raeburn 20865: }
1.285 raeburn 20866: $idx ++;
1.166 raeburn 20867: }
20868: }
1.118 jms 20869: }
1.123 jms 20870: my $putresult;
20871: if (keys(%changes) > 0) {
1.166 raeburn 20872: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 20873: if ($putresult eq 'ok') {
1.285 raeburn 20874: if (ref($helphash{'helpsettings'}) eq 'HASH') {
20875: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
20876: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
20877: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
20878: }
20879: }
20880: my $cachetime = 24*60*60;
20881: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
20882: if (ref($lastactref) eq 'HASH') {
20883: $lastactref->{'domdefaults'} = 1;
20884: }
20885: } else {
20886: $errors .= '<li><span class="LC_error">'.
20887: &mt('An error occurred storing the settings: [_1]',
20888: $putresult).'</span></li>';
20889: }
20890: }
20891: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
20892: $resulttext = &mt('Changes made:').'<ul>';
20893: my (%shownprivs,@levelorder);
20894: @levelorder = ('c','d','s');
20895: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 20896: foreach my $item (sort(keys(%changes))) {
20897: if ($item eq 'submitbugs') {
20898: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
20899: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
20900: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 20901: } elsif ($item eq 'customrole') {
20902: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 20903: my @keyorder = ('order','desc','access','status','exc','inc');
20904: my %keytext = &Apache::lonlocal::texthash(
20905: order => 'Order',
20906: desc => 'Role description',
20907: access => 'Role usage',
1.300 droeschl 20908: status => 'Allowed institutional types',
1.285 raeburn 20909: exc => 'Allowed personnel',
20910: inc => 'Disallowed personnel',
20911: );
1.282 raeburn 20912: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 20913: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
20914: if ($role eq $newrole) {
20915: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
20916: $role).'<ul>';
20917: } else {
20918: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
20919: $role).'<ul>';
20920: }
20921: foreach my $key (@keyorder) {
20922: if ($changes{'customrole'}{$role}{$key}) {
20923: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
20924: $keytext{$key},$newsettings{$role}{$key}).
20925: '</li>';
20926: }
20927: }
20928: if (ref($changedprivs{$role}) eq 'HASH') {
20929: $shownprivs{$role} = 1;
20930: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
20931: foreach my $level (@levelorder) {
20932: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
20933: next if ($item eq '');
20934: my ($priv) = split(/\&/,$item,2);
20935: if (&Apache::lonnet::plaintext($priv)) {
20936: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
20937: unless ($level eq 'c') {
20938: $resulttext .= ' ('.$lt{$level}.')';
20939: }
20940: $resulttext .= '</li>';
20941: }
20942: }
20943: }
20944: $resulttext .= '</ul>';
20945: }
20946: $resulttext .= '</ul></li>';
20947: }
20948: }
20949: }
20950: }
20951: }
20952: }
20953: if (keys(%changedprivs)) {
20954: foreach my $role (sort(keys(%changedprivs))) {
20955: unless ($shownprivs{$role}) {
20956: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
20957: $role).'<ul>'.
20958: '<li>'.&mt('Privileges set to :').'<ul>';
20959: foreach my $level (@levelorder) {
20960: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
20961: next if ($item eq '');
20962: my ($priv) = split(/\&/,$item,2);
20963: if (&Apache::lonnet::plaintext($priv)) {
20964: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
20965: unless ($level eq 'c') {
20966: $resulttext .= ' ('.$lt{$level}.')';
20967: }
20968: $resulttext .= '</li>';
20969: }
1.282 raeburn 20970: }
20971: }
1.285 raeburn 20972: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 20973: }
20974: }
20975: }
1.285 raeburn 20976: $resulttext .= '</ul>';
20977: } else {
20978: $resulttext = &mt('No changes made to help settings');
1.118 jms 20979: }
20980: if ($errors) {
1.168 raeburn 20981: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 20982: $errors.'</ul>';
1.118 jms 20983: }
20984: return $resulttext;
20985: }
20986:
1.121 raeburn 20987: sub modify_coursedefaults {
1.212 raeburn 20988: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 20989: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 20990: my %defaultchecked = (
20991: 'canuse_pdfforms' => 'off',
20992: 'uselcmath' => 'on',
1.398 raeburn 20993: 'usejsme' => 'on',
20994: 'inline_chem' => 'on',
1.404 raeburn 20995: 'ltiauth' => 'off',
1.257 raeburn 20996: );
1.404 raeburn 20997: my @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem','ltiauth');
1.198 raeburn 20998: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 20999: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
1.428 raeburn 21000: 'coursequota_official','coursequota_unofficial','coursequota_community',
21001: 'coursequota_textbook','coursequota_placement','mysqltables_official',
21002: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook',
21003: 'mysqltables_placement');
1.271 raeburn 21004: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 21005: my %staticdefaults = (
21006: anonsurvey_threshold => 10,
21007: uploadquota => 500,
1.428 raeburn 21008: coursequota => 20,
1.257 raeburn 21009: postsubmit => 60,
1.276 raeburn 21010: mysqltables => 172800,
1.422 raeburn 21011: domexttool => 1,
1.198 raeburn 21012: );
1.314 raeburn 21013: my %texoptions = (
21014: MathJax => 'MathJax',
21015: mimetex => &mt('Convert to Images'),
21016: tth => &mt('TeX to HTML'),
21017: );
1.121 raeburn 21018: $defaultshash{'coursedefaults'} = {};
21019:
21020: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
21021: if ($domconfig{'coursedefaults'} eq '') {
21022: $domconfig{'coursedefaults'} = {};
21023: }
21024: }
21025:
21026: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
21027: foreach my $item (@toggles) {
21028: if ($defaultchecked{$item} eq 'on') {
21029: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21030: ($env{'form.'.$item} eq '0')) {
21031: $changes{$item} = 1;
1.192 raeburn 21032: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 21033: $changes{$item} = 1;
21034: }
21035: } elsif ($defaultchecked{$item} eq 'off') {
21036: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21037: ($env{'form.'.$item} eq '1')) {
21038: $changes{$item} = 1;
21039: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
21040: $changes{$item} = 1;
21041: }
21042: }
21043: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
21044: }
1.198 raeburn 21045: foreach my $item (@numbers) {
21046: my ($currdef,$newdef);
1.208 raeburn 21047: $newdef = $env{'form.'.$item};
1.198 raeburn 21048: if ($item eq 'anonsurvey_threshold') {
21049: $currdef = $domconfig{'coursedefaults'}{$item};
21050: $newdef =~ s/\D//g;
21051: if ($newdef eq '' || $newdef < 1) {
21052: $newdef = 1;
21053: }
21054: $defaultshash{'coursedefaults'}{$item} = $newdef;
21055: } else {
1.428 raeburn 21056: my ($setting,$type) = ($item =~ /^(uploadquota|coursequota|mysqltables)_(\w+)$/);
1.276 raeburn 21057: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
21058: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 21059: }
21060: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 21061: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 21062: }
21063: if ($currdef ne $newdef) {
21064: if ($item eq 'anonsurvey_threshold') {
21065: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
21066: $changes{$item} = 1;
21067: }
1.428 raeburn 21068: } elsif ($item =~ /^(uploadquota|coursequota|mysqltables)_/) {
1.289 raeburn 21069: my $setting = $1;
1.276 raeburn 21070: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
21071: $changes{$setting} = 1;
1.198 raeburn 21072: }
21073: }
1.139 raeburn 21074: }
21075: }
1.314 raeburn 21076: my $texengine;
21077: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
21078: $texengine = $env{'form.texengine'};
1.349 raeburn 21079: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
21080: if ($currdef eq '') {
21081: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 21082: $changes{'texengine'} = 1;
21083: }
1.349 raeburn 21084: } elsif ($currdef ne $texengine) {
1.314 raeburn 21085: $changes{'texengine'} = 1;
21086: }
21087: }
21088: if ($texengine ne '') {
21089: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
21090: }
1.264 raeburn 21091: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
21092: my @currclonecode;
21093: if (ref($currclone) eq 'HASH') {
21094: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
21095: @currclonecode = @{$currclone->{'instcode'}};
21096: }
21097: }
21098: my $newclone;
1.289 raeburn 21099: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 21100: $newclone = $env{'form.canclone'};
21101: }
21102: if ($newclone eq 'instcode') {
21103: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
21104: my (%codedefaults,@code_order,@clonecode);
21105: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
21106: \@code_order);
21107: foreach my $item (@code_order) {
21108: if (grep(/^\Q$item\E$/,@newcodes)) {
21109: push(@clonecode,$item);
21110: }
21111: }
21112: if (@clonecode) {
21113: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
21114: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
21115: if (@diffs) {
21116: $changes{'canclone'} = 1;
21117: }
21118: } else {
21119: $newclone eq '';
21120: }
21121: } elsif ($newclone ne '') {
1.289 raeburn 21122: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
21123: }
1.264 raeburn 21124: if ($newclone ne $currclone) {
21125: $changes{'canclone'} = 1;
21126: }
1.257 raeburn 21127: my %credits;
21128: foreach my $type (@types) {
21129: unless ($type eq 'community') {
21130: $credits{$type} = $env{'form.'.$type.'_credits'};
21131: $credits{$type} =~ s/[^\d.]+//g;
21132: }
21133: }
21134: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
21135: ($env{'form.coursecredits'} eq '1')) {
21136: $changes{'coursecredits'} = 1;
21137: foreach my $type (keys(%credits)) {
21138: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21139: }
21140: } else {
1.289 raeburn 21141: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 21142: foreach my $type (@types) {
21143: unless ($type eq 'community') {
1.289 raeburn 21144: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 21145: $changes{'coursecredits'} = 1;
21146: }
21147: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21148: }
21149: }
21150: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21151: foreach my $type (@types) {
21152: unless ($type eq 'community') {
21153: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
21154: $changes{'coursecredits'} = 1;
21155: last;
21156: }
21157: }
21158: }
21159: }
21160: }
21161: if ($env{'form.postsubmit'} eq '1') {
21162: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
21163: my %currtimeout;
21164: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21165: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
21166: $changes{'postsubmit'} = 1;
21167: }
21168: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21169: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
21170: }
21171: } else {
21172: $changes{'postsubmit'} = 1;
21173: }
21174: foreach my $type (@types) {
21175: my $timeout = $env{'form.'.$type.'_timeout'};
21176: $timeout =~ s/\D//g;
21177: if ($timeout == $staticdefaults{'postsubmit'}) {
21178: $timeout = '';
21179: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
21180: $timeout = '0';
21181: }
21182: unless ($timeout eq '') {
21183: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
21184: }
21185: if (exists($currtimeout{$type})) {
21186: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 21187: $changes{'postsubmit'} = 1;
1.257 raeburn 21188: }
21189: } elsif ($timeout ne '') {
21190: $changes{'postsubmit'} = 1;
21191: }
21192: }
21193: } else {
21194: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
21195: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21196: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
21197: $changes{'postsubmit'} = 1;
21198: }
21199: } else {
21200: $changes{'postsubmit'} = 1;
21201: }
1.192 raeburn 21202: }
1.422 raeburn 21203: my (%newdomexttool,%newexttool,%olddomexttool,%oldexttool);
21204: map { $newdomexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.domexttool');
1.425 raeburn 21205: map { $newexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.exttool');
1.422 raeburn 21206: if (ref($domconfig{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21207: %olddomexttool = %{$domconfig{'coursedefaults'}{'domexttool'}};
21208: } else {
21209: foreach my $type (@types) {
21210: if ($staticdefaults{'domexttool'}) {
21211: $olddomexttool{$type} = 1;
21212: } else {
21213: $olddomexttool{$type} = 0;
21214: }
21215: }
21216: }
21217: if (ref($domconfig{'coursedefaults'}{'exttool'}) eq 'HASH') {
1.425 raeburn 21218: %oldexttool = %{$domconfig{'coursedefaults'}{'exttool'}};
1.422 raeburn 21219: } else {
21220: foreach my $type (@types) {
21221: if ($staticdefaults{'exttool'}) {
21222: $oldexttool{$type} = 1;
21223: } else {
21224: $oldexttool{$type} = 0;
21225: }
21226: }
21227: }
21228: foreach my $type (@types) {
21229: unless ($newdomexttool{$type}) {
21230: $newdomexttool{$type} = 0;
21231: }
21232: unless ($newexttool{$type}) {
21233: $newexttool{$type} = 0;
21234: }
21235: if ($newdomexttool{$type} != $olddomexttool{$type}) {
21236: $changes{'domexttool'} = 1;
21237: }
21238: if ($newexttool{$type} != $oldexttool{$type}) {
21239: $changes{'exttool'} = 1;
21240: }
21241: }
21242: $defaultshash{'coursedefaults'}{'domexttool'} = \%newdomexttool;
21243: $defaultshash{'coursedefaults'}{'exttool'} = \%newexttool;
1.121 raeburn 21244: }
21245: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21246: $dom);
21247: if ($putresult eq 'ok') {
21248: if (keys(%changes) > 0) {
1.213 raeburn 21249: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 21250: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 21251: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.398 raeburn 21252: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
1.422 raeburn 21253: ($changes{'inline_chem'}) || ($changes{'ltiauth'}) || ($changes{'domexttool'}) ||
1.428 raeburn 21254: ($changes{'exttool'}) || ($changes{'coursequota'})) {
1.422 raeburn 21255: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','inline_chem','texengine',
21256: 'ltiauth') {
1.257 raeburn 21257: if ($changes{$item}) {
21258: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
21259: }
1.289 raeburn 21260: }
1.192 raeburn 21261: if ($changes{'coursecredits'}) {
21262: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 21263: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
21264: $domdefaults{$type.'credits'} =
21265: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
21266: }
21267: }
21268: }
21269: if ($changes{'postsubmit'}) {
21270: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21271: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
21272: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21273: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
21274: $domdefaults{$type.'postsubtimeout'} =
21275: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21276: }
21277: }
1.192 raeburn 21278: }
21279: }
1.198 raeburn 21280: if ($changes{'uploadquota'}) {
21281: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21282: foreach my $type (@types) {
21283: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
21284: }
21285: }
21286: }
1.428 raeburn 21287: if ($changes{'coursequota'}) {
21288: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
21289: foreach my $type (@types) {
21290: $domdefaults{$type.'coursequota'}=$defaultshash{'coursedefaults'}{'coursequota'}{$type};
21291: }
21292: }
21293: }
1.264 raeburn 21294: if ($changes{'canclone'}) {
21295: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21296: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21297: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
21298: if (@clonecodes) {
21299: $domdefaults{'canclone'} = join('+',@clonecodes);
21300: }
21301: }
21302: } else {
21303: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
21304: }
21305: }
1.422 raeburn 21306: if ($changes{'domexttool'}) {
21307: if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21308: foreach my $type (@types) {
21309: $domdefaults{$type.'domexttool'}=$defaultshash{'coursedefaults'}{'domexttool'}{$type};
21310: }
21311: }
21312: }
21313: if ($changes{'exttool'}) {
21314: if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
21315: foreach my $type (@types) {
21316: $domdefaults{$type.'exttool'}=$defaultshash{'coursedefaults'}{'exttool'}{$type};
21317: }
21318: }
21319: }
1.121 raeburn 21320: my $cachetime = 24*60*60;
21321: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 21322: if (ref($lastactref) eq 'HASH') {
21323: $lastactref->{'domdefaults'} = 1;
21324: }
1.121 raeburn 21325: }
21326: $resulttext = &mt('Changes made:').'<ul>';
21327: foreach my $item (sort(keys(%changes))) {
21328: if ($item eq 'canuse_pdfforms') {
21329: if ($env{'form.'.$item} eq '1') {
21330: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
21331: } else {
21332: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
21333: }
1.257 raeburn 21334: } elsif ($item eq 'uselcmath') {
21335: if ($env{'form.'.$item} eq '1') {
21336: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
21337: } else {
21338: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
21339: }
21340: } elsif ($item eq 'usejsme') {
21341: if ($env{'form.'.$item} eq '1') {
21342: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
21343: } else {
1.289 raeburn 21344: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 21345: }
1.398 raeburn 21346: } elsif ($item eq 'inline_chem') {
21347: if ($env{'form.'.$item} eq '1') {
21348: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
21349: } else {
21350: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
21351: }
1.314 raeburn 21352: } elsif ($item eq 'texengine') {
21353: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
21354: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
21355: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
21356: }
1.139 raeburn 21357: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 21358: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 21359: } elsif ($item eq 'uploadquota') {
21360: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21361: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
21362: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
21363: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 21364: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 21365: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 21366: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
21367: '</ul>'.
21368: '</li>';
21369: } else {
21370: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
21371: }
1.428 raeburn 21372: } elsif ($item eq 'coursequota') {
21373: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
21374: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course set as follows:').'<ul>'.
21375: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'official'}.'</b>').'</li>'.
21376: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'unofficial'}.'</b>').'</li>'.
21377: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'textbook'}.'</b>').'</li>'.
21378: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'placement'}.'</b>').'</li>'.
21379: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'community'}.'</b>').'</li>'.
21380: '</ul>'.
21381: '</li>';
21382: } else {
21383: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course remains default: [_1] MB',$staticdefaults{'coursequota'}).'</li>';
21384: }
1.276 raeburn 21385: } elsif ($item eq 'mysqltables') {
21386: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
21387: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
21388: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
21389: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
21390: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
21391: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
21392: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
21393: '</ul>'.
21394: '</li>';
21395: } else {
21396: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
21397: }
1.257 raeburn 21398: } elsif ($item eq 'postsubmit') {
21399: if ($domdefaults{'postsubmit'} eq 'off') {
21400: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
21401: } else {
21402: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 21403: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 21404: $resulttext .= &mt('durations:').'<ul>';
21405: foreach my $type (@types) {
21406: $resulttext .= '<li>';
21407: my $timeout;
21408: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21409: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21410: }
21411: my $display;
21412: if ($timeout eq '0') {
21413: $display = &mt('unlimited');
21414: } elsif ($timeout eq '') {
21415: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
21416: } else {
21417: $display = &mt('[quant,_1,second]',$timeout);
21418: }
21419: if ($type eq 'community') {
21420: $resulttext .= &mt('Communities');
21421: } elsif ($type eq 'official') {
21422: $resulttext .= &mt('Official courses');
21423: } elsif ($type eq 'unofficial') {
21424: $resulttext .= &mt('Unofficial courses');
21425: } elsif ($type eq 'textbook') {
21426: $resulttext .= &mt('Textbook courses');
1.271 raeburn 21427: } elsif ($type eq 'placement') {
21428: $resulttext .= &mt('Placement tests');
1.257 raeburn 21429: }
21430: $resulttext .= ' -- '.$display.'</li>';
21431: }
21432: $resulttext .= '</ul>';
21433: }
1.289 raeburn 21434: $resulttext .= '</li>';
1.257 raeburn 21435: }
1.192 raeburn 21436: } elsif ($item eq 'coursecredits') {
21437: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21438: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 21439: ($domdefaults{'unofficialcredits'} eq '') &&
21440: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 21441: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21442: } else {
21443: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
21444: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
21445: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 21446: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 21447: '</ul>'.
21448: '</li>';
21449: }
21450: } else {
21451: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21452: }
1.264 raeburn 21453: } elsif ($item eq 'canclone') {
21454: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21455: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21456: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
21457: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
21458: }
21459: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
21460: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
21461: } else {
1.289 raeburn 21462: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 21463: }
1.404 raeburn 21464: } elsif ($item eq 'ltiauth') {
21465: if ($env{'form.'.$item} eq '1') {
21466: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
21467: } else {
21468: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
21469: }
1.422 raeburn 21470: } elsif ($item eq 'domexttool') {
21471: my @noyes = (&mt('no'),&mt('yes'));
21472: if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21473: $resulttext .= '<li>'.&mt('External Tools defined in the domain may be used as follows:').'<ul>'.
21474: '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'official'}].'</b>').'</li>'.
21475: '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'unofficial'}].'</b>').'</li>'.
21476: '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'textbook'}].'</b>').'</li>'.
21477: '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'placement'}].'</b>').'</li>'.
21478: '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'community'}].'</b>').'</li>'.
21479: '</ul>'.
21480: '</li>';
21481: } else {
21482: $resulttext .= '<li>'.&mt('External Tools defined in the domain may be used in all course types, by default').'</li>';
21483: }
21484: } elsif ($item eq 'exttool') {
21485: my @noyes = (&mt('no'),&mt('yes'));
21486: if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
21487: $resulttext .= '<li>'.&mt('External Tools can be defined and configured in course containers as follows:').'<ul>'.
21488: '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'official'}].'</b>').'</li>'.
21489: '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'unofficial'}].'</b>').'</li>'.
21490: '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'textbook'}].'</b>').'</li>'.
21491: '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'placement'}].'</b>').'</li>'.
21492: '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'community'}].'</b>').'</li>'.
21493: '</ul>'.
21494: '</li>';
21495: } else {
21496: $resulttext .= '<li>'.&mt('External Tools can not be defined in any course types, by default').'</li>';
21497: }
1.140 raeburn 21498: }
1.121 raeburn 21499: }
21500: $resulttext .= '</ul>';
21501: } else {
21502: $resulttext = &mt('No changes made to course defaults');
21503: }
21504: } else {
21505: $resulttext = '<span class="LC_error">'.
21506: &mt('An error occurred: [_1]',$putresult).'</span>';
21507: }
21508: return $resulttext;
21509: }
21510:
1.231 raeburn 21511: sub modify_selfenrollment {
21512: my ($dom,$lastactref,%domconfig) = @_;
21513: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 21514: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 21515: my %titles = &tool_titles();
1.232 raeburn 21516: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
21517: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 21518: $ordered{'default'} = ['types','registered','approval','limit'];
21519:
21520: my (%roles,%shown,%toplevel);
21521: $roles{'0'} = &Apache::lonnet::plaintext('dc');
21522:
21523: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
21524: if ($domconfig{'selfenrollment'} eq '') {
21525: $domconfig{'selfenrollment'} = {};
21526: }
21527: }
21528: %toplevel = (
21529: admin => 'Configuration Rights',
21530: default => 'Default settings',
21531: validation => 'Validation of self-enrollment requests',
21532: );
1.233 raeburn 21533: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 21534:
21535: if (ref($ordered{'admin'}) eq 'ARRAY') {
21536: foreach my $item (@{$ordered{'admin'}}) {
21537: foreach my $type (@types) {
21538: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
21539: $selfenrollhash{'admin'}{$type}{$item} = 1;
21540: } else {
21541: $selfenrollhash{'admin'}{$type}{$item} = 0;
21542: }
21543: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
21544: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
21545: if ($selfenrollhash{'admin'}{$type}{$item} ne
21546: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
21547: push(@{$changes{'admin'}{$type}},$item);
21548: }
21549: } else {
21550: if (!$selfenrollhash{'admin'}{$type}{$item}) {
21551: push(@{$changes{'admin'}{$type}},$item);
21552: }
21553: }
21554: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
21555: push(@{$changes{'admin'}{$type}},$item);
21556: }
21557: }
21558: }
21559: }
21560:
21561: foreach my $item (@{$ordered{'default'}}) {
21562: foreach my $type (@types) {
21563: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
21564: if ($item eq 'types') {
21565: unless (($value eq 'all') || ($value eq 'dom')) {
21566: $value = '';
21567: }
21568: } elsif ($item eq 'registered') {
21569: unless ($value eq '1') {
21570: $value = 0;
21571: }
21572: } elsif ($item eq 'approval') {
21573: unless ($value =~ /^[012]$/) {
21574: $value = 0;
21575: }
21576: } else {
21577: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21578: $value = 'none';
21579: }
21580: }
21581: $selfenrollhash{'default'}{$type}{$item} = $value;
21582: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
21583: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21584: if ($selfenrollhash{'default'}{$type}{$item} ne
21585: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
21586: push(@{$changes{'default'}{$type}},$item);
21587: }
21588: } else {
21589: push(@{$changes{'default'}{$type}},$item);
21590: }
21591: } else {
21592: push(@{$changes{'default'}{$type}},$item);
21593: }
21594: if ($item eq 'limit') {
21595: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21596: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
21597: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
21598: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
21599: }
21600: } else {
21601: $selfenrollhash{'default'}{$type}{'cap'} = '';
21602: }
21603: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21604: if ($selfenrollhash{'default'}{$type}{'cap'} ne
21605: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
21606: push(@{$changes{'default'}{$type}},'cap');
21607: }
21608: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
21609: push(@{$changes{'default'}{$type}},'cap');
21610: }
21611: }
21612: }
21613: }
21614:
21615: foreach my $item (@{$itemsref}) {
21616: if ($item eq 'fields') {
21617: my @changed;
21618: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
21619: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
21620: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
21621: }
21622: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21623: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
21624: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
21625: $domconfig{'selfenrollment'}{'validation'}{$item});
21626: } else {
21627: @changed = @{$selfenrollhash{'validation'}{$item}};
21628: }
21629: } else {
21630: @changed = @{$selfenrollhash{'validation'}{$item}};
21631: }
21632: if (@changed) {
21633: if ($selfenrollhash{'validation'}{$item}) {
21634: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
21635: } else {
21636: $changes{'validation'}{$item} = &mt('None');
21637: }
21638: }
21639: } else {
21640: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
21641: if ($item eq 'markup') {
21642: if ($env{'form.selfenroll_validation_'.$item}) {
21643: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
21644: }
21645: }
21646: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21647: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
21648: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
21649: }
21650: }
21651: }
21652: }
21653:
21654: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
21655: $dom);
21656: if ($putresult eq 'ok') {
21657: if (keys(%changes) > 0) {
21658: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
21659: $resulttext = &mt('Changes made:').'<ul>';
21660: foreach my $key ('admin','default','validation') {
21661: if (ref($changes{$key}) eq 'HASH') {
21662: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
21663: if ($key eq 'validation') {
21664: foreach my $item (@{$itemsref}) {
21665: if (exists($changes{$key}{$item})) {
21666: if ($item eq 'markup') {
21667: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
21668: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
21669: } else {
21670: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
21671: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
21672: }
21673: }
21674: }
21675: } else {
21676: foreach my $type (@types) {
21677: if ($type eq 'community') {
21678: $roles{'1'} = &mt('Community personnel');
21679: } else {
21680: $roles{'1'} = &mt('Course personnel');
21681: }
21682: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 21683: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
21684: if ($key eq 'admin') {
21685: my @mgrdc = ();
21686: if (ref($ordered{$key}) eq 'ARRAY') {
21687: foreach my $item (@{$ordered{'admin'}}) {
21688: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
21689: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
21690: push(@mgrdc,$item);
21691: }
21692: }
21693: }
21694: if (@mgrdc) {
21695: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
21696: } else {
21697: delete($domdefaults{$type.'selfenrolladmdc'});
21698: }
21699: }
21700: } else {
21701: if (ref($ordered{$key}) eq 'ARRAY') {
21702: foreach my $item (@{$ordered{$key}}) {
21703: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
21704: $domdefaults{$type.'selfenroll'.$item} =
21705: $selfenrollhash{$key}{$type}{$item};
21706: }
21707: }
21708: }
21709: }
21710: }
1.231 raeburn 21711: $resulttext .= '<li>'.$titles{$type}.'<ul>';
21712: foreach my $item (@{$ordered{$key}}) {
21713: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
21714: $resulttext .= '<li>';
21715: if ($key eq 'admin') {
21716: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
21717: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
21718: } else {
21719: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
21720: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
21721: }
21722: $resulttext .= '</li>';
21723: }
21724: }
21725: $resulttext .= '</ul></li>';
21726: }
21727: }
21728: $resulttext .= '</ul></li>';
21729: }
21730: }
1.305 raeburn 21731: }
21732: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
21733: my $cachetime = 24*60*60;
21734: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21735: if (ref($lastactref) eq 'HASH') {
21736: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 21737: }
1.231 raeburn 21738: }
21739: $resulttext .= '</ul>';
21740: } else {
21741: $resulttext = &mt('No changes made to self-enrollment settings');
21742: }
21743: } else {
21744: $resulttext = '<span class="LC_error">'.
21745: &mt('An error occurred: [_1]',$putresult).'</span>';
21746: }
21747: return $resulttext;
21748: }
21749:
1.373 raeburn 21750: sub modify_wafproxy {
21751: my ($dom,$action,$lastactref,%domconfig) = @_;
21752: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 21753: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
21754: %wafproxy,%changes,%expirecache,%expiresaml);
1.373 raeburn 21755: foreach my $server (sort(keys(%servers))) {
21756: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
21757: if ($serverhome eq $server) {
21758: my $serverdom = &Apache::lonnet::host_domain($server);
21759: if ($serverdom eq $dom) {
21760: $canset{$server} = 1;
21761: }
21762: }
21763: }
1.381 raeburn 21764: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
21765: %{$values{$dom}} = ();
21766: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
21767: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
21768: }
1.388 raeburn 21769: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
21770: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
21771: }
1.382 raeburn 21772: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.381 raeburn 21773: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
21774: }
21775: }
1.373 raeburn 21776: my $output;
21777: if (keys(%canset)) {
21778: %{$wafproxy{'alias'}} = ();
1.388 raeburn 21779: %{$wafproxy{'saml'}} = ();
1.373 raeburn 21780: foreach my $key (sort(keys(%canset))) {
1.381 raeburn 21781: if ($env{'form.wafproxy_'.$dom}) {
21782: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
21783: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
21784: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
21785: $changes{'alias'} = 1;
21786: }
1.388 raeburn 21787: if ($env{'form.wafproxy_alias_saml_'.$key}) {
21788: $wafproxy{'saml'}{$key} = 1;
21789: }
21790: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
21791: $changes{'saml'} = 1;
21792: }
1.381 raeburn 21793: } else {
21794: $wafproxy{'alias'}{$key} = '';
1.388 raeburn 21795: $wafproxy{'saml'}{$key} = '';
1.381 raeburn 21796: if ($curralias{$key}) {
21797: $changes{'alias'} = 1;
21798: }
1.388 raeburn 21799: if ($currsaml{$key}) {
21800: $changes{'saml'} = 1;
21801: }
1.373 raeburn 21802: }
21803: if ($wafproxy{'alias'}{$key} eq '') {
21804: if ($curralias{$key}) {
21805: $expirecache{$key} = 1;
21806: }
21807: delete($wafproxy{'alias'}{$key});
21808: }
1.388 raeburn 21809: if ($wafproxy{'saml'}{$key} eq '') {
21810: if ($currsaml{$key}) {
21811: $expiresaml{$key} = 1;
21812: }
21813: delete($wafproxy{'saml'}{$key});
21814: }
1.373 raeburn 21815: }
21816: unless (keys(%{$wafproxy{'alias'}})) {
21817: delete($wafproxy{'alias'});
21818: }
1.388 raeburn 21819: unless (keys(%{$wafproxy{'saml'}})) {
21820: delete($wafproxy{'saml'});
21821: }
21822: # Localization for values in %warn occurs in &mt() calls separately.
1.373 raeburn 21823: my %warn = (
21824: trusted => 'trusted IP range(s)',
1.381 raeburn 21825: vpnint => 'internal IP range(s) for VPN sessions(s)',
21826: vpnext => 'IP range(s) for backend WAF connections',
1.373 raeburn 21827: );
1.382 raeburn 21828: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 21829: my $possible = $env{'form.wafproxy_'.$item};
21830: $possible =~ s/^\s+|\s+$//g;
21831: if ($possible ne '') {
1.381 raeburn 21832: if ($item eq 'remoteip') {
21833: if ($possible =~ /^[mhn]$/) {
21834: $wafproxy{$item} = $possible;
21835: }
21836: } elsif ($item eq 'ipheader') {
21837: if ($wafproxy{'remoteip'} eq 'h') {
21838: $wafproxy{$item} = $possible;
21839: }
1.382 raeburn 21840: } elsif ($item eq 'sslopt') {
21841: if ($possible =~ /^0|1$/) {
21842: $wafproxy{$item} = $possible;
21843: }
1.373 raeburn 21844: } else {
21845: my (@ok,$count);
1.381 raeburn 21846: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
21847: unless ($env{'form.wafproxy_vpnaccess'}) {
21848: $possible = '';
21849: }
21850: } elsif ($item eq 'trusted') {
21851: unless ($wafproxy{'remoteip'} eq 'h') {
21852: $possible = '';
21853: }
21854: }
21855: unless ($possible eq '') {
21856: $possible =~ s/[\r\n]+/\s/g;
21857: $possible =~ s/\s*-\s*/-/g;
21858: $possible =~ s/\s+/,/g;
1.393 raeburn 21859: $possible =~ s/,+/,/g;
1.381 raeburn 21860: }
1.373 raeburn 21861: $count = 0;
1.381 raeburn 21862: if ($possible ne '') {
1.373 raeburn 21863: foreach my $poss (split(/\,/,$possible)) {
21864: $count ++;
1.393 raeburn 21865: $poss = &validate_ip_pattern($poss);
21866: if ($poss ne '') {
1.373 raeburn 21867: push(@ok,$poss);
21868: }
21869: }
21870: my $diff = $count - scalar(@ok);
21871: if ($diff) {
21872: push(@warnings,'<li>'.
21873: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
21874: $diff,$warn{$item}).
21875: '</li>');
21876: }
1.393 raeburn 21877: if (@ok) {
21878: my @cidr_list;
21879: foreach my $item (@ok) {
21880: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
21881: }
21882: $wafproxy{$item} = join(',',@cidr_list);
21883: }
1.373 raeburn 21884: }
21885: }
1.381 raeburn 21886: if ($wafproxy{$item} ne $currvalue{$item}) {
1.373 raeburn 21887: $changes{$item} = 1;
21888: }
1.381 raeburn 21889: } elsif ($currvalue{$item}) {
21890: $changes{$item} = 1;
1.425 raeburn 21891: }
1.381 raeburn 21892: }
21893: } else {
21894: if (keys(%curralias)) {
21895: $changes{'alias'} = 1;
1.388 raeburn 21896: }
21897: if (keys(%currsaml)) {
21898: $changes{'saml'} = 1;
1.425 raeburn 21899: }
1.381 raeburn 21900: if (keys(%currvalue)) {
21901: foreach my $key (keys(%currvalue)) {
21902: $changes{$key} = 1;
1.373 raeburn 21903: }
21904: }
21905: }
21906: if (keys(%changes)) {
21907: my %defaultshash = (
21908: wafproxy => \%wafproxy,
1.425 raeburn 21909: );
1.373 raeburn 21910: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21911: $dom);
21912: if ($putresult eq 'ok') {
21913: my $cachetime = 24*60*60;
21914: my (%domdefaults,$updatedomdefs);
1.382 raeburn 21915: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 21916: if ($changes{$item}) {
21917: unless ($updatedomdefs) {
21918: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
21919: $updatedomdefs = 1;
21920: }
21921: if ($wafproxy{$item}) {
21922: $domdefaults{'waf_'.$item} = $wafproxy{$item};
21923: } elsif (exists($domdefaults{'waf_'.$item})) {
21924: delete($domdefaults{'waf_'.$item});
1.425 raeburn 21925: }
1.373 raeburn 21926: }
21927: }
21928: if ($updatedomdefs) {
21929: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21930: if (ref($lastactref) eq 'HASH') {
21931: $lastactref->{'domdefaults'} = 1;
21932: }
21933: }
21934: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
21935: my %updates = %expirecache;
21936: foreach my $key (keys(%expirecache)) {
21937: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
21938: }
21939: if (ref($wafproxy{'alias'}) eq 'HASH') {
21940: my $cachetime = 24*60*60;
21941: foreach my $key (keys(%{$wafproxy{'alias'}})) {
21942: $updates{$key} = 1;
21943: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
21944: $cachetime);
21945: }
21946: }
21947: if (ref($lastactref) eq 'HASH') {
21948: $lastactref->{'proxyalias'} = \%updates;
21949: }
21950: }
1.388 raeburn 21951: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
21952: my %samlupdates = %expiresaml;
21953: foreach my $key (keys(%expiresaml)) {
21954: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
21955: }
21956: if (ref($wafproxy{'saml'}) eq 'HASH') {
21957: my $cachetime = 24*60*60;
21958: foreach my $key (keys(%{$wafproxy{'saml'}})) {
21959: $samlupdates{$key} = 1;
21960: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
21961: $cachetime);
21962: }
21963: }
21964: if (ref($lastactref) eq 'HASH') {
21965: $lastactref->{'proxysaml'} = \%samlupdates;
21966: }
21967: }
1.373 raeburn 21968: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.401 raeburn 21969: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 21970: if ($changes{$item}) {
21971: if ($item eq 'alias') {
21972: my $numaliased = 0;
21973: if (ref($wafproxy{'alias'}) eq 'HASH') {
21974: my $shown;
21975: if (keys(%{$wafproxy{'alias'}})) {
21976: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
21977: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
21978: &Apache::lonnet::hostname($server),
21979: $wafproxy{'alias'}{$server}).'</li>';
21980: $numaliased ++;
21981: }
21982: if ($numaliased) {
21983: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
21984: '<ul>'.$shown.'</ul>').'</li>';
21985: }
21986: }
21987: }
21988: unless ($numaliased) {
21989: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
21990: }
1.388 raeburn 21991: } elsif ($item eq 'saml') {
1.425 raeburn 21992: my $shown;
1.388 raeburn 21993: if (ref($wafproxy{'saml'}) eq 'HASH') {
21994: if (keys(%{$wafproxy{'saml'}})) {
21995: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
21996: }
21997: }
21998: if ($shown) {
1.396 raeburn 21999: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
1.388 raeburn 22000: $shown).'</li>';
22001: } else {
1.396 raeburn 22002: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
1.388 raeburn 22003: }
1.373 raeburn 22004: } else {
1.381 raeburn 22005: if ($item eq 'remoteip') {
22006: my %ip_methods = &remoteip_methods();
22007: if ($wafproxy{$item} =~ /^[mh]$/) {
22008: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
22009: $ip_methods{$wafproxy{$item}}).'</li>';
22010: } else {
22011: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
22012: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
22013: '</li>';
22014: } else {
22015: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
22016: }
22017: }
22018: } elsif ($item eq 'ipheader') {
1.373 raeburn 22019: if ($wafproxy{$item}) {
1.381 raeburn 22020: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
1.373 raeburn 22021: $wafproxy{$item}).'</li>';
22022: } else {
1.381 raeburn 22023: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
1.373 raeburn 22024: }
22025: } elsif ($item eq 'trusted') {
22026: if ($wafproxy{$item}) {
1.381 raeburn 22027: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
1.373 raeburn 22028: $wafproxy{$item}).'</li>';
22029: } else {
22030: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
22031: }
1.381 raeburn 22032: } elsif ($item eq 'vpnint') {
22033: if ($wafproxy{$item}) {
22034: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
22035: $wafproxy{$item}).'</li>';
22036: } else {
22037: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
22038: }
22039: } elsif ($item eq 'vpnext') {
1.373 raeburn 22040: if ($wafproxy{$item}) {
1.381 raeburn 22041: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
1.373 raeburn 22042: $wafproxy{$item}).'</li>';
22043: } else {
1.381 raeburn 22044: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
1.373 raeburn 22045: }
1.382 raeburn 22046: } elsif ($item eq 'sslopt') {
22047: if ($wafproxy{$item}) {
22048: $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>';
22049: } else {
22050: $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>';
22051: }
1.373 raeburn 22052: }
22053: }
22054: }
22055: }
1.420 raeburn 22056: $output .= '</ul>';
1.373 raeburn 22057: } else {
22058: $output = '<span class="LC_error">'.
22059: &mt('An error occurred: [_1]',$putresult).'</span>';
22060: }
22061: } elsif (keys(%canset)) {
22062: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
22063: }
22064: if (@warnings) {
22065: $output .= '<br />'.&mt('Warnings:').'<ul>'.
22066: join("\n",@warnings).'</ul>';
22067: }
22068: return $output;
22069: }
22070:
22071: sub validate_ip_pattern {
22072: my ($pattern) = @_;
22073: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
22074: my ($start,$end) = ($1,$2);
22075: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
1.393 raeburn 22076: if (($start !~ m{/}) && ($end !~ m{/})) {
22077: return $start.'-'.$end;
22078: }
22079: }
22080: } elsif ($pattern ne '') {
22081: $pattern = &Net::CIDR::cidrvalidate($pattern);
22082: if ($pattern ne '') {
22083: return $pattern;
1.373 raeburn 22084: }
22085: }
1.393 raeburn 22086: return;
1.373 raeburn 22087: }
22088:
1.137 raeburn 22089: sub modify_usersessions {
1.212 raeburn 22090: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 22091: my @hostingtypes = ('version','excludedomain','includedomain');
22092: my @offloadtypes = ('primary','default');
22093: my %types = (
22094: remote => \@hostingtypes,
22095: hosted => \@hostingtypes,
22096: spares => \@offloadtypes,
22097: );
22098: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 22099: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 22100: my (%by_ip,%by_location,@intdoms,@instdoms);
22101: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 22102: my @locations = sort(keys(%by_location));
1.137 raeburn 22103: my (%defaultshash,%changes);
22104: foreach my $prefix (@prefixes) {
22105: $defaultshash{'usersessions'}{$prefix} = {};
22106: }
1.212 raeburn 22107: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 22108: my $resulttext;
1.138 raeburn 22109: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 22110: foreach my $prefix (@prefixes) {
1.145 raeburn 22111: next if ($prefix eq 'spares');
22112: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 22113: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22114: if ($type eq 'version') {
22115: my $value = $env{'form.'.$prefix.'_'.$type};
22116: my $okvalue;
22117: if ($value ne '') {
22118: if (grep(/^\Q$value\E$/,@lcversions)) {
22119: $okvalue = $value;
22120: }
22121: }
22122: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22123: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22124: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
22125: if ($inuse == 0) {
22126: $changes{$prefix}{$type} = 1;
22127: } else {
22128: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
22129: $changes{$prefix}{$type} = 1;
22130: }
22131: if ($okvalue ne '') {
22132: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22133: }
22134: }
22135: } else {
22136: if (($inuse == 1) && ($okvalue ne '')) {
22137: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22138: $changes{$prefix}{$type} = 1;
22139: }
22140: }
22141: } else {
22142: if (($inuse == 1) && ($okvalue ne '')) {
22143: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22144: $changes{$prefix}{$type} = 1;
22145: }
22146: }
22147: } else {
22148: if (($inuse == 1) && ($okvalue ne '')) {
22149: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22150: $changes{$prefix}{$type} = 1;
22151: }
22152: }
22153: } else {
22154: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22155: my @okvals;
22156: foreach my $val (@vals) {
1.138 raeburn 22157: if ($val =~ /:/) {
22158: my @items = split(/:/,$val);
22159: foreach my $item (@items) {
22160: if (ref($by_location{$item}) eq 'ARRAY') {
22161: push(@okvals,$item);
22162: }
22163: }
22164: } else {
22165: if (ref($by_location{$val}) eq 'ARRAY') {
22166: push(@okvals,$val);
22167: }
1.137 raeburn 22168: }
22169: }
22170: @okvals = sort(@okvals);
22171: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22172: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22173: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22174: if ($inuse == 0) {
22175: $changes{$prefix}{$type} = 1;
22176: } else {
22177: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22178: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
22179: if (@changed > 0) {
22180: $changes{$prefix}{$type} = 1;
22181: }
22182: }
22183: } else {
22184: if ($inuse == 1) {
22185: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22186: $changes{$prefix}{$type} = 1;
22187: }
22188: }
22189: } else {
22190: if ($inuse == 1) {
22191: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22192: $changes{$prefix}{$type} = 1;
22193: }
22194: }
22195: } else {
22196: if ($inuse == 1) {
22197: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22198: $changes{$prefix}{$type} = 1;
22199: }
22200: }
22201: }
22202: }
22203: }
1.145 raeburn 22204:
22205: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 22206: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 22207: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
22208: my $savespares;
22209:
22210: foreach my $lonhost (sort(keys(%servers))) {
22211: my $serverhomeID =
22212: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 22213: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 22214: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
22215: my %spareschg;
22216: foreach my $type (@{$types{'spares'}}) {
22217: my @okspares;
22218: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
22219: foreach my $server (@checked) {
1.152 raeburn 22220: if (&Apache::lonnet::hostname($server) ne '') {
22221: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
22222: unless (grep(/^\Q$server\E$/,@okspares)) {
22223: push(@okspares,$server);
22224: }
1.145 raeburn 22225: }
22226: }
22227: }
22228: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
22229: my $newspare;
1.152 raeburn 22230: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
22231: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 22232: $newspare = $new;
22233: }
22234: }
1.152 raeburn 22235: my @spares;
22236: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
22237: @spares = sort(@okspares,$newspare);
22238: } else {
22239: @spares = sort(@okspares);
22240: }
22241: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 22242: if (ref($spareid{$lonhost}) eq 'HASH') {
22243: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 22244: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 22245: if (@diffs > 0) {
22246: $spareschg{$type} = 1;
22247: }
22248: }
22249: }
22250: }
22251: if (keys(%spareschg) > 0) {
22252: $changes{'spares'}{$lonhost} = \%spareschg;
22253: }
22254: }
1.261 raeburn 22255: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371 raeburn 22256: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261 raeburn 22257: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
22258: my @okoffload;
22259: if (@offloadnow) {
22260: foreach my $server (@offloadnow) {
22261: if (&Apache::lonnet::hostname($server) ne '') {
22262: unless (grep(/^\Q$server\E$/,@okoffload)) {
22263: push(@okoffload,$server);
22264: }
22265: }
22266: }
22267: if (@okoffload) {
22268: foreach my $lonhost (@okoffload) {
22269: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
22270: }
22271: }
22272: }
1.371 raeburn 22273: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
22274: my @okoffloadoth;
22275: if (@offloadoth) {
22276: foreach my $server (@offloadoth) {
22277: if (&Apache::lonnet::hostname($server) ne '') {
22278: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
22279: push(@okoffloadoth,$server);
22280: }
22281: }
22282: }
22283: if (@okoffloadoth) {
22284: foreach my $lonhost (@okoffloadoth) {
22285: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
22286: }
22287: }
22288: }
1.145 raeburn 22289: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22290: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
22291: if (ref($changes{'spares'}) eq 'HASH') {
22292: if (keys(%{$changes{'spares'}}) > 0) {
22293: $savespares = 1;
22294: }
22295: }
22296: } else {
22297: $savespares = 1;
22298: }
1.371 raeburn 22299: foreach my $offload ('offloadnow','offloadoth') {
22300: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
22301: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
22302: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
22303: $changes{$offload} = 1;
22304: last;
22305: }
1.261 raeburn 22306: }
1.371 raeburn 22307: unless ($changes{$offload}) {
22308: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
22309: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
22310: $changes{$offload} = 1;
22311: last;
22312: }
1.261 raeburn 22313: }
22314: }
1.371 raeburn 22315: } else {
22316: if (($offload eq 'offloadnow') && (@okoffload)) {
22317: $changes{'offloadnow'} = 1;
22318: }
22319: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
22320: $changes{'offloadoth'} = 1;
22321: }
1.425 raeburn 22322: }
1.371 raeburn 22323: }
22324: } else {
22325: if (@okoffload) {
1.261 raeburn 22326: $changes{'offloadnow'} = 1;
22327: }
1.371 raeburn 22328: if (@okoffloadoth) {
22329: $changes{'offloadoth'} = 1;
22330: }
1.145 raeburn 22331: }
1.147 raeburn 22332: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
22333: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 22334: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22335: $dom);
22336: if ($putresult eq 'ok') {
22337: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22338: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
22339: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
22340: }
22341: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
22342: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
22343: }
1.261 raeburn 22344: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22345: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
22346: }
1.371 raeburn 22347: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22348: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
22349: }
1.137 raeburn 22350: }
22351: my $cachetime = 24*60*60;
22352: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 22353: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 22354: if (ref($lastactref) eq 'HASH') {
22355: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 22356: $lastactref->{'usersessions'} = 1;
1.212 raeburn 22357: }
1.147 raeburn 22358: if (keys(%changes) > 0) {
22359: my %lt = &usersession_titles();
22360: $resulttext = &mt('Changes made:').'<ul>';
22361: foreach my $prefix (@prefixes) {
22362: if (ref($changes{$prefix}) eq 'HASH') {
22363: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
22364: if ($prefix eq 'spares') {
22365: if (ref($changes{$prefix}) eq 'HASH') {
22366: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
22367: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 22368: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 22369: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
22370: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 22371: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
22372: foreach my $type (@{$types{$prefix}}) {
22373: if ($changes{$prefix}{$lonhost}{$type}) {
22374: my $offloadto = &mt('None');
22375: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
22376: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
22377: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
22378: }
1.145 raeburn 22379: }
1.147 raeburn 22380: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 22381: }
1.137 raeburn 22382: }
22383: }
1.147 raeburn 22384: $resulttext .= '</li>';
1.137 raeburn 22385: }
22386: }
1.147 raeburn 22387: } else {
22388: foreach my $type (@{$types{$prefix}}) {
22389: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22390: my ($newvalue,$notinuse);
1.147 raeburn 22391: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22392: if (ref($defaultshash{'usersessions'}{$prefix})) {
22393: if ($type eq 'version') {
22394: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 22395: } else {
22396: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22397: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
22398: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
22399: }
22400: } else {
22401: $notinuse = 1;
1.147 raeburn 22402: }
1.145 raeburn 22403: }
22404: }
22405: }
1.147 raeburn 22406: if ($newvalue eq '') {
22407: if ($type eq 'version') {
22408: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 22409: } elsif ($notinuse) {
22410: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 22411: } else {
22412: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
22413: }
1.145 raeburn 22414: } else {
1.147 raeburn 22415: if ($type eq 'version') {
1.344 raeburn 22416: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 22417: }
22418: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 22419: }
1.137 raeburn 22420: }
22421: }
22422: }
1.147 raeburn 22423: $resulttext .= '</ul>';
1.137 raeburn 22424: }
22425: }
1.261 raeburn 22426: if ($changes{'offloadnow'}) {
22427: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22428: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371 raeburn 22429: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261 raeburn 22430: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
22431: $resulttext .= '<li>'.$lonhost.'</li>';
22432: }
22433: $resulttext .= '</ul>';
22434: } else {
1.371 raeburn 22435: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
22436: }
22437: } else {
22438: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
22439: }
22440: }
22441: if ($changes{'offloadoth'}) {
22442: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22443: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
22444: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
22445: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
22446: $resulttext .= '<li>'.$lonhost.'</li>';
22447: }
22448: $resulttext .= '</ul>';
22449: } else {
22450: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261 raeburn 22451: }
22452: } else {
1.371 raeburn 22453: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261 raeburn 22454: }
22455: }
1.147 raeburn 22456: $resulttext .= '</ul>';
22457: } else {
22458: $resulttext = $nochgmsg;
1.137 raeburn 22459: }
22460: } else {
22461: $resulttext = '<span class="LC_error">'.
22462: &mt('An error occurred: [_1]',$putresult).'</span>';
22463: }
22464: } else {
1.147 raeburn 22465: $resulttext = $nochgmsg;
1.137 raeburn 22466: }
22467: return $resulttext;
22468: }
22469:
1.275 raeburn 22470: sub modify_ssl {
22471: my ($dom,$lastactref,%domconfig) = @_;
22472: my (%by_ip,%by_location,@intdoms,@instdoms);
22473: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
22474: my @locations = sort(keys(%by_location));
22475: my %servers = &Apache::lonnet::internet_dom_servers($dom);
22476: my (%defaultshash,%changes);
22477: my $action = 'ssl';
1.293 raeburn 22478: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 22479: foreach my $prefix (@prefixes) {
22480: $defaultshash{$action}{$prefix} = {};
22481: }
22482: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22483: my $resulttext;
22484: my %iphost = &Apache::lonnet::get_iphost();
22485: my @reptypes = ('certreq','nocertreq');
22486: my @connecttypes = ('dom','intdom','other');
22487: my %types = (
1.293 raeburn 22488: connto => \@connecttypes,
22489: connfrom => \@connecttypes,
22490: replication => \@reptypes,
1.275 raeburn 22491: );
22492: foreach my $prefix (sort(keys(%types))) {
22493: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 22494: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22495: my $value = 'yes';
22496: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
22497: $value = $env{'form.'.$prefix.'_'.$type};
22498: }
1.335 raeburn 22499: if (ref($domconfig{$action}) eq 'HASH') {
22500: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22501: if ($domconfig{$action}{$prefix}{$type} ne '') {
22502: if ($value ne $domconfig{$action}{$prefix}{$type}) {
22503: $changes{$prefix}{$type} = 1;
22504: }
22505: $defaultshash{$action}{$prefix}{$type} = $value;
22506: } else {
22507: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 22508: $changes{$prefix}{$type} = 1;
22509: }
22510: } else {
22511: $defaultshash{$action}{$prefix}{$type} = $value;
22512: $changes{$prefix}{$type} = 1;
22513: }
22514: } else {
22515: $defaultshash{$action}{$prefix}{$type} = $value;
22516: $changes{$prefix}{$type} = 1;
22517: }
22518: if (($type eq 'dom') && (keys(%servers) == 1)) {
22519: delete($changes{$prefix}{$type});
22520: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
22521: delete($changes{$prefix}{$type});
22522: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
22523: delete($changes{$prefix}{$type});
22524: }
22525: } elsif ($prefix eq 'replication') {
22526: if (@locations > 0) {
22527: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22528: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22529: my @okvals;
22530: foreach my $val (@vals) {
22531: if ($val =~ /:/) {
22532: my @items = split(/:/,$val);
22533: foreach my $item (@items) {
22534: if (ref($by_location{$item}) eq 'ARRAY') {
22535: push(@okvals,$item);
22536: }
22537: }
22538: } else {
22539: if (ref($by_location{$val}) eq 'ARRAY') {
22540: push(@okvals,$val);
22541: }
22542: }
22543: }
22544: @okvals = sort(@okvals);
22545: if (ref($domconfig{$action}) eq 'HASH') {
22546: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22547: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
22548: if ($inuse == 0) {
22549: $changes{$prefix}{$type} = 1;
22550: } else {
22551: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22552: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
22553: if (@changed > 0) {
22554: $changes{$prefix}{$type} = 1;
22555: }
22556: }
22557: } else {
22558: if ($inuse == 1) {
22559: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22560: $changes{$prefix}{$type} = 1;
22561: }
22562: }
22563: } else {
22564: if ($inuse == 1) {
22565: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22566: $changes{$prefix}{$type} = 1;
22567: }
22568: }
22569: } else {
22570: if ($inuse == 1) {
22571: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22572: $changes{$prefix}{$type} = 1;
22573: }
22574: }
22575: }
22576: }
22577: }
22578: }
1.336 raeburn 22579: if (keys(%changes)) {
22580: foreach my $prefix (keys(%changes)) {
22581: if (ref($changes{$prefix}) eq 'HASH') {
22582: if (scalar(keys(%{$changes{$prefix}})) == 0) {
22583: delete($changes{$prefix});
22584: }
22585: } else {
22586: delete($changes{$prefix});
22587: }
22588: }
22589: }
1.275 raeburn 22590: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
22591: if (keys(%changes) > 0) {
22592: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22593: $dom);
22594: if ($putresult eq 'ok') {
22595: if (ref($defaultshash{$action}) eq 'HASH') {
22596: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
22597: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
22598: }
1.293 raeburn 22599: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 22600: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 22601: }
22602: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 22603: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 22604: }
22605: }
22606: my $cachetime = 24*60*60;
22607: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22608: if (ref($lastactref) eq 'HASH') {
22609: $lastactref->{'domdefaults'} = 1;
22610: }
22611: if (keys(%changes) > 0) {
22612: my %titles = &ssl_titles();
22613: $resulttext = &mt('Changes made:').'<ul>';
22614: foreach my $prefix (@prefixes) {
22615: if (ref($changes{$prefix}) eq 'HASH') {
22616: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
22617: foreach my $type (@{$types{$prefix}}) {
22618: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22619: my ($newvalue,$notinuse);
1.275 raeburn 22620: if (ref($defaultshash{$action}) eq 'HASH') {
22621: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 22622: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22623: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 22624: } else {
22625: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
22626: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
22627: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
22628: }
22629: } else {
22630: $notinuse = 1;
1.275 raeburn 22631: }
22632: }
22633: }
1.344 raeburn 22634: if ($notinuse) {
22635: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
22636: } elsif ($newvalue eq '') {
1.275 raeburn 22637: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
22638: } else {
22639: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
22640: }
22641: }
22642: }
22643: }
22644: $resulttext .= '</ul>';
22645: }
22646: }
22647: } else {
22648: $resulttext = $nochgmsg;
22649: }
22650: } else {
22651: $resulttext = '<span class="LC_error">'.
22652: &mt('An error occurred: [_1]',$putresult).'</span>';
22653: }
22654: } else {
22655: $resulttext = $nochgmsg;
22656: }
22657: return $resulttext;
22658: }
22659:
1.279 raeburn 22660: sub modify_trust {
22661: my ($dom,$lastactref,%domconfig) = @_;
22662: my (%by_ip,%by_location,@intdoms,@instdoms);
22663: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
22664: my @locations = sort(keys(%by_location));
22665: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
22666: my @types = ('exc','inc');
22667: my (%defaultshash,%changes);
22668: foreach my $prefix (@prefixes) {
22669: $defaultshash{'trust'}{$prefix} = {};
22670: }
22671: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22672: my $resulttext;
22673: foreach my $prefix (@prefixes) {
22674: foreach my $type (@types) {
22675: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22676: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22677: my @okvals;
22678: foreach my $val (@vals) {
22679: if ($val =~ /:/) {
22680: my @items = split(/:/,$val);
22681: foreach my $item (@items) {
22682: if (ref($by_location{$item}) eq 'ARRAY') {
22683: push(@okvals,$item);
22684: }
22685: }
22686: } else {
22687: if (ref($by_location{$val}) eq 'ARRAY') {
22688: push(@okvals,$val);
22689: }
22690: }
22691: }
22692: @okvals = sort(@okvals);
22693: if (ref($domconfig{'trust'}) eq 'HASH') {
22694: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
22695: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
22696: if ($inuse == 0) {
22697: $changes{$prefix}{$type} = 1;
22698: } else {
22699: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22700: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
22701: if (@changed > 0) {
22702: $changes{$prefix}{$type} = 1;
22703: }
22704: }
22705: } else {
22706: if ($inuse == 1) {
22707: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22708: $changes{$prefix}{$type} = 1;
22709: }
22710: }
22711: } else {
22712: if ($inuse == 1) {
22713: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22714: $changes{$prefix}{$type} = 1;
22715: }
22716: }
22717: } else {
22718: if ($inuse == 1) {
22719: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22720: $changes{$prefix}{$type} = 1;
22721: }
22722: }
22723: }
22724: }
22725: my $nochgmsg = &mt('No changes made to trust settings.');
22726: if (keys(%changes) > 0) {
22727: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22728: $dom);
22729: if ($putresult eq 'ok') {
22730: if (ref($defaultshash{'trust'}) eq 'HASH') {
22731: foreach my $prefix (@prefixes) {
22732: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
22733: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
22734: }
22735: }
22736: }
22737: my $cachetime = 24*60*60;
22738: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.410 raeburn 22739: &Apache::lonnet::do_cache_new('trust',$dom,$defaultshash{'trust'},3600);
1.279 raeburn 22740: if (ref($lastactref) eq 'HASH') {
22741: $lastactref->{'domdefaults'} = 1;
1.410 raeburn 22742: $lastactref->{'trust'} = 1;
1.279 raeburn 22743: }
22744: if (keys(%changes) > 0) {
22745: my %lt = &trust_titles();
22746: $resulttext = &mt('Changes made:').'<ul>';
22747: foreach my $prefix (@prefixes) {
22748: if (ref($changes{$prefix}) eq 'HASH') {
22749: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
22750: foreach my $type (@types) {
22751: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22752: my ($newvalue,$notinuse);
1.279 raeburn 22753: if (ref($defaultshash{'trust'}) eq 'HASH') {
22754: if (ref($defaultshash{'trust'}{$prefix})) {
22755: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
22756: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
22757: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
22758: }
1.344 raeburn 22759: } else {
22760: $notinuse = 1;
1.279 raeburn 22761: }
22762: }
22763: }
1.344 raeburn 22764: if ($notinuse) {
22765: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
22766: } elsif ($newvalue eq '') {
1.279 raeburn 22767: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
22768: } else {
22769: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
22770: }
22771: }
22772: }
22773: $resulttext .= '</ul>';
22774: }
22775: }
22776: $resulttext .= '</ul>';
22777: } else {
22778: $resulttext = $nochgmsg;
22779: }
22780: } else {
22781: $resulttext = '<span class="LC_error">'.
22782: &mt('An error occurred: [_1]',$putresult).'</span>';
22783: }
22784: } else {
22785: $resulttext = $nochgmsg;
22786: }
22787: return $resulttext;
22788: }
22789:
1.150 raeburn 22790: sub modify_loadbalancing {
22791: my ($dom,%domconfig) = @_;
22792: my $primary_id = &Apache::lonnet::domain($dom,'primary');
22793: my $intdom = &Apache::lonnet::internet_dom($primary_id);
22794: my ($othertitle,$usertypes,$types) =
22795: &Apache::loncommon::sorted_inst_types($dom);
22796: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 22797: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 22798: my @sparestypes = ('primary','default');
22799: my %typetitles = &sparestype_titles();
22800: my $resulttext;
1.342 raeburn 22801: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 22802: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
22803: %existing = %{$domconfig{'loadbalancing'}};
22804: }
22805: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 22806: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 22807: my ($saveloadbalancing,%defaultshash,%changes);
22808: my ($alltypes,$othertypes,$titles) =
22809: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
22810: my %ruletitles = &offloadtype_text();
22811: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
22812: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
22813: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
22814: if ($balancer eq '') {
22815: next;
22816: }
1.210 raeburn 22817: if (!exists($servers{$balancer})) {
1.171 raeburn 22818: if (exists($currbalancer{$balancer})) {
22819: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 22820: }
1.171 raeburn 22821: next;
22822: }
22823: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
22824: push(@{$changes{'delete'}},$balancer);
22825: next;
22826: }
22827: if (!exists($currbalancer{$balancer})) {
22828: push(@{$changes{'add'}},$balancer);
22829: }
22830: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
22831: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
22832: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
22833: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
22834: $saveloadbalancing = 1;
22835: }
22836: foreach my $sparetype (@sparestypes) {
22837: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
22838: my @offloadto;
22839: foreach my $target (@targets) {
22840: if (($servers{$target}) && ($target ne $balancer)) {
22841: if ($sparetype eq 'default') {
22842: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
22843: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 22844: }
22845: }
1.171 raeburn 22846: unless(grep(/^\Q$target\E$/,@offloadto)) {
22847: push(@offloadto,$target);
22848: }
1.150 raeburn 22849: }
22850: }
1.284 raeburn 22851: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
22852: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
22853: push(@offloadto,$balancer);
22854: }
22855: }
22856: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 22857: }
1.342 raeburn 22858: if ($env{'form.loadbalancing_cookie_'.$i}) {
22859: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
1.425 raeburn 22860: if (exists($currbalancer{$balancer})) {
1.342 raeburn 22861: unless ($currcookies{$balancer}) {
22862: $changes{'curr'}{$balancer}{'cookie'} = 1;
22863: }
22864: }
22865: } elsif (exists($currbalancer{$balancer})) {
22866: if ($currcookies{$balancer}) {
22867: $changes{'curr'}{$balancer}{'cookie'} = 1;
22868: }
22869: }
1.171 raeburn 22870: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 22871: foreach my $sparetype (@sparestypes) {
1.171 raeburn 22872: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
22873: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 22874: if (@targetdiffs > 0) {
1.171 raeburn 22875: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 22876: }
1.171 raeburn 22877: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
22878: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
22879: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 22880: }
22881: }
22882: }
22883: } else {
1.171 raeburn 22884: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 22885: foreach my $sparetype (@sparestypes) {
1.171 raeburn 22886: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
22887: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
22888: $changes{'curr'}{$balancer}{'targets'} = 1;
22889: }
1.150 raeburn 22890: }
22891: }
1.210 raeburn 22892: }
1.150 raeburn 22893: }
22894: my $ishomedom;
1.171 raeburn 22895: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
22896: $ishomedom = 1;
1.150 raeburn 22897: }
22898: if (ref($alltypes) eq 'ARRAY') {
22899: foreach my $type (@{$alltypes}) {
22900: my $rule;
1.210 raeburn 22901: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 22902: (!$ishomedom)) {
1.171 raeburn 22903: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
22904: }
22905: if ($rule eq 'specific') {
1.255 raeburn 22906: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 22907: if (exists($servers{$specifiedhost})) {
1.255 raeburn 22908: $rule = $specifiedhost;
22909: }
1.150 raeburn 22910: }
1.171 raeburn 22911: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
22912: if (ref($currrules{$balancer}) eq 'HASH') {
22913: if ($rule ne $currrules{$balancer}{$type}) {
22914: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 22915: }
22916: } elsif ($rule ne '') {
1.171 raeburn 22917: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 22918: }
22919: }
22920: }
1.171 raeburn 22921: }
22922: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
22923: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
22924: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
22925: $defaultshash{'loadbalancing'} = {};
22926: }
22927: my $putresult = &Apache::lonnet::put_dom('configuration',
22928: \%defaultshash,$dom);
22929: if ($putresult eq 'ok') {
22930: if (keys(%changes) > 0) {
1.252 raeburn 22931: my %toupdate;
1.171 raeburn 22932: if (ref($changes{'delete'}) eq 'ARRAY') {
22933: foreach my $balancer (sort(@{$changes{'delete'}})) {
22934: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 22935: $toupdate{$balancer} = 1;
1.150 raeburn 22936: }
1.171 raeburn 22937: }
22938: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 22939: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 22940: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 22941: $toupdate{$balancer} = 1;
1.171 raeburn 22942: }
22943: }
22944: if (ref($changes{'curr'}) eq 'HASH') {
22945: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 22946: $toupdate{$balancer} = 1;
1.171 raeburn 22947: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
22948: if ($changes{'curr'}{$balancer}{'targets'}) {
22949: my %offloadstr;
22950: foreach my $sparetype (@sparestypes) {
22951: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
22952: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
22953: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
22954: }
22955: }
1.150 raeburn 22956: }
1.171 raeburn 22957: if (keys(%offloadstr) == 0) {
22958: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 22959: } else {
1.171 raeburn 22960: my $showoffload;
22961: foreach my $sparetype (@sparestypes) {
22962: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
22963: if (defined($offloadstr{$sparetype})) {
22964: $showoffload .= $offloadstr{$sparetype};
22965: } else {
22966: $showoffload .= &mt('None');
22967: }
22968: $showoffload .= (' 'x3);
22969: }
22970: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 22971: }
22972: }
22973: }
1.171 raeburn 22974: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
22975: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
22976: foreach my $type (@{$alltypes}) {
22977: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
22978: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
22979: my $balancetext;
22980: if ($rule eq '') {
22981: $balancetext = $ruletitles{'default'};
1.209 raeburn 22982: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 22983: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 22984: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 22985: foreach my $sparetype (@sparestypes) {
22986: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
22987: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
22988: }
22989: }
1.253 raeburn 22990: foreach my $item (@{$alltypes}) {
22991: next if ($item =~ /^_LC_ipchange/);
22992: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
22993: if ($hasrule eq 'homeserver') {
22994: map { $toupdate{$_} = 1; } (keys(%libraryservers));
22995: } else {
22996: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
22997: if ($servers{$hasrule}) {
22998: $toupdate{$hasrule} = 1;
22999: }
23000: }
23001: }
23002: }
1.254 raeburn 23003: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
23004: $balancetext = $ruletitles{$rule};
23005: } else {
23006: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23007: $balancetext = $ruletitles{'particular'}.' '.$receiver;
23008: if ($receiver) {
23009: $toupdate{$receiver};
23010: }
23011: }
23012: } else {
23013: $balancetext = $ruletitles{$rule};
1.252 raeburn 23014: }
1.171 raeburn 23015: } else {
23016: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
23017: }
1.210 raeburn 23018: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 23019: }
23020: }
23021: }
23022: }
1.342 raeburn 23023: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.389 raeburn 23024: if ($currcookies{$balancer}) {
23025: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
23026: $balancer).'</li>';
23027: } else {
23028: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
23029: $balancer).'</li>';
23030: }
1.342 raeburn 23031: }
1.375 raeburn 23032: }
23033: }
23034: if (keys(%toupdate)) {
23035: my %thismachine;
23036: my $updatedhere;
23037: my $cachetime = 60*60*24;
23038: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
23039: foreach my $lonhost (keys(%toupdate)) {
23040: if ($thismachine{$lonhost}) {
23041: unless ($updatedhere) {
23042: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
23043: $defaultshash{'loadbalancing'},
23044: $cachetime);
23045: $updatedhere = 1;
1.252 raeburn 23046: }
1.375 raeburn 23047: } else {
23048: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
23049: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.252 raeburn 23050: }
1.150 raeburn 23051: }
1.171 raeburn 23052: }
23053: if ($resulttext ne '') {
23054: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 23055: } else {
23056: $resulttext = $nochgmsg;
23057: }
23058: } else {
1.171 raeburn 23059: $resulttext = $nochgmsg;
1.150 raeburn 23060: }
23061: } else {
1.171 raeburn 23062: $resulttext = '<span class="LC_error">'.
23063: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 23064: }
23065: } else {
1.171 raeburn 23066: $resulttext = $nochgmsg;
1.150 raeburn 23067: }
23068: return $resulttext;
23069: }
23070:
1.48 raeburn 23071: sub recurse_check {
23072: my ($chkcats,$categories,$depth,$name) = @_;
23073: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
23074: my $chg = 0;
23075: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
23076: my $category = $chkcats->[$depth]{$name}[$j];
23077: my $item;
23078: if ($category eq '') {
23079: $chg ++;
23080: } else {
23081: my $deeper = $depth + 1;
23082: $item = &escape($category).':'.&escape($name).':'.$depth;
23083: if ($chg) {
23084: $categories->{$item} -= $chg;
23085: }
23086: &recurse_check($chkcats,$categories,$deeper,$category);
23087: $deeper --;
23088: }
23089: }
23090: }
23091: return;
23092: }
23093:
23094: sub recurse_cat_deletes {
23095: my ($item,$coursecategories,$deletions) = @_;
23096: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
23097: my $subdepth = $depth + 1;
23098: if (ref($coursecategories) eq 'HASH') {
23099: foreach my $subitem (keys(%{$coursecategories})) {
23100: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
23101: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
23102: delete($coursecategories->{$subitem});
23103: $deletions->{$subitem} = 1;
23104: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 23105: }
1.48 raeburn 23106: }
23107: }
23108: return;
23109: }
23110:
1.125 raeburn 23111: sub active_dc_picker {
1.191 raeburn 23112: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 23113: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 23114: my @domcoord = keys(%domcoords);
23115: if (keys(%currhash)) {
23116: foreach my $dc (keys(%currhash)) {
23117: unless (exists($domcoords{$dc})) {
23118: push(@domcoord,$dc);
23119: }
23120: }
23121: }
23122: @domcoord = sort(@domcoord);
1.210 raeburn 23123: my $numdcs = scalar(@domcoord);
1.191 raeburn 23124: my $rows = 0;
23125: my $table;
1.125 raeburn 23126: if ($numdcs > 1) {
1.191 raeburn 23127: $table = '<table>';
23128: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 23129: my $rem = $i%($numinrow);
23130: if ($rem == 0) {
23131: if ($i > 0) {
1.191 raeburn 23132: $table .= '</tr>';
1.125 raeburn 23133: }
1.191 raeburn 23134: $table .= '<tr>';
23135: $rows ++;
1.125 raeburn 23136: }
1.191 raeburn 23137: my $check = '';
23138: if ($inputtype eq 'radio') {
23139: if (keys(%currhash) == 0) {
23140: if (!$i) {
23141: $check = ' checked="checked"';
23142: }
23143: } elsif (exists($currhash{$domcoord[$i]})) {
23144: $check = ' checked="checked"';
23145: }
23146: } else {
23147: if (exists($currhash{$domcoord[$i]})) {
23148: $check = ' checked="checked"';
1.125 raeburn 23149: }
23150: }
1.191 raeburn 23151: if ($i == @domcoord - 1) {
1.125 raeburn 23152: my $colsleft = $numinrow - $rem;
23153: if ($colsleft > 1) {
1.191 raeburn 23154: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 23155: } else {
1.191 raeburn 23156: $table .= '<td class="LC_left_item">';
1.125 raeburn 23157: }
23158: } else {
1.191 raeburn 23159: $table .= '<td class="LC_left_item">';
23160: }
23161: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
23162: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
23163: $table .= '<span class="LC_nobreak"><label>'.
23164: '<input type="'.$inputtype.'" name="'.$name.'"'.
23165: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
23166: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 23167: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 23168: }
1.219 raeburn 23169: $table .= '</label></span></td>';
1.191 raeburn 23170: }
23171: $table .= '</tr></table>';
23172: } elsif ($numdcs == 1) {
1.219 raeburn 23173: my ($dcname,$dcdom) = split(':',$domcoord[0]);
23174: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 23175: if ($inputtype eq 'radio') {
1.247 raeburn 23176: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 23177: if ($user ne $dcname.':'.$dcdom) {
23178: $table .= ' ('.$dcname.':'.$dcdom.')';
23179: }
1.191 raeburn 23180: } else {
23181: my $check;
23182: if (exists($currhash{$domcoord[0]})) {
23183: $check = ' checked="checked"';
1.125 raeburn 23184: }
1.247 raeburn 23185: $table = '<span class="LC_nobreak"><label>'.
23186: '<input type="checkbox" name="'.$name.'" '.
23187: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 23188: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 23189: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 23190: }
1.220 raeburn 23191: $table .= '</label></span>';
1.191 raeburn 23192: $rows ++;
1.125 raeburn 23193: }
23194: }
1.191 raeburn 23195: return ($numdcs,$table,$rows);
1.125 raeburn 23196: }
23197:
1.137 raeburn 23198: sub usersession_titles {
23199: return &Apache::lonlocal::texthash(
23200: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
23201: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 23202: spares => 'Servers offloaded to, when busy',
1.137 raeburn 23203: version => 'LON-CAPA version requirement',
1.138 raeburn 23204: excludedomain => 'Allow all, but exclude specific domains',
23205: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 23206: primary => 'Primary (checked first)',
1.154 raeburn 23207: default => 'Default',
1.137 raeburn 23208: );
23209: }
23210:
1.152 raeburn 23211: sub id_for_thisdom {
23212: my (%servers) = @_;
23213: my %altids;
23214: foreach my $server (keys(%servers)) {
23215: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
23216: if ($serverhome ne $server) {
23217: $altids{$serverhome} = $server;
23218: }
23219: }
23220: return %altids;
23221: }
23222:
1.150 raeburn 23223: sub count_servers {
23224: my ($currbalancer,%servers) = @_;
23225: my (@spares,$numspares);
23226: foreach my $lonhost (sort(keys(%servers))) {
23227: next if ($currbalancer eq $lonhost);
23228: push(@spares,$lonhost);
23229: }
23230: if ($currbalancer) {
23231: $numspares = scalar(@spares);
23232: } else {
23233: $numspares = scalar(@spares) - 1;
23234: }
23235: return ($numspares,@spares);
23236: }
23237:
23238: sub lonbalance_targets_js {
1.171 raeburn 23239: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 23240: my $select = &mt('Select');
23241: my ($alltargets,$allishome,$allinsttypes,@alltypes);
23242: if (ref($servers) eq 'HASH') {
23243: $alltargets = join("','",sort(keys(%{$servers})));
23244: my @homedoms;
23245: foreach my $server (sort(keys(%{$servers}))) {
23246: if (&Apache::lonnet::host_domain($server) eq $dom) {
23247: push(@homedoms,'1');
23248: } else {
23249: push(@homedoms,'0');
23250: }
23251: }
23252: $allishome = join("','",@homedoms);
23253: }
23254: if (ref($types) eq 'ARRAY') {
23255: if (@{$types} > 0) {
23256: @alltypes = @{$types};
23257: }
23258: }
23259: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
23260: $allinsttypes = join("','",@alltypes);
1.342 raeburn 23261: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 23262: if (ref($settings) eq 'HASH') {
23263: %existing = %{$settings};
23264: }
23265: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 23266: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 23267: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 23268: return <<"END";
23269:
23270: <script type="text/javascript">
23271: // <![CDATA[
23272:
1.171 raeburn 23273: currBalancers = new Array('$balancers');
23274:
23275: function toggleTargets(balnum) {
23276: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23277: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
23278: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
23279: var prevbalancer = prevhostitem.value;
23280: var baltotal = document.getElementById('loadbalancing_total').value;
23281: prevhostitem.value = balancer;
23282: if (prevbalancer != '') {
23283: var prevIdx = currBalancers.indexOf(prevbalancer);
23284: if (prevIdx != -1) {
23285: currBalancers.splice(prevIdx,1);
23286: }
23287: }
1.150 raeburn 23288: if (balancer == '') {
1.171 raeburn 23289: hideSpares(balnum);
1.150 raeburn 23290: } else {
1.171 raeburn 23291: var currIdx = currBalancers.indexOf(balancer);
23292: if (currIdx == -1) {
23293: currBalancers.push(balancer);
23294: }
1.150 raeburn 23295: var homedoms = new Array('$allishome');
1.171 raeburn 23296: var ishomedom = homedoms[lonhostitem.selectedIndex];
23297: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 23298: }
1.171 raeburn 23299: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 23300: return;
23301: }
23302:
1.171 raeburn 23303: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 23304: var alltargets = new Array('$alltargets');
23305: var insttypes = new Array('$allinsttypes');
1.151 raeburn 23306: var offloadtypes = new Array('primary','default');
23307:
1.171 raeburn 23308: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
23309: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 23310:
1.151 raeburn 23311: for (var i=0; i<offloadtypes.length; i++) {
23312: var count = 0;
23313: for (var j=0; j<alltargets.length; j++) {
23314: if (alltargets[j] != balancer) {
1.171 raeburn 23315: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
23316: item.value = alltargets[j];
23317: item.style.textAlign='left';
23318: item.style.textFace='normal';
23319: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
23320: if (currBalancers.indexOf(alltargets[j]) == -1) {
23321: item.disabled = '';
23322: } else {
23323: item.disabled = 'disabled';
23324: item.checked = false;
23325: }
1.151 raeburn 23326: count ++;
23327: }
1.150 raeburn 23328: }
23329: }
1.151 raeburn 23330: for (var k=0; k<insttypes.length; k++) {
23331: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 23332: if (ishomedom == 1) {
1.171 raeburn 23333: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23334: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23335: } else {
1.171 raeburn 23336: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23337: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 23338: }
23339: } else {
1.171 raeburn 23340: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23341: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23342: }
1.151 raeburn 23343: if ((insttypes[k] != '_LC_external') &&
23344: ((insttypes[k] != '_LC_internetdom') ||
23345: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 23346: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
23347: item.options.length = 0;
23348: item.options[0] = new Option("","",true,true);
1.210 raeburn 23349: var idx = 0;
1.151 raeburn 23350: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 23351: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
23352: idx ++;
23353: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 23354: }
23355: }
23356: }
23357: }
23358: return;
23359: }
23360:
1.171 raeburn 23361: function hideSpares(balnum) {
1.150 raeburn 23362: var alltargets = new Array('$alltargets');
23363: var insttypes = new Array('$allinsttypes');
23364: var offloadtypes = new Array('primary','default');
23365:
1.171 raeburn 23366: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
23367: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 23368:
23369: var total = alltargets.length - 1;
23370: for (var i=0; i<offloadtypes; i++) {
23371: for (var j=0; j<total; j++) {
1.171 raeburn 23372: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
23373: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
23374: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 23375: }
1.150 raeburn 23376: }
23377: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 23378: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23379: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 23380: if (insttypes[k] != '_LC_external') {
1.171 raeburn 23381: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
23382: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 23383: }
23384: }
23385: return;
23386: }
23387:
1.171 raeburn 23388: function checkOffloads(item,balnum,type) {
1.150 raeburn 23389: var alltargets = new Array('$alltargets');
23390: var offloadtypes = new Array('primary','default');
23391: if (item.checked) {
23392: var total = alltargets.length - 1;
23393: var other;
23394: if (type == offloadtypes[0]) {
1.151 raeburn 23395: other = offloadtypes[1];
1.150 raeburn 23396: } else {
1.151 raeburn 23397: other = offloadtypes[0];
1.150 raeburn 23398: }
23399: for (var i=0; i<total; i++) {
1.171 raeburn 23400: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 23401: if (server == item.value) {
1.171 raeburn 23402: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
23403: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 23404: }
23405: }
23406: }
23407: }
23408: return;
23409: }
23410:
1.171 raeburn 23411: function singleServerToggle(balnum,type) {
23412: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 23413: if (offloadtoSelIdx == 0) {
1.171 raeburn 23414: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
23415: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23416:
23417: } else {
1.171 raeburn 23418: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
23419: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 23420: }
23421: return;
23422: }
23423:
1.171 raeburn 23424: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 23425: if (type == '_LC_external') {
1.171 raeburn 23426: return;
1.150 raeburn 23427: }
1.171 raeburn 23428: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 23429: for (var i=0; i<typesRules.length; i++) {
23430: if (formname.elements[typesRules[i]].checked) {
23431: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 23432: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
23433: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23434: } else {
1.171 raeburn 23435: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
23436: }
23437: }
23438: }
23439: return;
23440: }
23441:
23442: function balancerDeleteChange(balnum) {
23443: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23444: var baltotal = document.getElementById('loadbalancing_total').value;
23445: var addtarget;
23446: var removetarget;
23447: var action = 'delete';
23448: if (document.getElementById('loadbalancing_delete_'+balnum)) {
23449: var lonhost = hostitem.value;
23450: var currIdx = currBalancers.indexOf(lonhost);
23451: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
23452: if (currIdx != -1) {
23453: currBalancers.splice(currIdx,1);
23454: }
23455: addtarget = lonhost;
23456: } else {
23457: if (currIdx == -1) {
23458: currBalancers.push(lonhost);
23459: }
23460: removetarget = lonhost;
23461: action = 'undelete';
23462: }
23463: balancerChange(balnum,baltotal,action,addtarget,removetarget);
23464: }
23465: return;
23466: }
23467:
23468: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
23469: if (baltotal > 1) {
23470: var offloadtypes = new Array('primary','default');
23471: var alltargets = new Array('$alltargets');
23472: var insttypes = new Array('$allinsttypes');
23473: for (var i=0; i<baltotal; i++) {
23474: if (i != balnum) {
23475: for (var j=0; j<offloadtypes.length; j++) {
23476: var total = alltargets.length - 1;
23477: for (var k=0; k<total; k++) {
23478: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
23479: var server = serveritem.value;
23480: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23481: if (server == addtarget) {
23482: serveritem.disabled = '';
23483: }
23484: }
23485: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23486: if (server == removetarget) {
23487: serveritem.disabled = 'disabled';
23488: serveritem.checked = false;
23489: }
23490: }
23491: }
23492: }
23493: for (var j=0; j<insttypes.length; j++) {
23494: if (insttypes[j] != '_LC_external') {
23495: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
23496: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
23497: var currSel = singleserver.selectedIndex;
23498: var currVal = singleserver.options[currSel].value;
23499: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23500: var numoptions = singleserver.options.length;
23501: var needsnew = 1;
23502: for (var k=0; k<numoptions; k++) {
23503: if (singleserver.options[k] == addtarget) {
23504: needsnew = 0;
23505: break;
23506: }
23507: }
23508: if (needsnew == 1) {
23509: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
23510: }
23511: }
23512: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23513: singleserver.options.length = 0;
23514: if ((currVal) && (currVal != removetarget)) {
23515: singleserver.options[0] = new Option("","",false,false);
23516: } else {
23517: singleserver.options[0] = new Option("","",true,true);
23518: }
23519: var idx = 0;
23520: for (var m=0; m<alltargets.length; m++) {
23521: if (currBalancers.indexOf(alltargets[m]) == -1) {
23522: idx ++;
23523: if (currVal == alltargets[m]) {
23524: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
23525: } else {
23526: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
23527: }
23528: }
23529: }
23530: }
23531: }
23532: }
23533: }
1.150 raeburn 23534: }
23535: }
23536: }
23537: return;
23538: }
23539:
1.152 raeburn 23540: // ]]>
23541: </script>
23542:
23543: END
23544: }
23545:
23546: sub new_spares_js {
23547: my @sparestypes = ('primary','default');
23548: my $types = join("','",@sparestypes);
23549: my $select = &mt('Select');
23550: return <<"END";
23551:
23552: <script type="text/javascript">
23553: // <![CDATA[
23554:
23555: function updateNewSpares(formname,lonhost) {
23556: var types = new Array('$types');
23557: var include = new Array();
23558: var exclude = new Array();
23559: for (var i=0; i<types.length; i++) {
23560: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
23561: for (var j=0; j<spareboxes.length; j++) {
23562: if (formname.elements[spareboxes[j]].checked) {
23563: exclude.push(formname.elements[spareboxes[j]].value);
23564: } else {
23565: include.push(formname.elements[spareboxes[j]].value);
23566: }
23567: }
23568: }
23569: for (var i=0; i<types.length; i++) {
23570: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
23571: var selIdx = newSpare.selectedIndex;
23572: var currnew = newSpare.options[selIdx].value;
23573: var okSpares = new Array();
23574: for (var j=0; j<newSpare.options.length; j++) {
23575: var possible = newSpare.options[j].value;
23576: if (possible != '') {
23577: if (exclude.indexOf(possible) == -1) {
23578: okSpares.push(possible);
23579: } else {
23580: if (currnew == possible) {
23581: selIdx = 0;
23582: }
23583: }
23584: }
23585: }
23586: for (var k=0; k<include.length; k++) {
23587: if (okSpares.indexOf(include[k]) == -1) {
23588: okSpares.push(include[k]);
23589: }
23590: }
23591: okSpares.sort();
23592: newSpare.options.length = 0;
23593: if (selIdx == 0) {
23594: newSpare.options[0] = new Option("$select","",true,true);
23595: } else {
23596: newSpare.options[0] = new Option("$select","",false,false);
23597: }
23598: for (var m=0; m<okSpares.length; m++) {
23599: var idx = m+1;
23600: var selThis = 0;
23601: if (selIdx != 0) {
23602: if (okSpares[m] == currnew) {
23603: selThis = 1;
23604: }
23605: }
23606: if (selThis == 1) {
23607: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
23608: } else {
23609: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
23610: }
23611: }
23612: }
23613: return;
23614: }
23615:
23616: function checkNewSpares(lonhost,type) {
23617: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
23618: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.372 raeburn 23619: if (chosen != '') {
1.152 raeburn 23620: var othertype;
23621: var othernewSpare;
23622: if (type == 'primary') {
23623: othernewSpare = document.getElementById('newspare_default_'+lonhost);
23624: }
23625: if (type == 'default') {
23626: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
23627: }
23628: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
23629: othernewSpare.selectedIndex = 0;
23630: }
23631: }
23632: return;
23633: }
23634:
23635: // ]]>
23636: </script>
23637:
23638: END
23639:
23640: }
23641:
23642: sub common_domprefs_js {
23643: return <<"END";
23644:
23645: <script type="text/javascript">
23646: // <![CDATA[
23647:
1.150 raeburn 23648: function getIndicesByName(formname,item) {
1.152 raeburn 23649: var group = new Array();
1.150 raeburn 23650: for (var i=0;i<formname.elements.length;i++) {
23651: if (formname.elements[i].name == item) {
1.152 raeburn 23652: group.push(formname.elements[i].id);
1.150 raeburn 23653: }
23654: }
1.152 raeburn 23655: return group;
1.150 raeburn 23656: }
23657:
23658: // ]]>
23659: </script>
23660:
23661: END
1.152 raeburn 23662:
1.150 raeburn 23663: }
23664:
1.165 raeburn 23665: sub recaptcha_js {
23666: my %lt = &captcha_phrases();
23667: return <<"END";
23668:
23669: <script type="text/javascript">
23670: // <![CDATA[
23671:
23672: function updateCaptcha(caller,context) {
23673: var privitem;
23674: var pubitem;
23675: var privtext;
23676: var pubtext;
1.269 raeburn 23677: var versionitem;
23678: var versiontext;
1.165 raeburn 23679: if (document.getElementById(context+'_recaptchapub')) {
23680: pubitem = document.getElementById(context+'_recaptchapub');
23681: } else {
23682: return;
23683: }
23684: if (document.getElementById(context+'_recaptchapriv')) {
23685: privitem = document.getElementById(context+'_recaptchapriv');
23686: } else {
23687: return;
23688: }
23689: if (document.getElementById(context+'_recaptchapubtxt')) {
23690: pubtext = document.getElementById(context+'_recaptchapubtxt');
23691: } else {
23692: return;
23693: }
23694: if (document.getElementById(context+'_recaptchaprivtxt')) {
23695: privtext = document.getElementById(context+'_recaptchaprivtxt');
23696: } else {
23697: return;
23698: }
1.269 raeburn 23699: if (document.getElementById(context+'_recaptchaversion')) {
23700: versionitem = document.getElementById(context+'_recaptchaversion');
23701: } else {
23702: return;
23703: }
23704: if (document.getElementById(context+'_recaptchavertxt')) {
23705: versiontext = document.getElementById(context+'_recaptchavertxt');
23706: } else {
23707: return;
23708: }
1.165 raeburn 23709: if (caller.checked) {
23710: if (caller.value == 'recaptcha') {
23711: pubitem.type = 'text';
23712: privitem.type = 'text';
23713: pubitem.size = '40';
23714: privitem.size = '40';
23715: pubtext.innerHTML = "$lt{'pub'}";
23716: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 23717: versionitem.type = 'text';
23718: versionitem.size = '3';
1.289 raeburn 23719: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 23720: } else {
23721: pubitem.type = 'hidden';
23722: privitem.type = 'hidden';
1.269 raeburn 23723: versionitem.type = 'hidden';
1.165 raeburn 23724: pubtext.innerHTML = '';
23725: privtext.innerHTML = '';
1.269 raeburn 23726: versiontext.innerHTML = '';
1.165 raeburn 23727: }
23728: }
23729: return;
23730: }
23731:
23732: // ]]>
23733: </script>
23734:
23735: END
23736:
23737: }
23738:
1.236 raeburn 23739: sub toggle_display_js {
1.192 raeburn 23740: return <<"END";
23741:
23742: <script type="text/javascript">
23743: // <![CDATA[
23744:
1.236 raeburn 23745: function toggleDisplay(domForm,caller) {
23746: if (document.getElementById(caller)) {
23747: var divitem = document.getElementById(caller);
23748: var optionsElement = domForm.coursecredits;
1.264 raeburn 23749: var checkval = 1;
23750: var dispval = 'block';
1.303 raeburn 23751: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 23752: if (caller == 'emailoptions') {
1.372 raeburn 23753: optionsElement = domForm.cancreate_email;
1.236 raeburn 23754: }
1.257 raeburn 23755: if (caller == 'studentsubmission') {
23756: optionsElement = domForm.postsubmit;
23757: }
1.264 raeburn 23758: if (caller == 'cloneinstcode') {
23759: optionsElement = domForm.canclone;
23760: checkval = 'instcode';
23761: }
1.303 raeburn 23762: if (selfcreateRegExp.test(caller)) {
23763: optionsElement = domForm.elements[caller];
23764: checkval = 'other';
23765: dispval = 'inline'
23766: }
1.236 raeburn 23767: if (optionsElement.length) {
1.192 raeburn 23768: var currval;
1.236 raeburn 23769: for (var i=0; i<optionsElement.length; i++) {
23770: if (optionsElement[i].checked) {
23771: currval = optionsElement[i].value;
1.192 raeburn 23772: }
23773: }
1.264 raeburn 23774: if (currval == checkval) {
23775: divitem.style.display = dispval;
1.192 raeburn 23776: } else {
1.236 raeburn 23777: divitem.style.display = 'none';
1.192 raeburn 23778: }
23779: }
23780: }
23781: return;
23782: }
23783:
23784: // ]]>
23785: </script>
23786:
23787: END
23788:
23789: }
23790:
1.165 raeburn 23791: sub captcha_phrases {
23792: return &Apache::lonlocal::texthash (
23793: priv => 'Private key',
23794: pub => 'Public key',
23795: original => 'original (CAPTCHA)',
23796: recaptcha => 'successor (ReCAPTCHA)',
23797: notused => 'unused',
1.289 raeburn 23798: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 23799: );
23800: }
23801:
1.205 raeburn 23802: sub devalidate_remote_domconfs {
1.212 raeburn 23803: my ($dom,$cachekeys) = @_;
23804: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 23805: my %servers = &Apache::lonnet::internet_dom_servers($dom);
23806: my %thismachine;
23807: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 raeburn 23808: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.394 raeburn 23809: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
1.410 raeburn 23810: 'ipaccess','trust');
1.386 raeburn 23811: my %cache_by_lonhost;
23812: if (exists($cachekeys->{'samllanding'})) {
23813: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
23814: my %landing = %{$cachekeys->{'samllanding'}};
23815: my %domservers = &Apache::lonnet::get_servers($dom);
23816: if (keys(%domservers)) {
23817: foreach my $server (keys(%domservers)) {
23818: my @cached;
23819: next if ($thismachine{$server});
23820: if ($landing{$server}) {
23821: push(@cached,&escape('samllanding').':'.&escape($server));
23822: }
23823: if (@cached) {
23824: $cache_by_lonhost{$server} = \@cached;
23825: }
23826: }
23827: }
23828: }
23829: }
1.260 raeburn 23830: if (keys(%servers)) {
1.205 raeburn 23831: foreach my $server (keys(%servers)) {
23832: next if ($thismachine{$server});
1.212 raeburn 23833: my @cached;
23834: foreach my $name (@posscached) {
23835: if ($cachekeys->{$name}) {
1.388 raeburn 23836: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
1.386 raeburn 23837: if (ref($cachekeys->{$name}) eq 'HASH') {
1.373 raeburn 23838: foreach my $key (keys(%{$cachekeys->{$name}})) {
23839: push(@cached,&escape($name).':'.&escape($key));
23840: }
23841: }
23842: } else {
23843: push(@cached,&escape($name).':'.&escape($dom));
23844: }
1.212 raeburn 23845: }
23846: }
1.386 raeburn 23847: if ((exists($cache_by_lonhost{$server})) &&
23848: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
23849: push(@cached,@{$cache_by_lonhost{$server}});
23850: }
1.212 raeburn 23851: if (@cached) {
23852: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
23853: }
1.205 raeburn 23854: }
23855: }
23856: return;
23857: }
23858:
1.3 raeburn 23859: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>